Skip to content

Commit

Permalink
Item2110: Merge trunk InterwikiPlugin with no settings in topic to 1.0.7
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/branches/Release01x00@5022 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
KennethLavrsen authored and KennethLavrsen committed Sep 20, 2009
1 parent b2c1b36 commit f506561
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 78 deletions.
34 changes: 15 additions & 19 deletions 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
<!--
* Set SHORTDESCRIPTION = %$SHORTDESCRIPTION%
-->

The <nop>%TOPIC% links ==ExternalSite:Page== text to external sites based on aliases defined in the %SYSTEMWEB%.InterWikis topic. This plugin is inspired by <nop>UseMod Wiki's inter-wiki links, http://www.usemod.com/cgi-bin/wiki.pl?InterWiki.

Expand All @@ -20,23 +23,19 @@ The <nop>%TOPIC% links ==ExternalSite:Page== text to external sites based on ali

---++ <nop>%TOPIC% Settings

Plugin settings are stored as [[%SYSTEMWEB%.PreferenceSettings][preference settings]]. To reference
a plugin setting write ==%<nop>&lt;plugin&gt;_&lt;setting&gt;%==, for example, ==%<nop>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 | =&lt;a href="$url" title="$tooltip" class="interwikiLink"&gt;&lt;noautolink&gt;$label&lt;/noautolink&gt;&lt;/a&gt;= |
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 = <a href="$url" title="$tooltip" class="interwikiLink"><noautolink>$label</noautolink></a>


---++ Plugin Installation Instructions

Expand All @@ -46,11 +45,14 @@ a plugin setting write ==%<nop>&lt;plugin&gt;_&lt;setting&gt;%==, for example, =

---++ Plugin Info

| Plugin Author: | TWiki:Main.AndreaSterbini, TWiki:Main.PeterThoeny |
| Author: | Foswiki:%USERSWEB%.AndreaSterbini, TWiki:Main.PeterThoeny |
| Copyright: | &copy; 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: | <!-- versions below in reverse order -->&nbsp; |
| 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 |
Expand All @@ -72,13 +74,7 @@ a plugin setting write ==%<nop>&lt;plugin&gt;_&lt;setting&gt;%==, 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
107 changes: 49 additions & 58 deletions InterwikiPlugin/lib/Foswiki/Plugins/InterwikiPlugin.pm
Expand Up @@ -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' ) ||
'<a href="$url" title="$tooltip"><noautolink>$label</noautolink></a>';
Foswiki::Func::getPreferencesValue('INTERWIKIPLUGIN_INTERLINKFORMAT')
|| '<a class="interwikiLink" href="$url" title="$tooltip"><noautolink>$label</noautolink></a>';

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;
}
}
Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion InterwikiPlugin/lib/Foswiki/Plugins/InterwikiPlugin/build.pl
Expand Up @@ -2,6 +2,8 @@
#
# Build for InterwikiPlugin
#
use strict;

BEGIN {
foreach my $pc (split(/:/, $ENV{FOSWIKI_LIBS})) {
unshift @INC, $pc;
Expand All @@ -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});
Expand Down

0 comments on commit f506561

Please sign in to comment.