Merge "BacklinkCache performance tweaks"
[lhc/web/wiklou.git] / maintenance / language / languages.inc
index dcd9b9b..61ee424 100644 (file)
 /**
  * @ingroup MaintenanceLanguage
  */
-class languages {
-       protected $mLanguages; # List of languages
+class Languages {
+       /** @var array List of languages */
+       protected $mLanguages; #
 
-       protected $mRawMessages; # Raw list of the messages in each language
-       protected $mMessages; # Messages in each language (except for English), divided to groups
-       protected $mFallback; # Fallback language in each language
-       protected $mGeneralMessages; # General messages in English, divided to groups
-       protected $mIgnoredMessages; # All the messages which should be exist only in the English file
-       protected $mOptionalMessages; # All the messages which may be translated or not, depending on the language
+       /** @var array Raw list of the messages in each language  */
+       protected $mRawMessages;
 
-       protected $mNamespaceNames; # Namespace names
-       protected $mNamespaceAliases; # Namespace aliases
-       protected $mMagicWords; # Magic words
-       protected $mSpecialPageAliases; # Special page aliases
+       /** @var array Messages in each language (except for English), divided to groups */
+       protected $mMessages;
+
+       /** @var array Fallback language in each language */
+       protected $mFallback;
+
+       /** @var array General messages in English, divided to groups */
+       protected $mGeneralMessages;
+
+       /** @var array All the messages which should be exist only in the English file */
+       protected $mIgnoredMessages;
+
+       /** @var array All the messages which may be translated or not, depending on the language */
+       protected $mOptionalMessages;
+
+       /** @var array Namespace names */
+       protected $mNamespaceNames;
+
+       /** @var array Namespace aliases */
+       protected $mNamespaceAliases;
+
+       /** @var array Magic words */
+       protected $mMagicWords;
+
+       /** @var  array Special page aliases */
+       protected $mSpecialPageAliases;
 
        /**
         * Load the list of languages: all the Messages*.php
         * files in the languages directory.
         *
-        * @param $exif bool Treat the EXIF messages?
+        * @param $exif bool Treat the Exif messages?
         */
        function __construct( $exif = true ) {
-               require( __DIR__ . '/messageTypes.inc' );
+               require __DIR__ . '/messageTypes.inc';
                $this->mIgnoredMessages = $wgIgnoredMessages;
                if ( $exif ) {
                        $this->mOptionalMessages = array_merge( $wgOptionalMessages );
@@ -96,7 +115,8 @@ class languages {
                        isset( $this->mNamespaceNames[$code] ) &&
                        isset( $this->mNamespaceAliases[$code] ) &&
                        isset( $this->mMagicWords[$code] ) &&
-                       isset( $this->mSpecialPageAliases[$code] ) ) {
+                       isset( $this->mSpecialPageAliases[$code] )
+               ) {
                        return;
                }
                $this->mRawMessages[$code] = array();
@@ -107,7 +127,7 @@ class languages {
                $this->mSpecialPageAliases[$code] = array();
                $filename = Language::getMessagesFileName( $code );
                if ( file_exists( $filename ) ) {
-                       require( $filename );
+                       require $filename;
                        if ( isset( $messages ) ) {
                                $this->mRawMessages[$code] = $messages;
                        }
@@ -130,12 +150,16 @@ class languages {
        }
 
        /**
-        * Load the messages for a specific language (which is not English) and divide them to groups:
+        * Load the messages for a specific language (which is not English) and divide them to
+        * groups:
         * all - all the messages.
         * required - messages which should be translated in order to get a complete translation.
-        * optional - messages which can be translated, the fallback translation is used if not translated.
-        * obsolete - messages which should not be translated, either because they do not exist, or they are ignored messages.
-        * translated - messages which are either required or optional, but translated from English and needed.
+        * optional - messages which can be translated, the fallback translation is used if not
+        *   translated.
+        * obsolete - messages which should not be translated, either because they do not exist,
+        *   or they are ignored messages.
+        * translated - messages which are either required or optional, but translated from
+        *   English and needed.
         *
         * @param $code string The language code.
         */
@@ -154,7 +178,7 @@ class languages {
                        if ( isset( $this->mGeneralMessages['required'][$key] ) ) {
                                $this->mMessages[$code]['required'][$key] = $value;
                                $this->mMessages[$code]['translated'][$key] = $value;
-                       } else if ( isset( $this->mGeneralMessages['optional'][$key] ) ) {
+                       } elseif ( isset( $this->mGeneralMessages['optional'][$key] ) ) {
                                $this->mMessages[$code]['optional'][$key] = $value;
                                $this->mMessages[$code]['translated'][$key] = $value;
                        } else {
@@ -166,10 +190,13 @@ class languages {
        /**
         * Load the messages for English and divide them to groups:
         * all - all the messages.
-        * required - messages which should be translated to other languages in order to get a complete translation.
-        * optional - messages which can be translated to other languages, but it's not required for a complete translation.
+        * required - messages which should be translated to other languages in order to get a
+        *   complete translation.
+        * optional - messages which can be translated to other languages, but it's not required
+        *   for a complete translation.
         * ignored - messages which should not be translated to other languages.
-        * translatable - messages which are either required or optional, but can be translated from English.
+        * translatable - messages which are either required or optional, but can be translated
+        *   from English.
         */
        private function loadGeneralMessages() {
                if ( isset( $this->mGeneralMessages ) ) {
@@ -184,7 +211,7 @@ class languages {
                foreach ( $this->mGeneralMessages['all'] as $key => $value ) {
                        if ( in_array( $key, $this->mIgnoredMessages ) ) {
                                $this->mGeneralMessages['ignored'][$key] = $value;
-                       } else if ( in_array( $key, $this->mOptionalMessages ) ) {
+                       } elseif ( in_array( $key, $this->mOptionalMessages ) ) {
                                $this->mGeneralMessages['optional'][$key] = $value;
                                $this->mGeneralMessages['translatable'][$key] = $value;
                        } else {
@@ -199,9 +226,12 @@ class languages {
         * fallback language messages, divided to groups:
         * all - all the messages.
         * required - messages which should be translated in order to get a complete translation.
-        * optional - messages which can be translated, the fallback translation is used if not translated.
-        * obsolete - messages which should not be translated, either because they do not exist, or they are ignored messages.
-        * translated - messages which are either required or optional, but translated from English and needed.
+        * optional - messages which can be translated, the fallback translation is used if not
+        *   translated.
+        * obsolete - messages which should not be translated, either because they do not exist,
+        *   or they are ignored messages.
+        * translated - messages which are either required or optional, but translated from
+        *   English and needed.
         *
         * @param $code string The language code.
         *
@@ -209,21 +239,26 @@ class languages {
         */
        public function getMessages( $code ) {
                $this->loadMessages( $code );
+
                return $this->mMessages[$code];
        }
 
        /**
         * Get all the general English messages, divided to groups:
         * all - all the messages.
-        * required - messages which should be translated to other languages in order to get a complete translation.
-        * optional - messages which can be translated to other languages, but it's not required for a complete translation.
+        * required - messages which should be translated to other languages in
+        *   order to get a complete translation.
+        * optional - messages which can be translated to other languages, but it's
+        *   not required for a complete translation.
         * ignored - messages which should not be translated to other languages.
-        * translatable - messages which are either required or optional, but can be translated from English.
+        * translatable - messages which are either required or optional, but can be
+        *   translated from English.
         *
         * @return array The general English messages.
         */
        public function getGeneralMessages() {
                $this->loadGeneralMessages();
+
                return $this->mGeneralMessages;
        }
 
@@ -236,6 +271,7 @@ class languages {
         */
        public function getFallback( $code ) {
                $this->loadFile( $code );
+
                return $this->mFallback[$code];
        }
 
@@ -248,6 +284,7 @@ class languages {
         */
        public function getNamespaceNames( $code ) {
                $this->loadFile( $code );
+
                return $this->mNamespaceNames[$code];
        }
 
@@ -260,6 +297,7 @@ class languages {
         */
        public function getNamespaceAliases( $code ) {
                $this->loadFile( $code );
+
                return $this->mNamespaceAliases[$code];
        }
 
@@ -272,6 +310,7 @@ class languages {
         */
        public function getMagicWords( $code ) {
                $this->loadFile( $code );
+
                return $this->mMagicWords[$code];
        }
 
@@ -284,6 +323,7 @@ class languages {
         */
        public function getSpecialPageAliases( $code ) {
                $this->loadFile( $code );
+
                return $this->mSpecialPageAliases[$code];
        }
 
@@ -297,6 +337,7 @@ class languages {
        public function getUntranslatedMessages( $code ) {
                $this->loadGeneralMessages();
                $this->loadMessages( $code );
+
                return array_diff_key( $this->mGeneralMessages['required'], $this->mMessages[$code]['required'] );
        }
 
@@ -316,6 +357,7 @@ class languages {
                                $duplicateMessages[$key] = $value;
                        }
                }
+
                return $duplicateMessages;
        }
 
@@ -329,6 +371,7 @@ class languages {
        public function getObsoleteMessages( $code ) {
                $this->loadGeneralMessages();
                $this->loadMessages( $code );
+
                return $this->mMessages[$code]['obsolete'];
        }
 
@@ -348,11 +391,13 @@ class languages {
                        $missing = false;
                        foreach ( $variables as $var ) {
                                if ( preg_match( "/$var/sU", $this->mGeneralMessages['translatable'][$key] ) &&
-                                       !preg_match( "/$var/sU", $value ) ) {
+                                       !preg_match( "/$var/sU", $value )
+                               ) {
                                        $missing = true;
                                }
                                if ( !preg_match( "/$var/sU", $this->mGeneralMessages['translatable'][$key] ) &&
-                                       preg_match( "/$var/sU", $value ) ) {
+                                       preg_match( "/$var/sU", $value )
+                               ) {
                                        $missing = true;
                                }
                        }
@@ -360,6 +405,7 @@ class languages {
                                $mismatchMessages[$key] = $value;
                        }
                }
+
                return $mismatchMessages;
        }
 
@@ -375,10 +421,13 @@ class languages {
                $this->loadMessages( $code );
                $messagesWithoutPlural = array();
                foreach ( $this->mMessages[$code]['translated'] as $key => $value ) {
-                       if ( stripos( $this->mGeneralMessages['translatable'][$key], '{{plural:' ) !== false && stripos( $value, '{{plural:' ) === false ) {
+                       if ( stripos( $this->mGeneralMessages['translatable'][$key], '{{plural:' ) !== false &&
+                               stripos( $value, '{{plural:' ) === false
+                       ) {
                                $messagesWithoutPlural[$key] = $value;
                        }
                }
+
                return $messagesWithoutPlural;
        }
 
@@ -398,6 +447,7 @@ class languages {
                                $emptyMessages[$key] = $value;
                        }
                }
+
                return $emptyMessages;
        }
 
@@ -417,6 +467,7 @@ class languages {
                                $messagesWithWhitespace[$key] = $value;
                        }
                }
+
                return $messagesWithWhitespace;
        }
 
@@ -445,6 +496,7 @@ class languages {
                                $nonXHTMLMessages[$key] = $value;
                        }
                }
+
                return $nonXHTMLMessages;
        }
 
@@ -466,11 +518,11 @@ class languages {
                        '[POP]' => "\xE2\x80\xAC",
                        '[LRO]' => "\xE2\x80\xAD",
                        '[RLO]' => "\xE2\x80\xAB",
-                       '[ZWSP]'=> "\xE2\x80\x8B",
-                       '[NBSP]'=> "\xC2\xA0",
-                       '[WJ]'  => "\xE2\x81\xA0",
+                       '[ZWSP]' => "\xE2\x80\x8B",
+                       '[NBSP]' => "\xC2\xA0",
+                       '[WJ]' => "\xE2\x81\xA0",
                        '[BOM]' => "\xEF\xBB\xBF",
-                       '[FFFD]'=> "\xEF\xBF\xBD",
+                       '[FFFD]' => "\xEF\xBF\xBD",
                );
                $wrongRegExp = '/(' . implode( '|', array_values( $wrongChars ) ) . ')/sDu';
                $wrongCharsMessages = array();
@@ -482,6 +534,7 @@ class languages {
                                $wrongCharsMessages[$key] = $value;
                        }
                }
+
                return $wrongCharsMessages;
        }
 
@@ -500,17 +553,18 @@ class languages {
                foreach ( $this->mMessages[$code]['translated'] as $key => $value ) {
                        $matches = array();
                        preg_match_all( "/\[\[([{$tc}]+)(?:\\|(.+?))?]]/sDu", $value, $matches );
-                       for ($i = 0; $i < count($matches[0]); $i++ ) {
-                               if ( preg_match( "/.*project.*/isDu",  $matches[1][$i] ) ) {
+                       $numMatches = count( $matches[0] );
+                       for ( $i = 0; $i < $numMatches; $i++ ) {
+                               if ( preg_match( "/.*project.*/isDu", $matches[1][$i] ) ) {
                                        $messages[$key][] = $matches[0][$i];
                                }
                        }
 
-
                        if ( isset( $messages[$key] ) ) {
                                $messages[$key] = implode( $messages[$key], ", " );
                        }
                }
+
                return $messages;
        }
 
@@ -547,8 +601,8 @@ class languages {
                        if ( $a !== $b || $c !== $d ) {
                                $messages[$key] = "$a, $b, $c, $d";
                        }
-
                }
+
                return $messages;
        }
 
@@ -563,7 +617,10 @@ class languages {
                $this->loadFile( 'en' );
                $this->loadFile( $code );
                $namespacesDiff = array_diff_key( $this->mNamespaceNames['en'], $this->mNamespaceNames[$code] );
-               if ( isset( $namespacesDiff[NS_MAIN] ) ) unset( $namespacesDiff[NS_MAIN] );
+               if ( isset( $namespacesDiff[NS_MAIN] ) ) {
+                       unset( $namespacesDiff[NS_MAIN] );
+               }
+
                return $namespacesDiff;
        }
 
@@ -579,7 +636,7 @@ class languages {
                $namespaces = array();
 
                # Check default namespace name
-               if( isset( $this->mNamespaceNames[$code][NS_PROJECT_TALK] ) ) {
+               if ( isset( $this->mNamespaceNames[$code][NS_PROJECT_TALK] ) ) {
                        $default = $this->mNamespaceNames[$code][NS_PROJECT_TALK];
                        if ( strpos( $default, '$1' ) === false ) {
                                $namespaces[$default] = 'default';
@@ -587,7 +644,7 @@ class languages {
                }
 
                # Check namespace aliases
-               foreach( $this->mNamespaceAliases[$code] as $key => $value ) {
+               foreach ( $this->mNamespaceAliases[$code] as $key => $value ) {
                        if ( $value == NS_PROJECT_TALK && strpos( $key, '$1' ) === false ) {
                                $namespaces[$key] = '';
                        }
@@ -612,6 +669,7 @@ class languages {
                                $magicWords[$key] = $value[1];
                        }
                }
+
                return $magicWords;
        }
 
@@ -631,6 +689,7 @@ class languages {
                                $magicWords[$key] = $value[1];
                        }
                }
+
                return $magicWords;
        }
 
@@ -660,6 +719,7 @@ class languages {
                                }
                        }
                }
+
                return $magicWords;
        }
 
@@ -683,6 +743,7 @@ class languages {
                                $magicWords[$key] = $local[0];
                        }
                }
+
                return $magicWords;
        }
 
@@ -702,6 +763,7 @@ class languages {
                                $specialPageAliases[$key] = $value[0];
                        }
                }
+
                return $specialPageAliases;
        }
 
@@ -721,12 +783,12 @@ class languages {
                                $specialPageAliases[$key] = $value[0];
                        }
                }
+
                return $specialPageAliases;
        }
 }
 
-class extensionLanguages extends languages {
-
+class ExtensionLanguages extends Languages {
        /**
         * @var MessageGroup
         */
@@ -758,9 +820,9 @@ class extensionLanguages extends languages {
         * @param $code string The language code.
         */
        protected function loadFile( $code ) {
-               if( !isset( $this->mRawMessages[$code] ) ) {
+               if ( !isset( $this->mRawMessages[$code] ) ) {
                        $this->mRawMessages[$code] = $this->mMessageGroup->load( $code );
-                       if( empty( $this->mRawMessages[$code] ) ) {
+                       if ( empty( $this->mRawMessages[$code] ) ) {
                                $this->mRawMessages[$code] = array();
                        }
                }