From c1f9b1f7b1b77776192048005dcc66dcf3df2bfb Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 27 Dec 2014 15:41:37 +0100 Subject: Update to MediaWiki 1.24.1 --- includes/parser/ParserOptions.php | 517 ++++++++++++++++++++++++++------------ 1 file changed, 356 insertions(+), 161 deletions(-) (limited to 'includes/parser/ParserOptions.php') diff --git a/includes/parser/ParserOptions.php b/includes/parser/ParserOptions.php index e12f32d8..7e4059b8 100644 --- a/includes/parser/ParserOptions.php +++ b/includes/parser/ParserOptions.php @@ -22,9 +22,10 @@ */ /** - * \brief Set options of the Parser + * @brief Set options of the Parser * - * All member variables are supposed to be private in theory, although in practise this is not the case. + * All member variables are supposed to be private in theory, although in + * practise this is not the case. * * @ingroup Parser */ @@ -33,108 +34,108 @@ class ParserOptions { /** * Interlanguage links are removed and returned in an array */ - var $mInterwikiMagic; + public $mInterwikiMagic; /** * Allow external images inline? */ - var $mAllowExternalImages; + public $mAllowExternalImages; /** * If not, any exception? */ - var $mAllowExternalImagesFrom; + public $mAllowExternalImagesFrom; /** * If not or it doesn't match, should we check an on-wiki whitelist? */ - var $mEnableImageWhitelist; + public $mEnableImageWhitelist; /** * Date format index */ - var $mDateFormat = null; + public $mDateFormat = null; /** * Create "edit section" links? */ - var $mEditSection = true; + public $mEditSection = true; /** * Allow inclusion of special pages? */ - var $mAllowSpecialInclusion; + public $mAllowSpecialInclusion; /** * Use tidy to cleanup output HTML? */ - var $mTidy = false; + public $mTidy = false; /** * Which lang to call for PLURAL and GRAMMAR */ - var $mInterfaceMessage = false; + public $mInterfaceMessage = false; /** * Overrides $mInterfaceMessage with arbitrary language */ - var $mTargetLanguage = null; + public $mTargetLanguage = null; /** * Maximum size of template expansions, in bytes */ - var $mMaxIncludeSize; + public $mMaxIncludeSize; /** * Maximum number of nodes touched by PPFrame::expand() */ - var $mMaxPPNodeCount; + public $mMaxPPNodeCount; /** * Maximum number of nodes generated by Preprocessor::preprocessToObj() */ - var $mMaxGeneratedPPNodeCount; + public $mMaxGeneratedPPNodeCount; /** * Maximum recursion depth in PPFrame::expand() */ - var $mMaxPPExpandDepth; + public $mMaxPPExpandDepth; /** * Maximum recursion depth for templates within templates */ - var $mMaxTemplateDepth; + public $mMaxTemplateDepth; /** * Maximum number of calls per parse to expensive parser functions */ - var $mExpensiveParserFunctionLimit; + public $mExpensiveParserFunctionLimit; /** * Remove HTML comments. ONLY APPLIES TO PREPROCESS OPERATIONS */ - var $mRemoveComments = true; + public $mRemoveComments = true; /** * Callback for template fetching. Used as first argument to call_user_func(). */ - var $mTemplateCallback = + public $mTemplateCallback = array( 'Parser', 'statelessFetchTemplate' ); /** * Enable limit report in an HTML comment on output */ - var $mEnableLimitReport = false; + public $mEnableLimitReport = false; /** * Timestamp used for {{CURRENTDAY}} etc. */ - var $mTimestamp; + public $mTimestamp; /** * Target attribute for external links */ - var $mExternalLinkTarget; + public $mExternalLinkTarget; /** * Clean up signature texts? @@ -142,37 +143,32 @@ class ParserOptions { * 1) Strip ~~~, ~~~~ and ~~~~~ out of signatures * 2) Substitute all transclusions */ - var $mCleanSignatures; + public $mCleanSignatures; /** * Transform wiki markup when saving the page? */ - var $mPreSaveTransform = true; + public $mPreSaveTransform = true; /** * Whether content conversion should be disabled */ - var $mDisableContentConversion; + public $mDisableContentConversion; /** * Whether title conversion should be disabled */ - var $mDisableTitleConversion; + public $mDisableTitleConversion; /** * Automatically number headings? */ - var $mNumberHeadings; - - /** - * User math preference (as integer). Not used (1.19) - */ - var $mMath; + public $mNumberHeadings; /** * Thumb size preferred by the user. */ - var $mThumbSize; + public $mThumbSize; /** * Maximum article size of an article to be marked as "stub" @@ -182,90 +178,176 @@ class ParserOptions { /** * Language object of the User language. */ - var $mUserLang; + public $mUserLang; /** * @var User * Stored user object */ - var $mUser; + public $mUser; /** * Parsing the page for a "preview" operation? */ - var $mIsPreview = false; + public $mIsPreview = false; /** * Parsing the page for a "preview" operation on a single section? */ - var $mIsSectionPreview = false; + public $mIsSectionPreview = false; /** * Parsing the printable version of the page? */ - var $mIsPrintable = false; + public $mIsPrintable = false; /** * Extra key that should be present in the caching key. */ - var $mExtraKey = ''; + public $mExtraKey = ''; /** * Function to be called when an option is accessed. */ protected $onAccessCallback = null; - function getInterwikiMagic() { return $this->mInterwikiMagic; } - function getAllowExternalImages() { return $this->mAllowExternalImages; } - function getAllowExternalImagesFrom() { return $this->mAllowExternalImagesFrom; } - function getEnableImageWhitelist() { return $this->mEnableImageWhitelist; } - function getEditSection() { return $this->mEditSection; } - function getNumberHeadings() { $this->optionUsed( 'numberheadings' ); - return $this->mNumberHeadings; } - function getAllowSpecialInclusion() { return $this->mAllowSpecialInclusion; } - function getTidy() { return $this->mTidy; } - function getInterfaceMessage() { return $this->mInterfaceMessage; } - function getTargetLanguage() { return $this->mTargetLanguage; } - function getMaxIncludeSize() { return $this->mMaxIncludeSize; } - function getMaxPPNodeCount() { return $this->mMaxPPNodeCount; } - function getMaxGeneratedPPNodeCount() { return $this->mMaxGeneratedPPNodeCount; } - function getMaxPPExpandDepth() { return $this->mMaxPPExpandDepth; } - function getMaxTemplateDepth() { return $this->mMaxTemplateDepth; } + /** + * If the page being parsed is a redirect, this should hold the redirect + * target. + * @var Title|null + */ + private $redirectTarget = null; + + public function getInterwikiMagic() { + return $this->mInterwikiMagic; + } + + public function getAllowExternalImages() { + return $this->mAllowExternalImages; + } + + public function getAllowExternalImagesFrom() { + return $this->mAllowExternalImagesFrom; + } + + public function getEnableImageWhitelist() { + return $this->mEnableImageWhitelist; + } + + public function getEditSection() { + return $this->mEditSection; + } + + public function getNumberHeadings() { + $this->optionUsed( 'numberheadings' ); + + return $this->mNumberHeadings; + } + + public function getAllowSpecialInclusion() { + return $this->mAllowSpecialInclusion; + } + + public function getTidy() { + return $this->mTidy; + } + + public function getInterfaceMessage() { + return $this->mInterfaceMessage; + } + + public function getTargetLanguage() { + return $this->mTargetLanguage; + } + + public function getMaxIncludeSize() { + return $this->mMaxIncludeSize; + } + + public function getMaxPPNodeCount() { + return $this->mMaxPPNodeCount; + } + + public function getMaxGeneratedPPNodeCount() { + return $this->mMaxGeneratedPPNodeCount; + } + + public function getMaxPPExpandDepth() { + return $this->mMaxPPExpandDepth; + } + + public function getMaxTemplateDepth() { + return $this->mMaxTemplateDepth; + } + /* @since 1.20 */ - function getExpensiveParserFunctionLimit() { return $this->mExpensiveParserFunctionLimit; } - function getRemoveComments() { return $this->mRemoveComments; } - function getTemplateCallback() { return $this->mTemplateCallback; } - function getEnableLimitReport() { return $this->mEnableLimitReport; } - function getCleanSignatures() { return $this->mCleanSignatures; } - function getExternalLinkTarget() { return $this->mExternalLinkTarget; } - function getDisableContentConversion() { return $this->mDisableContentConversion; } - function getDisableTitleConversion() { return $this->mDisableTitleConversion; } - /** @deprecated since 1.22 use User::getOption('math') instead */ - function getMath() { $this->optionUsed( 'math' ); - return $this->mMath; } - function getThumbSize() { $this->optionUsed( 'thumbsize' ); - return $this->mThumbSize; } - function getStubThreshold() { $this->optionUsed( 'stubthreshold' ); - return $this->mStubThreshold; } - - function getIsPreview() { return $this->mIsPreview; } - function getIsSectionPreview() { return $this->mIsSectionPreview; } - function getIsPrintable() { $this->optionUsed( 'printable' ); - return $this->mIsPrintable; } - function getUser() { return $this->mUser; } - function getPreSaveTransform() { return $this->mPreSaveTransform; } - - /** - * @param $title Title - * @return Skin - * @deprecated since 1.18 Use Linker::* instead - */ - function getSkin( $title = null ) { - wfDeprecated( __METHOD__, '1.18' ); - return new DummyLinker; - } - - function getDateFormat() { + public function getExpensiveParserFunctionLimit() { + return $this->mExpensiveParserFunctionLimit; + } + + public function getRemoveComments() { + return $this->mRemoveComments; + } + + public function getTemplateCallback() { + return $this->mTemplateCallback; + } + + public function getEnableLimitReport() { + return $this->mEnableLimitReport; + } + + public function getCleanSignatures() { + return $this->mCleanSignatures; + } + + public function getExternalLinkTarget() { + return $this->mExternalLinkTarget; + } + + public function getDisableContentConversion() { + return $this->mDisableContentConversion; + } + + public function getDisableTitleConversion() { + return $this->mDisableTitleConversion; + } + + public function getThumbSize() { + $this->optionUsed( 'thumbsize' ); + + return $this->mThumbSize; + } + + public function getStubThreshold() { + $this->optionUsed( 'stubthreshold' ); + + return $this->mStubThreshold; + } + + public function getIsPreview() { + return $this->mIsPreview; + } + + public function getIsSectionPreview() { + return $this->mIsSectionPreview; + } + + public function getIsPrintable() { + $this->optionUsed( 'printable' ); + + return $this->mIsPrintable; + } + + public function getUser() { + return $this->mUser; + } + + public function getPreSaveTransform() { + return $this->mPreSaveTransform; + } + + public function getDateFormat() { $this->optionUsed( 'dateformat' ); if ( !isset( $this->mDateFormat ) ) { $this->mDateFormat = $this->mUser->getDatePreference(); @@ -273,7 +355,7 @@ class ParserOptions { return $this->mDateFormat; } - function getTimestamp() { + public function getTimestamp() { if ( !isset( $this->mTimestamp ) ) { $this->mTimestamp = wfTimestampNow(); } @@ -293,10 +375,10 @@ class ParserOptions { * * {{int: }} uses this which used to produce inconsistent link tables (bug 14404). * - * @return Language object + * @return Language * @since 1.19 */ - function getUserLangObj() { + public function getUserLangObj() { $this->optionUsed( 'userlang' ); return $this->mUserLang; } @@ -304,70 +386,180 @@ class ParserOptions { /** * Same as getUserLangObj() but returns a string instead. * - * @return String Language code + * @return string Language code * @since 1.17 */ - function getUserLang() { + public function getUserLang() { return $this->getUserLangObj()->getCode(); } - function setInterwikiMagic( $x ) { return wfSetVar( $this->mInterwikiMagic, $x ); } - function setAllowExternalImages( $x ) { return wfSetVar( $this->mAllowExternalImages, $x ); } - function setAllowExternalImagesFrom( $x ) { return wfSetVar( $this->mAllowExternalImagesFrom, $x ); } - function setEnableImageWhitelist( $x ) { return wfSetVar( $this->mEnableImageWhitelist, $x ); } - function setDateFormat( $x ) { return wfSetVar( $this->mDateFormat, $x ); } - function setEditSection( $x ) { return wfSetVar( $this->mEditSection, $x ); } - function setNumberHeadings( $x ) { return wfSetVar( $this->mNumberHeadings, $x ); } - function setAllowSpecialInclusion( $x ) { return wfSetVar( $this->mAllowSpecialInclusion, $x ); } - function setTidy( $x ) { return wfSetVar( $this->mTidy, $x ); } - - /** @deprecated in 1.19 */ - function setSkin( $x ) { wfDeprecated( __METHOD__, '1.19' ); } - function setInterfaceMessage( $x ) { return wfSetVar( $this->mInterfaceMessage, $x ); } - function setTargetLanguage( $x ) { return wfSetVar( $this->mTargetLanguage, $x, true ); } - function setMaxIncludeSize( $x ) { return wfSetVar( $this->mMaxIncludeSize, $x ); } - function setMaxPPNodeCount( $x ) { return wfSetVar( $this->mMaxPPNodeCount, $x ); } - function setMaxGeneratedPPNodeCount( $x ) { return wfSetVar( $this->mMaxGeneratedPPNodeCount, $x ); } - function setMaxTemplateDepth( $x ) { return wfSetVar( $this->mMaxTemplateDepth, $x ); } + public function setInterwikiMagic( $x ) { + return wfSetVar( $this->mInterwikiMagic, $x ); + } + + public function setAllowExternalImages( $x ) { + return wfSetVar( $this->mAllowExternalImages, $x ); + } + + public function setAllowExternalImagesFrom( $x ) { + return wfSetVar( $this->mAllowExternalImagesFrom, $x ); + } + + public function setEnableImageWhitelist( $x ) { + return wfSetVar( $this->mEnableImageWhitelist, $x ); + } + + public function setDateFormat( $x ) { + return wfSetVar( $this->mDateFormat, $x ); + } + + public function setEditSection( $x ) { + return wfSetVar( $this->mEditSection, $x ); + } + + public function setNumberHeadings( $x ) { + return wfSetVar( $this->mNumberHeadings, $x ); + } + + public function setAllowSpecialInclusion( $x ) { + return wfSetVar( $this->mAllowSpecialInclusion, $x ); + } + + public function setTidy( $x ) { + return wfSetVar( $this->mTidy, $x ); + } + + public function setInterfaceMessage( $x ) { + return wfSetVar( $this->mInterfaceMessage, $x ); + } + + public function setTargetLanguage( $x ) { + return wfSetVar( $this->mTargetLanguage, $x, true ); + } + + public function setMaxIncludeSize( $x ) { + return wfSetVar( $this->mMaxIncludeSize, $x ); + } + + public function setMaxPPNodeCount( $x ) { + return wfSetVar( $this->mMaxPPNodeCount, $x ); + } + + public function setMaxGeneratedPPNodeCount( $x ) { + return wfSetVar( $this->mMaxGeneratedPPNodeCount, $x ); + } + + public function setMaxTemplateDepth( $x ) { + return wfSetVar( $this->mMaxTemplateDepth, $x ); + } + /* @since 1.20 */ - function setExpensiveParserFunctionLimit( $x ) { return wfSetVar( $this->mExpensiveParserFunctionLimit, $x ); } - function setRemoveComments( $x ) { return wfSetVar( $this->mRemoveComments, $x ); } - function setTemplateCallback( $x ) { return wfSetVar( $this->mTemplateCallback, $x ); } - function enableLimitReport( $x = true ) { return wfSetVar( $this->mEnableLimitReport, $x ); } - function setTimestamp( $x ) { return wfSetVar( $this->mTimestamp, $x ); } - function setCleanSignatures( $x ) { return wfSetVar( $this->mCleanSignatures, $x ); } - function setExternalLinkTarget( $x ) { return wfSetVar( $this->mExternalLinkTarget, $x ); } - function disableContentConversion( $x = true ) { return wfSetVar( $this->mDisableContentConversion, $x ); } - function disableTitleConversion( $x = true ) { return wfSetVar( $this->mDisableTitleConversion, $x ); } - /** @deprecated since 1.22 */ - function setMath( $x ) { return wfSetVar( $this->mMath, $x ); } - function setUserLang( $x ) { + public function setExpensiveParserFunctionLimit( $x ) { + return wfSetVar( $this->mExpensiveParserFunctionLimit, $x ); + } + + public function setRemoveComments( $x ) { + return wfSetVar( $this->mRemoveComments, $x ); + } + + public function setTemplateCallback( $x ) { + return wfSetVar( $this->mTemplateCallback, $x ); + } + + public function enableLimitReport( $x = true ) { + return wfSetVar( $this->mEnableLimitReport, $x ); + } + + public function setTimestamp( $x ) { + return wfSetVar( $this->mTimestamp, $x ); + } + + public function setCleanSignatures( $x ) { + return wfSetVar( $this->mCleanSignatures, $x ); + } + + public function setExternalLinkTarget( $x ) { + return wfSetVar( $this->mExternalLinkTarget, $x ); + } + + public function disableContentConversion( $x = true ) { + return wfSetVar( $this->mDisableContentConversion, $x ); + } + + public function disableTitleConversion( $x = true ) { + return wfSetVar( $this->mDisableTitleConversion, $x ); + } + + public function setUserLang( $x ) { if ( is_string( $x ) ) { $x = Language::factory( $x ); } + return wfSetVar( $this->mUserLang, $x ); } - function setThumbSize( $x ) { return wfSetVar( $this->mThumbSize, $x ); } - function setStubThreshold( $x ) { return wfSetVar( $this->mStubThreshold, $x ); } - function setPreSaveTransform( $x ) { return wfSetVar( $this->mPreSaveTransform, $x ); } - function setIsPreview( $x ) { return wfSetVar( $this->mIsPreview, $x ); } - function setIsSectionPreview( $x ) { return wfSetVar( $this->mIsSectionPreview, $x ); } - function setIsPrintable( $x ) { return wfSetVar( $this->mIsPrintable, $x ); } + public function setThumbSize( $x ) { + return wfSetVar( $this->mThumbSize, $x ); + } + + public function setStubThreshold( $x ) { + return wfSetVar( $this->mStubThreshold, $x ); + } + + public function setPreSaveTransform( $x ) { + return wfSetVar( $this->mPreSaveTransform, $x ); + } + + public function setIsPreview( $x ) { + return wfSetVar( $this->mIsPreview, $x ); + } + + public function setIsSectionPreview( $x ) { + return wfSetVar( $this->mIsSectionPreview, $x ); + } + + public function setIsPrintable( $x ) { + return wfSetVar( $this->mIsPrintable, $x ); + } + + /** + * Set the redirect target. + * + * Note that setting or changing this does not *make* the page a redirect + * or change its target, it merely records the information for reference + * during the parse. + * + * @since 1.24 + * @param Title|null $title + */ + function setRedirectTarget( $title ) { + $this->redirectTarget = $title; + } + + /** + * Get the previously-set redirect target. + * + * @since 1.24 + * @return Title|null + */ + function getRedirectTarget() { + return $this->redirectTarget; + } /** * Extra key that should be present in the parser cache key. + * @param string $key */ - function addExtraKey( $key ) { + public function addExtraKey( $key ) { $this->mExtraKey .= '!' . $key; } /** * Constructor - * @param $user User object - * @param $lang Language object + * @param User $user + * @param Language $lang */ - function __construct( $user = null, $lang = null ) { + public function __construct( $user = null, $lang = null ) { if ( $user === null ) { global $wgUser; if ( $wgUser === null ) { @@ -390,8 +582,8 @@ class ParserOptions { * Get a ParserOptions object from a given user. * Language will be taken from $wgLang. * - * @param $user User object - * @return ParserOptions object + * @param User $user + * @return ParserOptions */ public static function newFromUser( $user ) { return new ParserOptions( $user ); @@ -400,9 +592,9 @@ class ParserOptions { /** * Get a ParserOptions object from a given user and language * - * @param $user User object - * @param $lang Language object - * @return ParserOptions object + * @param User $user + * @param Language $lang + * @return ParserOptions */ public static function newFromUserAndLang( User $user, Language $lang ) { return new ParserOptions( $user, $lang ); @@ -411,8 +603,8 @@ class ParserOptions { /** * Get a ParserOptions object from a IContextSource object * - * @param $context IContextSource object - * @return ParserOptions object + * @param IContextSource $context + * @return ParserOptions */ public static function newFromContext( IContextSource $context ) { return new ParserOptions( $context->getUser(), $context->getLanguage() ); @@ -421,8 +613,8 @@ class ParserOptions { /** * Get user options * - * @param $user User object - * @param $lang Language object + * @param User $user + * @param Language $lang */ private function initialiseFromUser( $user, $lang ) { global $wgInterwikiMagic, $wgAllowExternalImages, @@ -451,7 +643,6 @@ class ParserOptions { $this->mUser = $user; $this->mNumberHeadings = $user->getOption( 'numberheadings' ); - $this->mMath = $user->getOption( 'math' ); $this->mThumbSize = $user->getOption( 'thumbsize' ); $this->mStubThreshold = $user->getStubThreshold(); $this->mUserLang = $lang; @@ -462,15 +653,17 @@ class ParserOptions { /** * Registers a callback for tracking which ParserOptions which are used. * This is a private API with the parser. + * @param callable $callback */ - function registerWatcher( $callback ) { + public function registerWatcher( $callback ) { $this->onAccessCallback = $callback; } /** * Called when an option is accessed. + * @param string $optionName Name of the option */ - protected function optionUsed( $optionName ) { + public function optionUsed( $optionName ) { if ( $this->onAccessCallback ) { call_user_func( $this->onAccessCallback, $optionName ); } @@ -483,37 +676,39 @@ class ParserOptions { * @return array */ public static function legacyOptions() { - return array( 'math', 'stubthreshold', 'numberheadings', 'userlang', 'thumbsize', 'editsection', 'printable' ); + return array( + 'stubthreshold', + 'numberheadings', + 'userlang', + 'thumbsize', + 'editsection', + 'printable' + ); } /** * Generate a hash string with the values set on these ParserOptions * for the keys given in the array. * This will be used as part of the hash key for the parser cache, - * so users sharign the options with vary for the same page share + * so users sharing the options with vary for the same page share * the same cached data safely. * - * Replaces User::getPageRenderingHash() - * * Extensions which require it should install 'PageRenderingHash' hook, * which will give them a chance to modify this key based on their own * settings. * * @since 1.17 - * @param $forOptions Array - * @param $title Title: used to get the content language of the page (since r97636) + * @param array $forOptions + * @param Title $title Used to get the content language of the page (since r97636) * @return string Page rendering hash */ public function optionsHash( $forOptions, $title = null ) { global $wgRenderHashAppend; - $confstr = ''; - - if ( in_array( 'math', $forOptions ) ) { - $confstr .= $this->mMath; - } else { - $confstr .= '*'; - } + // FIXME: Once the cache key is reorganized this argument + // can be dropped. It was used when the math extension was + // part of core. + $confstr = '*'; // Space assigned for the stubthreshold but unused // since it disables the parser cache, its value will always @@ -573,7 +768,7 @@ class ParserOptions { // Give a chance for extensions to modify the hash, if they have // extra options or other effects on the parser cache. - wfRunHooks( 'PageRenderingHash', array( &$confstr ) ); + wfRunHooks( 'PageRenderingHash', array( &$confstr, $this->getUser(), &$forOptions ) ); // Make it a valid memcached key fragment $confstr = str_replace( ' ', '_', $confstr ); -- cgit v1.2.2