From 7779b7237389e730007df527a3ed5ebb34cf30d6 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Fri, 24 Jun 2011 10:00:35 +0000 Subject: [PATCH] Reduce calls to wfTimestampNow() by using temporary variable. Inspired by CR on r88278. --- includes/Block.php | 12 +++++++----- includes/specials/SpecialRecentchanges.php | 5 +++-- includes/specials/SpecialWatchlist.php | 7 ++++--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/includes/Block.php b/includes/Block.php index cadeabd23b..e875e9e069 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -613,7 +613,8 @@ class Block { $autoblock->setTarget( $autoblockIP ); $autoblock->setBlocker( $this->getBlocker() ); $autoblock->mReason = wfMsgForContent( 'autoblocker', $this->getTarget(), $this->mReason ); - $autoblock->mTimestamp = wfTimestampNow(); + $timestamp = wfTimestampNow(); + $autoblock->mTimestamp = $timestamp; $autoblock->mAuto = 1; $autoblock->prevents( 'createaccount', $this->prevents( 'createaccount' ) ); # Continue suppressing the name if needed @@ -623,11 +624,11 @@ class Block { $dbr = wfGetDB( DB_SLAVE ); if ( $this->mTimestamp == $dbr->getInfinity() ) { # Original block was indefinite, start an autoblock now - $autoblock->mExpiry = Block::getAutoblockExpiry( wfTimestampNow() ); + $autoblock->mExpiry = Block::getAutoblockExpiry( $timestamp ); } else { # If the user is already blocked with an expiry date, we don't # want to pile on top of that. - $autoblock->mExpiry = min( $this->mExpiry, Block::getAutoblockExpiry( wfTimestampNow() ) ); + $autoblock->mExpiry = min( $this->mExpiry, Block::getAutoblockExpiry( $timestamp ) ); } # Insert the block... @@ -662,12 +663,13 @@ class Block { * @return Boolean */ public function isExpired() { - wfDebug( "Block::isExpired() checking current " . wfTimestampNow() . " vs $this->mExpiry\n" ); + $timestamp = wfTimestampNow(); + wfDebug( "Block::isExpired() checking current " . $timestamp . " vs $this->mExpiry\n" ); if ( !$this->mExpiry ) { return false; } else { - return wfTimestampNow() > $this->mExpiry; + return $timestamp > $this->mExpiry; } } diff --git a/includes/specials/SpecialRecentchanges.php b/includes/specials/SpecialRecentchanges.php index cf24ec1c04..6f1025041f 100644 --- a/includes/specials/SpecialRecentchanges.php +++ b/includes/specials/SpecialRecentchanges.php @@ -827,9 +827,10 @@ class SpecialRecentChanges extends IncludableSpecialPage { } // show from this onward link - $now = $wgLang->timeanddate( wfTimestampNow(), true ); + $timestamp = wfTimestampNow(); + $now = $wgLang->timeanddate( $timestamp, true ); $tl = $this->makeOptionsLink( - $now, array( 'from' => wfTimestampNow() ), $nondefaults + $now, array( 'from' => $timestamp ), $nondefaults ); $rclinks = wfMsgExt( 'rclinks', array( 'parseinline', 'replaceafter' ), diff --git a/includes/specials/SpecialWatchlist.php b/includes/specials/SpecialWatchlist.php index 89e9e9081d..9179a50352 100644 --- a/includes/specials/SpecialWatchlist.php +++ b/includes/specials/SpecialWatchlist.php @@ -299,12 +299,13 @@ class SpecialWatchlist extends SpecialPage { $wlInfo = ''; if( $values['days'] >= 1 ) { + $timestamp = wfTimestampNow(); $wlInfo = wfMsgExt( 'rcnote', 'parseinline', $wgLang->formatNum( $numRows ), $wgLang->formatNum( $values['days'] ), - $wgLang->timeAndDate( wfTimestampNow(), true ), - $wgLang->date( wfTimestampNow(), true ), - $wgLang->time( wfTimestampNow(), true ) + $wgLang->timeAndDate( $timestamp, true ), + $wgLang->date( $timestamp, true ), + $wgLang->time( $timestamp, true ) ) . '
'; } elseif( $values['days'] > 0 ) { $wlInfo = wfMsgExt( 'wlnote', 'parseinline', -- 2.20.1