Changeset 1632

Show
Ignore:
Timestamp:
04/18/2010 11:55:39 AM (3 years ago)
Author:
BrianKoontz
Message:

Modified forced links ([[...]]) to correctly parse non-CC page names.
In order to do this, and to maintain backwards compatibility, the
following cases are now checked (in the order specified) that should
account for the vast majority of forced links. We should consider
deprecating the use of forced links that contain a url and text, but
no separator (currently whitespace; proposed is the pipe character
"|"):

Case 1: First part is a URL, followed by one or more whitespaces,
followed by link text (deprecated; backwards compatible)

Case 2: First part is a CC string, followed by one or more whitespaces,
followed by link text (deprecated; backwards compatible)

Case 3: Text (possibly containing embedded whitespaces) that matches
an existing internal wiki page (must not contain "|" symbol; backwards
compatible)

Case 4: First part is a URL, followed by a "|" symbol, followed by
link text (new)

Refs #191

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/1.3/formatters/wakka.php

    r1493 r1632  
    766766                        return $output; 
    767767                } 
     768 
    768769                // forced links 
    769770                // \S : any character that is not a whitespace character 
    770771                // \s : any whitespace character 
    771                 // @@@ regex accepts NO non-whitespace before whitespace, surely not correct? [[  something]] 
    772                 else if (preg_match("/^\[\[(\S*)(\s+(.+))?\]\]$/s", $thing, $matches))          # recognize forced links across lines 
    773                 { 
    774                         if (!isset($matches[1])) $matches[1] = ''; #38 
    775                         if (!isset($matches[3])) $matches[3] = ''; #38 
    776                         list (, $url, , $text) = $matches; 
     772                else if(preg_match("/^\[\[(.*?)\]\]$/s", $thing, $matches)) 
     773                { 
     774                        $contents = $matches[1]; 
     775                        if(empty($contents) || !isset($contents)) 
     776                                return ""; 
     777 
     778                        // Case 1: Deprecated...(first part is a URL followed by 
     779                        // one or more whitespaces) 
     780                        if (preg_match("/^((http|https|ftp|news|irc|gopher):\/\/([^\|\\s\"<>]+))\s+([^\|]+)$/s", $contents, $matches))          # recognize forced links across lines 
     781                        { 
     782                                if (!isset($matches[1])) $matches[1] = ''; #38 
     783                                if (!isset($matches[4])) $matches[4] = ''; #38 
     784                                $url = $matches[1]; 
     785                                $text = $matches[4]; 
     786                        } 
     787 
     788                        // Case 2: Deprecated...(first part is a CC string 
     789                        // followed by one or more whitespaces) 
     790                        else if(preg_match("/^(.*?)\s+([^|]+)$/s", $contents, $matches) &&  
     791                                preg_match(VALID_PAGENAME_PATTERN, $matches[1])) 
     792                        { 
     793                                $url = $matches[1];  
     794                                $text = $matches[2]; 
     795                        } 
     796 
     797                        // Case 3: If no "|" exists in $contents, assume the match 
     798                        // refers to an internal page 
     799                        else if(preg_match("/^([^\|]+)$/s", $contents, $matches)) 
     800                        { 
     801                                $url = $matches[1]; 
     802                                $text = $matches[1]; 
     803                        } 
     804 
     805                        // Case 4: If a "|" symbol exists, assume two parts, a URL and 
     806                        // text 
     807                        else if(preg_match("/^(.*?)\s*\|\s*(.*?)$/s", $contents, $matches)) 
     808                        { 
     809                                if (!isset($matches[1])) $matches[1] = ''; 
     810                                if (!isset($matches[2])) $matches[2] = ''; 
     811                                $url = $matches[1]; 
     812                                $text = $matches[2]; 
     813                        } 
     814 
    777815                        if ($url) 
    778816                        { 
     
    787825                        } 
    788826                } 
     827 
    789828                // indented text 
    790829                elseif (preg_match("/(^|\n)([\t~]+)(-|&|([0-9a-zA-Z]+)\))?(\n|$)/s", $thing, $matches))