$parserOutput->setEditSectionTokens( false ); // no section edit links
return [
'parserOutput' => $parserOutput,
- 'html' => $parserOutput->getText() ];
+ 'html' => $parserOutput->getText( [
+ 'enableSectionEditLinks' => false
+ ] )
+ ];
}
/**
$this->getLanguage()
);
- return $out instanceof ParserOutput ? $out->getText() : $out;
+ return $out instanceof ParserOutput
+ ? $out->getText( [ 'enableSectionEditLinks' => false ] )
+ : $out;
}
/**
$popts->setTidy( $oldTidy );
- $this->addParserOutput( $parserOutput );
+ $this->addParserOutput( $parserOutput, [
+ 'enableSectionEditLinks' => false,
+ ] );
}
/**
*
* @since 1.24
* @param ParserOutput $parserOutput
+ * @param array $poOptions Options to ParserOutput::getText()
*/
- public function addParserOutputContent( $parserOutput ) {
- $this->addParserOutputText( $parserOutput );
+ public function addParserOutputContent( $parserOutput, $poOptions = [] ) {
+ $this->addParserOutputText( $parserOutput, $poOptions );
$this->addModules( $parserOutput->getModules() );
$this->addModuleScripts( $parserOutput->getModuleScripts() );
*
* @since 1.24
* @param ParserOutput $parserOutput
+ * @param array $poOptions Options to ParserOutput::getText()
*/
- public function addParserOutputText( $parserOutput ) {
- $text = $parserOutput->getText();
+ public function addParserOutputText( $parserOutput, $poOptions = [] ) {
+ $text = $parserOutput->getText( $poOptions );
// Avoid PHP 7.1 warning of passing $this by reference
$outputPage = $this;
Hooks::runWithoutAbort( 'OutputPageBeforeHTML', [ &$outputPage, &$text ] );
* Add everything from a ParserOutput object.
*
* @param ParserOutput $parserOutput
+ * @param array $poOptions Options to ParserOutput::getText()
*/
- function addParserOutput( $parserOutput ) {
+ 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 );
+ $this->addParserOutputText( $parserOutput, $poOptions );
}
/**
$popts->setTargetLanguage( $oldLang );
}
- return $parserOutput->getText();
+ return $parserOutput->getText( [
+ 'enableSectionEditLinks' => false,
+ ] );
}
/**
* Enables/disables section edit links, doesn't override __NOEDITSECTION__
* @param bool $flag
* @since 1.23
+ * @deprecated since 1.31, use $poOptions to addParserOutput() instead.
*/
public function enableSectionEditLinks( $flag = true ) {
$this->mEnableSectionEditLinks = $flag;
/**
* @return bool
* @since 1.23
+ * @deprecated since 1.31, use $poOptions to addParserOutput() instead.
*/
public function sectionEditLinksEnabled() {
return $this->mEnableSectionEditLinks;
$lang = $this->languageFromParam( $lang );
$text = $this->getWikiText( $shortContext, $longContext, $lang );
$out = MessageCache::singleton()->parse( $text, null, true, true, $lang );
- return $out instanceof ParserOutput ? $out->getText() : $out;
+ return $out instanceof ParserOutput
+ ? $out->getText( [ 'enableSectionEditLinks' => false ] )
+ : $out;
}
/**
$result_array['textsuppressed'] = true;
}
- if ( $params['disabletoc'] ) {
- $p_result->setTOCEnabled( false );
- }
-
if ( isset( $params['useskin'] ) ) {
$factory = MediaWikiServices::getInstance()->getSkinFactory();
$skin = $factory->makeSkin( Skin::normalizeKey( $params['useskin'] ) );
}
if ( isset( $prop['text'] ) ) {
- $result_array['text'] = $p_result->getText();
+ $result_array['text'] = $p_result->getText( [
+ 'allowTOC' => !$params['disabletoc'],
+ 'enableSectionEditLinks' => !$params['disableeditsection'],
+ ] );
$result_array[ApiResult::META_BC_SUBELEMENTS][] = 'text';
}
if ( !is_null( $this->allText ) ) {
return;
}
- $this->parserOutput->setEditSectionTokens( false );
- $this->parserOutput->setTOCEnabled( false );
- $text = $this->parserOutput->getText();
+ $text = $this->parserOutput->getText( [
+ 'enableSectionEditTokens' => false,
+ 'allowTOC' => false,
+ ] );
if ( strlen( $text ) == 0 ) {
$this->allText = "";
// empty text - nothing to seek here
if ( Hooks::run( 'DifferenceEngineRenderRevisionAddParserOutput',
[ $this, $out, $parserOutput, $wikiPage ] )
) {
- $out->addParserOutput( $parserOutput );
+ $out->addParserOutput( $parserOutput, [
+ 'enableSectionEditLinks' => $this->mNewRev->isCurrent()
+ && $this->mNewRev->getTitle()->quickUserCan( 'edit', $this->getUser() ),
+ ] );
}
}
}
try {
$out = $wgParser->parse( $text, $this->parserTitle, $this->parserOptions, $lineStart );
- $html = $out->getText();
+ $html = $out->getText( [
+ 'enableSectionEditLinks' => false,
+ ] );
} catch ( MediaWiki\Services\ServiceDisabledException $e ) {
$html = '<!--DB access attempted during parse--> ' . htmlspecialchars( $text );
/** @var ParserOutput */
public $mParserOutput;
+ /**
+ * @var bool Whether render() was called. With the way subclasses work
+ * here, there doesn't seem to be any other way to stop calling
+ * OutputPage::enableSectionEditLinks() and still have it work as it did before.
+ */
+ private $disableSectionEditForRender = false;
+
/**
* Constructor and clear the article
* @param Title $title Reference to a Title object.
$parserCache = MediaWikiServices::getInstance()->getParserCache();
$parserOptions = $this->getParserOptions();
+ $poOptions = [];
# Render printable version, use printable version cache
if ( $outputPage->isPrintable() ) {
$parserOptions->setIsPrintable( true );
$parserOptions->setEditSection( false );
- } elseif ( !$this->isCurrent() || !$this->getTitle()->quickUserCan( 'edit', $user ) ) {
+ $poOptions['enableSectionEditLinks'] = false;
+ } elseif ( $this->disableSectionEditForRender
+ || !$this->isCurrent() || !$this->getTitle()->quickUserCan( 'edit', $user )
+ ) {
$parserOptions->setEditSection( false );
+ $poOptions['enableSectionEditLinks'] = false;
}
# Try client and file cache
} else {
wfDebug( __METHOD__ . ": showing parser cache contents\n" );
}
- $outputPage->addParserOutput( $this->mParserOutput );
+ $outputPage->addParserOutput( $this->mParserOutput, $poOptions );
# Ensure that UI elements requiring revision ID have
# the correct version information.
$outputPage->setRevisionId( $this->mPage->getLatest() );
}
$this->mParserOutput = $poolArticleView->getParserOutput();
- $outputPage->addParserOutput( $this->mParserOutput );
+ $outputPage->addParserOutput( $this->mParserOutput, $poOptions );
if ( $content->getRedirectTarget() ) {
$outputPage->addSubtitle( "<span id=\"redirectsub\">" .
$this->getContext()->msg( 'redirectpagesub' )->parse() . "</span>" );
$this->getContext()->getRequest()->response()->header( 'X-Robots-Tag: noindex' );
$this->getContext()->getOutput()->setArticleBodyOnly( true );
$this->getContext()->getOutput()->enableSectionEditLinks( false );
+ $this->disableSectionEditForRender = true;
$this->view();
}
* @ingroup Parser
*/
class ParserOutput extends CacheTime {
+ /**
+ * Feature flag to indicate to extensions that MediaWiki core supports and
+ * uses getText() stateless transforms.
+ */
+ const SUPPORTS_STATELESS_TRANSFORMS = 1;
+
/**
* @var string $mText The output text
*/
* @deprecated since 1.31 Use getText() options.
* @var bool $mEditSectionTokens prefix/suffix markers if edit sections were output as tokens.
*/
- public $mEditSectionTokens = false;
+ public $mEditSectionTokens = true;
/**
* @var array $mProperties Name/value pairs to be cached in the DB.
// @todo Warn if !array_key_exists( 'enableSectionEditLinks', $options )
// && !$this->mEditSectionTokens
- // Note that while $this->mEditSectionTokens defaults to false,
+ // 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.
/*interface*/false,
$wgContLang
);
- $content = $parserOutput->getText();
+ $content = $parserOutput->getText( [
+ 'enableSectionEditLinks' => false,
+ ] );
// Add only metadata here (including the language links), text is added below
$this->getOutput()->addParserOutputMetadata( $parserOutput );
$popts->setEditSection( false );
$pout = $content->getParserOutput( $this->mTargetObj, $rev->getId(), $popts, true );
- $out->addParserOutput( $pout );
+ $out->addParserOutput( $pout, [
+ 'enableSectionEditLinks' => false,
+ ] );
}
if ( $isText ) {
$out = $parser->getPreloadText( $test['input'], $title, $options );
} else {
$output = $parser->parse( $test['input'], $title, $options, true, true, 1337 );
- $output->setTOCEnabled( !isset( $opts['notoc'] ) );
- $out = $output->getText();
+ $out = $output->getText( [
+ 'allowTOC' => !isset( $opts['notoc'] )
+ ] );
if ( isset( $opts['tidy'] ) ) {
$out = preg_replace( '/\s+$/', '', $out );
}