Merge "API: Add reference to the mailing list in errors and deprecation warnings"
[lhc/web/wiklou.git] / includes / title / MediaWikiTitleCodec.php
index 1bf05d9..7a71714 100644 (file)
@@ -21,6 +21,7 @@
  * @license GPL 2+
  * @author Daniel Kinzler
  */
+use MediaWiki\Interwiki\InterwikiLookup;
 use MediaWiki\MediaWikiServices;
 use MediaWiki\Linker\LinkTarget;
 
@@ -51,17 +52,25 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser {
         */
        protected $localInterwikis;
 
+       /**
+        * @var InterwikiLookup
+        */
+       protected $interwikiLookup;
+
        /**
         * @param Language $language The language object to use for localizing namespace names.
         * @param GenderCache $genderCache The gender cache for generating gendered namespace names
         * @param string[]|string $localInterwikis
+        * @param InterwikiLookup|null $interwikiLookup
         */
        public function __construct( Language $language, GenderCache $genderCache,
-               $localInterwikis = []
+               $localInterwikis = [], $interwikiLookup = null
        ) {
                $this->language = $language;
                $this->genderCache = $genderCache;
                $this->localInterwikis = (array)$localInterwikis;
+               $this->interwikiLookup = $interwikiLookup ?:
+                       MediaWikiServices::getInstance()->getInterwikiLookup();
        }
 
        /**
@@ -310,7 +319,6 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser {
                        if ( preg_match( $prefixRegexp, $dbkey, $m ) ) {
                                $p = $m[1];
                                $ns = $this->language->getNsIndex( $p );
-                               $interwikiLookup = MediaWikiServices::getInstance()->getInterwikiLookup();
                                if ( $ns !== false ) {
                                        # Ordinary namespace
                                        $dbkey = $m[2];
@@ -320,13 +328,13 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser {
                                                if ( $this->language->getNsIndex( $x[1] ) ) {
                                                        # Disallow Talk:File:x type titles...
                                                        throw new MalformedTitleException( 'title-invalid-talk-namespace', $text );
-                                               } elseif ( $interwikiLookup->isValidInterwiki( $x[1] ) ) {
+                                               } 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 );
                                                }
                                        }
-                               } elseif ( $interwikiLookup->isValidInterwiki( $p ) ) {
+                               } elseif ( $this->interwikiLookup->isValidInterwiki( $p ) ) {
                                        # Interwiki link
                                        $dbkey = $m[2];
                                        $parts['interwiki'] = $this->language->lc( $p );