Another attempt at fixing bug 2. Call replaceInternalLinks() before
authorWil Mahan <wmahan@users.mediawiki.org>
Fri, 24 Sep 2004 18:29:01 +0000 (18:29 +0000)
committerWil Mahan <wmahan@users.mediawiki.org>
Fri, 24 Sep 2004 18:29:01 +0000 (18:29 +0000)
replaceExternalLinks(). Use placeholders for interwiki links, as with
other internal links, to avoid parsing them as external. Disallow
links to pages containing a URL protocol followed by a colon.
Unrelated: output a warning comment when a template loop is detected.

includes/OutputPage.php
includes/Parser.php
includes/Skin.php

index 0bb6b14..d240667 100644 (file)
@@ -935,6 +935,15 @@ class OutputPage {
                                "outputReplaceMatches",
                                $text);
                        wfProfileOut( $fname.'-replace' );
+
+                       wfProfileIn( $fname.'-interwiki' );
+                       global $wgInterwikiLinkHolders;
+                       $outputReplace = $wgInterwikiLinkHolders;
+                       $text = preg_replace_callback(
+                               '/<!--IWLINK (.*?)-->/',
+                               "outputReplaceMatches",
+                               $text);
+                       wfProfileOut( $fname.'-interwiki' );
                }
                wfProfileOut( $fname );
                return $colours;
index 823748e..d7ba5fa 100644 (file)
@@ -1,7 +1,5 @@
 <?php
 
-// require_once('Tokenizer.php');
-
 /**
  * File for Parser and related classes
  *
@@ -661,12 +659,11 @@ class Parser
                        $text = $wgDateFormatter->reformat( $this->mOptions->getDateFormat(), $text );
                }
                $text = $this->doAllQuotes( $text );
-               $text = $this->replaceExternalLinks( $text );
                $text = $this->doMagicLinks( $text );
                $text = $this->replaceInternalLinks ( $text );
                # Another call to replace links and images inside captions of images
                $text = $this->replaceInternalLinks ( $text );
-
+               $text = $this->replaceExternalLinks( $text );
                $text = $this->doTableStuff( $text );
                $text = $this->formatHeadings( $text, $isMain );
                $sk =& $this->mOptions->getSkin();
@@ -1130,6 +1127,14 @@ class Parser
                                continue;
                        }
 
+                       # Don't allow internal links to pages containing
+                       # PROTO: where PROTO is a valid URL protocol; these
+                       # should be external links.
+                       if (preg_match('/((?:'.URL_PROTOCOLS.'):)/', $m[1])) {
+                               $s .= $prefix . '[[' . $line ;
+                               continue;
+                       }
+
                        # Valid link forms:
                        # Foobar -- normal
                        # :Foobar -- override special treatment of prefix (images, language links)
@@ -1772,14 +1777,16 @@ class Parser
                # Did we encounter this template already? If yes, it is in the cache
                # and we need to check for loops.
                if ( !$found && isset( $this->mTemplates[$part1] ) ) {
+                       # set $text to cached message.
+                       $text = $this->mTemplates[$part1];
+                       $found = true;
+
                        # Infinite loop test
                        if ( isset( $this->mTemplatePath[$part1] ) ) {
                                $noparse = true;
                                $found = true;
+                               $text .= '<!-- WARNING: template loop detected -->';
                        }
-                       # set $text to cached message.
-                       $text = $this->mTemplates[$part1];
-                       $found = true;
                }
 
                # Load from database
index 6653572..d24cac3 100644 (file)
@@ -61,6 +61,8 @@ $wgLinkHolders = array(
        'texts' => array(),
        'titles' => array()
 );
+global $wgInterwikiLinkHolders;
+$wgInterwikiLinkHolders = array();
 
 /**
  * @todo document
@@ -1534,7 +1536,12 @@ class Skin {
                                        $trail = $m[2];
                                }
                        }
-                       $retVal = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>{$trail}";
+                       # Assume $this->postParseLinkColour(). This prevents
+                       # interwiki links from being parsed as external links.
+                       global $wgInterwikiLinkHolders;
+                       $t = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>";
+                       $nr = array_push($wgInterwikiLinkHolders, $t);
+                       $retVal = '<!--IWLINK '. ($nr-1) ."-->{$trail}";
                } elseif ( 0 == $nt->getNamespace() && "" == $nt->getText() ) {
                        $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
                } elseif ( ( -1 == $nt->getNamespace() ) ||