ParserOptions.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. /**
  3. * Set options of the Parser
  4. * @todo document
  5. * @ingroup Parser
  6. */
  7. class ParserOptions
  8. {
  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 $mEnableImageWhitelist; # If not or it doesn't match, should we check an on-wiki whitelist?
  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.
  32. var $mExternalLinkTarget; # Target attribute for external links
  33. var $mUser; # Stored user object, just used to initialise the skin
  34. var $mIsPreview; # Parsing the page for a "preview" operation
  35. var $mIsSectionPreview; # Parsing the page for a "preview" operation on a single section
  36. var $mIsPrintable; # Parsing the printable version of the page
  37. function getUseTeX() { return $this->mUseTeX; }
  38. function getUseDynamicDates() { return $this->mUseDynamicDates; }
  39. function getInterwikiMagic() { return $this->mInterwikiMagic; }
  40. function getAllowExternalImages() { return $this->mAllowExternalImages; }
  41. function getAllowExternalImagesFrom() { return $this->mAllowExternalImagesFrom; }
  42. function getEnableImageWhitelist() { return $this->mEnableImageWhitelist; }
  43. function getEditSection() { return $this->mEditSection; }
  44. function getNumberHeadings() { return $this->mNumberHeadings; }
  45. function getAllowSpecialInclusion() { return $this->mAllowSpecialInclusion; }
  46. function getTidy() { return $this->mTidy; }
  47. function getInterfaceMessage() { return $this->mInterfaceMessage; }
  48. function getTargetLanguage() { return $this->mTargetLanguage; }
  49. function getMaxIncludeSize() { return $this->mMaxIncludeSize; }
  50. function getMaxPPNodeCount() { return $this->mMaxPPNodeCount; }
  51. function getMaxTemplateDepth() { return $this->mMaxTemplateDepth; }
  52. function getRemoveComments() { return $this->mRemoveComments; }
  53. function getTemplateCallback() { return $this->mTemplateCallback; }
  54. function getEnableLimitReport() { return $this->mEnableLimitReport; }
  55. function getCleanSignatures() { return $this->mCleanSignatures; }
  56. function getExternalLinkTarget() { return $this->mExternalLinkTarget; }
  57. function getIsPreview() { return $this->mIsPreview; }
  58. function getIsSectionPreview() { return $this->mIsSectionPreview; }
  59. function getIsPrintable() { return $this->mIsPrintable; }
  60. function getSkin() {
  61. if ( !isset( $this->mSkin ) ) {
  62. $this->mSkin = $this->mUser->getSkin();
  63. }
  64. return $this->mSkin;
  65. }
  66. function getDateFormat() {
  67. if ( !isset( $this->mDateFormat ) ) {
  68. $this->mDateFormat = $this->mUser->getDatePreference();
  69. }
  70. return $this->mDateFormat;
  71. }
  72. function getTimestamp() {
  73. if ( !isset( $this->mTimestamp ) ) {
  74. $this->mTimestamp = wfTimestampNow();
  75. }
  76. return $this->mTimestamp;
  77. }
  78. function setUseTeX( $x ) { return wfSetVar( $this->mUseTeX, $x ); }
  79. function setUseDynamicDates( $x ) { return wfSetVar( $this->mUseDynamicDates, $x ); }
  80. function setInterwikiMagic( $x ) { return wfSetVar( $this->mInterwikiMagic, $x ); }
  81. function setAllowExternalImages( $x ) { return wfSetVar( $this->mAllowExternalImages, $x ); }
  82. function setAllowExternalImagesFrom( $x ) { return wfSetVar( $this->mAllowExternalImagesFrom, $x ); }
  83. function setEnableImageWhitelist( $x ) { return wfSetVar( $this->mEnableImageWhitelist, $x ); }
  84. function setDateFormat( $x ) { return wfSetVar( $this->mDateFormat, $x ); }
  85. function setEditSection( $x ) { return wfSetVar( $this->mEditSection, $x ); }
  86. function setNumberHeadings( $x ) { return wfSetVar( $this->mNumberHeadings, $x ); }
  87. function setAllowSpecialInclusion( $x ) { return wfSetVar( $this->mAllowSpecialInclusion, $x ); }
  88. function setTidy( $x ) { return wfSetVar( $this->mTidy, $x); }
  89. function setSkin( $x ) { $this->mSkin = $x; }
  90. function setInterfaceMessage( $x ) { return wfSetVar( $this->mInterfaceMessage, $x); }
  91. function setTargetLanguage( $x ) { return wfSetVar( $this->mTargetLanguage, $x); }
  92. function setMaxIncludeSize( $x ) { return wfSetVar( $this->mMaxIncludeSize, $x ); }
  93. function setMaxPPNodeCount( $x ) { return wfSetVar( $this->mMaxPPNodeCount, $x ); }
  94. function setMaxTemplateDepth( $x ) { return wfSetVar( $this->mMaxTemplateDepth, $x ); }
  95. function setRemoveComments( $x ) { return wfSetVar( $this->mRemoveComments, $x ); }
  96. function setTemplateCallback( $x ) { return wfSetVar( $this->mTemplateCallback, $x ); }
  97. function enableLimitReport( $x = true ) { return wfSetVar( $this->mEnableLimitReport, $x ); }
  98. function setTimestamp( $x ) { return wfSetVar( $this->mTimestamp, $x ); }
  99. function setCleanSignatures( $x ) { return wfSetVar( $this->mCleanSignatures, $x ); }
  100. function setExternalLinkTarget( $x ) { return wfSetVar( $this->mExternalLinkTarget, $x ); }
  101. function setIsPreview( $x ) { return wfSetVar( $this->mIsPreview, $x ); }
  102. function setIsSectionPreview( $x ) { return wfSetVar( $this->mIsSectionPreview, $x ); }
  103. function setIsPrintable( $x ) { return wfSetVar( $this->mIsPrintable, $x ); }
  104. function __construct( $user = null ) {
  105. $this->initialiseFromUser( $user );
  106. }
  107. /**
  108. * Get parser options
  109. * @static
  110. */
  111. static function newFromUser( $user ) {
  112. return new ParserOptions( $user );
  113. }
  114. /** Get user options */
  115. function initialiseFromUser( $userInput ) {
  116. global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
  117. global $wgAllowExternalImagesFrom, $wgEnableImageWhitelist, $wgAllowSpecialInclusion, $wgMaxArticleSize;
  118. global $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth, $wgCleanSignatures;
  119. global $wgExternalLinkTarget;
  120. $fname = 'ParserOptions::initialiseFromUser';
  121. wfProfileIn( $fname );
  122. if ( !$userInput ) {
  123. global $wgUser;
  124. if ( isset( $wgUser ) ) {
  125. $user = $wgUser;
  126. } else {
  127. $user = new User;
  128. }
  129. } else {
  130. $user =& $userInput;
  131. }
  132. $this->mUser = $user;
  133. $this->mUseTeX = $wgUseTeX;
  134. $this->mUseDynamicDates = $wgUseDynamicDates;
  135. $this->mInterwikiMagic = $wgInterwikiMagic;
  136. $this->mAllowExternalImages = $wgAllowExternalImages;
  137. $this->mAllowExternalImagesFrom = $wgAllowExternalImagesFrom;
  138. $this->mEnableImageWhitelist = $wgEnableImageWhitelist;
  139. $this->mSkin = null; # Deferred
  140. $this->mDateFormat = null; # Deferred
  141. $this->mEditSection = true;
  142. $this->mNumberHeadings = $user->getOption( 'numberheadings' );
  143. $this->mAllowSpecialInclusion = $wgAllowSpecialInclusion;
  144. $this->mTidy = false;
  145. $this->mInterfaceMessage = false;
  146. $this->mTargetLanguage = null; // default depends on InterfaceMessage setting
  147. $this->mMaxIncludeSize = $wgMaxArticleSize * 1024;
  148. $this->mMaxPPNodeCount = $wgMaxPPNodeCount;
  149. $this->mMaxPPExpandDepth = $wgMaxPPExpandDepth;
  150. $this->mMaxTemplateDepth = $wgMaxTemplateDepth;
  151. $this->mRemoveComments = true;
  152. $this->mTemplateCallback = array( 'Parser', 'statelessFetchTemplate' );
  153. $this->mEnableLimitReport = false;
  154. $this->mCleanSignatures = $wgCleanSignatures;
  155. $this->mExternalLinkTarget = $wgExternalLinkTarget;
  156. $this->mIsPreview = false;
  157. $this->mIsSectionPreview = false;
  158. wfProfileOut( $fname );
  159. }
  160. }