38671fb0991c5e86bcbf7934cf547570a121785a
8 var $mVersion = Parser
::VERSION
, # Compatibility check
9 $mCacheTime = '', # Time when this object was generated, or -1 for uncacheable. Used in ParserCache.
10 $mCacheExpiry = null, # Seconds after which the object should expire, use 0 for uncachable. Used in ParserCache.
11 $mContainsOldMagic; # Boolean variable indicating if the input contained variables like {{CURRENTDAY}}
13 function getCacheTime() { return $this->mCacheTime
; }
15 function containsOldMagic() { return $this->mContainsOldMagic
; }
16 function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic
, $com ); }
19 * setCacheTime() sets the timestamp expressing when the page has been rendered.
20 * This doesn not control expiry, see updateCacheExpiry() for that!
22 function setCacheTime( $t ) { return wfSetVar( $this->mCacheTime
, $t ); }
26 * Sets the number of seconds after which this object should expire.
27 * This value is used with the ParserCache.
28 * If called with a value greater than the value provided at any previous call,
29 * the new call has no effect. The value returned by getCacheExpiry is smaller
30 * or equal to the smallest number that was provided as an argument to
31 * updateCacheExpiry().
33 function updateCacheExpiry( $seconds ) {
34 $seconds = (int)$seconds;
36 if ( $this->mCacheExpiry
=== null ||
$this->mCacheExpiry
> $seconds )
37 $this->mCacheExpiry
= $seconds;
39 // hack: set old-style marker for uncacheable entries.
40 if ( $this->mCacheExpiry
!== null && $this->mCacheExpiry
<= 0 )
41 $this->mCacheTime
= -1;
45 * Returns the number of seconds after which this object should expire.
46 * This method is used by ParserCache to determine how long the ParserOutput can be cached.
47 * The timestamp of expiry can be calculated by adding getCacheExpiry() to getCacheTime().
48 * The value returned by getCacheExpiry is smaller or equal to the smallest number
49 * that was provided to a call of updateCacheExpiry(), and smaller or equal to the
50 * value of $wgParserCacheExpireTime.
52 function getCacheExpiry() {
53 global $wgParserCacheExpireTime;
55 if ( $this->mCacheTime
< 0 ) return 0; // old-style marker for "not cachable"
57 $expire = $this->mCacheExpiry
;
59 if ( $expire === null )
60 $expire = $wgParserCacheExpireTime;
62 $expire = min( $expire, $wgParserCacheExpireTime );
64 if( $this->containsOldMagic() ) { //compatibility hack
65 $expire = min( $expire, 3600 ); # 1 hour
68 if ( $expire <= 0 ) return 0; // not cachable
73 function isCacheable() {
74 return $this->getCacheExpiry() > 0;
78 * Return true if this cached output object predates the global or
79 * per-article cache invalidation timestamps, or if it comes from
80 * an incompatible older version.
82 * @param $touched String: the affected article's last touched timestamp
85 public function expired( $touched ) {
87 return !$this->isCacheable() ||
// parser says it's uncacheable
88 $this->getCacheTime() < $touched ||
89 $this->getCacheTime() <= $wgCacheEpoch ||
90 $this->getCacheTime() < wfTimestamp( TS_MW
, time() - $this->getCacheExpiry() ) ||
// expiry period has passed
91 !isset( $this->mVersion
) ||
92 version_compare( $this->mVersion
, Parser
::VERSION
, "lt" );
96 class ParserOutput
extends CacheTime
98 var $mText, # The output text
99 $mLanguageLinks, # List of the full text of language links, in the order they appear
100 $mCategories, # Map of category names to sort keys
101 $mTitleText, # title text of the chosen language variant
102 $mLinks = array(), # 2-D map of NS/DBK to ID for the links in the document. ID=zero for broken.
103 $mTemplates = array(), # 2-D map of NS/DBK to ID for the template references. ID=zero for broken.
104 $mTemplateIds = array(), # 2-D map of NS/DBK to rev ID for the template references. ID=zero for broken.
105 $mImages = array(), # DB keys of the images used, in the array key only
106 $mExternalLinks = array(), # External link URLs, in the key only
107 $mInterwikiLinks = array(), # 2-D map of prefix/DBK (in keys only) for the inline interwiki links in the document.
108 $mNewSection = false, # Show a new section link?
109 $mHideNewSection = false, # Hide the new section link?
110 $mNoGallery = false, # No gallery on category page? (__NOGALLERY__)
111 $mHeadItems = array(), # Items to put in the <head> section
112 $mOutputHooks = array(), # Hook tags as per $wgParserOutputHooks
113 $mWarnings = array(), # Warning text to be returned to the user. Wikitext formatted, in the key only
114 $mSections = array(), # Table of contents
115 $mProperties = array(), # Name/value pairs to be cached in the DB
116 $mTOCHTML = ''; # HTML of the TOC
117 private $mIndexPolicy = ''; # 'index' or 'noindex'? Any other value will result in no change.
119 function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(),
120 $containsOldMagic = false, $titletext = '' )
122 $this->mText
= $text;
123 $this->mLanguageLinks
= $languageLinks;
124 $this->mCategories
= $categoryLinks;
125 $this->mContainsOldMagic
= $containsOldMagic;
126 $this->mTitleText
= $titletext;
129 function getText() { return $this->mText
; }
130 function &getLanguageLinks() { return $this->mLanguageLinks
; }
131 function getInterwikiLinks() { return $this->mInterwikiLinks
; }
132 function getCategoryLinks() { return array_keys( $this->mCategories
); }
133 function &getCategories() { return $this->mCategories
; }
134 function getTitleText() { return $this->mTitleText
; }
135 function getSections() { return $this->mSections
; }
136 function &getLinks() { return $this->mLinks
; }
137 function &getTemplates() { return $this->mTemplates
; }
138 function &getImages() { return $this->mImages
; }
139 function &getExternalLinks() { return $this->mExternalLinks
; }
140 function getNoGallery() { return $this->mNoGallery
; }
141 function getHeadItems() { return $this->mHeadItems
; }
142 function getSubtitle() { return $this->mSubtitle
; }
143 function getOutputHooks() { return (array)$this->mOutputHooks
; }
144 function getWarnings() { return array_keys( $this->mWarnings
); }
145 function getIndexPolicy() { return $this->mIndexPolicy
; }
146 function getTOCHTML() { return $this->mTOCHTML
; }
148 function setText( $text ) { return wfSetVar( $this->mText
, $text ); }
149 function setLanguageLinks( $ll ) { return wfSetVar( $this->mLanguageLinks
, $ll ); }
150 function setCategoryLinks( $cl ) { return wfSetVar( $this->mCategories
, $cl ); }
152 function setTitleText( $t ) { return wfSetVar( $this->mTitleText
, $t ); }
153 function setSections( $toc ) { return wfSetVar( $this->mSections
, $toc ); }
154 function setIndexPolicy( $policy ) { return wfSetVar( $this->mIndexPolicy
, $policy ); }
155 function setTOCHTML( $tochtml ) { return wfSetVar( $this->mTOCHTML
, $tochtml ); }
157 function addCategory( $c, $sort ) { $this->mCategories
[$c] = $sort; }
158 function addLanguageLink( $t ) { $this->mLanguageLinks
[] = $t; }
159 function addWarning( $s ) { $this->mWarnings
[$s] = 1; }
161 function addOutputHook( $hook, $data = false ) {
162 $this->mOutputHooks
[] = array( $hook, $data );
165 function setNewSection( $value ) {
166 $this->mNewSection
= (bool)$value;
168 function hideNewSection ( $value ) {
169 $this->mHideNewSection
= (bool)$value;
171 function getHideNewSection () {
172 return (bool)$this->mHideNewSection
;
174 function getNewSection() {
175 return (bool)$this->mNewSection
;
178 function addExternalLink( $url ) {
179 # We don't register links pointing to our own server, unless... :-)
180 global $wgServer, $wgRegisterInternalExternals;
181 if( $wgRegisterInternalExternals or stripos($url,$wgServer.'/')!==0)
182 $this->mExternalLinks
[$url] = 1;
186 * Record a local or interwiki inline link for saving in future link tables.
188 * @param $title Title object
189 * @param $id Mixed: optional known page_id so we can skip the lookup
191 function addLink( $title, $id = null ) {
192 if ( $title->isExternal() ) {
193 // Don't record interwikis in pagelinks
194 $this->addInterwikiLink( $title );
197 $ns = $title->getNamespace();
198 $dbk = $title->getDBkey();
199 if ( $ns == NS_MEDIA
) {
200 // Normalize this pseudo-alias if it makes it down here...
202 } elseif( $ns == NS_SPECIAL
) {
203 // We don't record Special: links currently
204 // It might actually be wise to, but we'd need to do some normalization.
206 } elseif( $dbk === '' ) {
207 // Don't record self links - [[#Foo]]
210 if ( !isset( $this->mLinks
[$ns] ) ) {
211 $this->mLinks
[$ns] = array();
213 if ( is_null( $id ) ) {
214 $id = $title->getArticleID();
216 $this->mLinks
[$ns][$dbk] = $id;
219 function addImage( $name ) {
220 $this->mImages
[$name] = 1;
223 function addTemplate( $title, $page_id, $rev_id ) {
224 $ns = $title->getNamespace();
225 $dbk = $title->getDBkey();
226 if ( !isset( $this->mTemplates
[$ns] ) ) {
227 $this->mTemplates
[$ns] = array();
229 $this->mTemplates
[$ns][$dbk] = $page_id;
230 if ( !isset( $this->mTemplateIds
[$ns] ) ) {
231 $this->mTemplateIds
[$ns] = array();
233 $this->mTemplateIds
[$ns][$dbk] = $rev_id; // For versioning
237 * @param $title Title object, must be an interwiki link
238 * @throws MWException if given invalid input
240 function addInterwikiLink( $title ) {
241 $prefix = $title->getInterwiki();
242 if( $prefix == '' ) {
243 throw new MWException( 'Non-interwiki link passed, internal parser error.' );
245 if (!isset($this->mInterwikiLinks
[$prefix])) {
246 $this->mInterwikiLinks
[$prefix] = array();
248 $this->mInterwikiLinks
[$prefix][$title->getDBkey()] = 1;
252 * Add some text to the <head>.
253 * If $tag is set, the section with that tag will only be included once
256 function addHeadItem( $section, $tag = false ) {
257 if ( $tag !== false ) {
258 $this->mHeadItems
[$tag] = $section;
260 $this->mHeadItems
[] = $section;
265 * Override the title to be used for display
266 * -- this is assumed to have been validated
267 * (check equal normalisation, etc.)
269 * @param $text String: desired title text
271 public function setDisplayTitle( $text ) {
272 $this->setTitleText( $text );
273 $this->setProperty( 'displaytitle', $text );
277 * Get the title to be used for display
281 public function getDisplayTitle() {
282 $t = $this->getTitleText( );
290 * Fairly generic flag setter thingy.
292 public function setFlag( $flag ) {
293 $this->mFlags
[$flag] = true;
296 public function getFlag( $flag ) {
297 return isset( $this->mFlags
[$flag] );
301 * Set a property to be cached in the DB
303 public function setProperty( $name, $value ) {
304 $this->mProperties
[$name] = $value;
307 public function getProperty( $name ){
308 return isset( $this->mProperties
[$name] ) ?
$this->mProperties
[$name] : false;
311 public function getProperties() {
312 if ( !isset( $this->mProperties
) ) {
313 $this->mProperties
= array();
315 return $this->mProperties
;