Skip to content

Commit

Permalink
Item9964: Restore removed blocks in reverse order
Browse files Browse the repository at this point in the history
Item9968:  Update regex to use WikiWord delimiters from Render.pm
 - Update unit test to clear setting set in another test.
 - Improve documentation of regular expression
 - Add comma to Config.spec
 - Bump version for release

git-svn-id: http://svn.foswiki.org/trunk/ControlWikiWordPlugin@9888 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Nov 6, 2010
1 parent 2d8fab3 commit 3cc7a04
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
9 changes: 5 additions & 4 deletions data/System/ControlWikiWordPlugin.txt
Expand Up @@ -110,14 +110,14 @@ The system administrator uses the =bin/configure= interface to set one or more R
should be linked. ={qr/Regular Expression/,'Webname'}= If the webname is not provided, the link will be for the web of the topic containing the matching word.
The plugin performs case-sensitive matching.

%X% *Caution:* Syntax errors in =LocalSite.cfg= can render the site non-operational. This is an *Expert* level perl language configuration and should be approached with caution!
%X% *Caution:* Syntax errors in =LocalSite.cfg= can render the site non-operational. This is an *Expert* level perl language configuration and should be approached with caution! Each entry in the list of regular expressions must be followed by a comma.

---+++++!! Sample Configuration:
<verbatim>
{Plugins}{ControlWikiWordPlugin}{SingletonWords} = {
'(?:Item[[:digit:]]{3,6})' => 'Tasks'
'(?:Question[[:digit:]]{3,5}|FAQ[[:digit:]]{1,3})' => 'Support'
'(?:Plugins)' => ''
'(?:Item[[:digit:]]{3,6})' => 'Tasks',
'(?:Question[[:digit:]]{3,5}|FAQ[[:digit:]]{1,3})' => 'Support',
'(?:Plugins)' => '',
};
</verbatim>
Will perform the following links:
Expand Down Expand Up @@ -161,6 +161,7 @@ modifiers. The - "negates" or turns off the following options:
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order --> |
| 6 Nov 2010 | Foswikitask:Item9964 - Fix issue with Attachment table on 1.1, Foswikitask:Item9968 - Improve regular expressions |
| 24 Aug 2010 | Foswikitask:Item9473 - Restructure for performance, clarify documentation |
| 16 Mar 2010 | Foswikitask:Item8720 - STOPWIKIWORDLINK should be an exact match. |
| 15 Mar 2010 | Foswikitask:Item8714 - Update author and copyright attributions. Bump version - no code changes. |
Expand Down
28 changes: 13 additions & 15 deletions lib/Foswiki/Plugins/ControlWikiWordPlugin.pm
Expand Up @@ -87,12 +87,8 @@ sub initPlugin {
$prefs{'stopWords'} =~ s/\, */\|/go; # Change comma's to "or"
$prefs{'stopWords'} =~ s/^ *//o; # Drop leading spaces
$prefs{'stopWords'} =~ s/ *$//o; # Drop trailing spaces
#SMELL: This ought to be done in the config checker - error out non-WikiWords
$prefs{'stopWords'} =~ s/[^$Foswiki::regex{mixedAlphaNum}\|]//go
; # Filter any characters not valid in WikiWords
$prefs{'stopWords'} =~
s/\|/[\\W\\s]|/go; # Add a Word or Whitespace separator
$prefs{'stopWords'} .= '[\W\s]'; # .. and a trailing one too.
}

$prefs{'controlAbbrev'} =
Expand Down Expand Up @@ -124,13 +120,16 @@ sub preRenderingHandler {
my $controlAbbrev = $prefs{'controlAbbrev'};
my $dotSINGLETON = $prefs{'dotSINGLETON'};

#Lookbehind / Lookahead WikiWord delimiters taken from Foswiki::Render
my $STARTWW = qr/^|(?<=[\s\(])/m;
my $ENDWW = qr/$|(?=[\s,.;:!?)])/m;

my $stopWordsRE = ''; # Clear - handler only processes topic if provided

if ($stopWords) {

# build regularex:
$stopWordsRE = "(^|[\( \n\r\t\|])($stopWords)"
; # WikiWord preceeded by space or parens
$stopWordsRE = qr/$STARTWW($stopWords)$ENDWW/;
Foswiki::Func::writeDebug(
"ControlWikiWordPlugin - stopWordsRE: $stopWordsRE")
if $debug;
Expand All @@ -140,10 +139,7 @@ sub preRenderingHandler {
my $removedTextareas = {};
my $removedProtected = {};

#Foswiki::Func::writeDebug("stopWords ($stopWordsRE) before ($_[0]") if $debug;
$_[0] =~ s/$stopWordsRE/$1<nop>$2/g if ($stopWordsRE);

#Foswiki::Func::writeDebug("stopWords after ($_[0] ") if $debug;
$_[0] =~ s/$stopWordsRE/<nop>$1/g if ($stopWordsRE);

# If we don't have any regex and don't want the dot format, forget it.
if ( scalar keys %$regexInput > 0 || $dotSINGLETON || $controlAbbrev ) {
Expand Down Expand Up @@ -173,24 +169,28 @@ sub preRenderingHandler {
my $linkWeb = $regexInput->{$regex} || $web;
Foswiki::Func::writeDebug(" Regex is $regex Web is $linkWeb ")
if $debug;
$_[0] =~ s/(\s)($regex)\b/$1."[[$linkWeb.$2][$2]]"/ge;
$_[0] =~ s/$STARTWW($regex)$ENDWW/"[[$linkWeb.$1][$1]]"/ge;
}

$_[0] =~ s/(\s+)\.([A-Z]+[a-z]*)/"$1"."[[$web.$2][$2]]"/geo
$_[0] =~ s/$STARTWW\.([A-Z]+[a-z]*)$ENDWW/"[[$web.$1][$1]]"/geo
if ($dotSINGLETON);

if ($controlAbbrev) {
undef %acronyms;
Foswiki::Func::writeDebug("Clearing acronyms") if $debug;
$_[0] =~ s/(
(?:^|(?<=[\s\(,])) # Prefix
$STARTWW # Prefix
(?:$Foswiki::regex{'webNameRegex'}\.)? # Webname. optional
(?:$Foswiki::regex{'abbrevRegex'}) # Abbreviation
$ENDWW
)
/&_findAbbrev($web,$1)
/geox;
}

# Need to put back everything in the reverse order that it was removed.
$renderer->_putBackProtected( \$_[0], 'htmllink', $removedProtected );
$renderer->_putBackProtected( \$_[0], 'wikilink', $removedProtected );
# put back everything that was removed
if ($@) {
Foswiki::putBackBlocks( \$_[0], $removedTextareas, 'noautolink',
Expand All @@ -200,8 +200,6 @@ sub preRenderingHandler {
$renderer->putBackBlocks( \$_[0], $removedTextareas, 'noautolink',
'noautolink' );
}
$renderer->_putBackProtected( \$_[0], 'wikilink', $removedProtected );
$renderer->_putBackProtected( \$_[0], 'htmllink', $removedProtected );
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Foswiki/Plugins/ControlWikiWordPlugin/Config.spec
Expand Up @@ -8,5 +8,5 @@
$Foswiki::cfg{Plugins}{ControlWikiWordPlugin}{SingletonWords} = {
'(?:Item[[:digit:]]{3,6})' => 'Tasks',
'(?:Question[[:digit:]]{3,5}|FAQ[[:digit:]]{1,3})' => 'Support',
'(?:Plugins)' => ''
'(?:Plugins)' => '',
};
4 changes: 4 additions & 0 deletions test/unit/ControlWikiWordPlugin/ControlWikiWordPluginTests.pm
Expand Up @@ -227,6 +227,10 @@ END_EXPECTED

# Verify blocks with plugin setting

# Note that the short preference takes prescedence so need to clear.
Foswiki::Func::setPreferencesValue(
'STOPWIKIWORDLINK',
'' );
Foswiki::Func::setPreferencesValue(
'CONTROLWIKIWORDPLUGIN_STOPWIKIWORDLINK',
'MacDonald, WikiWord, MyTest' );
Expand Down

0 comments on commit 3cc7a04

Please sign in to comment.