restore old order of replaceInternal/replaceExternal, mask absolute URLs
authorErik Moeller <erik@users.mediawiki.org>
Mon, 25 Oct 2004 05:24:23 +0000 (05:24 +0000)
committerErik Moeller <erik@users.mediawiki.org>
Mon, 25 Oct 2004 05:24:23 +0000 (05:24 +0000)
left behind by [[Media:]] links to prevent them from being parsed twice.

includes/Parser.php
includes/Skin.php

index 52f14f9..f66e68f 100644 (file)
@@ -679,8 +679,13 @@ class Parser
                        $text = $wgDateFormatter->reformat( $this->mOptions->getDateFormat(), $text );
                }
                $text = $this->doAllQuotes( $text );
-               $text = $this->replaceExternalLinks( $text );           
                $text = $this->replaceInternalLinks ( $text );
+               $text = $this->replaceExternalLinks( $text );           
+               
+               # replaceInternalLinks may sometimes leave behind
+               # absolute URLs, which have to be masked to hide them from replaceExternalLinks
+               $text = str_replace("http-noparse://","http://",$text);
+               
                $text = $this->doMagicLinks( $text );
                $text = $this->doTableStuff( $text );
                $text = $this->formatHeadings( $text, $isMain );
@@ -923,9 +928,8 @@ class Parser
        /**
         * Replace external links
         *
-        * Note: we have to do external links before the internal ones,
-        * and otherwise take great care in the order of things here, so
-        * that we don't end up interpreting some URLs twice.
+        * Note: this is all very hackish and the order of execution matters a lot.
+        * Make sure to run maintenance/parserTests.php if you change this code.
         *
         * @access private
         */
@@ -1313,7 +1317,7 @@ class Parser
 
                        # Special and Media are pseudo-namespaces; no pages actually exist in them
                        if( $ns == NS_MEDIA ) {
-                               $s .= $prefix . $sk->makeMediaLinkObj( $nt, $text ) . $trail;
+                               $s .= $prefix . $sk->makeMediaLinkObj( $nt, $text, true ) . $trail;
                                $wgLinkCache->addImageLinkObj( $nt );
                                continue;
                        } elseif( $ns == NS_SPECIAL ) {
index 16615f6..0b2ae7b 100644 (file)
@@ -1889,7 +1889,7 @@ class Skin {
                return $this->makeMediaLinkObj( $nt, $alt );
        }
 
-       function makeMediaLinkObj( $nt, $alt = '' ) {           
+       function makeMediaLinkObj( $nt, $alt = '', $nourl=false ) {             
                if ( ! isset( $nt ) )
                {
                        ### HOTFIX. Instead of breaking, return empty string.
@@ -1898,6 +1898,11 @@ class Skin {
                        $name = $nt->getDBKey();        
                        $img   = Image::newFromTitle( $nt );
                        $url = $img->getURL();
+                       # $nourl can be set by the parser
+                       # this is a hack to mask absolute URLs, so the parser doesn't
+                       # linkify them (it is currently not context-aware)
+                       # 2004-10-25
+                       if ($nourl) { $url=str_replace("http://","http-noparse://",$url) ; }
                        if ( empty( $alt ) ) {
                                $alt = preg_replace( '/\.(.+?)^/', '', $name );
                        }