4 * Set options of the Parser
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.
34 var $mUser; # Stored user object, just used to initialise the skin
36 function getUseTeX() { return $this->mUseTeX
; }
37 function getUseDynamicDates() { return $this->mUseDynamicDates
; }
38 function getInterwikiMagic() { return $this->mInterwikiMagic
; }
39 function getAllowExternalImages() { return $this->mAllowExternalImages
; }
40 function getAllowExternalImagesFrom() { return $this->mAllowExternalImagesFrom
; }
41 function getEnableImageWhitelist() { return $this->mEnableImageWhitelist
; }
42 function getEditSection() { return $this->mEditSection
; }
43 function getNumberHeadings() { return $this->mNumberHeadings
; }
44 function getAllowSpecialInclusion() { return $this->mAllowSpecialInclusion
; }
45 function getTidy() { return $this->mTidy
; }
46 function getInterfaceMessage() { return $this->mInterfaceMessage
; }
47 function getTargetLanguage() { return $this->mTargetLanguage
; }
48 function getMaxIncludeSize() { return $this->mMaxIncludeSize
; }
49 function getMaxPPNodeCount() { return $this->mMaxPPNodeCount
; }
50 function getMaxTemplateDepth() { return $this->mMaxTemplateDepth
; }
51 function getRemoveComments() { return $this->mRemoveComments
; }
52 function getTemplateCallback() { return $this->mTemplateCallback
; }
53 function getEnableLimitReport() { return $this->mEnableLimitReport
; }
54 function getCleanSignatures() { return $this->mCleanSignatures
; }
57 if ( !isset( $this->mSkin
) ) {
58 $this->mSkin
= $this->mUser
->getSkin();
63 function getDateFormat() {
64 if ( !isset( $this->mDateFormat
) ) {
65 $this->mDateFormat
= $this->mUser
->getDatePreference();
67 return $this->mDateFormat
;
70 function getTimestamp() {
71 if ( !isset( $this->mTimestamp
) ) {
72 $this->mTimestamp
= wfTimestampNow();
74 return $this->mTimestamp
;
77 function setUseTeX( $x ) { return wfSetVar( $this->mUseTeX
, $x ); }
78 function setUseDynamicDates( $x ) { return wfSetVar( $this->mUseDynamicDates
, $x ); }
79 function setInterwikiMagic( $x ) { return wfSetVar( $this->mInterwikiMagic
, $x ); }
80 function setAllowExternalImages( $x ) { return wfSetVar( $this->mAllowExternalImages
, $x ); }
81 function setAllowExternalImagesFrom( $x ) { return wfSetVar( $this->mAllowExternalImagesFrom
, $x ); }
82 function setEnableImageWhitelist( $x ) { return wfSetVar( $this->mEnableImageWhitelist
, $x ); }
83 function setDateFormat( $x ) { return wfSetVar( $this->mDateFormat
, $x ); }
84 function setEditSection( $x ) { return wfSetVar( $this->mEditSection
, $x ); }
85 function setNumberHeadings( $x ) { return wfSetVar( $this->mNumberHeadings
, $x ); }
86 function setAllowSpecialInclusion( $x ) { return wfSetVar( $this->mAllowSpecialInclusion
, $x ); }
87 function setTidy( $x ) { return wfSetVar( $this->mTidy
, $x); }
88 function setSkin( $x ) { $this->mSkin
= $x; }
89 function setInterfaceMessage( $x ) { return wfSetVar( $this->mInterfaceMessage
, $x); }
90 function setTargetLanguage( $x ) { return wfSetVar( $this->mTargetLanguage
, $x); }
91 function setMaxIncludeSize( $x ) { return wfSetVar( $this->mMaxIncludeSize
, $x ); }
92 function setMaxPPNodeCount( $x ) { return wfSetVar( $this->mMaxPPNodeCount
, $x ); }
93 function setMaxTemplateDepth( $x ) { return wfSetVar( $this->mMaxTemplateDepth
, $x ); }
94 function setRemoveComments( $x ) { return wfSetVar( $this->mRemoveComments
, $x ); }
95 function setTemplateCallback( $x ) { return wfSetVar( $this->mTemplateCallback
, $x ); }
96 function enableLimitReport( $x = true ) { return wfSetVar( $this->mEnableLimitReport
, $x ); }
97 function setTimestamp( $x ) { return wfSetVar( $this->mTimestamp
, $x ); }
98 function setCleanSignatures( $x ) { return wfSetVar( $this->mCleanSignatures
, $x ); }
100 function __construct( $user = null ) {
101 $this->initialiseFromUser( $user );
108 static function newFromUser( $user ) {
109 return new ParserOptions( $user );
112 /** Get user options */
113 function initialiseFromUser( $userInput ) {
114 global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
115 global $wgAllowExternalImagesFrom, $wgEnableImageWhitelist, $wgAllowSpecialInclusion, $wgMaxArticleSize;
116 global $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth, $wgCleanSignatures;
117 $fname = 'ParserOptions::initialiseFromUser';
118 wfProfileIn( $fname );
121 if ( isset( $wgUser ) ) {
130 $this->mUser
= $user;
132 $this->mUseTeX
= $wgUseTeX;
133 $this->mUseDynamicDates
= $wgUseDynamicDates;
134 $this->mInterwikiMagic
= $wgInterwikiMagic;
135 $this->mAllowExternalImages
= $wgAllowExternalImages;
136 $this->mAllowExternalImagesFrom
= $wgAllowExternalImagesFrom;
137 $this->mEnableImageWhitelist
= $wgEnableImageWhitelist;
138 $this->mSkin
= null; # Deferred
139 $this->mDateFormat
= null; # Deferred
140 $this->mEditSection
= true;
141 $this->mNumberHeadings
= $user->getOption( 'numberheadings' );
142 $this->mAllowSpecialInclusion
= $wgAllowSpecialInclusion;
143 $this->mTidy
= false;
144 $this->mInterfaceMessage
= false;
145 $this->mTargetLanguage
= null; // default depends on InterfaceMessage setting
146 $this->mMaxIncludeSize
= $wgMaxArticleSize * 1024;
147 $this->mMaxPPNodeCount
= $wgMaxPPNodeCount;
148 $this->mMaxPPExpandDepth
= $wgMaxPPExpandDepth;
149 $this->mMaxTemplateDepth
= $wgMaxTemplateDepth;
150 $this->mRemoveComments
= true;
151 $this->mTemplateCallback
= array( 'Parser', 'statelessFetchTemplate' );
152 $this->mEnableLimitReport
= false;
153 $this->mCleanSignatures
= $wgCleanSignatures;
154 wfProfileOut( $fname );