Skip to content

Commit

Permalink
Item2645: Eliminate CommonTagsHandler, move link forcing to preRender…
Browse files Browse the repository at this point in the history
…ing handler.

   Add code to remove noautolink blocks.  (SMELL - uses code outside of Func.pm -
   Utility code to remove / add blocks would be really useful.  This same code is used
   by WYSIWYG, ExplicitNumbering plugins, probably others as well.)


git-svn-id: http://svn.foswiki.org/trunk/ControlWikiWordPlugin@6078 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Jan 17, 2010
1 parent 898ba22 commit e0707eb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
8 changes: 6 additions & 2 deletions data/System/ControlWikiWordPlugin.txt
Expand Up @@ -22,11 +22,15 @@ This plugin provides 3 functions:
This feature has no WikiUser configurable features. The System Administrator
can set regular expression rules in the Foswiki Configuration that will match
topic names useful for your configuration. Examples might include bug
tracking link on http://foswiki.org/Tasks, where Task topics are the word
_Task_ followed by a 3-5 digit number.
tracking link on http://foswiki.org/Support, where question topics are the word
_Question_ followed by a 3-5 digit number.

The sample configuration will provide a link for Question123

<noautolink>
&lt;noautolink> sections are honored Question456 &lt;/noautolink>
</noautolink>

---+++ Rules-based blocking of WikiWord linking

In this mode, the Plugin prevents automatic linking of selected [[%SYSTEMWEB%.WikiWord][WikiWords]] such as <nop>LinuxWorld or <nop>MacDonald.
Expand Down
47 changes: 39 additions & 8 deletions lib/Foswiki/Plugins/ControlWikiWordPlugin.pm
Expand Up @@ -57,6 +57,9 @@ $RELEASE = '0.9';
# entries so they can be used with =configure=.
our $NO_PREFS_IN_TOPIC = 1;

my $TT0 = chr(0);
my $TT1 = chr(1);
my $TT2 = chr(2);

# =========================
sub initPlugin
Expand Down Expand Up @@ -98,16 +101,18 @@ sub initPlugin
}

# =========================
sub commonTagsHandler
{
#sub commonTagsHandler
#{
### my ( $text, $topic, $web ) = @_; # do not uncomment, use $_[0], $_[1]... instead

writeDebug( "- X - ControlWikiWordPlugin::commonTagsHandler( $_[0]$_[2].$_[1] )" );
# writeDebug( "- X - ControlWikiWordPlugin::commonTagsHandler( $_[0]$_[2].$_[1] )" );

unless ( Foswiki::Func::getPreferencesFlag('NOAUTOLINK') ) {
$_[0] =~ s/(\s+)\.([A-Z]+[a-z]*)/"$1".&Foswiki::Func::internalLink("[[$2]]",$web,$web,"",1)/geo if ($dotSINGLETON);
}
}

# unless ( Foswiki::Func::getPreferencesFlag('NOAUTOLINK') ) {
# $_[0] =~ s/(\s+)\.([A-Z]+[a-z]*)/"$1".&Foswiki::Func::internalLink("[[$2]]",$web,$web,"",1)/geo if ($dotSINGLETON);
# }

#}

sub writeDebug
{
Expand All @@ -119,7 +124,33 @@ sub preRenderingHandler {
# do not uncomment, use $_[0], $_[1]... instead
#my( $text, $pMap ) = @_;

$_[0] =~ s/$stopWordsRE/$1<nop>$2/g if ($stopWordsRE);
my $renderer = $Foswiki::Plugins::SESSION->{renderer};
my $removedTextareas = {};

$_[0] =~ s/$stopWordsRE/$1<nop>$2/g if ($stopWordsRE);

eval ('$renderer->takeOutBlocks');
my $tOB = $@;

unless ( Foswiki::Func::getPreferencesFlag('NOAUTOLINK') ) {

if ($tOB eq "") {
$_[0] = $renderer->takeOutBlocks( $_[0], 'noautolink', $removedTextareas );
} else {
$_[0] = Foswiki::takeOutBlocks( $_[0], 'noautolink', $removedTextareas );
}

$_[0] =~ s/(\s+)(Question[[:digit:]]{3,5})(\s+)/"$1"."[[$web.$2][$2]]".$3/geo;

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

if ($tOB eq "") {
$renderer->putBackBlocks( \$_[0], $removedTextareas, 'noautolink', 'noautolink' );
} else {
Foswiki::putBackBlocks( \$_[0], $removedTextareas, 'noautolink', 'noautolink' );
}
}

}

1;
Expand Down

0 comments on commit e0707eb

Please sign in to comment.