6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
26 var $mVersion = Parser
::VERSION
, # Compatibility check
27 $mCacheTime = '', # Time when this object was generated, or -1 for uncacheable. Used in ParserCache.
28 $mCacheExpiry = null, # Seconds after which the object should expire, use 0 for uncachable. Used in ParserCache.
29 $mContainsOldMagic; # Boolean variable indicating if the input contained variables like {{CURRENTDAY}}
31 function getCacheTime() { return $this->mCacheTime
; }
33 function containsOldMagic() { return $this->mContainsOldMagic
; }
34 function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic
, $com ); }
37 * setCacheTime() sets the timestamp expressing when the page has been rendered.
38 * This doesn not control expiry, see updateCacheExpiry() for that!
42 function setCacheTime( $t ) { return wfSetVar( $this->mCacheTime
, $t ); }
45 * Sets the number of seconds after which this object should expire.
46 * This value is used with the ParserCache.
47 * If called with a value greater than the value provided at any previous call,
48 * the new call has no effect. The value returned by getCacheExpiry is smaller
49 * or equal to the smallest number that was provided as an argument to
50 * updateCacheExpiry().
52 * @param $seconds number
54 function updateCacheExpiry( $seconds ) {
55 $seconds = (int)$seconds;
57 if ( $this->mCacheExpiry
=== null ||
$this->mCacheExpiry
> $seconds ) {
58 $this->mCacheExpiry
= $seconds;
61 // hack: set old-style marker for uncacheable entries.
62 if ( $this->mCacheExpiry
!== null && $this->mCacheExpiry
<= 0 ) {
63 $this->mCacheTime
= -1;
68 * Returns the number of seconds after which this object should expire.
69 * This method is used by ParserCache to determine how long the ParserOutput can be cached.
70 * The timestamp of expiry can be calculated by adding getCacheExpiry() to getCacheTime().
71 * The value returned by getCacheExpiry is smaller or equal to the smallest number
72 * that was provided to a call of updateCacheExpiry(), and smaller or equal to the
73 * value of $wgParserCacheExpireTime.
74 * @return int|mixed|null
76 function getCacheExpiry() {
77 global $wgParserCacheExpireTime;
79 if ( $this->mCacheTime
< 0 ) {
81 } // old-style marker for "not cachable"
83 $expire = $this->mCacheExpiry
;
85 if ( $expire === null ) {
86 $expire = $wgParserCacheExpireTime;
88 $expire = min( $expire, $wgParserCacheExpireTime );
91 if( $this->containsOldMagic() ) { //compatibility hack
92 $expire = min( $expire, 3600 ); # 1 hour
96 return 0; // not cachable
105 function isCacheable() {
106 return $this->getCacheExpiry() > 0;
110 * Return true if this cached output object predates the global or
111 * per-article cache invalidation timestamps, or if it comes from
112 * an incompatible older version.
114 * @param $touched String: the affected article's last touched timestamp
117 public function expired( $touched ) {
118 global $wgCacheEpoch;
119 return !$this->isCacheable() ||
// parser says it's uncacheable
120 $this->getCacheTime() < $touched ||
121 $this->getCacheTime() <= $wgCacheEpoch ||
122 $this->getCacheTime() < wfTimestamp( TS_MW
, time() - $this->getCacheExpiry() ) ||
// expiry period has passed
123 !isset( $this->mVersion
) ||
124 version_compare( $this->mVersion
, Parser
::VERSION
, "lt" );