From 29c06f2b2fd0579e31358e1a798fe8b6ce5616eb Mon Sep 17 00:00:00 2001 From: Rowan Collins Date: Sat, 20 Aug 2005 15:30:22 +0000 Subject: [PATCH] (bug 676) Avoid creating invalid title objects when there's a leading colon and a real namespace (as in {{:Project:Foo}}); should mean things like [[{{NAMESPACE}}:Foo]] should work too. --- includes/Title.php | 89 +++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 44 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index d4df8cfef9..b4c681c6b9 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1280,57 +1280,58 @@ class Title { $this->mDbkeyform = $t; - # Initial colon indicating main namespace + # Initial colon indicates main namespace rather than specified default + # but should not create invalid {ns,title} pairs such as {0,Project:Foo} if ( ':' == $t{0} ) { - $r = substr( $t, 1 ); $this->mNamespace = NS_MAIN; - } else { - # Namespace or interwiki prefix - $firstPass = true; - do { - if ( preg_match( "/^(.+?)_*:_*(.*)$/S", $t, $m ) ) { - $p = $m[1]; - $lowerNs = strtolower( $p ); - if ( $ns = Namespace::getCanonicalIndex( $lowerNs ) ) { - # Canonical namespace - $t = $m[2]; - $this->mNamespace = $ns; - } elseif ( $ns = $wgContLang->getNsIndex( $lowerNs )) { - # Ordinary namespace - $t = $m[2]; - $this->mNamespace = $ns; - } elseif( $this->getInterwikiLink( $p ) ) { - if( !$firstPass ) { - # Can't make a local interwiki link to an interwiki link. - # That's just crazy! + $t = substr( $t, 1 ); # remove the colon but continue processing + } + + # Namespace or interwiki prefix + $firstPass = true; + do { + if ( preg_match( "/^(.+?)_*:_*(.*)$/S", $t, $m ) ) { + $p = $m[1]; + $lowerNs = strtolower( $p ); + if ( $ns = Namespace::getCanonicalIndex( $lowerNs ) ) { + # Canonical namespace + $t = $m[2]; + $this->mNamespace = $ns; + } elseif ( $ns = $wgContLang->getNsIndex( $lowerNs )) { + # Ordinary namespace + $t = $m[2]; + $this->mNamespace = $ns; + } elseif( $this->getInterwikiLink( $p ) ) { + if( !$firstPass ) { + # Can't make a local interwiki link to an interwiki link. + # That's just crazy! + wfProfileOut( $fname ); + return false; + } + + # Interwiki link + $t = $m[2]; + $this->mInterwiki = $p; + + # Redundant interwiki prefix to the local wiki + if ( 0 == strcasecmp( $this->mInterwiki, $wgLocalInterwiki ) ) { + if( $t == '' ) { + # Can't have an empty self-link wfProfileOut( $fname ); return false; } - - # Interwiki link - $t = $m[2]; - $this->mInterwiki = $p; - - # Redundant interwiki prefix to the local wiki - if ( 0 == strcasecmp( $this->mInterwiki, $wgLocalInterwiki ) ) { - if( $t == '' ) { - # Can't have an empty self-link - wfProfileOut( $fname ); - return false; - } - $this->mInterwiki = ''; - $firstPass = false; - # Do another namespace split... - continue; - } + $this->mInterwiki = ''; + $firstPass = false; + # Do another namespace split... + continue; } - # If there's no recognized interwiki or namespace, - # then let the colon expression be part of the title. } - break; - } while( true ); - $r = $t; - } + # If there's no recognized interwiki or namespace, + # then let the colon expression be part of the title. + } + break; + } while( true ); + $r = $t; # We already know that some pages won't be in the database! # -- 2.20.1