Merge "Set context on RedirectSpecialPage in MediaWiki.php"
[lhc/web/wiklou.git] / languages / LanguageConverter.php
index 41d282b..4eeba64 100644 (file)
@@ -539,27 +539,45 @@ class LanguageConverter {
         * @return string Namespace name for display
         */
        public function convertNamespace( $index, $variant = null ) {
+               if ( $index === NS_MAIN ) {
+                       return '';
+               }
+
                if ( $variant === null ) {
                        $variant = $this->getPreferredVariant();
                }
-               if ( $index === NS_MAIN ) {
-                       return '';
-               } else {
-                       // First check if a message gives a converted name in the target variant.
-                       $nsConvMsg = wfMessage( 'conversion-ns' . $index )->inLanguage( $variant );
-                       if ( $nsConvMsg->exists() ) {
-                               return $nsConvMsg->plain();
-                       }
-                       // Then check if a message gives a converted name in content language
-                       // which needs extra translation to the target variant.
+
+               $cache = ObjectCache::newAccelerator( CACHE_NONE );
+               $key = wfMemcKey( 'languageconverter', 'namespace-text', $index, $variant );
+               $nsVariantText = $cache->get( $key );
+               if ( $nsVariantText !== false ) {
+                       return $nsVariantText;
+               }
+
+               // First check if a message gives a converted name in the target variant.
+               $nsConvMsg = wfMessage( 'conversion-ns' . $index )->inLanguage( $variant );
+               if ( $nsConvMsg->exists() ) {
+                       $nsVariantText = $nsConvMsg->plain();
+               }
+
+               // Then check if a message gives a converted name in content language
+               // which needs extra translation to the target variant.
+               if ( $nsVariantText === false ) {
                        $nsConvMsg = wfMessage( 'conversion-ns' . $index )->inContentLanguage();
                        if ( $nsConvMsg->exists() ) {
-                               return $this->translate( $nsConvMsg->plain(), $variant );
+                               $nsVariantText = $this->translate( $nsConvMsg->plain(), $variant );
                        }
+               }
+
+               if ( $nsVariantText === false ) {
                        // No message exists, retrieve it from the target variant's namespace names.
                        $langObj = $this->mLangObj->factory( $variant );
-                       return $langObj->getFormattedNsText( $index );
+                       $nsVariantText = $langObj->getFormattedNsText( $index );
                }
+
+               $cache->set( $key, $nsVariantText, 60 );
+
+               return $nsVariantText;
        }
 
        /**
@@ -1035,24 +1053,12 @@ class LanguageConverter {
        }
 
        /**
-        * Hook to refresh the cache of conversion tables when
+        * Refresh the cache of conversion tables when
         * MediaWiki:Conversiontable* is updated.
-        * @private
         *
-        * @param WikiPage $page
-        * @param User $user User object for the current user
-        * @param Content $content New page content
-        * @param string $summary Edit summary of the edit
-        * @param bool $isMinor Was the edit marked as minor?
-        * @param null $isWatch Unused.
-        * @param null $section Unused.
-        * @param int $flags Bitfield
-        * @param Revision|null $revision New Revision object or null
-        * @return bool True
+        * @param Title $titleobj The Title of the page being updated
         */
-       function OnPageContentSaveComplete( $page, $user, $content, $summary, $isMinor,
-                       $isWatch, $section, $flags, $revision ) {
-               $titleobj = $page->getTitle();
+       public function updateConversionTable( Title $titleobj ) {
                if ( $titleobj->getNamespace() == NS_MEDIAWIKI ) {
                        $title = $titleobj->getDBkey();
                        $t = explode( '/', $title, 3 );
@@ -1063,23 +1069,6 @@ class LanguageConverter {
                                }
                        }
                }
-               return true;
-       }
-
-       /**
-        * Armour rendered math against conversion.
-        * Escape special chars in parsed math text. (in most cases are img elements)
-        *
-        * @param string $text Text to armour against conversion
-        * @return string Armoured text where { and } have been converted to
-        *   { and }
-        * @deprecated since 1.22 is no longer used
-        */
-       public function armourMath( $text ) {
-               // convert '-{' and '}-' to '-{' and '}-' to prevent
-               // any unwanted markup appearing in the math image tag.
-               $text = strtr( $text, array( '-{' => '-{', '}-' => '}-' ) );
-               return $text;
        }
 
        /**