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.
34 var $mThumbSize; # Thumb size preferred by the user.
36 var $mUser; # Stored user object, just used to initialise the skin
37 var $mIsPreview; # Parsing the page for a "preview" operation
38 var $mIsSectionPreview; # Parsing the page for a "preview" operation on a single section
39 var $mIsPrintable; # Parsing the printable version of the page
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 getMaxPPExpandDepth() { return $this->mMaxPPExpandDepth
; }
55 function getMaxTemplateDepth() { return $this->mMaxTemplateDepth
; }
56 function getRemoveComments() { return $this->mRemoveComments
; }
57 function getTemplateCallback() { return $this->mTemplateCallback
; }
58 function getEnableLimitReport() { return $this->mEnableLimitReport
; }
59 function getCleanSignatures() { return $this->mCleanSignatures
; }
60 function getExternalLinkTarget() { return $this->mExternalLinkTarget
; }
61 function getMath() { return $this->mMath
; }
62 function getThumbSize() { return $this->mThumbSize
; }
64 function getIsPreview() { return $this->mIsPreview
; }
65 function getIsSectionPreview() { return $this->mIsSectionPreview
; }
66 function getIsPrintable() { return $this->mIsPrintable
; }
69 if ( !isset( $this->mSkin
) ) {
70 $this->mSkin
= $this->mUser
->getSkin();
75 function getDateFormat() {
76 if ( !isset( $this->mDateFormat
) ) {
77 $this->mDateFormat
= $this->mUser
->getDatePreference();
79 return $this->mDateFormat
;
82 function getTimestamp() {
83 if ( !isset( $this->mTimestamp
) ) {
84 $this->mTimestamp
= wfTimestampNow();
86 return $this->mTimestamp
;
89 # You shouldn't use this. Really. $parser->getFunctionLang() is all you need.
90 # Using this fragments the cache and is discouraged. Yes, {{int: }} uses this,
91 # producing inconsistent tables (Bug 14404).
92 function getUserLang() {
93 return $this->mUserLang
;
96 function setUseDynamicDates( $x ) { return wfSetVar( $this->mUseDynamicDates
, $x ); }
97 function setInterwikiMagic( $x ) { return wfSetVar( $this->mInterwikiMagic
, $x ); }
98 function setAllowExternalImages( $x ) { return wfSetVar( $this->mAllowExternalImages
, $x ); }
99 function setAllowExternalImagesFrom( $x ) { return wfSetVar( $this->mAllowExternalImagesFrom
, $x ); }
100 function setEnableImageWhitelist( $x ) { return wfSetVar( $this->mEnableImageWhitelist
, $x ); }
101 function setDateFormat( $x ) { return wfSetVar( $this->mDateFormat
, $x ); }
102 function setEditSection( $x ) { return wfSetVar( $this->mEditSection
, $x ); }
103 function setNumberHeadings( $x ) { return wfSetVar( $this->mNumberHeadings
, $x ); }
104 function setAllowSpecialInclusion( $x ) { return wfSetVar( $this->mAllowSpecialInclusion
, $x ); }
105 function setTidy( $x ) { return wfSetVar( $this->mTidy
, $x); }
106 function setSkin( $x ) { $this->mSkin
= $x; }
107 function setInterfaceMessage( $x ) { return wfSetVar( $this->mInterfaceMessage
, $x); }
108 function setTargetLanguage( $x ) { return wfSetVar( $this->mTargetLanguage
, $x); }
109 function setMaxIncludeSize( $x ) { return wfSetVar( $this->mMaxIncludeSize
, $x ); }
110 function setMaxPPNodeCount( $x ) { return wfSetVar( $this->mMaxPPNodeCount
, $x ); }
111 function setMaxTemplateDepth( $x ) { return wfSetVar( $this->mMaxTemplateDepth
, $x ); }
112 function setRemoveComments( $x ) { return wfSetVar( $this->mRemoveComments
, $x ); }
113 function setTemplateCallback( $x ) { return wfSetVar( $this->mTemplateCallback
, $x ); }
114 function enableLimitReport( $x = true ) { return wfSetVar( $this->mEnableLimitReport
, $x ); }
115 function setTimestamp( $x ) { return wfSetVar( $this->mTimestamp
, $x ); }
116 function setCleanSignatures( $x ) { return wfSetVar( $this->mCleanSignatures
, $x ); }
117 function setExternalLinkTarget( $x ) { return wfSetVar( $this->mExternalLinkTarget
, $x ); }
118 function setMath( $x ) { return wfSetVar( $this->mMath
, $x ); }
119 function setUserLang( $x ) { return wfSetVar( $this->mUserLang
, $x ); }
120 function setThumbSize() { return wfSetVar( $this->mThumbSize
, $x ); }
122 function setIsPreview( $x ) { return wfSetVar( $this->mIsPreview
, $x ); }
123 function setIsSectionPreview( $x ) { return wfSetVar( $this->mIsSectionPreview
, $x ); }
124 function setIsPrintable( $x ) { return wfSetVar( $this->mIsPrintable
, $x ); }
126 function __construct( $user = null ) {
127 $this->initialiseFromUser( $user );
133 * @param $user User object
134 * @return ParserOptions object
136 static function newFromUser( $user ) {
137 return new ParserOptions( $user );
140 /** Get user options */
141 function initialiseFromUser( $userInput ) {
142 global $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
143 global $wgAllowExternalImagesFrom, $wgEnableImageWhitelist, $wgAllowSpecialInclusion, $wgMaxArticleSize;
144 global $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth, $wgCleanSignatures;
145 global $wgExternalLinkTarget, $wgLang;
147 wfProfileIn( __METHOD__
);
151 if ( isset( $wgUser ) ) {
160 $this->mUser
= $user;
162 $this->mUseDynamicDates
= $wgUseDynamicDates;
163 $this->mInterwikiMagic
= $wgInterwikiMagic;
164 $this->mAllowExternalImages
= $wgAllowExternalImages;
165 $this->mAllowExternalImagesFrom
= $wgAllowExternalImagesFrom;
166 $this->mEnableImageWhitelist
= $wgEnableImageWhitelist;
167 $this->mSkin
= null; # Deferred
168 $this->mDateFormat
= null; # Deferred
169 $this->mEditSection
= true;
170 $this->mNumberHeadings
= $user->getOption( 'numberheadings' );
171 $this->mAllowSpecialInclusion
= $wgAllowSpecialInclusion;
172 $this->mTidy
= false;
173 $this->mInterfaceMessage
= false;
174 $this->mTargetLanguage
= null; // default depends on InterfaceMessage setting
175 $this->mMaxIncludeSize
= $wgMaxArticleSize * 1024;
176 $this->mMaxPPNodeCount
= $wgMaxPPNodeCount;
177 $this->mMaxPPExpandDepth
= $wgMaxPPExpandDepth;
178 $this->mMaxTemplateDepth
= $wgMaxTemplateDepth;
179 $this->mRemoveComments
= true;
180 $this->mTemplateCallback
= array( 'Parser', 'statelessFetchTemplate' );
181 $this->mEnableLimitReport
= false;
182 $this->mCleanSignatures
= $wgCleanSignatures;
183 $this->mExternalLinkTarget
= $wgExternalLinkTarget;
184 $this->mMath
= $user->getOption( 'math' );
185 $this->mUserLang
= $wgLang->getCode();
186 $this->mThumbSize
= $user->getOption( 'thumbsize' );
188 $this->mIsPreview
= false;
189 $this->mIsSectionPreview
= false;
190 $this->mIsPrintable
= false;
192 wfProfileOut( __METHOD__
);