* PARAM_REQUIRED parameter flag added. If this flag is set, and the end user does...
authorX! <soxred93@users.mediawiki.org>
Wed, 4 Aug 2010 13:35:08 +0000 (13:35 +0000)
committerX! <soxred93@users.mediawiki.org>
Wed, 4 Aug 2010 13:35:08 +0000 (13:35 +0000)
  the parameter, the API will automatically throw an error.

RELEASE-NOTES
includes/api/ApiBase.php

index 23c39bc..1103595 100644 (file)
@@ -316,6 +316,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 24564) Fix fatal errors when using list=deletedrevs, prop=revisions or 
   one of the backlinks generators with limit=max.
 * (bug 24656) API's parse module needs option to disable PP report
+* PARAM_REQUIRED parameter flag added. If this flag is set, and the end user does not set 
+  the parameter, the API will automatically throw an error.
 
 === Languages updated in 1.17 ===
 
index b28224b..099d6f5 100644 (file)
@@ -50,6 +50,7 @@ abstract class ApiBase {
        const PARAM_MIN = 5; // Lowest value allowed for a parameter. Only applies if TYPE='integer'
        const PARAM_ALLOW_DUPLICATES = 6; // Boolean, do we allow the same value to be set more than once when ISMULTI=true
        const PARAM_DEPRECATED = 7; // Boolean, is the parameter deprecated (will show a warning)
+       const PARAM_REQUIRED = 8; // Boolean, is the parameter required?
 
        const LIMIT_BIG1 = 500; // Fast query, std user limit
        const LIMIT_BIG2 = 5000; // Fast query, bot/sysop limit
@@ -306,6 +307,12 @@ abstract class ApiBase {
                                if ( $deprecated ) {
                                        $desc = "DEPRECATED! $desc";
                                }
+                               
+                               $required = isset( $paramSettings[self::PARAM_REQUIRED] ) ?
+                                       $paramSettings[self::PARAM_REQUIRED] : false;
+                               if ( $required ) {
+                                       $desc .= $paramPrefix . "This parameter is required";
+                               }
 
                                $type = isset( $paramSettings[self::PARAM_TYPE] ) ? $paramSettings[self::PARAM_TYPE] : null;
                                if ( isset( $type ) ) {
@@ -493,6 +500,14 @@ abstract class ApiBase {
                        }
                        $this->mParamCache[$parseLimit] = $results;
                }
+               
+               $allparams = $this->getAllowedParams();
+               foreach( $this->mParamCache[$parseLimit] as $param => $val ) {
+                       if( !isset( $allparams[$param][ApiBase::PARAM_REQUIRED] ) ) {
+                               $this->dieUsageMsg( array( 'missingparam', $param ) );
+                       }
+               }
+               
                return $this->mParamCache[$parseLimit];
        }