Skip to content

Commit

Permalink
Item13045: Override INTERLINKFORMAT per interlink
Browse files Browse the repository at this point in the history
This is needed to better support migration from "trac" links per svn
revision to GitHub commit pointers.

Also fix a couple of typos in the unit tests    And correct the
interwiki link for Squeak.  It has moved.
  • Loading branch information
gac410 committed Oct 3, 2014
1 parent 9829d74 commit 42f9b94
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 23 deletions.
8 changes: 4 additions & 4 deletions InterwikiPlugin/data/System/InterWikis.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" date="1292007729" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" date="1412365793" format="1.1" version="1"}%
%META:TOPICPARENT{name="InterwikiPlugin"}%
---+ <nop>Inter-Wiki Link Rules (or Links to other Sites)

Expand Down Expand Up @@ -51,19 +51,19 @@ Any inter-wikis you add to [[%USERSWEB%.InterWikis]] will then be available in t

<noautolink>

| *Alias:* | *URL:* | *Tooltip Text:* |
| *Alias:* | *URL:* | *Tooltip Text:* | *Format override:* |
| Advogato | http://www.advogato.org/ | '$page' on Advogato community site (with peer review) |
| C2find | http://c2.com/cgi/wiki?FindPage&value= | Search '$page' on the original 'WikiWikiWeb' site |
| DokuWiki | http://wiki.splitbrain.org/wiki: | '$page' on Doku Wiki site |
| Foswiki | http://foswiki.org/ | '$page' on foswiki.org |
| Foswikitask | http://foswiki.org/Tasks/ | '$page' on the 'Foswiki' issue tracking site |
| Foswikirev | http://trac.foswiki.org/changeset/ | revision $page of 'Foswiki' |
| Foswikirev | %REV2REF{$page}% | revision $page of 'Foswiki' on Github | $url |
| FoxWiki | http://fox.wikis.com/wc.dll?Wiki~ | '$page' on Fox Wiki site |
| HammondWiki | http://www.dairiki.org/HammondWiki/index.php3? | '$page' on 'HammondWiki' site |
| MeatBall | http://www.usemod.com/cgi-bin/mb.pl? | '$page' on 'MeatBall' site, a 'UseMod' Wiki variant |
| MoinMoin | http://moinmo.in/ | '$page' on 'MoinMoin' Wiki site |
| PPR | http://c2.com/cgi/wiki? | '$page' on the original 'PortlandPatternRepository' site |
| Squeak | http://minnow.cc.gatech.edu/squeak/ | '$page' on Squeak Smalltalk Wiki |
| Squeak | http://wiki.squeak.org/squeak/ | '$page' on Squeak Smalltalk Wiki |
| TWiki | http://twiki.org/cgi-bin/view/ | '$page' on TWiki.org |
| TWikibug | http://develop.twiki.org/~twiki4/cgi-bin/view/Bugs/ | '$page' on the TWiki issue tracking site |
| TWikirev | http://develop.twiki.org/trac/changeset/ | revision $page of TWiki svn |
Expand Down
14 changes: 8 additions & 6 deletions InterwikiPlugin/data/System/InterwikiPlugin.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" date="1400981068" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" date="1412365793" format="1.1" version="1"}%
%META:TOPICPARENT{name="Plugins"}%
---+!! Interwiki Plugin
<!--
Expand All @@ -14,12 +14,13 @@ The <nop>%TOPIC% links ==ExternalSite:Page== text to external sites based on ali
* Enter ==ExternalSite:Page== to create a link that points to the ==Page== on the ==ExternalSite== server.
* If ==Page== contains spaces, it can be enclosed in single or double quotes. Example: ==MySite:'My Photo.jpg'==. Special characters contained within the quotes are URL encoded.
* Enter ==[<nop>[ExternalSite:Page][any label]]== to specify a custom label.
* All ==ExternalSite== aliases are defined in the %SYSTEMWEB%.InterWikis topic.
* All ==ExternalSite== aliases are defined in the %SYSTEMWEB%.InterWikis topic or as specified by the =INTERWIKIPLUGIN_RULESTOPIC= topic list.
* Add and edit aliases in %SYSTEMWEB%.InterWikis.
* Each entry must be of format: <br /> ==| External site alias | URL | Tooltip help text |==.
* Site aliases must start with an upper case letter and may contain alphanumeric letters.
* The URL and Tooltip Text may contain optional ==$page== formatting tokens; the token gets expanded to the page name.
* The URL may contain foswiki macros. They are expanded when the URL is expanded.
* Each entry must be 3 or 4 columns of format: <br /> ==| External site alias | URL | Tooltip help text | Optional INTERLINKFORMAT override |==.
* Site aliases must start with an upper case letter and may contain alphanumeric letters.
* The URL and Tooltip Text may contain optional ==$page== formatting tokens; the token gets expanded to the page name.
* The URL may contain foswiki macros. They are expanded when the URL is rendered.
* If the link format override is provided, it overrides the =INTERWIKIPLUGIN_INTERLINKFORMAT= for just that entry.
<blockquote class="foswikiHelp">%H% For Foswiki and TWiki sites, both the *web* and the *topic* have to be specified: ==<nop>Foswiki:Webname/<nop>SomePage==

Foswiki:Extensions/InterwikiPlugin or Foswiki:Extensions.InterwikiPlugin
Expand Down Expand Up @@ -58,6 +59,7 @@ The =INTERWIKIPLUGIN_INTERLINKFORMAT= supports a number of formatting tokens:
| Version: | %$VERSION% |
| Release: | %$RELEASE% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 03 Oct 2014: (1.21) | Foswikitask:Item13045: Add per-link override of INTERLINKFORMAT |
| 24 May 2014: (1.20) | Foswikitask:Item12819: Expand variables defined in !InterWiki links%BR% \
Foswikitask:Item11587: Replace call to deprecated =Foswiki::Func::readTopicText()= |
| 23 Oct 2013: (1.1.7) | Foswikitask:Item12555: Documentation updates |
Expand Down
29 changes: 23 additions & 6 deletions InterwikiPlugin/lib/Foswiki/Plugins/InterwikiPlugin.pm
Expand Up @@ -26,8 +26,8 @@ use warnings;
use Foswiki::Func (); # The plugins API
use Foswiki::Plugins (); # For the API version

our $VERSION = '1.20';
our $RELEASE = '1.20';
our $VERSION = '1.21';
our $RELEASE = '1.21';
our $NO_PREFS_IN_TOPIC = 1;
our $SHORTDESCRIPTION =
'Link !ExternalSite:Page text to external sites based on aliases defined in a rules topic';
Expand Down Expand Up @@ -88,19 +88,36 @@ sub initPlugin {
Foswiki::Func::readTopic( $interWeb, $interTopic );

# '| alias | URL | ...' table and extract into 'alias', "URL" list
$text =~
s/^\|\s*$sitePattern\s*\|\s*(.*?)\s*\|\s*(.*?)\s*\|.*$/_map($1,$2,$3)/meg;
$text =~ s/
^\|\s* # Start of table
$sitePattern
\s*\|\s* # Column separator
(.*?) # URL
\s*\|\s* # Column separator
(.*?) # tooltip
(?:
\s*\|\s* # Colunmn separator
([^\|\n]+) # Not a separator or end of line
)?
\s*\|.*? # Last column separator
/_map($1,$2,$3,$4)/megx;

}

$sitePattern = "(" . join( "|", keys %interSiteTable ) . ")";

return 1;
}

sub _map {
my ( $site, $url, $tooltip ) = @_;
my ( $site, $url, $tooltip, $format ) = @_;
if ($site) {
$interSiteTable{$site}{url} = $url || '';
$interSiteTable{$site}{tooltip} = $tooltip || '';
if ( defined $format ) {
$format =~ s/\s*$//g; # remove trailing spaces
$interSiteTable{$site}{format} = $format;
}
}
return '';
}
Expand Down Expand Up @@ -156,7 +173,7 @@ sub _link {
}
}

my $format = $interLinkFormat;
my $format = $interSiteTable{$site}{format} || $interLinkFormat;
$format =~ s/\$url/$url/g;
$format =~ s/\$tooltip/$tooltip/g;
$format =~ s/\$label/$label/g;
Expand Down
43 changes: 36 additions & 7 deletions InterwikiPlugin/test/unit/InterwikiPlugin/InterwikiPluginTests.pm
Expand Up @@ -46,7 +46,7 @@ sub test_link_from_local_rules_topic {
<noautolink>
| *Alias:* | *URL:* | *Tooltip Text:* |
| Localrule | http://rule.invalid.url?page= | Local rule |
</nautolink>
</noautolink>
HERE

Foswiki::Func::setPreferencesValue( "INTERWIKIPLUGIN_RULESTOPIC",
Expand All @@ -73,7 +73,7 @@ sub test_link_from_inherted_rules_topic {
| *Alias:* | *URL:* | *Tooltip Text:* |
| Localrule | http://rule.invalid.url?page= | Local rule |
| Wiki | http://foo.bar/cgi/wiki? | Redefined rule |
</nautolink>
</noautolink>
HERE

Foswiki::Func::setPreferencesValue( "INTERWIKIPLUGIN_RULESTOPIC",
Expand Down Expand Up @@ -115,7 +115,7 @@ sub test_cant_view_rules_topic {
<noautolink>
| *Alias:* | *URL:* | *Tooltip Text:* |
| Localrule | http://rule.invalid.url?page= | Local rule |
</nautolink>
</noautolink>
* Set DENYTOPICVIEW = %USERSWEB%.WikiGuest
HERE
Expand Down Expand Up @@ -180,7 +180,7 @@ sub test_link_with_topic_name {
<noautolink>
| *Alias:* | *URL:* | *Tooltip Text:* |
| WebHome | http://rule.invalid.url?page= | Local rule |
</nautolink>
</noautolink>
HERE

Foswiki::Func::setPreferencesValue( "INTERWIKIPLUGIN_RULESTOPIC",
Expand All @@ -205,8 +205,8 @@ sub test_link_with_topic_macro {
---+++ Local rules
<noautolink>
| *Alias:* | *URL:* | *Tooltip Text:* |
| WebHome | http://rule.invalid.url?page=%WEB%. | Local rule |
</nautolink>
| WebHome | http://rule.invalid.url?page=%WEB%. | Local rule | |
</noautolink>
HERE

Foswiki::Func::setPreferencesValue( "INTERWIKIPLUGIN_RULESTOPIC",
Expand All @@ -222,6 +222,35 @@ HERE
);
}

sub test_link_with_link_override {
my $this = shift;
my $localRulesTopic = "LocalInterWikis";

# This test doesn't make much sense, but it verifies that a %MACRO% will expand,
# and the results are generated with a different link format from the default.

Foswiki::Func::saveTopic( $this->{test_web}, $localRulesTopic, undef,
<<'HERE');
---+++ Local rules
<noautolink>
| *Alias:* | *URL:* | *Tooltip Text:* |
| Spaced | %SPACEOUT{"$page"}% | Local rule | <a href='http://Some.Site?param="$url"'>$url</a> |
</noautolink>
HERE

Foswiki::Func::setPreferencesValue( "INTERWIKIPLUGIN_RULESTOPIC",
"$this->{test_web}.$localRulesTopic" );
Foswiki::Plugins::InterwikiPlugin::initPlugin(
$this->{test_web}, $this->{test_topic},
$this->{test_user}, $Foswiki::cfg{SystemWebName}
);

$this->assert_html_equals(
"<a href='http://Some.Site?param=\"A Spaced Out Page\"'>A Spaced Out Page</a>",
Foswiki::Func::renderText( "Spaced:ASpacedOutPage", $this->{test_web} )
);
}

# http://foswiki.org/Tasks/Item10151
# http://foswiki.org/Tasks/Item10151
sub test_link_with_parentheses {
Expand Down Expand Up @@ -355,7 +384,7 @@ sub test_link_with_quoted_string {
<noautolink>
| *Alias:* | *URL:* | *Tooltip Text:* |
| Photo | http://www.example.com/photos/gallery.cgi?mode=view&photo= | Local rule |
</nautolink>
</noautolink>
HERE

Foswiki::Func::setPreferencesValue( "INTERWIKIPLUGIN_RULESTOPIC",
Expand Down

0 comments on commit 42f9b94

Please sign in to comment.