(file) Return to RDiff.pm CVS log (file) (dir) Up to [RizwankCVS] / geekymedia_web / twiki / lib / TWiki / UI

  1 rizwank 1.1 # TWiki Collaboration Platform, http://TWiki.org/
  2             #
  3             # Copyright (C) 1999-2004 Peter Thoeny, peter@thoeny.com
  4             #
  5             # For licensing info read license.txt file in the TWiki root.
  6             # This program is free software; you can redistribute it and/or
  7             # modify it under the terms of the GNU General Public License
  8             # as published by the Free Software Foundation; either version 2
  9             # of the License, or (at your option) any later version.
 10             #
 11             # This program is distributed in the hope that it will be useful,
 12             # but WITHOUT ANY WARRANTY; without even the implied warranty of
 13             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14             # GNU General Public License for more details, published at 
 15             # http://www.gnu.org/copyleft/gpl.html
 16             =begin twiki
 17             
 18             ---+ TWiki::UI::RDiff
 19             
 20             UI functions for diffing.
 21             
 22 rizwank 1.1 =cut
 23             
 24             package TWiki::UI::RDiff;
 25             
 26             use strict;
 27             use TWiki;
 28             use TWiki::Store;
 29             use TWiki::Prefs;
 30             use TWiki::UI;
 31             
 32             #TODO: this needs to be exposed to plugins and whoever might want to over-ride the rendering of diffs
 33             #Hash, indexed by diffType (+,-,c,u,l.....)
 34             #contains {colour, CssClassName}
 35             my %diffColours = ( "+" => [ "#ccccff", "twikiDiffAddedMarker"],
 36                                 "-" => [ "#ff9999", "twikiDiffDeletedMarker"],
 37                                 "c" => [ "#99ff99", "twikiDiffChangedText"],
 38                                 "u" => [ "#ffffff", "twikiDiffUnchangedText"],
 39                                 "l" => [ "#eeeeee", "twikiDiffLineNumberHeader"] );
 40             
 41             #SVEN - new design.
 42             #main gets the info (NO MAJOR CHANGES NEEDED)
 43 rizwank 1.1 #parseDiffs reads the diffs and interprets the information into types {"+", "-", "u", "c", "l"} (add, remove, unchanged, changed, lineNumber} where line number is for diffs that skip unchanged lines (diff -u etc)
 44             #so renderDiffs would get an array of [changeType, $oldstring, $newstring] 
 45             #		corresponding to Algorithm::Diff's output
 46             #renderDiffs iterates through the interpreted info and makes it into TML / HTML? (mmm)
 47             #and can be over-ridden :)
 48             #(now can we do this in a way that automagically can cope eith word / letter based diffs?)
 49             #NOTE: if we do our own diffs in perl we can go straight to renderDiffs
 50             #TODO: I'm starting to think that we should have a variable number of lines of context. more context if you are doing a 1.13 tp 1.14 diff, less when you do a show page history.
 51             #TODO: ***URGENT*** the diff rendering dies badly when you have table cell changes and context
 52             #TODO: ?type={history|diff} so that you can do a normal diff between r1.3 and r1.32 (rather than a history) (and when doing a history, we maybe should not expand %SEARCH...
 53             
 54             
 55             # =========================
 56             =pod
 57             
 58             ---+++ _renderCellData( $data, $topic ) ==> $data
 59             
 60             | Description: | twiki render a cell of data from a Diff |
 61             | Parameter: =$data= |  |
 62             | Parameter: =$topic= |  |
 63             | Return: =$text= | Formatted html text |
 64 rizwank 1.1 | TODO: | this should move to Render.pm |
 65             | TODO: | need to fix unmatched <p>, <div> and.... |
 66             
 67             =cut
 68             # -------------------------
 69             sub _renderCellData {
 70                 my( $data, $topic ) = @_;
 71                 if (( $data ) && ( $data ne "" )) {
 72             #improve meta-data diff's - Main.PeterKlausner
 73                     if( $data =~ /%META/ )
 74                     {
 75                         $data =~ s(^%META:TOPICPARENT.*="([^"]+).*$)
 76                                   (|*META TOPICPARENT*|$1 ||)gm;
 77                         $data =~ s(^%META:FIELD.name="(.*?)".title="(.*?)".value="(.*?)".*$)
 78                                   (|*META FIELD $2*|$1 |$3 |)gm;
 79                         $data =~ s(^%META:([A-Z]+).\w+="([^"]+)"(.*).%$)
 80                                   (|*META $1*|$2 |$3 |)gm;
 81                     }
 82             
 83                     $data = &TWiki::handleCommonTags( $data, $topic );
 84                     $data = &TWiki::Render::getRenderedVersion( $data );
 85 rizwank 1.1         if( $data =~ m/<\/?(th|td|table)/i )
 86                     {
 87                         # data has <th> or <td>, need to fix <table>
 88                         my $bTable = ( $data =~ s/(<table)/$1/gois ) || 0;
 89                         my $eTable = ( $data =~ s/(<\/table)/$1/gois ) || 0;
 90                         my $i = 0;
 91                         if( $bTable > $eTable ) {
 92                             for( $i = $eTable; $i < $bTable; $i++ ) {
 93                                $data .= "</table>";
 94                             }
 95                         } elsif( $bTable < $eTable ) {
 96                             for( $i = $bTable; $i < $eTable; $i++ ) {
 97                                $data = "\n<table>$data";
 98                             }
 99                         } elsif( ( $bTable == 0 ) && ( $eTable == 0 ) ) {
100                             $data = "\n<table>$data\n</table>";
101                         }
102                     }
103             	#remove the <!--- type tag (i don't know how you would find the matching >)
104             	$data =~ s/<!/&lt!/go;
105                 }
106 rizwank 1.1     return $data;
107             }
108             
109             # =========================
110             =pod
111             
112             ---+++ _renderSideBySide( $topic, $diffType, $left, $right ) ==> $result
113             
114             | Description: | render the Diff entry using side by side |
115             | Parameter: =$diffType= | {+,-,u,c,l} denotes the patch operation |
116             | Parameter: =$left= | the text blob before the opteration |
117             | Parameter: =$right= | the text after the operation |
118             | Return: =$result= | Formatted html text |
119             | TODO: | this should move to Render.pm |
120             
121             =cut
122             # -------------------------
123             sub _renderSideBySide
124             {
125               my ( $topic, $diffType, $left, $right ) = @_;
126               my $result = "";
127 rizwank 1.1 
128               $left = _renderCellData( $left, $topic );
129               $right = _renderCellData( $right, $topic );
130             
131               if ( $diffType eq "-") {
132                 $result .= qq(<tr><td bgcolor="$diffColours{"-"}[0]" class="$diffColours{"-"}[1]" valign="top">$left&nbsp;</td>);
133                 $result .= qq(<td bgcolor="$diffColours{"u"}[0]" class="$diffColours{"u"}[1]" valign="top">$right&nbsp;</td></tr>\n);
134               } elsif ( $diffType eq "+") {
135                 $result .= qq(<tr><td bgcolor="$diffColours{"u"}[0]" class="$diffColours{"u"}[1]" valign="top">$left&nbsp;</td>);
136                 $result .= qq(<td bgcolor="$diffColours{"+"}[0]" class="$diffColours{"+"}[1]" valign="top">$right&nbsp;</td></tr>\n);
137               } elsif ( $diffType eq "u") {
138                 $result .= qq(<tr><td bgcolor="$diffColours{"u"}[0]" class="$diffColours{"u"}[1]" valign="top">$left&nbsp;</td>);
139                 $result .= qq(<td bgcolor="$diffColours{"u"}[0]" class="$diffColours{"u"}[1]" valign="top">$right&nbsp;</td></tr>\n);
140               } elsif ( $diffType eq "c") {
141                 $result .= qq(<tr><td bgcolor="$diffColours{"c"}[0]" class="$diffColours{"c"}[1]" valign="top">$left&nbsp;</td>);
142                 $result .= qq(<td bgcolor="$diffColours{"c"}[0]" class="$diffColours{"c"}[1]" valign="top">$right&nbsp;</td></tr>\n);
143               } elsif ( $diffType eq "l") {
144                 if (( $left ne "" ) && ($right ne "" )) {
145                   $result .= qq(<tr bgcolor="$diffColours{"l"}[0]" class="$diffColours{"l"}[1]"><th align="center">Line: $left</th><th align="center">Line: $right</th></tr>\n);
146                 }
147               }
148 rizwank 1.1 
149               return $result;
150             }
151             
152             # =========================
153             =pod
154             
155             ---+++ renderDebug( $diffType, $left, $right ) ==> $result
156             
157             | Description: | render the Diff array (no TML conversion) |
158             | Parameter: =$diffType= | {+,-,u,c,l} denotes the patch operation |
159             | Parameter: =$left= | the text blob before the opteration |
160             | Parameter: =$right= | the text after the operation |
161             | Return: =$result= | Formatted html text |
162             | TODO: | this should move to Render.pm |
163             
164             =cut
165             # -------------------------
166             sub renderDebug
167             {
168               my ( $diffType, $left, $right ) = @_;
169 rizwank 1.1   my $result = "";
170             
171             #de-html-ize
172               $left =~ s/</&lt;/go;
173               $right =~ s/</&lt;/go;
174               $left =~ s/>/&gt;/go;
175               $right =~ s/>/&gt;/go;
176             
177               $result = "<hr>type: $diffType\n";
178               $result .= "<div style=\"border: 1px dotted;\">$left</div>\n";
179               $result .= "<div style=\"border: 1px dotted;\">$right</div>\n";
180             
181               return $result;
182             }
183             
184             
185             # =========================
186             =pod
187             
188             ---+++ _renderSequential( $topic, $diffType, $left, $right ) ==> $result
189             
190 rizwank 1.1 | Description: | render the Diff using old style sequential blocks |
191             | Parameter: =$diffType= | {+,-,u,c,l} denotes the patch operation |
192             | Parameter: =$left= | the text blob before the opteration |
193             | Parameter: =$right= | the text after the operation |
194             | Return: =$result= | Formatted html text |
195             | TODO: | this should move to Render.pm |
196             
197             =cut
198             # -------------------------
199             sub _renderSequential
200             {
201               my ( $topic, $diffType, $left, $right ) = @_;
202               my $result = "";
203             
204             #note: I have made the colspan 9 to make sure that it spans all columns (thought there are only 2 now)
205               if ( $diffType eq "-") {
206                 $result .= qq(<tr><td bgcolor="#FFD7D7" class="twikiDiffDeletedHeader" colspan ="9"><b> Deleted: </b>\n</td></tr>\n);
207                 $result .= qq(<tr><td bgcolor="$diffColours{"-"}[0]" class="$diffColours{"-"}[1]" valign="top" width="1%">&lt;<br />&lt;</td>\n);
208                 $result .= qq(<td class="twikiDiffDeletedText">\n);
209                 $result .= _renderCellData( $left, $topic );
210                 $result .= qq(\n</td></tr>\n);
211 rizwank 1.1   } elsif ( $diffType eq "+") {
212                 $result .= qq(<tr><td bgcolor="#D0FFD0" class="twikiDiffAddedHeader" colspan ="9"><b> Added:   </b>\n</td></tr>\n);
213                 $result .= qq(<tr><td bgcolor="$diffColours{"+"}[0]" class="$diffColours{"+"}[1]" valign="top" width="1%">&gt;<br />&gt;</td>\n);
214                 $result .= qq(<td class="twikiDiffAddedText">\n);
215                 $result .= _renderCellData( $right, $topic );
216                 $result .= qq(\n</td></tr>\n);
217               } elsif ( $diffType eq "u") {
218                 $result .= qq(<tr><td valign="top" bgcolor="$diffColours{"u"}[0]" class="$diffColours{"u"}[1]" width="1%"><br /></td>\n);
219                 $result .= qq(<td class="twikiDiffUnchangedText">\n);
220                 $result .= _renderCellData( $right, $topic );
221                 $result .= qq(\n</td></tr>\n);
222               } elsif ( $diffType eq "c") {
223                 $result .= qq(<tr><td bgcolor="#D0FFD0" class="twikiDiffChangedHeader" colspan ="9"><b> Changed: </b></td></tr>\n);
224                 $result .= qq(<tr><td bgcolor="$diffColours{"-"}[0]" class="$diffColours{"-"}[1]" valign="top" width="1%">&lt;<br />&lt;</td>\n);
225                 $result .= qq(<td class="twikiDiffDeletedText">\n);
226                 $result .= _renderCellData( $left, $topic );
227                 $result .= qq(\n</td></tr>\n);
228                 $result .= qq(<tr><td bgcolor="$diffColours{"+"}[0]" class="$diffColours{"+"}[1]" valign="top" width="1%">&gt;<br />&gt;</td>\n);
229                 $result .= qq(<td class="twikiDiffAddedText">\n);
230                 $result .= _renderCellData( $right, $topic );
231                 $result .= qq(\n</td></tr>\n);
232 rizwank 1.1   } elsif ( $diffType eq "l") {
233                 if (( $left ne "" ) && ($right ne "" )) {
234                   $result .= qq(<tr bgcolor="$diffColours{"l"}[0]" class="twikiDiffLineNumberHeader"><th align="left" colspan="9">Line: $left to $right</th></tr>\n);
235                 }
236               }
237             
238               return $result;
239             }
240             
241             # =========================
242             =pod
243             
244             ---+++ _renderRevisionDiff( $topic, $diffArray_ref, $renderStyle ) ==> $text
245             
246             | Description: | uses renderStyle to choose the rendering function to use |
247             | Parameter: =$diffArray= | array generated by parseRevisionDiff |
248             | Parameter: =$renderStyle= | style of rendering { debug, sequential, sidebyside} |
249             | Return: =$text= | output html for one renderes revision diff |
250             | TODO: | move into Render.pm |
251             
252             =cut
253 rizwank 1.1 # -------------------------
254             sub _renderRevisionDiff
255             {
256                 my( $topic, $sdiffArray_ref, $renderStyle ) = @_;
257             
258             #combine sequential array elements that are the same diffType
259                 my @diffArray = ();
260             	foreach my $ele ( @$sdiffArray_ref ) {
261             		if( ( @$ele[1] =~ /^\%META\:TOPICINFO/ ) || ( @$ele[2] =~ /^\%META\:TOPICINFO/ ) ) {
262             			# do nothing, ignore redundant topic info
263             			# FIXME: Intelligently remove followup lines in case META:TOPICINFO is the only change
264             		} elsif( ( @diffArray ) && ( @{$diffArray[$#diffArray]}[0] eq @$ele[0] ) ) {
265             			@{$diffArray[$#diffArray]}[1] .= "\n".@$ele[1];
266             			@{$diffArray[$#diffArray]}[2] .= "\n".@$ele[2];
267             		} else {
268             			push @diffArray, $ele;
269             		}
270             	}
271             	my $diffArray_ref = \@diffArray;
272             
273                 my $result = "<table class=\"twikiDiffTable\" width=\"100%\" cellspacing=\"0\">\n";
274 rizwank 1.1     my $data = "";
275                 my $diff_ref = undef;
276                 for my $next_ref ( @$diffArray_ref ) {
277                 	if (( @$next_ref[0] eq "l" ) && ( @$next_ref[1] eq 0 ) && (@$next_ref[2] eq 0)) {
278             	    next;
279             		}
280             		if (! $diff_ref ) {
281             		   $diff_ref = $next_ref;
282             		   next;
283             		}
284             		if (( @$diff_ref[0] eq "-" ) && ( @$next_ref[0] eq "+" )) {
285             		    $diff_ref = ["c", @$diff_ref[1], @$next_ref[2]];
286                 	        $next_ref = undef;
287             		}
288             		if ( $renderStyle eq "sequential" ) {
289             		    $result .= _renderSequential ( $topic, @$diff_ref );
290             		} elsif ( $renderStyle eq "sidebyside" ) {
291                 		    $result .= "<tr><td width=\"50%\"></td><td width=\"50%\"></td></tr>\n";
292             		    $result .= _renderSideBySide ( $topic, @$diff_ref );
293             		} elsif ( $renderStyle eq "debug" ) {
294             		    $result .= renderDebug ( @$diff_ref );
295 rizwank 1.1 		}
296             		$diff_ref = $next_ref;
297             	}
298             #don't forget the last one ;)
299                if ( $diff_ref ) {
300             	if ( $renderStyle eq "sequential" ) {
301             	    $result .= _renderSequential ( $topic, @$diff_ref );
302             	} elsif ( $renderStyle eq "sidebyside" ) {
303                 	    $result .= "<tr><td width=\"50%\"></td><td width=\"50%\"></td></tr>\n";
304             	    $result .= _renderSideBySide ( $topic, @$diff_ref );
305             	} elsif ( $renderStyle eq "debug" ) {
306             	    $result .= renderDebug ( @$diff_ref );
307             	}
308                 }
309                 return "$result\n<\/table>";
310             }
311             
312             # =========================
313             =pod
314             
315             ---+++ getRevInfo( $web, $rev, $topic, $short ) ==> $revInfo
316 rizwank 1.1 
317             | Description: | gets a displayable date and user string |
318             | Parameter: =$web= | topic webname |
319             | Parameter: =$rev= | revision number of the topic |
320             | Parameter: =$topic= | topic name |
321             | Parameter: =$short= | use a shortened version of the date string |
322             | Return: =$text= | date - wikiusername |
323             | TODO: | move to Render.pm |
324             
325             =cut
326             # -------------------------
327             sub getRevInfo
328             {
329                 my( $web, $rev, $topic, $short ) = @_;
330             
331                 my( $date, $user ) = &TWiki::Store::getRevisionInfo( $web, $topic, "1.$rev");
332                 $user = TWiki::Render::getRenderedVersion( TWiki::userToWikiName( $user ) );
333             	
334                 if ( $short ) {
335             	    $date = TWiki::formatTime( $date, "\$day \$month \$year" );
336                     # eliminate white space to prevent wrap around in HR table:
337 rizwank 1.1         $date =~ s/ /\&nbsp\;/go;
338                 } else {
339                     $date = TWiki::formatTime( $date );
340             	}
341             
342                 my $revInfo = "$date - $user";
343                 $revInfo =~ s/[\n\r]*//go;
344                 return $revInfo;
345             }
346             
347             
348             # =========================
349             =pod
350             
351             ---++ diff( $web, $topic, $query )
352             
353             | Description: | CgiScript to render the differences between version of a TwikiTopic |
354             | Parameter: param("topic") | topic that we are showing the differences of |
355             | Parameter: param( "rev1" ) | the higher revision |
356             | Parameter: param( "rev2" ) | the lower revision |
357             | Parameter: param('render') | the rendering style {sequential, sidebyside, raw, debug} |
358 rizwank 1.1 | Parameter: param( 'type' ) | {history, diff, last} history diff, version to version, last version to previous |
359             | Parameter: param( 'context' ) | number of lines of context |
360             | TODO: | add a {word} render style |
361             | Parameter: param( "skin" ) | the skin to use to display the diff |
362             | TODO: | move the common CGI param handling to one place |
363             | TODO: | move defaults somewhere |
364             | Return: | none |
365             
366             =cut
367             
368             sub diff {
369               my ( $webName, $topic, $userName, $query ) = @_;
370             
371               my $renderStyle = $query->param('render');
372               $renderStyle = &TWiki::Prefs::getPreferencesValue( "DIFFRENDERSTYLE" ) unless ( $renderStyle );
373               my $diffType = $query->param('type');
374               my $contextLines = $query->param('context');
375               $contextLines = &TWiki::Prefs::getPreferencesValue( "DIFFCONTEXTLINES" ) unless ( $contextLines );
376               my $skin = $query->param( "skin" );
377               $skin = &TWiki::Prefs::getPreferencesValue( "SKIN" ) unless ( $skin );
378               my $rev1 = $query->param( "rev1" );
379 rizwank 1.1   my $rev2 = $query->param( "rev2" );
380             
381               $renderStyle = "sequential" if ( ! $renderStyle );
382               $diffType = "history" if ( ! $diffType );
383               $contextLines = 3 if ( ! $contextLines );
384             
385               return unless TWiki::UI::webExists( $webName, $topic );
386             
387               my $tmpl = "";
388               my $diff = "";
389               my $maxrev= 1;
390               my $i = $maxrev;
391               my $j = $maxrev;
392               my $revTitle1 = "";
393               my $revTitle2 = "";
394               my $revInfo1 = "";
395               my $revInfo2 = "";
396               my $isMultipleDiff = 0;
397               my $scriptUrlPath = $TWiki::scriptUrlPath;
398             
399               $tmpl = &TWiki::Store::readTemplate( "rdiff", $skin );
400 rizwank 1.1   $tmpl =~ s/\%META{.*?}\%//go;  # remove %META{"parent"}%
401             
402               my( $before, $difftmpl, $after) = split( /%REPEAT%/, $tmpl);
403             
404               my $topicExists = &TWiki::Store::topicExists( $webName, $topic );
405               if( $topicExists ) {
406                 $maxrev = &TWiki::Store::getRevisionNumber( $webName, $topic );
407                 $maxrev =~ s/r?1\.//go;  # cut 'r' and major
408                 if( ! $rev1 ) { $rev1 = 0; }
409                 if( ! $rev2 ) { $rev2 = 0; }
410                 $rev1 =~ s/r?1\.//go;  # cut 'r' and major
411                 $rev2 =~ s/r?1\.//go;  # cut 'r' and major
412                 if( $rev1 < 1 )       { $rev1 = $maxrev; }
413                 if( $rev1 > $maxrev ) { $rev1 = $maxrev; }
414                 if( $rev2 < 1 )       { $rev2 = 1; }
415                 if( $rev2 > $maxrev ) { $rev2 = $maxrev; }
416                 if ( $diffType eq "last" ) {
417                   $rev1 = $maxrev;
418                   $rev2 = $maxrev-1;
419                 }
420                 $revTitle1 = "r1.$rev1";
421 rizwank 1.1     $revInfo1 = getRevInfo( $webName, $rev1, $topic );
422                 if( $rev1 != $rev2 ) {
423                   $revTitle2 = "r1.$rev2";
424                   $revInfo2 = getRevInfo( $webName, $rev2, $topic );
425                 }
426               } else {
427                 $rev1 = 1;
428                 $rev2 = 1;
429               }
430             
431               # check access permission
432               my $wikiUserName = &TWiki::userToWikiName( $userName );
433               my $viewAccessOK = &TWiki::Access::checkAccessPermission( "view", $wikiUserName, "", $topic, $webName );
434               if( $TWiki::readTopicPermissionFailed ) {
435                 # Can't read requested topic and/or included (or other accessed topics)
436                 # user could not be authenticated, may be not logged in yet?
437                 my $rdiffauthFile = $ENV{'SCRIPT_FILENAME'};
438                 $rdiffauthFile =~ s|/rdiff|/rdiffauth|o;
439                 if( ( ! $query->remote_user() ) && (-e $rdiffauthFile ) ) {
440                   # try again with authenticated rdiffauth script
441                   # instead of non authenticated rdiff script
442 rizwank 1.1       my $url = $ENV{"REQUEST_URI"};
443                   if( $url ) {
444                     # $url i.e. is "twiki/bin/rdiff.cgi/Web/Topic?cms1=val1&cmd2=val2"
445                     $url =~ s|/rdiff|/rdiffauth|o;
446                     $url = "$TWiki::urlHost$url";
447                   } else {
448                     $url = "$TWiki::urlHost$scriptUrlPath/$rdiffauthFile/$webName/$topic";
449                   }
450                   TWiki::UI::redirect( $url );
451                   return;
452                 }
453               }
454               if( ! $viewAccessOK ) {
455                 TWiki::UI::oops( $webName, $topic, "accessview" );
456                 return;
457               }
458             
459               # format "before" part
460               $before =~ s/%REVTITLE1%/$revTitle1/go;
461               $before =~ s/%REVTITLE2%/$revTitle2/go;
462               $before = &TWiki::handleCommonTags( $before, $topic );
463 rizwank 1.1   $before = &TWiki::Render::getRenderedVersion( $before );
464               $before =~ s/( ?) *<\/?(nop|noautolink)\/?>\n?/$1/gois;   # remove <nop> and <noautolink> tags
465               &TWiki::writeHeader( $query );
466               print $before;
467             
468               # do one or more diffs
469               $difftmpl = &TWiki::handleCommonTags( $difftmpl, $topic );
470               if( $topicExists ) {
471                 my $r1 = $rev1;
472                 my $r2 = $rev2;
473                 my $rInfo = "";
474                 if (( $diffType eq "history" ) && ( $r1 > $r2 + 1)) {
475                   $r2 = $r1 - 1;
476                   $isMultipleDiff = 1;
477                 }
478                 do {
479                   $diff = $difftmpl;
480                   $diff =~ s/%REVTITLE1%/r1\.$r1/go;
481                   $rInfo = getRevInfo( $webName, $r1, $topic, 1 );
482                   $diff =~ s/%REVINFO1%/$rInfo/go;
483                   my $diffArrayRef = &TWiki::Store::getRevisionDiff( $webName, $topic, "1.$r2", "1.$r1", $contextLines );
484 rizwank 1.1       #            $text = &TWiki::Store::getRevisionDiff( $webName, $topic, "1.$r2", "1.$r1", $contextLines );
485                   #            if ( $renderStyle eq "raw" ) {
486                   #                $text = "\n<code>\n$text\n</code>\n";
487                   #            } else {
488                   #                my $diffArray = parseRevisionDiff( $text );
489                   my $text = _renderRevisionDiff( $topic, $diffArrayRef, $renderStyle );
490                   #            }
491                   $diff =~ s/%TEXT%/$text/go;
492                   $diff =~ s/( ?) *<\/?(nop|noautolink)\/?>\n?/$1/gois;   # remove <nop> and <noautolink> tags
493                   print $diff;
494                   $r1 = $r1 - 1;
495                   $r2 = $r2 - 1;
496                   if( $r2 < 1 ) { $r2 = 1; }
497                 } while( ( $diffType eq "history") && (( $r1 > $rev2 ) || ( $r1 == 1 )) );
498                 
499               } else {
500                 $diff = $difftmpl;
501                 $diff =~ s/%REVTITLE1%/$revTitle1/go;
502                 $diff =~ s/%REVTITLE2%/$revTitle2/go;
503                 $diff =~ s/%TEXT%//go;
504                 $diff =~ s/( ?) *<\/?(nop|noautolink)\/?>\n?/$1/gois;   # remove <nop> and <noautolink> tags
505 rizwank 1.1     print $diff;
506               }
507               
508               if( $TWiki::doLogTopicRdiff ) {
509                 # write log entry
510                 &TWiki::Store::writeLog( "rdiff", "$webName.$topic", "r1.$rev1 r1.$rev2" );
511               }
512               
513               # format "after" part
514               $i = $maxrev;
515               $j = $maxrev;
516               my $revisions = "";
517               my $breakRev = 0;
518               if( ( $TWiki::numberOfRevisions > 0 ) && ( $TWiki::numberOfRevisions < $maxrev ) ) {
519                 $breakRev = $maxrev - $TWiki::numberOfRevisions + 1;
520               }
521               
522               while( $i > 0 ) {
523                 $revisions .= " | <a href=\"$scriptUrlPath/view%SCRIPTSUFFIX%/%WEB%/%TOPIC%?rev=1.$i\">r1.$i</a>";
524                 if( $i != 1 ) {
525                   if( $i == $breakRev ) {
526 rizwank 1.1         # Now obsolete because of 'More' link
527                     # $revisions = "$revisions | <a href=\"$scriptUrlPath/oops%SCRIPTSUFFIX%/%WEB%/%TOPIC%?template=oopsrev&amp;param1=1.$maxrev\">&gt;...</a>";
528                     $i = 1;
529                     
530                   } else {
531                     if( ( $i == $rev1 ) && ( !$isMultipleDiff ) ) {
532                       $revisions .= " | &gt;";
533                     } else {
534                       $j = $i - 1;
535                       $revisions .= " | <a href=\"$scriptUrlPath/rdiff%SCRIPTSUFFIX%/%WEB%/%TOPIC%?rev1=1.$i&amp;rev2=1.$j\">&gt;</a>";
536                     }
537                   }
538                 }
539                 $i = $i - 1;
540               }
541               $after =~ s/%REVISIONS%/$revisions/go;
542               $after =~ s/%CURRREV%/1.$rev1/go;
543               $after =~ s/%MAXREV%/1.$maxrev/go;
544               $after =~ s/%REVTITLE1%/$revTitle1/go;
545               $after =~ s/%REVINFO1%/$revInfo1/go;
546               $after =~ s/%REVTITLE2%/$revTitle2/go;
547 rizwank 1.1   $after =~ s/%REVINFO2%/$revInfo2/go;
548               
549               $after = &TWiki::handleCommonTags( $after, $topic );
550               $after = &TWiki::Render::getRenderedVersion( $after );
551               $after =~ s/( ?) *<\/?(nop|noautolink)\/?>\n?/$1/gois;   # remove <nop> and <noautolink> tags
552               
553               print $after;
554             }
555             
556             1;

Rizwan Kassim
Powered by
ViewCVS 0.9.2