Parent5446 has uploaded a new change for review.
https://gerrit.wikimedia.org/r/64649
Change subject: Create ApiBase::requireAtLeastOneParameter helper
......................................................................
Create ApiBase::requireAtLeastOneParameter helper
Added new ApiBase::requireAtLeastOneParameter() helper method for modules
that need one or more of a combination of parameters. The associated help
message function has also been added.
Change-Id: Iae6649ed503fdbf14b313d0be1a82f3dca8d7162
---
M includes/api/ApiBase.php
1 file changed, 32 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/49/64649/1
diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php
index 7e7365f..02ab19b 100644
--- a/includes/api/ApiBase.php
+++ b/includes/api/ApiBase.php
@@ -744,6 +744,38 @@
}
/**
+ * Die if none of a certain set of parameters is set and not false.
+ * @param array $params of parameter names
+ */
+ public function requireAtLeastOneParameter( $params ) {
+ $required = func_get_args();
+ array_shift( $required );
+ $p = $this->getModulePrefix();
+
+ $intersection = array_intersect( array_keys( array_filter(
$params,
+ array( $this, "parameterNotEmpty" ) ) ), $required );
+
+ if ( count( $intersection ) == 0 ) {
+ $this->dieUsage( "At least one of the parameters {$p}"
. implode( ", {$p}", $required ) . ' is required', "{$p}missingparam" );
+ }
+ }
+
+ /**
+ * Generates the possible errors requireAtLeastOneParameter() can die
with
+ *
+ * @param $params array
+ * @return array
+ */
+ public function getRequireAtLeastOneParameterErrorMessages( $params ) {
+ $p = $this->getModulePrefix();
+ $params = implode( ", {$p}", $params );
+
+ return array(
+ array( 'code' => "{$p}missingparam", 'info' => "At
least one of the parameters {$p}{$params} is required" ),
+ );
+ }
+
+ /**
* @param $params array
* @param bool|string $load Whether load the object's state from the
database:
* - false: don't load (if the pageid is given, it will still be
loaded)
--
To view, visit https://gerrit.wikimedia.org/r/64649
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iae6649ed503fdbf14b313d0be1a82f3dca8d7162
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Parent5446 <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits