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 $mSkin; # Reference to the preferred skin
17 var $mDateFormat; # Date format index
18 var $mEditSection; # Create "edit section" links
19 var $mNumberHeadings; # Automatically number headings
20 var $mAllowSpecialInclusion; # Allow inclusion of special pages
21 var $mTidy; # Ask for tidy cleanup
22 var $mInterfaceMessage; # Which lang to call for PLURAL and GRAMMAR
23 var $mTargetLanguage; # Overrides above setting with arbitrary language
24 var $mMaxIncludeSize; # Maximum size of template expansions, in bytes
25 var $mMaxPPNodeCount; # Maximum number of nodes touched by PPFrame::expand()
26 var $mMaxPPExpandDepth; # Maximum recursion depth in PPFrame::expand()
27 var $mMaxTemplateDepth; # Maximum recursion depth for templates within templates
28 var $mRemoveComments; # Remove HTML comments. ONLY APPLIES TO PREPROCESS OPERATIONS
29 var $mTemplateCallback; # Callback for template fetching
30 var $mEnableLimitReport; # Enable limit report in an HTML comment on output
31 var $mTimestamp; # Timestamp used for {{CURRENTDAY}} etc.
33 var $mUser; # Stored user object, just used to initialise the skin
35 function getUseTeX() { return $this->mUseTeX
; }
36 function getUseDynamicDates() { return $this->mUseDynamicDates
; }
37 function getInterwikiMagic() { return $this->mInterwikiMagic
; }
38 function getAllowExternalImages() { return $this->mAllowExternalImages
; }
39 function getAllowExternalImagesFrom() { return $this->mAllowExternalImagesFrom
; }
40 function getEditSection() { return $this->mEditSection
; }
41 function getNumberHeadings() { return $this->mNumberHeadings
; }
42 function getAllowSpecialInclusion() { return $this->mAllowSpecialInclusion
; }
43 function getTidy() { return $this->mTidy
; }
44 function getInterfaceMessage() { return $this->mInterfaceMessage
; }
45 function getTargetLanguage() { return $this->mTargetLanguage
; }
46 function getMaxIncludeSize() { return $this->mMaxIncludeSize
; }
47 function getMaxPPNodeCount() { return $this->mMaxPPNodeCount
; }
48 function getMaxTemplateDepth() { return $this->mMaxTemplateDepth
; }
49 function getRemoveComments() { return $this->mRemoveComments
; }
50 function getTemplateCallback() { return $this->mTemplateCallback
; }
51 function getEnableLimitReport() { return $this->mEnableLimitReport
; }
54 if ( !isset( $this->mSkin
) ) {
55 $this->mSkin
= $this->mUser
->getSkin();
60 function getDateFormat() {
61 if ( !isset( $this->mDateFormat
) ) {
62 $this->mDateFormat
= $this->mUser
->getDatePreference();
64 return $this->mDateFormat
;
67 function getTimestamp() {
68 if ( !isset( $this->mTimestamp
) ) {
69 $this->mTimestamp
= wfTimestampNow();
71 return $this->mTimestamp
;
74 function setUseTeX( $x ) { return wfSetVar( $this->mUseTeX
, $x ); }
75 function setUseDynamicDates( $x ) { return wfSetVar( $this->mUseDynamicDates
, $x ); }
76 function setInterwikiMagic( $x ) { return wfSetVar( $this->mInterwikiMagic
, $x ); }
77 function setAllowExternalImages( $x ) { return wfSetVar( $this->mAllowExternalImages
, $x ); }
78 function setAllowExternalImagesFrom( $x ) { return wfSetVar( $this->mAllowExternalImagesFrom
, $x ); }
79 function setDateFormat( $x ) { return wfSetVar( $this->mDateFormat
, $x ); }
80 function setEditSection( $x ) { return wfSetVar( $this->mEditSection
, $x ); }
81 function setNumberHeadings( $x ) { return wfSetVar( $this->mNumberHeadings
, $x ); }
82 function setAllowSpecialInclusion( $x ) { return wfSetVar( $this->mAllowSpecialInclusion
, $x ); }
83 function setTidy( $x ) { return wfSetVar( $this->mTidy
, $x); }
84 function setSkin( $x ) { $this->mSkin
= $x; }
85 function setInterfaceMessage( $x ) { return wfSetVar( $this->mInterfaceMessage
, $x); }
86 function setTargetLanguage( $x ) { return wfSetVar( $this->mTargetLanguage
, $x); }
87 function setMaxIncludeSize( $x ) { return wfSetVar( $this->mMaxIncludeSize
, $x ); }
88 function setMaxPPNodeCount( $x ) { return wfSetVar( $this->mMaxPPNodeCount
, $x ); }
89 function setMaxTemplateDepth( $x ) { return wfSetVar( $this->mMaxTemplateDepth
, $x ); }
90 function setRemoveComments( $x ) { return wfSetVar( $this->mRemoveComments
, $x ); }
91 function setTemplateCallback( $x ) { return wfSetVar( $this->mTemplateCallback
, $x ); }
92 function enableLimitReport( $x = true ) { return wfSetVar( $this->mEnableLimitReport
, $x ); }
93 function setTimestamp( $x ) { return wfSetVar( $this->mTimestamp
, $x ); }
95 function __construct( $user = null ) {
96 $this->initialiseFromUser( $user );
103 static function newFromUser( $user ) {
104 return new ParserOptions( $user );
107 /** Get user options */
108 function initialiseFromUser( $userInput ) {
109 global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
110 global $wgAllowExternalImagesFrom, $wgAllowSpecialInclusion, $wgMaxArticleSize;
111 global $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth;
112 $fname = 'ParserOptions::initialiseFromUser';
113 wfProfileIn( $fname );
116 if ( isset( $wgUser ) ) {
125 $this->mUser
= $user;
127 $this->mUseTeX
= $wgUseTeX;
128 $this->mUseDynamicDates
= $wgUseDynamicDates;
129 $this->mInterwikiMagic
= $wgInterwikiMagic;
130 $this->mAllowExternalImages
= $wgAllowExternalImages;
131 $this->mAllowExternalImagesFrom
= $wgAllowExternalImagesFrom;
132 $this->mSkin
= null; # Deferred
133 $this->mDateFormat
= null; # Deferred
134 $this->mEditSection
= true;
135 $this->mNumberHeadings
= $user->getOption( 'numberheadings' );
136 $this->mAllowSpecialInclusion
= $wgAllowSpecialInclusion;
137 $this->mTidy
= false;
138 $this->mInterfaceMessage
= false;
139 $this->mTargetLanguage
= null; // default depends on InterfaceMessage setting
140 $this->mMaxIncludeSize
= $wgMaxArticleSize * 1024;
141 $this->mMaxPPNodeCount
= $wgMaxPPNodeCount;
142 $this->mMaxPPExpandDepth
= $wgMaxPPExpandDepth;
143 $this->mMaxTemplateDepth
= $wgMaxTemplateDepth;
144 $this->mRemoveComments
= true;
145 $this->mTemplateCallback
= array( 'Parser', 'statelessFetchTemplate' );
146 $this->mEnableLimitReport
= false;
147 wfProfileOut( $fname );