Change API result data structure to be cleaner in new formats
[lhc/web/wiklou.git] / includes / api / ApiQueryUserInfo.php
index fd095fc..3d3590c 100644 (file)
@@ -61,7 +61,7 @@ class ApiQueryUserInfo extends ApiQueryBase {
                $vals['name'] = $user->getName();
 
                if ( $user->isAnon() ) {
-                       $vals['anon'] = '';
+                       $vals['anon'] = true;
                }
 
                if ( isset( $this->prop['blockinfo'] ) ) {
@@ -78,23 +78,26 @@ class ApiQueryUserInfo extends ApiQueryBase {
                        }
                }
 
-               if ( isset( $this->prop['hasmsg'] ) && $user->getNewtalk() ) {
-                       $vals['messages'] = '';
+               if ( isset( $this->prop['hasmsg'] ) ) {
+                       $vals['messages'] = $user->getNewtalk();
                }
 
                if ( isset( $this->prop['groups'] ) ) {
                        $vals['groups'] = $user->getEffectiveGroups();
+                       ApiResult::setArrayType( $vals['groups'], 'array' ); // even if empty
                        ApiResult::setIndexedTagName( $vals['groups'], 'g' ); // even if empty
                }
 
                if ( isset( $this->prop['implicitgroups'] ) ) {
                        $vals['implicitgroups'] = $user->getAutomaticGroups();
+                       ApiResult::setArrayType( $vals['implicitgroups'], 'array' ); // even if empty
                        ApiResult::setIndexedTagName( $vals['implicitgroups'], 'g' ); // even if empty
                }
 
                if ( isset( $this->prop['rights'] ) ) {
                        // User::getRights() may return duplicate values, strip them
                        $vals['rights'] = array_values( array_unique( $user->getRights() ) );
+                       ApiResult::setArrayType( $vals['rights'], 'array' ); // even if empty
                        ApiResult::setIndexedTagName( $vals['rights'], 'r' ); // even if empty
                }
 
@@ -108,6 +111,7 @@ class ApiQueryUserInfo extends ApiQueryBase {
 
                if ( isset( $this->prop['options'] ) ) {
                        $vals['options'] = $user->getOptions();
+                       $vals['options'][ApiResult::META_BC_BOOLS] = array_keys( $vals['options'] );
                }
 
                if ( isset( $this->prop['preferencestoken'] ) ) {
@@ -191,9 +195,13 @@ class ApiQueryUserInfo extends ApiQueryBase {
        }
 
        protected function getRateLimits() {
+               $retval = array(
+                       ApiResult::META_TYPE => 'assoc',
+               );
+
                $user = $this->getUser();
                if ( !$user->isPingLimitable() ) {
-                       return array(); // No limits
+                       return $retval; // No limits
                }
 
                // Find out which categories we belong to
@@ -213,7 +221,6 @@ class ApiQueryUserInfo extends ApiQueryBase {
                $categories = array_merge( $categories, $user->getGroups() );
 
                // Now get the actual limits
-               $retval = array();
                foreach ( $this->getConfig()->get( 'RateLimits' ) as $action => $limits ) {
                        foreach ( $categories as $cat ) {
                                if ( isset( $limits[$cat] ) && !is_null( $limits[$cat] ) ) {