From: Kunal Mehta Date: Thu, 12 May 2016 18:25:51 +0000 (-0700) Subject: TitleFormatter: Match Title behavior for non-existent namespaces X-Git-Tag: 1.31.0-rc.0~6998^2 X-Git-Url: http://git.cyclocoop.org/%22.htmlspecialchars%28%24url_syndic%29.%22?a=commitdiff_plain;h=147ec4cad8b591831eec2c84a73f60e66abf0847;p=lhc%2Fweb%2Fwiklou.git TitleFormatter: Match Title behavior for non-existent namespaces In TitleFormatter::getPrefixedDBkey(), match the Title::getPrefixedDBkey() behavior for non-existent namespaces by using an empty string for the namespace and including a leading colon. Change-Id: I195c36df69963c7409711dd97bece078f61faf77 --- diff --git a/includes/title/MediaWikiTitleCodec.php b/includes/title/MediaWikiTitleCodec.php index 5c504f3513..38e9ecdacf 100644 --- a/includes/title/MediaWikiTitleCodec.php +++ b/includes/title/MediaWikiTitleCodec.php @@ -192,12 +192,18 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser { if ( $target->isExternal() ) { $key .= $target->getInterwiki() . ':'; } - $nsName = $this->getNamespaceName( - $target->getNamespace(), - $target->getText() - ); + // Try to get a namespace name, but fallback + // to empty string if it doesn't exist + try { + $nsName = $this->getNamespaceName( + $target->getNamespace(), + $target->getText() + ); + } catch ( InvalidArgumentException $e ) { + $nsName = ''; + } - if ( $nsName !== '' ) { + if ( $target->getNamespace() !== 0 ) { $key .= $nsName . ':'; } diff --git a/tests/phpunit/includes/title/MediaWikiTitleCodecTest.php b/tests/phpunit/includes/title/MediaWikiTitleCodecTest.php index 40065f559e..e55a3a4438 100644 --- a/tests/phpunit/includes/title/MediaWikiTitleCodecTest.php +++ b/tests/phpunit/includes/title/MediaWikiTitleCodecTest.php @@ -191,7 +191,10 @@ class MediaWikiTitleCodecTest extends MediaWikiTestCase { // names ending in "a" to be female. [ NS_USER, 'Lisa_Müller', '', '', 'de', 'Benutzerin:Lisa_Müller' ], - [ NS_MAIN, 'Remote_page', '', 'remotetestiw', 'en', 'remotetestiw:Remote_page' ] + [ NS_MAIN, 'Remote_page', '', 'remotetestiw', 'en', 'remotetestiw:Remote_page' ], + + // non-existent namespace + [ 10000000, 'Foobar', '', '', 'en', ':Foobar' ], ]; }