From: Brad Jorsch
Date: Wed, 22 Nov 2017 23:12:40 +0000 (-0500)
Subject: Hard-deprecate ParserOutput stateful transform methods
X-Git-Tag: 1.31.0-rc.0~604^2
X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22sites_tous%22%29%20.%20%22?a=commitdiff_plain;h=2791fb08619545b12e58dd576ee6a98c38082c64;p=lhc%2Fweb%2Fwiklou.git
Hard-deprecate ParserOutput stateful transform methods
This also removes all the in-core calls that had been kept for the
benefit of extensions, and causes them to not have any effect since
anything that had been calling them was already either a no-op or will
probably be broken now that nothing in core is setting or checking the
flags.
Change-Id: Id22c1a5a6d6a249debb14063ae3f8838d105b634
---
diff --git a/includes/EditPage.php b/includes/EditPage.php
index 6fbeed7b4d..cdf2106cba 100644
--- a/includes/EditPage.php
+++ b/includes/EditPage.php
@@ -4028,7 +4028,6 @@ ERROR;
$this->mTitle, $pstContent, $user );
$parserOutput = $pstContent->getParserOutput( $this->mTitle, null, $parserOptions );
ScopedCallback::consume( $scopedCallback );
- $parserOutput->setEditSectionTokens( false ); // no section edit links
return [
'parserOutput' => $parserOutput,
'html' => $parserOutput->getText( [
diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index 6b44a557b4..d210da4191 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -287,11 +287,6 @@ class OutputPage extends ContextSource {
*/
private $mEnableTOC = false;
- /**
- * @var bool Whether parser output should contain section edit links
- */
- private $mEnableSectionEditLinks = true;
-
/**
* @var string|null The URL to send in a element with rel=license
*/
@@ -1548,7 +1543,6 @@ class OutputPage extends ContextSource {
// Someone is trying to set a bogus pre-$wgUser PO. Check if it has
// been changed somehow, and keep it if so.
$anonPO = ParserOptions::newFromAnon();
- $anonPO->setEditSection( false );
$anonPO->setAllowUnsafeRawHtml( false );
if ( !$options->matches( $anonPO ) ) {
wfLogWarning( __METHOD__ . ': Setting a changed bogus ParserOptions: ' . wfGetAllCallers( 5 ) );
@@ -1562,7 +1556,6 @@ class OutputPage extends ContextSource {
// ParserOptions for it. And don't cache this ParserOptions
// either.
$po = ParserOptions::newFromAnon();
- $po->setEditSection( false );
$po->setAllowUnsafeRawHtml( false );
$po->isBogus = true;
if ( $options !== null ) {
@@ -1572,7 +1565,6 @@ class OutputPage extends ContextSource {
}
$this->mParserOptions = ParserOptions::newFromContext( $this->getContext() );
- $this->mParserOptions->setEditSection( false );
$this->mParserOptions->setAllowUnsafeRawHtml( false );
}
@@ -1822,7 +1814,7 @@ class OutputPage extends ContextSource {
// so that extensions may modify ParserOutput to toggle TOC.
// This cannot be moved to addParserOutputText because that is not
// called by EditPage for Preview.
- if ( $parserOutput->getTOCEnabled() && $parserOutput->getTOCHTML() ) {
+ if ( $parserOutput->getTOCHTML() ) {
$this->mEnableTOC = true;
}
}
@@ -1868,17 +1860,6 @@ class OutputPage extends ContextSource {
*/
function addParserOutput( $parserOutput, $poOptions = [] ) {
$this->addParserOutputMetadata( $parserOutput );
-
- // Touch section edit links only if not previously disabled
- if ( $parserOutput->getEditSectionTokens() ) {
- $parserOutput->setEditSectionTokens( $this->mEnableSectionEditLinks );
- }
- if ( !$this->mEnableSectionEditLinks
- && !array_key_exists( 'enableSectionEditLinks', $poOptions )
- ) {
- $poOptions['enableSectionEditLinks'] = false;
- }
-
$this->addParserOutputText( $parserOutput, $poOptions );
}
@@ -3896,7 +3877,7 @@ class OutputPage extends ContextSource {
* @deprecated since 1.31, use $poOptions to addParserOutput() instead.
*/
public function enableSectionEditLinks( $flag = true ) {
- $this->mEnableSectionEditLinks = $flag;
+ wfDeprecated( __METHOD__, '1.31' );
}
/**
@@ -3905,7 +3886,8 @@ class OutputPage extends ContextSource {
* @deprecated since 1.31, use $poOptions to addParserOutput() instead.
*/
public function sectionEditLinksEnabled() {
- return $this->mEnableSectionEditLinks;
+ wfDeprecated( __METHOD__, '1.31' );
+ return true;
}
/**
diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php
index 3326fab5e4..cbd62a97df 100644
--- a/includes/api/ApiParse.php
+++ b/includes/api/ApiParse.php
@@ -536,7 +536,6 @@ class ApiParse extends ApiBase {
$popts->enableLimitReport( !$params['disablepp'] && !$params['disablelimitreport'] );
$popts->setIsPreview( $params['preview'] || $params['sectionpreview'] );
$popts->setIsSectionPreview( $params['sectionpreview'] );
- $popts->setEditSection( !$params['disableeditsection'] );
if ( $params['disabletidy'] ) {
$popts->setTidy( false );
}
diff --git a/includes/cache/MessageCache.php b/includes/cache/MessageCache.php
index 63c03af25b..d5ff6cbc9a 100644
--- a/includes/cache/MessageCache.php
+++ b/includes/cache/MessageCache.php
@@ -191,13 +191,11 @@ class MessageCache {
// ParserOptions for it. And don't cache this ParserOptions
// either.
$po = ParserOptions::newFromAnon();
- $po->setEditSection( false );
$po->setAllowUnsafeRawHtml( false );
return $po;
}
$this->mParserOptions = new ParserOptions;
- $this->mParserOptions->setEditSection( false );
// Messages may take parameters that could come
// from malicious sources. As a precaution, disable
// the parser tag when parsing messages.
diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php
index e76bffcace..fa30d68655 100644
--- a/includes/diff/DifferenceEngine.php
+++ b/includes/diff/DifferenceEngine.php
@@ -658,11 +658,6 @@ class DifferenceEngine extends ContextSource {
*/
protected function getParserOutput( WikiPage $page, Revision $rev ) {
$parserOptions = $page->makeParserOptions( $this->getContext() );
-
- if ( !$rev->isCurrent() || !$rev->getTitle()->quickUserCan( 'edit', $this->getUser() ) ) {
- $parserOptions->setEditSection( false );
- }
-
$parserOutput = $page->getParserOutput( $parserOptions, $rev->getId() );
return $parserOutput;
diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php
index dbd143c8e4..f5e12d6477 100644
--- a/includes/installer/Installer.php
+++ b/includes/installer/Installer.php
@@ -445,7 +445,6 @@ abstract class Installer {
$this->parserTitle = Title::newFromText( 'Installer' );
$this->parserOptions = new ParserOptions( $wgUser ); // language will be wrong :(
- $this->parserOptions->setEditSection( false );
// Don't try to access DB before user language is initialised
$this->setParserLanguage( Language::factory( 'en' ) );
}
diff --git a/includes/page/Article.php b/includes/page/Article.php
index 343c4c8d6f..8eb3709b53 100644
--- a/includes/page/Article.php
+++ b/includes/page/Article.php
@@ -480,12 +480,10 @@ class Article implements Page {
# Render printable version, use printable version cache
if ( $outputPage->isPrintable() ) {
$parserOptions->setIsPrintable( true );
- $parserOptions->setEditSection( false );
$poOptions['enableSectionEditLinks'] = false;
} elseif ( $this->disableSectionEditForRender
|| !$this->isCurrent() || !$this->getTitle()->quickUserCan( 'edit', $user )
) {
- $parserOptions->setEditSection( false );
$poOptions['enableSectionEditLinks'] = false;
}
@@ -1526,7 +1524,6 @@ class Article implements Page {
public function render() {
$this->getContext()->getRequest()->response()->header( 'X-Robots-Tag: noindex' );
$this->getContext()->getOutput()->setArticleBodyOnly( true );
- $this->getContext()->getOutput()->enableSectionEditLinks( false );
$this->disableSectionEditForRender = true;
$this->view();
}
diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php
index b2d8511de8..2adfd0a5d2 100644
--- a/includes/parser/Parser.php
+++ b/includes/parser/Parser.php
@@ -4032,13 +4032,9 @@ class Parser {
# Inhibit editsection links if requested in the page
if ( isset( $this->mDoubleUnderscores['noeditsection'] ) ) {
- $maybeShowEditLink = $showEditLink = false;
+ $maybeShowEditLink = false;
} else {
- $maybeShowEditLink = true; /* Actual presence will depend on ParserOptions option */
- $showEditLink = $this->mOptions->getEditSection();
- }
- if ( $showEditLink ) {
- $this->mOutput->setEditSectionTokens( true );
+ $maybeShowEditLink = true; /* Actual presence will depend on post-cache transforms */
}
# Get all headlines for numbering them and adding funky stuff like [edit]
@@ -4390,9 +4386,9 @@ class Parser {
* $this : caller
* $section : the section number
* &$sectionContent : ref to the content of the section
- * $showEditLinks : boolean describing whether this section has an edit link
+ * $maybeShowEditLinks : boolean describing whether this section has an edit link
*/
- Hooks::run( 'ParserSectionCreate', [ $this, $i, &$sections[$i], $showEditLink ] );
+ Hooks::run( 'ParserSectionCreate', [ $this, $i, &$sections[$i], $maybeShowEditLink ] );
$i++;
}
diff --git a/includes/parser/ParserCache.php b/includes/parser/ParserCache.php
index c680129934..8a7fca6c29 100644
--- a/includes/parser/ParserCache.php
+++ b/includes/parser/ParserCache.php
@@ -253,11 +253,6 @@ class ParserCache {
wfDebug( "ParserOutput cache found.\n" );
- // The edit section preference may not be the appropiate one in
- // the ParserOutput, as we are not storing it in the parsercache
- // key. Force it here. See T33445.
- $value->setEditSectionTokens( $popts->getEditSection() );
-
$wikiPage = method_exists( $article, 'getPage' )
? $article->getPage()
: $article;
diff --git a/includes/parser/ParserOptions.php b/includes/parser/ParserOptions.php
index ca8e739f9a..bbddbe2809 100644
--- a/includes/parser/ParserOptions.php
+++ b/includes/parser/ParserOptions.php
@@ -80,13 +80,6 @@ class ParserOptions {
*/
private $mTimestamp;
- /**
- * The edit section flag is in ParserOptions for historical reasons, but
- * doesn't actually affect the parser output since Feb 2015.
- * @var bool
- */
- private $mEditSection = true;
-
/**
* Stored user object
* @var User
@@ -876,7 +869,8 @@ class ParserOptions {
* @return bool
*/
public function getEditSection() {
- return $this->mEditSection;
+ wfDeprecated( __METHOD__, '1.31' );
+ return true;
}
/**
@@ -886,7 +880,8 @@ class ParserOptions {
* @return bool Old value
*/
public function setEditSection( $x ) {
- return wfSetVar( $this->mEditSection, $x );
+ wfDeprecated( __METHOD__, '1.31' );
+ return true;
}
/**
@@ -1284,18 +1279,6 @@ class ParserOptions {
$defaults = self::getCanonicalOverrides() + self::getDefaults();
$inCacheKey = self::$inCacheKey;
- // Historical hack: 'editsection' hasn't been a true parser option since
- // 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.
- // @deprecated since 1.30, Wikibase should use addExtraKey() or something instead.
- if ( in_array( 'editsection', $forOptions, true ) ) {
- $options['editsection'] = $this->mEditSection;
- $defaults['editsection'] = true;
- $inCacheKey['editsection'] = true;
- ksort( $inCacheKey );
- }
-
// We only include used options with non-canonical values in the key
// so adding a new option doesn't invalidate the entire parser cache.
// The drawback to this is that changing the default value of an option
diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php
index 19375e0c21..8f0a1d7cc9 100644
--- a/includes/parser/ParserOutput.php
+++ b/includes/parser/ParserOutput.php
@@ -151,12 +151,6 @@ class ParserOutput extends CacheTime {
*/
public $mSections = [];
- /**
- * @deprecated since 1.31 Use getText() options.
- * @var bool $mEditSectionTokens prefix/suffix markers if edit sections were output as tokens.
- */
- public $mEditSectionTokens = true;
-
/**
* @var array $mProperties Name/value pairs to be cached in the DB.
*/
@@ -172,12 +166,6 @@ class ParserOutput extends CacheTime {
*/
public $mTimestamp;
- /**
- * @deprecated since 1.31 Use getText() options.
- * @var bool $mTOCEnabled Whether TOC should be shown, can't override __NOTOC__.
- */
- public $mTOCEnabled = true;
-
/**
* @var bool $mEnableOOUI Whether OOUI should be enabled.
*/
@@ -280,22 +268,9 @@ class ParserOutput extends CacheTime {
* @return string HTML
*/
public function getText( $options = [] ) {
- if ( !array_key_exists( 'allowTOC', $options ) && empty( $this->mTOCEnabled ) ) {
- wfDeprecated( 'ParserOutput stateful allowTOC', '1.31' );
- }
-
- // Note that while $this->mEditSectionTokens formerly defaulted to false,
- // ParserOptions->getEditSection() defaults to true and Parser copies
- // that to us so true makes more sense as the stateless default.
- if ( !array_key_exists( 'enableSectionEditLinks', $options ) && !$this->mEditSectionTokens ) {
- wfDeprecated( 'ParserOutput stateful enableSectionEditLinks', '1.31' );
- }
-
$options += [
- // empty() here because old cached versions might lack the field somehow.
- // In that situation, the historical behavior (possibly buggy) is to remove the TOC.
- 'allowTOC' => !empty( $this->mTOCEnabled ),
- 'enableSectionEditLinks' => $this->mEditSectionTokens,
+ 'allowTOC' => true,
+ 'enableSectionEditLinks' => true,
'unwrap' => false,
'deduplicateStyles' => true,
];
@@ -442,7 +417,8 @@ class ParserOutput extends CacheTime {
* @deprecated since 1.31 Use getText() options.
*/
public function getEditSectionTokens() {
- return $this->mEditSectionTokens;
+ wfDeprecated( __METHOD__, '1.31' );
+ return true;
}
public function &getLinks() {
@@ -532,7 +508,8 @@ class ParserOutput extends CacheTime {
* @deprecated since 1.31 Use getText() options.
*/
public function getTOCEnabled() {
- return $this->mTOCEnabled;
+ wfDeprecated( __METHOD__, '1.31' );
+ return true;
}
public function getEnableOOUI() {
@@ -563,7 +540,8 @@ class ParserOutput extends CacheTime {
* @deprecated since 1.31 Use getText() options.
*/
public function setEditSectionTokens( $t ) {
- return wfSetVar( $this->mEditSectionTokens, $t );
+ wfDeprecated( __METHOD__, '1.31' );
+ return true;
}
public function setIndexPolicy( $policy ) {
@@ -582,7 +560,8 @@ class ParserOutput extends CacheTime {
* @deprecated since 1.31 Use getText() options.
*/
public function setTOCEnabled( $flag ) {
- return wfSetVar( $this->mTOCEnabled, $flag );
+ wfDeprecated( __METHOD__, '1.31' );
+ return true;
}
public function addCategory( $c, $sort ) {
diff --git a/includes/specials/SpecialUndelete.php b/includes/specials/SpecialUndelete.php
index f821effdf0..127a36ba3c 100644
--- a/includes/specials/SpecialUndelete.php
+++ b/includes/specials/SpecialUndelete.php
@@ -450,9 +450,7 @@ class SpecialUndelete extends SpecialPage {
if ( ( $this->mPreview || !$isText ) && $content ) {
// NOTE: non-text content has no source view, so always use rendered preview
- // Hide [edit]s
$popts = $out->parserOptions();
- $popts->setEditSection( false );
$pout = $content->getParserOutput( $this->mTargetObj, $rev->getId(), $popts, true );
$out->addParserOutput( $pout, [
diff --git a/tests/phpunit/includes/parser/ParserOptionsTest.php b/tests/phpunit/includes/parser/ParserOptionsTest.php
index d55372c61f..e2ed1d57e0 100644
--- a/tests/phpunit/includes/parser/ParserOptionsTest.php
+++ b/tests/phpunit/includes/parser/ParserOptionsTest.php
@@ -141,23 +141,6 @@ class ParserOptionsTest extends MediaWikiTestCase {
$confstr .= '!onPageRenderingHash';
}
- // Test weird historical behavior is still weird
- public function testOptionsHashEditSection() {
- $popt = ParserOptions::newCanonical();
- $popt->registerWatcher( function ( $name ) {
- $this->assertNotEquals( 'editsection', $name );
- } );
-
- $this->assertTrue( $popt->getEditSection() );
- $this->assertSame( 'canonical', $popt->optionsHash( [] ) );
- $this->assertSame( 'canonical', $popt->optionsHash( [ 'editsection' ] ) );
-
- $popt->setEditSection( false );
- $this->assertFalse( $popt->getEditSection() );
- $this->assertSame( 'canonical', $popt->optionsHash( [] ) );
- $this->assertSame( 'editsection=0', $popt->optionsHash( [ 'editsection' ] ) );
- }
-
/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Unknown parser option bogus
diff --git a/tests/phpunit/includes/parser/ParserOutputTest.php b/tests/phpunit/includes/parser/ParserOutputTest.php
index 44c1773adb..b08ba6c484 100644
--- a/tests/phpunit/includes/parser/ParserOutputTest.php
+++ b/tests/phpunit/includes/parser/ParserOutputTest.php
@@ -1,7 +1,5 @@
setMwGlobals( [
'wgArticlePath' => '/wiki/$1',
'wgScriptPath' => '/w',
'wgScript' => '/w/index.php',
] );
- $this->hideDeprecated( 'ParserOutput stateful allowTOC' );
- $this->hideDeprecated( 'ParserOutput stateful enableSectionEditLinks' );
$po = new ParserOutput( $text );
-
- // Emulate Parser
- $po->setEditSectionTokens( true );
-
- if ( $poState ) {
- $wrap = TestingAccessWrapper::newFromObject( $po );
- foreach ( $poState as $key => $value ) {
- $wrap->$key = $value;
- }
- }
-
$actual = $po->getText( $options );
$this->assertSame( $expect, $actual );
}
@@ -169,89 +153,8 @@ EOF;
EOF;
return [
- 'No stateless options, default state' => [
- [], [], $text, <<Test document.
-
-
-
-Section 1[edit]
-One
-
-Section 2[edit]
-Two
-
-Section 2.1[edit]
-Two point one
-
-Section 3[edit]
-Three
-
-EOF
- ],
- 'No stateless options, TOC statefully disabled' => [
- [], [ 'mTOCEnabled' => false ], $text, <<Test document.
-
-
-Section 1[edit]
-One
-
-Section 2[edit]
-Two
-
-Section 2.1[edit]
-Two point one
-
-Section 3[edit]
-Three
-
-EOF
- ],
- 'No stateless options, section edits statefully disabled' => [
- [], [ 'mEditSectionTokens' => false ], $text, <<Test document.
-
-
-
-Section 1
-One
-
-Section 2
-Two
-
-Section 2.1
-Two point one
-
-Section 3
-Three
-
-EOF
- ],
- 'Stateless options override stateful settings' => [
- [ 'allowTOC' => true, 'enableSectionEditLinks' => true ],
- [ 'mTOCEnabled' => false, 'mEditSectionTokens' => false ],
- $text, << [
+ [], $text, <<Test document.
Contents
@@ -280,8 +183,8 @@ EOF
EOF
],
- 'Statelessly disable section edit links' => [
- [ 'enableSectionEditLinks' => false ], [], $text, << [
+ [ 'enableSectionEditLinks' => false ], $text, <<Test document.
Contents
@@ -310,8 +213,8 @@ EOF
EOF
],
- 'Statelessly disable TOC' => [
- [ 'allowTOC' => false ], [], $text, << [
+ [ 'allowTOC' => false ], $text, <<Test document.
@@ -329,8 +232,8 @@ EOF
EOF
],
- 'Statelessly unwrap text' => [
- [ 'unwrap' => true ], [], $text, << [
+ [ 'unwrap' => true ], $text, <<Test document.
Contents
@@ -360,15 +263,15 @@ EOF
EOF
],
'Unwrap without a mw-parser-output wrapper' => [
- [ 'unwrap' => true ], [], '
Content
', '
Content
'
+ [ 'unwrap' => true ], '
Content
', '
Content
'
],
'Unwrap with extra comment at end' => [
- [ 'unwrap' => true ], [], '
+ [ 'unwrap' => true ], '
', '
Test document.
'
],
'Style deduplication' => [
- [], [], $dedupText, <<
This is a test document.
@@ -382,7 +285,7 @@ EOF
EOF
],
'Style deduplication disabled' => [
- [ 'deduplicateStyles' => false ], [], $dedupText, $dedupText
+ [ 'deduplicateStyles' => false ], $dedupText, $dedupText
],
];
// phpcs:enable