From d2f27cf300549eabdd9ed1a4152f351a3cb33a5c Mon Sep 17 00:00:00 2001 From: Erik Moeller Date: Mon, 25 Oct 2004 05:24:23 +0000 Subject: [PATCH] restore old order of replaceInternal/replaceExternal, mask absolute URLs left behind by [[Media:]] links to prevent them from being parsed twice. --- includes/Parser.php | 14 +++++++++----- includes/Skin.php | 7 ++++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/includes/Parser.php b/includes/Parser.php index 52f14f9471..f66e68fefb 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -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 ) { diff --git a/includes/Skin.php b/includes/Skin.php index 16615f6e9e..0b2ae7b657 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -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 ); } -- 2.20.1