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
33 var $mUser; # Stored user object, just used to initialise the skin
34 var $mIsPreview; # Parsing the page for a "preview" operation
35 var $mIsSectionPreview; # Parsing the page for a "preview" operation on a single section
36 var $mIsPrintable; # Parsing the printable version of the page
38 function getUseDynamicDates() { return $this->mUseDynamicDates
; }
39 function getInterwikiMagic() { return $this->mInterwikiMagic
; }
40 function getAllowExternalImages() { return $this->mAllowExternalImages
; }
41 function getAllowExternalImagesFrom() { return $this->mAllowExternalImagesFrom
; }
42 function getEnableImageWhitelist() { return $this->mEnableImageWhitelist
; }
43 function getEditSection() { return $this->mEditSection
; }
44 function getNumberHeadings() { return $this->mNumberHeadings
; }
45 function getAllowSpecialInclusion() { return $this->mAllowSpecialInclusion
; }
46 function getTidy() { return $this->mTidy
; }
47 function getInterfaceMessage() { return $this->mInterfaceMessage
; }
48 function getTargetLanguage() { return $this->mTargetLanguage
; }
49 function getMaxIncludeSize() { return $this->mMaxIncludeSize
; }
50 function getMaxPPNodeCount() { return $this->mMaxPPNodeCount
; }
51 function getMaxTemplateDepth() { return $this->mMaxTemplateDepth
; }
52 function getRemoveComments() { return $this->mRemoveComments
; }
53 function getTemplateCallback() { return $this->mTemplateCallback
; }
54 function getEnableLimitReport() { return $this->mEnableLimitReport
; }
55 function getCleanSignatures() { return $this->mCleanSignatures
; }
56 function getExternalLinkTarget() { return $this->mExternalLinkTarget
; }
57 function getIsPreview() { return $this->mIsPreview
; }
58 function getIsSectionPreview() { return $this->mIsSectionPreview
; }
59 function getIsPrintable() { return $this->mIsPrintable
; }
62 if ( !isset( $this->mSkin
) ) {
63 $this->mSkin
= $this->mUser
->getSkin();
68 function getDateFormat() {
69 if ( !isset( $this->mDateFormat
) ) {
70 $this->mDateFormat
= $this->mUser
->getDatePreference();
72 return $this->mDateFormat
;
75 function getTimestamp() {
76 if ( !isset( $this->mTimestamp
) ) {
77 $this->mTimestamp
= wfTimestampNow();
79 return $this->mTimestamp
;
82 function setUseDynamicDates( $x ) { return wfSetVar( $this->mUseDynamicDates
, $x ); }
83 function setInterwikiMagic( $x ) { return wfSetVar( $this->mInterwikiMagic
, $x ); }
84 function setAllowExternalImages( $x ) { return wfSetVar( $this->mAllowExternalImages
, $x ); }
85 function setAllowExternalImagesFrom( $x ) { return wfSetVar( $this->mAllowExternalImagesFrom
, $x ); }
86 function setEnableImageWhitelist( $x ) { return wfSetVar( $this->mEnableImageWhitelist
, $x ); }
87 function setDateFormat( $x ) { return wfSetVar( $this->mDateFormat
, $x ); }
88 function setEditSection( $x ) { return wfSetVar( $this->mEditSection
, $x ); }
89 function setNumberHeadings( $x ) { return wfSetVar( $this->mNumberHeadings
, $x ); }
90 function setAllowSpecialInclusion( $x ) { return wfSetVar( $this->mAllowSpecialInclusion
, $x ); }
91 function setTidy( $x ) { return wfSetVar( $this->mTidy
, $x); }
92 function setSkin( $x ) { $this->mSkin
= $x; }
93 function setInterfaceMessage( $x ) { return wfSetVar( $this->mInterfaceMessage
, $x); }
94 function setTargetLanguage( $x ) { return wfSetVar( $this->mTargetLanguage
, $x); }
95 function setMaxIncludeSize( $x ) { return wfSetVar( $this->mMaxIncludeSize
, $x ); }
96 function setMaxPPNodeCount( $x ) { return wfSetVar( $this->mMaxPPNodeCount
, $x ); }
97 function setMaxTemplateDepth( $x ) { return wfSetVar( $this->mMaxTemplateDepth
, $x ); }
98 function setRemoveComments( $x ) { return wfSetVar( $this->mRemoveComments
, $x ); }
99 function setTemplateCallback( $x ) { return wfSetVar( $this->mTemplateCallback
, $x ); }
100 function enableLimitReport( $x = true ) { return wfSetVar( $this->mEnableLimitReport
, $x ); }
101 function setTimestamp( $x ) { return wfSetVar( $this->mTimestamp
, $x ); }
102 function setCleanSignatures( $x ) { return wfSetVar( $this->mCleanSignatures
, $x ); }
103 function setExternalLinkTarget( $x ) { return wfSetVar( $this->mExternalLinkTarget
, $x ); }
104 function setIsPreview( $x ) { return wfSetVar( $this->mIsPreview
, $x ); }
105 function setIsSectionPreview( $x ) { return wfSetVar( $this->mIsSectionPreview
, $x ); }
106 function setIsPrintable( $x ) { return wfSetVar( $this->mIsPrintable
, $x ); }
108 function __construct( $user = null ) {
109 $this->initialiseFromUser( $user );
116 static function newFromUser( $user ) {
117 return new ParserOptions( $user );
120 /** Get user options */
121 function initialiseFromUser( $userInput ) {
122 global $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
123 global $wgAllowExternalImagesFrom, $wgEnableImageWhitelist, $wgAllowSpecialInclusion, $wgMaxArticleSize;
124 global $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth, $wgCleanSignatures;
125 global $wgExternalLinkTarget;
127 wfProfileIn( __METHOD__
);
131 if ( isset( $wgUser ) ) {
140 $this->mUser
= $user;
142 $this->mUseDynamicDates
= $wgUseDynamicDates;
143 $this->mInterwikiMagic
= $wgInterwikiMagic;
144 $this->mAllowExternalImages
= $wgAllowExternalImages;
145 $this->mAllowExternalImagesFrom
= $wgAllowExternalImagesFrom;
146 $this->mEnableImageWhitelist
= $wgEnableImageWhitelist;
147 $this->mSkin
= null; # Deferred
148 $this->mDateFormat
= null; # Deferred
149 $this->mEditSection
= true;
150 $this->mNumberHeadings
= $user->getOption( 'numberheadings' );
151 $this->mAllowSpecialInclusion
= $wgAllowSpecialInclusion;
152 $this->mTidy
= false;
153 $this->mInterfaceMessage
= false;
154 $this->mTargetLanguage
= null; // default depends on InterfaceMessage setting
155 $this->mMaxIncludeSize
= $wgMaxArticleSize * 1024;
156 $this->mMaxPPNodeCount
= $wgMaxPPNodeCount;
157 $this->mMaxPPExpandDepth
= $wgMaxPPExpandDepth;
158 $this->mMaxTemplateDepth
= $wgMaxTemplateDepth;
159 $this->mRemoveComments
= true;
160 $this->mTemplateCallback
= array( 'Parser', 'statelessFetchTemplate' );
161 $this->mEnableLimitReport
= false;
162 $this->mCleanSignatures
= $wgCleanSignatures;
163 $this->mExternalLinkTarget
= $wgExternalLinkTarget;
164 $this->mIsPreview
= false;
165 $this->mIsSectionPreview
= false;
167 wfProfileOut( __METHOD__
);