Index: trunk/phase3/includes/parser/ParserOutput.php |
— | — | @@ -3,16 +3,102 @@ |
4 | 4 | * @todo document |
5 | 5 | * @ingroup Parser |
6 | 6 | */ |
7 | | -class ParserOutput |
| 7 | + |
| 8 | +class CacheTime { |
| 9 | + var $mVersion = Parser::VERSION, # Compatibility check |
| 10 | + $mCacheTime = '', # Time when this object was generated, or -1 for uncacheable. Used in ParserCache. |
| 11 | + $mCacheExpiry = null, # Seconds after which the object should expire, use 0 for uncachable. Used in ParserCache. |
| 12 | + $mContainsOldMagic; # Boolean variable indicating if the input contained variables like {{CURRENTDAY}} |
| 13 | + |
| 14 | + function getCacheTime() { return $this->mCacheTime; } |
| 15 | + |
| 16 | + function containsOldMagic() { return $this->mContainsOldMagic; } |
| 17 | + function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic, $com ); } |
| 18 | + |
| 19 | + /** |
| 20 | + * setCacheTime() sets the timestamp expressing when the page has been rendered. |
| 21 | + * This doesn not control expiry, see updateCacheExpiry() for that! |
| 22 | + */ |
| 23 | + function setCacheTime( $t ) { return wfSetVar( $this->mCacheTime, $t ); } |
| 24 | + |
| 25 | + |
| 26 | + /** |
| 27 | + * Sets the number of seconds after which this object should expire. |
| 28 | + * This value is used with the ParserCache. |
| 29 | + * If called with a value greater than the value provided at any previous call, |
| 30 | + * the new call has no effect. The value returned by getCacheExpiry is smaller |
| 31 | + * or equal to the smallest number that was provided as an argument to |
| 32 | + * updateCacheExpiry(). |
| 33 | + */ |
| 34 | + function updateCacheExpiry( $seconds ) { |
| 35 | + $seconds = (int)$seconds; |
| 36 | + |
| 37 | + if ( $this->mCacheExpiry === null || $this->mCacheExpiry > $seconds ) |
| 38 | + $this->mCacheExpiry = $seconds; |
| 39 | + |
| 40 | + // hack: set old-style marker for uncacheable entries. |
| 41 | + if ( $this->mCacheExpiry !== null && $this->mCacheExpiry <= 0 ) |
| 42 | + $this->mCacheTime = -1; |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Returns the number of seconds after which this object should expire. |
| 47 | + * This method is used by ParserCache to determine how long the ParserOutput can be cached. |
| 48 | + * The timestamp of expiry can be calculated by adding getCacheExpiry() to getCacheTime(). |
| 49 | + * The value returned by getCacheExpiry is smaller or equal to the smallest number |
| 50 | + * that was provided to a call of updateCacheExpiry(), and smaller or equal to the |
| 51 | + * value of $wgParserCacheExpireTime. |
| 52 | + */ |
| 53 | + function getCacheExpiry() { |
| 54 | + global $wgParserCacheExpireTime; |
| 55 | + |
| 56 | + if ( $this->mCacheTime < 0 ) return 0; // old-style marker for "not cachable" |
| 57 | + |
| 58 | + $expire = $this->mCacheExpiry; |
| 59 | + |
| 60 | + if ( $expire === null ) |
| 61 | + $expire = $wgParserCacheExpireTime; |
| 62 | + else |
| 63 | + $expire = min( $expire, $wgParserCacheExpireTime ); |
| 64 | + |
| 65 | + if( $this->containsOldMagic() ) { //compatibility hack |
| 66 | + $expire = min( $expire, 3600 ); # 1 hour |
| 67 | + } |
| 68 | + |
| 69 | + if ( $expire <= 0 ) return 0; // not cachable |
| 70 | + else return $expire; |
| 71 | + } |
| 72 | + |
| 73 | + |
| 74 | + function isCacheable() { |
| 75 | + return $this->getCacheExpiry() > 0; |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Return true if this cached output object predates the global or |
| 80 | + * per-article cache invalidation timestamps, or if it comes from |
| 81 | + * an incompatible older version. |
| 82 | + * |
| 83 | + * @param $touched String: the affected article's last touched timestamp |
| 84 | + * @return Boolean |
| 85 | + */ |
| 86 | + public function expired( $touched ) { |
| 87 | + global $wgCacheEpoch; |
| 88 | + return !$this->isCacheable() || // parser says it's uncacheable |
| 89 | + $this->getCacheTime() < $touched || |
| 90 | + $this->getCacheTime() <= $wgCacheEpoch || |
| 91 | + $this->getCacheTime() < wfTimestamp( TS_MW, time() - $this->getCacheExpiry() ) || // expiry period has passed |
| 92 | + !isset( $this->mVersion ) || |
| 93 | + version_compare( $this->mVersion, Parser::VERSION, "lt" ); |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +class ParserOutput extends CacheTime |
8 | 98 | { |
9 | 99 | var $mText, # The output text |
10 | 100 | $mLanguageLinks, # List of the full text of language links, in the order they appear |
11 | 101 | $mCategories, # Map of category names to sort keys |
12 | | - $mContainsOldMagic, # Boolean variable indicating if the input contained variables like {{CURRENTDAY}} |
13 | 102 | $mTitleText, # title text of the chosen language variant |
14 | | - $mCacheTime = '', # Time when this object was generated, or -1 for uncacheable. Used in ParserCache. |
15 | | - $mCacheExpiry = null, # Seconds after which the object should expire, use 0 for uncachable. Used in ParserCache. |
16 | | - $mVersion = Parser::VERSION, # Compatibility check |
17 | 103 | $mLinks = array(), # 2-D map of NS/DBK to ID for the links in the document. ID=zero for broken. |
18 | 104 | $mTemplates = array(), # 2-D map of NS/DBK to ID for the template references. ID=zero for broken. |
19 | 105 | $mTemplateIds = array(), # 2-D map of NS/DBK to rev ID for the template references. ID=zero for broken. |
— | — | @@ -45,7 +131,6 @@ |
46 | 132 | function getInterwikiLinks() { return $this->mInterwikiLinks; } |
47 | 133 | function getCategoryLinks() { return array_keys( $this->mCategories ); } |
48 | 134 | function &getCategories() { return $this->mCategories; } |
49 | | - function getCacheTime() { return $this->mCacheTime; } |
50 | 135 | function getTitleText() { return $this->mTitleText; } |
51 | 136 | function getSections() { return $this->mSections; } |
52 | 137 | function &getLinks() { return $this->mLinks; } |
— | — | @@ -60,71 +145,15 @@ |
61 | 146 | function getIndexPolicy() { return $this->mIndexPolicy; } |
62 | 147 | function getTOCHTML() { return $this->mTOCHTML; } |
63 | 148 | |
64 | | - function containsOldMagic() { return $this->mContainsOldMagic; } |
65 | 149 | function setText( $text ) { return wfSetVar( $this->mText, $text ); } |
66 | 150 | function setLanguageLinks( $ll ) { return wfSetVar( $this->mLanguageLinks, $ll ); } |
67 | 151 | function setCategoryLinks( $cl ) { return wfSetVar( $this->mCategories, $cl ); } |
68 | | - function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic, $com ); } |
69 | 152 | |
70 | | - /** setCacheTime() sets the timestamp expressing when the page has been rendered. |
71 | | - * This doesn not control expiry, see updateCacheExpiry() for that! |
72 | | - */ |
73 | | - function setCacheTime( $t ) { return wfSetVar( $this->mCacheTime, $t ); } |
74 | 153 | function setTitleText( $t ) { return wfSetVar( $this->mTitleText, $t ); } |
75 | 154 | function setSections( $toc ) { return wfSetVar( $this->mSections, $toc ); } |
76 | 155 | function setIndexPolicy( $policy ) { return wfSetVar( $this->mIndexPolicy, $policy ); } |
77 | 156 | function setTOCHTML( $tochtml ) { return wfSetVar( $this->mTOCHTML, $tochtml ); } |
78 | 157 | |
79 | | - |
80 | | - /** Sets the number of seconds after which this object should expire. |
81 | | - * This value is used with the ParserCache. |
82 | | - * If called with a value greater than the value provided at any previous call, |
83 | | - * the new call has no effect. The value returned by getCacheExpiry is smaller |
84 | | - * or equal to the smallest number that was provided as an argument to |
85 | | - * updateCacheExpiry(). |
86 | | - */ |
87 | | - function updateCacheExpiry( $seconds ) { |
88 | | - $seconds = (int)$seconds; |
89 | | - |
90 | | - if ( $this->mCacheExpiry === null || $this->mCacheExpiry > $seconds ) |
91 | | - $this->mCacheExpiry = $seconds; |
92 | | - |
93 | | - // hack: set old-style marker for uncacheable entries. |
94 | | - if ( $this->mCacheExpiry !== null && $this->mCacheExpiry <= 0 ) |
95 | | - $this->mCacheTime = -1; |
96 | | - } |
97 | | - |
98 | | - /** Returns the number of seconds after which this object should expire. |
99 | | - * This method is used by ParserCache to determine how long the ParserOutput can be cached. |
100 | | - * The timestamp of expiry can be calculated by adding getCacheExpiry() to getCacheTime(). |
101 | | - * The value returned by getCacheExpiry is smaller or equal to the smallest number |
102 | | - * that was provided to a call of updateCacheExpiry(), and smaller or equal to the |
103 | | - * value of $wgParserCacheExpireTime. |
104 | | - */ |
105 | | - function getCacheExpiry() { |
106 | | - global $wgParserCacheExpireTime; |
107 | | - |
108 | | - if ( $this->mCacheTime < 0 ) return 0; // old-style marker for "not cachable" |
109 | | - |
110 | | - $expire = $this->mCacheExpiry; |
111 | | - |
112 | | - if ( $expire === null ) |
113 | | - $expire = $wgParserCacheExpireTime; |
114 | | - else |
115 | | - $expire = min( $expire, $wgParserCacheExpireTime ); |
116 | | - |
117 | | - if( $this->containsOldMagic() ) { //compatibility hack |
118 | | - $expire = min( $expire, 3600 ); # 1 hour |
119 | | - } |
120 | | - |
121 | | - if ( $expire <= 0 ) return 0; // not cachable |
122 | | - else return $expire; |
123 | | - } |
124 | | - |
125 | | - function isCacheable() { |
126 | | - return $this->getCacheExpiry() > 0; |
127 | | - } |
128 | | - |
129 | 158 | function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; } |
130 | 159 | function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; } |
131 | 160 | function addWarning( $s ) { $this->mWarnings[$s] = 1; } |
— | — | @@ -220,24 +249,6 @@ |
221 | 250 | } |
222 | 251 | |
223 | 252 | /** |
224 | | - * Return true if this cached output object predates the global or |
225 | | - * per-article cache invalidation timestamps, or if it comes from |
226 | | - * an incompatible older version. |
227 | | - * |
228 | | - * @param $touched String: the affected article's last touched timestamp |
229 | | - * @return Boolean |
230 | | - */ |
231 | | - public function expired( $touched ) { |
232 | | - global $wgCacheEpoch; |
233 | | - return !$this->isCacheable() || // parser says it's uncacheable |
234 | | - $this->getCacheTime() < $touched || |
235 | | - $this->getCacheTime() <= $wgCacheEpoch || |
236 | | - $this->getCacheTime() < wfTimestamp( TS_MW, time() - $this->getCacheExpiry() ) || // expiry period has passed |
237 | | - !isset( $this->mVersion ) || |
238 | | - version_compare( $this->mVersion, Parser::VERSION, "lt" ); |
239 | | - } |
240 | | - |
241 | | - /** |
242 | 253 | * Add some text to the <head>. |
243 | 254 | * If $tag is set, the section with that tag will only be included once |
244 | 255 | * in a given page. |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -27,6 +27,7 @@ |
28 | 28 | 'BagOStuff' => 'includes/BagOStuff.php', |
29 | 29 | 'Block' => 'includes/Block.php', |
30 | 30 | 'CacheDependency' => 'includes/CacheDependency.php', |
| 31 | + 'CacheTime' => 'includes/parser/ParserOutput.php', |
31 | 32 | 'Category' => 'includes/Category.php', |
32 | 33 | 'Categoryfinder' => 'includes/Categoryfinder.php', |
33 | 34 | 'CategoryPage' => 'includes/CategoryPage.php', |