8 var $mText, # The output text
9 $mLanguageLinks, # List of the full text of language links, in the order they appear
10 $mCategories, # Map of category names to sort keys
11 $mContainsOldMagic, # Boolean variable indicating if the input contained variables like {{CURRENTDAY}}
12 $mTitleText, # title text of the chosen language variant
13 $mCacheTime = '', # Time when this object was generated, or -1 for uncacheable. Used in ParserCache.
14 $mCacheExpiry = null, # Seconds after which the object should expire, use 0 for uncachable. Used in ParserCache.
15 $mVersion = Parser
::VERSION
, # Compatibility check
16 $mLinks = array(), # 2-D map of NS/DBK to ID for the links in the document. ID=zero for broken.
17 $mTemplates = array(), # 2-D map of NS/DBK to ID for the template references. ID=zero for broken.
18 $mTemplateIds = array(), # 2-D map of NS/DBK to rev ID for the template references. ID=zero for broken.
19 $mImages = array(), # DB keys of the images used, in the array key only
20 $mExternalLinks = array(), # External link URLs, in the key only
21 $mInterwikiLinks = array(), # 2-D map of prefix/DBK (in keys only) for the inline interwiki links in the document.
22 $mNewSection = false, # Show a new section link?
23 $mHideNewSection = false, # Hide the new section link?
24 $mNoGallery = false, # No gallery on category page? (__NOGALLERY__)
25 $mHeadItems = array(), # Items to put in the <head> section
26 $mOutputHooks = array(), # Hook tags as per $wgParserOutputHooks
27 $mWarnings = array(), # Warning text to be returned to the user. Wikitext formatted, in the key only
28 $mSections = array(), # Table of contents
29 $mProperties = array(), # Name/value pairs to be cached in the DB
30 $mTOCHTML = ''; # HTML of the TOC
31 private $mIndexPolicy = '', # 'index' or 'noindex'? Any other value will result in no change.
32 $mPageIcons = array(); # Array of icons to show for the page (like Protect, Featured, etc)
34 function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(),
35 $containsOldMagic = false, $titletext = '' )
38 $this->mLanguageLinks
= $languageLinks;
39 $this->mCategories
= $categoryLinks;
40 $this->mContainsOldMagic
= $containsOldMagic;
41 $this->mTitleText
= $titletext;
44 function getText() { return $this->mText
; }
45 function &getLanguageLinks() { return $this->mLanguageLinks
; }
46 function getInterwikiLinks() { return $this->mInterwikiLinks
; }
47 function getCategoryLinks() { return array_keys( $this->mCategories
); }
48 function &getCategories() { return $this->mCategories
; }
49 function getCacheTime() { return $this->mCacheTime
; }
50 function getTitleText() { return $this->mTitleText
; }
51 function getSections() { return $this->mSections
; }
52 function &getLinks() { return $this->mLinks
; }
53 function &getTemplates() { return $this->mTemplates
; }
54 function &getImages() { return $this->mImages
; }
55 function &getExternalLinks() { return $this->mExternalLinks
; }
56 function getNoGallery() { return $this->mNoGallery
; }
57 function getHeadItems() { return $this->mHeadItems
; }
58 function getSubtitle() { return $this->mSubtitle
; }
59 function getOutputHooks() { return (array)$this->mOutputHooks
; }
60 function getWarnings() { return array_keys( $this->mWarnings
); }
61 function getIndexPolicy() { return $this->mIndexPolicy
; }
62 function getTOCHTML() { return $this->mTOCHTML
; }
63 function getPageIcons() { return $this->mPageIcons
; }
65 function containsOldMagic() { return $this->mContainsOldMagic
; }
66 function setText( $text ) { return wfSetVar( $this->mText
, $text ); }
67 function setLanguageLinks( $ll ) { return wfSetVar( $this->mLanguageLinks
, $ll ); }
68 function setCategoryLinks( $cl ) { return wfSetVar( $this->mCategories
, $cl ); }
69 function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic
, $com ); }
71 /** setCacheTime() sets the timestamp expressing when the page has been rendered.
72 * This doesn not control expiry, see updateCacheExpiry() for that!
74 function setCacheTime( $t ) { return wfSetVar( $this->mCacheTime
, $t ); }
75 function setTitleText( $t ) { return wfSetVar( $this->mTitleText
, $t ); }
76 function setSections( $toc ) { return wfSetVar( $this->mSections
, $toc ); }
77 function setIndexPolicy( $policy ) { return wfSetVar( $this->mIndexPolicy
, $policy ); }
78 function setTOCHTML( $tochtml ) { return wfSetVar( $this->mTOCHTML
, $tochtml ); }
81 /** Sets the number of seconds after which this object should expire.
82 * This value is used with the ParserCache.
83 * If called with a value greater than the value provided at any previous call,
84 * the new call has no effect. The value returned by getCacheExpiry is smaller
85 * or equal to the smallest number that was provided as an argument to
86 * updateCacheExpiry().
88 function updateCacheExpiry( $seconds ) {
89 $seconds = (int)$seconds;
91 if ( $this->mCacheExpiry
=== null ||
$this->mCacheExpiry
> $seconds )
92 $this->mCacheExpiry
= $seconds;
94 // hack: set old-style marker for uncacheable entries.
95 if ( $this->mCacheExpiry
!== null && $this->mCacheExpiry
<= 0 )
96 $this->mCacheTime
= -1;
99 /** Returns the number of seconds after which this object should expire.
100 * This method is used by ParserCache to determine how long the ParserOutput can be cached.
101 * The timestamp of expiry can be calculated by adding getCacheExpiry() to getCacheTime().
102 * The value returned by getCacheExpiry is smaller or equal to the smallest number
103 * that was provided to a call of updateCacheExpiry(), and smaller or equal to the
104 * value of $wgParserCacheExpireTime.
106 function getCacheExpiry() {
107 global $wgParserCacheExpireTime;
109 if ( $this->mCacheTime
< 0 ) return 0; // old-style marker for "not cachable"
111 $expire = $this->mCacheExpiry
;
113 if ( $expire === null )
114 $expire = $wgParserCacheExpireTime;
116 $expire = min( $expire, $wgParserCacheExpireTime );
118 if( $this->containsOldMagic() ) { //compatibility hack
119 $expire = min( $expire, 3600 ); # 1 hour
122 if ( $expire <= 0 ) return 0; // not cachable
126 function isCacheable() {
127 return $this->getCacheExpiry() > 0;
130 function addCategory( $c, $sort ) { $this->mCategories
[$c] = $sort; }
131 function addLanguageLink( $t ) { $this->mLanguageLinks
[] = $t; }
132 function addWarning( $s ) { $this->mWarnings
[$s] = 1; }
134 function addOutputHook( $hook, $data = false ) {
135 $this->mOutputHooks
[] = array( $hook, $data );
138 function setNewSection( $value ) {
139 $this->mNewSection
= (bool)$value;
141 function hideNewSection ( $value ) {
142 $this->mHideNewSection
= (bool)$value;
144 function getHideNewSection () {
145 return (bool)$this->mHideNewSection
;
147 function getNewSection() {
148 return (bool)$this->mNewSection
;
151 function addExternalLink( $url ) {
152 # We don't register links pointing to our own server, unless... :-)
153 global $wgServer, $wgRegisterInternalExternals;
154 if( $wgRegisterInternalExternals or stripos($url,$wgServer.'/')!==0)
155 $this->mExternalLinks
[$url] = 1;
159 * Record a local or interwiki inline link for saving in future link tables.
161 * @param $title Title object
162 * @param $id Mixed: optional known page_id so we can skip the lookup
164 function addLink( $title, $id = null ) {
165 if ( $title->isExternal() ) {
166 // Don't record interwikis in pagelinks
167 $this->addInterwikiLink( $title );
170 $ns = $title->getNamespace();
171 $dbk = $title->getDBkey();
172 if ( $ns == NS_MEDIA
) {
173 // Normalize this pseudo-alias if it makes it down here...
175 } elseif( $ns == NS_SPECIAL
) {
176 // We don't record Special: links currently
177 // It might actually be wise to, but we'd need to do some normalization.
179 } elseif( $dbk === '' ) {
180 // Don't record self links - [[#Foo]]
183 if ( !isset( $this->mLinks
[$ns] ) ) {
184 $this->mLinks
[$ns] = array();
186 if ( is_null( $id ) ) {
187 $id = $title->getArticleID();
189 $this->mLinks
[$ns][$dbk] = $id;
192 function addImage( $name ) {
193 $this->mImages
[$name] = 1;
196 function addTemplate( $title, $page_id, $rev_id ) {
197 $ns = $title->getNamespace();
198 $dbk = $title->getDBkey();
199 if ( !isset( $this->mTemplates
[$ns] ) ) {
200 $this->mTemplates
[$ns] = array();
202 $this->mTemplates
[$ns][$dbk] = $page_id;
203 if ( !isset( $this->mTemplateIds
[$ns] ) ) {
204 $this->mTemplateIds
[$ns] = array();
206 $this->mTemplateIds
[$ns][$dbk] = $rev_id; // For versioning
210 * @param $title Title object, must be an interwiki link
211 * @throws MWException if given invalid input
213 function addInterwikiLink( $title ) {
214 $prefix = $title->getInterwiki();
215 if( $prefix == '' ) {
216 throw new MWException( 'Non-interwiki link passed, internal parser error.' );
218 if (!isset($this->mInterwikiLinks
[$prefix])) {
219 $this->mInterwikiLinks
[$prefix] = array();
221 $this->mInterwikiLinks
[$prefix][$title->getDBkey()] = 1;
225 * Return true if this cached output object predates the global or
226 * per-article cache invalidation timestamps, or if it comes from
227 * an incompatible older version.
229 * @param $touched String: the affected article's last touched timestamp
232 public function expired( $touched ) {
233 global $wgCacheEpoch;
234 return !$this->isCacheable() ||
// parser says it's uncacheable
235 $this->getCacheTime() < $touched ||
236 $this->getCacheTime() <= $wgCacheEpoch ||
237 $this->getCacheTime() < wfTimestamp( TS_MW
, time() - $this->getCacheExpiry() ) ||
// expiry period has passed
238 !isset( $this->mVersion
) ||
239 version_compare( $this->mVersion
, Parser
::VERSION
, "lt" );
243 * Add some text to the <head>.
244 * If $tag is set, the section with that tag will only be included once
247 function addHeadItem( $section, $tag = false ) {
248 if ( $tag !== false ) {
249 $this->mHeadItems
[$tag] = $section;
251 $this->mHeadItems
[] = $section;
256 * Add page icons to the parser output.
257 * @param File $file A valid file
258 * @param String $alt Alt text, if any
260 function addPageIcon( $file, $alt = '' ) {
261 $this->mPageIcons
[] = array( $file, $alt );
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 );
276 * Get the title to be used for display
280 public function getDisplayTitle() {
281 $t = $this->getTitleText( );
289 * Fairly generic flag setter thingy.
291 public function setFlag( $flag ) {
292 $this->mFlags
[$flag] = true;
295 public function getFlag( $flag ) {
296 return isset( $this->mFlags
[$flag] );
300 * Set a property to be cached in the DB
302 public function setProperty( $name, $value ) {
303 $this->mProperties
[$name] = $value;
306 public function getProperty( $name ){
307 return isset( $this->mProperties
[$name] ) ?
$this->mProperties
[$name] : false;
310 public function getProperties() {
311 if ( !isset( $this->mProperties
) ) {
312 $this->mProperties
= array();
314 return $this->mProperties
;