templated parameters.
* It is now an error to submit too many values for a multi-valued parameter.
This has generated a warning since MediaWiki 1.14.
+* Assertion failures from the 'assert' and 'assertuser' parameters will no
+ longer use the action module's custom response format, for the few modules
+ that use custom formatters that handle errors.
=== Action API internal changes in 1.32 ===
* Added 'ApiParseMakeOutputPage' hook.
*/
protected function executeAction() {
$params = $this->setupExecuteAction();
+
+ // Check asserts early so e.g. errors in parsing a module's parameters due to being
+ // logged out don't override the client's intended "am I logged in?" check.
+ $this->checkAsserts( $params );
+
$module = $this->setupModule();
$this->mModule = $module;
$this->setupExternalResponse( $module, $params );
}
- $this->checkAsserts( $params );
-
// Execute
$module->execute();
Hooks::run( 'APIAfterExecute', [ &$module ] );
}
}
+ /**
+ * Test that 'assert' is processed before module errors
+ */
+ public function testAssertBeforeModule() {
+ // Sanity check that the query without assert throws too-many-titles
+ try {
+ $this->doApiRequest( [
+ 'action' => 'query',
+ 'titles' => implode( '|', range( 1, ApiBase::LIMIT_SML1 + 1 ) ),
+ ], null, null, new User );
+ $this->fail( 'Expected exception not thrown' );
+ } catch ( ApiUsageException $e ) {
+ $this->assertTrue( self::apiExceptionHasCode( $e, 'too-many-titles' ), 'sanity check' );
+ }
+
+ // Now test that the assert happens first
+ try {
+ $this->doApiRequest( [
+ 'action' => 'query',
+ 'titles' => implode( '|', range( 1, ApiBase::LIMIT_SML1 + 1 ) ),
+ 'assert' => 'user',
+ ], null, null, new User );
+ $this->fail( 'Expected exception not thrown' );
+ } catch ( ApiUsageException $e ) {
+ $this->assertTrue( self::apiExceptionHasCode( $e, 'assertuserfailed' ),
+ "Error '{$e->getMessage()}' matched expected 'assertuserfailed'" );
+ }
+ }
+
/**
* Test if all classes in the main module manager exists
*/