Followup r86622: add initial QUnit test cases for jquery.textSelection module.
[lhc/web/wiklou.git] / includes / api / ApiParamInfo.php
index 0108c8f..6ba115e 100644 (file)
@@ -1,11 +1,10 @@
 <?php
-
 /**
- * Created on Dec 01, 2007
  *
- * API for MediaWiki 1.8+
  *
- * Copyright © 2008 Roan Kattouw <Firstname>.<Lastname>@home.nl
+ * Created on Dec 01, 2007
+ *
+ * Copyright © 2008 Roan Kattouw <Firstname>.<Lastname>@gmail.com
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -21,6 +20,8 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
  */
 
 if ( !defined( 'MEDIAWIKI' ) ) {
@@ -69,6 +70,7 @@ class ApiParamInfo extends ApiBase {
                                $obj = new $qmodArr[$qm]( $this, $qm );
                                $a = $this->getClassInfo( $obj );
                                $a['name'] = $qm;
+                               $a['querytype'] = $queryObj->getModuleType( $qm );
                                $r['querymodules'][] = $a;
                        }
                        $result->setIndexedTagName( $r['querymodules'], 'module' );
@@ -83,10 +85,16 @@ class ApiParamInfo extends ApiBase {
                $result->addValue( null, $this->getModuleName(), $r );
        }
 
+       /**
+        * @param $obj ApiBase
+        * @return ApiResult
+        */
        function getClassInfo( $obj ) {
                $result = $this->getResult();
                $retval['classname'] = get_class( $obj );
                $retval['description'] = implode( "\n", (array)$obj->getDescription() );
+               $examples = (array)$obj->getExamples();
+               $retval['examples'] = implode( "\n", $examples );
                $retval['version'] = implode( "\n", (array)$obj->getVersion() );
                $retval['prefix'] = $obj->getModulePrefix();
 
@@ -108,6 +116,12 @@ class ApiParamInfo extends ApiBase {
                        return $retval;
                }
 
+               $retval['helpurls'] = (array)$obj->getHelpUrls();
+               $result->setIndexedTagName( $retval['helpurls'], 'helpurl' );
+
+               $retval['allexamples'] = $examples;
+               $result->setIndexedTagName( $retval['allexamples'], 'example' );
+
                $retval['parameters'] = array();
                $paramDesc = $obj->getFinalParamDescription();
                foreach ( $allowedParams as $n => $p ) {
@@ -115,45 +129,62 @@ 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 = isset( $p[ApiBase::PARAM_DFLT] ) ? $p[ApiBase::PARAM_DFLT] : null;
+                               if ( is_bool( $dflt ) ) {
+                                       $p[ApiBase::PARAM_TYPE] = 'boolean';
+                               } 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'] = '';
                        }
-                       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_REQUIRED] ) && $p[ApiBase::PARAM_REQUIRED] ) {
+                               $a['required'] = '';
                        }
 
                        if ( isset( $p[ApiBase::PARAM_DFLT] ) ) {
-                               $a['default'] = $p[ApiBase::PARAM_DFLT];
-                       }
-                       if ( isset( $p[ApiBase::PARAM_ISMULTI] ) ) {
-                               if ( $p[ApiBase::PARAM_ISMULTI] ) {
-                                       $a['multi'] = '';
-                                       $a['limit'] = $this->getMain()->canApiHighLimits() ?
-                                                       ApiBase::LIMIT_SML2 :
-                                                       ApiBase::LIMIT_SML1;
+                               $type = $p[ApiBase::PARAM_TYPE];
+                               if( $type === 'boolean' ) {
+                                       $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'] = '';
+                               $a['limit'] = $this->getMain()->canApiHighLimits() ?
+                                       ApiBase::LIMIT_SML2 :
+                                       ApiBase::LIMIT_SML1;
+                               $a['lowlimit'] = ApiBase::LIMIT_SML1;
+                               $a['highlimit'] = ApiBase::LIMIT_SML2;
+                       }
 
-                       if ( isset( $p[ApiBase::PARAM_ALLOW_DUPLICATES] ) ) {
-                               if ( $p[ApiBase::PARAM_ALLOW_DUPLICATES] ) {
-                                       $a['allowsduplicates'] = '';
-                               }
+                       if ( isset( $p[ApiBase::PARAM_ALLOW_DUPLICATES] ) && $p[ApiBase::PARAM_ALLOW_DUPLICATES] ) {
+                               $a['allowsduplicates'] = '';
                        }
 
                        if ( isset( $p[ApiBase::PARAM_TYPE] ) ) {
                                $a['type'] = $p[ApiBase::PARAM_TYPE];
                                if ( is_array( $a['type'] ) ) {
+                                       $a['type'] = array_values( $a['type'] ); // to prevent sparse arrays from being serialized to JSON as objects
                                        $result->setIndexedTagName( $a['type'], 't' );
                                }
                        }
@@ -172,7 +203,6 @@ class ApiParamInfo extends ApiBase {
 
                // Errors
                $retval['errors'] = $this->parseErrors( $obj->getPossibleErrors() );
-
                $result->setIndexedTagName( $retval['errors'], 'error' );
 
                return $retval;
@@ -214,6 +244,10 @@ class ApiParamInfo extends ApiBase {
                );
        }
 
+       public function getHelpUrls() {
+               return 'http://www.mediawiki.org/wiki/API:Parameter_information';
+       }
+
        public function getVersion() {
                return __CLASS__ . ': $Id$';
        }