Merge "resourceloader: Removed tests for deprecated 'position' parameter"
[lhc/web/wiklou.git] / includes / title / MediaWikiTitleCodec.php
index 7a71714..890a870 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * A codec for %MediaWiki page titles.
+ * A codec for MediaWiki page titles.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -18,7 +18,6 @@
  * http://www.gnu.org/copyleft/gpl.html
  *
  * @file
- * @license GPL 2+
  * @author Daniel Kinzler
  */
 use MediaWiki\Interwiki\InterwikiLookup;
@@ -26,7 +25,7 @@ use MediaWiki\MediaWikiServices;
 use MediaWiki\Linker\LinkTarget;
 
 /**
- * A codec for %MediaWiki page titles.
+ * A codec for MediaWiki page titles.
  *
  * @note Normalization and validation is applied while parsing, not when formatting.
  * It's possible to construct a TitleValue with an invalid title, and use MediaWikiTitleCodec
@@ -86,7 +85,6 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser {
                if ( $this->language->needsGenderDistinction() &&
                        MWNamespace::hasGenderDistinction( $namespace )
                ) {
-
                        // NOTE: we are assuming here that the title text is a user name!
                        $gender = $this->genderCache->getGenderOf( $text, __METHOD__ );
                        $name = $this->language->getGenderNsText( $namespace, $gender );
@@ -302,7 +300,7 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser {
 
                # Initial colon indicates main namespace rather than specified default
                # but should not create invalid {ns,title} pairs such as {0,Project:Foo}
-               if ( $dbkey !== '' && ':' == $dbkey[0] ) {
+               if ( $dbkey !== '' && $dbkey[0] == ':' ) {
                        $parts['namespace'] = NS_MAIN;
                        $dbkey = substr( $dbkey, 1 ); # remove the colon but continue processing
                        $dbkey = trim( $dbkey, '_' ); # remove any subsequent whitespace
@@ -329,7 +327,6 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser {
                                                        # Disallow Talk:File:x type titles...
                                                        throw new MalformedTitleException( 'title-invalid-talk-namespace', $text );
                                                } elseif ( $this->interwikiLookup->isValidInterwiki( $x[1] ) ) {
-                                                       // TODO: get rid of global state!
                                                        # Disallow Talk:Interwiki:x type titles...
                                                        throw new MalformedTitleException( 'title-invalid-talk-namespace', $text );
                                                }
@@ -369,6 +366,7 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser {
                                        if ( $dbkey !== '' && $dbkey[0] == ':' ) {
                                                $parts['namespace'] = NS_MAIN;
                                                $dbkey = substr( $dbkey, 1 );
+                                               $dbkey = trim( $dbkey, '_' );
                                        }
                                }
                                # If there's no recognized interwiki or namespace,