Changeset 5350


Ignore:
Timestamp:
10/22/09 14:38:23 (3 years ago)
Author:
AndrewJones
Message:

Item2278: fix hyperlinks in EasyTimelinePlugin

Location:
trunk/EasyTimelinePlugin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/EasyTimelinePlugin/lib/Foswiki/Plugins/EasyTimelinePlugin.pm

    r3066 r5350  
    118118        } 
    119119 
     120        # convert links 
     121        $text =~ s/\[\[([$Foswiki::regex{mixedAlphaNum}\._\:\/-]*)\]\[([$Foswiki::regex{mixedAlphaNum} \/&\._-]*)\]\]/&renderLink($1, $2, $web, $topic)/egs; 
     122         
    120123        # output the timeline text into the tmp file 
    121124        open OUTFILE, ">$tmpFile.txt" 
     
    131134            $Foswiki::cfg{Plugins}{$pluginName}{PloticusCmd} . # /usr/local/bin/pl 
    132135            ' -T %TMPDIR|F% -A ' . 
    133             $Foswiki::cfg{ScriptUrlPath} . 'view' . $Foswiki::cfg{ScriptSuffix} . # /bin/view/ 
    134             '/%WEB|F%'; 
     136            $Foswiki::cfg{ScriptUrlPath} . 'view' . $Foswiki::cfg{ScriptSuffix}; # /bin/view/ 
    135137        &writeDebug("Command: $cmd"); 
    136138        my ( $output, $status ) = Foswiki::Sandbox->sysCommand( 
    137139            $cmd, 
    138140            INFILE => $tmpFile . '.txt', 
    139             WEB    => $web, 
    140141            TMPDIR => $tmpDir, 
    141142        ); 
     
    223224} 
    224225 
     226# converts Foswiki style links into absolute Mediawiki style links that work with the EasyTimelne.pl script 
     227sub renderLink { 
     228    # [[$link][$title]] 
     229    my ($link, $title, $web, $topic) = @_; 
     230     
     231    if( $link =~ m!^http://! ){ 
     232        return "[[$link|$title]]" 
     233    } else { 
     234        my ( $linkedWeb, $linkedTopic ) = Foswiki::Func::normalizeWebTopicName( '', $link ); 
     235        my $url = Foswiki::Func::getScriptUrl( $linkedWeb, $linkedTopic, 'view' ); 
     236        return "[[$url|$title]]"; 
     237    } 
     238} 
     239 
    225240# ========================= 
    226241sub cleanTmp { 
  • trunk/EasyTimelinePlugin/tools/EasyTimeline.pl

    r3059 r5350  
    50005000 
    50015001      $text =~ s/(\[+) [^\|\]]+ \| ([^\]]*) (\]+)/$1$2$3/gx ; 
    5002       $text =~ s/(https?)\:/$1colon/gx ; 
     5002      #$text =~ s/(https?)\:/$1colon/gx ; 
    50035003#     $text =~ s/(\[+) [^\:\]]+ \: ([^\]]*) (\]+)/$1$2$3/gx ;  #??? 
    50045004 
    50055005      # remove interwiki link prefix 
    5006       $text =~ s/(\[+) (?:.{2,3}|(?:zh\-.*)|simple|minnan|tokipona) \: ([^\]]*) (\]+)/$1$2$3/gxi ;  #??? 
     5006      #$text =~ s/(\[+) (?:.{2,3}|(?:zh\-.*)|simple|minnan|tokipona) \: ([^\]]*) (\]+)/$1$2$3/gxi ;  #??? 
    50075007 
    50085008      $text =~ s/\[+ ([^\]]+) \]+/{{{$1}}}/x ; 
     
    50105010      $text =~ s/\{\{\{ ([^\}]*) \}\}\}/[[$1]]/x ; 
    50115011    } 
    5012 #    if ($text =~ /\[\[.+\]\]/) 
    5013 #    { 
    5014 #      $wikilink = $true ; 
    5015 #      $link = $text ; 
    5016 #      $link =~ s/\n//g ; 
    5017 #      $link =~ s/^.*?\[\[/[[/x ; 
    5018 #      $link =~ s/\| .*? \]\].*$/]]/x ; 
    5019 #      $link =~ s/\]\].*$/]]/x ; 
    5020 #      $text =~ s/\[\[ [^\|\]]+ \| (.*?) \]\]/[[$1]]/x ; 
    5021 #      $text =~ s/\[\[ [^\:\]]+ \: (.*?) \]\]/[[$1]]/x ; 
    5022  
    5023 #      # remove remaining links 
    5024 #      $text =~ s/\[\[ ([^\]]+) \]\]/^%#$1#%^/x ; 
    5025 #      $text =~ s/\[+ ([^\]]+) \]+/$1/gx ; 
    5026 #      $text =~ s/\^$hPerc\# (.*?) \#$hPerc\^/[[$1]]/x ; 
    5027 #    } 
    5028 #    elsif ($text =~ /\[.+\]/) 
    5029 #    { 
    5030 #      $link = $text ; 
    5031 #      $link =~ s/\n//g ; 
    5032 #      $link =~ s/^.*?\[/[/x ; 
    5033 #      $link =~ s/\| .*? \].*$/]/x ; 
    5034 #      $link =~ s/\].*$/]/x ; 
    5035 #      $link =~ s/\[ ([^\]]+) \]/$1/x ; 
    5036 #      $text =~ s/\[ [^\|\]]+ \| (.*?) \]/[[$1]]/x ; 
    5037  
    5038 #      # remove remaining links 
    5039 #      $text =~ s/\[\[ ([^\]]+) \]\]/^%#$1#%^/x ; 
    5040 #      $text =~ s/\[+ ([^\]]+) \]+/$1/gx ; 
    5041 #      $text =~ s/\^$hPerc\# (.*?) \#$hPerc\^/[[$1]]/x ; 
    5042 ##     $text =~ s/\[\[ (.*) \]\]/$1/gx ; 
    5043 #    } 
    50445012 
    50455013  } 
     
    50475015  if ($wikilink) 
    50485016  { 
    5049 #   if ($link =~ /^\[\[.+\:.+\]\]$/) # has a colon in its name 
    5050     if ($link =~ /^\[\[ (?:.{2,3}|(?:zh\-.*)|simple|minnan|tokipona) \: .+\]\]$/xi) # has a interwiki link prefix 
    5051     { 
    5052       # This will fail for all interwiki links other than Wikipedia. 
    5053       $wiki  = lc ($link) ; 
    5054       $title = $link ; 
    5055       $wiki  =~ s/\[\[([^\:]+)\:.*$/$1/x ; 
    5056       $title =~ s/^[^\:]+\:(.*)\]\]$/$1/x ; 
    5057       $title =~ s/ /_/g ; 
    5058       $link = "http://$wiki.wikipedia.org/wiki/$title" ; 
    5059           $link = &EncodeURL ($title) ; 
    5060       if (($hint eq "") && ($title ne "")) 
    5061       { $hint = "$wiki: $title" ; } 
    5062     } 
    5063     else 
    5064     { 
    5065     # $wiki = "en" ; 
    5066       $title = $link ; 
    5067       $title =~ s/^\[\[(.*)\]\]$/$1/x ; 
    5068       $title =~ s/ /_/g ; 
    5069       $link = $articlepath ; 
    5070           $urlpart = &EncodeURL ($title) ; 
    5071           $link =~ s/\$1/$urlpart/ ; 
    5072       if (($hint eq "") && ($title ne "")) 
    5073       { $hint = "$title" ; } 
    5074     } 
     5017      $link =~ s/^\[\[(.*)\]\]$/$1/x ; 
     5018      $link =~ s/ /_/g ; 
     5019      if (($hint eq "") && ($link ne "")) 
     5020      { $hint = "$link" ; } 
     5021     
    50755022    $hint =~ s/_/ /g ; 
    50765023  } 
Note: See TracChangeset for help on using the changeset viewer.