# Read language names
global $wgLanguageNames;
-require_once( __DIR__ . '/Names.php' );
+require_once __DIR__ . '/Names.php';
if ( function_exists( 'mb_strtoupper' ) ) {
mb_internal_encoding( 'UTF-8' );
static $coreLanguageNames;
if ( $coreLanguageNames === null ) {
- include( MWInit::compiledPath( 'languages/Names.php' ) );
+ include MWInit::compiledPath( 'languages/Names.php' );
}
if ( isset( $coreLanguageNames[$tag] )
}
if ( file_exists( "$IP/languages/classes/$class.php" ) ) {
- include_once( "$IP/languages/classes/$class.php" );
+ include_once "$IP/languages/classes/$class.php";
}
}
static $coreLanguageNames;
if ( $coreLanguageNames === null ) {
- include( MWInit::compiledPath( 'languages/Names.php' ) );
+ include MWInit::compiledPath( 'languages/Names.php' );
}
$names = array();
}
/**
+ * Get all magic words from cache.
* @return array
*/
function getMagicWords() {
return self::$dataCache->getItem( $this->mCode, 'magicWords' );
}
+ /**
+ * Run the LanguageGetMagic hook once.
+ */
protected function doMagicHook() {
if ( $this->mMagicHookDone ) {
return;
* @param $mw
*/
function getMagic( $mw ) {
- $this->doMagicHook();
+ // Saves a function call
+ if ( ! $this->mMagicHookDone ) {
+ $this->doMagicHook();
+ }
if ( isset( $this->mMagicExtensions[$mw->mId] ) ) {
$rawEntry = $this->mMagicExtensions[$mw->mId];
} else {
- $magicWords = $this->getMagicWords();
- if ( isset( $magicWords[$mw->mId] ) ) {
- $rawEntry = $magicWords[$mw->mId];
- } else {
- $rawEntry = false;
- }
+ $rawEntry = self::$dataCache->getSubitem(
+ $this->mCode, 'magicWords', $mw->mId );
}
if ( !is_array( $rawEntry ) ) {
* @return string Correct form of plural for $count in this language
*/
function convertPlural( $count, $forms ) {
- if ( !count( $forms ) ) {
- return '';
- }
-
// Handle explicit n=pluralform cases
foreach ( $forms as $index => $form ) {
if ( preg_match( '/\d+=/i', $form ) ) {
unset( $forms[$index] );
}
}
+
$forms = array_values( $forms );
+ if ( !count( $forms ) ) {
+ return '';
+ }
$pluralForm = $this->getPluralRuleIndexNumber( $count );
$pluralForm = min( $pluralForm, count( $forms ) - 1 );