$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( [
*/
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 <link> element with rel=license
*/
// 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 ) );
// 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 ) {
}
$this->mParserOptions = ParserOptions::newFromContext( $this->getContext() );
- $this->mParserOptions->setEditSection( false );
$this->mParserOptions->setAllowUnsafeRawHtml( false );
}
// 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;
}
}
*/
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 );
}
* @deprecated since 1.31, use $poOptions to addParserOutput() instead.
*/
public function enableSectionEditLinks( $flag = true ) {
- $this->mEnableSectionEditLinks = $flag;
+ wfDeprecated( __METHOD__, '1.31' );
}
/**
* @deprecated since 1.31, use $poOptions to addParserOutput() instead.
*/
public function sectionEditLinksEnabled() {
- return $this->mEnableSectionEditLinks;
+ wfDeprecated( __METHOD__, '1.31' );
+ return true;
}
/**
$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 );
}
// 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 <html> parser tag when parsing messages.
*/
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;
$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' ) );
}
# 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;
}
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();
}
# 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]
* $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++;
}
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;
*/
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
* @return bool
*/
public function getEditSection() {
- return $this->mEditSection;
+ wfDeprecated( __METHOD__, '1.31' );
+ return true;
}
/**
* @return bool Old value
*/
public function setEditSection( $x ) {
- return wfSetVar( $this->mEditSection, $x );
+ wfDeprecated( __METHOD__, '1.31' );
+ return true;
}
/**
$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
*/
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.
*/
*/
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.
*/
* @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,
];
* @deprecated since 1.31 Use getText() options.
*/
public function getEditSectionTokens() {
- return $this->mEditSectionTokens;
+ wfDeprecated( __METHOD__, '1.31' );
+ return true;
}
public function &getLinks() {
* @deprecated since 1.31 Use getText() options.
*/
public function getTOCEnabled() {
- return $this->mTOCEnabled;
+ wfDeprecated( __METHOD__, '1.31' );
+ return true;
}
public function getEnableOOUI() {
* @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 ) {
* @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 ) {
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, [
$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
<?php
-use Wikimedia\TestingAccessWrapper;
-
/**
* @group Database
* ^--- trigger DB shadowing because we are using Title magic
* @covers ParserOutput::getText
* @dataProvider provideGetText
* @param array $options Options to getText()
- * @param array $poState ParserOptions state fields to set
* @param string $text Parser text
* @param string $expect Expected output
*/
- public function testGetText( $options, $poState, $text, $expect ) {
+ public function testGetText( $options, $text, $expect ) {
$this->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 );
}
EOF;
return [
- 'No stateless options, default state' => [
- [], [], $text, <<<EOF
-<div class="mw-parser-output"><p>Test document.
-</p>
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
-<ul>
-<li class="toclevel-1 tocsection-1"><a href="#Section_1"><span class="tocnumber">1</span> <span class="toctext">Section 1</span></a></li>
-<li class="toclevel-1 tocsection-2"><a href="#Section_2"><span class="tocnumber">2</span> <span class="toctext">Section 2</span></a>
-<ul>
-<li class="toclevel-2 tocsection-3"><a href="#Section_2.1"><span class="tocnumber">2.1</span> <span class="toctext">Section 2.1</span></a></li>
-</ul>
-</li>
-<li class="toclevel-1 tocsection-4"><a href="#Section_3"><span class="tocnumber">3</span> <span class="toctext">Section 3</span></a></li>
-</ul>
-</div>
-
-<h2><span class="mw-headline" id="Section_1">Section 1</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Test_Page&action=edit&section=1" title="Edit section: Section 1">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
-<p>One
-</p>
-<h2><span class="mw-headline" id="Section_2">Section 2</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Test_Page&action=edit&section=2" title="Edit section: Section 2">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
-<p>Two
-</p>
-<h3><span class="mw-headline" id="Section_2.1">Section 2.1</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Test_Page&action=edit&section=3" title="Edit section: Section 2.1">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
-<p>Two point one
-</p>
-<h2><span class="mw-headline" id="Section_3">Section 3</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Test_Page&action=edit&section=4" title="Edit section: Section 3">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
-<p>Three
-</p></div>
-EOF
- ],
- 'No stateless options, TOC statefully disabled' => [
- [], [ 'mTOCEnabled' => false ], $text, <<<EOF
-<div class="mw-parser-output"><p>Test document.
-</p>
-
-<h2><span class="mw-headline" id="Section_1">Section 1</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Test_Page&action=edit&section=1" title="Edit section: Section 1">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
-<p>One
-</p>
-<h2><span class="mw-headline" id="Section_2">Section 2</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Test_Page&action=edit&section=2" title="Edit section: Section 2">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
-<p>Two
-</p>
-<h3><span class="mw-headline" id="Section_2.1">Section 2.1</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Test_Page&action=edit&section=3" title="Edit section: Section 2.1">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
-<p>Two point one
-</p>
-<h2><span class="mw-headline" id="Section_3">Section 3</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Test_Page&action=edit&section=4" title="Edit section: Section 3">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
-<p>Three
-</p></div>
-EOF
- ],
- 'No stateless options, section edits statefully disabled' => [
- [], [ 'mEditSectionTokens' => false ], $text, <<<EOF
-<div class="mw-parser-output"><p>Test document.
-</p>
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
-<ul>
-<li class="toclevel-1 tocsection-1"><a href="#Section_1"><span class="tocnumber">1</span> <span class="toctext">Section 1</span></a></li>
-<li class="toclevel-1 tocsection-2"><a href="#Section_2"><span class="tocnumber">2</span> <span class="toctext">Section 2</span></a>
-<ul>
-<li class="toclevel-2 tocsection-3"><a href="#Section_2.1"><span class="tocnumber">2.1</span> <span class="toctext">Section 2.1</span></a></li>
-</ul>
-</li>
-<li class="toclevel-1 tocsection-4"><a href="#Section_3"><span class="tocnumber">3</span> <span class="toctext">Section 3</span></a></li>
-</ul>
-</div>
-
-<h2><span class="mw-headline" id="Section_1">Section 1</span></h2>
-<p>One
-</p>
-<h2><span class="mw-headline" id="Section_2">Section 2</span></h2>
-<p>Two
-</p>
-<h3><span class="mw-headline" id="Section_2.1">Section 2.1</span></h3>
-<p>Two point one
-</p>
-<h2><span class="mw-headline" id="Section_3">Section 3</span></h2>
-<p>Three
-</p></div>
-EOF
- ],
- 'Stateless options override stateful settings' => [
- [ 'allowTOC' => true, 'enableSectionEditLinks' => true ],
- [ 'mTOCEnabled' => false, 'mEditSectionTokens' => false ],
- $text, <<<EOF
+ 'No options' => [
+ [], $text, <<<EOF
<div class="mw-parser-output"><p>Test document.
</p>
<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
</p></div>
EOF
],
- 'Statelessly disable section edit links' => [
- [ 'enableSectionEditLinks' => false ], [], $text, <<<EOF
+ 'Disable section edit links' => [
+ [ 'enableSectionEditLinks' => false ], $text, <<<EOF
<div class="mw-parser-output"><p>Test document.
</p>
<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
</p></div>
EOF
],
- 'Statelessly disable TOC' => [
- [ 'allowTOC' => false ], [], $text, <<<EOF
+ 'Disable TOC' => [
+ [ 'allowTOC' => false ], $text, <<<EOF
<div class="mw-parser-output"><p>Test document.
</p>
</p></div>
EOF
],
- 'Statelessly unwrap text' => [
- [ 'unwrap' => true ], [], $text, <<<EOF
+ 'Unwrap text' => [
+ [ 'unwrap' => true ], $text, <<<EOF
<p>Test document.
</p>
<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
EOF
],
'Unwrap without a mw-parser-output wrapper' => [
- [ 'unwrap' => true ], [], '<div class="foobar">Content</div>', '<div class="foobar">Content</div>'
+ [ 'unwrap' => true ], '<div class="foobar">Content</div>', '<div class="foobar">Content</div>'
],
'Unwrap with extra comment at end' => [
- [ 'unwrap' => true ], [], '<div class="mw-parser-output"><p>Test document.</p></div>
+ [ 'unwrap' => true ], '<div class="mw-parser-output"><p>Test document.</p></div>
<!-- Saved in parser cache... -->', '<p>Test document.</p>
<!-- Saved in parser cache... -->'
],
'Style deduplication' => [
- [], [], $dedupText, <<<EOF
+ [], $dedupText, <<<EOF
<p>This is a test document.</p>
<style data-mw-deduplicate="duplicate1">.Duplicate1 {}</style>
<link rel="mw-deduplicated-inline-style" href="mw-data:duplicate1"/>
EOF
],
'Style deduplication disabled' => [
- [ 'deduplicateStyles' => false ], [], $dedupText, $dedupText
+ [ 'deduplicateStyles' => false ], $dedupText, $dedupText
],
];
// phpcs:enable