private $mTarget = null;
/**
- * @var bool Whether parser output should contain table of contents
+ * @var bool Whether parser output contains a table of contents
*/
- private $mEnableTOC = true;
+ private $mEnableTOC = false;
/**
* @var bool Whether parser output should contain section edit links
$outputPage = $this;
Hooks::run( 'LanguageLinks', [ $this->getTitle(), &$this->mLanguageLinks, &$linkFlags ] );
Hooks::run( 'OutputPageParserOutput', [ &$outputPage, $parserOutput ] );
+
+ // This check must be after 'OutputPageParserOutput' runs in addParserOutputMetadata
+ // 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() ) {
+ $this->mEnableTOC = true;
+ }
}
/**
*/
function addParserOutput( $parserOutput ) {
$this->addParserOutputMetadata( $parserOutput );
- $parserOutput->setTOCEnabled( $this->mEnableTOC );
// Touch section edit links only if not previously disabled
if ( $parserOutput->getEditSectionTokens() ) {
}
$sk = $this->getSkin();
- // add skin specific modules
- $modules = $sk->getDefaultModules();
-
- // Enforce various default modules for all pages and all skins
- $coreModules = [
- // Keep this list as small as possible
- 'site',
- 'mediawiki.page.startup',
- 'mediawiki.user',
- ];
-
- // Support for high-density display images if enabled
- if ( $config->get( 'ResponsiveImages' ) ) {
- $coreModules[] = 'mediawiki.hidpi';
- }
-
- $this->addModules( $coreModules );
- foreach ( $modules as $group ) {
+ foreach ( $sk->getDefaultModules() as $group ) {
$this->addModules( $group );
}
+
MWDebug::addModules( $this );
// Avoid PHP 7.1 warning of passing $this by reference
}
/**
- * Enables/disables TOC, doesn't override __NOTOC__
- * @param bool $flag
- * @since 1.22
- */
- public function enableTOC( $flag = true ) {
- $this->mEnableTOC = $flag;
- }
-
- /**
+ * Whether the output has a table of contents
* @return bool
* @since 1.22
*/
* @file
*/
+use MediaWiki\MediaWikiServices;
+
/**
* @ingroup API
*/
$result_array['title'] = $titleObj->getPrefixedText();
$result_array['pageid'] = $pageid ?: $pageObj->getId();
+ if ( $params['disabletoc'] ) {
+ $p_result->setTOCEnabled( false );
+ }
+
+ if ( isset( $params['useskin'] ) ) {
+ $factory = MediaWikiServices::getInstance()->getSkinFactory();
+ $skin = $factory->makeSkin( Skin::normalizeKey( $params['useskin'] ) );
+ } else {
+ $skin = null;
+ }
+
+ $outputPage = null;
+ if ( $skin || isset( $prop['headhtml'] ) ) {
+ // Enabling the skin via 'useskin' or 'headhtml' gets OutputPage and
+ // Skin involved, which (among others) applies these hooks:
+ // - ParserOutputHooks
+ // - Hook: LanguageLinks
+ // - Hook: OutputPageParserOutput
+ $context = new DerivativeContext( $this->getContext() );
+ $context->setTitle( $titleObj );
+ $context->setWikiPage( $pageObj );
+
+ if ( $skin ) {
+ // Use the skin specified by 'useskin'
+ $context->setSkin( $skin );
+ // Context clones the skin, refetch to stay in sync. (T166022)
+ $skin = $context->getSkin();
+ }
+
+ $outputPage = new OutputPage( $context );
+ $outputPage->addParserOutputMetadata( $p_result );
+ $context->setOutput( $outputPage );
+
+ if ( $skin ) {
+ // Based on OutputPage::output()
+ foreach ( $skin->getDefaultModules() as $group ) {
+ $outputPage->addModules( $group );
+ }
+ }
+ }
+
if ( !is_null( $oldid ) ) {
$result_array['revid'] = intval( $oldid );
}
$result_array['redirects'] = $redirValues;
}
- if ( $params['disabletoc'] ) {
- $p_result->setTOCEnabled( false );
- }
-
if ( isset( $prop['text'] ) ) {
$result_array['text'] = $p_result->getText();
$result_array[ApiResult::META_BC_SUBELEMENTS][] = 'text';
}
if ( isset( $prop['langlinks'] ) ) {
- $langlinks = $p_result->getLanguageLinks();
-
- if ( $params['effectivelanglinks'] ) {
- // Link flags are ignored for now, but may in the future be
- // included in the result.
- $linkFlags = [];
- Hooks::run( 'LanguageLinks', [ $titleObj, &$langlinks, &$linkFlags ] );
+ if ( $skin ) {
+ $langlinks = $outputPage->getLanguageLinks();
+ } else {
+ $langlinks = $p_result->getLanguageLinks();
+ // The deprecated 'effectivelanglinks' option depredates OutputPage
+ // support via 'useskin'. If not already applied, then run just this
+ // one hook of OutputPage::addParserOutputMetadata here.
+ if ( $params['effectivelanglinks'] ) {
+ $linkFlags = [];
+ Hooks::run( 'LanguageLinks', [ $titleObj, &$langlinks, &$linkFlags ] );
+ }
}
- } else {
- $langlinks = false;
- }
- if ( isset( $prop['langlinks'] ) ) {
$result_array['langlinks'] = $this->formatLangLinks( $langlinks );
}
if ( isset( $prop['categories'] ) ) {
}
if ( isset( $prop['headitems'] ) ) {
- $result_array['headitems'] = $this->formatHeadItems( $p_result->getHeadItems() );
+ if ( $skin ) {
+ $result_array['headitems'] = $this->formatHeadItems( $outputPage->getHeadItemsArray() );
+ } else {
+ $result_array['headitems'] = $this->formatHeadItems( $p_result->getHeadItems() );
+ }
$this->addDeprecation( 'apiwarn-deprecation-parse-headitems', 'action=parse&prop=headitems' );
}
if ( isset( $prop['headhtml'] ) ) {
- $context = new DerivativeContext( $this->getContext() );
- $context->setTitle( $titleObj );
- $context->setWikiPage( $pageObj );
-
- // We need an OutputPage tied to $context, not to the
- // RequestContext at the root of the stack.
- $output = new OutputPage( $context );
- $output->addParserOutputMetadata( $p_result );
-
- $result_array['headhtml'] = $output->headElement( $context->getSkin() );
+ $result_array['headhtml'] = $outputPage->headElement( $context->getSkin() );
$result_array[ApiResult::META_BC_SUBELEMENTS][] = 'headhtml';
}
if ( isset( $prop['modules'] ) ) {
- $result_array['modules'] = array_values( array_unique( $p_result->getModules() ) );
- $result_array['modulescripts'] = array_values( array_unique( $p_result->getModuleScripts() ) );
- $result_array['modulestyles'] = array_values( array_unique( $p_result->getModuleStyles() ) );
+ if ( $skin ) {
+ $result_array['modules'] = $outputPage->getModules();
+ $result_array['modulescripts'] = $outputPage->getModuleScripts();
+ $result_array['modulestyles'] = $outputPage->getModuleStyles();
+ } else {
+ $result_array['modules'] = array_values( array_unique( $p_result->getModules() ) );
+ $result_array['modulescripts'] = array_values( array_unique( $p_result->getModuleScripts() ) );
+ $result_array['modulestyles'] = array_values( array_unique( $p_result->getModuleStyles() ) );
+ }
}
if ( isset( $prop['jsconfigvars'] ) ) {
- $result_array['jsconfigvars'] =
- ApiResult::addMetadataToResultVars( $p_result->getJsConfigVars() );
+ $jsconfigvars = $skin ? $outputPage->getJsConfigVars() : $p_result->getJsConfigVars();
+ $result_array['jsconfigvars'] = ApiResult::addMetadataToResultVars( $jsconfigvars );
}
if ( isset( $prop['encodedjsconfigvars'] ) ) {
+ $jsconfigvars = $skin ? $outputPage->getJsConfigVars() : $p_result->getJsConfigVars();
$result_array['encodedjsconfigvars'] = FormatJson::encode(
- $p_result->getJsConfigVars(), false, FormatJson::ALL_OK
+ $jsconfigvars,
+ false,
+ FormatJson::ALL_OK
);
$result_array[ApiResult::META_SUBELEMENTS][] = 'encodedjsconfigvars';
}
}
if ( isset( $prop['indicators'] ) ) {
- $result_array['indicators'] = (array)$p_result->getIndicators();
+ if ( $skin ) {
+ $result_array['indicators'] = (array)$outputPage->getIndicators();
+ } else {
+ $result_array['indicators'] = (array)$p_result->getIndicators();
+ }
ApiResult::setArrayType( $result_array['indicators'], 'BCkvp', 'name' );
}
'wrapoutputclass' => 'mw-parser-output',
'pst' => false,
'onlypst' => false,
- 'effectivelanglinks' => false,
+ 'effectivelanglinks' => [
+ ApiBase::PARAM_DFLT => false,
+ ApiBase::PARAM_DEPRECATED => true,
+ ],
'section' => null,
'sectiontitle' => [
ApiBase::PARAM_TYPE => 'string',
'preview' => false,
'sectionpreview' => false,
'disabletoc' => false,
+ 'useskin' => [
+ ApiBase::PARAM_TYPE => array_keys( Skin::getAllowedSkins() ),
+ ],
'contentformat' => [
ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(),
],