00001 <?php 00002 00008 class ParserOptions 00009 { 00010 # All variables are supposed to be private in theory, although in practise this is not the case. 00011 var $mUseTeX; # Use texvc to expand <math> tags 00012 var $mUseDynamicDates; # Use DateFormatter to format dates 00013 var $mInterwikiMagic; # Interlanguage links are removed and returned in an array 00014 var $mAllowExternalImages; # Allow external images inline 00015 var $mAllowExternalImagesFrom; # If not, any exception? 00016 var $mEnableImageWhitelist; # If not or it doesn't match, should we check an on-wiki whitelist? 00017 var $mSkin; # Reference to the preferred skin 00018 var $mDateFormat; # Date format index 00019 var $mEditSection; # Create "edit section" links 00020 var $mNumberHeadings; # Automatically number headings 00021 var $mAllowSpecialInclusion; # Allow inclusion of special pages 00022 var $mTidy; # Ask for tidy cleanup 00023 var $mInterfaceMessage; # Which lang to call for PLURAL and GRAMMAR 00024 var $mTargetLanguage; # Overrides above setting with arbitrary language 00025 var $mMaxIncludeSize; # Maximum size of template expansions, in bytes 00026 var $mMaxPPNodeCount; # Maximum number of nodes touched by PPFrame::expand() 00027 var $mMaxPPExpandDepth; # Maximum recursion depth in PPFrame::expand() 00028 var $mMaxTemplateDepth; # Maximum recursion depth for templates within templates 00029 var $mRemoveComments; # Remove HTML comments. ONLY APPLIES TO PREPROCESS OPERATIONS 00030 var $mTemplateCallback; # Callback for template fetching 00031 var $mEnableLimitReport; # Enable limit report in an HTML comment on output 00032 var $mTimestamp; # Timestamp used for {{CURRENTDAY}} etc. 00033 var $mExternalLinkTarget; # Target attribute for external links 00034 00035 var $mUser; # Stored user object, just used to initialise the skin 00036 var $mIsPreview; # Parsing the page for a "preview" operation 00037 var $mIsSectionPreview; # Parsing the page for a "preview" operation on a single section 00038 var $mIsPrintable; # Parsing the printable version of the page 00039 00040 function getUseTeX() { return $this->mUseTeX; } 00041 function getUseDynamicDates() { return $this->mUseDynamicDates; } 00042 function getInterwikiMagic() { return $this->mInterwikiMagic; } 00043 function getAllowExternalImages() { return $this->mAllowExternalImages; } 00044 function getAllowExternalImagesFrom() { return $this->mAllowExternalImagesFrom; } 00045 function getEnableImageWhitelist() { return $this->mEnableImageWhitelist; } 00046 function getEditSection() { return $this->mEditSection; } 00047 function getNumberHeadings() { return $this->mNumberHeadings; } 00048 function getAllowSpecialInclusion() { return $this->mAllowSpecialInclusion; } 00049 function getTidy() { return $this->mTidy; } 00050 function getInterfaceMessage() { return $this->mInterfaceMessage; } 00051 function getTargetLanguage() { return $this->mTargetLanguage; } 00052 function getMaxIncludeSize() { return $this->mMaxIncludeSize; } 00053 function getMaxPPNodeCount() { return $this->mMaxPPNodeCount; } 00054 function getMaxTemplateDepth() { return $this->mMaxTemplateDepth; } 00055 function getRemoveComments() { return $this->mRemoveComments; } 00056 function getTemplateCallback() { return $this->mTemplateCallback; } 00057 function getEnableLimitReport() { return $this->mEnableLimitReport; } 00058 function getCleanSignatures() { return $this->mCleanSignatures; } 00059 function getExternalLinkTarget() { return $this->mExternalLinkTarget; } 00060 function getIsPreview() { return $this->mIsPreview; } 00061 function getIsSectionPreview() { return $this->mIsSectionPreview; } 00062 function getIsPrintable() { return $this->mIsPrintable; } 00063 00064 function getSkin() { 00065 if ( !isset( $this->mSkin ) ) { 00066 $this->mSkin = $this->mUser->getSkin(); 00067 } 00068 return $this->mSkin; 00069 } 00070 00071 function getDateFormat() { 00072 if ( !isset( $this->mDateFormat ) ) { 00073 $this->mDateFormat = $this->mUser->getDatePreference(); 00074 } 00075 return $this->mDateFormat; 00076 } 00077 00078 function getTimestamp() { 00079 if ( !isset( $this->mTimestamp ) ) { 00080 $this->mTimestamp = wfTimestampNow(); 00081 } 00082 return $this->mTimestamp; 00083 } 00084 00085 function setUseTeX( $x ) { return wfSetVar( $this->mUseTeX, $x ); } 00086 function setUseDynamicDates( $x ) { return wfSetVar( $this->mUseDynamicDates, $x ); } 00087 function setInterwikiMagic( $x ) { return wfSetVar( $this->mInterwikiMagic, $x ); } 00088 function setAllowExternalImages( $x ) { return wfSetVar( $this->mAllowExternalImages, $x ); } 00089 function setAllowExternalImagesFrom( $x ) { return wfSetVar( $this->mAllowExternalImagesFrom, $x ); } 00090 function setEnableImageWhitelist( $x ) { return wfSetVar( $this->mEnableImageWhitelist, $x ); } 00091 function setDateFormat( $x ) { return wfSetVar( $this->mDateFormat, $x ); } 00092 function setEditSection( $x ) { return wfSetVar( $this->mEditSection, $x ); } 00093 function setNumberHeadings( $x ) { return wfSetVar( $this->mNumberHeadings, $x ); } 00094 function setAllowSpecialInclusion( $x ) { return wfSetVar( $this->mAllowSpecialInclusion, $x ); } 00095 function setTidy( $x ) { return wfSetVar( $this->mTidy, $x); } 00096 function setSkin( $x ) { $this->mSkin = $x; } 00097 function setInterfaceMessage( $x ) { return wfSetVar( $this->mInterfaceMessage, $x); } 00098 function setTargetLanguage( $x ) { return wfSetVar( $this->mTargetLanguage, $x); } 00099 function setMaxIncludeSize( $x ) { return wfSetVar( $this->mMaxIncludeSize, $x ); } 00100 function setMaxPPNodeCount( $x ) { return wfSetVar( $this->mMaxPPNodeCount, $x ); } 00101 function setMaxTemplateDepth( $x ) { return wfSetVar( $this->mMaxTemplateDepth, $x ); } 00102 function setRemoveComments( $x ) { return wfSetVar( $this->mRemoveComments, $x ); } 00103 function setTemplateCallback( $x ) { return wfSetVar( $this->mTemplateCallback, $x ); } 00104 function enableLimitReport( $x = true ) { return wfSetVar( $this->mEnableLimitReport, $x ); } 00105 function setTimestamp( $x ) { return wfSetVar( $this->mTimestamp, $x ); } 00106 function setCleanSignatures( $x ) { return wfSetVar( $this->mCleanSignatures, $x ); } 00107 function setExternalLinkTarget( $x ) { return wfSetVar( $this->mExternalLinkTarget, $x ); } 00108 function setIsPreview( $x ) { return wfSetVar( $this->mIsPreview, $x ); } 00109 function setIsSectionPreview( $x ) { return wfSetVar( $this->mIsSectionPreview, $x ); } 00110 function setIsPrintable( $x ) { return wfSetVar( $this->mIsPrintable, $x ); } 00111 00112 function __construct( $user = null ) { 00113 $this->initialiseFromUser( $user ); 00114 } 00115 00120 static function newFromUser( $user ) { 00121 return new ParserOptions( $user ); 00122 } 00123 00125 function initialiseFromUser( $userInput ) { 00126 global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages; 00127 global $wgAllowExternalImagesFrom, $wgEnableImageWhitelist, $wgAllowSpecialInclusion, $wgMaxArticleSize; 00128 global $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth, $wgCleanSignatures; 00129 global $wgExternalLinkTarget; 00130 $fname = 'ParserOptions::initialiseFromUser'; 00131 wfProfileIn( $fname ); 00132 if ( !$userInput ) { 00133 global $wgUser; 00134 if ( isset( $wgUser ) ) { 00135 $user = $wgUser; 00136 } else { 00137 $user = new User; 00138 } 00139 } else { 00140 $user =& $userInput; 00141 } 00142 00143 $this->mUser = $user; 00144 00145 $this->mUseTeX = $wgUseTeX; 00146 $this->mUseDynamicDates = $wgUseDynamicDates; 00147 $this->mInterwikiMagic = $wgInterwikiMagic; 00148 $this->mAllowExternalImages = $wgAllowExternalImages; 00149 $this->mAllowExternalImagesFrom = $wgAllowExternalImagesFrom; 00150 $this->mEnableImageWhitelist = $wgEnableImageWhitelist; 00151 $this->mSkin = null; # Deferred 00152 $this->mDateFormat = null; # Deferred 00153 $this->mEditSection = true; 00154 $this->mNumberHeadings = $user->getOption( 'numberheadings' ); 00155 $this->mAllowSpecialInclusion = $wgAllowSpecialInclusion; 00156 $this->mTidy = false; 00157 $this->mInterfaceMessage = false; 00158 $this->mTargetLanguage = null; // default depends on InterfaceMessage setting 00159 $this->mMaxIncludeSize = $wgMaxArticleSize * 1024; 00160 $this->mMaxPPNodeCount = $wgMaxPPNodeCount; 00161 $this->mMaxPPExpandDepth = $wgMaxPPExpandDepth; 00162 $this->mMaxTemplateDepth = $wgMaxTemplateDepth; 00163 $this->mRemoveComments = true; 00164 $this->mTemplateCallback = array( 'Parser', 'statelessFetchTemplate' ); 00165 $this->mEnableLimitReport = false; 00166 $this->mCleanSignatures = $wgCleanSignatures; 00167 $this->mExternalLinkTarget = $wgExternalLinkTarget; 00168 $this->mIsPreview = false; 00169 $this->mIsSectionPreview = false; 00170 wfProfileOut( $fname ); 00171 } 00172 }