* (bug 1459) Search for duplicate files by hash: Special:FileDuplicateSearch
[lhc/web/wiklou.git] / includes / ParserOptions.php
1 <?php
2
3 /**
4 * Set options of the Parser
5 * @todo document
6 * @addtogroup Parser
7 */
8 class ParserOptions
9 {
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 $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 * @static
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;
111 $fname = 'ParserOptions::initialiseFromUser';
112 wfProfileIn( $fname );
113 if ( !$userInput ) {
114 global $wgUser;
115 if ( isset( $wgUser ) ) {
116 $user = $wgUser;
117 } else {
118 $user = new User;
119 }
120 } else {
121 $user =& $userInput;
122 }
123
124 $this->mUser = $user;
125
126 $this->mUseTeX = $wgUseTeX;
127 $this->mUseDynamicDates = $wgUseDynamicDates;
128 $this->mInterwikiMagic = $wgInterwikiMagic;
129 $this->mAllowExternalImages = $wgAllowExternalImages;
130 $this->mAllowExternalImagesFrom = $wgAllowExternalImagesFrom;
131 $this->mSkin = null; # Deferred
132 $this->mDateFormat = null; # Deferred
133 $this->mEditSection = true;
134 $this->mNumberHeadings = $user->getOption( 'numberheadings' );
135 $this->mAllowSpecialInclusion = $wgAllowSpecialInclusion;
136 $this->mTidy = false;
137 $this->mInterfaceMessage = false;
138 $this->mTargetLanguage = null; // default depends on InterfaceMessage setting
139 $this->mMaxIncludeSize = $wgMaxArticleSize * 1024;
140 $this->mMaxPPNodeCount = $wgMaxPPNodeCount;
141 $this->mMaxTemplateDepth = $wgMaxTemplateDepth;
142 $this->mRemoveComments = true;
143 $this->mTemplateCallback = array( 'Parser', 'statelessFetchTemplate' );
144 $this->mEnableLimitReport = false;
145 wfProfileOut( $fname );
146 }
147 }
148
149