summaryrefslogtreecommitdiff
path: root/languages/Language.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2007-01-11 19:06:07 +0000
committerPierre Schmitz <pierre@archlinux.de>2007-01-11 19:06:07 +0000
commita58285fd06c8113c45377c655dd43cef6337e815 (patch)
treedfe31d3d12652352fe44890b4811eda0728faefb /languages/Language.php
parent20194986f6638233732ba1fc3e838f117d3cc9ea (diff)
Aktualisierung auf MediaWiki 1.9.0
Diffstat (limited to 'languages/Language.php')
-rw-r--r--languages/Language.php100
1 files changed, 76 insertions, 24 deletions
diff --git a/languages/Language.php b/languages/Language.php
index 454d60e1..fd7786e5 100644
--- a/languages/Language.php
+++ b/languages/Language.php
@@ -51,7 +51,7 @@ class FakeConverter {
function markNoConversion($text, $noParse=false) {return $text;}
function convertCategoryKey( $key ) {return $key; }
function convertLinkToAllVariants($text){ return array( $this->mLang->getCode() => $text); }
- function setNoTitleConvert(){}
+ function armourMath($text){ return $text; }
}
#--------------------------------------------------------------------------
@@ -67,13 +67,15 @@ class Language {
'separatorTransformTable', 'fallback8bitEncoding', 'linkPrefixExtension',
'defaultUserOptionOverrides', 'linkTrail', 'namespaceAliases',
'dateFormats', 'datePreferences', 'datePreferenceMigrationMap',
- 'defaultDateFormat', 'extraUserToggles' );
+ 'defaultDateFormat', 'extraUserToggles', 'specialPageAliases' );
static public $mMergeableMapKeys = array( 'messages', 'namespaceNames', 'mathNames',
'dateFormats', 'defaultUserOptionOverrides', 'magicWords' );
static public $mMergeableListKeys = array( 'extraUserToggles' );
+ static public $mMergeableAliasListKeys = array( 'specialPageAliases' );
+
static public $mLocalisationCache = array();
static public $mWeekdayMsgs = array(
@@ -229,12 +231,8 @@ class Language {
*/
function getNsIndex( $text ) {
$this->load();
- $index = @$this->mNamespaceIds[$this->lc($text)];
- if ( is_null( $index ) ) {
- return false;
- } else {
- return $index;
- }
+ $lctext = $this->lc($text);
+ return isset( $this->mNamespaceIds[$lctext] ) ? $this->mNamespaceIds[$lctext] : false;
}
/**
@@ -248,6 +246,10 @@ class Language {
}
function specialPage( $name ) {
+ $aliases = $this->getSpecialPageAliases();
+ if ( isset( $aliases[$name][0] ) ) {
+ $name = $aliases[$name][0];
+ }
return $this->getNsText(NS_SPECIAL) . ':' . $name;
}
@@ -304,7 +306,7 @@ class Language {
* Get language names, indexed by code.
* If $customisedOnly is true, only returns codes with a messages file
*/
- function getLanguageNames( $customisedOnly = false ) {
+ public static function getLanguageNames( $customisedOnly = false ) {
global $wgLanguageNames;
if ( !$customisedOnly ) {
return $wgLanguageNames;
@@ -755,7 +757,7 @@ class Language {
function getMessage( $key ) {
$this->load();
- return @$this->messages[$key];
+ return isset( $this->messages[$key] ) ? $this->messages[$key] : null;
}
function getAllMessages() {
@@ -908,6 +910,21 @@ class Language {
$str );
}
+ /**
+ * Return a case-folded representation of $s
+ *
+ * This is a representation such that caseFold($s1)==caseFold($s2) if $s1
+ * and $s2 are the same except for the case of their characters. It is not
+ * necessary for the value returned to make sense when displayed.
+ *
+ * Do *not* perform any other normalisation in this function. If a caller
+ * uses this function when it should be using a more general normalisation
+ * function, then fix the caller.
+ */
+ function caseFold( $s ) {
+ return $this->uc( $s );
+ }
+
function checkTitleEncoding( $s ) {
if( is_array( $s ) ) {
wfDebugDieBacktrace( 'Given array to checkTitleEncoding.' );
@@ -937,6 +954,11 @@ class Language {
* @return string
*/
function stripForSearch( $string ) {
+ global $wgDBtype;
+ if ( $wgDBtype != 'mysql' ) {
+ return $string;
+ }
+
# MySQL fulltext index doesn't grok utf-8, so we
# need to fold cases and convert to hex
@@ -1084,6 +1106,20 @@ class Language {
}
/**
+ * Get special page names, as an associative array
+ * case folded alias => real name
+ */
+ function getSpecialPageAliases() {
+ $this->load();
+ if ( !isset( $this->mExtendedSpecialPageAliases ) ) {
+ $this->mExtendedSpecialPageAliases = $this->specialPageAliases;
+ wfRunHooks( 'LangugeGetSpecialPageAliases',
+ array( &$this->mExtendedSpecialPageAliases, $this->getCode() ) );
+ }
+ return $this->mExtendedSpecialPageAliases;
+ }
+
+ /**
* Italic is unsuitable for some languages
*
* @public
@@ -1135,6 +1171,17 @@ class Language {
return $number;
}
+ function parseFormattedNumber( $number ) {
+ $s = $this->digitTransformTable();
+ if (!is_null($s)) { $number = strtr($number, array_flip($s)); }
+
+ $s = $this->separatorTransformTable();
+ if (!is_null($s)) { $number = strtr($number, array_flip($s)); }
+
+ $number = strtr( $number, array (',' => '') );
+ return $number;
+ }
+
/**
* Adds commas to a given number
*
@@ -1246,9 +1293,11 @@ class Language {
* @param string $wordform1
* @param string $wordform2
* @param string $wordform3 (optional)
+ * @param string $wordform4 (optional)
+ * @param string $wordform5 (optional)
* @return string
*/
- function convertPlural( $count, $w1, $w2, $w3) {
+ function convertPlural( $count, $w1, $w2, $w3, $w4, $w5) {
return $count == '1' ? $w1 : $w2;
}
@@ -1309,16 +1358,16 @@ class Language {
return $this->mConverter->parserConvert( $text, $parser );
}
- # Tell the converter that it shouldn't convert titles
- function setNoTitleConvert(){
- $this->mConverter->setNotitleConvert();
- }
-
# Check if this is a language with variants
function hasVariants(){
return sizeof($this->getVariants())>1;
}
+ # Put custom tags (e.g. -{ }-) around math to prevent conversion
+ function armourMath($text){
+ return $this->mConverter->armourMath($text);
+ }
+
/**
* Perform output conversion on a string, and encode for safe HTML output.
@@ -1479,7 +1528,7 @@ class Language {
$cache = wfGetPrecompiledData( self::getFileName( "Messages", $code, '.ser' ) );
if ( $cache ) {
self::$mLocalisationCache[$code] = $cache;
- wfDebug( "Got localisation for $code from precompiled data file\n" );
+ wfDebug( "Language::loadLocalisation(): got localisation for $code from precompiled data file\n" );
wfProfileOut( __METHOD__ );
return self::$mLocalisationCache[$code]['deps'];
}
@@ -1499,10 +1548,10 @@ class Language {
if ( self::isLocalisationOutOfDate( $cache ) ) {
$wgMemc->delete( $memcKey );
$cache = false;
- wfDebug( "Localisation cache for $code had expired due to update of $file\n" );
+ wfDebug( "Language::loadLocalisation(): localisation cache for $code had expired due to update of $file\n" );
} else {
self::$mLocalisationCache[$code] = $cache;
- wfDebug( "Got localisation for $code from cache\n" );
+ wfDebug( "Language::loadLocalisation(): got localisation for $code from cache\n" );
wfProfileOut( __METHOD__ );
return $cache['deps'];
}
@@ -1511,25 +1560,26 @@ class Language {
wfProfileIn( __METHOD__ );
}
+ # Default fallback, may be overridden when the messages file is included
if ( $code != 'en' ) {
$fallback = 'en';
} else {
$fallback = false;
}
-
+
# Load the primary localisation from the source file
$filename = self::getMessagesFileName( $code );
if ( !file_exists( $filename ) ) {
- wfDebug( "No localisation file for $code, using implicit fallback to en\n" );
+ wfDebug( "Language::loadLocalisation(): no localisation file for $code, using implicit fallback to en\n" );
$cache = array();
$deps = array();
} else {
$deps = array( $filename => filemtime( $filename ) );
require( $filename );
$cache = compact( self::$mLocalisationKeys );
- wfDebug( "Got localisation for $code from source\n" );
+ wfDebug( "Language::loadLocalisation(): got localisation for $code from source\n" );
}
-
+
if ( !empty( $fallback ) ) {
# Load the fallback localisation, with a circular reference guard
if ( isset( $recursionGuard[$code] ) ) {
@@ -1550,6 +1600,8 @@ class Language {
$cache[$key] = $cache[$key] + $secondary[$key];
} elseif ( in_array( $key, self::$mMergeableListKeys ) ) {
$cache[$key] = array_merge( $secondary[$key], $cache[$key] );
+ } elseif ( in_array( $key, self::$mMergeableAliasListKeys ) ) {
+ $cache[$key] = array_merge_recursive( $cache[$key], $secondary[$key] );
}
}
} else {
@@ -1626,7 +1678,7 @@ class Language {
*/
static function getMessageFor( $key, $code ) {
self::loadLocalisation( $code );
- return @self::$mLocalisationCache[$code]['messages'][$key];
+ return isset( self::$mLocalisationCache[$code]['messages'][$key] ) ? self::$mLocalisationCache[$code]['messages'][$key] : null;
}
/**