Merge "Refactor global function wfBCP47 to static function LanguageCode::bcp47"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 5 Oct 2017 17:55:50 +0000 (17:55 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 5 Oct 2017 17:55:50 +0000 (17:55 +0000)
1  2 
includes/GlobalFunctions.php
includes/OutputPage.php
includes/parser/CoreParserFunctions.php

@@@ -2350,7 -2350,6 +2350,7 @@@ function wfShellExecWithStderr( $cmd, &
   * @see $wgShellLocale
   */
  function wfInitShellLocale() {
 +      wfDeprecated( __FUNCTION__, '1.30' );
  }
  
  /**
@@@ -3167,29 -3166,13 +3167,13 @@@ function wfShorthandToInteger( $string 
   * See unit test for examples.
   * See mediawiki.language.bcp47 for the JavaScript implementation.
   *
+  * @deprecated since 1.31, use LanguageCode::bcp47() directly.
+  *
   * @param string $code The language code.
   * @return string The language code which complying with BCP 47 standards.
   */
  function wfBCP47( $code ) {
-       $codeSegment = explode( '-', $code );
-       $codeBCP = [];
-       foreach ( $codeSegment as $segNo => $seg ) {
-               // when previous segment is x, it is a private segment and should be lc
-               if ( $segNo > 0 && strtolower( $codeSegment[( $segNo - 1 )] ) == 'x' ) {
-                       $codeBCP[$segNo] = strtolower( $seg );
-               // ISO 3166 country code
-               } elseif ( ( strlen( $seg ) == 2 ) && ( $segNo > 0 ) ) {
-                       $codeBCP[$segNo] = strtoupper( $seg );
-               // ISO 15924 script code
-               } elseif ( ( strlen( $seg ) == 4 ) && ( $segNo > 0 ) ) {
-                       $codeBCP[$segNo] = ucfirst( strtolower( $seg ) );
-               // Use lowercase for other cases
-               } else {
-                       $codeBCP[$segNo] = strtolower( $seg );
-               }
-       }
-       $langCode = implode( '-', $codeBCP );
-       return $langCode;
+       return LanguageCode::bcp47( $code );
  }
  
  /**
diff --combined includes/OutputPage.php
@@@ -1596,7 -1596,7 +1596,7 @@@ class OutputPage extends ContextSource 
  
                if ( !$this->mParserOptions ) {
                        if ( !$this->getContext()->getUser()->isSafeToLoad() ) {
 -                              // $wgUser isn't loaded yet, so don't try to get a
 +                              // $wgUser isn't unstubbable yet, so don't try to get a
                                // ParserOptions for it. And don't cache this ParserOptions
                                // either.
                                $po = ParserOptions::newFromAnon();
                                        // IE and some other browsers use BCP 47 standards in
                                        // their Accept-Language header, like "zh-CN" or "zh-Hant".
                                        // We should handle these too.
-                                       $variantBCP47 = wfBCP47( $variant );
+                                       $variantBCP47 = LanguageCode::bcp47( $variant );
                                        if ( $variantBCP47 !== $variant ) {
                                                $aloption[] = 'substr=' . $variantBCP47;
                                        }
                                foreach ( $variants as $variant ) {
                                        $tags["variant-$variant"] = Html::element( 'link', [
                                                'rel' => 'alternate',
-                                               'hreflang' => wfBCP47( $variant ),
+                                               'hreflang' => LanguageCode::bcp47( $variant ),
                                                'href' => $this->getTitle()->getLocalURL(
                                                        [ 'variant' => $variant ] )
                                                ]
@@@ -493,7 -493,7 +493,7 @@@ class CoreParserFunctions 
         *
         * @param int|float $num
         * @param string $raw
 -       * @param Language $language
 +       * @param Language|StubUserLang $language
         * @return string
         */
        public static function formatRaw( $num, $raw, $language ) {
                $code = strtolower( $code );
                $inLanguage = strtolower( $inLanguage );
                $lang = Language::fetchLanguageName( $code, $inLanguage );
-               return $lang !== '' ? $lang : wfBCP47( $code );
+               return $lang !== '' ? $lang : LanguageCode::bcp47( $code );
        }
  
        /**