+ 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 );
+ }
+