~ubuntu-branches/debian/stretch/hiki/stretch

« back to all changes in this revision

Viewing changes to misc/plugin/diffmail.rb

  • Committer: Bazaar Package Importer
  • Author(s): Taku YASUI
  • Date: 2005-08-05 07:43:00 UTC
  • Revision ID: james.westby@ubuntu.com-20050805074300-u0bxuhac6ssxltlu
Tags: 0.8.3-1
* New upstream release
  - Security fix release (fix cross-site scripting)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# $Id: diffmail.rb,v 1.2 2004/02/15 02:48:35 hitoshi Exp $
2
 
# Copyright (C) 2003 SHIMADA Mitsunobu <simm@fan.jp>
3
 
 
4
 
require 'hiki/algorithm/diff'
5
 
 
6
 
#----- send a mail on updating
7
 
def updating_mail
8
 
  begin
9
 
    latest_text = @db.load(@page) || ''
10
 
    type = (!@db.text or @db.text.size == 0) ? 'create' : 'update'
11
 
    if type == 'create' then
12
 
      text = "#{latest_text}\n"
13
 
    elsif type == 'update'
14
 
      text = ''
15
 
      src = @db.text.split("\n").collect{|s| "#{s}\n"}
16
 
      dst = latest_text.split("\n").collect{|s| "#{s}\n"}
17
 
      si = 0
18
 
      di = 0
19
 
      Diff.diff(src,dst).each do |action,position,elements|
20
 
        case action
21
 
        when :-
22
 
          while si < position
23
 
            text << "  #{src[si]}"
24
 
            si += 1
25
 
            di += 1
26
 
          end
27
 
          si += elements.length
28
 
          elements.each do |l|
29
 
            text << "- #{l}"
30
 
          end
31
 
        when :+
32
 
          while di < position
33
 
            text << "  #{src[si]}"
34
 
            si += 1
35
 
            di += 1
36
 
          end
37
 
          di += elements.length
38
 
          elements.each do |l|
39
 
            text << "+ #{l}"
40
 
          end
41
 
        end
42
 
      end
43
 
      while si < src.length
44
 
        text << "  #{src[si]}"
45
 
        si += 1
46
 
      end
47
 
    end
48
 
    send_updating_mail(@page, type, text)
49
 
  rescue
50
 
  end
51
 
end
 
1
# $Id: diffmail.rb,v 1.11 2005/07/17 14:29:06 fdiary Exp $
 
2
# Copyright (C) 2004-2005 Kazuhiko <kazuhiko@fdiary.net>
 
3
 
 
4
#----- send a mail on updating
 
5
def updating_mail
 
6
  begin
 
7
    latest_text = @db.load(@page) || ''
 
8
    if @params['page_title'][0]
 
9
      title = @params['page_title'][0].empty? ? @page : @params['page_title'][0].strip
 
10
    else
 
11
      title = nil
 
12
    end
 
13
    if @params['keyword'][0]
 
14
      keyword = (@params['keyword'][0]||'').split("\n").collect {|k|
 
15
        k.chomp.strip}.delete_if{|k| k.empty?}.join(' / ')
 
16
    else
 
17
      keyword = nil
 
18
    end
 
19
    head = ''
 
20
    type = (!@db.text or @db.text.empty?) ? 'create' : 'update'
 
21
    if type == 'create' then
 
22
      head << "TITLE       = #{title}\n" if title
 
23
      head << "KEYWORD     = #{keyword}\n" if keyword
 
24
      r = "#{latest_text}\n"
 
25
    elsif type == 'update'
 
26
      title_old = CGI::unescapeHTML( page_name( @page ) )
 
27
      keyword_old = @db.get_attribute(@page, :keyword).join(' / ')
 
28
      if title && title != title_old
 
29
        head << "TITLE       = #{title_old} -> #{title}\n"
 
30
      end
 
31
      if keyword && keyword != keyword_old
 
32
        head << "KEYWORD     = #{keyword_old} -> #{keyword}\n"
 
33
      end
 
34
      head << "-------------------------\n" unless head.empty?
 
35
 
 
36
      src = @db.text
 
37
      dst = latest_text
 
38
      diff_style = @options['diffmail.style'] || 0
 
39
      case diff_style.to_i
 
40
      when 0
 
41
        unified = @options['diffmail.lines'] || 3
 
42
        r = unified_diff( src, dst, unified )
 
43
      when 1
 
44
        r = word_diff_text( src, dst, true )
 
45
      end
 
46
    end
 
47
    send_updating_mail(@page, type, head + r) unless (head + r).empty?
 
48
  rescue
 
49
  end
 
50
end