Better error message via api when content model does not allow editing
authorErik Bernhardson <ebernhardson@wikimedia.org>
Fri, 19 Jun 2015 22:39:48 +0000 (15:39 -0700)
committerEBernhardson <ebernhardson@wikimedia.org>
Wed, 1 Jul 2015 06:13:37 +0000 (06:13 +0000)
Change-Id: I699b4f5fd2eac8dfc4c54922474f939262bc803d

includes/api/ApiEditPage.php
tests/phpunit/includes/api/ApiEditPageTest.php

index e70b8f0..b623849 100644 (file)
@@ -96,9 +96,11 @@ class ApiEditPage extends ApiBase {
                        $contentHandler = ContentHandler::getForModelID( $params['contentmodel'] );
                }
 
+               $name = $titleObj->getPrefixedDBkey();
+               $model = $contentHandler->getModelID();
                if ( $contentHandler->supportsDirectApiEditing() === false ) {
                        $this->dieUsage(
-                               'Direct editing via API is not supported for this content type.',
+                               "Direct editing via API is not supported for content model $model used by $name",
                                'no-direct-editing'
                        );
                }
@@ -110,8 +112,6 @@ class ApiEditPage extends ApiBase {
                $contentFormat = $params['contentformat'];
 
                if ( !$contentHandler->isSupportedFormat( $contentFormat ) ) {
-                       $name = $titleObj->getPrefixedDBkey();
-                       $model = $contentHandler->getModelID();
 
                        $this->dieUsage( "The requested format $contentFormat is not supported for content model " .
                                " $model used by $name", 'badformat' );
index fa528da..e006bf7 100644 (file)
@@ -475,7 +475,7 @@ class ApiEditPageTest extends ApiTestCase {
        public function testCheckDirectApiEditingDisallowed_forNonTextContent() {
                $this->setExpectedException(
                        'UsageException',
-                       'Direct editing via API is not supported for this content type.'
+                       'Direct editing via API is not supported for content model testing used by Dummy:ApiEditPageTest_nonTextPageEdit'
                );
 
                $this->doApiRequestWithToken( array(