return $lang;
}
+ /**
+ * Get the LocalisationCache instance
+ */
public static function getLocalisationCache() {
if ( is_null( self::$dataCache ) ) {
global $wgLocalisationCacheConf;
self::$dataCache = new $class( $wgLocalisationCacheConf );
}
return self::$dataCache;
- }
+ }
function __construct() {
$this->mConverter = new FakeConverter($this);
}
function iconv( $in, $out, $string ) {
- # For most languages, this is a wrapper for iconv
- return iconv( $in, $out . '//IGNORE', $string );
+ # This is a wrapper for iconv in all languages except esperanto,
+ # which does some nasty x-conversions beforehand
+
+ # Even with //IGNORE iconv can whine about illegal characters in
+ # *input* string. We just ignore those too.
+ # REF: http://bugs.php.net/bug.php?id=37166
+ # REF: https://bugzilla.wikimedia.org/show_bug.cgi?id=16885
+ wfSuppressWarnings();
+ $text = iconv( $in, $out . '//IGNORE', $string );
+ wfRestoreWarnings();
+ return $text;
}
// callback functions for uc(), lc(), ucwords(), ucwordbreaks()
}
function ucfirst( $str ) {
- if ( empty($str) ) return $str;
- if ( ord($str[0]) < 128 ) return ucfirst($str);
- else return self::uc($str,true); // fall back to more complex logic in case of multibyte strings
+ $o = ord( $str );
+ if ( $o < 96 ) {
+ return $str;
+ } elseif ( $o < 128 ) {
+ return ucfirst($str);
+ } else {
+ // fall back to more complex logic in case of multibyte strings
+ return self::uc($str,true);
+ }
}
function uc( $str, $first = false ) {
}
function lcfirst( $str ) {
- if ( empty($str) ) return $str;
- if ( is_string( $str ) && ord($str[0]) < 128 ) {
- // editing string in place = cool
- $str[0]=strtolower($str[0]);
+ $o = ord( $str );
+ if ( !$o ) {
+ return strval( $str );
+ } elseif ( $o >= 128 ) {
+ return self::lc( $str, true );
+ } elseif ( $o > 96 ) {
+ return $str;
+ } else {
+ $str[0] = strtolower( $str[0] );
return $str;
}
- else return self::lc( $str, true );
}
function lc( $str, $first = false ) {
function isRTL() {
return self::$dataCache->getItem( $this->mCode, 'rtl' );
}
+
+ /**
+ * Return the correct HTML 'dir' attribute value for this language.
+ * @return String
+ */
+ function getDir() {
+ return $this->isRTL() ? 'rtl' : 'ltr';
+ }
+
+ /**
+ * Return 'left' or 'right' as appropriate alignment for line-start
+ * for this language's text direction.
+ *
+ * Should be equivalent to CSS3 'start' text-align value....
+ *
+ * @return String
+ */
+ function alignStart() {
+ return $this->isRTL() ? 'right' : 'left';
+ }
+
+ /**
+ * Return 'right' or 'left' as appropriate alignment for line-end
+ * for this language's text direction.
+ *
+ * Should be equivalent to CSS3 'end' text-align value....
+ *
+ * @return String
+ */
+ function alignEnd() {
+ return $this->isRTL() ? 'left' : 'right';
+ }
/**
* A hidden direction mark (LRM or RLM), depending on the language direction
}
# Fill a MagicWord object with data from here
- function getMagic( &$mw ) {
+ function getMagic( $mw ) {
if ( !$this->mMagicHookDone ) {
$this->mMagicHookDone = true;
+ wfProfileIn( 'LanguageGetMagic' );
wfRunHooks( 'LanguageGetMagic', array( &$this->mMagicExtensions, $this->getCode() ) );
+ wfProfileOut( 'LanguageGetMagic' );
}
if ( isset( $this->mMagicExtensions[$mw->mId] ) ) {
$rawEntry = $this->mMagicExtensions[$mw->mId];
/**
* Perform output conversion on a string, and encode for safe HTML output.
- * @param $text String
- * @param $isTitle Bool -- wtf?
+ * @param $text String text to be converted
+ * @param $isTitle Bool whether this conversion is for the article title
* @return string
* @todo this should get integrated somewhere sane
*/