Skip to content

Commit

Permalink
Item9464: Implement token $change(-n)
Browse files Browse the repository at this point in the history
Relative revision offset for changes summary.
  • Loading branch information
gac410 committed Dec 14, 2017
1 parent 7e4ec96 commit 1e31698
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
38 changes: 38 additions & 0 deletions UnitTestContrib/test/unit/Fn_SEARCH.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6220,6 +6220,19 @@ FOO <nop>$this->{test_web}.RevTopic
EXP
$this->assert_equals( $expected, $result );

#Simple $changes - compare Rev 2 - Rev 3 (using -1)
$result = $this->{test_topicObject}->expandMacros(
'%SEARCH{"1"
type="query"
web="%WEB%"
topic="RevTopic"
nonoise="on"
format="FOO $changes(-1)$n"
}%'
);

$this->assert_equals( $expected, $result );

#$changes(1) - compare Rev 1 - Rev 3
$result = $this->{test_topicObject}->expandMacros(
'%SEARCH{"1"
Expand All @@ -6238,6 +6251,31 @@ FOO <nop>$this->{test_web}.RevTopic
EXP
$this->assert_equals( $expected, $result );

#$changes(-2) - compare Rev 1 - Rev 3
$result = $this->{test_topicObject}->expandMacros(
'%SEARCH{"1"
type="query"
web="%WEB%"
topic="RevTopic"
nonoise="on"
format="FOO $changes(-2)$n"
}%'
);

$this->assert_equals( $expected, $result );

#$changes(-42) - compare Rev 1 - Rev 3
$result = $this->{test_topicObject}->expandMacros(
'%SEARCH{"1"
type="query"
web="%WEB%"
topic="RevTopic"
nonoise="on"
format="FOO $changes(-42)$n"
}%'
);
$this->assert_equals( $expected, $result );

#$changes() - undef rev, generate a summary
$result = $this->{test_topicObject}->expandMacros(
'%SEARCH{"1"
Expand Down
3 changes: 2 additions & 1 deletion core/data/System/FormattedSearch.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" date="1443185186" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" date="1513215936" format="1.1" version="1"}%
%META:TOPICPARENT{name="UserDocumentationCategory"}%
---+ Formatted Search
Customize the display of search results.
Expand Down Expand Up @@ -101,6 +101,7 @@ Format tokens that can be used in the format string:
| =$summary(searchcontext, 50)= | Creates a topic summary with the search terms highlighted, up to 50 characters |
| =$changes= | Summary of changes between latest rev and previous rev |
| =$changes(n)= | Summary of changes between latest rev and rev n |
| =$changes(-n)= | Summary of changes between latest rev and rev -n |
| =$formname= | The name of the form attached to the topic; empty if none |
| =$formfield(name)= | The field value of a form field; for example, if FAQWhatIsWikiWiki was a search hit, =$formfield(<nop>TopicClassification)= would get expanded to =%QUERY{"'WhatIsWikiWiki'/TopicClassification"}%=. This applies only to topics that have a [[DataForms][DataForm]]. For multi-line textfields new lines are replaced by the value of the =newline= parameter if it is defined, otherwise by an HTML &lt;br /&gt; |
| =$formfield(name, 10)= | Form field value, "<tt>- </tt>" hyphenated every 10 characters |
Expand Down
9 changes: 7 additions & 2 deletions core/lib/Foswiki/Meta.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3580,6 +3580,7 @@ sub _summariseTextWithSearchContext {
Generate a (max 3 line) summary of the differences between the revs.
* =$orev= - older rev, if not defined will use ($nrev - 1)
* - $orev can also be an offset (-n) from current rev.
* =$nrev= - later rev, if not defined defaults to latest
* =$tml= - if true will generate renderable TML (i.e. HTML with NOPs.
If false will generate a summary suitable for use in plain text
Expand Down Expand Up @@ -3607,10 +3608,14 @@ sub summariseChanges {

$orev = $nrev - 1 unless defined($orev);

ASSERT( $orev =~ m/^\s*\d+\s*/ ) if DEBUG; # looks like a number
ASSERT( $orev >= 0 ) if DEBUG;
ASSERT( $orev =~ m/^\s*-?\d+\s*/ ) if DEBUG; # looks like a number
ASSERT( $nrev >= $orev ) if DEBUG;

if ( $orev =~ m/\s*-(\d+)\s*/ ) {
my $offset = $1;
$orev = ( $offset < $nrev ) ? $nrev - $offset : 1;
}

unless ( defined $this->{_loadedRev} && $this->{_loadedRev} eq $nrev ) {
$this = $this->load($nrev);
}
Expand Down
5 changes: 5 additions & 0 deletions core/lib/Foswiki/Search.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1304,10 +1304,15 @@ s/\$formfield\(\s*([^\)]*)\s*\)/displayFormField( $item, $1, $newLine )/ges;
if ( defined( $item->topic ) ) {
$out =~ s/\$summary(?:\(([^\)]*)\))?/
$item->summariseText( $1, $text, $searchOptions )/ges;

#summariseChanges( $olderrev, $newerrev, $tml, $nochecks) -> $text
$out =~
s/\$changes(?!\()/$item->summariseChanges(undef,$revNum)/ges;
$out =~ s/\$changes(?:\((-[0-9]+)\))/
$item->summariseChanges($1, $revNum)/ges;
$out =~ s/\$changes(?:\(([^\)]*)\))/
$item->summariseChanges(Foswiki::Store::cleanUpRevID($1), $revNum)/ges;

$out =~ s/\$formfield\(\s*([^\)]*)\s*\)/
displayFormField( $item, $1, $newLine )/ges;
$out =~ s/\$parent\(([^\)]*)\)/
Expand Down

0 comments on commit 1e31698

Please sign in to comment.