From 27fd0920a12dbf70100b450a97485471137e1d35 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Wed, 21 Jun 2017 11:35:32 -0400 Subject: [PATCH] Remove ParserOptions::optionsHashPre30() The pre-1.30 version of ParserOptions::optionsHash() was kept temporarily as ParserOptions::optionsHashPre30() to prevent a cache stampede on WMF sites when the hash format was changed in I7fb9ffca9. Now that the cache has been rebuilt, it's no longer needed and we should clean it up instead of leaving it forever to bitrot. Change-Id: I037d8dfdefe72a295547bd331bc1454e69cb418d --- includes/parser/ParserCache.php | 31 +----- includes/parser/ParserOptions.php | 95 +------------------ .../includes/parser/ParserOptionsTest.php | 60 ------------ 3 files changed, 2 insertions(+), 184 deletions(-) diff --git a/includes/parser/ParserCache.php b/includes/parser/ParserCache.php index 1f0e19eb26..76a7e1ed7a 100644 --- a/includes/parser/ParserCache.php +++ b/includes/parser/ParserCache.php @@ -138,20 +138,6 @@ class ParserCache { * @return bool|mixed|string */ public function getKey( $article, $popts, $useOutdated = true ) { - $dummy = null; - return $this->getKeyReal( $article, $popts, $useOutdated, $dummy ); - } - - /** - * Temporary internal function to allow accessing $usedOptions - * @todo Merge this back to self::getKey() when ParserOptions::optionsHashPre30() is removed - * @param WikiPage $article - * @param ParserOptions $popts - * @param bool $useOutdated (default true) - * @param array &$usedOptions Don't use this, it will go away soon - * @return bool|mixed|string - */ - private function getKeyReal( $article, $popts, $useOutdated, &$usedOptions ) { global $wgCacheEpoch; if ( $popts instanceof User ) { @@ -218,8 +204,7 @@ class ParserCache { $touched = $article->getTouched(); - $usedOptions = null; - $parserOutputKey = $this->getKeyReal( $article, $popts, $useOutdated, $usedOptions ); + $parserOutputKey = $this->getKey( $article, $popts, $useOutdated ); if ( $parserOutputKey === false ) { wfIncrStats( 'pcache.miss.absent' ); return false; @@ -228,13 +213,6 @@ class ParserCache { $casToken = null; /** @var ParserOutput $value */ $value = $this->mMemc->get( $parserOutputKey, $casToken, BagOStuff::READ_VERIFIED ); - if ( !$value ) { - $parserOutputKey = $this->getParserOutputKey( - $article, - $popts->optionsHashPre30( $usedOptions, $article->getTitle() ) - ); - $value = $this->mMemc->get( $parserOutputKey, $casToken, BagOStuff::READ_VERIFIED ); - } if ( !$value ) { wfDebug( "ParserOutput cache miss.\n" ); wfIncrStats( "pcache.miss.absent" ); @@ -327,13 +305,6 @@ class ParserCache { // ...and its pointer $this->mMemc->set( $this->getOptionsKey( $page ), $optionsKey, $expire ); - // Normally, when there was no key change, the above would have - // overwritten the old entry. Delete that old entry to save disk - // space. - $oldParserOutputKey = $this->getParserOutputKey( $page, - $popts->optionsHashPre30( $optionsKey->mUsedOptions, $page->getTitle() ) ); - $this->mMemc->delete( $oldParserOutputKey ); - Hooks::run( 'ParserCacheSaveComplete', [ $this, $parserOutput, $page->getTitle(), $popts, $revId ] diff --git a/includes/parser/ParserOptions.php b/includes/parser/ParserOptions.php index 5be0321bbe..4809917b63 100644 --- a/includes/parser/ParserOptions.php +++ b/includes/parser/ParserOptions.php @@ -1269,8 +1269,7 @@ class ParserOptions { // Feb 2015 (instead the parser outputs a constant placeholder and post-parse // processing handles the option). But Wikibase forces it in $forOptions // and expects the cache key to still vary on it for T85252. - // @todo Deprecate and remove this behavior after optionsHashPre30() is - // removed (Wikibase can use addExtraKey() or something instead). + // @deprecated since 1.30, Wikibase should use addExtraKey() or something instead. if ( in_array( 'editsection', $forOptions, true ) ) { $options['editsection'] = $this->mEditSection; $defaults['editsection'] = true; @@ -1321,98 +1320,6 @@ class ParserOptions { return $confstr; } - /** - * Generate the hash used before MediaWiki 1.30 - * @since 1.30 - * @deprecated since 1.30. Do not use this unless you're ParserCache. - * @param array $forOptions - * @param Title $title Used to get the content language of the page (since r97636) - * @return string Page rendering hash - */ - public function optionsHashPre30( $forOptions, $title = null ) { - global $wgRenderHashAppend; - - // 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 - // be 0 when this function is called by parsercache. - if ( in_array( 'stubthreshold', $forOptions ) ) { - $confstr .= '!' . $this->options['stubthreshold']; - } else { - $confstr .= '!*'; - } - - if ( in_array( 'dateformat', $forOptions ) ) { - $confstr .= '!' . $this->getDateFormat(); - } - - if ( in_array( 'numberheadings', $forOptions ) ) { - $confstr .= '!' . ( $this->options['numberheadings'] ? '1' : '' ); - } else { - $confstr .= '!*'; - } - - if ( in_array( 'userlang', $forOptions ) ) { - $confstr .= '!' . $this->options['userlang']->getCode(); - } else { - $confstr .= '!*'; - } - - if ( in_array( 'thumbsize', $forOptions ) ) { - $confstr .= '!' . $this->options['thumbsize']; - } else { - $confstr .= '!*'; - } - - // add in language specific options, if any - // @todo FIXME: This is just a way of retrieving the url/user preferred variant - if ( !is_null( $title ) ) { - $confstr .= $title->getPageLanguage()->getExtraHashOptions(); - } else { - global $wgContLang; - $confstr .= $wgContLang->getExtraHashOptions(); - } - - $confstr .= $wgRenderHashAppend; - - // @note: as of Feb 2015, core never sets the editsection flag, since it uses - // tags to inject editsections on the fly. However, extensions - // may be using it by calling ParserOption::optionUsed resp. ParserOutput::registerOption - // directly. At least Wikibase does at this point in time. - if ( !in_array( 'editsection', $forOptions ) ) { - $confstr .= '!*'; - } elseif ( !$this->mEditSection ) { - $confstr .= '!edit=0'; - } - - if ( $this->options['printable'] && in_array( 'printable', $forOptions ) ) { - $confstr .= '!printable=1'; - } - - if ( $this->options['wrapclass'] !== 'mw-parser-output' && - in_array( 'wrapclass', $forOptions ) - ) { - $confstr .= '!wrapclass=' . $this->options['wrapclass']; - } - - if ( $this->mExtraKey != '' ) { - $confstr .= $this->mExtraKey; - } - - // Give a chance for extensions to modify the hash, if they have - // extra options or other effects on the parser cache. - Hooks::run( 'PageRenderingHash', [ &$confstr, $this->getUser(), &$forOptions ] ); - - // Make it a valid memcached key fragment - $confstr = str_replace( ' ', '_', $confstr ); - - return $confstr; - } - /** * Test whether these options are safe to cache * @since 1.30 diff --git a/tests/phpunit/includes/parser/ParserOptionsTest.php b/tests/phpunit/includes/parser/ParserOptionsTest.php index d6061420e7..264e35d5a2 100644 --- a/tests/phpunit/includes/parser/ParserOptionsTest.php +++ b/tests/phpunit/includes/parser/ParserOptionsTest.php @@ -37,66 +37,6 @@ class ParserOptionsTest extends MediaWikiTestCase { ]; } - /** - * @dataProvider provideOptionsHashPre30 - * @param array $usedOptions Used options - * @param string $expect Expected value - * @param array $options Options to set - * @param array $globals Globals to set - */ - public function testOptionsHashPre30( $usedOptions, $expect, $options, $globals = [] ) { - global $wgHooks; - - $globals += [ - 'wgRenderHashAppend' => '', - 'wgHooks' => [], - ]; - $globals['wgHooks'] += [ - 'PageRenderingHash' => [], - ] + $wgHooks; - $this->setMwGlobals( $globals ); - - $popt = new ParserOptions(); - foreach ( $options as $setter => $value ) { - $popt->$setter( $value ); - } - $this->assertSame( $expect, $popt->optionsHashPre30( $usedOptions ) ); - } - - public static function provideOptionsHashPre30() { - $used = [ 'wrapclass', 'printable' ]; - - return [ - 'Canonical options, nothing used' => [ [], '*!*!*!*!*!*', [] ], - 'Canonical options, used some options' => [ $used, '*!*!*!*!*!*', [] ], - 'Used some options, non-default values' => [ - $used, - '*!*!*!*!*!*!printable=1!wrapclass=foobar', - [ - 'setWrapOutputClass' => 'foobar', - 'setIsPrintable' => true, - ] - ], - 'Canonical options, nothing used, but with hooks and $wgRenderHashAppend' => [ - [], - '*!*!*!*!*!wgRenderHashAppend!*!onPageRenderingHash', - [], - [ - 'wgRenderHashAppend' => '!wgRenderHashAppend', - 'wgHooks' => [ 'PageRenderingHash' => [ [ __CLASS__ . '::onPageRenderingHash' ] ] ], - ] - ], - - // Test weird historical behavior is still weird - 'Canonical options, editsection=true used' => [ [ 'editsection' ], '*!*!*!*!*', [ - 'setEditSection' => true, - ] ], - 'Canonical options, editsection=false used' => [ [ 'editsection' ], '*!*!*!*!*!edit=0', [ - 'setEditSection' => false, - ] ], - ]; - } - /** * @dataProvider provideOptionsHash * @param array $usedOptions Used options -- 2.20.1