$this->rules[self::ALL][self::DM] = self::DM;
$this->rules[self::NONE][self::ISO2] = self::ISO1;
- $this->preferences = array(
+ $this->preferences = [
'default' => self::NONE,
'dmy' => self::DMY,
'mdy' => self::MDY,
'ymd' => self::YMD,
'ISO 8601' => self::ISO1,
- );
+ ];
}
/**
* Defaults to the site content language
* @return DateFormatter
*/
- public static function &getInstance( $lang = null ) {
- global $wgMemc, $wgContLang;
- static $dateFormatter = false;
+ public static function getInstance( $lang = null ) {
+ global $wgContLang, $wgMainCacheType;
+
$lang = $lang ? wfGetLangObj( $lang ) : $wgContLang;
- $key = wfMemcKey( 'dateformatter', $lang->getCode() );
+ $cache = ObjectCache::getLocalServerInstance( $wgMainCacheType );
+
+ static $dateFormatter = false;
if ( !$dateFormatter ) {
- $dateFormatter = $wgMemc->get( $key );
- if ( !$dateFormatter ) {
- $dateFormatter = new DateFormatter( $lang );
- $wgMemc->set( $key, $dateFormatter, 3600 );
- }
+ $dateFormatter = $cache->getWithSetCallback(
+ $cache->makeKey( 'dateformatter', $lang->getCode() ),
+ $cache::TTL_HOUR,
+ function () use ( $lang ) {
+ return new DateFormatter( $lang );
+ }
+ );
}
+
return $dateFormatter;
}
*
* @return string
*/
- public function reformat( $preference, $text, $options = array( 'linked' ) ) {
+ public function reformat( $preference, $text, $options = [ 'linked' ] ) {
$linked = in_array( 'linked', $options );
$match_whole = in_array( 'match-whole', $options );
// Horrible hack
if ( !$linked ) {
- $regex = str_replace( array( '\[\[', '\]\]' ), '', $regex );
+ $regex = str_replace( [ '\[\[', '\]\]' ], '', $regex );
}
if ( $match_whole ) {
// Another horrible hack
$this->mLinked = $linked;
- $text = preg_replace_callback( $regex, array( &$this, 'replace' ), $text );
+ $text = preg_replace_callback( $regex, [ &$this, 'replace' ], $text );
unset( $this->mLinked );
}
return $text;
$linked = $this->mLinked;
}
- $bits = array();
+ $bits = [];
$key = $this->keys[$this->mSource];
$keyLength = strlen( $key );
for ( $p = 0; $p < $keyLength; $p++ ) {
// strip piped links
$format = preg_replace( '/\[\[[^|]+\|([^\]]+)\]\]/', '$1', $format );
// strip remaining links
- $format = str_replace( array( '[[', ']]' ), '', $format );
+ $format = str_replace( [ '[[', ']]' ], '', $format );
}
# Construct new date
$text = $matches[0];
}
- $isoBits = array();
+ $isoBits = [];
if ( isset( $bits['y'] ) ) {
$isoBits[] = $bits['y'];
}
// Output is not strictly HTML (it's wikitext), but <span> is whitelisted.
$text = Html::rawElement( 'span',
- array( 'class' => 'mw-formatted-date', 'title' => $isoDate ), $text );
+ [ 'class' => 'mw-formatted-date', 'title' => $isoDate ], $text );
return $text;
}
* @return string regex to find the months with
*/
public function getMonthRegex() {
- $names = array();
+ $names = [];
for ( $i = 1; $i <= 12; $i++ ) {
$names[] = $this->lang->getMonthName( $i );
$names[] = $this->lang->getMonthAbbreviation( $i );