]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/ParserOptions.php
MediaWiki 1.11.0-scripts
[autoinstallsdev/mediawiki.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 $mMaxIncludeSize;            # Maximum size of template expansions, in bytes
24         var $mRemoveComments;            # Remove HTML comments. ONLY APPLIES TO PREPROCESS OPERATIONS
25
26         var $mUser;                      # Stored user object, just used to initialise the skin
27
28         function getUseTeX()                        { return $this->mUseTeX; }
29         function getUseDynamicDates()               { return $this->mUseDynamicDates; }
30         function getInterwikiMagic()                { return $this->mInterwikiMagic; }
31         function getAllowExternalImages()           { return $this->mAllowExternalImages; }
32         function getAllowExternalImagesFrom()       { return $this->mAllowExternalImagesFrom; }
33         function getEditSection()                   { return $this->mEditSection; }
34         function getNumberHeadings()                { return $this->mNumberHeadings; }
35         function getAllowSpecialInclusion()         { return $this->mAllowSpecialInclusion; }
36         function getTidy()                          { return $this->mTidy; }
37         function getInterfaceMessage()              { return $this->mInterfaceMessage; }
38         function getMaxIncludeSize()                { return $this->mMaxIncludeSize; }
39         function getRemoveComments()                { return $this->mRemoveComments; }
40
41         function getSkin() {
42                 if ( !isset( $this->mSkin ) ) {
43                         $this->mSkin = $this->mUser->getSkin();
44                 }
45                 return $this->mSkin;
46         }
47
48         function getDateFormat() {
49                 if ( !isset( $this->mDateFormat ) ) {
50                         $this->mDateFormat = $this->mUser->getDatePreference();
51                 }
52                 return $this->mDateFormat;
53         }
54
55         function setUseTeX( $x )                    { return wfSetVar( $this->mUseTeX, $x ); }
56         function setUseDynamicDates( $x )           { return wfSetVar( $this->mUseDynamicDates, $x ); }
57         function setInterwikiMagic( $x )            { return wfSetVar( $this->mInterwikiMagic, $x ); }
58         function setAllowExternalImages( $x )       { return wfSetVar( $this->mAllowExternalImages, $x ); }
59         function setAllowExternalImagesFrom( $x )   { return wfSetVar( $this->mAllowExternalImagesFrom, $x ); }
60         function setDateFormat( $x )                { return wfSetVar( $this->mDateFormat, $x ); }
61         function setEditSection( $x )               { return wfSetVar( $this->mEditSection, $x ); }
62         function setNumberHeadings( $x )            { return wfSetVar( $this->mNumberHeadings, $x ); }
63         function setAllowSpecialInclusion( $x )     { return wfSetVar( $this->mAllowSpecialInclusion, $x ); }
64         function setTidy( $x )                      { return wfSetVar( $this->mTidy, $x); }
65         function setSkin( $x )                      { $this->mSkin = $x; }
66         function setInterfaceMessage( $x )          { return wfSetVar( $this->mInterfaceMessage, $x); }
67         function setMaxIncludeSize( $x )            { return wfSetVar( $this->mMaxIncludeSize, $x ); }
68         function setRemoveComments( $x )            { return wfSetVar( $this->mRemoveComments, $x ); }
69
70         function __construct( $user = null ) {
71                 $this->initialiseFromUser( $user );
72         }
73
74         /**
75          * Get parser options
76          * @static
77          */
78         static function newFromUser( $user ) {
79                 return new ParserOptions( $user );
80         }
81
82         /** Get user options */
83         function initialiseFromUser( $userInput ) {
84                 global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
85                 global $wgAllowExternalImagesFrom, $wgAllowSpecialInclusion, $wgMaxArticleSize;
86                 $fname = 'ParserOptions::initialiseFromUser';
87                 wfProfileIn( $fname );
88                 if ( !$userInput ) {
89                         global $wgUser;
90                         if ( isset( $wgUser ) ) {
91                                 $user = $wgUser;
92                         } else {
93                                 $user = new User;
94                         }
95                 } else {
96                         $user =& $userInput;
97                 }
98
99                 $this->mUser = $user;
100
101                 $this->mUseTeX = $wgUseTeX;
102                 $this->mUseDynamicDates = $wgUseDynamicDates;
103                 $this->mInterwikiMagic = $wgInterwikiMagic;
104                 $this->mAllowExternalImages = $wgAllowExternalImages;
105                 $this->mAllowExternalImagesFrom = $wgAllowExternalImagesFrom;
106                 $this->mSkin = null; # Deferred
107                 $this->mDateFormat = null; # Deferred
108                 $this->mEditSection = true;
109                 $this->mNumberHeadings = $user->getOption( 'numberheadings' );
110                 $this->mAllowSpecialInclusion = $wgAllowSpecialInclusion;
111                 $this->mTidy = false;
112                 $this->mInterfaceMessage = false;
113                 $this->mMaxIncludeSize = $wgMaxArticleSize * 1024;
114                 $this->mRemoveComments = true;
115                 wfProfileOut( $fname );
116         }
117 }
118
119