From: Wil Mahan Date: Fri, 24 Sep 2004 18:29:01 +0000 (+0000) Subject: Another attempt at fixing bug 2. Call replaceInternalLinks() before X-Git-Tag: 1.5.0alpha1~1818 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/modifier.php?a=commitdiff_plain;h=486098370577c1fc6b6eeafbc4c5610668b4151a;p=lhc%2Fweb%2Fwiklou.git Another attempt at fixing bug 2. Call replaceInternalLinks() before 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. --- diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 0bb6b147b2..d240667070 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -935,6 +935,15 @@ class OutputPage { "outputReplaceMatches", $text); wfProfileOut( $fname.'-replace' ); + + wfProfileIn( $fname.'-interwiki' ); + global $wgInterwikiLinkHolders; + $outputReplace = $wgInterwikiLinkHolders; + $text = preg_replace_callback( + '//', + "outputReplaceMatches", + $text); + wfProfileOut( $fname.'-interwiki' ); } wfProfileOut( $fname ); return $colours; diff --git a/includes/Parser.php b/includes/Parser.php index 823748ea74..d7ba5fa93c 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -1,7 +1,5 @@ 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 .= ''; } - # set $text to cached message. - $text = $this->mTemplates[$part1]; - $found = true; } # Load from database diff --git a/includes/Skin.php b/includes/Skin.php index 6653572394..d24cac352d 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -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 = "{$text}{$inside}{$trail}"; + # Assume $this->postParseLinkColour(). This prevents + # interwiki links from being parsed as external links. + global $wgInterwikiLinkHolders; + $t = "{$text}{$inside}"; + $nr = array_push($wgInterwikiLinkHolders, $t); + $retVal = '{$trail}"; } elseif ( 0 == $nt->getNamespace() && "" == $nt->getText() ) { $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix ); } elseif ( ( -1 == $nt->getNamespace() ) ||