4fd7ca289b855995dabcc1a54a92b176d536936f
[lhc/web/wiklou.git] / includes / ParserOptions.php
1 <?php
2
3 /**
4 * Set options of the Parser
5 * @todo document
6 * @ingroup Parser
7 */
8 class ParserOptions {
9 # All variables are supposed to be private in theory, although in practise this is not the case.
10 var $mUseTeX; //!< Use texvc to expand <math> tags
11 var $mUseDynamicDates; //!< Use DateFormatter to format dates
12 var $mInterwikiMagic; //!< Interlanguage links are removed and returned in an array
13 var $mAllowExternalImages; //!< Allow external images inline
14 var $mAllowExternalImagesFrom; //!< If not, any exception?
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
32 var $mUser; //!< Stored user object, just used to initialise the skin
33
34 function getUseTeX() { return $this->mUseTeX; }
35 function getUseDynamicDates() { return $this->mUseDynamicDates; }
36 function getInterwikiMagic() { return $this->mInterwikiMagic; }
37 function getAllowExternalImages() { return $this->mAllowExternalImages; }
38 function getAllowExternalImagesFrom() { return $this->mAllowExternalImagesFrom; }
39 function getEditSection() { return $this->mEditSection; }
40 function getNumberHeadings() { return $this->mNumberHeadings; }
41 function getAllowSpecialInclusion() { return $this->mAllowSpecialInclusion; }
42 function getTidy() { return $this->mTidy; }
43 function getInterfaceMessage() { return $this->mInterfaceMessage; }
44 function getTargetLanguage() { return $this->mTargetLanguage; }
45 function getMaxIncludeSize() { return $this->mMaxIncludeSize; }
46 function getMaxPPNodeCount() { return $this->mMaxPPNodeCount; }
47 function getMaxTemplateDepth() { return $this->mMaxTemplateDepth; }
48 function getRemoveComments() { return $this->mRemoveComments; }
49 function getTemplateCallback() { return $this->mTemplateCallback; }
50 function getEnableLimitReport() { return $this->mEnableLimitReport; }
51
52 function getSkin() {
53 if ( !isset( $this->mSkin ) ) {
54 $this->mSkin = $this->mUser->getSkin();
55 }
56 return $this->mSkin;
57 }
58
59 function getDateFormat() {
60 if ( !isset( $this->mDateFormat ) ) {
61 $this->mDateFormat = $this->mUser->getDatePreference();
62 }
63 return $this->mDateFormat;
64 }
65
66 function getTimestamp() {
67 if ( !isset( $this->mTimestamp ) ) {
68 $this->mTimestamp = wfTimestampNow();
69 }
70 return $this->mTimestamp;
71 }
72
73 function setUseTeX( $x ) { return wfSetVar( $this->mUseTeX, $x ); }
74 function setUseDynamicDates( $x ) { return wfSetVar( $this->mUseDynamicDates, $x ); }
75 function setInterwikiMagic( $x ) { return wfSetVar( $this->mInterwikiMagic, $x ); }
76 function setAllowExternalImages( $x ) { return wfSetVar( $this->mAllowExternalImages, $x ); }
77 function setAllowExternalImagesFrom( $x ) { return wfSetVar( $this->mAllowExternalImagesFrom, $x ); }
78 function setDateFormat( $x ) { return wfSetVar( $this->mDateFormat, $x ); }
79 function setEditSection( $x ) { return wfSetVar( $this->mEditSection, $x ); }
80 function setNumberHeadings( $x ) { return wfSetVar( $this->mNumberHeadings, $x ); }
81 function setAllowSpecialInclusion( $x ) { return wfSetVar( $this->mAllowSpecialInclusion, $x ); }
82 function setTidy( $x ) { return wfSetVar( $this->mTidy, $x); }
83 function setSkin( $x ) { $this->mSkin = $x; }
84 function setInterfaceMessage( $x ) { return wfSetVar( $this->mInterfaceMessage, $x); }
85 function setTargetLanguage( $x ) { return wfSetVar( $this->mTargetLanguage, $x); }
86 function setMaxIncludeSize( $x ) { return wfSetVar( $this->mMaxIncludeSize, $x ); }
87 function setMaxPPNodeCount( $x ) { return wfSetVar( $this->mMaxPPNodeCount, $x ); }
88 function setMaxTemplateDepth( $x ) { return wfSetVar( $this->mMaxTemplateDepth, $x ); }
89 function setRemoveComments( $x ) { return wfSetVar( $this->mRemoveComments, $x ); }
90 function setTemplateCallback( $x ) { return wfSetVar( $this->mTemplateCallback, $x ); }
91 function enableLimitReport( $x = true ) { return wfSetVar( $this->mEnableLimitReport, $x ); }
92 function setTimestamp( $x ) { return wfSetVar( $this->mTimestamp, $x ); }
93
94 function __construct( $user = null ) {
95 $this->initialiseFromUser( $user );
96 }
97
98 /**
99 * Get parser options
100 * @param $user User
101 */
102 static function newFromUser( $user ) {
103 return new ParserOptions( $user );
104 }
105
106 /** Get user options */
107 function initialiseFromUser( $userInput ) {
108 global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
109 global $wgAllowExternalImagesFrom, $wgAllowSpecialInclusion, $wgMaxArticleSize;
110 global $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth;
111
112 wfProfileIn( __METHOD__ );
113
114 if ( !$userInput ) {
115 global $wgUser;
116 if ( isset( $wgUser ) ) {
117 $user = $wgUser;
118 } else {
119 $user = new User;
120 }
121 } else {
122 $user =& $userInput;
123 }
124
125 $this->mUser = $user;
126
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
148 wfProfileOut( __METHOD__ );
149 }
150 }