From 3756f810bc184c299c015e133c7d61d5068e70c8 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Tue, 16 Oct 2012 11:42:54 -0400 Subject: [PATCH] (bug 41042) Regression: API action=parse with nonexistent page Changeset Iec98e472 changed the behavior of action=parse&page=... when passed a page that does not exist: previously, it would return a "missingtitle" error instead of assuming an empty page. As some people had been depending on this old behavior, restore the error checking. Change-Id: I4c76ce458ceb01e233c6074cd9251879013ec143 --- RELEASE-NOTES-1.21 | 1 + includes/api/ApiParse.php | 3 +++ tests/phpunit/includes/api/ApiParseTest.php | 29 +++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 tests/phpunit/includes/api/ApiParseTest.php diff --git a/RELEASE-NOTES-1.21 b/RELEASE-NOTES-1.21 index d8f65068d1..9565f4bb2f 100644 --- a/RELEASE-NOTES-1.21 +++ b/RELEASE-NOTES-1.21 @@ -47,6 +47,7 @@ production. page content; See docs/contenthandler.txt for details. * (bug 35693) ApiQueryImageInfo now suppresses errors when unserializing metadata. * (bug 40111) Disable minor edit for page/section creation by API +* (bug 41042) Revert change to action=parse&page=... behavior when the page does not exist. === Languages updated in 1.21 === diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index a29a0bd0b7..9d95648ee2 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -147,6 +147,9 @@ class ApiParse extends ApiBase { $pageObj = $this->getTitleOrPageId( $pageParams, 'fromdb' ); $titleObj = $pageObj->getTitle(); + if ( !$titleObj || !$titleObj->exists() ) { + $this->dieUsage( "The page you specified doesn't exist", 'missingtitle' ); + } $wgTitle = $titleObj; if ( isset( $prop['revid'] ) ) { diff --git a/tests/phpunit/includes/api/ApiParseTest.php b/tests/phpunit/includes/api/ApiParseTest.php new file mode 100644 index 0000000000..b5dabf0c66 --- /dev/null +++ b/tests/phpunit/includes/api/ApiParseTest.php @@ -0,0 +1,29 @@ +doLogin(); + } + + function testParseNonexistentPage() { + $somePage = mt_rand(); + + try { + $data = $this->doApiRequest( array( + 'action' => 'parse', + 'page' => $somePage ) ); + + $this->fail( "API did not return an error when parsing a nonexistent page" ); + } catch(UsageException $ex){ + $this->assertEquals( 'missingtitle', $ex->getCodeString(), + "Parse request for nonexistent page must give 'missingtitle' error: " . var_export( $ex->getMessageArray(), true ) ); + } + } + +} -- 2.20.1