Skip to content

Commit

Permalink
Item351: Rebranding CompareRevisionsAddOn
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@1075 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
KennethLavrsen authored and KennethLavrsen committed Nov 30, 2008
1 parent 14bb0a8 commit babc841
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 64 deletions.
Expand Up @@ -7,7 +7,7 @@ This add-on compares the renderd HTML output of two revisions and shows the diff

---++ Description

The !CompareRevisionsAddOn compares two revisions of a document, like _rdiff_ does. But in contrast to normal _rdiff_, the comparison is done with the rendered HTML output of the revisions instead of the TWiki source text files. (This feature was proposed by many of our users, who found the normal _rdiff_ output too technical - even with the _sidebyside_ option - and wanted to see
The !CompareRevisionsAddOn compares two revisions of a document, like _rdiff_ does. But in contrast to normal _rdiff_, the comparison is done with the rendered HTML output of the revisions instead of the Foswiki source text files. (This feature was proposed by many of our users, who found the normal _rdiff_ output too technical - even with the _sidebyside_ option - and wanted to see
differences in the content of the page).

Furthermore, the differences between the revisions are shown as close as possible. If necessary, this means that different words are marked instead of whole lines or even paragraphs.
Expand Down Expand Up @@ -115,7 +115,7 @@ and ==twikiCompareChange2== are defined with a light green background.

---++ Add-On Installation Instructions

__Note:__ You do not need to install anything on the browser to use this add-on. The following instructions are for the administrator who installs the add-on on the server where TWiki is running.
__Note:__ You do not need to install anything on the browser to use this add-on. The following instructions are for the administrator who installs the add-on on the server where Foswiki is running.

* This script needs some additional Perl modules.
If necessary, download and install the required perl modules from [[http://www.cpan.org][CPAN]].
Expand All @@ -128,21 +128,21 @@ __Note:__ You do not need to install anything on the browser to use this add-on.
* [[http://cpan.uwinnipeg.ca/module/HTML::Tree][HTML::Tree]] (with HTML::TreeBuilder and HTML::Element). These modules in turn need
* [[http://cpan.uwinnipeg.ca/module/HTML::Parser][HTML::Parser]]
* [[http://cpan.uwinnipeg.ca/module/HTML::Tagset][HTML::Tagset]]
* Algorithm::Diff (which is included in the standard TWiki installation
* Algorithm::Diff (which is included in the standard Foswiki installation
* Download the [[%ATTACHURL%/CompareRevisionsAddOn.zip][ZIP file]] from the Add-on Home (see below)
* Unzip ==%TOPIC%.zip== in your twiki installation directory. Content:
| *File:* | *Description:* |
| ==data/TWiki/%TOPIC%.txt== | Add-on topic |
| ==data/System/%TOPIC%.txt== | Add-on topic |
| ==bin/compare== | Add-on script |
| ==lib/TWiki/UI/Compare.pm== | Perl package used by the script |
| ==lib/Foswiki/UI/Compare.pm== | Perl package used by the script |
| ==templates/compare.tmpl== | Template for side-by-side output |
| ==templates/compare.pattern.tmpl== | Same for pattern skin |
| ==templates/interweave.tmpl== | Template for interwoven output |
| ==templates/interweave.pattern.tmpl== | Same for pattern skin |
| ==lib/Foswiki/Plugins/CompareRevisionsAddonPlugin.pm== | Helper plugin |
| ==data/TWiki/CompareRevisionsAddonPlugin.txt== | Plugin topic |
| ==pub/TWiki/CompareRevisionsAddOn/interweaved.png== | Interwoven screenshot |
| ==pub/TWiki/CompareRevisionsAddOn/sidebyside.png== | Side-by-side screenshot |
| ==data/System/CompareRevisionsAddonPlugin.txt== | Plugin topic |
| ==pub/System/CompareRevisionsAddOn/interweaved.png== | Interwoven screenshot |
| ==pub/System/CompareRevisionsAddOn/sidebyside.png== | Side-by-side screenshot |
| ==data/Sandbox/CompareRevisionsAddOnDemoTopic.txt== | Demonstration topic |
| ==data/Sandbox/CompareRevisionsAddOnDemoTopic.txt,v== | Demonstration topic history |

Expand Down
@@ -1,7 +1,7 @@
%META:TOPICINFO{author="ProjectContributor" date="1144607735" format="1.1" version="1.1"}%
---+ !CompareRevisionsAddOn Plugin

This is an helper plugin for the CompareRevisionsAddOn on TWiki 4.
This is an helper plugin for the CompareRevisionsAddOn on Foswiki

It has two purposes:
1 It sets the =CompareRevisionAddonPluginEnabled= flag, which can be used by templates (e.g. used by the HistoryPlugin)
Expand Down
58 changes: 29 additions & 29 deletions .../Contrib/CompareRevisionsAddOn/Compare.pm → .../Contrib/CompareRevisionsAddOn/Compare.pm 100644 → 100755
Expand Up @@ -6,7 +6,7 @@
# the differences broken down to the word-by-word level if necessary.
# The output can be formatted by templates and skins.
#
# See the documentation in TWiki/CompareRevisionsAddOn
# See the documentation in Foswiki/CompareRevisionsAddOn
#
# History:
#
Expand All @@ -17,16 +17,16 @@
# 14 Sep 2005 - JChristophFuchs - Fix for Codev.SecurityAlertExecuteCommandsWithRev
# 26 Feb 2006 - JChristophFuchs - Updated for Dakar
########################################################################
package TWiki::Contrib::CompareRevisionsAddOn::Compare;
package Foswiki::Contrib::CompareRevisionsAddOn::Compare;

use strict;

use CGI::Carp qw(fatalsToBrowser);
use CGI;

use TWiki::UI;
use TWiki::Func;
use TWiki::Plugins;
use Foswiki::UI;
use Foswiki::Func;
use Foswiki::Plugins;

use HTML::TreeBuilder;
use Algorithm::Diff;
Expand All @@ -44,36 +44,36 @@ my $scripturl;
sub compare {
my $session = shift;

$TWiki::Plugins::SESSION = $session;
$Foswiki::Plugins::SESSION = $session;

my $query = $session->{cgiQuery};
my $webName = $session->{webName};
my $topic = $session->{topicName};

unless ( TWiki::Func::topicExists( $webName, $topic ) ) {
TWiki::Func::redirectCgiQuery( $query,
TWiki::Func::getOopsUrl( $webName, $topic, 'oopsmissing' ) );
unless ( Foswiki::Func::topicExists( $webName, $topic ) ) {
Foswiki::Func::redirectCgiQuery( $query,
Foswiki::Func::getOopsUrl( $webName, $topic, 'oopsmissing' ) );
}

$scripturl = TWiki::Func::getScriptUrl( $webName, $topic, 'compare' );
$scripturl = Foswiki::Func::getScriptUrl( $webName, $topic, 'compare' );

# Check, if interweave or sidebyside

my $renderStyle = $query->param('render')
|| &TWiki::Func::getPreferencesValue( "COMPARERENDERSTYLE", $webName )
|| &Foswiki::Func::getPreferencesValue( "COMPARERENDERSTYLE", $webName )
|| 'interweave';
$interweave = $renderStyle eq 'interweave';

# Check context

$context = $query->param('context');
$context = &TWiki::Func::getPreferencesValue( "COMPARECONTEXT", $webName )
$context = &Foswiki::Func::getPreferencesValue( "COMPARECONTEXT", $webName )
unless defined($context);
$context = -1 unless defined($context) && $context =~ /^\d+$/;

# Get Revisions. rev2 default to maxrev, rev1 to rev2-1

my $maxrev = ( TWiki::Func::getRevisionInfo( $webName, $topic ) )[2];
my $maxrev = ( Foswiki::Func::getRevisionInfo( $webName, $topic ) )[2];
my $rev2 = $query->param('rev2') || $maxrev;
$rev2 =~ s/^1\.// if $rev2;

Expand Down Expand Up @@ -101,11 +101,11 @@ sub compare {

my $tree2 = _getTree( $session, $webName, $topic, $rev2 );
if ( $tree2 =~ /^http:.*oops/ ) {
TWiki::Func::redirectCgiQuery( $query, $tree2 );
Foswiki::Func::redirectCgiQuery( $query, $tree2 );
}
my $tree1 = _getTree( $session, $webName, $topic, $rev1 );
if ( $tree1 =~ /^http:.*oops/ ) {
TWiki::Func::redirectCgiQuery( $query, $tree1 );
Foswiki::Func::redirectCgiQuery( $query, $tree1 );
}

# Reset the skin
Expand All @@ -127,16 +127,16 @@ sub compare {
# get and process templates

my $tmpl =
TWiki::Func::readTemplate( $interweave ? 'compareinterweave' : 'comparesidebyside' );
Foswiki::Func::readTemplate( $interweave ? 'compareinterweave' : 'comparesidebyside' );

$tmpl =~ s/\%META{.*?\}\%\s*//g; # Meta data already processed
# in _getTree
$tmpl = TWiki::Func::expandCommonVariables( $tmpl, $topic, $webName );
$tmpl = Foswiki::Func::expandCommonVariables( $tmpl, $topic, $webName );
$tmpl =~ s/%REVTITLE1%/$revtitle1/g;
$tmpl =~ s/%REVTITLE2%/$revtitle2/g;
$tmpl =~ s/%REVINFO1%/$revinfo1/g;
$tmpl =~ s/%REVINFO2%/$revinfo2/g;
$tmpl = TWiki::Func::renderText( $tmpl, $webName );
$tmpl = Foswiki::Func::renderText( $tmpl, $webName );
$tmpl =~ s/( ?) *<\/?(nop|noautolink)\/?>\n?/$1/gois
;

Expand Down Expand Up @@ -249,8 +249,8 @@ sub compare {

last
if $i == 1
|| ( $TWiki::cfg{NumberOfRevisions} > 0
&& $i == $maxrev - $TWiki::cfg{NumberOfRevisions} + 1 );
|| ( $Foswiki::cfg{NumberOfRevisions} > 0
&& $i == $maxrev - $Foswiki::cfg{NumberOfRevisions} + 1 );
if ( $i == $rev2 && $i - 1 == $rev1 ) {
$revisions .= " &lt;";
}
Expand Down Expand Up @@ -279,8 +279,8 @@ sub compare {
$tmpl_after =~ s/%REVINFO2%/$revinfo2/go;

$tmpl_after =
TWiki::Func::expandCommonVariables( $tmpl_after, $topic, $webName );
$tmpl_after = TWiki::Func::renderText( $tmpl_after, $webName );
Foswiki::Func::expandCommonVariables( $tmpl_after, $topic, $webName );
$tmpl_after = Foswiki::Func::renderText( $tmpl_after, $webName );
$tmpl_after =~ s/( ?) *<\/?(nop|noautolink)\/?>\n?/$1/gois
; # remove <nop> and <noautolink> tags

Expand All @@ -297,13 +297,13 @@ sub _getTree {

# Read document

my ( $meta, $text ) = TWiki::Func::readTopic( $webName, $topicName, $rev );
my ( $meta, $text ) = Foswiki::Func::readTopic( $webName, $topicName, $rev );
$text .= "\n" . '%META{"form"}%';
$text .= "\n" . '%META{"attachments"}%';

$session->enterContext( 'can_render_meta', $meta );
$text = TWiki::Func::expandCommonVariables( $text, $topicName, $webName );
$text = TWiki::Func::renderText( $text, $webName );
$text = Foswiki::Func::expandCommonVariables( $text, $topicName, $webName );
$text = Foswiki::Func::renderText( $text, $webName );

$text =~ s/^\s*//;
$text =~ s/\s*$//;
Expand Down Expand Up @@ -547,12 +547,12 @@ sub _getTextFromAction {
sub getRevInfo {
my ( $web, $rev, $topic, $short ) = @_;

my ( $date, $user ) = TWiki::Func::getRevisionInfo( $web, $topic, $rev );
my $mainweb = TWiki::Func::getMainWebname();
my ( $date, $user ) = Foswiki::Func::getRevisionInfo( $web, $topic, $rev );
my $mainweb = Foswiki::Func::getMainWebname();
$user = "$mainweb.$user";

# $user = TWiki::Render::getRenderedVersion( TWiki::userToWikiName( $user ) );
$date = TWiki::Func::formatTime($date);
# $user = Foswiki::Render::getRenderedVersion( Foswiki::userToWikiName( $user ) );
$date = Foswiki::Func::formatTime($date);

my $revInfo = "$date - $user";
$revInfo =~ s/[\n\r]*//go;
Expand Down
@@ -0,0 +1,14 @@
bin/compare 0555
data/Sandbox/CompareRevisionsAddOnDemoTopic.txt 0644
data/Sandbox/CompareRevisionsAddOnDemoTopic.txt,v 0644
data/System/CompareRevisionsAddOn.txt 0644
data/System/CompareRevisionsAddonPlugin.txt 0644
lib/Foswiki/Plugins/CompareRevisionsAddonPlugin.pm 0444
lib/Foswiki/Contrib/CompareRevisionsAddOn/Compare.pm 0444
lib/Foswiki/Contrib/CompareRevisionsAddOn/Config.spec 0444
pub/System/CompareRevisionsAddOn/interweave.png 0644
pub/System/CompareRevisionsAddOn/sidebyside.png 0644
templates/compare.tmpl 0444
templates/compareinterweave.tmpl 0444
templates/comparesidebyside.tmpl 0444

Expand Up @@ -8,10 +8,10 @@ BEGIN
}
}

use TWiki::Contrib::Build;
use Foswiki::Contrib::Build;

# Create the build object
$build = new TWiki::Contrib::Build( 'CompareRevisionsAddOn' );
$build = new Foswiki::Contrib::Build( 'CompareRevisionsAddOn' );

# Build the target on the command line, or the default target
$build->build($build->{target});
Expand Down
Expand Up @@ -5,6 +5,7 @@
# and TWiki Contributors. All Rights Reserved. TWiki Contributors
# are listed in the AUTHORS file in the root of this distribution.
# NOTE: Please extend that file, not this notice.
# Copyright (C) 2008 Foswiki Contributors
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -16,7 +17,7 @@
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# For licensing info read LICENSE file in the TWiki root.
# For licensing info read LICENSE file in the Foswiki root.

=pod
Expand All @@ -27,18 +28,18 @@ This is a helper plugin for the CompareRevisionsAddon package.
=cut

# change the package name and $pluginName!!!
package TWiki::Plugins::CompareRevisionsAddonPlugin;
package Foswiki::Plugins::CompareRevisionsAddonPlugin;

# Always use strict to enforce variable scoping
use strict;

use TWiki;
use Foswiki;

# $VERSION is referred to by TWiki, and is the only global variable that
# $VERSION is referred to by Foswiki, and is the only global variable that
# *must* exist in this package
use vars qw( $VERSION $RELEASE $debug $pluginName );

# This should always be $Rev: 8713$ so that TWiki can determine the checked-in
# This should always be $Rev: 8713$ so that Foswiki can determine the checked-in
# status of the plugin. It is used by the build automation tools, so
# you should leave it alone.
$VERSION = '$Rev: 8713$';
Expand All @@ -56,8 +57,8 @@ sub initPlugin {
my( $topic, $web, $user, $installWeb ) = @_;

# check for Plugins.pm versions
if( $TWiki::Plugins::VERSION < 1.026 ) {
TWiki::Func::writeWarning( "Version mismatch between $pluginName and Plugins.pm" );
if( $Foswiki::Plugins::VERSION < 1.026 ) {
Foswiki::Func::writeWarning( "Version mismatch between $pluginName and Plugins.pm" );
return 0;
}

Expand All @@ -69,16 +70,16 @@ sub commonTagsHandler {
# do not uncomment, use $_[0], $_[1]... instead
### my ( $text, $topic, $web ) = @_;

TWiki::Func::writeDebug( "- ${pluginName}::commonTagsHandler( $_[2].$_[1] )" ) if $debug;
Foswiki::Func::writeDebug( "- ${pluginName}::commonTagsHandler( $_[2].$_[1] )" ) if $debug;

$_[0] =~ s/%RDIFF2COMPARE{"?(.*?)"?}%/&_handleRdiff2Compare($1)/ge;
}

sub _handleRdiff2Compare {

my $text = shift;
$text =~ s{/rdiff $TWiki::cfg{ScriptSuffix}/}
{/compare$TWiki::cfg{ScriptSuffix}/}xmsg;
$text =~ s{/rdiff $Foswiki::cfg{ScriptSuffix}/}
{/compare$Foswiki::cfg{ScriptSuffix}/}xmsg;
return $text;

}
Expand Down

This file was deleted.

File renamed without changes
File renamed without changes

0 comments on commit babc841

Please sign in to comment.