API: Fix action=parse without any page or title or text
authorBrad Jorsch <bjorsch@wikimedia.org>
Fri, 10 May 2013 15:59:11 +0000 (11:59 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Fri, 14 Jun 2013 00:58:27 +0000 (20:58 -0400)
action=parse was raising an error about missing 'text' with 'title' even
when 'title' wasn't actually passed, due to a fix for bug 33865. But
this broke using action=parse to parse an edit summary without also
giving it wikitext to parse.

Instead, let's give the client a warning (unless it seems clear they
know what they are doing) and assume the empty string for 'text'.

Also, while we're editing the file, add some more examples as also
requested in bug 48319.

Bug: 48319
Change-Id: I03c1fbcb0bd31dea8bd84e164104f7ced0ace449

RELEASE-NOTES-1.22
includes/api/ApiParse.php

index 52ca63f..1b434d9 100644 (file)
@@ -146,6 +146,10 @@ production.
 * (bug 14176) System messages that are empty were previously incorrectly treated
   as non-existent, causing a fallback to the default. This stopped users from
   overriding system messages to make them blank.
+* (bug 48319) action=parse no longer returns an error if passed none of 'oldid',
+  'pageid', 'page', 'title', and 'text' (e.g. if only passed 'summary'). A
+  warning will instead be issued if 'title' is non-default, unless no props are
+  requested.
 
 === API changes in 1.22 ===
 * (bug 46626) xmldoublequote parameter was removed. Because of a bug, the
index 58b46a2..ac6913e 100644 (file)
@@ -171,7 +171,14 @@ class ApiParse extends ApiBase {
                        $popts = $this->makeParserOptions( $pageObj, $params );
 
                        if ( is_null( $text ) ) {
-                               $this->dieUsage( 'The text parameter should be passed with the title parameter. Should you be using the "page" parameter instead?', 'params' );
+                               if ( $title !== 'API' && ( $prop || $params['generatexml'] ) ) {
+                                       $this->setWarning(
+                                               "'title' used without 'text', and parsed page properties were requested " .
+                                               "(did you mean to use 'page' instead of 'title'?)"
+                                       );
+                               }
+                               // Prevent warning from ContentHandler::makeContent()
+                               $text = '';
                        }
 
                        try {
@@ -685,7 +692,6 @@ class ApiParse extends ApiBase {
        public function getPossibleErrors() {
                return array_merge( parent::getPossibleErrors(), array(
                        array( 'code' => 'params', 'info' => 'The page parameter cannot be used together with the text and title parameters' ),
-                       array( 'code' => 'params', 'info' => 'The text parameter should be passed with the title parameter. Should you be using the "page" parameter instead?' ),
                        array( 'code' => 'missingrev', 'info' => 'There is no revision ID oldid' ),
                        array( 'code' => 'permissiondenied', 'info' => 'You don\'t have permission to view deleted revisions' ),
                        array( 'code' => 'missingtitle', 'info' => 'The page you specified doesn\'t exist' ),
@@ -700,7 +706,10 @@ class ApiParse extends ApiBase {
 
        public function getExamples() {
                return array(
-                       'api.php?action=parse&text={{Project:Sandbox}}'
+                       'api.php?action=parse&page=Project:Sandbox' => 'Parse a page',
+                       'api.php?action=parse&text={{Project:Sandbox}}' => 'Parse wikitext',
+                       'api.php?action=parse&text={{PAGENAME}}&title=Test' => 'Parse wikitext, specifying the page title',
+                       'api.php?action=parse&summary=Some+[[link]]&prop=' => 'Parse a summary',
                );
        }