From 5ad73b8aab3020ed25050cb7d4431ef459d5a723 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Thu, 25 May 2017 11:18:48 -0400 Subject: [PATCH] ApiParse: Use existing OutputPage for prop=categorieshtml Follows up Iaa85ac49. This also ensures that the Skin correctly refers back to the constructed OutputPage even when 'useskin' isn't specified. Change-Id: I983e907c05acd753733e88904953f355e26f393d --- includes/api/ApiParse.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index d09978eadf..91e49abc9c 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -292,12 +292,14 @@ class ApiParse extends ApiBase { } $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: + if ( $skin || isset( $prop['headhtml'] ) || isset( $prop['categorieshtml'] ) ) { + // Enabling the skin via 'useskin', 'headhtml', or 'categorieshtml' + // gets OutputPage and Skin involved, which (among others) applies + // these hooks: // - ParserOutputHooks // - Hook: LanguageLinks // - Hook: OutputPageParserOutput + // - Hook: OutputPageMakeCategoryLinks $context = new DerivativeContext( $this->getContext() ); $context->setTitle( $titleObj ); $context->setWikiPage( $pageObj ); @@ -307,6 +309,11 @@ class ApiParse extends ApiBase { $context->setSkin( $skin ); // Context clones the skin, refetch to stay in sync. (T166022) $skin = $context->getSkin(); + } else { + // Make sure the context's skin refers to the context. Without this, + // $outputPage->getSkin()->getOutput() !== $outputPage which + // confuses some of the output. + $context->setSkin( $context->getSkin() ); } $outputPage = new OutputPage( $context ); @@ -361,7 +368,7 @@ class ApiParse extends ApiBase { $result_array['categories'] = $this->formatCategoryLinks( $p_result->getCategories() ); } if ( isset( $prop['categorieshtml'] ) ) { - $result_array['categorieshtml'] = $this->categoriesHtml( $p_result->getCategories() ); + $result_array['categorieshtml'] = $outputPage->getSkin()->getCategories(); $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'categorieshtml'; } if ( isset( $prop['links'] ) ) { @@ -709,13 +716,6 @@ class ApiParse extends ApiBase { return $result; } - private function categoriesHtml( $categories ) { - $context = $this->getContext(); - $context->getOutput()->addCategoryLinks( $categories ); - - return $context->getSkin()->getCategories(); - } - private function formatLinks( $links ) { $result = []; foreach ( $links as $ns => $nslinks ) { -- 2.20.1