X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FMWTimestamp.php;h=f2bd6ba56919463e03918b3d8e6e847c0146fed0;hb=e7c9096ecc084bb81a99d3acc949c32b0ef49d56;hp=26f5e543702cb71df7689f3478ca6142bbbfc75d;hpb=e0615b688d8e1caaec1992fa467ebf7b4e5f486f;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/MWTimestamp.php b/includes/MWTimestamp.php index 26f5e54370..f2bd6ba569 100644 --- a/includes/MWTimestamp.php +++ b/includes/MWTimestamp.php @@ -182,6 +182,11 @@ class MWTimestamp { $output .= ' GMT'; } + if ( $style == TS_MW && strlen( $output ) !== 14 ) { + throw new TimestampException( __METHOD__ . ': The timestamp cannot be represented in ' . + 'the specified format' ); + } + return $output; } @@ -194,42 +199,19 @@ class MWTimestamp { * * @since 1.20 * @since 1.22 Uses Language::getHumanTimestamp to produce the timestamp + * @deprecated since 1.26 Use Language::getHumanTimestamp directly * - * @param MWTimestamp|null $relativeTo The base timestamp to compare to - * (defaults to now). - * @param User|null $user User the timestamp is being generated for (or null - * to use main context's user). - * @param Language|null $lang Language to use to make the human timestamp - * (or null to use main context's language). + * @param MWTimestamp|null $relativeTo The base timestamp to compare to (defaults to now) + * @param User|null $user User the timestamp is being generated for (or null to use main context's user) + * @param Language|null $lang Language to use to make the human timestamp (or null to use main context's language) * @return string Formatted timestamp */ - public function getHumanTimestamp( MWTimestamp $relativeTo = null, - User $user = null, Language $lang = null - ) { - if ( $relativeTo === null ) { - $relativeTo = new self(); - } - if ( $user === null ) { - $user = RequestContext::getMain()->getUser(); - } + public function getHumanTimestamp( MWTimestamp $relativeTo = null, User $user = null, Language $lang = null ) { if ( $lang === null ) { $lang = RequestContext::getMain()->getLanguage(); } - // Adjust for the user's timezone. - $offsetThis = $this->offsetForUser( $user ); - $offsetRel = $relativeTo->offsetForUser( $user ); - - $ts = ''; - if ( wfRunHooks( 'GetHumanTimestamp', array( &$ts, $this, $relativeTo, $user, $lang ) ) ) { - $ts = $lang->getHumanTimestamp( $this, $relativeTo, $user ); - } - - // Reset the timezone on the objects. - $this->timestamp->sub( $offsetThis ); - $relativeTo->timestamp->sub( $offsetRel ); - - return $ts; + return $lang->getHumanTimestamp( $this, $relativeTo, $user ); } /** @@ -326,7 +308,7 @@ class MWTimestamp { $ts = ''; $diff = $this->diff( $relativeTo ); - if ( wfRunHooks( + if ( Hooks::run( 'GetRelativeTimestamp', array( &$ts, &$diff, $this, $relativeTo, $user, $lang ) ) ) {