* (bug 28254) action=paraminfo: Extract type from PARAM_DFLT if PARAM_TYPE is not set
authorSam Reed <reedy@users.mediawiki.org>
Sun, 10 Apr 2011 13:01:47 +0000 (13:01 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Sun, 10 Apr 2011 13:01:47 +0000 (13:01 +0000)
Patch by Umherirrender

RELEASE-NOTES
includes/api/ApiParamInfo.php

index b4aca3e..fb8ad95 100644 (file)
@@ -329,6 +329,8 @@ PHP if you have not done so prior to upgrading MediaWiki.
   action=import&xml=
 * (bug 28391) action=feedwatchlist&allrev should be a bool
 * (bug 28364) add registration date to meta=userinfo
+* (bug 28254) action=paraminfo: Extract type from PARAM_DFLT if
+  PARAM_TYPE is not set
 
 === Languages updated in 1.18 ===
 
index 7f1f945..ac91ea3 100644 (file)
@@ -121,6 +121,26 @@ class ApiParamInfo extends ApiBase {
                        if ( isset( $paramDesc[$n] ) ) {
                                $a['description'] = implode( "\n", (array)$paramDesc[$n] );
                        }
+
+                       //handle shorthand
+                       if( !is_array( $p ) ) {
+                               $p = array(
+                                       ApiBase::PARAM_DFLT => $p,
+                               );
+                       }
+
+                       //handle missing type
+                       if ( !isset( $p[ApiBase::PARAM_TYPE] ) ) {
+                               $dflt = $p[ApiBase::PARAM_DFLT];
+                               if ( is_bool( $dflt ) ) {
+                                       $p[ApiBase::PARAM_TYPE] = 'bool';
+                               } elseif ( is_string( $dflt ) || is_null( $dflt ) ) {
+                                       $p[ApiBase::PARAM_TYPE] = 'string';
+                               } elseif ( is_int( $dflt ) ) {
+                                       $p[ApiBase::PARAM_TYPE] = 'integer';
+                               }
+                       }
+
                        if ( isset( $p[ApiBase::PARAM_DEPRECATED] ) && $p[ApiBase::PARAM_DEPRECATED] ) {
                                $a['deprecated'] = '';
                        }
@@ -128,23 +148,17 @@ class ApiParamInfo extends ApiBase {
                                $a['required'] = '';
                        }
 
-                       if ( !is_array( $p ) ) {
-                               if ( is_bool( $p ) ) {
-                                       $a['type'] = 'bool';
-                                       $a['default'] = ( $p ? 'true' : 'false' );
-                               } elseif ( is_string( $p ) || is_null( $p ) ) {
-                                       $a['type'] = 'string';
-                                       $a['default'] = strval( $p );
-                               } elseif ( is_int( $p ) ) {
-                                       $a['type'] = 'integer';
-                                       $a['default'] = intval( $p );
-                               }
-                               $retval['parameters'][] = $a;
-                               continue;
-                       }
-
                        if ( isset( $p[ApiBase::PARAM_DFLT] ) ) {
-                               $a['default'] = $p[ApiBase::PARAM_DFLT];
+                               $type = $p[ApiBase::PARAM_TYPE];
+                               if( $type === 'bool' ) {
+                                       $a['default'] = ( $p[ApiBase::PARAM_DFLT] ? 'true' : 'false' );
+                               } elseif( $type === 'string' ) {
+                                       $a['default'] = strval( $p[ApiBase::PARAM_DFLT] );
+                               } elseif( $type === 'integer' ) {
+                                       $a['default'] = intval( $p[ApiBase::PARAM_DFLT] );
+                               } else {
+                                       $a['default'] = $p[ApiBase::PARAM_DFLT];
+                               }
                        }
                        if ( isset( $p[ApiBase::PARAM_ISMULTI] ) && $p[ApiBase::PARAM_ISMULTI] ) {
                                $a['multi'] = '';