X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fparser%2FDateFormatter.php;h=40da3685ab4a4f04aa405736050dd81ffed7ed04;hb=623eed968818809477e6184b1f4fa125f6dfc88c;hp=ef295ab217e7aea98cc3b83e76ee02ccd1890547;hpb=cf73ab56fff68ebf3eb3fc3d1d600c950b42e4dc;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/parser/DateFormatter.php b/includes/parser/DateFormatter.php index ef295ab217..40da3685ab 100644 --- a/includes/parser/DateFormatter.php +++ b/includes/parser/DateFormatter.php @@ -108,13 +108,13 @@ class DateFormatter { $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, - ); + ]; } /** @@ -124,18 +124,23 @@ class DateFormatter { * 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; } @@ -146,7 +151,7 @@ class 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 ); @@ -174,7 +179,7 @@ class DateFormatter { // Horrible hack if ( !$linked ) { - $regex = str_replace( array( '\[\[', '\]\]' ), '', $regex ); + $regex = str_replace( [ '\[\[', '\]\]' ], '', $regex ); } if ( $match_whole ) { @@ -186,7 +191,7 @@ class DateFormatter { // 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; @@ -203,7 +208,7 @@ class DateFormatter { $linked = $this->mLinked; } - $bits = array(); + $bits = []; $key = $this->keys[$this->mSource]; $keyLength = strlen( $key ); for ( $p = 0; $p < $keyLength; $p++ ) { @@ -227,7 +232,7 @@ class DateFormatter { // strip piped links $format = preg_replace( '/\[\[[^|]+\|([^\]]+)\]\]/', '$1', $format ); // strip remaining links - $format = str_replace( array( '[[', ']]' ), '', $format ); + $format = str_replace( [ '[[', ']]' ], '', $format ); } # Construct new date @@ -299,7 +304,7 @@ class DateFormatter { $text = $matches[0]; } - $isoBits = array(); + $isoBits = []; if ( isset( $bits['y'] ) ) { $isoBits[] = $bits['y']; } @@ -309,7 +314,7 @@ class DateFormatter { // Output is not strictly HTML (it's wikitext), but is whitelisted. $text = Html::rawElement( 'span', - array( 'class' => 'mw-formatted-date', 'title' => $isoDate ), $text ); + [ 'class' => 'mw-formatted-date', 'title' => $isoDate ], $text ); return $text; } @@ -319,7 +324,7 @@ class DateFormatter { * @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 );