diff --git a/InterwikiPlugin/data/System/InterwikiPlugin.txt b/InterwikiPlugin/data/System/InterwikiPlugin.txt index 01279a8dd3..c9cdf0db87 100644 --- a/InterwikiPlugin/data/System/InterwikiPlugin.txt +++ b/InterwikiPlugin/data/System/InterwikiPlugin.txt @@ -1,6 +1,9 @@ -%META:TOPICINFO{author="PeterThoeny" date="1186881349" format="1.1" version="$Rev$"}% +%META:TOPICINFO{author="ProjectContributor" date="1186881349" format="1.1" version="$Rev$"}% %META:TOPICPARENT{name="Plugins"}% ---+!! Interwiki Plugin + The %TOPIC% links ==ExternalSite:Page== text to external sites based on aliases defined in the %SYSTEMWEB%.InterWikis topic. This plugin is inspired by UseMod Wiki's inter-wiki links, http://www.usemod.com/cgi-bin/wiki.pl?InterWiki. @@ -20,23 +23,19 @@ The %TOPIC% links ==ExternalSite:Page== text to external sites based on ali ---++ %TOPIC% Settings -Plugin settings are stored as [[%SYSTEMWEB%.PreferenceSettings][preference settings]]. To reference -a plugin setting write ==%<plugin>_<setting>%==, for example, ==%INTERWIKIPLUGIN_SHORTDESCRIPTION%== +You can override the default settings using [[%SYSTEMWEB%.PreferenceSettings][preferences]]. These preferences can be set in your %USERSWEB%.SitePreferences, or in !WebPreferences, or in individual topics. - * One-line description, shown in the %SYSTEMWEB%.TextFormattingRules topic: - * Set SHORTDESCRIPTION = Link ==ExternalSite:Page== text to external sites based on aliases defined in a rules topic - - * Link rules topic name: (default is %SYSTEMWEB%.InterWikis) - * Set RULESTOPIC = - - * Inter-link format, with formatting tokens: +| *Preference* | *Use to* | *Default* | +| =INTERWIKIPLUGIN_RULESTOPIC= | Change the link rules topic name | %SYSTEMWEB%.InterWikis | +| =INTERWIKIPLUGIN_INTERLINKFORMAT= | Set the interlink format | =<a href="$url" title="$tooltip" class="interwikiLink"><noautolink>$label</noautolink></a>= | +The =INTERWIKIPLUGIN_INTERLINKFORMAT= supports a number of formatting tokens: | *Token* | *Meaning* | | $site | Site alias | | $page | Page (part after colon) | | $url | Site URL (might contain $page) | | $label | Equal to $site:$page | | $tooltip | Tooltip message | - * Set INTERLINKFORMAT = $label + ---++ Plugin Installation Instructions @@ -46,11 +45,14 @@ a plugin setting write ==%<plugin>_<setting>%==, for example, = ---++ Plugin Info -| Plugin Author: | TWiki:Main.AndreaSterbini, TWiki:Main.PeterThoeny | +| Author: | Foswiki:%USERSWEB%.AndreaSterbini, TWiki:Main.PeterThoeny | | Copyright: | © 2001-2007, Andrea Sterbini, Peter Thoeny ([[http://www.twiki.net/][TWIKI.NET]]), %SYSTEMWEB%.ProjectContributor | | License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) | -| Plugin Version: | %$VERSION% | +| Version: | %$VERSION% | +| Release: | %$RELEASE% | | Change History: |   | +| 20 Sep 2009: | Version from 15 Apr now included with Foswiki 1.0.7. | +| 15 Apr 2009: | Foswiki:Main.CrawfordCurrie - removed plugin preferences from this topic | | 16 Dec 2008: | Foswiki:Main.KennethLavrsen - Foswiki version - no features changed | | 03 Aug 2008: | TWiki 4.2.1 release version | | 22 Jan 2008: | TWiki 4.2.0 release version | @@ -72,13 +74,7 @@ a plugin setting write ==%<plugin>_<setting>%==, for example, = | 12 Jun 2001: | Added optional tool tips (IE only); added the link rules topic name variable; added flexible link patterns; optional ==$page== in URL | | 10 Jun 2001: | Changed rules topic to table-based syntax | | 20 Feb 2001: | TWiki:Main.AndreaSterbini, TWiki:Main.PeterThoeny - Initial version | -| CPAN Dependencies: | none | -| Other Dependencies: | none | -| Perl Version: | 5.0 | | Plugin Home: | http://foswiki.org/Extensions/%TOPIC% | | Support: | http://foswiki.org/Support/%TOPIC% | ---- -*Related Topics:* [[%SYSTEMWEB%.Plugins][Plugins]], %SYSTEMWEB%.DeveloperDocumentationCategory, %SYSTEMWEB%.AdminDocumentationCategory, %USERSWEB%.SitePreferences, %SYSTEMWEB%.InterWikis --- TWiki:Main.PeterThoeny - 25 Nov 2007 diff --git a/InterwikiPlugin/lib/Foswiki/Plugins/InterwikiPlugin.pm b/InterwikiPlugin/lib/Foswiki/Plugins/InterwikiPlugin.pm index 67d93ae39b..0ff0de6013 100644 --- a/InterwikiPlugin/lib/Foswiki/Plugins/InterwikiPlugin.pm +++ b/InterwikiPlugin/lib/Foswiki/Plugins/InterwikiPlugin.pm @@ -37,110 +37,100 @@ package Foswiki::Plugins::InterwikiPlugin; use strict; -require Foswiki::Func; # The plugins API -require Foswiki::Plugins; # For the API version - -use vars qw( - $VERSION - $RELEASE - $interWeb - $interLinkFormat - $sitePattern - $pagePattern - %interSiteTable - ); +use Foswiki::Func (); # The plugins API +use Foswiki::Plugins (); # For the API version -# This should always be $Rev$ so that TWiki 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$'; +our $VERSION = '$Rev$'; +our $RELEASE = '20 Sep 2009'; +our $NO_PREFS_IN_TOPIC = 1; +our $SHORTDESCRIPTION = +'Link ExternalSite:Page text to external sites based on aliases defined in a rules topic'; -# This is a free-form string you can use to "name" your own plugin version. -# It is *not* used by the build automation tools, but is reported as part -# of the version number in PLUGINDESCRIPTIONS. -$RELEASE = '03 Aug 2008'; +our $interLinkFormat; +our $sitePattern; +our $pagePattern; +our %interSiteTable; BEGIN { - # 'Use locale' for internationalisation of Perl sorting and searching - - if( $Foswiki::cfg{UseLocale} ) { + + # 'Use locale' for internationalisation of Perl sorting and searching - + if ( $Foswiki::cfg{UseLocale} ) { require locale; - import locale (); + import locale(); } } # Read preferences and get all InterWiki Site->URL mappings sub initPlugin { - my( $topic, $web, $user, $installWeb ) = @_; - - $interWeb = $installWeb; - - # check for Plugins.pm versions - if( $Foswiki::Plugins::VERSION < 1.026 ) { - Foswiki::Func::writeWarning( "Version mismatch between InterwikiPlugin and Plugins.pm" ); - return 0; - } + my ( $topic, $web, $user, $installWeb ) = @_; # Regexes for the Site:page format InterWiki reference my $man = Foswiki::Func::getRegularExpression('mixedAlphaNum'); - my $ua = Foswiki::Func::getRegularExpression('upperAlpha'); - $sitePattern = "([$ua][$man]+)"; - $pagePattern = "([${man}_\/][$man" . '\.\/\+\_\,\;\:\!\?\%\#\@\-]*?)'; + my $ua = Foswiki::Func::getRegularExpression('upperAlpha'); + $sitePattern = "([$ua][$man]+)"; + $pagePattern = "([${man}_\/][$man" . '\.\/\+\_\,\&\;\:\=\!\?\%\#\@\-]*?)'; # Get plugin preferences from InterwikiPlugin topic $interLinkFormat = - Foswiki::Func::getPreferencesValue( 'INTERWIKIPLUGIN_INTERLINKFORMAT' ) || - '$label'; + Foswiki::Func::getPreferencesValue('INTERWIKIPLUGIN_INTERLINKFORMAT') + || '$label'; - my $interTopic = - Foswiki::Func::getPreferencesValue( 'INTERWIKIPLUGIN_RULESTOPIC' ) - || 'InterWikis'; - ( $interWeb, $interTopic ) = - Foswiki::Func::normalizeWebTopicName( $interWeb, $interTopic ); + my ( $interWeb, $interTopic ) = Foswiki::Func::normalizeWebTopicName( + $installWeb, + Foswiki::Func::getPreferencesValue('INTERWIKIPLUGIN_RULESTOPIC') + || 'InterWikis' + ); my $text = Foswiki::Func::readTopicText( $interWeb, $interTopic, undef, 1 ); # '| alias | URL | ...' table and extract into 'alias', "URL" list - $text =~ s/^\|\s*$sitePattern\s*\|\s*(.*?)\s*\|\s*(.*?)\s*\|.*$/_map($1,$2,$3)/mego; + $text =~ +s/^\|\s*$sitePattern\s*\|\s*(.*?)\s*\|\s*(.*?)\s*\|.*$/_map($1,$2,$3)/mego; $sitePattern = "(" . join( "|", keys %interSiteTable ) . ")"; return 1; } sub _map { - my( $site, $url, $tooltip ) = @_; - if( $site ) { - $interSiteTable{$site}{url} = $url || ''; + my ( $site, $url, $tooltip ) = @_; + if ($site) { + $interSiteTable{$site}{url} = $url || ''; $interSiteTable{$site}{tooltip} = $tooltip || ''; } return ''; } sub preRenderingHandler { + # ref in [[ref]] or [[ref][ - $_[0] =~ s/(\[\[)$sitePattern:$pagePattern(\]\]|\]\[[^\]]+\]\])/_link($1,$2,$3,$4)/geo; + $_[0] =~ +s/(\[\[)$sitePattern:$pagePattern(\]\]|\]\[[^\]]+\]\])/_link($1,$2,$3,$4)/geo; + # ref in text - $_[0] =~ s/(^|[\s\-\*\(])$sitePattern:$pagePattern(?=[\s\.\,\;\:\!\?\)\|]*(\s|$))/_link($1,$2,$3)/geo; + $_[0] =~ +s/(^|[\s\-\*\(])$sitePattern:$pagePattern(?=[\s\.\,\;\:\!\?\)\|]*(\s|$))/_link($1,$2,$3)/geo; } sub _link { - my( $prefix, $site, $page, $postfix ) = @_; + my ( $prefix, $site, $page, $postfix ) = @_; - $prefix ||= ''; - $site ||= ''; - $page ||= ''; + $prefix ||= ''; + $site ||= ''; + $page ||= ''; $postfix ||= ''; my $text = $prefix; - if( defined( $interSiteTable{$site} ) ) { + if ( defined( $interSiteTable{$site} ) ) { my $tooltip = $interSiteTable{$site}{tooltip}; - my $url = $interSiteTable{$site}{url}; - $url .= $page unless( $url =~ /\$page/ ); + my $url = $interSiteTable{$site}{url}; + $url .= $page unless ( $url =~ /\$page/ ); my $label = '$site:$page'; - if( $postfix ) { + if ($postfix) { + # [[...]] or [[...][...]] interwiki link $text = ''; - if( $postfix =~ /^\]\[([^\]]+)/ ) { + if ( $postfix =~ /^\]\[([^\]]+)/ ) { $label = $1; } } @@ -152,7 +142,8 @@ sub _link { $format =~ s/\$site/$site/g; $format =~ s/\$page/$page/g; $text .= $format; - } else { + } + else { $text .= "$site\:$page$postfix"; } return $text; diff --git a/InterwikiPlugin/lib/Foswiki/Plugins/InterwikiPlugin/build.pl b/InterwikiPlugin/lib/Foswiki/Plugins/InterwikiPlugin/build.pl index b3afaa56f9..a6c5092714 100755 --- a/InterwikiPlugin/lib/Foswiki/Plugins/InterwikiPlugin/build.pl +++ b/InterwikiPlugin/lib/Foswiki/Plugins/InterwikiPlugin/build.pl @@ -2,6 +2,8 @@ # # Build for InterwikiPlugin # +use strict; + BEGIN { foreach my $pc (split(/:/, $ENV{FOSWIKI_LIBS})) { unshift @INC, $pc; @@ -11,7 +13,7 @@ BEGIN use Foswiki::Contrib::Build; # Create the build object -$build = new Foswiki::Contrib::Build( 'InterwikiPlugin' ); +my $build = new Foswiki::Contrib::Build( 'InterwikiPlugin' ); # Build the target on the command line, or the default target $build->build($build->{target});