Move tidy callbacks from the Parser class to a new Tidy class. This is to keep
[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 $mImages, # DB keys of the images used, in the array key only
18 $mExternalLinks, # External link URLs, in the key only
19 $mHTMLtitle, # Display HTML title
20 $mSubtitle, # Additional subtitle
21 $mNewSection, # Show a new section link?
22 $mNoGallery, # No gallery on category page? (__NOGALLERY__)
23 $mHeadItems; # Items to put in the <head> section
24
25 function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(),
26 $containsOldMagic = false, $titletext = '' )
27 {
28 $this->mText = $text;
29 $this->mLanguageLinks = $languageLinks;
30 $this->mCategories = $categoryLinks;
31 $this->mContainsOldMagic = $containsOldMagic;
32 $this->mCacheTime = '';
33 $this->mVersion = Parser::VERSION;
34 $this->mTitleText = $titletext;
35 $this->mLinks = array();
36 $this->mTemplates = array();
37 $this->mImages = array();
38 $this->mExternalLinks = array();
39 $this->mHTMLtitle = "" ;
40 $this->mSubtitle = "" ;
41 $this->mNewSection = false;
42 $this->mNoGallery = false;
43 $this->mHeadItems = array();
44 }
45
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 &getLinks() { return $this->mLinks; }
53 function &getTemplates() { return $this->mTemplates; }
54 function &getImages() { return $this->mImages; }
55 function &getExternalLinks() { return $this->mExternalLinks; }
56 function getNoGallery() { return $this->mNoGallery; }
57 function getSubtitle() { return $this->mSubtitle; }
58
59 function containsOldMagic() { return $this->mContainsOldMagic; }
60 function setText( $text ) { return wfSetVar( $this->mText, $text ); }
61 function setLanguageLinks( $ll ) { return wfSetVar( $this->mLanguageLinks, $ll ); }
62 function setCategoryLinks( $cl ) { return wfSetVar( $this->mCategories, $cl ); }
63 function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic, $com ); }
64 function setCacheTime( $t ) { return wfSetVar( $this->mCacheTime, $t ); }
65 function setTitleText( $t ) { return wfSetVar($this->mTitleText, $t); }
66 function setSubtitle( $st ) { return wfSetVar( $this->mSubtitle, $st ); }
67
68 function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; }
69 function addImage( $name ) { $this->mImages[$name] = 1; }
70 function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; }
71 function addExternalLink( $url ) { $this->mExternalLinks[$url] = 1; }
72
73 function setNewSection( $value ) {
74 $this->mNewSection = (bool)$value;
75 }
76 function getNewSection() {
77 return (bool)$this->mNewSection;
78 }
79
80 function addLink( $title, $id = null ) {
81 $ns = $title->getNamespace();
82 $dbk = $title->getDBkey();
83 if ( !isset( $this->mLinks[$ns] ) ) {
84 $this->mLinks[$ns] = array();
85 }
86 if ( is_null( $id ) ) {
87 $id = $title->getArticleID();
88 }
89 $this->mLinks[$ns][$dbk] = $id;
90 }
91
92 function addTemplate( $title, $id ) {
93 $ns = $title->getNamespace();
94 $dbk = $title->getDBkey();
95 if ( !isset( $this->mTemplates[$ns] ) ) {
96 $this->mTemplates[$ns] = array();
97 }
98 $this->mTemplates[$ns][$dbk] = $id;
99 }
100
101 /**
102 * Return true if this cached output object predates the global or
103 * per-article cache invalidation timestamps, or if it comes from
104 * an incompatible older version.
105 *
106 * @param string $touched the affected article's last touched timestamp
107 * @return bool
108 * @public
109 */
110 function expired( $touched ) {
111 global $wgCacheEpoch;
112 return $this->getCacheTime() == -1 || // parser says it's uncacheable
113 $this->getCacheTime() < $touched ||
114 $this->getCacheTime() <= $wgCacheEpoch ||
115 !isset( $this->mVersion ) ||
116 version_compare( $this->mVersion, Parser::VERSION, "lt" );
117 }
118
119 /**
120 * Add some text to the <head>.
121 * If $tag is set, the section with that tag will only be included once
122 * in a given page.
123 */
124 function addHeadItem( $section, $tag = false ) {
125 if ( $tag !== false ) {
126 $this->mHeadItems[$tag] = $section;
127 } else {
128 $this->mHeadItems[] = $section;
129 }
130 }
131 }
132
133 ?>