diff --git a/lib/Foswiki/Plugins/EasyTimelinePlugin.pm b/lib/Foswiki/Plugins/EasyTimelinePlugin.pm index 58bd999..b46351e 100644 --- a/lib/Foswiki/Plugins/EasyTimelinePlugin.pm +++ b/lib/Foswiki/Plugins/EasyTimelinePlugin.pm @@ -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"; @@ -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"); @@ -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; diff --git a/tools/EasyTimeline.pl b/tools/EasyTimeline.pl index 788bbef..81e200c 100644 --- a/tools/EasyTimeline.pl +++ b/tools/EasyTimeline.pl @@ -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