Merge "Convert Special:DeletedContributions to use OOUI."
[lhc/web/wiklou.git] / includes / title / MediaWikiTitleCodec.php
index 0e291ed..a937e75 100644 (file)
@@ -105,10 +105,16 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser {
         */
        public function formatTitle( $namespace, $text, $fragment = '', $interwiki = '' ) {
                if ( $namespace !== false ) {
-                       $namespace = $this->getNamespaceName( $namespace, $text );
+                       // Try to get a namespace name, but fallback
+                       // to empty string if it doesn't exist
+                       try {
+                               $nsName = $this->getNamespaceName( $namespace, $text );
+                       } catch ( InvalidArgumentException $e ) {
+                               $nsName = '';
+                       }
 
-                       if ( $namespace !== '' ) {
-                               $text = $namespace . ':' . $text;
+                       if ( $namespace !== 0 ) {
+                               $text = $nsName . ':' . $text;
                        }
                }
 
@@ -181,6 +187,37 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser {
                );
        }
 
+       /**
+        * @since 1.27
+        * @see TitleFormatter::getPrefixedDBkey()
+        * @param LinkTarget $target
+        * @return string
+        */
+       public function getPrefixedDBkey( LinkTarget $target ) {
+               $key = '';
+               if ( $target->isExternal() ) {
+                       $key .= $target->getInterwiki() . ':';
+               }
+               // 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 ( $target->getNamespace() !== 0 ) {
+                       $key .= $nsName . ':';
+               }
+
+               $key .= $target->getText();
+
+               return strtr( $key, ' ', '_' );
+       }
+
        /**
         * @see TitleFormatter::getText()
         *