X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2Fparser%2FCacheTime.php;h=e9840a424087237e88a190ae3dd5d2850429affd;hb=e1724b7a10be582ea6d53e94fa2a6e8339d0df9f;hp=05bcebef64cd6e3a9da3761b3a2bb18abc9a9eed;hpb=e968a1f431ad058dcb14adb2757bde5664b99a79;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/parser/CacheTime.php b/includes/parser/CacheTime.php index 05bcebef64..e9840a4240 100644 --- a/includes/parser/CacheTime.php +++ b/includes/parser/CacheTime.php @@ -27,28 +27,42 @@ * @ingroup Parser */ class CacheTime { - /** @var array|bool ParserOptions which have been taken into account to - * produce output or false if not available. + /** + * @var string[] ParserOptions which have been taken into account to produce output. */ public $mUsedOptions; - # Compatibility check + /** + * @var string|null Compatibility check + */ public $mVersion = Parser::VERSION; - # Time when this object was generated, or -1 for uncacheable. Used in ParserCache. + /** + * @var string|int TS_MW timestamp when this object was generated, or -1 for not cacheable. Used + * in ParserCache. + */ public $mCacheTime = ''; - # Seconds after which the object should expire, use 0 for uncacheable. Used in ParserCache. + /** + * @var int|null Seconds after which the object should expire, use 0 for not cacheable. Used in + * ParserCache. + */ public $mCacheExpiry = null; - # Revision ID that was parsed + /** + * @var int|null Revision ID that was parsed + */ public $mCacheRevisionId = null; /** * @return string TS_MW timestamp */ public function getCacheTime() { - return wfTimestamp( TS_MW, $this->mCacheTime ); + // NOTE: keep support for undocumented used of -1 to mean "not cacheable". + if ( $this->mCacheTime === '' ) { + $this->mCacheTime = MWTimestamp::now(); + } + return $this->mCacheTime; } /** @@ -58,6 +72,11 @@ class CacheTime { * @return string */ public function setCacheTime( $t ) { + // NOTE: keep support for undocumented used of -1 to mean "not cacheable". + if ( is_string( $t ) && $t !== '-1' ) { + $t = MWTimestamp::convert( TS_MW, $t ); + } + return wfSetVar( $this->mCacheTime, $t ); } @@ -71,7 +90,7 @@ class CacheTime { /** * @since 1.23 - * @param int $id Revision id + * @param int|null $id Revision ID */ public function setCacheRevisionId( $id ) { $this->mCacheRevisionId = $id; @@ -105,14 +124,15 @@ class CacheTime { * The value returned by getCacheExpiry is smaller or equal to the smallest number * that was provided to a call of updateCacheExpiry(), and smaller or equal to the * value of $wgParserCacheExpireTime. - * @return int|mixed|null + * @return int */ public function getCacheExpiry() { global $wgParserCacheExpireTime; + // NOTE: keep support for undocumented used of -1 to mean "not cacheable". if ( $this->mCacheTime < 0 ) { return 0; - } // old-style marker for "not cacheable" + } $expire = $this->mCacheExpiry; @@ -147,11 +167,12 @@ class CacheTime { public function expired( $touched ) { global $wgCacheEpoch; - return !$this->isCacheable() // parser says it's uncacheable + $expiry = MWTimestamp::convert( TS_MW, MWTimestamp::time() - $this->getCacheExpiry() ); + + return !$this->isCacheable() // parser says it's not cacheable || $this->getCacheTime() < $touched || $this->getCacheTime() <= $wgCacheEpoch - || $this->getCacheTime() < - wfTimestamp( TS_MW, time() - $this->getCacheExpiry() ) // expiry period has passed + || $this->getCacheTime() < $expiry // expiry period has passed || !isset( $this->mVersion ) || version_compare( $this->mVersion, Parser::VERSION, "lt" ); }