diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:12:12 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:12:12 -0400 |
commit | c9aa36da061816dee256a979c2ff8d2ee41824d9 (patch) | |
tree | 29f7002b80ee984b488bd047dbbd80b36bf892e9 /includes/parser/CacheTime.php | |
parent | b4274e0e33eafb5e9ead9d949ebf031a9fb8363b (diff) | |
parent | d1ba966140d7a60cd5ae4e8667ceb27c1a138592 (diff) |
Merge branch 'archwiki'
# Conflicts:
# skins/ArchLinux.php
# skins/ArchLinux/archlogo.gif
Diffstat (limited to 'includes/parser/CacheTime.php')
-rw-r--r-- | includes/parser/CacheTime.php | 98 |
1 files changed, 78 insertions, 20 deletions
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; + } } |