Localization update for he.
[lhc/web/wiklou.git] / languages / Language.php
index 366ab53..8853ace 100644 (file)
@@ -39,7 +39,7 @@ class FakeConverter {
        function parserConvert($t, $p) {return $t;}
        function getVariants() { return array( $this->mLang->getCode() ); }
        function getPreferredVariant() {return $this->mLang->getCode(); }
-       function findVariantLink(&$l, &$n, $forTemplate = false) {}
+       function findVariantLink(&$l, &$n, $ignoreOtherCond = false) {}
        function getExtraHashOptions() {return '';}
        function getParsedTitle() {return '';}
        function markNoConversion($text, $noParse=false) {return $text;}
@@ -53,7 +53,7 @@ class FakeConverter {
  * @ingroup Language
  */
 class Language {
-       var $mConverter, $mVariant, $mVariants, $mCode, $mLoaded = false;
+       var $mConverter, $mVariants, $mCode, $mLoaded = false;
        var $mMagicExtensions = array(), $mMagicHookDone = false;
 
        static public $mLocalisationKeys = array(
@@ -1564,7 +1564,7 @@ class Language {
                        $n = $minLength-1;
                        $out = preg_replace(
                                "/\b(\w{1,$n})\b/",
-                               "$1U800",
+                               "$1u800",
                                $out );
                }
                
@@ -1576,7 +1576,7 @@ class Language {
                // "example.wikipedia.com" and "192.168.83.1" as well.
                $out = preg_replace(
                        "/(\w)\.(\w|\*)/u",
-                       "$1U82e$2",
+                       "$1u82e$2",
                        $out );
                
                wfProfileOut( __METHOD__ );
@@ -1589,7 +1589,7 @@ class Language {
         * settings or anything else of the sort.
         */
        protected function stripForSearchCallback( $matches ) {
-               return 'U8' . bin2hex( $matches[1] );
+               return 'u8' . bin2hex( $matches[1] );
        }
        
        /**
@@ -1989,7 +1989,19 @@ class Language {
                        $list,
                        wfMsgExt( 'comma-separator', array( 'escapenoentities', 'language' => $this ) ) );
        }
-       
+
+       /**
+        * Take a list of strings and build a locale-friendly semicolon-separated
+        * list, using the local semicolon-separator message.
+        * @param $list array of strings to put in a semicolon list
+        * @return string
+        */
+       function semicolonList( $list ) {
+               return implode(
+                       $list,
+                       wfMsgExt( 'semicolon-separator', array( 'escapenoentities', 'language' => $this ) ) );
+       }
+
        /**
         * Same as commaList, but separate it with the pipe instead.
         * @param $list array of strings to put in a pipe list
@@ -2016,7 +2028,12 @@ class Language {
         * @param $ellipsis String to append to the truncated text
         * @return string
         */
-       function truncate( $string, $length, $ellipsis = "" ) {
+       function truncate( $string, $length, $ellipsis = '...' ) {
+               # Use the localized ellipsis character
+               if( $ellipsis == '...' ) {
+                       $ellipsis = wfMsgExt( 'ellipsis', array( 'escapenoentities', 'language' => $this ) );
+               }
+
                if( $length == 0 ) {
                        return $ellipsis;
                }
@@ -2033,7 +2050,7 @@ class Language {
                        } elseif( $char >= 0x80 &&
                                  preg_match( '/^(.*)(?:[\xe0-\xef][\x80-\xbf]|' .
                                              '[\xf0-\xf7][\x80-\xbf]{1,2})$/', $string, $m ) ) {
-                           # We chopped in the middle of a character; remove it
+                               # We chopped in the middle of a character; remove it
                                $string = $m[1];
                        }
                        return $string . $ellipsis;
@@ -2210,86 +2227,9 @@ class Language {
                return $this->mConverter->getVariants();
        }
 
-       /**
-        * get preferred language variants.
-        * moved from LanguageConverter class
-        * @param boolean $fromUser Get it from $wgUser's preferences
-        * @return string the preferred language code
-        * @public
-        */
-       function getPreferredVariant( $fromUser = true ) {
-               global $wgUser, $wgRequest, $wgVariantArticlePath, $wgDefaultLanguageVariant;
-
-               if($this->mVariant)
-                       return $this->mVariant;
-
-               // figure out user lang without constructing wgLang to avoid infinite recursion
-               if( $fromUser )
-                       $defaultUserLang = $wgUser->getOption( 'language' );
-               else
-                       $defaultUserLang = $this->mConverter->mMainLanguageCode;
-               $userLang = $wgRequest->getVal( 'uselang', $defaultUserLang );
-               // see if interface language is same as content, if not, prevent conversion
-               if( ! in_array( $userLang, $this->mConverter->mVariants ) ){ 
-                       $this->mVariant = $this->mConverter->mMainLanguageCode; // no conversion
-                       return $this->mVariant;
-               }
-
-               // see if the preference is set in the request
-               $req = $wgRequest->getText( 'variant' );
-               if( in_array( $req, $this->mConverter->mVariants ) ) {
-                       $this->mVariant = $req;
-                       return $req;
-               }
-
-               // check the syntax /code/ArticleTitle
-               if($wgVariantArticlePath!=false && isset($_SERVER['SCRIPT_NAME'])){
-                       // Note: SCRIPT_NAME probably won't hold the correct value if PHP is run as CGI
-                       // (it will hold path to php.cgi binary), and might not exist on some very old PHP installations
-                       $scriptBase = basename( $_SERVER['SCRIPT_NAME'] );
-                       if(in_array($scriptBase,$this->mConverter->mVariants)){
-                               $this->mVariant = $scriptBase;
-                               return $this->mPreferredVariant;
-                       }
-               }
-
-               // get language variant preference from logged in users
-               // Don't call this on stub objects because that causes infinite 
-               // recursion during initialisation
-               if( $fromUser && $wgUser->isLoggedIn() )  {
-                       $this->mVariant = $wgUser->getOption('variant');
-                       return $this->mVariant;
-               }
-
-               // see if default variant is globaly set
-               if($wgDefaultLanguageVariant != false  &&  in_array( $wgDefaultLanguageVariant, $this->mVariants )){
-                       $this->mVariant = $wgDefaultLanguageVariant;
-                       return $this->mVariant;
-               }
-
-               # FIXME rewrite code for parsing http header. The current code
-               # is written specific for detecting zh- variants
-               if( !$this->mVariant ) {
-                       // see if some supported language variant is set in the
-                       // http header, but we don't set the mPreferredVariant
-                       // variable in case this is called before the user's
-                       // preference is loaded
-                       $pv=$this->mConverter->mMainLanguageCode;
-                       if(array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) {
-                               $header = str_replace( '_', '-', strtolower($_SERVER["HTTP_ACCEPT_LANGUAGE"]));
-                               $zh = strstr($header, $pv.'-');
-                               if($zh) {
-                                       $ary = split("[,;]",$zh);
-                                       $pv = $ary[0];
-                               }
-                       }
-                       // don't try to return bad variant
-                       if(in_array( $pv, $this->mConverter->mVariants ))
-                               return $pv;
-               }
-
-               return $this->mConverter->mMainLanguageCode;
 
+       function getPreferredVariant( $fromUser = true ) {
+               return $this->mConverter->getPreferredVariant( $fromUser );
        }
 
        /**
@@ -2300,10 +2240,12 @@ class Language {
         *
         * @param $link String: the name of the link
         * @param $nt Mixed: the title object of the link
+        * @param boolean $ignoreOtherCond: to disable other conditions when
+        *      we need to transclude a template or update a category's link
         * @return null the input parameters may be modified upon return
         */
-       function findVariantLink( &$link, &$nt, $forTemplate = false ) {
-               $this->mConverter->findVariantLink($link, $nt, $forTemplate );
+       function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
+               $this->mConverter->findVariantLink( $link, $nt, $ignoreOtherCond );
        }
 
        /**
@@ -2311,7 +2253,6 @@ class Language {
         * into an array of all possible variants of the text:
         *  'variant' => text in that variant
         */
-
        function convertLinkToAllVariants($text){
                return $this->mConverter->convertLinkToAllVariants($text);
        }
@@ -2472,6 +2413,12 @@ class Language {
                        $cache = compact( self::$mLocalisationKeys );
                        wfDebug( "Language::loadLocalisation(): got localisation for $code from source\n" );
                }
+               
+               # Load magic word source file
+               global $IP;
+               $filename = "$IP/includes/MagicWord.php";
+               $newDeps = array( $filename => filemtime( $filename ) );
+               $deps = array_merge( $deps, $newDeps );
 
                if ( !empty( $fallback ) ) {
                        # Load the fallback localisation, with a circular reference guard
@@ -2548,6 +2495,10 @@ class Language {
                        self::loadLocalisation( $cache );
                        $cache = self::$mLocalisationCache[$cache];
                }
+               // At least one language file and the MagicWord file needed
+               if( count($cache['deps']) < 2 ) {
+                       return true;
+               }
                $expired = false;
                foreach ( $cache['deps'] as $file => $mtime ) {
                        if ( !file_exists( $file ) || filemtime( $file ) > $mtime ) {
@@ -2642,16 +2593,8 @@ class Language {
                        $this->namespaceNames[NS_PROJECT_TALK] = $wgMetaNamespaceTalk;
                } else {
                        $talk = $this->namespaceNames[NS_PROJECT_TALK];
-                       $talk = str_replace( '$1', $wgMetaNamespace, $talk );
-
-                       # Allow grammar transformations
-                       # Allowing full message-style parsing would make simple requests 
-                       # such as action=raw much more expensive than they need to be. 
-                       # This will hopefully cover most cases.
-                       $talk = preg_replace_callback( '/{{grammar:(.*?)\|(.*?)}}/i', 
-                               array( &$this, 'replaceGrammarInNamespace' ), $talk );
-                       $talk = str_replace( ' ', '_', $talk );
-                       $this->namespaceNames[NS_PROJECT_TALK] = $talk;
+                       $this->namespaceNames[NS_PROJECT_TALK] =
+                               $this->fixVariableInNamespace( $talk );
                }
                
                # The above mixing may leave namespaces out of canonical order.
@@ -2668,6 +2611,11 @@ class Language {
                }
                if ( $this->namespaceAliases ) {
                        foreach ( $this->namespaceAliases as $name => $index ) {
+                               if ( $index === NS_PROJECT_TALK ) {
+                                       unset( $this->namespaceAliases[$name] );
+                                       $name = $this->fixVariableInNamespace( $name );
+                                       $this->namespaceAliases[$name] = $index;
+                               }
                                $this->mNamespaceIds[$this->lc($name)] = $index;
                        }
                }
@@ -2683,6 +2631,21 @@ class Language {
                wfProfileOut( __METHOD__ );
        }
 
+       function fixVariableInNamespace( $talk ) {
+               if ( strpos( $talk, '$1' ) === false ) return $talk;
+
+               global $wgMetaNamespace;
+               $talk = str_replace( '$1', $wgMetaNamespace, $talk );
+
+               # Allow grammar transformations
+               # Allowing full message-style parsing would make simple requests 
+               # such as action=raw much more expensive than they need to be. 
+               # This will hopefully cover most cases.
+               $talk = preg_replace_callback( '/{{grammar:(.*?)\|(.*?)}}/i', 
+                       array( &$this, 'replaceGrammarInNamespace' ), $talk );
+               return str_replace( ' ', '_', $talk );
+       }
+
        function replaceGrammarInNamespace( $m ) {
                return $this->convertGrammar( trim( $m[2] ), trim( $m[1] ) );
        }