From f19050377c7b88d4080b10ab51daaf1631b9e1b0 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Thu, 21 Jul 2016 23:52:29 +0100 Subject: [PATCH] ApiParse: Deprecate prop=headitems This code has been rotting for a while. It is important missing stylesheets and critical inline scripts. Consuming these items is quite risky. One can't safely use it to update an existing document (as some parts are duplicative or conflicting). One also can't use it to build a new document as several critical pieces are missing. * Since ResourceLoader was introduced in 2011, buildCssLinksArray() doesn't have any stylesheets. For most pages, this will produce an empty array for headitems. Mark it as deprecated since in favour of 'prop=headhtml' or 'prop=modules'. Change-Id: I6084e4454e245f59bf3c82d6db830977725f71e5 --- includes/api/ApiParse.php | 38 +++++++++++--------------------------- includes/api/i18n/en.json | 6 +++--- 2 files changed, 14 insertions(+), 30 deletions(-) diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index d53dbb485f..35fad4a474 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -345,7 +345,15 @@ class ApiParse extends ApiBase { $titleObj->getPrefixedText(); } - if ( isset( $prop['headitems'] ) || isset( $prop['headhtml'] ) ) { + if ( isset( $prop['headitems'] ) ) { + $result_array['headitems'] = $this->formatHeadItems( $p_result->getHeadItems() ); + $this->logFeatureUsage( 'action=parse&prop=headitems' ); + $this->setWarning( 'headitems is deprecated since MediaWiki 1.28. ' + . 'Use prop=headhtml when creating new HTML documents, or ' + . 'prop=modules|jsconfigvars when updating a document client-side.' ); + } + + if ( isset( $prop['headhtml'] ) ) { $context = new DerivativeContext( $this->getContext() ); $context->setTitle( $titleObj ); $context->setWikiPage( $pageObj ); @@ -355,20 +363,8 @@ class ApiParse extends ApiBase { $output = new OutputPage( $context ); $output->addParserOutputMetadata( $p_result ); - if ( isset( $prop['headitems'] ) ) { - $headItems = $this->formatHeadItems( $p_result->getHeadItems() ); - - $css = $this->formatCss( $output->buildCssLinksArray() ); - - $scripts = [ $output->getHeadScripts() ]; - - $result_array['headitems'] = array_merge( $headItems, $css, $scripts ); - } - - if ( isset( $prop['headhtml'] ) ) { - $result_array['headhtml'] = $output->headElement( $context->getSkin() ); - $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'headhtml'; - } + $result_array['headhtml'] = $output->headElement( $context->getSkin() ); + $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'headhtml'; } if ( isset( $prop['modules'] ) ) { @@ -705,18 +701,6 @@ class ApiParse extends ApiBase { return $result; } - private function formatCss( $css ) { - $result = []; - foreach ( $css as $file => $link ) { - $entry = []; - $entry['file'] = $file; - ApiResult::setContentValue( $entry, 'link', $link ); - $result[] = $entry; - } - - return $result; - } - private function formatLimitReportData( $limitReportData ) { $result = []; diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json index a8f02787ad..666b51f427 100644 --- a/includes/api/i18n/en.json +++ b/includes/api/i18n/en.json @@ -325,10 +325,10 @@ "apihelp-parse-paramvalue-prop-sections": "Gives the sections in the parsed wikitext.", "apihelp-parse-paramvalue-prop-revid": "Adds the revision ID of the parsed page.", "apihelp-parse-paramvalue-prop-displaytitle": "Adds the title of the parsed wikitext.", - "apihelp-parse-paramvalue-prop-headitems": "Gives items to put in the <head> of the page.", + "apihelp-parse-paramvalue-prop-headitems": "Deprecated. Gives items to put in the <head> of the page.", "apihelp-parse-paramvalue-prop-headhtml": "Gives parsed <head> of the page.", - "apihelp-parse-paramvalue-prop-modules": "Gives the ResourceLoader modules used on the page. Either jsconfigvars or encodedjsconfigvars must be requested jointly with modules.", - "apihelp-parse-paramvalue-prop-jsconfigvars": "Gives the JavaScript configuration variables specific to the page.", + "apihelp-parse-paramvalue-prop-modules": "Gives the ResourceLoader modules used on the page. To load, use mw.loader.using(). Either jsconfigvars or encodedjsconfigvars must be requested jointly with modules.", + "apihelp-parse-paramvalue-prop-jsconfigvars": "Gives the JavaScript configuration variables specific to the page. To apply, use mw.config.set().", "apihelp-parse-paramvalue-prop-encodedjsconfigvars": "Gives the JavaScript configuration variables specific to the page as a JSON string.", "apihelp-parse-paramvalue-prop-indicators": "Gives the HTML of page status indicators used on the page.", "apihelp-parse-paramvalue-prop-iwlinks": "Gives interwiki links in the parsed wikitext.", -- 2.20.1