Explicit variable definition, tweak documentation
[lhc/web/wiklou.git] / includes / api / ApiBase.php
index f2af6e2..df7ca1b 100644 (file)
@@ -532,8 +532,8 @@ abstract class ApiBase {
                array_shift( $required );
 
                $intersection = array_intersect( array_keys( array_filter( $params,
-                               create_function( '$x', 'return !is_null($x) && $x !== false;' )
-                       ) ), $required );
+                               array( $this, "parameterNotEmpty" ) ) ), $required );
+
                if ( count( $intersection ) > 1 ) {
                        $this->dieUsage( 'The parameters ' . implode( ', ', $intersection ) . ' can not be used together', 'invalidparammix' );
                } elseif ( count( $intersection ) == 0 ) {
@@ -541,6 +541,16 @@ abstract class ApiBase {
                }
        }
 
+       /**
+        * Callback function used in requireOnlyOneParameter to check whether reequired parameters are set
+        *
+        * @param  $x object Parameter to check is not null/false
+        * @return bool
+        */
+       private function parameterNotEmpty( $x ) {
+               return !is_null( $x ) && $x !== false;
+       }
+
        /**
         * @deprecated use MWNamespace::getValidNamespaces()
         */
@@ -677,8 +687,6 @@ abstract class ApiBase {
 
                                                break;
                                        case 'integer': // Force everything using intval() and optionally validate limits
-                                               $value = is_array( $value ) ? array_map( 'intval', $value ) : intval( $value );
-
                                                $min = isset ( $paramSettings[self::PARAM_MIN] ) ? $paramSettings[self::PARAM_MIN] : null;
                                                $max = isset ( $paramSettings[self::PARAM_MAX] ) ? $paramSettings[self::PARAM_MAX] : null;
                                                $enforceLimits = isset ( $paramSettings[self::PARAM_RANGE_ENFORCE] )
@@ -686,11 +694,13 @@ abstract class ApiBase {
 
                                                if ( !is_null( $min ) || !is_null( $max ) ) {
                                                    if ( is_array( $value ) ) {
+                                                           $value = array_map( 'intval', $value );
                                                            foreach ( $value as &$v ) {
-                                                                       $this->validateLimit( $paramName, $v, $min, $max, $enforceLimits );
+                                                                       $this->validateLimit( $paramName, $v, $min, $max, null, $enforceLimits );
                                                                }
                                                    } else {
-                                                           $this->validateLimit( $paramName, $value, $min, $max, $enforceLimits );                                                         
+                                                           $value = intval( $value );
+                                                           $this->validateLimit( $paramName, $value, $min, $max, null, $enforceLimits );
                                                    }
                                                }
                                                break;
@@ -866,7 +876,7 @@ abstract class ApiBase {
         */
        private function warnOrDie( $msg, $enforceLimits = false ) {
                if ( $enforceLimits ) {
-                       $this->dieUsageMsg( $msg );
+                       $this->dieUsage( $msg, 'integeroutofrange' );
                } else {
                        $this->setWarning( $msg );
                }
@@ -998,7 +1008,6 @@ abstract class ApiBase {
                'createonly-exists' => array( 'code' => 'articleexists', 'info' => "The article you tried to create has been created already" ),
                'nocreate-missing' => array( 'code' => 'missingtitle', 'info' => "The article you tried to edit doesn't exist" ),
                'nosuchrcid' => array( 'code' => 'nosuchrcid', 'info' => "There is no change with rcid ``\$1''" ),
-               'cantpurge' => array( 'code' => 'cantpurge', 'info' => "Only users with the 'purge' right can purge pages via the API" ),
                'protect-invalidaction' => array( 'code' => 'protect-invalidaction', 'info' => "Invalid protection type ``\$1''" ),
                'protect-invalidlevel' => array( 'code' => 'protect-invalidlevel', 'info' => "Invalid protection level ``\$1''" ),
                'toofewexpiries' => array( 'code' => 'toofewexpiries', 'info' => "\$1 expiry timestamps were provided where \$2 were needed" ),