Index: openacs-4/packages/xowiki/tcl/lcs-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/lcs-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/tcl/lcs-procs.tcl 9 Dec 2006 22:02:21 -0000 1.1 @@ -0,0 +1,147 @@ +# Copyright (c) 2003 by Kevin B. Kenny. All rights reserved. +# See the file, +# 'http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tcllib/tcllib/license.terms' +# for terms and conditions of redistribution. + + namespace eval list { namespace export longestCommonSubsequence } + + # Do a compatibility version of [lset] for pre-8.4 versions of Tcl. + # This version does not do multi-arg [lset]! + + if { [package vcompare [package provide Tcl] 8.4] < 0 } { + proc list::K { x y } { set x } + proc list::lset { var index arg } { + upvar 1 $var list + set list [lreplace [K $list [set list {}]] $index $index $arg] + } + } + + # list::longestCommonSubsequence -- + # + # Computes the longest common subsequence of two lists. + # + # Parameters: + # sequence1, sequence2 -- Two lists to compare. + # + # Results: + # Returns a list of two lists of equal length. + # The first sublist is of indices into sequence1, and the + # second sublist is of indices into sequence2. Each corresponding + # pair of indices corresponds to equal elements in the sequences; + # the sequence returned is the longest possible. + # + # Side effects: + # None. + + proc list::longestCommonSubsequence { sequence1 sequence2 } { + + # Construct a set of equivalence classes of lines in file 2 + + set index 0 + foreach string $sequence2 { + lappend eqv($string) $index + incr index + } + + # K holds descriptions of the common subsequences. + # Initially, there is one common subsequence of length 0, + # with a fence saying that it includes line -1 of both files. + # The maximum subsequence length is 0; position 0 of + # K holds a fence carrying the line following the end + # of both files. + + lappend K [list -1 -1 {}] + lappend K [list [llength $sequence1] [llength $sequence2] {}] + set k 0 + + # Walk through the first file, letting i be the index of the line and + # string be the line itself. + + set i 0 + foreach string $sequence1 { + + # Consider each possible corresponding index j in the second file. + + if { [info exists eqv($string)] } { + + # c is the candidate match most recently found, and r is the + # length of the corresponding subsequence. + + set c [lindex $K 0] + set r 0 + + foreach j $eqv($string) { + + # Perform a binary search to find a candidate common + # subsequence to which may be appended this match. + + set max $k + set min $r + set s [expr { $k + 1 }] + while { $max >= $min } { + set mid [expr { ( $max + $min ) / 2 }] + set bmid [lindex [lindex $K $mid] 1] + if { $j == $bmid } { + break + } elseif { $j < $bmid } { + set max [expr {$mid - 1}] + } else { + set s $mid + set min [expr { $mid + 1 }] + } + } + + # Go to the next match point if there is no suitable + # candidate. + + if { $j == [lindex [lindex $K $mid] 1] || $s > $k} { + continue + } + + # s is the sequence length of the longest sequence + # to which this match point may be appended. Make + # a new candidate match and store the old one in K + # Set r to the length of the new candidate match. + + set newc [list $i $j [lindex $K $s]] + lset K $r $c + set c $newc + set r [expr {$s + 1}] + + # If we've extended the length of the longest match, + # we're done; move the fence. + + if { $s >= $k } { + lappend K [lindex $K end] + incr k + break + } + + } + + # Put the last candidate into the array + + lset K $r $c + + } + + incr i + + } + + set q [lindex $K $k] + + for { set i 0 } { $i < $k } {incr i } { + lappend seta {} + lappend setb {} + } + while { [lindex $q 0] >= 0 } { + incr k -1 + lset seta $k [lindex $q 0] + lset setb $k [lindex $q 1] + set q [lindex $q 2] + } + + return [list $seta $setb] + + } Index: openacs-4/packages/xowiki/tcl/package-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/package-procs.tcl,v diff -u -r1.24 -r1.25 --- openacs-4/packages/xowiki/tcl/package-procs.tcl 8 Dec 2006 16:01:51 -0000 1.24 +++ openacs-4/packages/xowiki/tcl/package-procs.tcl 9 Dec 2006 22:02:21 -0000 1.25 @@ -252,6 +252,7 @@ set [expr {$revision_id ? "item_id" : "revision_id"}] 0 #my log "--instantiate item_id $item_id revision_id $revision_id" set r [::Generic::CrItem instantiate -item_id $item_id -revision_id $revision_id] + $r destroy_on_cleanup #my log "--instantiate done CONTENT\n[$r serialize]" $r set package_id [namespace tail [self]] return $r @@ -307,7 +308,7 @@ my set folder_id $folder_id } - Package instproc return_page {-adp -variables -form} { + Package instproc return_page {-adp:required -variables -form} { #my log "--vars=[self args]" set __vars [list] foreach _var $variables { @@ -519,6 +520,7 @@ Class Page -array set require_permission { view none revisions {{package_id write}} + diff {{package_id write}} edit {{package_id write}} make-live-revision {{package_id write}} delete-revision {{package_id admin}} @@ -553,6 +555,7 @@ Class Page -array set require_permission { view {{package_id read}} revisions {{package_id write}} + diff {{package_id write}} edit {{package_id write}} make-live-revision {{package_id write}} delete-revision swa @@ -587,6 +590,7 @@ Class Page -array set require_permission { view {{item_id read}} revisions {{item_id write}} + diff {{item_id write}} edit {{item_id write}} make-live-revision {{item_id write}} delete-revision swa Index: openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl,v diff -u -r1.21 -r1.22 --- openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl 2 Dec 2006 14:09:35 -0000 1.21 +++ openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl 9 Dec 2006 22:02:21 -0000 1.22 @@ -365,4 +365,89 @@ ns_return 200 text/html "[_ xowiki.popular_tags_label]: [join $entries {, }]" } + Page instproc diff {} { + my instvar package_id + set compare_id [my query_parameter "compare_revision_id" 0] + if {$compare_id == 0} { + return "" + } + set my_page [::xowiki::Package instantiate_page_from_id -revision_id [my set revision_id]] + $my_page volatile + + set html1 [$my_page render] + set text1 [ad_html_text_convert -from text/html -to text/plain -- $html1] + set user1 [::xo::get_user_name [$my_page set creation_user]] + set time1 [$my_page set creation_date] + set revision_id1 [$my_page set revision_id] + regexp {^([^.]+)[.]} $time1 _ time1 + + set other_page [::xowiki::Package instantiate_page_from_id -revision_id $compare_id] + $other_page volatile + #$other_page absolute_links 1 + + set html2 [$other_page render] + set text2 [ad_html_text_convert -from text/html -to text/plain -- $html2] + set user2 [::xo::get_user_name [$other_page set creation_user]] + set time2 [$other_page set creation_date] + set revision_id2 [$other_page set revision_id] + regexp {^([^.]+)[.]} $time2 _ time2 + + set title "Differences for [my set name]" + set context [list $title] + + set content [::xowiki::html_diff $text2 $text1] + $package_id return_page -adp /packages/xowiki/www/diff -variables { + content title context + time1 time2 user1 user2 revision_id1 revision_id2 + } + } + + proc html_diff {doc1 doc2} { + set out "" + set i 0 + set j 0 + + set lines1 [split $doc1 "\n"] + set lines2 [split $doc2 "\n"] + + regsub -all \n $doc1
doc1 + regsub -all \n $doc2
doc2 + set lines1 [split $doc1 " "] + set lines2 [split $doc2 " "] + + foreach { x1 x2 } [list::longestCommonSubsequence $lines1 $lines2] { + foreach p $x1 q $x2 { + while { $i < $p } { + set l [lindex $lines1 $i] + incr i + #puts "R\t$i\t\t$l" + append out "$l\n" + } + while { $j < $q } { + set m [lindex $lines2 $j] + incr j + #puts "A\t\t$j\t$m" + append out "$m\n" + } + set l [lindex $lines1 $i] + incr i; incr j + #puts "B\t$i\t$j\t$l" + append out "$l\n" + } + } + while { $i < [llength $lines1] } { + set l [lindex $lines1 $i] + incr i + puts "$i\t\t$l" + append out "$l\n" + } + while { $j < [llength $lines2] } { + set m [lindex $lines2 $j] + incr j + #puts "\t$j\t$m" + append out "$m\n" + } + return $out + } + } Index: openacs-4/packages/xowiki/www/diff.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/diff.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/www/diff.adp 9 Dec 2006 22:02:22 -0000 1.1 @@ -0,0 +1,29 @@ + + @title;noquote@ + @context;noquote@ + + + + + + + +

Comparing +

+

+
+ +@content;noquote@ +