*/
static private $fallbackLanguageCache = array();
+ /**
+ * Cache for language names
+ * @var MapCacheLRU|null
+ */
+ static private $languageNameCache;
+
/**
* Get a cached or new language object for a given language code
* @param string $code
# Re-order by namespace ID number...
ksort( $this->namespaceNames );
- wfRunHooks( 'LanguageGetNamespaces', array( &$this->namespaceNames ) );
+ Hooks::run( 'LanguageGetNamespaces', array( &$this->namespaceNames ) );
}
return $this->namespaceNames;
}
/**
+ * @deprecated since 1.24, doesn't handle conflicting aliases. Use
+ * SpecialPageFactory::getLocalNameFor instead.
* @param string $name
* @return string
*/
* @since 1.20
*/
public static function fetchLanguageNames( $inLanguage = null, $include = 'mw' ) {
+ wfProfileIn( __METHOD__ );
+ $cacheKey = $inLanguage === null ? 'null' : $inLanguage;
+ $cacheKey .= ":$include";
+ if ( self::$languageNameCache === null ) {
+ self::$languageNameCache = new MapCacheLRU( 20 );
+ }
+ if ( self::$languageNameCache->has( $cacheKey ) ) {
+ $ret = self::$languageNameCache->get( $cacheKey );
+ } else {
+ $ret = self::fetchLanguageNamesUncached( $inLanguage, $include );
+ self::$languageNameCache->set( $cacheKey, $ret );
+ }
+ wfProfileOut( __METHOD__ );
+ return $ret;
+ }
+
+ /**
+ * Uncached helper for fetchLanguageNames
+ * @param null|string $inLanguage Code of language in which to return the names
+ * Use null for autonyms (native names)
+ * @param string $include One of:
+ * 'all' all available languages
+ * 'mw' only if the language is defined in MediaWiki or wgExtraLanguageNames (default)
+ * 'mwfile' only if the language is in 'mw' *and* has a message file
+ * @return array Language code => language name
+ */
+ private static function fetchLanguageNamesUncached( $inLanguage = null, $include = 'mw' ) {
global $wgExtraLanguageNames;
static $coreLanguageNames;
if ( $inLanguage ) {
# TODO: also include when $inLanguage is null, when this code is more efficient
- wfRunHooks( 'LanguageGetTranslatedLanguageNames', array( &$names, $inLanguage ) );
+ Hooks::run( 'LanguageGetTranslatedLanguageNames', array( &$names, $inLanguage ) );
}
$mwNames = $wgExtraLanguageNames + $coreLanguageNames;
}
$this->mMagicHookDone = true;
wfProfileIn( 'LanguageGetMagic' );
- wfRunHooks( 'LanguageGetMagic', array( &$this->mMagicExtensions, $this->getCode() ) );
+ Hooks::run( 'LanguageGetMagic', array( &$this->mMagicExtensions, $this->getCode() ) );
wfProfileOut( 'LanguageGetMagic' );
}
/**
* Get special page names, as an associative array
- * case folded alias => real name
+ * canonical name => array of valid names, including aliases
* @return array
*/
function getSpecialPageAliases() {
// Initialise array
$this->mExtendedSpecialPageAliases =
self::$dataCache->getItem( $this->mCode, 'specialPageAliases' );
- wfRunHooks( 'LanguageGetSpecialPageAliases',
+ Hooks::run( 'LanguageGetSpecialPageAliases',
array( &$this->mExtendedSpecialPageAliases, $this->getCode() ) );
}
// the string does not have any number part. Eg: .12345
return $sign . $groupedNumber;
}
- $start = $end = strlen( $integerPart[0] );
+ $start = $end = ($integerPart) ? strlen( $integerPart[0] ) : 0;
while ( $start > 0 ) {
$match = $matches[0][$numMatches - 1];
$matchLen = strlen( $match );
public static function getMessagesFileName( $code ) {
global $IP;
$file = self::getFileName( "$IP/languages/messages/Messages", $code, '.php' );
- wfRunHooks( 'Language::getMessagesFileName', array( $code, &$file ) );
+ Hooks::run( 'Language::getMessagesFileName', array( $code, &$file ) );
return $file;
}