From: Sam Reed Date: Fri, 25 Feb 2011 19:09:39 +0000 (+0000) Subject: Implement getRequireOnlyOneParameterErrorMessages, to make the error messages require... X-Git-Tag: 1.31.0-rc.0~31773 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=41e7860130435233d5089796f0830d9b2111eadc;p=lhc%2Fweb%2Fwiklou.git Implement getRequireOnlyOneParameterErrorMessages, to make the error messages requireOnlyOneParameter can throw. Use in 4 modules for more dynamicness --- diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index e761fbd246..d8905a85ec 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -555,6 +555,22 @@ abstract class ApiBase { } } + /** + * Generates the possible errors requireOnlyOneParameter() can die with + * + * @param $params array + * @return array + */ + public function getRequireOnlyOneParameterErrorMessages( $params ) { + $p = $this->getModulePrefix(); + $params = implode( ", {$p}", $params ); + + return array( + array( 'code' => "{$p}missingparam", 'info' => "One of the parameters {$p}{$params} is required" ), + array( 'code' => "{$p}invalidparammix", 'info' => "The parameters {$p}{$params} can not be used together" ) + ); + } + /** * Callback function used in requireOnlyOneParameter to check whether reequired parameters are set * diff --git a/includes/api/ApiDelete.php b/includes/api/ApiDelete.php index bae27bb51a..2f6ed2d351 100644 --- a/includes/api/ApiDelete.php +++ b/includes/api/ApiDelete.php @@ -255,14 +255,15 @@ class ApiDelete extends ApiBase { } public function getPossibleErrors() { - return array_merge( parent::getPossibleErrors(), array( - array( 'code' => 'missingparam', 'info' => 'One of the parameters title, pageid is required' ), - array( 'code' => 'invalidparammix', 'info' => 'The parameters title, pageid can not be used together' ), - array( 'invalidtitle', 'title' ), - array( 'nosuchpageid', 'pageid' ), - array( 'notanarticle' ), - array( 'hookaborted', 'error' ), - ) ); + return array_merge( parent::getPossibleErrors(), + $this->getRequireOnlyOneParameterErrorMessages( array( 'title', 'pageid' ) ), + array( + array( 'invalidtitle', 'title' ), + array( 'nosuchpageid', 'pageid' ), + array( 'notanarticle' ), + array( 'hookaborted', 'error' ), + ) + ); } public function needsToken() { diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php index 63fe7583aa..28ad025736 100644 --- a/includes/api/ApiMove.php +++ b/includes/api/ApiMove.php @@ -224,15 +224,16 @@ class ApiMove extends ApiBase { } public function getPossibleErrors() { - return array_merge( parent::getPossibleErrors(), array( - array( 'code' => 'missingparam', 'info' => 'One of the parameters from, fromid is required' ), - array( 'code' => 'invalidparammix', 'info' => 'The parameters from, fromid can not be used together' ), - array( 'invalidtitle', 'from' ), - array( 'nosuchpageid', 'fromid' ), - array( 'notanarticle' ), - array( 'invalidtitle', 'to' ), - array( 'sharedfile-exists' ), - ) ); + return array_merge( parent::getPossibleErrors(), + $this->getRequireOnlyOneParameterErrorMessages( array( 'from', 'fromid' ) ), + array( + array( 'invalidtitle', 'from' ), + array( 'nosuchpageid', 'fromid' ), + array( 'notanarticle' ), + array( 'invalidtitle', 'to' ), + array( 'sharedfile-exists' ), + ) + ); } public function needsToken() { diff --git a/includes/api/ApiQueryCategoryMembers.php b/includes/api/ApiQueryCategoryMembers.php index d245e66509..15da5cd48d 100644 --- a/includes/api/ApiQueryCategoryMembers.php +++ b/includes/api/ApiQueryCategoryMembers.php @@ -326,13 +326,14 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase { } public function getPossibleErrors() { - return array_merge( parent::getPossibleErrors(), array( - array( 'code' => 'cmmissingparam', 'info' => 'One of the parameters title, pageid is required' ), - array( 'code' => 'cminvalidparammix', 'info' => 'The parameters title, pageid can not be used together' ), - array( 'code' => 'invalidcategory', 'info' => 'The category name you entered is not valid' ), - array( 'code' => 'badcontinue', 'info' => 'Invalid continue param. You should pass the original value returned by the previous query' ), - array( 'nosuchpageid', 'pageid' ), - ) ); + return array_merge( parent::getPossibleErrors(), + $this->getRequireOnlyOneParameterErrorMessages( array( 'title', 'pageid' ) ), + array( + array( 'code' => 'invalidcategory', 'info' => 'The category name you entered is not valid' ), + array( 'code' => 'badcontinue', 'info' => 'Invalid continue param. You should pass the original value returned by the previous query' ), + array( 'nosuchpageid', 'pageid' ), + ) + ); } protected function getExamples() { diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index 658fa117f7..3d29b705db 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -474,24 +474,25 @@ class ApiUpload extends ApiBase { } public function getPossibleErrors() { - return array_merge( parent::getPossibleErrors(), array( - array( 'uploaddisabled' ), - array( 'invalid-session-key' ), - array( 'uploaddisabled' ), - array( 'mustbeloggedin', 'upload' ), - array( 'badaccess-groups' ), - array( 'code' => 'fetchfileerror', 'info' => '' ), - array( 'code' => 'nomodule', 'info' => 'No upload module set' ), - array( 'code' => 'empty-file', 'info' => 'The file you submitted was empty' ), - array( 'code' => 'filetype-missing', 'info' => 'The file is missing an extension' ), - array( 'code' => 'filename-tooshort', 'info' => 'The filename is too short' ), - array( 'code' => 'overwrite', 'info' => 'Overwriting an existing file is not allowed' ), - array( 'code' => 'stashfailed', 'info' => 'Stashing temporary file failed' ), - array( 'code' => 'internal-error', 'info' => 'An internal error occurred' ), - array( 'code' => 'missingparam', 'info' => 'One of the parameters sessionkey, file, url, statuskey is required' ), - array( 'code' => 'invalidparammix', 'info' => 'The parameters sessionkey, file, url, statuskey can not be used together' ), - array( 'code' => 'asynccopyuploaddisabled', 'info' => 'Asynchronous copy uploads disabled' ), - ) ); + return array_merge( parent::getPossibleErrors(), + $this->getRequireOnlyOneParameterErrorMessages( array( 'sessionkey', 'file', 'url', 'statuskey' ) ), + array( + array( 'uploaddisabled' ), + array( 'invalid-session-key' ), + array( 'uploaddisabled' ), + array( 'mustbeloggedin', 'upload' ), + array( 'badaccess-groups' ), + array( 'code' => 'fetchfileerror', 'info' => '' ), + array( 'code' => 'nomodule', 'info' => 'No upload module set' ), + array( 'code' => 'empty-file', 'info' => 'The file you submitted was empty' ), + array( 'code' => 'filetype-missing', 'info' => 'The file is missing an extension' ), + array( 'code' => 'filename-tooshort', 'info' => 'The filename is too short' ), + array( 'code' => 'overwrite', 'info' => 'Overwriting an existing file is not allowed' ), + array( 'code' => 'stashfailed', 'info' => 'Stashing temporary file failed' ), + array( 'code' => 'internal-error', 'info' => 'An internal error occurred' ), + array( 'code' => 'asynccopyuploaddisabled', 'info' => 'Asynchronous copy uploads disabled' ), + ) + ); } public function needsToken() {