4 * Set options of the Parser
9 # All variables are supposed to be private in theory, although in practise this is not the case.
10 var $mUseDynamicDates; # Use DateFormatter to format dates
11 var $mInterwikiMagic; # Interlanguage links are removed and returned in an array
12 var $mAllowExternalImages; # Allow external images inline
13 var $mAllowExternalImagesFrom; # If not, any exception?
14 var $mEnableImageWhitelist; # If not or it doesn't match, should we check an on-wiki whitelist?
15 var $mSkin; # Reference to the preferred skin
16 var $mDateFormat; # Date format index
17 var $mEditSection; # Create "edit section" links
18 var $mNumberHeadings; # Automatically number headings
19 var $mAllowSpecialInclusion; # Allow inclusion of special pages
20 var $mTidy; # Ask for tidy cleanup
21 var $mInterfaceMessage; # Which lang to call for PLURAL and GRAMMAR
22 var $mTargetLanguage; # Overrides above setting with arbitrary language
23 var $mMaxIncludeSize; # Maximum size of template expansions, in bytes
24 var $mMaxPPNodeCount; # Maximum number of nodes touched by PPFrame::expand()
25 var $mMaxPPExpandDepth; # Maximum recursion depth in PPFrame::expand()
26 var $mMaxTemplateDepth; # Maximum recursion depth for templates within templates
27 var $mRemoveComments; # Remove HTML comments. ONLY APPLIES TO PREPROCESS OPERATIONS
28 var $mTemplateCallback; # Callback for template fetching
29 var $mEnableLimitReport; # Enable limit report in an HTML comment on output
30 var $mTimestamp; # Timestamp used for {{CURRENTDAY}} etc.
31 var $mExternalLinkTarget; # Target attribute for external links
32 var $mMath; # User math preference (as integer)
33 var $mUserLang; # Language code of the User language.
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
40 function getUseDynamicDates() { return $this->mUseDynamicDates
; }
41 function getInterwikiMagic() { return $this->mInterwikiMagic
; }
42 function getAllowExternalImages() { return $this->mAllowExternalImages
; }
43 function getAllowExternalImagesFrom() { return $this->mAllowExternalImagesFrom
; }
44 function getEnableImageWhitelist() { return $this->mEnableImageWhitelist
; }
45 function getEditSection() { return $this->mEditSection
; }
46 function getNumberHeadings() { return $this->mNumberHeadings
; }
47 function getAllowSpecialInclusion() { return $this->mAllowSpecialInclusion
; }
48 function getTidy() { return $this->mTidy
; }
49 function getInterfaceMessage() { return $this->mInterfaceMessage
; }
50 function getTargetLanguage() { return $this->mTargetLanguage
; }
51 function getMaxIncludeSize() { return $this->mMaxIncludeSize
; }
52 function getMaxPPNodeCount() { return $this->mMaxPPNodeCount
; }
53 function getMaxPPExpandDepth() { return $this->mMaxPPExpandDepth
; }
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 getMath() { return $this->mMath
; }
62 function getIsPreview() { return $this->mIsPreview
; }
63 function getIsSectionPreview() { return $this->mIsSectionPreview
; }
64 function getIsPrintable() { return $this->mIsPrintable
; }
67 if ( !isset( $this->mSkin
) ) {
68 $this->mSkin
= $this->mUser
->getSkin();
73 function getDateFormat() {
74 if ( !$this->getUseDynamicDates() ) {
75 throw new MWException( 'Getting DateFormat option without UseDynamicDates.' );
78 if ( !isset( $this->mDateFormat
) ) {
79 $this->mDateFormat
= $this->mUser
->getDatePreference();
81 return $this->mDateFormat
;
84 function getTimestamp() {
85 if ( !isset( $this->mTimestamp
) ) {
86 $this->mTimestamp
= wfTimestampNow();
88 return $this->mTimestamp
;
91 # You shouldn't use this. Really. $parser->getFunctionLang() is all you need.
92 # Using this fragments the cache and is discouraged. Yes, {{int: }} uses this,
93 # producing inconsistent tables (Bug 14404).
94 function getUserLang() {
95 return $this->mUserLang
;
98 function setUseDynamicDates( $x ) { return wfSetVar( $this->mUseDynamicDates
, $x ); }
99 function setInterwikiMagic( $x ) { return wfSetVar( $this->mInterwikiMagic
, $x ); }
100 function setAllowExternalImages( $x ) { return wfSetVar( $this->mAllowExternalImages
, $x ); }
101 function setAllowExternalImagesFrom( $x ) { return wfSetVar( $this->mAllowExternalImagesFrom
, $x ); }
102 function setEnableImageWhitelist( $x ) { return wfSetVar( $this->mEnableImageWhitelist
, $x ); }
103 function setDateFormat( $x ) { return wfSetVar( $this->mDateFormat
, $x ); }
104 function setEditSection( $x ) { return wfSetVar( $this->mEditSection
, $x ); }
105 function setNumberHeadings( $x ) { return wfSetVar( $this->mNumberHeadings
, $x ); }
106 function setAllowSpecialInclusion( $x ) { return wfSetVar( $this->mAllowSpecialInclusion
, $x ); }
107 function setTidy( $x ) { return wfSetVar( $this->mTidy
, $x); }
108 function setSkin( $x ) { $this->mSkin
= $x; }
109 function setInterfaceMessage( $x ) { return wfSetVar( $this->mInterfaceMessage
, $x); }
110 function setTargetLanguage( $x ) { return wfSetVar( $this->mTargetLanguage
, $x); }
111 function setMaxIncludeSize( $x ) { return wfSetVar( $this->mMaxIncludeSize
, $x ); }
112 function setMaxPPNodeCount( $x ) { return wfSetVar( $this->mMaxPPNodeCount
, $x ); }
113 function setMaxTemplateDepth( $x ) { return wfSetVar( $this->mMaxTemplateDepth
, $x ); }
114 function setRemoveComments( $x ) { return wfSetVar( $this->mRemoveComments
, $x ); }
115 function setTemplateCallback( $x ) { return wfSetVar( $this->mTemplateCallback
, $x ); }
116 function enableLimitReport( $x = true ) { return wfSetVar( $this->mEnableLimitReport
, $x ); }
117 function setTimestamp( $x ) { return wfSetVar( $this->mTimestamp
, $x ); }
118 function setCleanSignatures( $x ) { return wfSetVar( $this->mCleanSignatures
, $x ); }
119 function setExternalLinkTarget( $x ) { return wfSetVar( $this->mExternalLinkTarget
, $x ); }
120 function setMath( $x ) { return wfSetVar( $this->mMath
, $x ); }
121 function setUserLang( $x ) { return wfSetVar( $this->mUserLang
, $x ); }
123 function setIsPreview( $x ) { return wfSetVar( $this->mIsPreview
, $x ); }
124 function setIsSectionPreview( $x ) { return wfSetVar( $this->mIsSectionPreview
, $x ); }
125 function setIsPrintable( $x ) { return wfSetVar( $this->mIsPrintable
, $x ); }
127 function __construct( $user = null ) {
128 $this->initialiseFromUser( $user );
134 * @param $user User object
135 * @return ParserOptions object
137 static function newFromUser( $user ) {
138 return new ParserOptions( $user );
141 /** Get user options */
142 function initialiseFromUser( $userInput ) {
143 global $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
144 global $wgAllowExternalImagesFrom, $wgEnableImageWhitelist, $wgAllowSpecialInclusion, $wgMaxArticleSize;
145 global $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth, $wgCleanSignatures;
146 global $wgExternalLinkTarget, $wgLang;
148 wfProfileIn( __METHOD__
);
152 if ( isset( $wgUser ) ) {
161 $this->mUser
= $user;
163 $this->mUseDynamicDates
= $wgUseDynamicDates;
164 $this->mInterwikiMagic
= $wgInterwikiMagic;
165 $this->mAllowExternalImages
= $wgAllowExternalImages;
166 $this->mAllowExternalImagesFrom
= $wgAllowExternalImagesFrom;
167 $this->mEnableImageWhitelist
= $wgEnableImageWhitelist;
168 $this->mSkin
= null; # Deferred
169 $this->mDateFormat
= null; # Deferred
170 $this->mEditSection
= true;
171 $this->mNumberHeadings
= $user->getOption( 'numberheadings' );
172 $this->mAllowSpecialInclusion
= $wgAllowSpecialInclusion;
173 $this->mTidy
= false;
174 $this->mInterfaceMessage
= false;
175 $this->mTargetLanguage
= null; // default depends on InterfaceMessage setting
176 $this->mMaxIncludeSize
= $wgMaxArticleSize * 1024;
177 $this->mMaxPPNodeCount
= $wgMaxPPNodeCount;
178 $this->mMaxPPExpandDepth
= $wgMaxPPExpandDepth;
179 $this->mMaxTemplateDepth
= $wgMaxTemplateDepth;
180 $this->mRemoveComments
= true;
181 $this->mTemplateCallback
= array( 'Parser', 'statelessFetchTemplate' );
182 $this->mEnableLimitReport
= false;
183 $this->mCleanSignatures
= $wgCleanSignatures;
184 $this->mExternalLinkTarget
= $wgExternalLinkTarget;
185 $this->mMath
= $user->getOption( 'math' );
186 $this->mUserLang
= $wgLang->getCode();
188 $this->mIsPreview
= false;
189 $this->mIsSectionPreview
= false;
190 $this->mIsPrintable
= false;
192 wfProfileOut( __METHOD__
);