update porting to new machine
[wikipedia-parser-hphp.git] / ParserOutput.php
blob38d21fb55b6ee00f9fa998219f003faa553d391c
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 $mHideNewSection = false, # Hide the new section link?
22 $mNoGallery = false, # No gallery on category page? (__NOGALLERY__)
23 $mHeadItems = array(), # Items to put in the <head> section
24 $mOutputHooks = array(), # Hook tags as per $wgParserOutputHooks
25 $mWarnings = array(), # Warning text to be returned to the user. Wikitext formatted, in the key only
26 $mSections = array(), # Table of contents
27 $mProperties = array(), # Name/value pairs to be cached in the DB
28 $mTOCHTML = ''; # HTML of the TOC
29 private $mIndexPolicy = ''; # 'index' or 'noindex'? Any other value will result in no change.
31 /**
32 * Overridden title for display
34 private $displayTitle = false;
36 function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(),
37 $containsOldMagic = false, $titletext = '' )
39 $this->mText = $text;
40 $this->mLanguageLinks = $languageLinks;
41 $this->mCategories = $categoryLinks;
42 $this->mContainsOldMagic = $containsOldMagic;
43 $this->mTitleText = $titletext;
46 function getText() { return $this->mText; }
47 function &getLanguageLinks() { return $this->mLanguageLinks; }
48 function getCategoryLinks() { return array_keys( $this->mCategories ); }
49 function &getCategories() { return $this->mCategories; }
50 function getCacheTime() { return $this->mCacheTime; }
51 function getTitleText() { return $this->mTitleText; }
52 function getSections() { return $this->mSections; }
53 function &getLinks() { return $this->mLinks; }
54 function &getTemplates() { return $this->mTemplates; }
55 function &getImages() { return $this->mImages; }
56 function &getExternalLinks() { return $this->mExternalLinks; }
57 function getNoGallery() { return $this->mNoGallery; }
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; }
64 function containsOldMagic() { return $this->mContainsOldMagic; }
65 function setText( $text ) { return wfSetVar( $this->mText, $text ); }
66 function setLanguageLinks( $ll ) { return wfSetVar( $this->mLanguageLinks, $ll ); }
67 function setCategoryLinks( $cl ) { return wfSetVar( $this->mCategories, $cl ); }
68 function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic, $com ); }
69 function setCacheTime( $t ) { return wfSetVar( $this->mCacheTime, $t ); }
70 function setTitleText( $t ) { return wfSetVar( $this->mTitleText, $t ); }
71 function setSections( $toc ) { return wfSetVar( $this->mSections, $toc ); }
72 function setIndexPolicy( $policy ) { return wfSetVar( $this->mIndexPolicy, $policy ); }
73 function setTOCHTML( $tochtml ) { return wfSetVar( $this->mTOCHTML, $tochtml ); }
75 function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; }
76 function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; }
77 function addWarning( $s ) { $this->mWarnings[$s] = 1; }
79 function addOutputHook( $hook, $data = false ) {
80 $this->mOutputHooks[] = array( $hook, $data );
83 function setNewSection( $value ) {
84 $this->mNewSection = (bool)$value;
86 function hideNewSection ( $value ) {
87 $this->mHideNewSection = (bool)$value;
89 function getHideNewSection () {
90 return (bool)$this->mHideNewSection;
92 function getNewSection() {
93 return (bool)$this->mNewSection;
96 function addExternalLink( $url ) {
97 # We don't register links pointing to our own server, unless... :-)
98 global $wgServer, $wgRegisterInternalExternals;
99 if( $wgRegisterInternalExternals or stripos($url,$wgServer.'/')!==0)
100 $this->mExternalLinks[$url] = 1;
103 function addLink( $title, $id = null ) {
104 if ( $title->isExternal() ) {
105 // Don't record interwikis in pagelinks
106 return;
108 $ns = $title->getNamespace();
109 $dbk = $title->getDBkey();
110 if ( $ns == NS_MEDIA ) {
111 // Normalize this pseudo-alias if it makes it down here...
112 $ns = NS_FILE;
113 } elseif( $ns == NS_SPECIAL ) {
114 // We don't record Special: links currently
115 // It might actually be wise to, but we'd need to do some normalization.
116 return;
117 } elseif( $dbk === '' ) {
118 // Don't record self links - [[#Foo]]
119 return;
121 if ( !isset( $this->mLinks[$ns] ) ) {
122 $this->mLinks[$ns] = array();
124 if ( is_null( $id ) ) {
125 $id = $title->getArticleID();
127 $this->mLinks[$ns][$dbk] = $id;
130 function addImage( $name ) {
131 $this->mImages[$name] = 1;
134 function addTemplate( $title, $page_id, $rev_id ) {
135 $ns = $title->getNamespace();
136 $dbk = $title->getDBkey();
137 if ( !isset( $this->mTemplates[$ns] ) ) {
138 $this->mTemplates[$ns] = array();
140 $this->mTemplates[$ns][$dbk] = $page_id;
141 if ( !isset( $this->mTemplateIds[$ns] ) ) {
142 $this->mTemplateIds[$ns] = array();
144 $this->mTemplateIds[$ns][$dbk] = $rev_id; // For versioning
148 * Return true if this cached output object predates the global or
149 * per-article cache invalidation timestamps, or if it comes from
150 * an incompatible older version.
152 * @param string $touched the affected article's last touched timestamp
153 * @return bool
154 * @public
156 function expired( $touched ) {
157 global $wgCacheEpoch;
158 return $this->getCacheTime() == -1 || // parser says it's uncacheable
159 $this->getCacheTime() < $touched ||
160 $this->getCacheTime() <= $wgCacheEpoch ||
161 !isset( $this->mVersion ) ||
162 version_compare( $this->mVersion, Parser::VERSION, "lt" );
166 * Add some text to the <head>.
167 * If $tag is set, the section with that tag will only be included once
168 * in a given page.
170 function addHeadItem( $section, $tag = false ) {
171 if ( $tag !== false ) {
172 $this->mHeadItems[$tag] = $section;
173 } else {
174 $this->mHeadItems[] = $section;
179 * Override the title to be used for display
180 * -- this is assumed to have been validated
181 * (check equal normalisation, etc.)
183 * @param string $text Desired title text
185 public function setDisplayTitle( $text ) {
186 $this->displayTitle = $text;
190 * Get the title to be used for display
192 * @return string
194 public function getDisplayTitle() {
195 return $this->displayTitle;
199 * Fairly generic flag setter thingy.
201 public function setFlag( $flag ) {
202 $this->mFlags[$flag] = true;
205 public function getFlag( $flag ) {
206 return isset( $this->mFlags[$flag] );
210 * Set a property to be cached in the DB
212 public function setProperty( $name, $value ) {
213 $this->mProperties[$name] = $value;
216 public function getProperty( $name ){
217 return isset( $this->mProperties[$name] ) ? $this->mProperties[$name] : false;
220 public function getProperties() {
221 if ( !isset( $this->mProperties ) ) {
222 $this->mProperties = array();
224 return $this->mProperties;