Skip to content

Commit

Permalink
Item10443: added parameter =versions= as a more versatile alternative…
Browse files Browse the repository at this point in the history
… to =rev1=, =rev2=, =nrev= and =reverse= (that are still supported)

git-svn-id: http://svn.foswiki.org/trunk@11030 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
ArthurClemens authored and ArthurClemens committed Mar 13, 2011
1 parent 4d455b5 commit a3a4d9d
Show file tree
Hide file tree
Showing 4 changed files with 628 additions and 232 deletions.
1 change: 1 addition & 0 deletions HistoryPlugin/data/System/HistoryPlugin.txt
Expand Up @@ -62,6 +62,7 @@ __Note:__ You do not need to install anything on the browser to use this plugin.
| Version: | %$VERSION% |
| Release: | %$RELEASE% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 13 Mar 2011: | 1.9 Arthur Clemens: added parameter =versions= as a more versatile alternative to =rev1=, =rev2=, =nrev= and =reverse=. |
| 13 Mar 2011: | 1.8 Arthur Clemens: fix rendering of =REVINFO= date and time parameters; add unit tests. |
| 27 Dec 2010: | 1.7 Arthur Clemens: update of screen layout. |
| 31 Jul 2010: | 1.6 Paul Harvey: Foswikitask:Item9415 - Documentation updates |
Expand Down
42 changes: 29 additions & 13 deletions HistoryPlugin/data/System/VarHISTORY.txt
Expand Up @@ -8,23 +8,39 @@
%TABLE{tablewidth="100%" sort="off" headerbg="#f5f5f5" databg="#ffffff" headercolor="#333333"}%
| *Argument* | *Description* | *Default&nbsp;value* |
| none | Default layout: a simple list of topic revisions using the default format (see below) | |
| ="format"= or =format="format"= | Format of one line, may include any variable which is supported by macro [[%SYSTEMWEB%.VarREVINFO][REVINFO]] | <code>"r$rev - $date - $wikiusername"</code> |
| =topic="topic"= |Topic name | current topic |
| =web="web"= |Web name | current web |
| =nrev="nrev"= |Number of revisions to show. Ignored if both =rev1= and =rev2= are specified. | Plugin preference variable =NREV= |
| =rev2="rev2"= |Newest revision to show | =rev1+nrev= if =rev1= is specified, latest revision otherwise |
| =rev1="rev1"= |Oldest revision to show | =rev2-nrev= |
| =reverse="on/off"= |Show newest revisions first, if =on= | ="on"= |
| =header="text"= |Text to print before the list. May contain the variables =$next= and =$previous= (see below) | ="$next"= |
| =footer="text"= |Text to print after the list. May contain the variables =$next= and =$previous= (see below) | ="$previous"= |
| ="format"= or =format="string"= | Format of one line, may include any variable which is supported by macro [[%SYSTEMWEB%.VarREVINFO][REVINFO]] | <code>"r$rev - $date - $wikiusername"</code> |
| =topic="topic"= | Topic name, can be in =web.topic= format | current topic |
| =web="web"= | Web name | current web |
| =versions="number or range"= | Number or range (format: =from..to=). Examples: %BR% \
To get version 2, write: =versions="2"= %BR% \
To get version 2 to 3, write: =versions="2..3"= %BR% \
To get version 2 to the latest, write: =versions="2.."= %BR% \
To get all versions up to version 5, write: =versions="..5"= %BR% \
To get all versions up to but not including the latest, write: =versions="..-1"= %BR% \
To get the versions from 1 to 5 in reverse order, write: =versions="5..1"= \
| all versions in the order latest to first |
| =header="text"= | Text to print before the list. %BR% \
May contain the tokens =$next= and =$previous= which will be evaluated if there are newer or older revisions available for the topic that are not listed according to =versions= (or =rev1=, =rev2=, =nrev=). %BR% \
These tokens take the syntax =$next{'some text' url='url'}= (the same for =$previous=). 'some text' is the text which should be printed, 'url' is the url for the corresponding link. %BR% \
The tokens =$rev1=, =$rev2=, =$nrev= in 'text' or 'url' will be replaced by appropriate values for the next or previous block of revisions. See the attached =oopshistory.tmpl= for an example of how to use this. | ="$next"= |
| =footer="text"= | Text to print after the list. May contain the tokens =$next= and =$previous= (see =header=) | ="$previous"= |

The parameters _header_ and _footer_ may contain the variables $next and $previous, which will only be evaluated, if there are newer or older revisions available for the topic which are not listed according to _rev1_, _rev2_, _nrev_. These variables take the syntax =$next{'text' url='url'}= (analog for $previous). _text_ is the text which should be printed, _url_ is the url for a corresponding link. The variables $rev1, $rev2, $nrev in _text_ or _url_ will be replaced by appropriate values for the next or previous block of revisions. See the attached =oopshistory.tmpl= for an example of how to use this.


Deprecated (but supported) parameters:
%TABLE{tablewidth="100%" sort="off" headerbg="#f5f5f5" databg="#ffffff" headercolor="#333333"}%
| *Argument* | *Description* | *Default&nbsp;value* |
| =nrev="number"= | Number of revisions to show. Ignored if =versions= is specified, or if both =rev1= and =rev2= are specified. | =10= |
| =rev2="number"= | Newest revision to show | =rev1+nrev= if =rev1= is specified, latest revision otherwise |
| =rev1="number"= | Oldest revision to show | =rev2-nrev= |
| =reverse="boolean"= |Show newest revisions first, if =on= | ="on"= |

The following variables are replaced only, if there is a corresponding %<nop>HISTORY% on the page. If more than
one %<nop>HISTORY% is used on the same page, the values from the last one will be used.
---+++ Additional macros
The following macros are replaced only if there is a corresponding =%<nop>HISTORY%= on the page. If more than one =%<nop>HISTORY%= is used on the same page, the values from the last one will be used.

* =%<nop>HISTORY_REV1%=: Oldest revision from the printed history
* =%<nop>HISTORY_REV2%=: Latest revision from the printed history
* =%<nop>HISTORY_NREV%=: Number of the printed revisions
* =%<nop>HISTORY_MAXREV%=: Latest available revision of the document
* =%<nop>HISTORY_MAXREV%=: Latest available revision of the topic

%ENDSECTION{"history_attributes"}%
116 changes: 78 additions & 38 deletions HistoryPlugin/lib/Foswiki/Plugins/HistoryPlugin.pm
Expand Up @@ -12,7 +12,7 @@ use Foswiki::AccessControlException ();
use vars qw( $VERSION $RELEASE $NO_PREFS_IN_TOPIC $SHORTDESCRIPTION);

$VERSION = '$Rev: 15950 $';
$RELEASE = '1.8';
$RELEASE = '1.9';
$NO_PREFS_IN_TOPIC = 1;
$SHORTDESCRIPTION = 'Shows a complete history of a topic';

Expand All @@ -36,42 +36,83 @@ sub handleHistory {

my $web = $params->{web} || $theWeb;
my $topic = $params->{topic} || $theTopic;
($web, $topic) = Foswiki::Func::normalizeWebTopicName($web, $topic);
( $web, $topic ) = Foswiki::Func::normalizeWebTopicName( $web, $topic );

# check topic exists
unless ( Foswiki::Func::topicExists( $web, $topic ) ) {
return "<noautolink><span class='foswikiAlert'>HistoryPlugin error: Topic $web.$topic does not exist</noautolink>";
return
"<noautolink><span class='foswikiAlert'>HistoryPlugin error: Topic $web.$topic does not exist</noautolink>";
}

# check access permissions
unless (Foswiki::Func::checkAccessPermission("VIEW", $session->{user}, undef, $topic, $web)) {
throw Foswiki::AccessControlException("VIEW", $session->{user},
$web, $topic, $Foswiki::Meta::reason );
unless (
Foswiki::Func::checkAccessPermission(
"VIEW", $session->{user}, undef, $topic, $web
)
)
{
throw Foswiki::AccessControlException( "VIEW", $session->{user}, $web,
$topic, $Foswiki::Meta::reason );
}


my $reverse = Foswiki::Func::isTrue( $params->{reverse}, 1 );

my $versions = $params->{versions};
my $versionStart;
my $versionEnd;
my $rev1;
my $rev2;
my $maxrev = ( Foswiki::Func::getRevisionInfo( $web, $topic ) )[2];
my $nrev;

$rev1 = $params->{rev1};
$rev1 =~ s/1\.// if $rev1;
$rev2 = $params->{rev2};
$rev2 =~ s/1\.// if $rev2;
$nrev = $params->{nrev} || 10;

$rev2 ||= $rev1 ? $rev1 + $nrev - 1 : $maxrev;
$rev1 ||= $rev2 - $nrev + 1;

( $rev1, $rev2 ) = ( $rev2, $rev1 ) if $rev1 > $rev2;
$rev1 = $maxrev if $rev1 > $maxrev;
$rev1 = 1 if $rev1 < 1;
$rev2 = $maxrev if $rev2 > $maxrev;
$rev2 = 1 if $rev2 < 1;

my $rev1 = $params->{rev1} ? $params->{rev1} : 1;
my $rev2 = $params->{rev2} ? $params->{rev2} : $maxrev;
my $nrev = $params->{nrev} ? $params->{nrev} : 10;

if ($versions) {
$versions =~ /([0-9\-]*)(\.\.)*([0-9\-]*)/;
if ( defined $1 && length $1 ) {
$rev1 = $1;
}
if ( defined $2 && length $2 ) {

# dots
$rev2 = $3 if ( defined $3 && length $3 );
}
else {
$rev2 = $rev1;
}

# wrap
$rev1 = $maxrev + $rev1 if $rev1 < 0;
$rev2 = $maxrev + $rev2 if $rev2 < 0;

# normalize
$rev1 = 1 if $rev1 == 0;
$rev2 = 1 if $rev2 == 0;
$rev1 = $maxrev if $rev1 > $maxrev;
$rev2 = $maxrev if $rev2 > $maxrev;
if ( $rev1 > $rev2 ) {
$reverse = 0;
( $rev1, $rev2 ) = ( $rev2, $rev1 );
}
}
else {

$rev1 =~ s/1\.// if $rev1;
$rev2 =~ s/1\.// if $rev2;

if ( defined $params->{rev1} || defined $params->{rev2} ) {
$rev2 ||= $rev1 ? $rev1 + $nrev - 1 : $maxrev;
$rev1 ||= $rev2 - $nrev + 1;
}
else {
$rev1 = ( $rev2 - $nrev ) + 1;
}

( $rev1, $rev2 ) = ( $rev2, $rev1 ) if $rev1 > $rev2;
$rev1 = $maxrev if $rev1 > $maxrev;
$rev1 = 1 if $rev1 < 1;
$rev2 = $maxrev if $rev2 > $maxrev;
$rev2 = 1 if $rev2 < 1;
}

my $format =
$params->{format}
|| $params->{_DEFAULT}
Expand All @@ -80,22 +121,19 @@ sub handleHistory {
$header = "\$next{'...'}%BR%" unless defined($header);
my $footer = $params->{footer};
$footer = "\$previous{'...'}" unless defined($footer);


Foswiki::Func::setPreferencesValue( "HISTORY_MAXREV", $maxrev );
Foswiki::Func::setPreferencesValue( "HISTORY_REV1", $rev1 );
Foswiki::Func::setPreferencesValue( "HISTORY_REV2", $rev2 );
Foswiki::Func::setPreferencesValue( "HISTORY_NREV", $nrev );

# Start the output
my $out = handleHeadFoot( $header, $rev1, $rev2, $nrev, $maxrev );
my $out = _handleHeadFoot( $header, $rev1, $rev2, $nrev, $maxrev );

# Print revision info

my @revs = ( $rev1 .. $rev2 );

my $reverse = $params->{reverse} || 1;
$reverse = 0 if $reverse =~ /off|no/i;
@revs = reverse(@revs) if $reverse;
my $mixedAlphaNum = Foswiki::Func::getRegularExpression('mixedAlphaNum');
my $checkFlag = 0;
Expand All @@ -118,7 +156,8 @@ sub handleHistory {
$revinfo =~ s/\$topic/$topic/g;
$revinfo =~ s/\$rev/$rev/g;
$revinfo =~ s/\$date/Foswiki::Func::formatTime($date)/ge;
$revinfo =~ s/\$(year|ye|week|web|wday|tz|topic|time|seconds|rev|rcs|month|mo|minutes|longdate|isotz|iso|http|hours|epoch|email|dow|day)/_formatTime("\$$1", $topic, $web)/ge;
$revinfo =~
s/\$(year|ye|week|web|wday|tz|topic|time|seconds|rev|rcs|month|mo|minutes|longdate|isotz|iso|http|hours|epoch|email|dow|day)/_formatTime("\$$1", $topic, $web)/ge;
$revinfo =~ s/\$username/$user/g;
$revinfo =~ s/\$wikiname/$wikiName/g;
$revinfo =~ s/\$wikiusername/$wikiUserName/g;
Expand All @@ -132,19 +171,20 @@ sub handleHistory {

$rev--;
}
$out .= handleHeadFoot( $footer, $rev1, $rev2, $nrev, $maxrev );
$out .= _handleHeadFoot( $footer, $rev1, $rev2, $nrev, $maxrev );
$out = Foswiki::Func::decodeFormatTokens($out);

return $out;
}

sub _formatTime {
my ($format, $topic, $web) = @_;

return Foswiki::Func::expandCommonVariables('%REVINFO{"' . $format . '"}%', $topic, $web);
my ( $format, $topic, $web ) = @_;

return Foswiki::Func::expandCommonVariables( '%REVINFO{"' . $format . '"}%',
$topic, $web );
}

sub handleHeadFoot {
sub _handleHeadFoot {

my ( $text, $rev1, $rev2, $nrev, $maxrev ) = @_;

Expand Down

0 comments on commit a3a4d9d

Please sign in to comment.