MediaWiki r106642 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r106641‎ | r106642 (on ViewVC)‎ | r106643 >
Date:11:18, 19 December 2011
Author:maxsem
Status:ok
Tags:
Comment:
ParserFunctions: made {{#time}} respect parser's timestamp, just as {{CURRENTDATE}} and friends do
Modified paths:

Diff [purge]

Index: trunk/extensions/ParserFunctions/ParserFunctions_body.php
@@ -433,9 +433,15 @@
434434 public static function time( $parser, $format = '', $date = '', $language = '', $local = false ) {
435435 global $wgLocaltimezone;
436436 self::registerClearHook();
437 - if ( isset( self::$mTimeCache[$format][$date][$language][$local] ) ) {
438 - return self::$mTimeCache[$format][$date][$language][$local];
 437+ if ( $date === '' ) {
 438+ $cacheKey = $parser->getOptions()->getTimestamp();
 439+ $date = wfTimestamp( TS_ISO_8601, $cacheKey );
 440+ } else {
 441+ $cacheKey = $date;
439442 }
 443+ if ( isset( self::$mTimeCache[$format][$cacheKey][$language][$local] ) ) {
 444+ return self::$mTimeCache[$format][$cacheKey][$language][$local];
 445+ }
440446
441447 # compute the timestamp string $ts
442448 # PHP >= 5.2 can handle dates before 1970 or after 2038 using the DateTime object
@@ -456,13 +462,9 @@
457463 }
458464
459465 # Parse date
460 - if ( $date !== '' ) {
461 - # UTC is a default input timezone.
462 - $dateObject = new DateTime( $date, $utc );
463 - } else {
464 - # use current date and time
465 - $dateObject = new DateTime( 'now', $utc );
466 - }
 466+ # UTC is a default input timezone.
 467+ $dateObject = new DateTime( $date, $utc );
 468+
467469 # Set output timezone.
468470 if ( $local ) {
469471 if ( isset( $wgLocaltimezone ) ) {
@@ -503,7 +505,7 @@
504506 }
505507 }
506508 }
507 - self::$mTimeCache[$format][$date][$language][$local] = $result;
 509+ self::$mTimeCache[$format][$cacheKey][$language][$local] = $result;
508510 return $result;
509511 }
510512

Status & tagging log

  • 05:06, 5 July 2012 Krinkle (talk | contribs) changed the tags for r106642 [removed: parser]
  • 18:56, 12 January 2012 GWicke (talk | contribs) changed the status of r106642 [removed: new added: ok]
  • 07:13, 23 December 2011 RobLa (talk | contribs) changed the tags for r106642 [removed: parsing added: parser]
  • 07:12, 23 December 2011 RobLa (talk | contribs) changed the tags for r106642 [added: parsing]