Revert "Include short descriptions for extensions bundled in the release"
[mediawiki.git] / includes / parser / CacheTime.php
blobe1b3f28deb66dfb32f7243d4492fb1cb908d574c
1 <?php
2 /**
3 * Parser cache specific expiry check.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup Parser
24 /**
25 * Parser cache specific expiry check.
27 * @ingroup Parser
29 class CacheTime {
30 /** @var array|bool ParserOptions which have been taken into account to
31 * produce output or false if not available.
33 public $mUsedOptions;
35 var $mVersion = Parser::VERSION, # Compatibility check
36 $mCacheTime = '', # Time when this object was generated, or -1 for uncacheable. Used in ParserCache.
37 $mCacheExpiry = null, # Seconds after which the object should expire, use 0 for uncachable. Used in ParserCache.
38 $mContainsOldMagic; # Boolean variable indicating if the input contained variables like {{CURRENTDAY}}
40 /**
41 * @return string TS_MW timestamp
43 function getCacheTime() {
44 return wfTimestamp( TS_MW, $this->mCacheTime );
47 /**
48 * @return bool
50 function containsOldMagic() {
51 return $this->mContainsOldMagic;
54 /**
55 * @param $com bool
56 * @return bool
58 function setContainsOldMagic( $com ) {
59 return wfSetVar( $this->mContainsOldMagic, $com );
62 /**
63 * setCacheTime() sets the timestamp expressing when the page has been rendered.
64 * This does not control expiry, see updateCacheExpiry() for that!
65 * @param $t string
66 * @return string
68 function setCacheTime( $t ) {
69 return wfSetVar( $this->mCacheTime, $t );
72 /**
73 * Sets the number of seconds after which this object should expire.
74 * This value is used with the ParserCache.
75 * If called with a value greater than the value provided at any previous call,
76 * the new call has no effect. The value returned by getCacheExpiry is smaller
77 * or equal to the smallest number that was provided as an argument to
78 * updateCacheExpiry().
80 * @param $seconds number
82 function updateCacheExpiry( $seconds ) {
83 $seconds = (int)$seconds;
85 if ( $this->mCacheExpiry === null || $this->mCacheExpiry > $seconds ) {
86 $this->mCacheExpiry = $seconds;
89 // hack: set old-style marker for uncacheable entries.
90 if ( $this->mCacheExpiry !== null && $this->mCacheExpiry <= 0 ) {
91 $this->mCacheTime = -1;
95 /**
96 * Returns the number of seconds after which this object should expire.
97 * This method is used by ParserCache to determine how long the ParserOutput can be cached.
98 * The timestamp of expiry can be calculated by adding getCacheExpiry() to getCacheTime().
99 * The value returned by getCacheExpiry is smaller or equal to the smallest number
100 * that was provided to a call of updateCacheExpiry(), and smaller or equal to the
101 * value of $wgParserCacheExpireTime.
102 * @return int|mixed|null
104 function getCacheExpiry() {
105 global $wgParserCacheExpireTime;
107 if ( $this->mCacheTime < 0 ) {
108 return 0;
109 } // old-style marker for "not cachable"
111 $expire = $this->mCacheExpiry;
113 if ( $expire === null ) {
114 $expire = $wgParserCacheExpireTime;
115 } else {
116 $expire = min( $expire, $wgParserCacheExpireTime );
119 if ( $this->containsOldMagic() ) { //compatibility hack
120 $expire = min( $expire, 3600 ); # 1 hour
123 if ( $expire <= 0 ) {
124 return 0; // not cachable
125 } else {
126 return $expire;
131 * @return bool
133 function isCacheable() {
134 return $this->getCacheExpiry() > 0;
138 * Return true if this cached output object predates the global or
139 * per-article cache invalidation timestamps, or if it comes from
140 * an incompatible older version.
142 * @param string $touched the affected article's last touched timestamp
143 * @return Boolean
145 public function expired( $touched ) {
146 global $wgCacheEpoch;
147 return !$this->isCacheable() || // parser says it's uncacheable
148 $this->getCacheTime() < $touched ||
149 $this->getCacheTime() <= $wgCacheEpoch ||
150 $this->getCacheTime() < wfTimestamp( TS_MW, time() - $this->getCacheExpiry() ) || // expiry period has passed
151 !isset( $this->mVersion ) ||
152 version_compare( $this->mVersion, Parser::VERSION, "lt" );