Merge "Add PreferencesFormPreSave hook"
[lhc/web/wiklou.git] / includes / api / ApiBase.php
index b6a7ca8..e610d19 100644 (file)
@@ -801,6 +801,48 @@ abstract class ApiBase extends ContextSource {
                );
        }
 
+       /**
+        * Die if none of a certain set of parameters is set and not false.
+        *
+        * @since 1.23
+        * @param array $params User provided set of parameters
+        * @param string ... List of parameter names to check
+        */
+       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
+        *
+        * @since 1.23
+        * @param $params array Array of parameter key names
+        * @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:
@@ -861,17 +903,6 @@ abstract class ApiBase extends ContextSource {
                return !is_null( $x ) && $x !== false;
        }
 
-       /**
-        * @deprecated since 1.17 use MWNamespace::getValidNamespaces()
-        *
-        * @return array
-        */
-       public static function getValidNamespaces() {
-               wfDeprecated( __METHOD__, '1.17' );
-
-               return MWNamespace::getValidNamespaces();
-       }
-
        /**
         * Return true if we're to watch the page, false if not, null if no change.
         * @param string $watchlist Valid values: 'watch', 'unwatch', 'preferences', 'nochange'