*Add year/month selector to user contribs (bug 516)
[lhc/web/wiklou.git] / includes / ParserOutput.php
1 <?php
2 /**
3 * @todo document
4 * @addtogroup 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 $mCacheTime, # Time when this object was generated, or -1 for uncacheable. Used in ParserCache.
13 $mVersion, # Compatibility check
14 $mTitleText, # title text of the chosen language variant
15 $mLinks, # 2-D map of NS/DBK to ID for the links in the document. ID=zero for broken.
16 $mTemplates, # 2-D map of NS/DBK to ID for the template references. ID=zero for broken.
17 $mTemplateIds, # 2-D map of NS/DBK to rev ID for the template references. ID=zero for broken.
18 $mImages, # DB keys of the images used, in the array key only
19 $mExternalLinks, # External link URLs, in the key only
20 $mHTMLtitle, # Display HTML title
21 $mSubtitle, # Additional subtitle
22 $mNewSection, # Show a new section link?
23 $mNoGallery, # No gallery on category page? (__NOGALLERY__)
24 $mHeadItems; # Items to put in the <head> section
25
26 function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(),
27 $containsOldMagic = false, $titletext = '' )
28 {
29 $this->mText = $text;
30 $this->mLanguageLinks = $languageLinks;
31 $this->mCategories = $categoryLinks;
32 $this->mContainsOldMagic = $containsOldMagic;
33 $this->mCacheTime = '';
34 $this->mVersion = Parser::VERSION;
35 $this->mTitleText = $titletext;
36 $this->mLinks = array();
37 $this->mTemplates = array();
38 $this->mImages = array();
39 $this->mExternalLinks = array();
40 $this->mHTMLtitle = "" ;
41 $this->mSubtitle = "" ;
42 $this->mNewSection = false;
43 $this->mNoGallery = false;
44 $this->mHeadItems = array();
45 $this->mTemplateIds = array();
46 }
47
48 function getText() { return $this->mText; }
49 function &getLanguageLinks() { return $this->mLanguageLinks; }
50 function getCategoryLinks() { return array_keys( $this->mCategories ); }
51 function &getCategories() { return $this->mCategories; }
52 function getCacheTime() { return $this->mCacheTime; }
53 function getTitleText() { return $this->mTitleText; }
54 function &getLinks() { return $this->mLinks; }
55 function &getTemplates() { return $this->mTemplates; }
56 function &getImages() { return $this->mImages; }
57 function &getExternalLinks() { return $this->mExternalLinks; }
58 function getNoGallery() { return $this->mNoGallery; }
59 function getSubtitle() { return $this->mSubtitle; }
60
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 setSubtitle( $st ) { return wfSetVar( $this->mSubtitle, $st ); }
69
70 function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; }
71 function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; }
72 function addExternalLink( $url ) { $this->mExternalLinks[$url] = 1; }
73
74 function setNewSection( $value ) {
75 $this->mNewSection = (bool)$value;
76 }
77 function getNewSection() {
78 return (bool)$this->mNewSection;
79 }
80
81 function addLink( $title, $id = null ) {
82 $ns = $title->getNamespace();
83 $dbk = $title->getDBkey();
84 if ( !isset( $this->mLinks[$ns] ) ) {
85 $this->mLinks[$ns] = array();
86 }
87 if ( is_null( $id ) ) {
88 $id = $title->getArticleID();
89 }
90 $this->mLinks[$ns][$dbk] = $id;
91 }
92
93 function addImage( $name ) {
94 $this->mImages[$name] = 1;
95 }
96
97 function addTemplate( $title, $page_id, $rev_id ) {
98 $ns = $title->getNamespace();
99 $dbk = $title->getDBkey();
100 if ( !isset( $this->mTemplates[$ns] ) ) {
101 $this->mTemplates[$ns] = array();
102 }
103 $this->mTemplates[$ns][$dbk] = $page_id;
104 if ( !isset( $this->mTemplateIds[$ns] ) ) {
105 $this->mTemplateIds[$ns] = array();
106 }
107 $this->mTemplateIds[$ns][$dbk] = $rev_id; // For versioning
108 }
109
110 /**
111 * Return true if this cached output object predates the global or
112 * per-article cache invalidation timestamps, or if it comes from
113 * an incompatible older version.
114 *
115 * @param string $touched the affected article's last touched timestamp
116 * @return bool
117 * @public
118 */
119 function expired( $touched ) {
120 global $wgCacheEpoch;
121 return $this->getCacheTime() == -1 || // parser says it's uncacheable
122 $this->getCacheTime() < $touched ||
123 $this->getCacheTime() <= $wgCacheEpoch ||
124 !isset( $this->mVersion ) ||
125 version_compare( $this->mVersion, Parser::VERSION, "lt" );
126 }
127
128 /**
129 * Add some text to the <head>.
130 * If $tag is set, the section with that tag will only be included once
131 * in a given page.
132 */
133 function addHeadItem( $section, $tag = false ) {
134 if ( $tag !== false ) {
135 $this->mHeadItems[$tag] = $section;
136 } else {
137 $this->mHeadItems[] = $section;
138 }
139 }
140 }
141
142 ?>