Merge "Add special pages aliases for Luri (lrc) from translatewiki"
[lhc/web/wiklou.git] / includes / cache / LocalisationCache.php
index 03162c0..dc5a2eb 100644 (file)
@@ -257,9 +257,7 @@ class LocalisationCache {
         */
        public function getItem( $code, $key ) {
                if ( !isset( $this->loadedItems[$code][$key] ) ) {
-                       wfProfileIn( __METHOD__ . '-load' );
                        $this->loadItem( $code, $key );
-                       wfProfileOut( __METHOD__ . '-load' );
                }
 
                if ( $key === 'fallback' && isset( $this->shallowFallbacks[$code] ) ) {
@@ -280,9 +278,7 @@ class LocalisationCache {
                if ( !isset( $this->loadedSubitems[$code][$key][$subkey] ) &&
                        !isset( $this->loadedItems[$code][$key] )
                ) {
-                       wfProfileIn( __METHOD__ . '-load' );
                        $this->loadSubitem( $code, $key, $subkey );
-                       wfProfileOut( __METHOD__ . '-load' );
                }
 
                if ( isset( $this->data[$code][$key][$subkey] ) ) {
@@ -509,7 +505,6 @@ class LocalisationCache {
         * @return array
         */
        protected function readPHPFile( $_fileName, $_fileType ) {
-               wfProfileIn( __METHOD__ );
                // Disable APC caching
                wfSuppressWarnings();
                $_apcEnabled = ini_set( 'apc.cache_by_default', '0' );
@@ -526,10 +521,8 @@ class LocalisationCache {
                } elseif ( $_fileType == 'aliases' ) {
                        $data = compact( 'aliases' );
                } else {
-                       wfProfileOut( __METHOD__ );
                        throw new MWException( __METHOD__ . ": Invalid file type: $_fileType" );
                }
-               wfProfileOut( __METHOD__ );
 
                return $data;
        }
@@ -541,24 +534,20 @@ class LocalisationCache {
         * @return array Array with a 'messages' key, or empty array if the file doesn't exist
         */
        public function readJSONFile( $fileName ) {
-               wfProfileIn( __METHOD__ );
 
                if ( !is_readable( $fileName ) ) {
-                       wfProfileOut( __METHOD__ );
 
                        return array();
                }
 
                $json = file_get_contents( $fileName );
                if ( $json === false ) {
-                       wfProfileOut( __METHOD__ );
 
                        return array();
                }
 
                $data = FormatJson::decode( $json, true );
                if ( $data === null ) {
-                       wfProfileOut( __METHOD__ );
 
                        throw new MWException( __METHOD__ . ": Invalid JSON file: $fileName" );
                }
@@ -570,8 +559,6 @@ class LocalisationCache {
                        }
                }
 
-               wfProfileOut( __METHOD__ );
-
                // The JSON format only supports messages, none of the other variables, so wrap the data
                return array( 'messages' => $data );
        }
@@ -654,10 +641,16 @@ class LocalisationCache {
         * rules, and save the compiled rules in a process-local cache.
         *
         * @param string $fileName
+        * @throws MWException
         */
        protected function loadPluralFile( $fileName ) {
+               // Use file_get_contents instead of DOMDocument::load (T58439)
+               $xml = file_get_contents( $fileName );
+               if ( !$xml ) {
+                       throw new MWException( "Unable to read plurals file $fileName" );
+               }
                $doc = new DOMDocument;
-               $doc->load( $fileName );
+               $doc->loadXML( $xml );
                $rulesets = $doc->getElementsByTagName( "pluralRules" );
                foreach ( $rulesets as $ruleset ) {
                        $codes = $ruleset->getAttribute( 'locales' );
@@ -691,7 +684,6 @@ class LocalisationCache {
         */
        protected function readSourceFilesAndRegisterDeps( $code, &$deps ) {
                global $IP;
-               wfProfileIn( __METHOD__ );
 
                // This reads in the PHP i18n file with non-messages l10n data
                $fileName = Language::getMessagesFileName( $code );
@@ -712,8 +704,6 @@ class LocalisationCache {
                $deps['plurals'] = new FileDependency( "$IP/languages/data/plurals.xml" );
                $deps['plurals-mw'] = new FileDependency( "$IP/languages/data/plurals-mediawiki.xml" );
 
-               wfProfileOut( __METHOD__ );
-
                return $data;
        }
 
@@ -817,10 +807,8 @@ class LocalisationCache {
         */
        public function recache( $code ) {
                global $wgExtensionMessagesFiles;
-               wfProfileIn( __METHOD__ );
 
                if ( !$code ) {
-                       wfProfileOut( __METHOD__ );
                        throw new MWException( "Invalid language code requested" );
                }
                $this->recachedLangs[$code] = true;
@@ -865,8 +853,6 @@ class LocalisationCache {
                $codeSequence = array_merge( array( $code ), $coreData['fallbackSequence'] );
                $messageDirs = $this->getMessagesDirs();
 
-               wfProfileIn( __METHOD__ . '-fallbacks' );
-
                # Load non-JSON localisation data for extensions
                $extensionData = array_combine(
                        $codeSequence,
@@ -963,8 +949,6 @@ class LocalisationCache {
                        }
                }
 
-               wfProfileOut( __METHOD__ . '-fallbacks' );
-
                # Add cache dependencies for any referenced globals
                $deps['wgExtensionMessagesFiles'] = new GlobalDependency( 'wgExtensionMessagesFiles' );
                // $wgMessagesDirs is used in LocalisationCache::getMessagesDirs()
@@ -1006,7 +990,6 @@ class LocalisationCache {
                Hooks::run( 'LocalisationCacheRecache', array( $this, $code, &$allData, &$purgeBlobs ) );
 
                if ( is_null( $allData['namespaceNames'] ) ) {
-                       wfProfileOut( __METHOD__ );
                        throw new MWException( __METHOD__ . ': Localisation data failed sanity check! ' .
                                'Check that your languages/messages/MessagesEn.php file is intact.' );
                }
@@ -1021,7 +1004,6 @@ class LocalisationCache {
                }
 
                # Save to the persistent cache
-               wfProfileIn( __METHOD__ . '-write' );
                $this->store->startWrite( $code );
                foreach ( $allData as $key => $value ) {
                        if ( in_array( $key, self::$splitKeys ) ) {
@@ -1033,16 +1015,15 @@ class LocalisationCache {
                        }
                }
                $this->store->finishWrite();
-               wfProfileOut( __METHOD__ . '-write' );
 
                # Clear out the MessageBlobStore
                # HACK: If using a null (i.e. disabled) storage backend, we
                # can't write to the MessageBlobStore either
                if ( $purgeBlobs && !$this->store instanceof LCStoreNull ) {
-                       MessageBlobStore::getInstance()->clear();
+                       $blobStore = new MessageBlobStore();
+                       $blobStore->clear();
                }
 
-               wfProfileOut( __METHOD__ );
        }
 
        /**