Fixed some doxygen warnings
[lhc/web/wiklou.git] / includes / parser / ParserOutput.php
1 <?php
2 /**
3 * @todo document
4 * @ingroup Parser
5 */
6 class ParserOutput
7 {
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.
31
32 function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(),
33 $containsOldMagic = false, $titletext = '' )
34 {
35 $this->mText = $text;
36 $this->mLanguageLinks = $languageLinks;
37 $this->mCategories = $categoryLinks;
38 $this->mContainsOldMagic = $containsOldMagic;
39 $this->mTitleText = $titletext;
40 }
41
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; }
61
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 ); }
72
73 function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; }
74 function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; }
75 function addWarning( $s ) { $this->mWarnings[$s] = 1; }
76
77 function addOutputHook( $hook, $data = false ) {
78 $this->mOutputHooks[] = array( $hook, $data );
79 }
80
81 function setNewSection( $value ) {
82 $this->mNewSection = (bool)$value;
83 }
84 function hideNewSection ( $value ) {
85 $this->mHideNewSection = (bool)$value;
86 }
87 function getHideNewSection () {
88 return (bool)$this->mHideNewSection;
89 }
90 function getNewSection() {
91 return (bool)$this->mNewSection;
92 }
93
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;
99 }
100
101 /**
102 * Record a local or interwiki inline link for saving in future link tables.
103 *
104 * @param $title Title object
105 * @param $id Mixed: optional known page_id so we can skip the lookup
106 */
107 function addLink( $title, $id = null ) {
108 if ( $title->isExternal() ) {
109 // Don't record interwikis in pagelinks
110 $this->addInterwikiLink( $title );
111 return;
112 }
113 $ns = $title->getNamespace();
114 $dbk = $title->getDBkey();
115 if ( $ns == NS_MEDIA ) {
116 // Normalize this pseudo-alias if it makes it down here...
117 $ns = NS_FILE;
118 } elseif( $ns == NS_SPECIAL ) {
119 // We don't record Special: links currently
120 // It might actually be wise to, but we'd need to do some normalization.
121 return;
122 } elseif( $dbk === '' ) {
123 // Don't record self links - [[#Foo]]
124 return;
125 }
126 if ( !isset( $this->mLinks[$ns] ) ) {
127 $this->mLinks[$ns] = array();
128 }
129 if ( is_null( $id ) ) {
130 $id = $title->getArticleID();
131 }
132 $this->mLinks[$ns][$dbk] = $id;
133 }
134
135 function addImage( $name ) {
136 $this->mImages[$name] = 1;
137 }
138
139 function addTemplate( $title, $page_id, $rev_id ) {
140 $ns = $title->getNamespace();
141 $dbk = $title->getDBkey();
142 if ( !isset( $this->mTemplates[$ns] ) ) {
143 $this->mTemplates[$ns] = array();
144 }
145 $this->mTemplates[$ns][$dbk] = $page_id;
146 if ( !isset( $this->mTemplateIds[$ns] ) ) {
147 $this->mTemplateIds[$ns] = array();
148 }
149 $this->mTemplateIds[$ns][$dbk] = $rev_id; // For versioning
150 }
151
152 /**
153 * @param $title Title object, must be an interwiki link
154 * @throws MWException if given invalid input
155 */
156 function addInterwikiLink( $title ) {
157 $prefix = $title->getInterwiki();
158 if( $prefix == '' ) {
159 throw new MWException( 'Non-interwiki link passed, internal parser error.' );
160 }
161 if (!isset($this->mInterwikiLinks[$prefix])) {
162 $this->mInterwikiLinks[$prefix] = array();
163 }
164 $this->mInterwikiLinks[$prefix][$title->getDBkey()] = 1;
165 }
166
167 /**
168 * Return true if this cached output object predates the global or
169 * per-article cache invalidation timestamps, or if it comes from
170 * an incompatible older version.
171 *
172 * @param $touched String: the affected article's last touched timestamp
173 * @return Boolean
174 */
175 public function expired( $touched ) {
176 global $wgCacheEpoch;
177 return $this->getCacheTime() == -1 || // parser says it's uncacheable
178 $this->getCacheTime() < $touched ||
179 $this->getCacheTime() <= $wgCacheEpoch ||
180 !isset( $this->mVersion ) ||
181 version_compare( $this->mVersion, Parser::VERSION, "lt" );
182 }
183
184 /**
185 * Add some text to the <head>.
186 * If $tag is set, the section with that tag will only be included once
187 * in a given page.
188 */
189 function addHeadItem( $section, $tag = false ) {
190 if ( $tag !== false ) {
191 $this->mHeadItems[$tag] = $section;
192 } else {
193 $this->mHeadItems[] = $section;
194 }
195 }
196
197 /**
198 * Override the title to be used for display
199 * -- this is assumed to have been validated
200 * (check equal normalisation, etc.)
201 *
202 * @param $text String: desired title text
203 */
204 public function setDisplayTitle( $text ) {
205 $this->setTitleText( $text );
206 }
207
208 /**
209 * Get the title to be used for display
210 *
211 * @return String
212 */
213 public function getDisplayTitle() {
214 $t = $this->getTitleText( );
215 if( $t === '' ) {
216 return false;
217 }
218 return $t;
219 }
220
221 /**
222 * Fairly generic flag setter thingy.
223 */
224 public function setFlag( $flag ) {
225 $this->mFlags[$flag] = true;
226 }
227
228 public function getFlag( $flag ) {
229 return isset( $this->mFlags[$flag] );
230 }
231
232 /**
233 * Set a property to be cached in the DB
234 */
235 public function setProperty( $name, $value ) {
236 $this->mProperties[$name] = $value;
237 }
238
239 public function getProperty( $name ){
240 return isset( $this->mProperties[$name] ) ? $this->mProperties[$name] : false;
241 }
242
243 public function getProperties() {
244 if ( !isset( $this->mProperties ) ) {
245 $this->mProperties = array();
246 }
247 return $this->mProperties;
248 }
249 }