From 9184dc83d66840afaf1224ec65cae76a379280b3 Mon Sep 17 00:00:00 2001 From: Robin Pepermans Date: Thu, 8 Mar 2012 20:56:26 +0000 Subject: [PATCH] Update core usage of getLanguageName[s]. --- includes/GlobalFunctions.php | 2 +- includes/SkinLegacy.php | 4 ++-- includes/SkinTemplate.php | 4 ++-- includes/api/ApiParse.php | 2 +- includes/api/ApiQuerySiteinfo.php | 14 ++------------ includes/cache/MessageCache.php | 7 +++---- includes/installer/WebInstaller.php | 2 +- includes/installer/WebInstallerPage.php | 4 ++-- includes/media/FormatMetadata.php | 7 +++---- includes/specials/SpecialAllmessages.php | 2 +- maintenance/language/StatOutputs.php | 4 ++-- maintenance/language/checkLanguage.inc | 3 +-- maintenance/language/languages.inc | 2 +- maintenance/language/transstat.php | 2 +- maintenance/rebuildLocalisationCache.php | 2 +- 15 files changed, 24 insertions(+), 37 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 3151755628..ce9c287e70 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1322,7 +1322,7 @@ function wfGetLangObj( $langcode = false ) { return $wgLang; } - $validCodes = array_keys( Language::getLanguageNames() ); + $validCodes = array_keys( Language::fetchLanguageNames() ); if( in_array( $langcode, $validCodes ) ) { # $langcode corresponds to a valid language. return Language::factory( $langcode ); diff --git a/includes/SkinLegacy.php b/includes/SkinLegacy.php index 7cdd0a079b..4db9da4af9 100644 --- a/includes/SkinLegacy.php +++ b/includes/SkinLegacy.php @@ -348,7 +348,7 @@ class LegacyTemplate extends BaseTemplate { } function otherLanguages() { - global $wgOut, $wgLang, $wgContLang, $wgHideInterlanguageLinks; + global $wgOut, $wgLang, $wgHideInterlanguageLinks; if ( $wgHideInterlanguageLinks ) { return ''; @@ -375,7 +375,7 @@ class LegacyTemplate extends BaseTemplate { $first = false; $nt = Title::newFromText( $l ); - $text = $wgContLang->getLanguageName( $nt->getInterwiki() ); + $text = Language::fetchLanguageName( $nt->getInterwiki() ); $s .= Html::element( 'a', array( 'href' => $nt->getFullURL(), 'title' => $nt->getText(), 'class' => "external" ), diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 68e595bdcf..2d198f9b0e 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -428,8 +428,8 @@ class SkinTemplate extends Skin { if ( $nt ) { $language_urls[] = array( 'href' => $nt->getFullURL(), - 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ? - $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ), + 'text' => ( Language::fetchLanguageName( $nt->getInterwiki() ) != '' ? + Language::fetchLanguageName( $nt->getInterwiki() ) : $l ), 'title' => $nt->getText(), 'class' => $class, 'lang' => $nt->getInterwiki(), diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 893491b9c4..141f779372 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -399,7 +399,7 @@ class ApiParse extends ApiBase { $langs = array(); foreach ( $languages as $l ) { $nt = Title::newFromText( $l ); - $text = $wgContLang->getLanguageName( $nt->getInterwiki() ); + $text = Language::fetchLanguageName( $nt->getInterwiki() ); $langs[] = Html::element( 'a', array( 'href' => $nt->getFullURL(), 'title' => $nt->getText(), 'class' => "external" ), diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index e95de21d94..c83be79815 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -273,12 +273,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { $params = $this->extractRequestParams(); $langCode = isset( $params['inlanguagecode'] ) ? $params['inlanguagecode'] : ''; - - if( $langCode ) { - $langNames = Language::getTranslatedLanguageNames( $langCode ); - } else { - $langNames = Language::getLanguageNames(); - } + $langNames = Language::fetchLanguageNames( $langCode ); $getPrefixes = Interwiki::getAllPrefixes( $local ); $data = array(); @@ -479,12 +474,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { public function appendLanguages( $property ) { $params = $this->extractRequestParams(); $langCode = isset( $params['inlanguagecode'] ) ? $params['inlanguagecode'] : ''; - - if( $langCode ) { - $langNames = Language::getTranslatedLanguageNames( $langCode ); - } else { - $langNames = Language::getLanguageNames(); - } + $langNames = Language::getLanguageNames( $langCode ); $data = array(); diff --git a/includes/cache/MessageCache.php b/includes/cache/MessageCache.php index a1d76dc45b..d1e658be0e 100644 --- a/includes/cache/MessageCache.php +++ b/includes/cache/MessageCache.php @@ -497,7 +497,7 @@ class MessageCache { if ( $code === 'en' ) { // Delete all sidebars, like for example on action=purge on the // sidebar messages - $codes = array_keys( Language::getLanguageNames() ); + $codes = array_keys( Language::fetchLanguageNames() ); } global $wgMemc; @@ -869,7 +869,7 @@ class MessageCache { * Clear all stored messages. Mainly used after a mass rebuild. */ function clear() { - $langs = Language::getLanguageNames( false ); + $langs = Language::fetchLanguageNames( null, 'mw' ); foreach ( array_keys($langs) as $code ) { # Global cache $this->mMemc->delete( wfMemcKey( 'messages', $code ) ); @@ -891,8 +891,7 @@ class MessageCache { } $lang = array_pop( $pieces ); - $validCodes = Language::getLanguageNames(); - if( !array_key_exists( $lang, $validCodes ) ) { + if( !Language::fetchLanguageName( $lang, null, 'mw' ) ) { return array( $key, $wgLanguageCode ); } diff --git a/includes/installer/WebInstaller.php b/includes/installer/WebInstaller.php index c340d9a392..eeeb7683c1 100644 --- a/includes/installer/WebInstaller.php +++ b/includes/installer/WebInstaller.php @@ -485,7 +485,7 @@ class WebInstaller extends Installer { public function getAcceptLanguage() { global $wgLanguageCode, $wgRequest; - $mwLanguages = Language::getLanguageNames(); + $mwLanguages = Language::fetchLanguageNames(); $headerLanguages = array_keys( $wgRequest->getAcceptLang() ); foreach ( $headerLanguages as $lang ) { diff --git a/includes/installer/WebInstallerPage.php b/includes/installer/WebInstallerPage.php index aa45f803f8..73a5ef2c22 100644 --- a/includes/installer/WebInstallerPage.php +++ b/includes/installer/WebInstallerPage.php @@ -162,7 +162,7 @@ class WebInstaller_Language extends WebInstallerPage { $userLang = $r->getVal( 'uselang' ); $contLang = $r->getVal( 'ContLang' ); - $languages = Language::getLanguageNames(); + $languages = Language::fetchLanguageNames(); $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) ); if ( !$lifetime ) { $lifetime = 1440; // PHP default @@ -233,7 +233,7 @@ class WebInstaller_Language extends WebInstallerPage { $s .= Html::openElement( 'select', array( 'id' => $name, 'name' => $name, 'tabindex' => $this->parent->nextTabIndex() ) ) . "\n"; - $languages = Language::getLanguageNames(); + $languages = Language::fetchLanguageNames(); ksort( $languages ); foreach ( $languages as $code => $lang ) { if ( isset( $wgDummyLanguageCodes[$code] ) ) continue; diff --git a/includes/media/FormatMetadata.php b/includes/media/FormatMetadata.php index 7125c96aee..24162524fc 100644 --- a/includes/media/FormatMetadata.php +++ b/includes/media/FormatMetadata.php @@ -800,7 +800,7 @@ class FormatMetadata { break; case 'LanguageCode': - $lang = $wgLang->getLanguageName( strtolower( $val ) ); + $lang = Language::fetchLanguageName( strtolower( $val ), $wgLang ); if ($lang) { $val = htmlspecialchars( $lang ); } else { @@ -941,7 +941,6 @@ class FormatMetadata { * this is treated as wikitext not html). */ private static function langItem( $value, $lang, $default = false, $noHtml = false ) { - global $wgContLang; if ( $lang === false && $default === false) { throw new MWException('$lang and $default cannot both ' . 'be false.'); @@ -966,11 +965,11 @@ class FormatMetadata { } $lowLang = strtolower( $lang ); - $langName = $wgContLang->getLanguageName( $lowLang ); + $langName = Language::fetchLanguageName( $lowLang ); if ( $langName === '' ) { //try just the base language name. (aka en-US -> en ). list( $langPrefix ) = explode( '-', $lowLang, 2 ); - $langName = $wgContLang->getLanguageName( $langPrefix ); + $langName = Language::fetchLanguageName( $langPrefix ); if ( $langName === '' ) { // give up. $langName = $lang; diff --git a/includes/specials/SpecialAllmessages.php b/includes/specials/SpecialAllmessages.php index d7acd86ee0..0c03871422 100644 --- a/includes/specials/SpecialAllmessages.php +++ b/includes/specials/SpecialAllmessages.php @@ -146,7 +146,7 @@ class AllmessagesTablePager extends TablePager { function buildForm() { global $wgScript; - $languages = Language::getLanguageNames( false ); + $languages = Language::fetchLanguageNames( null, 'mw' ); ksort( $languages ); $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-allmessages-form' ) ) . diff --git a/maintenance/language/StatOutputs.php b/maintenance/language/StatOutputs.php index befd0d7264..d77029e743 100644 --- a/maintenance/language/StatOutputs.php +++ b/maintenance/language/StatOutputs.php @@ -46,7 +46,7 @@ class statsOutput { /** Outputs WikiText */ class wikiStatsOutput extends statsOutput { function heading() { - global $wgDummyLanguageCodes, $wgContLang; + global $wgDummyLanguageCodes; $version = SpecialVersion::getVersion( 'nodb' ); echo "'''Statistics are based on:''' " . $version . "\n\n"; echo "'''Note:''' These statistics can be generated by running php maintenance/language/transstat.php.\n\n"; @@ -55,7 +55,7 @@ class wikiStatsOutput extends statsOutput { if( is_array( $wgDummyLanguageCodes ) ) { $dummyCodes = array(); foreach( $wgDummyLanguageCodes as $dummyCode => $correctCode ) { - $dummyCodes[] = $wgContLang->getLanguageName( $dummyCode ) . ' (' . $dummyCode . ')'; + $dummyCodes[] = Language::fetchLanguageName( $dummyCode ) . ' (' . $dummyCode . ')'; } echo ', as well as the following languages that are not intended for system message translations, usually because they redirect to other language codes: ' . implode( ', ', $dummyCodes ); } diff --git a/maintenance/language/checkLanguage.inc b/maintenance/language/checkLanguage.inc index 9865257fa6..11b00e148b 100644 --- a/maintenance/language/checkLanguage.inc +++ b/maintenance/language/checkLanguage.inc @@ -402,7 +402,6 @@ ENDS; * Output the checks results as wiki text. */ function outputWiki() { - global $wgContLang; $detailText = ''; $rows[] = '! Language !! Code !! Total !! ' . implode( ' !! ', array_diff( $this->checks, $this->nonMessageChecks() ) ); foreach ( $this->results as $code => $results ) { @@ -438,7 +437,7 @@ ENDS; # Don't list languages without problems continue; } - $language = $wgContLang->getLanguageName( $code ); + $language = Language::fetchLanguageName( $code ); $rows[] = "| $language || $code || $problems || " . implode( ' || ', $numbers ); } diff --git a/maintenance/language/languages.inc b/maintenance/language/languages.inc index 2b5c4499ad..15fa71249c 100644 --- a/maintenance/language/languages.inc +++ b/maintenance/language/languages.inc @@ -54,7 +54,7 @@ class languages { $this->mOptionalMessages = array_merge( $wgOptionalMessages, $wgEXIFMessages ); } - $this->mLanguages = array_keys( Language::getLanguageNames( true ) ); + $this->mLanguages = array_keys( Language::fetchLanguageNames( null, 'mwfile' ) ); sort( $this->mLanguages ); } diff --git a/maintenance/language/transstat.php b/maintenance/language/transstat.php index 36f214bf62..a2988417fa 100644 --- a/maintenance/language/transstat.php +++ b/maintenance/language/transstat.php @@ -102,7 +102,7 @@ foreach ( $wgLanguages->getLanguages() as $code ) { } # Calculate the numbers - $language = $wgContLang->getLanguageName( $code ); + $language = Language::fetchLanguageName( $code ); $fallback = $wgLanguages->getFallback( $code ); $messages = $wgLanguages->getMessages( $code ); $messagesNumber = count( $messages['translated'] ); diff --git a/maintenance/rebuildLocalisationCache.php b/maintenance/rebuildLocalisationCache.php index d1e47ee996..5915a6b02d 100644 --- a/maintenance/rebuildLocalisationCache.php +++ b/maintenance/rebuildLocalisationCache.php @@ -72,7 +72,7 @@ class RebuildLocalisationCache extends Maintenance { } $lc = new LocalisationCache_BulkLoad( $conf ); - $codes = array_keys( Language::getLanguageNames( true ) ); + $codes = array_keys( Language::fetchLanguageNames( null, 'mwfile' ) ); sort( $codes ); // Initialise and split into chunks -- 2.20.1