From 3d7f935aa7bcd9a92e9422f0c979691423a904f0 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 28 Dec 2005 22:58:54 +0000 Subject: [PATCH] * (bug 2726, 3397) Fix [[Special:]] and [[:Image]] links in action=render --- RELEASE-NOTES | 1 + includes/Parser.php | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 3e4ae5aa12..c14613644f 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 === diff --git a/includes/Parser.php b/includes/Parser.php index 64255ea073..b356a4a63b 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -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. -- 2.20.1