From aa973b9eb7df30f82cfde35a7396ee852ccc0c3c Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Thu, 11 Feb 2010 21:34:35 +0000 Subject: [PATCH] More of bug 18771 - List possible errors in action=paraminfo Followup to comments of r62282 --- includes/api/ApiBase.php | 26 +++++++++++++++++++++++++- includes/api/ApiBlock.php | 16 ++++++++-------- includes/api/ApiParamInfo.php | 5 +++-- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index e11e615688..224fecf880 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -968,7 +968,31 @@ abstract class ApiBase { * Returns a list of all possible errors returned by the module */ public function possibleErrors() { - return array(); + $ret = array( array( 'readrequired' ) ); + + if ( $this->mustBePosted() ) { + $ret = array_merge( $ret, array( array( 'code' => 'mustbeposted', 'info' => 'The {$this->mAction} module requires a POST request' ) ) ); + } + + return $ret; + } + + /** + * + */ + public function parseErrors( $errors ) { + $ret = array(); + + foreach ( $errors as $row ) + { + if ( isset( $row['code'] ) && isset( $row['info'] ) ) { + $ret[] = $row; + } + else { + $ret[] = $this->parseMsg( $row ); + } + } + return $ret; } /** diff --git a/includes/api/ApiBlock.php b/includes/api/ApiBlock.php index c061656b38..962f3b58e4 100644 --- a/includes/api/ApiBlock.php +++ b/includes/api/ApiBlock.php @@ -159,14 +159,14 @@ class ApiBlock extends ApiBase { } public function possibleErrors() { - return array ( - $this->parseMsg( array( 'missingparam', 'user' ) ), - $this->parseMsg( array( 'missingparam', 'token' ) ), - $this->parseMsg( array( 'sessionfailure' ) ), - $this->parseMsg( array( 'cantblock' ) ), - $this->parseMsg( array( 'canthide' ) ), - $this->parseMsg( array( 'cantblock-email' ) ), - ); + return array_merge( parent::possibleErrors(), array( + array( 'missingparam', 'user' ), + array( 'missingparam', 'token' ), + array( 'sessionfailure' ), + array( 'cantblock' ), + array( 'canthide' ), + array( 'cantblock-email' ), + ) ); } protected function getExamples() { diff --git a/includes/api/ApiParamInfo.php b/includes/api/ApiParamInfo.php index 719fb55799..1dcd91876f 100644 --- a/includes/api/ApiParamInfo.php +++ b/includes/api/ApiParamInfo.php @@ -171,8 +171,9 @@ class ApiParamInfo extends ApiBase { } $result->setIndexedTagName( $retval['parameters'], 'param' ); - // Errors - $retval['errors'] = $obj->possibleErrors(); + // Errors + $retval['errors'] = $this->parseErrors( $obj->possibleErrors() ); + $result->setIndexedTagName( $retval['errors'], 'error' ); return $retval; -- 2.20.1