function convertTitle( $t ) { return $t->getPrefixedText(); }
function getVariants() { return array( $this->mLang->getCode() ); }
function getPreferredVariant() { return $this->mLang->getCode(); }
+ function getDefaultVariant() { return $this->mLang->getCode(); }
+ function getURLVariant() { return ''; }
function getConvRuleTitle() { return false; }
function findVariantLink( &$l, &$n, $ignoreOtherCond = false ) { }
function getExtraHashOptions() { return ''; }
function getParsedTitle() { return ''; }
function markNoConversion( $text, $noParse = false ) { return $text; }
function convertCategoryKey( $key ) { return $key; }
- function convertLinkToAllVariants( $text ) { return autoConvertToAllVariants( $text ); }
+ function convertLinkToAllVariants( $text ) { return $this->autoConvertToAllVariants( $text ); }
function armourMath( $text ) { return $text; }
}
$this->namespaceNames[NS_PROJECT_TALK] =
$this->fixVariableInNamespace( $talk );
}
-
+
# Sometimes a language will be localised but not actually exist on this wiki.
foreach( $this->namespaceNames as $key => $text ) {
if ( !isset( $validNamespaces[$key] ) ) {
* escaping format.
*
* Supported format characters are dDjlNwzWFmMntLoYyaAgGhHiscrU. See the
- * PHP manual for definitions. "o" format character is supported since
- * PHP 5.1.0, previous versions return literal o.
- * There are a number of extensions, which start with "x":
+ * PHP manual for definitions. There are a number of extensions, which
+ * start with "x":
*
* xn Do not translate digits of the next numeric format character
* xN Toggle raw digit (xn) flag, stays set until explicitly unset
* @param $ts String: 14-character timestamp
* YYYYMMDDHHMMSS
* 01234567890123
- * @todo emulation of "o" format character for PHP pre 5.1.0
* @todo handling of "o" format character for Iranian, Hebrew, Hijri & Thai?
*/
function sprintfDate( $format, $ts ) {
}
$num = gmdate( 'L', $unix );
break;
- # 'o' is supported since PHP 5.1.0
- # return literal if not supported
- # TODO: emulation for pre 5.1.0 versions
case 'o':
if ( !$unix ) {
$unix = wfTimestamp( TS_UNIX, $ts );
}
- if ( version_compare( PHP_VERSION, '5.1.0' ) === 1 ) {
- $num = date( 'o', $unix );
- } else {
- $s .= 'o';
- }
+ $num = date( 'o', $unix );
break;
case 'Y':
$num = substr( $ts, 0, 4 );
} else {
$s .= $this->formatNum( $num, true );
}
- $num = false;
}
}
return $s;
return $s;
}
- /**
+ /**
* Hebrew Gematria number formatting up to 9999
*/
static function hebrewNumeral( $num ) {
* @return string
*/
function date( $ts, $adj = false, $format = true, $timecorrection = false ) {
+ $ts = wfTimestamp( TS_MW, $ts );
if ( $adj ) {
$ts = $this->userAdjust( $ts, $timecorrection );
}
* @return string
*/
function time( $ts, $adj = false, $format = true, $timecorrection = false ) {
+ $ts = wfTimestamp( TS_MW, $ts );
if ( $adj ) {
$ts = $this->userAdjust( $ts, $timecorrection );
}
}
function getMessage( $key ) {
- return self::$dataCache->getSubitem( $this->mCode, 'messages', $key );
+ return self::$dataCache->getSubitem( $this->getCodeForMessage(), 'messages', $key );
}
function getAllMessages() {
- return self::$dataCache->getItem( $this->mCode, 'messages' );
+ return self::$dataCache->getItem( $this->getCodeForMessage(), 'messages' );
}
function iconv( $in, $out, $string ) {
}
$isutf8 = preg_match( '/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
- '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s );
+ '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s );
if ( $isutf8 ) {
return $s;
}
# We got the first byte only of a multibyte char; remove it.
$string = substr( $string, 0, -1 );
} elseif ( $char >= 0x80 &&
- preg_match( '/^(.*)(?:[\xe0-\xef][\x80-\xbf]|' .
- '[\xf0-\xf7][\x80-\xbf]{1,2})$/', $string, $m ) )
+ preg_match( '/^(.*)(?:[\xe0-\xef][\x80-\xbf]|' .
+ '[\xf0-\xf7][\x80-\xbf]{1,2})$/', $string, $m ) )
{
# We chopped in the middle of a character; remove it
$string = $m[1];
*
* Note: tries to fix broken HTML with MWTidy
*
- * @param string $text String to truncate
+ * @param string $text HTML string to truncate
* @param int $length (zero/positive) Maximum length (excluding ellipses)
* @param string $ellipsis String to append to the truncated text
* @returns string
$tagType = 0; // 0-open, 1-close
$bracketState = 0; // 1-tag start, 2-tag name, 0-neither
$entityState = 0; // 0-not entity, 1-entity
- $tag = $ret = $ch = '';
- $openTags = array();
+ $tag = $ret = '';
+ $openTags = array(); // open tag stack
$textLen = strlen( $text );
for ( $pos = 0; $pos < $textLen; ++$pos ) {
$ch = $text[$pos];
if ( $displayLen == 0 ) {
return ''; // no text shown, nothing to format
}
- $this->truncate_endBracket( $tag, $text[$textLen - 1], $tagType, $openTags ); // for bad HTML
+ // Close the last tag if left unclosed by bad HTML
+ $this->truncate_endBracket( $tag, $text[$textLen - 1], $tagType, $openTags );
while ( count( $openTags ) > 0 ) {
$ret .= '</' . array_pop( $openTags ) . '>'; // close open tags
}
return $skipCount;
}
- // truncateHtml() helper function
- // (a) push or pop $tag from $openTags as needed
- // (b) clear $tag value
+ /*
+ * truncateHtml() helper function
+ * (a) push or pop $tag from $openTags as needed
+ * (b) clear $tag value
+ * @param String &$tag Current HTML tag name we are looking at
+ * @param int $tagType (0-open tag, 1-close tag)
+ * @param char $lastCh Character before the '>' that ended this tag
+ * @param array &$openTags Open tag stack (not accounting for $tag)
+ */
private function truncate_endBracket( &$tag, $tagType, $lastCh, &$openTags ) {
$tag = ltrim( $tag );
if ( $tag != '' ) {
}
/**
- * Get the list of variants supported by this langauge
+ * Get the list of variants supported by this language
* see sample implementation in LanguageZh.php
*
* @return array an array of language codes
return $this->mConverter->getVariants();
}
- function getPreferredVariant( $fromUser = true, $fromHeader = false ) {
- return $this->mConverter->getPreferredVariant( $fromUser, $fromHeader );
+ function getPreferredVariant() {
+ return $this->mConverter->getPreferredVariant();
+ }
+
+ function getDefaultVariant() {
+ return $this->mConverter->getDefaultVariant();
+ }
+
+ function getURLVariant() {
+ return $this->mConverter->getURLVariant();
}
/**
* If a language supports multiple variants, converts text
* into an array of all possible variants of the text:
* 'variant' => text in that variant
+ *
+ * @deprecated Use autoConvertToAllVariants()
*/
function convertLinkToAllVariants( $text ) {
return $this->mConverter->convertLinkToAllVariants( $text );
function getCode() {
return $this->mCode;
}
+
+ /**
+ * Get langcode for message
+ * Some language, like Chinese (zh, without any suffix), has multiple
+ * interface languages, we could choose a better one for user.
+ * Inherit class can override this function if necessary.
+ *
+ * @return string
+ */
+ function getCodeForMessage() {
+ return $this->getPreferredVariant();
+ }
function setCode( $code ) {
$this->mCode = $code;
}
function formatTimePeriod( $seconds ) {
- if ( $seconds < 10 ) {
- return $this->formatNum( sprintf( "%.1f", $seconds ) ) . $this->getMessageFromDB( 'seconds-abbrev' );
- } elseif ( $seconds < 60 ) {
+ if ( round( $seconds * 10 ) < 100 ) {
+ return $this->formatNum( sprintf( "%.1f", round( $seconds * 10 ) / 10 ) ) . $this->getMessageFromDB( 'seconds-abbrev' );
+ } elseif ( round( $seconds ) < 60 ) {
return $this->formatNum( round( $seconds ) ) . $this->getMessageFromDB( 'seconds-abbrev' );
- } elseif ( $seconds < 3600 ) {
+ } elseif ( round( $seconds ) < 3600 ) {
$minutes = floor( $seconds / 60 );
$secondsPart = round( fmod( $seconds, 60 ) );
if ( $secondsPart == 60 ) {