* (bug 2726, 3397) Fix [[Special:]] and [[:Image]] links in action=render
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 28 Dec 2005 22:58:54 +0000 (22:58 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 28 Dec 2005 22:58:54 +0000 (22:58 +0000)
RELEASE-NOTES
includes/Parser.php

index 3e4ae5a..c146136 100644 (file)
@@ -367,6 +367,7 @@ fully support the editing toolbar, but was found to be too confusing.
 * (bug 4411) Fix messages diff link for classic skin
 * (bug 4385) Separate parser cache entries for non-editing users, so section
   edit links don't vanish / appear unwanted on protected pages
+* (bug 2726, 3397) Fix [[Special:]] and [[:Image]] links in action=render
 
 
 === Caveats ===
index 64255ea..b356a4a 100644 (file)
@@ -1410,7 +1410,7 @@ class Parser
                                                $text = $this->replaceInternalLinks($text);
 
                                                # cloak any absolute URLs inside the image markup, so replaceExternalLinks() won't touch them
-                                               $s .= $prefix . preg_replace( "/\b(" . wfUrlProtocols() . ')/', "{$this->mUniqPrefix}NOPARSE$1", $this->makeImage( $nt, $text) ) . $trail;
+                                               $s .= $prefix . $this->armorLinks( $this->makeImage( $nt, $text ) ) . $trail;
                                                $wgLinkCache->addImageLinkObj( $nt );
 
                                                wfProfileOut( "$fname-image" );
@@ -1465,11 +1465,11 @@ class Parser
                        if( $ns == NS_MEDIA ) {
                                $link = $sk->makeMediaLinkObj( $nt, $text );
                                # Cloak with NOPARSE to avoid replacement in replaceExternalLinks
-                               $s .= $prefix . str_replace( 'http://', "http{$this->mUniqPrefix}NOPARSE://", $link ) . $trail;
+                               $s .= $prefix . $this->armorLinks( $link ) . $trail;
                                $wgLinkCache->addImageLinkObj( $nt );
                                continue;
                        } elseif( $ns == NS_SPECIAL ) {
-                               $s .= $prefix . $sk->makeKnownLinkObj( $nt, $text, '', $trail );
+                               $s .= $prefix . $this->armorLinks( $sk->makeKnownLinkObj( $nt, $text, '', $trail ) );
                                continue;
                        } elseif( $ns == NS_IMAGE ) {
                                $img = Image::newFromTitle( $nt );
@@ -1477,7 +1477,7 @@ class Parser
                                        // Force a blue link if the file exists; may be a remote
                                        // upload on the shared repository, and we want to see its
                                        // auto-generated page.
-                                       $s .= $prefix . $sk->makeKnownLinkObj( $nt, $text, '', $trail );
+                                       $s .= $prefix . $this->armorLinks( $sk->makeKnownLinkObj( $nt, $text, '', $trail ) );
                                        continue;
                                }
                        }
@@ -1518,6 +1518,23 @@ class Parser
                }
                return $retVal;
        }
+       
+       /**
+        * Insert a NOPARSE hacky thing into any inline links in a chunk that's
+        * going to go through further parsing steps before inline URL expansion.
+        *
+        * In particular this is important when using action=render, which causes
+        * full URLs to be included.
+        *
+        * Oh man I hate our multi-layer parser!
+        *
+        * @param string more-or-less HTML
+        * @return string less-or-more HTML with NOPARSE bits
+        */
+       function armorLinks( $text ) {
+               return preg_replace( "/\b(" . wfUrlProtocols() . ')/',
+                       "{$this->mUniqPrefix}NOPARSE$1", $text );
+       }
 
        /**
         * Return true if subpage links should be expanded on this page.