*/
public static function isValidCode( $code ) {
return
- strcspn( $code, ":/\\\000" ) === strlen( $code )
+ // People think language codes are html safe, so enforce it.
+ // Ideally we should only allow a-zA-Z0-9-
+ // but, .+ and other chars are often used for {{int:}} hacks
+ // see bugs 37564, 37587, 36938
+ strcspn( $code, ":/\\\000&<>'\"" ) === strlen( $code )
&& !preg_match( Title::getTitleInvalidRegex(), $code );
}
$s .= $num;
$raw = false;
} elseif ( $roman ) {
- $s .= self::romanNumeral( $num );
+ $s .= Language::romanNumeral( $num );
$roman = false;
} elseif ( $hebrewNum ) {
$s .= self::hebrewNumeral( $num );
}
/**
- * Roman number formatting up to 3000
+ * Roman number formatting up to 10000
*
* @param $num int
*
array( '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X' ),
array( '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC', 'C' ),
array( '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM', 'M' ),
- array( '', 'M', 'MM', 'MMM' )
+ array( '', 'M', 'MM', 'MMM', 'MMMM', 'MMMMM', 'MMMMMM', 'MMMMMMM', 'MMMMMMMM', 'MMMMMMMMM', 'MMMMMMMMMM' )
);
$num = intval( $num );
- if ( $num > 3000 || $num <= 0 ) {
+ if ( $num > 10000 || $num <= 0 ) {
return $num;
}
* @return int
*/
function userAdjust( $ts, $tz = false ) {
- global $wgUser, $wgLocaltimezone, $wgLocalTZoffset;
+ global $wgUser, $wgLocalTZoffset;
if ( $tz === false ) {
$tz = $wgUser->getOption( 'timecorrection' );
$data = explode( '|', $tz, 3 );
- if ( $data[0] == 'System' || $tz == '' ) {
- # Global timezone
- if ( isset( $wgLocaltimezone ) ) {
- $data[0] = 'ZoneInfo';
- $data[2] = $wgLocaltimezone;
- }
- # Global offset in minutes.
- if ( isset( $wgLocalTZoffset ) ) {
- $data[1] = $wgLocalTZoffset;
- }
- }
-
if ( $data[0] == 'ZoneInfo' ) {
wfSuppressWarnings();
$userTZ = timezone_open( $data[2] );
}
$minDiff = 0;
- if ( $data[0] == 'Offset' ) {
+ if ( $data[0] == 'System' || $tz == '' ) {
+ # Global offset in minutes.
+ if ( isset( $wgLocalTZoffset ) ) {
+ $minDiff = $wgLocalTZoffset;
+ }
+ } elseif ( $data[0] == 'Offset' ) {
$minDiff = intval( $data[1] );
} else {
$data = explode( ':', $tz );
* Take a list of strings and build a locale-friendly comma-separated
* list, using the local comma-separator message.
* The last two strings are chained with an "and".
+ * NOTE: This function will only work with standard numeric array keys (0, 1, 2…)
*
* @param $l Array
* @return string
function listToText( array $l ) {
$s = '';
$m = count( $l ) - 1;
- if ( $m == 1 ) {
+
+ if ( $m === 0 ) {
+ return $l[0];
+ } elseif ( $m === 1 ) {
return $l[0] . $this->getMessageFromDB( 'and' ) . $this->getMessageFromDB( 'word-separator' ) . $l[1];
} else {
for ( $i = $m; $i >= 0; $i-- ) {
/**
* Decode an expiry (block, protection, etc) which has come from the DB
*
- * @FIXME: why are we returnings DBMS-dependent strings???
+ * @todo 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
* @return String
+ * @since 1.18
*/
public function formatExpiry( $expiry, $format = true ) {
static $infinity, $infinityMsg;