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 $mVersion = Parser
::VERSION
, # Compatibility check
15 $mLinks = array(), # 2-D map of NS/DBK to ID for the links in the document. ID=zero for broken.
16 $mTemplates = array(), # 2-D map of NS/DBK to ID for the template references. ID=zero for broken.
17 $mTemplateIds = array(), # 2-D map of NS/DBK to rev ID for the template references. ID=zero for broken.
18 $mImages = array(), # DB keys of the images used, in the array key only
19 $mExternalLinks = array(), # External link URLs, in the key only
20 $mInterwikiLinks = array(), # 2-D map of prefix/DBK (in keys only) for the inline interwiki links in the document.
21 $mNewSection = false, # Show a new section link?
22 $mHideNewSection = false, # Hide the new section link?
23 $mNoGallery = false, # No gallery on category page? (__NOGALLERY__)
24 $mHeadItems = array(), # Items to put in the <head> section
25 $mOutputHooks = array(), # Hook tags as per $wgParserOutputHooks
26 $mWarnings = array(), # Warning text to be returned to the user. Wikitext formatted, in the key only
27 $mSections = array(), # Table of contents
28 $mProperties = array(), # Name/value pairs to be cached in the DB
29 $mTOCHTML = ''; # HTML of the TOC
30 private $mIndexPolicy = ''; # 'index' or 'noindex'? Any other value will result in no change.
32 function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(),
33 $containsOldMagic = false, $titletext = '' )
36 $this->mLanguageLinks
= $languageLinks;
37 $this->mCategories
= $categoryLinks;
38 $this->mContainsOldMagic
= $containsOldMagic;
39 $this->mTitleText
= $titletext;
42 function getText() { return $this->mText
; }
43 function &getLanguageLinks() { return $this->mLanguageLinks
; }
44 function getInterwikiLinks() { return $this->mInterwikiLinks
; }
45 function getCategoryLinks() { return array_keys( $this->mCategories
); }
46 function &getCategories() { return $this->mCategories
; }
47 function getCacheTime() { return $this->mCacheTime
; }
48 function getTitleText() { return $this->mTitleText
; }
49 function getSections() { return $this->mSections
; }
50 function &getLinks() { return $this->mLinks
; }
51 function &getTemplates() { return $this->mTemplates
; }
52 function &getImages() { return $this->mImages
; }
53 function &getExternalLinks() { return $this->mExternalLinks
; }
54 function getNoGallery() { return $this->mNoGallery
; }
55 function getHeadItems() { return $this->mHeadItems
; }
56 function getSubtitle() { return $this->mSubtitle
; }
57 function getOutputHooks() { return (array)$this->mOutputHooks
; }
58 function getWarnings() { return array_keys( $this->mWarnings
); }
59 function getIndexPolicy() { return $this->mIndexPolicy
; }
60 function getTOCHTML() { return $this->mTOCHTML
; }
62 function containsOldMagic() { return $this->mContainsOldMagic
; }
63 function setText( $text ) { return wfSetVar( $this->mText
, $text ); }
64 function setLanguageLinks( $ll ) { return wfSetVar( $this->mLanguageLinks
, $ll ); }
65 function setCategoryLinks( $cl ) { return wfSetVar( $this->mCategories
, $cl ); }
66 function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic
, $com ); }
67 function setCacheTime( $t ) { return wfSetVar( $this->mCacheTime
, $t ); }
68 function setTitleText( $t ) { return wfSetVar( $this->mTitleText
, $t ); }
69 function setSections( $toc ) { return wfSetVar( $this->mSections
, $toc ); }
70 function setIndexPolicy( $policy ) { return wfSetVar( $this->mIndexPolicy
, $policy ); }
71 function setTOCHTML( $tochtml ) { return wfSetVar( $this->mTOCHTML
, $tochtml ); }
73 function addCategory( $c, $sort ) { $this->mCategories
[$c] = $sort; }
74 function addLanguageLink( $t ) { $this->mLanguageLinks
[] = $t; }
75 function addWarning( $s ) { $this->mWarnings
[$s] = 1; }
77 function addOutputHook( $hook, $data = false ) {
78 $this->mOutputHooks
[] = array( $hook, $data );
81 function setNewSection( $value ) {
82 $this->mNewSection
= (bool)$value;
84 function hideNewSection ( $value ) {
85 $this->mHideNewSection
= (bool)$value;
87 function getHideNewSection () {
88 return (bool)$this->mHideNewSection
;
90 function getNewSection() {
91 return (bool)$this->mNewSection
;
94 function addExternalLink( $url ) {
95 # We don't register links pointing to our own server, unless... :-)
96 global $wgServer, $wgRegisterInternalExternals;
97 if( $wgRegisterInternalExternals or stripos($url,$wgServer.'/')!==0)
98 $this->mExternalLinks
[$url] = 1;
102 * Record a local or interwiki inline link for saving in future link tables.
104 * @param Title $title
105 * @param mixed $id optional known page_id so we can skip the lookup
107 function addLink( $title, $id = null ) {
108 wfDebug(__METHOD__
. " got: " . $title->getPrefixedText() . "\n");
109 if ( $title->isExternal() ) {
110 // Don't record interwikis in pagelinks
111 $this->addInterwikiLink( $title );
114 $ns = $title->getNamespace();
115 $dbk = $title->getDBkey();
116 if ( $ns == NS_MEDIA
) {
117 // Normalize this pseudo-alias if it makes it down here...
119 } elseif( $ns == NS_SPECIAL
) {
120 // We don't record Special: links currently
121 // It might actually be wise to, but we'd need to do some normalization.
123 } elseif( $dbk === '' ) {
124 // Don't record self links - [[#Foo]]
127 if ( !isset( $this->mLinks
[$ns] ) ) {
128 $this->mLinks
[$ns] = array();
130 if ( is_null( $id ) ) {
131 $id = $title->getArticleID();
133 $this->mLinks
[$ns][$dbk] = $id;
136 function addImage( $name ) {
137 $this->mImages
[$name] = 1;
140 function addTemplate( $title, $page_id, $rev_id ) {
141 $ns = $title->getNamespace();
142 $dbk = $title->getDBkey();
143 if ( !isset( $this->mTemplates
[$ns] ) ) {
144 $this->mTemplates
[$ns] = array();
146 $this->mTemplates
[$ns][$dbk] = $page_id;
147 if ( !isset( $this->mTemplateIds
[$ns] ) ) {
148 $this->mTemplateIds
[$ns] = array();
150 $this->mTemplateIds
[$ns][$dbk] = $rev_id; // For versioning
154 * @param Title $title object, must be an interwiki link
155 * @throws MWException if given invalid input
157 function addInterwikiLink( $title ) {
158 $prefix = $title->getInterwiki();
159 if( $prefix == '' ) {
160 throw new MWException( 'Non-interwiki link passed, internal parser error.' );
162 if (!isset($this->mInterwikiLinks
[$prefix])) {
163 $this->mInterwikiLinks
[$prefix] = array();
165 $this->mInterwikiLinks
[$prefix][$title->getDBkey()] = 1;
169 * Return true if this cached output object predates the global or
170 * per-article cache invalidation timestamps, or if it comes from
171 * an incompatible older version.
173 * @param string $touched the affected article's last touched timestamp
177 function expired( $touched ) {
178 global $wgCacheEpoch;
179 return $this->getCacheTime() == -1 ||
// parser says it's uncacheable
180 $this->getCacheTime() < $touched ||
181 $this->getCacheTime() <= $wgCacheEpoch ||
182 !isset( $this->mVersion
) ||
183 version_compare( $this->mVersion
, Parser
::VERSION
, "lt" );
187 * Add some text to the <head>.
188 * If $tag is set, the section with that tag will only be included once
191 function addHeadItem( $section, $tag = false ) {
192 if ( $tag !== false ) {
193 $this->mHeadItems
[$tag] = $section;
195 $this->mHeadItems
[] = $section;
200 * Override the title to be used for display
201 * -- this is assumed to have been validated
202 * (check equal normalisation, etc.)
204 * @param string $text Desired title text
206 public function setDisplayTitle( $text ) {
207 $this->setTitleText( $text );
211 * Get the title to be used for display
215 public function getDisplayTitle() {
216 $t = $this->getTitleText( );
224 * Fairly generic flag setter thingy.
226 public function setFlag( $flag ) {
227 $this->mFlags
[$flag] = true;
230 public function getFlag( $flag ) {
231 return isset( $this->mFlags
[$flag] );
235 * Set a property to be cached in the DB
237 public function setProperty( $name, $value ) {
238 $this->mProperties
[$name] = $value;
241 public function getProperty( $name ){
242 return isset( $this->mProperties
[$name] ) ?
$this->mProperties
[$name] : false;
245 public function getProperties() {
246 if ( !isset( $this->mProperties
) ) {
247 $this->mProperties
= array();
249 return $this->mProperties
;