From c1f9b1f7b1b77776192048005dcc66dcf3df2bfb Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 27 Dec 2014 15:41:37 +0100 Subject: Update to MediaWiki 1.24.1 --- includes/parser/CacheTime.php | 98 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 78 insertions(+), 20 deletions(-) (limited to 'includes/parser/CacheTime.php') diff --git a/includes/parser/CacheTime.php b/includes/parser/CacheTime.php index 8190a8a0..94abc266 100644 --- a/includes/parser/CacheTime.php +++ b/includes/parser/CacheTime.php @@ -27,24 +27,64 @@ * @ingroup Parser */ class CacheTime { + /** @var array|bool ParserOptions which have been taken into account to + * produce output or false if not available. + */ + public $mUsedOptions; - var $mVersion = Parser::VERSION, # Compatibility check + public $mVersion = Parser::VERSION, # Compatibility check $mCacheTime = '', # Time when this object was generated, or -1 for uncacheable. Used in ParserCache. $mCacheExpiry = null, # Seconds after which the object should expire, use 0 for uncachable. Used in ParserCache. - $mContainsOldMagic; # Boolean variable indicating if the input contained variables like {{CURRENTDAY}} + $mContainsOldMagic, # Boolean variable indicating if the input contained variables like {{CURRENTDAY}} + $mCacheRevisionId = null; # Revision ID that was parsed - function getCacheTime() { return $this->mCacheTime; } + /** + * @return string TS_MW timestamp + */ + public function getCacheTime() { + return wfTimestamp( TS_MW, $this->mCacheTime ); + } - function containsOldMagic() { return $this->mContainsOldMagic; } - function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic, $com ); } + /** + * @return bool + */ + public function containsOldMagic() { + return $this->mContainsOldMagic; + } + + /** + * @param bool $com + * @return bool + */ + public function setContainsOldMagic( $com ) { + return wfSetVar( $this->mContainsOldMagic, $com ); + } /** * setCacheTime() sets the timestamp expressing when the page has been rendered. - * This doesn not control expiry, see updateCacheExpiry() for that! - * @param $t string + * This does not control expiry, see updateCacheExpiry() for that! + * @param string $t * @return string */ - function setCacheTime( $t ) { return wfSetVar( $this->mCacheTime, $t ); } + public function setCacheTime( $t ) { + return wfSetVar( $this->mCacheTime, $t ); + } + + /** + * @since 1.23 + * @return int|null Revision id, if any was set + */ + public function getCacheRevisionId() { + return $this->mCacheRevisionId; + } + + /** + * @since 1.23 + * @param int $id Revision id + */ + public function setCacheRevisionId( $id ) { + $this->mCacheRevisionId = $id; + } /** * Sets the number of seconds after which this object should expire. @@ -54,9 +94,9 @@ class CacheTime { * or equal to the smallest number that was provided as an argument to * updateCacheExpiry(). * - * @param $seconds number + * @param int $seconds */ - function updateCacheExpiry( $seconds ) { + public function updateCacheExpiry( $seconds ) { $seconds = (int)$seconds; if ( $this->mCacheExpiry === null || $this->mCacheExpiry > $seconds ) { @@ -78,7 +118,7 @@ class CacheTime { * value of $wgParserCacheExpireTime. * @return int|mixed|null */ - function getCacheExpiry() { + public function getCacheExpiry() { global $wgParserCacheExpireTime; if ( $this->mCacheTime < 0 ) { @@ -107,7 +147,7 @@ class CacheTime { /** * @return bool */ - function isCacheable() { + public function isCacheable() { return $this->getCacheExpiry() > 0; } @@ -116,17 +156,35 @@ class CacheTime { * per-article cache invalidation timestamps, or if it comes from * an incompatible older version. * - * @param string $touched the affected article's last touched timestamp - * @return Boolean + * @param string $touched The affected article's last touched timestamp + * @return bool */ public function expired( $touched ) { global $wgCacheEpoch; - return !$this->isCacheable() || // parser says it's uncacheable - $this->getCacheTime() < $touched || - $this->getCacheTime() <= $wgCacheEpoch || - $this->getCacheTime() < wfTimestamp( TS_MW, time() - $this->getCacheExpiry() ) || // expiry period has passed - !isset( $this->mVersion ) || - version_compare( $this->mVersion, Parser::VERSION, "lt" ); + + return !$this->isCacheable() // parser says it's uncacheable + || $this->getCacheTime() < $touched + || $this->getCacheTime() <= $wgCacheEpoch + || $this->getCacheTime() < + wfTimestamp( TS_MW, time() - $this->getCacheExpiry() ) // expiry period has passed + || !isset( $this->mVersion ) + || version_compare( $this->mVersion, Parser::VERSION, "lt" ); } + /** + * Return true if this cached output object is for a different revision of + * the page. + * + * @todo We always return false if $this->getCacheRevisionId() is null; + * this prevents invalidating the whole parser cache when this change is + * deployed. Someday that should probably be changed. + * + * @since 1.23 + * @param int $id The affected article's current revision id + * @return bool + */ + public function isDifferentRevision( $id ) { + $cached = $this->getCacheRevisionId(); + return $cached !== null && $id !== $cached; + } } -- cgit v1.2.3-54-g00ecf