r10669 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r10668‎ | r10669 | r10670 >
Date:15:47, 20 August 2005
Author:imsop
Status:old
Tags:
Comment:
(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.
Modified paths:
  • /branches/REL1_5/phase3/includes/Title.php (modified) (history)

Diff [purge]

Index: branches/REL1_5/phase3/includes/Title.php
@@ -1280,57 +1280,58 @@
12811281
12821282 $this->mDbkeyform = $t;
12831283
1284 - # Initial colon indicating main namespace
 1284+ # Initial colon indicates main namespace rather than specified default
 1285+ # but should not create invalid {ns,title} pairs such as {0,Project:Foo}
12851286 if ( ':' == $t{0} ) {
1286 - $r = substr( $t, 1 );
12871287 $this->mNamespace = NS_MAIN;
1288 - } else {
1289 - # Namespace or interwiki prefix
1290 - $firstPass = true;
1291 - do {
1292 - if ( preg_match( "/^(.+?)_*:_*(.*)$/S", $t, $m ) ) {
1293 - $p = $m[1];
1294 - $lowerNs = strtolower( $p );
1295 - if ( $ns = Namespace::getCanonicalIndex( $lowerNs ) ) {
1296 - # Canonical namespace
1297 - $t = $m[2];
1298 - $this->mNamespace = $ns;
1299 - } elseif ( $ns = $wgContLang->getNsIndex( $lowerNs )) {
1300 - # Ordinary namespace
1301 - $t = $m[2];
1302 - $this->mNamespace = $ns;
1303 - } elseif( $this->getInterwikiLink( $p ) ) {
1304 - if( !$firstPass ) {
1305 - # Can't make a local interwiki link to an interwiki link.
1306 - # That's just crazy!
 1288+ $t = substr( $t, 1 ); # remove the colon but continue processing
 1289+ }
 1290+
 1291+ # Namespace or interwiki prefix
 1292+ $firstPass = true;
 1293+ do {
 1294+ if ( preg_match( "/^(.+?)_*:_*(.*)$/S", $t, $m ) ) {
 1295+ $p = $m[1];
 1296+ $lowerNs = strtolower( $p );
 1297+ if ( $ns = Namespace::getCanonicalIndex( $lowerNs ) ) {
 1298+ # Canonical namespace
 1299+ $t = $m[2];
 1300+ $this->mNamespace = $ns;
 1301+ } elseif ( $ns = $wgContLang->getNsIndex( $lowerNs )) {
 1302+ # Ordinary namespace
 1303+ $t = $m[2];
 1304+ $this->mNamespace = $ns;
 1305+ } elseif( $this->getInterwikiLink( $p ) ) {
 1306+ if( !$firstPass ) {
 1307+ # Can't make a local interwiki link to an interwiki link.
 1308+ # That's just crazy!
 1309+ wfProfileOut( $fname );
 1310+ return false;
 1311+ }
 1312+
 1313+ # Interwiki link
 1314+ $t = $m[2];
 1315+ $this->mInterwiki = $p;
 1316+
 1317+ # Redundant interwiki prefix to the local wiki
 1318+ if ( 0 == strcasecmp( $this->mInterwiki, $wgLocalInterwiki ) ) {
 1319+ if( $t == '' ) {
 1320+ # Can't have an empty self-link
13071321 wfProfileOut( $fname );
13081322 return false;
13091323 }
1310 -
1311 - # Interwiki link
1312 - $t = $m[2];
1313 - $this->mInterwiki = $p;
1314 -
1315 - # Redundant interwiki prefix to the local wiki
1316 - if ( 0 == strcasecmp( $this->mInterwiki, $wgLocalInterwiki ) ) {
1317 - if( $t == '' ) {
1318 - # Can't have an empty self-link
1319 - wfProfileOut( $fname );
1320 - return false;
1321 - }
1322 - $this->mInterwiki = '';
1323 - $firstPass = false;
1324 - # Do another namespace split...
1325 - continue;
1326 - }
 1324+ $this->mInterwiki = '';
 1325+ $firstPass = false;
 1326+ # Do another namespace split...
 1327+ continue;
13271328 }
1328 - # If there's no recognized interwiki or namespace,
1329 - # then let the colon expression be part of the title.
13301329 }
1331 - break;
1332 - } while( true );
1333 - $r = $t;
1334 - }
 1330+ # If there's no recognized interwiki or namespace,
 1331+ # then let the colon expression be part of the title.
 1332+ }
 1333+ break;
 1334+ } while( true );
 1335+ $r = $t;
13351336
13361337 # We already know that some pages won't be in the database!
13371338 #

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r10666(bug 676) Avoid creating invalid title objects when there's a leading colon a...imsop15:30, 20 August 2005

Status & tagging log