Merge "Get ConfigFactory & MainConfig from MediaWikiServices"
[lhc/web/wiklou.git] / includes / api / ApiBase.php
index 809d567..0cd46e4 100644 (file)
@@ -67,7 +67,8 @@ abstract class ApiBase extends ContextSource {
         * - limit: An integer or the string 'max'. Default lower limit is 0 (but
         *   see PARAM_MIN), and requires that PARAM_MAX and PARAM_MAX2 be
         *   specified. Cannot be used with PARAM_ISMULTI.
-        * - namespace: An integer representing a MediaWiki namespace.
+        * - namespace: An integer representing a MediaWiki namespace. Forces PARAM_ALL = true to
+        *   support easily specifying all namespaces.
         * - NULL: Any string.
         * - password: Any non-empty string. Input value is private or sensitive.
         *   <input type="password"> would be an appropriate HTML form field.
@@ -171,8 +172,18 @@ abstract class ApiBase extends ContextSource {
         */
        const PARAM_SUBMODULE_PARAM_PREFIX = 16;
 
+       /**
+        * (boolean|string) When PARAM_TYPE has a defined set of values and PARAM_ISMULTI is true,
+        * this allows for an asterisk ('*') to be passed in place of a pipe-separated list of
+        * every possible value. If a string is set, it will be used in place of the asterisk.
+        * @since 1.29
+        */
+       const PARAM_ALL = 17;
+
        /**@}*/
 
+       const ALL_DEFAULT_STRING = '*';
+
        /** Fast query, standard limit. */
        const LIMIT_BIG1 = 500;
        /** Fast query, apihighlimits limit. */
@@ -600,7 +611,7 @@ abstract class ApiBase extends ContextSource {
 
        /**
         * Gets a default replica DB connection object
-        * @return DatabaseBase
+        * @return Database
         */
        protected function getDB() {
                if ( !isset( $this->mSlaveDB ) ) {
@@ -920,6 +931,7 @@ abstract class ApiBase extends ContextSource {
                        $dupes = false;
                        $deprecated = false;
                        $required = false;
+                       $allowAll = false;
                } else {
                        $default = isset( $paramSettings[self::PARAM_DFLT] )
                                ? $paramSettings[self::PARAM_DFLT]
@@ -939,6 +951,9 @@ abstract class ApiBase extends ContextSource {
                        $required = isset( $paramSettings[self::PARAM_REQUIRED] )
                                ? $paramSettings[self::PARAM_REQUIRED]
                                : false;
+                       $allowAll = isset( $paramSettings[self::PARAM_ALL] )
+                               ? $paramSettings[self::PARAM_ALL]
+                               : false;
 
                        // When type is not given, and no choices, the type is the same as $default
                        if ( !isset( $type ) ) {
@@ -992,6 +1007,9 @@ abstract class ApiBase extends ContextSource {
 
                        if ( isset( $value ) && $type == 'namespace' ) {
                                $type = MWNamespace::getValidNamespaces();
+                               // By default, namespace parameters allow ALL_DEFAULT_STRING to be used to specify
+                               // all namespaces.
+                               $allowAll = true;
                        }
                        if ( isset( $value ) && $type == 'submodule' ) {
                                if ( isset( $paramSettings[self::PARAM_SUBMODULE_MAP] ) ) {
@@ -1027,12 +1045,19 @@ abstract class ApiBase extends ContextSource {
                        }
                }
 
+               $allSpecifier = ( is_string( $allowAll ) ? $allowAll : self::ALL_DEFAULT_STRING );
+               if ( $allowAll && $multi && is_array( $type ) && in_array( $allSpecifier, $type, true ) ) {
+                       ApiBase::dieDebug(
+                               __METHOD__,
+                               "For param $encParamName, PARAM_ALL collides with a possible value" );
+               }
                if ( isset( $value ) && ( $multi || is_array( $type ) ) ) {
                        $value = $this->parseMultiValue(
                                $encParamName,
                                $value,
                                $multi,
-                               is_array( $type ) ? $type : null
+                               is_array( $type ) ? $type : null,
+                               $allowAll ? $allSpecifier : null
                        );
                }
 
@@ -1215,9 +1240,13 @@ abstract class ApiBase extends ContextSource {
         *  separated by '|'?
         * @param string[]|null $allowedValues An array of values to check against. If
         *  null, all values are accepted.
+        * @param string|null $allSpecifier String to use to specify all allowed values, or null
+        *  if this behavior should not be allowed
         * @return string|string[] (allowMultiple ? an_array_of_values : a_single_value)
         */
-       protected function parseMultiValue( $valueName, $value, $allowMultiple, $allowedValues ) {
+       protected function parseMultiValue( $valueName, $value, $allowMultiple, $allowedValues,
+               $allSpecifier = null
+       ) {
                if ( ( trim( $value ) === '' || trim( $value ) === "\x1f" ) && $allowMultiple ) {
                        return [];
                }
@@ -1229,6 +1258,12 @@ abstract class ApiBase extends ContextSource {
                        ? self::LIMIT_SML2
                        : self::LIMIT_SML1;
 
+               if ( $allowMultiple && is_array( $allowedValues ) && $allSpecifier &&
+                       count( $valuesList ) === 1 && $valuesList[0] === $allSpecifier
+               ) {
+                       return $allowedValues;
+               }
+
                if ( self::truncateArray( $valuesList, $sizeLimit ) ) {
                        $this->logFeatureUsage( "too-many-$valueName-for-{$this->getModulePath()}" );
                        $this->setWarning( "Too many values supplied for parameter '$valueName': " .
@@ -2745,16 +2780,6 @@ abstract class ApiBase extends ContextSource {
                return 0;
        }
 
-       /**
-        * Get the result data array (read-only)
-        * @deprecated since 1.25, use $this->getResult() methods instead
-        * @return array
-        */
-       public function getResultData() {
-               wfDeprecated( __METHOD__, '1.25' );
-               return $this->getResult()->getData();
-       }
-
        /**
         * Call wfTransactionalTimeLimit() if this request was POSTed
         * @since 1.26