* Add method to FileRepo to get the human-readable name of the repository (getDisplay...
[mediawiki.git] / includes / parser / ParserOutput.php
blob4ad252a7a75ae39dcf2aa0c69b218cc81e187ddd
1 <?php
2 /**
3 * @todo document
4 * @ingroup Parser
5 */
6 class ParserOutput
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 $mNewSection = false, # Show a new section link?
21 $mNoGallery = false, # No gallery on category page? (__NOGALLERY__)
22 $mHeadItems = array(), # Items to put in the <head> section
23 $mOutputHooks = array(), # Hook tags as per $wgParserOutputHooks
24 $mWarnings = array(), # Warning text to be returned to the user. Wikitext formatted, in the key only
25 $mSections = array(), # Table of contents
26 $mProperties = array(); # Name/value pairs to be cached in the DB
27 private $mIndexPolicy = ''; # 'index' or 'noindex'? Any other value will result in no change.
29 /**
30 * Overridden title for display
32 private $displayTitle = false;
34 function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(),
35 $containsOldMagic = false, $titletext = '' )
37 $this->mText = $text;
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 getCategoryLinks() { return array_keys( $this->mCategories ); }
47 function &getCategories() { return $this->mCategories; }
48 function getCacheTime() { return $this->mCacheTime; }
49 function getTitleText() { return $this->mTitleText; }
50 function getSections() { return $this->mSections; }
51 function &getLinks() { return $this->mLinks; }
52 function &getTemplates() { return $this->mTemplates; }
53 function &getImages() { return $this->mImages; }
54 function &getExternalLinks() { return $this->mExternalLinks; }
55 function getNoGallery() { return $this->mNoGallery; }
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; }
61 function containsOldMagic() { return $this->mContainsOldMagic; }
62 function setText( $text ) { return wfSetVar( $this->mText, $text ); }
63 function setLanguageLinks( $ll ) { return wfSetVar( $this->mLanguageLinks, $ll ); }
64 function setCategoryLinks( $cl ) { return wfSetVar( $this->mCategories, $cl ); }
65 function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic, $com ); }
66 function setCacheTime( $t ) { return wfSetVar( $this->mCacheTime, $t ); }
67 function setTitleText( $t ) { return wfSetVar( $this->mTitleText, $t ); }
68 function setSections( $toc ) { return wfSetVar( $this->mSections, $toc ); }
69 function setIndexPolicy( $policy ) { return wfSetVar( $this->mIndexPolicy, $policy ); }
71 function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; }
72 function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; }
73 function addExternalLink( $url ) { $this->mExternalLinks[$url] = 1; }
74 function addWarning( $s ) { $this->mWarnings[$s] = 1; }
76 function addOutputHook( $hook, $data = false ) {
77 $this->mOutputHooks[] = array( $hook, $data );
80 function setNewSection( $value ) {
81 $this->mNewSection = (bool)$value;
83 function getNewSection() {
84 return (bool)$this->mNewSection;
87 function addLink( $title, $id = null ) {
88 $ns = $title->getNamespace();
89 $dbk = $title->getDBkey();
90 if ( $ns == NS_MEDIA ) {
91 // Normalize this pseudo-alias if it makes it down here...
92 $ns = NS_FILE;
93 } elseif( $ns == NS_SPECIAL ) {
94 // We don't record Special: links currently
95 // It might actually be wise to, but we'd need to do some normalization.
96 return;
97 } elseif( $dbk === '' ) {
98 // Don't record self links - [[#Foo]]
99 return;
101 if ( !isset( $this->mLinks[$ns] ) ) {
102 $this->mLinks[$ns] = array();
104 if ( is_null( $id ) ) {
105 $id = $title->getArticleID();
107 $this->mLinks[$ns][$dbk] = $id;
110 function addImage( $name ) {
111 $this->mImages[$name] = 1;
114 function addTemplate( $title, $page_id, $rev_id ) {
115 $ns = $title->getNamespace();
116 $dbk = $title->getDBkey();
117 if ( !isset( $this->mTemplates[$ns] ) ) {
118 $this->mTemplates[$ns] = array();
120 $this->mTemplates[$ns][$dbk] = $page_id;
121 if ( !isset( $this->mTemplateIds[$ns] ) ) {
122 $this->mTemplateIds[$ns] = array();
124 $this->mTemplateIds[$ns][$dbk] = $rev_id; // For versioning
128 * Return true if this cached output object predates the global or
129 * per-article cache invalidation timestamps, or if it comes from
130 * an incompatible older version.
132 * @param string $touched the affected article's last touched timestamp
133 * @return bool
134 * @public
136 function expired( $touched ) {
137 global $wgCacheEpoch;
138 return $this->getCacheTime() == -1 || // parser says it's uncacheable
139 $this->getCacheTime() < $touched ||
140 $this->getCacheTime() <= $wgCacheEpoch ||
141 !isset( $this->mVersion ) ||
142 version_compare( $this->mVersion, Parser::VERSION, "lt" );
146 * Add some text to the <head>.
147 * If $tag is set, the section with that tag will only be included once
148 * in a given page.
150 function addHeadItem( $section, $tag = false ) {
151 if ( $tag !== false ) {
152 $this->mHeadItems[$tag] = $section;
153 } else {
154 $this->mHeadItems[] = $section;
159 * Override the title to be used for display
160 * -- this is assumed to have been validated
161 * (check equal normalisation, etc.)
163 * @param string $text Desired title text
165 public function setDisplayTitle( $text ) {
166 $this->displayTitle = $text;
170 * Get the title to be used for display
172 * @return string
174 public function getDisplayTitle() {
175 return $this->displayTitle;
179 * Fairly generic flag setter thingy.
181 public function setFlag( $flag ) {
182 $this->mFlags[$flag] = true;
185 public function getFlag( $flag ) {
186 return isset( $this->mFlags[$flag] );
190 * Set a property to be cached in the DB
192 public function setProperty( $name, $value ) {
193 $this->mProperties[$name] = $value;
196 public function getProperty( $name ){
197 return isset( $this->mProperties[$name] ) ? $this->mProperties[$name] : false;
200 public function getProperties() {
201 if ( !isset( $this->mProperties ) ) {
202 $this->mProperties = array();
204 return $this->mProperties;