http://www.mediawiki.org/wiki/Special:Code/MediaWiki/82807
Revision: 82807
Author: reedy
Date: 2011-02-25 19:09:39 +0000 (Fri, 25 Feb 2011)
Log Message:
-----------
Implement getRequireOnlyOneParameterErrorMessages, to make the error messages
requireOnlyOneParameter can throw.
Use in 4 modules for more dynamicness
Modified Paths:
--------------
trunk/phase3/includes/api/ApiBase.php
trunk/phase3/includes/api/ApiDelete.php
trunk/phase3/includes/api/ApiMove.php
trunk/phase3/includes/api/ApiQueryCategoryMembers.php
trunk/phase3/includes/api/ApiUpload.php
Modified: trunk/phase3/includes/api/ApiBase.php
===================================================================
--- trunk/phase3/includes/api/ApiBase.php 2011-02-25 18:17:10 UTC (rev
82806)
+++ trunk/phase3/includes/api/ApiBase.php 2011-02-25 19:09:39 UTC (rev
82807)
@@ -556,6 +556,22 @@
}
/**
+ * 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
*
* @param $x object Parameter to check is not null/false
Modified: trunk/phase3/includes/api/ApiDelete.php
===================================================================
--- trunk/phase3/includes/api/ApiDelete.php 2011-02-25 18:17:10 UTC (rev
82806)
+++ trunk/phase3/includes/api/ApiDelete.php 2011-02-25 19:09:39 UTC (rev
82807)
@@ -255,14 +255,15 @@
}
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() {
Modified: trunk/phase3/includes/api/ApiMove.php
===================================================================
--- trunk/phase3/includes/api/ApiMove.php 2011-02-25 18:17:10 UTC (rev
82806)
+++ trunk/phase3/includes/api/ApiMove.php 2011-02-25 19:09:39 UTC (rev
82807)
@@ -224,15 +224,16 @@
}
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() {
Modified: trunk/phase3/includes/api/ApiQueryCategoryMembers.php
===================================================================
--- trunk/phase3/includes/api/ApiQueryCategoryMembers.php 2011-02-25
18:17:10 UTC (rev 82806)
+++ trunk/phase3/includes/api/ApiQueryCategoryMembers.php 2011-02-25
19:09:39 UTC (rev 82807)
@@ -326,13 +326,14 @@
}
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() {
Modified: trunk/phase3/includes/api/ApiUpload.php
===================================================================
--- trunk/phase3/includes/api/ApiUpload.php 2011-02-25 18:17:10 UTC (rev
82806)
+++ trunk/phase3/includes/api/ApiUpload.php 2011-02-25 19:09:39 UTC (rev
82807)
@@ -474,24 +474,25 @@
}
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() {
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs