Fixing some irritating whitespace
[lhc/web/wiklou.git] / includes / parser / ParserOptions.php
1 <?php
2
3 /**
4 * Set options of the Parser
5 * @todo document
6 * @ingroup Parser
7 */
8 class ParserOptions
9 {
10 # All variables are supposed to be private in theory, although in practise this is not the case.
11 var $mUseTeX; # Use texvc to expand <math> tags
12 var $mUseDynamicDates; # Use DateFormatter to format dates
13 var $mInterwikiMagic; # Interlanguage links are removed and returned in an array
14 var $mAllowExternalImages; # Allow external images inline
15 var $mAllowExternalImagesFrom; # If not, any exception?
16 var $mEnableImageWhitelist; # If not or it doesn't match, should we check an on-wiki whitelist?
17 var $mSkin; # Reference to the preferred skin
18 var $mDateFormat; # Date format index
19 var $mEditSection; # Create "edit section" links
20 var $mNumberHeadings; # Automatically number headings
21 var $mAllowSpecialInclusion; # Allow inclusion of special pages
22 var $mTidy; # Ask for tidy cleanup
23 var $mInterfaceMessage; # Which lang to call for PLURAL and GRAMMAR
24 var $mTargetLanguage; # Overrides above setting with arbitrary language
25 var $mMaxIncludeSize; # Maximum size of template expansions, in bytes
26 var $mMaxPPNodeCount; # Maximum number of nodes touched by PPFrame::expand()
27 var $mMaxPPExpandDepth; # Maximum recursion depth in PPFrame::expand()
28 var $mMaxTemplateDepth; # Maximum recursion depth for templates within templates
29 var $mRemoveComments; # Remove HTML comments. ONLY APPLIES TO PREPROCESS OPERATIONS
30 var $mTemplateCallback; # Callback for template fetching
31 var $mEnableLimitReport; # Enable limit report in an HTML comment on output
32 var $mTimestamp; # Timestamp used for {{CURRENTDAY}} etc.
33 var $mExternalLinkTarget; # Target attribute for external links
34
35 var $mUser; # Stored user object, just used to initialise the skin
36 var $mIsPreview; # Parsing the page for a "preview" operation
37 var $mIsSectionPreview; # Parsing the page for a "preview" operation on a single section
38 var $mIsPrintable; # Parsing the printable version of the page
39
40 function getUseTeX() { return $this->mUseTeX; }
41 function getUseDynamicDates() { return $this->mUseDynamicDates; }
42 function getInterwikiMagic() { return $this->mInterwikiMagic; }
43 function getAllowExternalImages() { return $this->mAllowExternalImages; }
44 function getAllowExternalImagesFrom() { return $this->mAllowExternalImagesFrom; }
45 function getEnableImageWhitelist() { return $this->mEnableImageWhitelist; }
46 function getEditSection() { return $this->mEditSection; }
47 function getNumberHeadings() { return $this->mNumberHeadings; }
48 function getAllowSpecialInclusion() { return $this->mAllowSpecialInclusion; }
49 function getTidy() { return $this->mTidy; }
50 function getInterfaceMessage() { return $this->mInterfaceMessage; }
51 function getTargetLanguage() { return $this->mTargetLanguage; }
52 function getMaxIncludeSize() { return $this->mMaxIncludeSize; }
53 function getMaxPPNodeCount() { return $this->mMaxPPNodeCount; }
54 function getMaxTemplateDepth() { return $this->mMaxTemplateDepth; }
55 function getRemoveComments() { return $this->mRemoveComments; }
56 function getTemplateCallback() { return $this->mTemplateCallback; }
57 function getEnableLimitReport() { return $this->mEnableLimitReport; }
58 function getCleanSignatures() { return $this->mCleanSignatures; }
59 function getExternalLinkTarget() { return $this->mExternalLinkTarget; }
60 function getIsPreview() { return $this->mIsPreview; }
61 function getIsSectionPreview() { return $this->mIsSectionPreview; }
62 function getIsPrintable() { return $this->mIsPrintable; }
63
64 function getSkin() {
65 if ( !isset( $this->mSkin ) ) {
66 $this->mSkin = $this->mUser->getSkin();
67 }
68 return $this->mSkin;
69 }
70
71 function getDateFormat() {
72 if ( !isset( $this->mDateFormat ) ) {
73 $this->mDateFormat = $this->mUser->getDatePreference();
74 }
75 return $this->mDateFormat;
76 }
77
78 function getTimestamp() {
79 if ( !isset( $this->mTimestamp ) ) {
80 $this->mTimestamp = wfTimestampNow();
81 }
82 return $this->mTimestamp;
83 }
84
85 function setUseTeX( $x ) { return wfSetVar( $this->mUseTeX, $x ); }
86 function setUseDynamicDates( $x ) { return wfSetVar( $this->mUseDynamicDates, $x ); }
87 function setInterwikiMagic( $x ) { return wfSetVar( $this->mInterwikiMagic, $x ); }
88 function setAllowExternalImages( $x ) { return wfSetVar( $this->mAllowExternalImages, $x ); }
89 function setAllowExternalImagesFrom( $x ) { return wfSetVar( $this->mAllowExternalImagesFrom, $x ); }
90 function setEnableImageWhitelist( $x ) { return wfSetVar( $this->mEnableImageWhitelist, $x ); }
91 function setDateFormat( $x ) { return wfSetVar( $this->mDateFormat, $x ); }
92 function setEditSection( $x ) { return wfSetVar( $this->mEditSection, $x ); }
93 function setNumberHeadings( $x ) { return wfSetVar( $this->mNumberHeadings, $x ); }
94 function setAllowSpecialInclusion( $x ) { return wfSetVar( $this->mAllowSpecialInclusion, $x ); }
95 function setTidy( $x ) { return wfSetVar( $this->mTidy, $x); }
96 function setSkin( $x ) { $this->mSkin = $x; }
97 function setInterfaceMessage( $x ) { return wfSetVar( $this->mInterfaceMessage, $x); }
98 function setTargetLanguage( $x ) { return wfSetVar( $this->mTargetLanguage, $x); }
99 function setMaxIncludeSize( $x ) { return wfSetVar( $this->mMaxIncludeSize, $x ); }
100 function setMaxPPNodeCount( $x ) { return wfSetVar( $this->mMaxPPNodeCount, $x ); }
101 function setMaxTemplateDepth( $x ) { return wfSetVar( $this->mMaxTemplateDepth, $x ); }
102 function setRemoveComments( $x ) { return wfSetVar( $this->mRemoveComments, $x ); }
103 function setTemplateCallback( $x ) { return wfSetVar( $this->mTemplateCallback, $x ); }
104 function enableLimitReport( $x = true ) { return wfSetVar( $this->mEnableLimitReport, $x ); }
105 function setTimestamp( $x ) { return wfSetVar( $this->mTimestamp, $x ); }
106 function setCleanSignatures( $x ) { return wfSetVar( $this->mCleanSignatures, $x ); }
107 function setExternalLinkTarget( $x ) { return wfSetVar( $this->mExternalLinkTarget, $x ); }
108 function setIsPreview( $x ) { return wfSetVar( $this->mIsPreview, $x ); }
109 function setIsSectionPreview( $x ) { return wfSetVar( $this->mIsSectionPreview, $x ); }
110 function setIsPrintable( $x ) { return wfSetVar( $this->mIsPrintable, $x ); }
111
112 function __construct( $user = null ) {
113 $this->initialiseFromUser( $user );
114 }
115
116 /**
117 * Get parser options
118 * @static
119 */
120 static function newFromUser( $user ) {
121 return new ParserOptions( $user );
122 }
123
124 /** Get user options */
125 function initialiseFromUser( $userInput ) {
126 global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
127 global $wgAllowExternalImagesFrom, $wgEnableImageWhitelist, $wgAllowSpecialInclusion, $wgMaxArticleSize;
128 global $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth, $wgCleanSignatures;
129 global $wgExternalLinkTarget;
130 $fname = 'ParserOptions::initialiseFromUser';
131 wfProfileIn( $fname );
132 if ( !$userInput ) {
133 global $wgUser;
134 if ( isset( $wgUser ) ) {
135 $user = $wgUser;
136 } else {
137 $user = new User;
138 }
139 } else {
140 $user =& $userInput;
141 }
142
143 $this->mUser = $user;
144
145 $this->mUseTeX = $wgUseTeX;
146 $this->mUseDynamicDates = $wgUseDynamicDates;
147 $this->mInterwikiMagic = $wgInterwikiMagic;
148 $this->mAllowExternalImages = $wgAllowExternalImages;
149 $this->mAllowExternalImagesFrom = $wgAllowExternalImagesFrom;
150 $this->mEnableImageWhitelist = $wgEnableImageWhitelist;
151 $this->mSkin = null; # Deferred
152 $this->mDateFormat = null; # Deferred
153 $this->mEditSection = true;
154 $this->mNumberHeadings = $user->getOption( 'numberheadings' );
155 $this->mAllowSpecialInclusion = $wgAllowSpecialInclusion;
156 $this->mTidy = false;
157 $this->mInterfaceMessage = false;
158 $this->mTargetLanguage = null; // default depends on InterfaceMessage setting
159 $this->mMaxIncludeSize = $wgMaxArticleSize * 1024;
160 $this->mMaxPPNodeCount = $wgMaxPPNodeCount;
161 $this->mMaxPPExpandDepth = $wgMaxPPExpandDepth;
162 $this->mMaxTemplateDepth = $wgMaxTemplateDepth;
163 $this->mRemoveComments = true;
164 $this->mTemplateCallback = array( 'Parser', 'statelessFetchTemplate' );
165 $this->mEnableLimitReport = false;
166 $this->mCleanSignatures = $wgCleanSignatures;
167 $this->mExternalLinkTarget = $wgExternalLinkTarget;
168 $this->mIsPreview = false;
169 $this->mIsSectionPreview = false;
170 wfProfileOut( $fname );
171 }
172 }