Skip to content

Commit

Permalink
Item2278: fix hyperlinks in EasyTimelinePlugin
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/EasyTimelinePlugin@5350 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
AndrewJones authored and AndrewJones committed Oct 22, 2009
1 parent bf73e2f commit 549d91c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 63 deletions.
21 changes: 18 additions & 3 deletions lib/Foswiki/Plugins/EasyTimelinePlugin.pm
Expand Up @@ -117,6 +117,9 @@ sub handleTimeline {
or return "!$pluginName Error: *tmp folder $tmpDir could not be created*";
}

# convert links
$text =~ s/\[\[([$Foswiki::regex{mixedAlphaNum}\._\:\/-]*)\]\[([$Foswiki::regex{mixedAlphaNum} \/&\._-]*)\]\]/&renderLink($1, $2, $web, $topic)/egs;

# output the timeline text into the tmp file
open OUTFILE, ">$tmpFile.txt"
or return "!$pluginName Error: could not create file";
Expand All @@ -130,13 +133,11 @@ sub handleTimeline {
' -i %INFILE|F% -m -P ' .
$Foswiki::cfg{Plugins}{$pluginName}{PloticusCmd} . # /usr/local/bin/pl
' -T %TMPDIR|F% -A ' .
$Foswiki::cfg{ScriptUrlPath} . 'view' . $Foswiki::cfg{ScriptSuffix} . # /bin/view/
'/%WEB|F%';
$Foswiki::cfg{ScriptUrlPath} . 'view' . $Foswiki::cfg{ScriptSuffix}; # /bin/view/
&writeDebug("Command: $cmd");
my ( $output, $status ) = Foswiki::Sandbox->sysCommand(
$cmd,
INFILE => $tmpFile . '.txt',
WEB => $web,
TMPDIR => $tmpDir,
);
&writeDebug("$pluginName: output $output status $status");
Expand Down Expand Up @@ -222,6 +223,20 @@ sub handleTimeline {
}
}

# converts Foswiki style links into absolute Mediawiki style links that work with the EasyTimelne.pl script
sub renderLink {
# [[$link][$title]]
my ($link, $title, $web, $topic) = @_;

if( $link =~ m!^http://! ){
return "[[$link|$title]]"
} else {
my ( $linkedWeb, $linkedTopic ) = Foswiki::Func::normalizeWebTopicName( '', $link );
my $url = Foswiki::Func::getScriptUrl( $linkedWeb, $linkedTopic, 'view' );
return "[[$url|$title]]";
}
}

# =========================
sub cleanTmp {
my $dir = shift;
Expand Down
67 changes: 7 additions & 60 deletions tools/EasyTimeline.pl
Expand Up @@ -4999,79 +4999,26 @@ sub ProcessWikiLink
{ $link = "[[" . $link . "]]" ; }

$text =~ s/(\[+) [^\|\]]+ \| ([^\]]*) (\]+)/$1$2$3/gx ;
$text =~ s/(https?)\:/$1colon/gx ;
#$text =~ s/(https?)\:/$1colon/gx ;
# $text =~ s/(\[+) [^\:\]]+ \: ([^\]]*) (\]+)/$1$2$3/gx ; #???

# remove interwiki link prefix
$text =~ s/(\[+) (?:.{2,3}|(?:zh\-.*)|simple|minnan|tokipona) \: ([^\]]*) (\]+)/$1$2$3/gxi ; #???
#$text =~ s/(\[+) (?:.{2,3}|(?:zh\-.*)|simple|minnan|tokipona) \: ([^\]]*) (\]+)/$1$2$3/gxi ; #???

$text =~ s/\[+ ([^\]]+) \]+/{{{$1}}}/x ;
$text =~ s/\[+ ([^\]]+) \]+/$1/gx ;
$text =~ s/\{\{\{ ([^\}]*) \}\}\}/[[$1]]/x ;
}
# if ($text =~ /\[\[.+\]\]/)
# {
# $wikilink = $true ;
# $link = $text ;
# $link =~ s/\n//g ;
# $link =~ s/^.*?\[\[/[[/x ;
# $link =~ s/\| .*? \]\].*$/]]/x ;
# $link =~ s/\]\].*$/]]/x ;
# $text =~ s/\[\[ [^\|\]]+ \| (.*?) \]\]/[[$1]]/x ;
# $text =~ s/\[\[ [^\:\]]+ \: (.*?) \]\]/[[$1]]/x ;

# # remove remaining links
# $text =~ s/\[\[ ([^\]]+) \]\]/^%#$1#%^/x ;
# $text =~ s/\[+ ([^\]]+) \]+/$1/gx ;
# $text =~ s/\^$hPerc\# (.*?) \#$hPerc\^/[[$1]]/x ;
# }
# elsif ($text =~ /\[.+\]/)
# {
# $link = $text ;
# $link =~ s/\n//g ;
# $link =~ s/^.*?\[/[/x ;
# $link =~ s/\| .*? \].*$/]/x ;
# $link =~ s/\].*$/]/x ;
# $link =~ s/\[ ([^\]]+) \]/$1/x ;
# $text =~ s/\[ [^\|\]]+ \| (.*?) \]/[[$1]]/x ;

# # remove remaining links
# $text =~ s/\[\[ ([^\]]+) \]\]/^%#$1#%^/x ;
# $text =~ s/\[+ ([^\]]+) \]+/$1/gx ;
# $text =~ s/\^$hPerc\# (.*?) \#$hPerc\^/[[$1]]/x ;
## $text =~ s/\[\[ (.*) \]\]/$1/gx ;
# }

}

if ($wikilink)
{
# if ($link =~ /^\[\[.+\:.+\]\]$/) # has a colon in its name
if ($link =~ /^\[\[ (?:.{2,3}|(?:zh\-.*)|simple|minnan|tokipona) \: .+\]\]$/xi) # has a interwiki link prefix
{
# This will fail for all interwiki links other than Wikipedia.
$wiki = lc ($link) ;
$title = $link ;
$wiki =~ s/\[\[([^\:]+)\:.*$/$1/x ;
$title =~ s/^[^\:]+\:(.*)\]\]$/$1/x ;
$title =~ s/ /_/g ;
$link = "http://$wiki.wikipedia.org/wiki/$title" ;
$link = &EncodeURL ($title) ;
if (($hint eq "") && ($title ne ""))
{ $hint = "$wiki: $title" ; }
}
else
{
# $wiki = "en" ;
$title = $link ;
$title =~ s/^\[\[(.*)\]\]$/$1/x ;
$title =~ s/ /_/g ;
$link = $articlepath ;
$urlpart = &EncodeURL ($title) ;
$link =~ s/\$1/$urlpart/ ;
if (($hint eq "") && ($title ne ""))
{ $hint = "$title" ; }
}
$link =~ s/^\[\[(.*)\]\]$/$1/x ;
$link =~ s/ /_/g ;
if (($hint eq "") && ($link ne ""))
{ $hint = "$link" ; }

$hint =~ s/_/ /g ;
}
else
Expand Down

0 comments on commit 549d91c

Please sign in to comment.