/**
* Create a language object for a given language code
* @param $code String
+ * @throws MWException
* @return Language
*/
protected static function newFromCode( $code ) {
if ( $usemsg && wfMessage( $msg )->exists() ) {
return $this->getMessageFromDB( $msg );
}
- $name = self::getLanguageName( $code );
+ $name = self::fetchLanguageName( $code );
if ( $name ) {
return $name; # if it's defined as a language name, show that
} else {
return self::fetchLanguageNames( $code, 'all' );
}
-
- /*
+ /**
* Get an array of language names, indexed by code.
* @param $inLanguage null|string: Code of language in which to return the names
- * Use null for autonyms (native names)
+ * Use null for autonyms (native names)
* @param $include string:
* 'all' all available languages
* 'mw' only if the language is defined in MediaWiki or wgExtraLanguageNames
* 'mwfile' only if the language is in 'mw' *and* has a message file
- * @return array|false: language code => language name, false if $include is wrong
+ * @return array|bool: language code => language name, false if $include is wrong
+ * @since 1.20
*/
- public static function fetchLanguageNames( $inLanguage = null, $include = 'all' ) {
+ public static function fetchLanguageNames( $inLanguage = null, $include = 'mw' ) {
global $wgExtraLanguageNames;
static $coreLanguageNames;
/**
* @param $code string: The code of the language for which to get the name
* @param $inLanguage null|string: Code of language in which to return the name (null for autonyms)
+ * @param $include string: 'all', 'mw' or 'mwfile'; see fetchLanguageNames()
* @return string: Language name or empty
* @since 1.20
*/
- public static function fetchLanguageName( $code, $inLanguage = null ) {
- $array = self::fetchLanguageNames( $inLanguage, 'all' );
+ public static function fetchLanguageName( $code, $inLanguage = null, $include = 'all' ) {
+ $array = self::fetchLanguageNames( $inLanguage, $include );
return !array_key_exists( $code, $array ) ? '' : $array[$code];
}
* @param $file string
* @param $string string
*
+ * @throws MWException
* @return string
*/
function transformUsingPairFile( $file, $string ) {
}
/**
- * A hidden direction mark (LRM or RLM), depending on the language direction
+ * A hidden direction mark (LRM or RLM), depending on the language direction.
+ * Unlike getDirMark(), this function returns the character as an HTML entity.
+ * This function should be used when the output is guaranteed to be HTML,
+ * because it makes the output HTML source code more readable. When
+ * the output is plain text or can be escaped, getDirMark() should be used.
+ *
+ * @param $opposite Boolean Get the direction mark opposite to your language
+ * @return string
+ */
+ function getDirMarkEntity( $opposite = false ) {
+ if ( $opposite ) { return $this->isRTL() ? '‎' : '‏'; }
+ return $this->isRTL() ? '‏' : '‎';
+ }
+
+ /**
+ * A hidden direction mark (LRM or RLM), depending on the language direction.
+ * This function produces them as invisible Unicode characters and
+ * the output may be hard to read and debug, so it should only be used
+ * when the output is plain text or can be escaped. When the output is
+ * HTML, use getDirMarkEntity() instead.
*
* @param $opposite Boolean Get the direction mark opposite to your language
* @return string
*/
function getDirMark( $opposite = false ) {
- $rtl = "\xE2\x80\x8F";
- $ltr = "\xE2\x80\x8E";
- if ( $opposite ) { return $this->isRTL() ? $ltr : $rtl; }
- return $this->isRTL() ? $rtl : $ltr;
+ $lrm = "\xE2\x80\x8E"; # LEFT-TO-RIGHT MARK, commonly abbreviated LRM
+ $rlm = "\xE2\x80\x8F"; # RIGHT-TO-LEFT MARK, commonly abbreviated RLM
+ if ( $opposite ) { return $this->isRTL() ? $lrm : $rlm; }
+ return $this->isRTL() ? $rlm : $lrm;
}
/**
* @param $prefix string Prepend this to the filename
* @param $code string Language code
* @param $suffix string Append this to the filename
+ * @throws MWException
* @return string $prefix . $mangledCode . $suffix
*/
public static function getFileName( $prefix = 'Language', $code, $suffix = '.php' ) {
/**
* Decode an expiry (block, protection, etc) which has come from the DB
*
+ * @FIXME: why are we returnings DBMS-dependent strings???
+ *
* @param $expiry String: Database expiry String
* @param $format Bool|Int true to process using language functions, or TS_ constant
* to return the expiry in a given timestamp