/
RDiff.pm
762 lines (664 loc) · 24.5 KB
/
RDiff.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
# See bottom of file for license and copyright information
=begin TML
---+ package Foswiki::UI::RDiff
UI functions for diffing.
=cut
package Foswiki::UI::RDiff;
use v5.14;
use Assert;
use Try::Tiny;
use Foswiki ();
use Foswiki::Class;
extends qw(Foswiki::UI);
#TODO: this needs to be exposed to plugins and whoever might want to over-ride the rendering of diffs
#Hash, indexed by diffType (+,-,c,u,l.....)
#contains {colour, CssClassName}
my %format = (
'+' => [ '#ccccff', 'foswikiDiffAddedMarker' ],
'-' => [ '#ff9999', 'foswikiDiffDeletedMarker' ],
'c' => [ '#99ff99', 'foswikiDiffChangedText' ],
'u' => [ '#ffffff', 'foswikiDiffUnchangedText' ],
'l' => [ '#eeeeee', 'foswikiDiffLineNumberHeader' ]
);
#SVEN - new design.
#main gets the info (NO MAJOR CHANGES NEEDED)
#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)
#so renderDiffs would get an array of [changeType, $oldstring, $newstring]
# corresponding to Algorithm::Diff's output
#renderDiffs iterates through the interpreted info and makes it into TML / HTML? (mmm)
#and can be over-ridden :)
#(now can we do this in a way that automagically can cope eith word / letter based diffs?)
#NOTE: if we do our own diffs in perl we can go straight to renderDiffs
#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.
#TODO: ***URGENT*** the diff rendering dies badly when you have table cell changes and context
#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...
#| Description: | renders a cell of data from a diff |
#| Parameter: =$data= | |
#| Parameter: =$topic= | |
#| Return: =$text= | Formatted html text |
#| TODO: | this should move to Render.pm |
sub _renderCellData {
my $this = shift;
my ( $data, $topicObject ) = @_;
my $app = $this->app;
if ($data) {
# SMELL: assumption about storage of meta-data embedded in topic
# text
$data =~ s/^%META:FIELD\{(.*)\}%.*$/
_renderAttrs($1, '|*FORM FIELD $title*|$name|$value|')/gem;
$data =~ s/^%META:([A-Z]+)\{(.*)\}%$/
'|*META '.$1.'*|'._renderAttrs($2).'||'/gem;
if ( Foswiki::Func::getContext()->{'TablePluginEnabled'} ) {
$data = "\n"
. '%TABLE{summary="'
. $app->i18n->maketext('Topic data')
. '" tablerules="all" databg="#ffffff" headeralign="left"}%'
. "\n"
. $data;
}
$data = $topicObject->expandMacros($data);
$data = $topicObject->renderTML($data);
# Match up table tags, remove comments
if ( $data =~ m/<\/?(th|td|table)\b/i ) {
# data has <th> or <td>, need to fix ables
my $bTable = ( $data =~ s/(<table)/$1/gis ) || 0;
my $eTable = ( $data =~ s/(<\/table)/$1/gis ) || 0;
while ( $eTable < $bTable ) {
$data .= CGI::end_table();
$eTable++;
}
while ( $bTable < $eTable ) {
$data = CGI::start_table() . $data;
$bTable++;
}
unless ($bTable) {
$data = CGI::start_table() . $data . CGI::end_table();
}
}
# unhide html comments (<!-- --> type tags)
$data =~ s/<!--(.*?)-->/<pre><--$1--><\/pre>/gs;
}
return $data;
}
# Simple method to expand attribute values in a format string
sub _renderAttrs {
my ( $p, $f ) = @_;
require Foswiki::Attrs;
my $attrs = new Foswiki::Attrs($p);
require Foswiki::Store;
if ($f) {
for my $key ( keys %$attrs ) {
my $av = Foswiki::Meta::dataDecode( $attrs->{$key} );
$f =~ s/\$$key\b/$av/g;
}
}
else {
$f = $attrs->stringify();
}
return $f;
}
sub _sideBySideRow {
my ( $left, $right, $lc, $rc ) = @_;
my $d1 = CGI::td(
{
bgcolor => $format{$lc}[0],
class => $format{$lc}[1],
valign => 'top'
},
$left . ' '
);
my $d2 = CGI::td(
{
bgcolor => $format{$rc}[0],
class => $format{$rc}[1],
valign => 'top'
},
$right . ' '
);
return CGI::Tr( {}, $d1 . $d2 );
}
#| Description: | render the Diff entry using side by side |
#| Parameter: =$diffType= | {+,-,u,c,l} denotes the patch operation |
#| Parameter: =$left= | the text blob before the opteration |
#| Parameter: =$right= | the text after the operation |
#| Return: =$result= | Formatted html text |
#| TODO: | this should move to Render.pm |
sub _renderSideBySide {
my $this = shift;
my ( $topicObject, $diffType, $left, $right ) = @_;
my $app = $this->app;
my $result = '';
$left = $this->_renderCellData( $left, $topicObject );
$right = $this->_renderCellData( $right, $topicObject );
if ( $diffType eq '-' ) {
$result .= _sideBySideRow( $left, $right, '-', 'u' );
}
elsif ( $diffType eq "+" ) {
$result .= _sideBySideRow( $left, $right, 'u', '+' );
}
elsif ( $diffType eq "u" ) {
$result .= _sideBySideRow( $left, $right, 'u', 'u' );
}
elsif ( $diffType eq "c" ) {
$result .= _sideBySideRow( $left, $right, 'c', 'c' );
}
elsif ( $diffType eq "l" && $left ne '' && $right ne '' ) {
$result .= CGI::Tr(
{
bgcolor => $format{l}[0],
class => $format{l}[1],
},
CGI::th( ( $app->i18n->maketext( 'Line: [_1]', $left ) ) )
. CGI::th( ( $app->i18n->maketext( 'Line: [_1]', $right ) ) )
);
}
# unhide html comments (<!-- --> type tags)
$result =~ s/<!--(.*?)-->/<pre><--$1--><\/pre>/gs;
return $result;
}
#| Description: | render the Diff array (no TML conversion) |
#| Parameter: =$diffType= | {+,-,u,c,l} denotes the patch operation |
#| Parameter: =$left= | the text blob before the opteration |
#| Parameter: =$right= | the text after the operation |
#| Return: =$result= | Formatted html text |
#| TODO: | this should move to Render.pm |
sub _renderDebug {
my ( $diffType, $left, $right ) = @_;
my $result = '';
#de-html-ize
$left =~ s/&/&/g;
$left =~ s/</</g;
$left =~ s/>/>/g;
$right =~ s/&/&/g;
$right =~ s/</</g;
$right =~ s/>/>/g;
$result = CGI::Tr( {}, CGI::td( {}, 'type: ' . $diffType ) );
my %classMap = (
'+' => ['foswikiDiffAddedText'],
'-' => ['foswikiDiffDeletedText'],
'c' => ['foswikiDiffChangedText'],
'u' => ['foswikiDiffUnchangedText'],
'l' => ['foswikiDiffLineNumberHeader']
);
my $styleClass = ' ' . $classMap{$diffType}[0] || '';
my $styleClassLeft = ( $diffType ne 'c' ) ? $styleClass : '';
my $styleClassRight = $styleClass;
if ( $diffType ne '+' ) {
$result .= CGI::Tr(
{ class => 'foswikiDiffDebug' },
CGI::td(
{ class => 'foswikiDiffDebugLeft ' . $styleClassLeft },
CGI::div( {}, $left )
)
);
}
if ( ( $diffType ne '-' ) && ( $diffType ne 'l' ) ) {
$result .= CGI::Tr(
{ class => 'foswikiDiffDebug' },
CGI::td(
{ class => 'foswikiDiffDebugRight ' . $styleClassRight },
CGI::div( {}, $right )
)
);
}
# unhide html comments (<!-- --> type tags)
$result =~ s/<!--(.*?)-->/<pre><--$1--><\/pre>/gs;
return $result;
}
sub _sequentialRow {
my $this = shift;
my ( $bg, $hdrcls, $bodycls, $data, $code, $char ) = @_;
my $app = $this->app;
my $row = '';
if ($char) {
$row = CGI::td(
{
bgcolor => $format{$code}[0],
class => $format{$code}[1],
valign => 'top',
width => "1%"
},
$char . CGI::br() . $char
);
}
else {
$row = CGI::td( { class => 'foswikiDiffUnchangedMarker', }, ' ' );
}
$row .= CGI::td( { class => "foswikiDiff${bodycls}Text" }, $data );
$row = CGI::Tr( {}, $row );
if ($bg) {
return CGI::Tr(
{},
CGI::td(
{
bgcolor => $bg,
class => "foswikiDiff${hdrcls}Header",
colspan => 9
},
CGI::b( {}, $app->i18n->maketext($hdrcls) . ': ' )
)
) . $row;
}
else {
return $row;
}
}
#| Description: | render the Diff using old style sequential blocks |
#| Parameter: =$diffType= | {+,-,u,c,l} denotes the patch operation |
#| Parameter: =$left= | the text blob before the opteration |
#| Parameter: =$right= | the text after the operation |
#| Return: =$result= | Formatted html text |
#| TODO: | this should move to Render.pm |
sub _renderSequential {
my $this = shift;
my ( $topicObject, $diffType, $left, $right ) = @_;
my $app = $this->app;
my $result = '';
#note: I have made the colspan 9 to make sure that it spans all columns (thought there are only 2 now)
if ( $diffType eq '-' ) {
$result .=
$this->_sequentialRow( '#FFD7D7', 'Deleted', 'Deleted',
$this->_renderCellData( $left, $topicObject ),
'-', '<' );
}
elsif ( $diffType eq '+' ) {
$result .=
$this->_sequentialRow( '#D0FFD0', 'Added', 'Added',
$this->_renderCellData( $right, $topicObject ),
'+', '>' );
}
elsif ( $diffType eq 'u' ) {
$result .=
$this->_sequentialRow( undef, 'Unchanged', 'Unchanged',
$this->_renderCellData( $right, $topicObject ),
'u', '' );
}
elsif ( $diffType eq 'c' ) {
$result .=
$this->_sequentialRow( '#D0FFD0', 'Changed', 'Deleted',
$this->_renderCellData( $left, $topicObject ),
'-', '<' );
$result .=
$this->_sequentialRow( undef, 'Changed', 'Added',
$this->_renderCellData( $right, $topicObject ),
'+', '>' );
}
elsif ( $diffType eq 'l' && $left ne '' && $right ne '' ) {
$result .= CGI::Tr(
{
bgcolor => $format{l}[0],
class => 'foswikiDiffLineNumberHeader'
},
CGI::th(
{ colspan => 9 },
( $app->i18n->maketext( 'Line: [_1] to [_2]', $left, $right ) )
)
);
}
# unhide html comments (<!-- --> type tags)
$result =~ s/<!--(.*?)-->/<pre><--$1--><\/pre>/gs;
return $result;
}
#| Description: | uses renderStyle to choose the rendering function to use |
#| Parameter: =$diffArray= | array generated by parseRevisionDiff |
#| Parameter: =$renderStyle= | style of rendering { debug, sequential, sidebyside} |
#| Return: =$text= | output html for one renderes revision diff |
#| TODO: | move into Render.pm |
sub _renderRevisionDiff {
my $this = shift;
my ( $topicObject, $sdiffArray_ref, $renderStyle ) = @_;
#combine sequential array elements that are the same diffType
my @diffArray = ();
foreach my $ele (@$sdiffArray_ref) {
if ( ( @$ele[1] =~ m/^\%META\:TOPICINFO/ )
|| ( @$ele[2] =~ m/^\%META\:TOPICINFO/ ) )
{
# do nothing, ignore redundant topic info
# FIXME: Intelligently remove followup lines in case META:TOPICINFO is the only change
}
elsif ((@diffArray)
&& ( @{ $diffArray[$#diffArray] }[0] eq @$ele[0] ) )
{
@{ $diffArray[$#diffArray] }[1] .= "\n" . @$ele[1];
@{ $diffArray[$#diffArray] }[2] .= "\n" . @$ele[2];
}
else {
# Store doesn't expand REVINFO and we don't have rev info available now; escape tags to avoid confusion
@$ele[1] =~ s/\%REVINFO/\%<nop>REVINFO/
unless $renderStyle eq 'debug';
@$ele[2] =~ s/\%REVINFO/\%<nop>REVINFO/
unless $renderStyle eq 'debug';
push @diffArray, $ele;
}
}
my $diffArray_ref = \@diffArray;
my $result = "";
my $data = '';
my $diff_ref = undef;
for my $next_ref (@$diffArray_ref) {
if ( ( @$next_ref[0] eq 'l' )
&& ( @$next_ref[1] eq 0 )
&& ( @$next_ref[2] eq 0 ) )
{
next;
}
if ( !$diff_ref ) {
$diff_ref = $next_ref;
next;
}
if ( ( @$diff_ref[0] eq '-' ) && ( @$next_ref[0] eq '+' ) ) {
$diff_ref = [ 'c', @$diff_ref[1], @$next_ref[2] ];
$next_ref = undef;
}
if ( $renderStyle eq 'sequential' ) {
$result .= $this->_renderSequential( $topicObject, @$diff_ref );
}
elsif ( $renderStyle eq 'sidebyside' ) {
$result .= CGI::Tr(
{},
CGI::td( { width => '50%' }, '' ),
CGI::td( { width => '50%' }, '' )
);
$result .= $this->_renderSideBySide( $topicObject, @$diff_ref );
}
elsif ( $renderStyle eq 'debug' ) {
$result .= _renderDebug(@$diff_ref);
}
$diff_ref = $next_ref;
}
#don't forget the last one ;)
if ($diff_ref) {
if ( $renderStyle eq 'sequential' ) {
$result .= $this->_renderSequential( $topicObject, @$diff_ref );
}
elsif ( $renderStyle eq 'sidebyside' ) {
$result .= CGI::Tr(
{},
CGI::td( { width => '50%' }, '' ),
CGI::td( { width => '50%' }, '' )
);
$result .= $this->_renderSideBySide( $topicObject, @$diff_ref );
}
elsif ( $renderStyle eq 'debug' ) {
$result .= _renderDebug(@$diff_ref);
}
}
return CGI::table(
{
class => 'foswikiDiffTable',
summary => 'changes to ' . $topicObject->topic,
width => '100%',
cellspacing => 0,
cellpadding => 0
},
$result
);
}
=begin TML
---++ ObjectMethod diff( )
=diff= command handler.
This method is designed to be
invoked via the =UI::run= method.
Renders the differences between version of a topic
| topic | topic that we are showing the differences of |
| rev1 | the higher revision |
| rev2 | the lower revision |
| render | the rendering style {sequential, sidebyside, raw, debug} | (preferences) DIFFRENDERSTYLE, =sequential= |
| type | {history, diff, last} history diff, version to version, last version to previous | =history= |
| context | number of lines of context |
| skin | the skin(s) to use to display the diff |
TODO:
* add a {word} render style
* move the common CGI param handling to one place
* move defaults somewhere
=cut
sub diff {
my $this = shift;
my $app = $this->app;
my $req = $app->request;
my $web = $req->web;
my $topic = $req->topic;
$this->checkWebExists( $web, 'diff' );
$this->checkTopicExists( $web, $topic, 'diff' );
my $topicObject =
$this->create( 'Foswiki::Meta', web => $web, topic => $topic );
my $renderStyle =
$req->param('render')
|| $app->prefs->getPreference('DIFFRENDERSTYLE')
|| 'sequential';
my $diffType = $req->param('type') || 'history';
my $contextLines = $req->param('context');
unless ( defined $contextLines ) {
$app->prefs->getPreference('DIFFCONTEXTLINES');
$contextLines = 3 unless defined $contextLines;
}
my $revHigh = Foswiki::Store::cleanUpRevID( scalar( $req->param('rev1') ) );
my $revLow = Foswiki::Store::cleanUpRevID( scalar( $req->param('rev2') ) );
my $tmpl = $app->templates->readTemplate('rdiff');
$tmpl =~ s/\%META\{.*?\}\%//g; # remove %META{'parent'}%
# The template is split by up to 4 %REPEAT% tags. The sections are:
# $before - text before any output
# $difftmpl - template for a single diff
# $after - text after the diffs
# tail - appears to generate revision info for each of the
# displayed revisions, but not sure - looks like a legacy thing, it's
# not used in any of the existing templates.
my ( $before, $difftmpl, $after, $tail ) = split( /%REPEAT%/, $tmpl, 4 );
$before ||= '';
$after ||= '';
$tail ||= '';
my $revIt = $topicObject->getRevisionHistory();
my @history = $revIt->all(); # most recent rev first
my ( $olderi, $neweri ); # indexes into history
if ( $diffType eq 'last' ) {
$neweri = 0;
$olderi = ( scalar(@history) > 1 ) ? $neweri + 1 : 0;
}
else {
for ( my $i = 0 ; $i <= $#history ; $i++ ) {
$neweri = $i if ( $history[$i] == $revHigh );
$olderi = $i if ( $history[$i] == $revLow );
last if ( defined $olderi && defined $neweri );
}
$neweri = 0 unless defined $neweri;
$olderi = $#history unless defined $olderi;
}
my $revTitleHigh = $history[$neweri];
my $revTitleLow = ( $olderi != $neweri ) ? $history[$olderi] : '';
# Limit the total number of diffs to avoid DoS
my $step =
int(
( $olderi - $neweri ) / $app->cfg->data->{MaxRevisionsInADiff} + 0.5 );
$step = 1 if $step < 1;
$before =~ s/%REVTITLE1%/$revTitleHigh/g;
$before =~ s/%REVTITLE2%/$revTitleLow/g;
$before = $topicObject->expandMacros($before);
$before = $topicObject->renderTML($before);
my $page = $before;
# do one or more diffs
$difftmpl = $topicObject->expandMacros($difftmpl);
my $rNewer = $neweri;
my $rOlder = $olderi;
my $isMultipleDiff = 0;
if ( $diffType eq 'history' && $olderi > $neweri + 1 ) {
$rOlder = $neweri + $step;
$isMultipleDiff = 1;
}
# If we are applying control to the raw view:
if ( $renderStyle eq 'debug'
&& defined $app->cfg->data->{FeatureAccess}{AllowRaw}
&& $app->cfg->data->{FeatureAccess}{AllowRaw} ne 'all' )
{
if ( $app->cfg->data->{FeatureAccess}{AllowRaw} eq 'authenticated' ) {
Foswiki::AccessControlException->throw(
mode => 'authenticated',
user => $app->user,
web => $web,
topic => $topic,
reason => $Foswiki::Meta::reason
) unless $app->inContext("authenticated");
}
else {
$this->checkAccess( 'RAW', $topicObject )
unless $topicObject->haveAccess('CHANGE');
}
}
# If we are applying control to the revisions:
if ( defined $app->cfg->data->{FeatureAccess}{AllowHistory}
&& $app->cfg->data->{FeatureAccess}{AllowHistory} ne 'all' )
{
if ( $app->cfg->data->{FeatureAccess}{AllowHistory} eq 'authenticated' )
{
Foswiki::AccessControlException->throw(
mode => 'authenticated',
user => $app->user,
web => $web,
topic => $topic,
reason => $Foswiki::Meta::reason
) unless $app->inContext("authenticated");
}
else {
$this->checkAccess( 'HISTORY', $topicObject );
}
}
my %toms;
do {
last if ( $rOlder > $#history );
my $rHigh = $history[$rNewer];
my $rLow = $history[$rOlder];
# Load the revs being diffed
$toms{$rHigh} =
Foswiki::Meta->load( $app, $topicObject->web, $topicObject->topic,
$rHigh )
unless $toms{$rHigh};
ASSERT(
$toms{$rHigh}->getLoadedRev() == $rHigh,
$toms{$rHigh}->getLoadedRev() . " == $rHigh"
) if DEBUG;
$toms{$rLow} =
Foswiki::Meta->load( $app, $topicObject->web, $topicObject->topic,
$rLow )
unless $toms{$rLow};
ASSERT(
$toms{$rLow}->getLoadedRev() == $rLow,
$toms{$rLow}->getLoadedRev() . " == $rLow"
) if DEBUG;
my $diff = $difftmpl;
$diff =~ s/%REVTITLE1%/$rHigh/g;
$diff =~ s/%REVTITLE2%/$rLow/g;
my $rInfo = '';
my $rInfo2 = '';
my $text;
if ( $rHigh > $rLow + 1 ) {
$rInfo = $app->i18n->maketext( "Changes from r[_1] to r[_2]",
$rLow, $rHigh );
}
else {
$rInfo =
$app->renderer->renderRevisionInfo( $topicObject, $rHigh,
'$date - $wikiusername' );
$rInfo2 =
$app->renderer->renderRevisionInfo( $topicObject, $rHigh,
'$rev ($date - $time) - $wikiusername' );
}
# eliminate white space to prevent wrap around in HR table:
$rInfo =~ s/\s+/ /g;
$rInfo2 =~ s/\s+/ /g;
# Check access rights
my $rd;
if ( !$toms{$rHigh}->haveAccess() ) {
$rd = [ [ '-', " *Revision $rHigh is unreadable* ", '' ] ];
if ( !$toms{$rLow}->haveAccess() ) {
push( @$rd, [ '+', '', " *Revision $rLow is unreadable* " ] );
}
else {
foreach ( split( "\n", $rLow ) ) {
push( @$rd, [ '+', '', $_ ] );
}
}
}
elsif ( !$toms{$rLow}->haveAccess() ) {
$rd = [ [ '+', '', " *Revision $rLow is unreadable* " ] ];
foreach ( split( "\n", $rHigh ) ) {
push( @$rd, [ '-', $_, '' ] );
}
}
else {
$rd = $toms{$rLow}->getDifferences( $rHigh, $contextLines );
}
$text = $this->_renderRevisionDiff( $topicObject, $rd, $renderStyle );
$diff =~ s/%REVINFO1%/$rInfo/g;
$diff =~ s/%REVINFO2%/$rInfo2/g;
$diff =~ s/%TEXT%/$text/g;
$page .= $diff;
$rNewer += $step;
$rOlder += $step;
$rOlder = $#history if $rOlder > $#history;
} while ( $diffType eq 'history' && $rNewer < $olderi );
$app->logger->log(
{
level => 'info',
action => 'rdiff',
webTopic => $web . '.' . $topic,
extra => "$revHigh $revLow"
}
);
# Generate the revisions navigator
my $viewObj = $this->create('Foswiki::UI::View');
my $revisions =
$viewObj->revisionsAround( $topicObject,
$history[$neweri], $history[$neweri], $history[0] );
my $tailResult = '';
if ( defined $tail ) {
# SMELL: made this conditional as it doesn't seem to be used
# Generate information about each of the revs shown
my $i = $neweri;
my $revTitle = '';
while ( $i <= $olderi ) {
last if ( $i > $#history );
my $n = $history[$i];
$revTitle = CGI::a(
{
href => $app->cfg->getScriptUrl(
0, 'view', $web, $topic, rev => $n
),
rel => 'nofollow'
},
$i
);
my $revInfo =
$app->renderer->renderRevisionInfo( $topicObject, undef, $n );
$tailResult .= $tail;
$tailResult =~ s/%REVTITLE%/$revTitle/g;
$tailResult =~ s/%REVINFO%/$revInfo/g;
$i += $step;
}
}
$after =~ s/%TAIL%/$tailResult/g; # SMELL: unused in templates
$after =~ s/%REVISIONS%/$revisions/g;
$after =~ s/%CURRREV%/$revHigh/g;
$after =~ s/%MAXREV%/$history[0]/g;
$after = $topicObject->expandMacros($after);
$after = $topicObject->renderTML($after);
$page .= $after;
$app->writeCompletePage($page);
return;
}
1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2010 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Additional copyrights apply to some or all of the code in this
file as follows:
Copyright (C) 1999-2007 TWiki Contributors. All Rights Reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. For
more details read LICENSE in the root of this distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
As per the GPL, removal of this notice is prohibited.