Skip to content

Commit

Permalink
Item11069: compatibility fixes
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/AliasPlugin@12375 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelDaum authored and MichaelDaum committed Aug 25, 2011
1 parent b18f827 commit 3a81658
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
8 changes: 5 additions & 3 deletions data/System/AliasPlugin.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" date="1259345825" format="1.1" version="1.3"}%
%META:TOPICINFO{author="micha" comment="save topic" date="1312904371" format="1.1" reprev="4" version="4"}%
---+!! <nop>AliasPlugin

%TOC%
Expand All @@ -22,7 +22,8 @@ it will be replaced by an appropriate link.

Configuration of this plugin is done by writing
your aliases into a specific topic, the <nop>WebAliases defining the WebAliases for the current web.
Site-wide aliases can be defined in <nop>%USERSWEB%.SiteAliases. Definitions are looked up in the given order:
Site-wide aliases can be defined in %IF{"istopic '%USERSWEB%.SiteAliases' else="<nop>"}%%USERSWEB%.SiteAliases.
Definitions are looked up in the given order:

1 current topic
1 current web's <nop>WebAliases
Expand Down Expand Up @@ -80,11 +81,12 @@ non-alphabetic characters. Some textile examples:
* Set SHORTDESCRIPTION = Define aliases which will be replaced with arbitrary strings automatically
-->
| Plugin Author: | Othello Maurer, Michael Daum |
| Copyright &copy;: | 2003, Othello Maurer; 2003-2010, Michael Daum http://michaeldaumconsulting.com |
| Copyright &copy;: | 2003, Othello Maurer; 2003-2011, Michael Daum http://michaeldaumconsulting.com |
| License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) |
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: | &nbsp; |
| 25 Aug 2011: | minor compatibility fixes |
| 09 Nov 2010: | fixing error using =takOutBlocks= |
| 07 Jun 2010: | don't expand ADDTOZONE/ADDTOHEAD when parsing in alias definitions |
| 12 Feb 2010: | compatibility with newer foswiki engines |
Expand Down
40 changes: 25 additions & 15 deletions lib/Foswiki/Plugins/AliasPlugin.pm
@@ -1,7 +1,7 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2003 Othello Maurer <maurer@nats.informatik.uni-hamburg.de>
# Copyright (C) 2003-2010 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2003-2011 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -23,7 +23,7 @@ use Foswiki::Attrs ();

# Foswiki maintenance
our $VERSION = '$Rev$';
our $RELEASE = '3.03';
our $RELEASE = '3.04';
our $SHORTDESCRIPTION = 'Define aliases which will be replaced with arbitrary strings automatically';
our $NO_PREFS_IN_TOPIC = 1;

Expand Down Expand Up @@ -154,8 +154,8 @@ sub handleAlias {
my $theRegex = $params->{regex} || '';

if ($theKey && $theValue) {
$theRegex =~ s/\$start/$START/go;
$theRegex =~ s/\$stop/$STOP/go;
$theRegex =~ s/\$start/$START/g;
$theRegex =~ s/\$stop/$STOP/g;
addAliasPattern($theKey, $theValue, $theRegex);
#writeDebug("handleAlias(): added alias $theKey -> $theValue");
return "";
Expand Down Expand Up @@ -231,22 +231,21 @@ sub getAliases {
$web ||= $baseWeb;
($web, $topic) = Foswiki::Func::normalizeWebTopicName($web, $topic);

writeDebug("getAliases($web, $topic)");

# have we alread red these aliaes
return 0 if defined $seenAliasWebTopics{"$web.$topic"};
$seenAliasWebTopics{"$web.$topic"} = 1;

#writeDebug("getAliases($web, $topic)");

# parse the topic containing the alias definitions
return 0 unless Foswiki::Func::topicExists($web, $topic);

my (undef, $text) = Foswiki::Func::readTopic($web, $topic);
return 0 unless $text =~ /%(UN)?ALIAS({.*?})?%/;


# hack: disable ADDTOHEAD and ADDTOZONE
$text =~ s/%(ADDTO(HEAD|ZONE))/%<nop>$1/g;

Foswiki::Func::expandCommonVariables($text, $web, $topic);
Foswiki::Func::expandCommonVariables($text, $topic, $web);

return 1;
}
Expand All @@ -257,6 +256,10 @@ sub completePageHandler {

return unless $_[0];

my $query = Foswiki::Func::getCgiQuery();
my $raw = $query->param("raw");
return if defined $raw && $raw =~ /^(all)$/;

# cleanup
$_[0] =~ s/<!-- \/\/ALIAS -->//g;
$_[0] =~ s/<!-- ALIAS:.*? -->//g;
Expand All @@ -272,14 +275,15 @@ sub beforeSaveHandler {
return if $web eq $Foswiki::cfg{SystemWebName};

# do the text
my $text = $meta->text();
my $text = $meta->text() || '';

#print STDERR "beforeSave 1 - text=$text\n";

my $removed = {};

# remove ALIAS macros and verbatims temporarily
my $macros = {};

$text = takeOutBlocks($text, 'verbatim', $removed);
$text =~ s/(%ALIAS{(.*?)}%)/takeOutAliasMacro($1, $2, $macros)/gmse;

Expand All @@ -290,7 +294,7 @@ sub beforeSaveHandler {
#print STDERR "beforeSave 3 - text=$text\n";

# put back stuff
$_[0] =~ s/$TranslationToken(\d+)$TranslationToken/$$macros{$1}/g;
$text =~ s/$TranslationToken(\d+)$TranslationToken/$$macros{$1}/g;
putBackBlocks( \$text, $removed, 'verbatim', 'verbatim' );

# store new text
Expand All @@ -313,7 +317,7 @@ sub beforeEditHandler {

# revert any alias before editing
# ... from text
my $text = $meta->text();
my $text = $meta->text() || '';
#print STDERR "beforeEdit 1 - text='$text'\n";

my $removed = {};
Expand Down Expand Up @@ -356,6 +360,8 @@ sub insertAliases {

###############################################################################
sub removeAliases {
return unless $_[0];

$_[0] =~ s/<!-- ALIAS:(.*?) -->.*?<!-- \/\/ALIAS -->/$1/gms;
$_[0] =~ s/&#60;!-- ALIAS:(.*?) --&#62;.*?&#60;!-- \/\/ALIAS --&#62;/$1/gms;
}
Expand All @@ -378,15 +384,19 @@ sub takeOutAliasMacro {
###############################################################################
# compatibility wrapper
sub takeOutBlocks {
return Foswiki::takeOutBlocks(@_) if defined &Foswiki::takeOutBlocks;
return $Foswiki::Plugins::SESSION->renderer->takeOutBlocks(@_);
my ($text, $tag, $map) = @_;

return '' unless $text;

return Foswiki::takeOutBlocks($text, $tag, $map) if defined &Foswiki::takeOutBlocks;
return $Foswiki::Plugins::SESSION->renderer->takeOutBlocks($text, $tag, $map);
}

###############################################################################
# compatibility wrapper
sub putBackBlocks {
return Foswiki::putBackBlocks(@_) if defined &Foswiki::putBackBlocks;
return $Foswiki::Plugins::SESSION->{renderer}->putBackBlocks(@_);
return $Foswiki::Plugins::SESSION->renderer->putBackBlocks(@_);
}

###############################################################################
Expand Down

0 comments on commit 3a81658

Please sign in to comment.