Merge "Disable the db LCStore if the maintenance script doesn't need a db."
[lhc/web/wiklou.git] / languages / Language.php
index 9f00d04..b531f2a 100644 (file)
@@ -1,6 +1,21 @@
 <?php
 /**
- * Internationalisation code
+ * Internationalisation code.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
  *
  * @file
  * @ingroup Language
@@ -241,6 +256,7 @@ class Language {
         *
         * @param $code string
         *
+        * @throws MWException
         * @since 1.18
         * @return bool
         */
@@ -284,10 +300,6 @@ class Language {
                }
 
                if ( !defined( 'MW_COMPILED' ) ) {
-                       // Preload base classes to work around APC/PHP5 bug
-                       if ( file_exists( "$IP/languages/classes/$class.deps.php" ) ) {
-                               include_once( "$IP/languages/classes/$class.deps.php" );
-                       }
                        if ( file_exists( "$IP/languages/classes/$class.php" ) ) {
                                include_once( "$IP/languages/classes/$class.php" );
                        }
@@ -734,9 +746,8 @@ class Language {
                $mwNames = $wgExtraLanguageNames + $coreLanguageNames;
                foreach ( $mwNames as $mwCode => $mwName ) {
                        # - Prefer own MediaWiki native name when not using the hook
-                       #       TODO: prefer it always to make it consistent, but casing is different in CLDR
                        # - For other names just add if not added through the hook
-                       if ( ( $mwCode === $inLanguage && !$inLanguage ) || !isset( $names[$mwCode] ) ) {
+                       if ( $mwCode === $inLanguage || !isset( $names[$mwCode] ) ) {
                                $names[$mwCode] = $mwName;
                        }
                }
@@ -2396,8 +2407,12 @@ class Language {
                        return $s;
                }
 
-               $isutf8 = preg_match( '/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
-                               '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s );
+               if ( function_exists( 'mb_check_encoding' ) ) {
+                       $isutf8 = mb_check_encoding( $s, 'UTF-8' );
+               } else {
+                       $isutf8 = preg_match( '/^(?>[\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
+                                       '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s );
+               }
                if ( $isutf8 ) {
                        return $s;
                }
@@ -3673,6 +3688,9 @@ class Language {
        /**
         * Get the RFC 3066 code for this language object
         *
+        * NOTE: The return value of this function is NOT HTML-safe and must be escaped with
+        * htmlspecialchars() or similar
+        *
         * @return string
         */
        public function getCode() {
@@ -3682,6 +3700,10 @@ class Language {
        /**
         * Get the code in Bcp47 format which we can use
         * inside of html lang="" tags.
+        *
+        * NOTE: The return value of this function is NOT HTML-safe and must be escaped with
+        * htmlspecialchars() or similar.
+        *
         * @since 1.19
         * @return string
         */
@@ -4094,7 +4116,7 @@ class Language {
         * @param $title Title object to link
         * @param $offset Integer offset parameter
         * @param $limit Integer limit parameter
-        * @param $query String optional URL query parameter string
+        * @param $query array|String optional URL query parameter string
         * @param $atend Bool optional param for specified if this is the last page
         * @return String
         */