ApiParse: Deprecate prop=headitems
authorTimo Tijhof <krinklemail@gmail.com>
Thu, 21 Jul 2016 22:52:29 +0000 (23:52 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Thu, 28 Jul 2016 17:23:26 +0000 (18:23 +0100)
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
includes/api/i18n/en.json

index d53dbb4..35fad4a 100644 (file)
@@ -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 = [];
 
index a8f0278..666b51f 100644 (file)
        "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 <code>&lt;head&gt;</code> of the page.",
+       "apihelp-parse-paramvalue-prop-headitems": "<span class=\"apihelp-deprecated\">Deprecated.</span> Gives items to put in the <code>&lt;head&gt;</code> of the page.",
        "apihelp-parse-paramvalue-prop-headhtml": "Gives parsed <code>&lt;head&gt;</code> of the page.",
-       "apihelp-parse-paramvalue-prop-modules": "Gives the ResourceLoader modules used on the page. Either <kbd>jsconfigvars</kbd> or <kbd>encodedjsconfigvars</kbd> must be requested jointly with <kbd>modules</kbd>.",
-       "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 <code>mw.loader.using()</code>. Either <kbd>jsconfigvars</kbd> or <kbd>encodedjsconfigvars</kbd> must be requested jointly with <kbd>modules</kbd>.",
+       "apihelp-parse-paramvalue-prop-jsconfigvars": "Gives the JavaScript configuration variables specific to the page. To apply, use <code>mw.config.set()</code>.",
        "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.",