API: Rename disablepp and introduce disabletidy
authorTim Starling <tstarling@wikimedia.org>
Mon, 24 Aug 2015 05:05:09 +0000 (15:05 +1000)
committerOri.livneh <ori@wikimedia.org>
Wed, 26 Aug 2015 04:38:34 +0000 (04:38 +0000)
* Rename disablepp to disablelimitreport, since it does not disable the
  preprocessor (which is what PP stands for in "NewPP").
* Introduce new option "disabletidy" for T89331
* Suppress the use of the parser cache when options are specified that
  affect the output but are not in ParserOptions::optionsHash(). This
  was already broken, but the damage was fairly limited since the
  options rarely caused user-visible changes. It would break very badly
  if I use the disabletidy option for what I am intending.

Change-Id: I4b0e55fe34e237a68450f583bf59bab7dd703a29

includes/api/ApiParse.php
includes/api/i18n/en.json
includes/api/i18n/qqq.json

index 1b8f6d9..d67655b 100644 (file)
@@ -169,9 +169,23 @@ class ApiParse extends ApiBase {
 
                                $popts = $this->makeParserOptions( $pageObj, $params );
 
-                               // Potentially cached
-                               $p_result = $this->getParsedContent( $pageObj, $popts, $pageid,
-                                       isset( $prop['wikitext'] ) );
+                               // Don't pollute the parser cache when setting options that aren't
+                               // in ParserOptions::optionsHash()
+                               $suppressCache =
+                                       $params['disablepp'] ||
+                                       $params['disablelimitreport'] ||
+                                       $params['preview'] ||
+                                       $params['sectionpreview'] ||
+                                       $params['disabletidy'];
+
+                               if ( $suppressCache ) {
+                                       $this->content = $this->getContent( $pageObj, $pageid );
+                                       $p_result = $this->content->getParserOutput( $titleObj, null, $popts );
+                               } else {
+                                       // Potentially cached
+                                       $p_result = $this->getParsedContent( $pageObj, $popts, $pageid,
+                                               isset( $prop['wikitext'] ) );
+                               }
                        }
                } else { // Not $oldid, $pageid, $page. Hence based on $text
                        $titleObj = Title::newFromText( $title );
@@ -464,10 +478,13 @@ class ApiParse extends ApiBase {
        protected function makeParserOptions( WikiPage $pageObj, array $params ) {
 
                $popts = $pageObj->makeParserOptions( $this->getContext() );
-               $popts->enableLimitReport( !$params['disablepp'] );
+               $popts->enableLimitReport( !$params['disablepp'] && !$params['disablelimitreport'] );
                $popts->setIsPreview( $params['preview'] || $params['sectionpreview'] );
                $popts->setIsSectionPreview( $params['sectionpreview'] );
                $popts->setEditSection( !$params['disableeditsection'] );
+               if ( $params['disabletidy'] ) {
+                       $popts->setTidy( false );
+               }
 
                return $popts;
        }
@@ -480,14 +497,9 @@ class ApiParse extends ApiBase {
         * @return ParserOutput
         */
        private function getParsedContent( WikiPage $page, $popts, $pageId = null, $getWikitext = false ) {
-               $this->content = $page->getContent( Revision::RAW ); //XXX: really raw?
+               $this->content = $this->getContent( $page, $pageId );
 
                if ( $this->section !== false && $this->content !== null ) {
-                       $this->content = $this->getSectionContent(
-                               $this->content,
-                               !is_null( $pageId ) ? 'page id ' . $pageId : $page->getTitle()->getPrefixedText()
-                       );
-
                        // Not cached (save or load)
                        return $this->content->getParserOutput( $page->getTitle(), null, $popts );
                }
@@ -506,6 +518,27 @@ class ApiParse extends ApiBase {
        }
 
        /**
+        * Get the content for the given page and the requested section.
+        *
+        * @param WikiPage $page
+        * @param int $pageId
+        * @return Content
+        */
+       private function getContent( WikiPage $page, $pageId = null ) {
+               $content = $page->getContent( Revision::RAW ); //XXX: really raw?
+
+               if ( $this->section !== false && $content !== null ) {
+                       $content = $this->getSectionContent(
+                               $content,
+                               !is_null( $pageId ) ? 'page id ' . $pageId : $page->getTitle()->getPrefixedText()
+                       );
+               }
+               return $content;
+       }
+
+       /**
+        * Extract the requested section from the given Content
+        *
         * @param Content $content
         * @param string $what Identifies the content in error messages, e.g. page title.
         * @return Content|bool
@@ -762,8 +795,13 @@ class ApiParse extends ApiBase {
                        'sectiontitle' => array(
                                ApiBase::PARAM_TYPE => 'string',
                        ),
-                       'disablepp' => false,
+                       'disablepp' => array(
+                               ApiBase::PARAM_DFLT => false,
+                               ApiBase::PARAM_DEPRECATED => true,
+                       ),
+                       'disablelimitreport' => false,
                        'disableeditsection' => false,
+                       'disabletidy' => false,
                        'generatexml' => array(
                                ApiBase::PARAM_DFLT => false,
                                ApiBase::PARAM_HELP_MSG => array(
index d3189c6..396f5da 100644 (file)
        "apihelp-parse-paramvalue-prop-iwlinks": "Gives interwiki links in the parsed wikitext.",
        "apihelp-parse-paramvalue-prop-wikitext": "Gives the original wikitext that was parsed.",
        "apihelp-parse-paramvalue-prop-properties": "Gives various properties defined in the parsed wikitext.",
-       "apihelp-parse-paramvalue-prop-limitreportdata": "Gives the limit report in a structured way. Gives no data, when <var>$1disablepp</var> is set.",
-       "apihelp-parse-paramvalue-prop-limitreporthtml": "Gives the HTML version of the limit report. Gives no data, when <var>$1disablepp</var> is set.",
+       "apihelp-parse-paramvalue-prop-limitreportdata": "Gives the limit report in a structured way. Gives no data, when <var>$1disablelimitreport</var> is set.",
+       "apihelp-parse-paramvalue-prop-limitreporthtml": "Gives the HTML version of the limit report. Gives no data, when <var>$1disablelimitreport</var> is set.",
        "apihelp-parse-paramvalue-prop-parsetree": "The XML parse tree of revision content (requires content model <code>$1</code>)",
        "apihelp-parse-param-pst": "Do a pre-save transform on the input before parsing it. Only valid when used with text.",
        "apihelp-parse-param-onlypst": "Do a pre-save transform (PST) on the input, but don't parse it. Returns the same wikitext, after a PST has been applied. Only valid when used with <var>$1text</var>.",
        "apihelp-parse-param-effectivelanglinks": "Includes language links supplied by extensions (for use with <kbd>$1prop=langlinks</kbd>).",
        "apihelp-parse-param-section": "Only retrieve the content of this section number or when <kbd>new</kbd> generate a new section.\n\n<kbd>new</kbd> section is only honored when specifying <var>text</var>.",
        "apihelp-parse-param-sectiontitle": "New section title when <var>section</var> is <kbd>new</kbd>.\n\nUnlike page editing, this does not fall back to <var>summary</var> when omitted or empty.",
-       "apihelp-parse-param-disablepp": "Omit the preprocessor report (\"NewPP limit report\") from the parser output.",
+       "apihelp-parse-param-disablelimitreport": "Omit the limit report (\"NewPP limit report\") from the parser output.",
+       "apihelp-parse-param-disablepp": "Use <var>$1disablelimitreport</var> instead.",
        "apihelp-parse-param-disableeditsection": "Omit edit section links from the parser output.",
+       "apihelp-parse-param-disabletidy": "Do not run HTML cleanup (e.g. tidy) on the parser output.",
        "apihelp-parse-param-generatexml": "Generate XML parse tree (requires content model <code>$1</code>; replaced by <kbd>$2prop=parsetree</kbd>).",
        "apihelp-parse-param-preview": "Parse in preview mode.",
        "apihelp-parse-param-sectionpreview": "Parse in section preview mode (enables preview mode too).",
index 5ac1e0d..ef803f5 100644 (file)
        "apihelp-parse-param-effectivelanglinks": "{{doc-apihelp-param|parse|effectivelanglinks}}",
        "apihelp-parse-param-section": "{{doc-apihelp-param|parse|section}}",
        "apihelp-parse-param-sectiontitle": "{{doc-apihelp-param|parse|sectiontitle}}",
+       "apihelp-parse-param-disablelimitreport": "{{doc-apihelp-param|parse|disablelimitreport}}",
        "apihelp-parse-param-disablepp": "{{doc-apihelp-param|parse|disablepp}}",
        "apihelp-parse-param-disableeditsection": "{{doc-apihelp-param|parse|disableeditsection}}",
+       "apihelp-parse-param-disabletidy": "{{doc-apihelp-param|parse|disabletidy}}",
        "apihelp-parse-param-generatexml": "{{doc-apihelp-param|parse|generatexml|params=* $1 - Value of the constant CONTENT_MODEL_WIKITEXT|paramstart=2}}",
        "apihelp-parse-param-preview": "{{doc-apihelp-param|parse|preview}}",
        "apihelp-parse-param-sectionpreview": "{{doc-apihelp-param|parse|sectionpreview}}",