Merge "Set $wgMainWANCache to none for PHPUnit, as is done for $wgMainCacheType"
[lhc/web/wiklou.git] / includes / api / ApiQueryUserInfo.php
index 1e3a432..e003e31 100644 (file)
@@ -51,6 +51,31 @@ class ApiQueryUserInfo extends ApiQueryBase {
                $result->addValue( 'query', $this->getModuleName(), $r );
        }
 
+       /**
+        * Get basic info about a given block
+        * @param Block $block
+        * @return array Array containing several keys:
+        *  - blockid - ID of the block
+        *  - blockedby - username of the blocker
+        *  - blockedbyid - user ID of the blocker
+        *  - blockreason - reason provided for the block
+        *  - blockedtimestamp - timestamp for when the block was placed/modified
+        *  - blockexpiry - expiry time of the block
+        */
+       public static function getBlockInfo( Block $block ) {
+               global $wgContLang;
+               $vals = array();
+               $vals['blockid'] = $block->getId();
+               $vals['blockedby'] = $block->getByName();
+               $vals['blockedbyid'] = $block->getBy();
+               $vals['blockreason'] = $block->mReason;
+               $vals['blockedtimestamp'] = wfTimestamp( TS_ISO_8601, $block->mTimestamp );
+               $vals['blockexpiry'] = $wgContLang->formatExpiry(
+                       $block->getExpiry(), TS_ISO_8601, 'infinite'
+               );
+               return $vals;
+       }
+
        protected function getCurrentUserInfo() {
                $user = $this->getUser();
                $result = $this->getResult();
@@ -59,53 +84,47 @@ class ApiQueryUserInfo extends ApiQueryBase {
                $vals['name'] = $user->getName();
 
                if ( $user->isAnon() ) {
-                       $vals['anon'] = '';
+                       $vals['anon'] = true;
                }
 
-               if ( isset( $this->prop['blockinfo'] ) ) {
-                       if ( $user->isBlocked() ) {
-                               $block = $user->getBlock();
-                               $vals['blockid'] = $block->getId();
-                               $vals['blockedby'] = $block->getByName();
-                               $vals['blockedbyid'] = $block->getBy();
-                               $vals['blockreason'] = $user->blockedFor();
-                               $vals['blockedtimestamp'] = wfTimestamp( TS_ISO_8601, $block->mTimestamp );
-                               $vals['blockexpiry'] = $block->getExpiry() === 'infinity'
-                                       ? 'infinite'
-                                       : wfTimestamp( TS_ISO_8601, $block->getExpiry() );
-                       }
+               if ( isset( $this->prop['blockinfo'] ) && $user->isBlocked() ) {
+                       $vals = array_merge( $vals, self::getBlockInfo( $user->getBlock() ) );
                }
 
-               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();
-                       $result->setIndexedTagName( $vals['groups'], 'g' ); // even if empty
+                       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();
-                       $result->setIndexedTagName( $vals['implicitgroups'], 'g' ); // even if empty
+                       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() ) );
-                       $result->setIndexedTagName( $vals['rights'], 'r' ); // even if empty
+                       ApiResult::setArrayType( $vals['rights'], 'array' ); // even if empty
+                       ApiResult::setIndexedTagName( $vals['rights'], 'r' ); // even if empty
                }
 
                if ( isset( $this->prop['changeablegroups'] ) ) {
                        $vals['changeablegroups'] = $user->changeableGroups();
-                       $result->setIndexedTagName( $vals['changeablegroups']['add'], 'g' );
-                       $result->setIndexedTagName( $vals['changeablegroups']['remove'], 'g' );
-                       $result->setIndexedTagName( $vals['changeablegroups']['add-self'], 'g' );
-                       $result->setIndexedTagName( $vals['changeablegroups']['remove-self'], 'g' );
+                       ApiResult::setIndexedTagName( $vals['changeablegroups']['add'], 'g' );
+                       ApiResult::setIndexedTagName( $vals['changeablegroups']['remove'], 'g' );
+                       ApiResult::setIndexedTagName( $vals['changeablegroups']['add-self'], 'g' );
+                       ApiResult::setIndexedTagName( $vals['changeablegroups']['remove-self'], 'g' );
                }
 
                if ( isset( $this->prop['options'] ) ) {
                        $vals['options'] = $user->getOptions();
+                       $vals['options'][ApiResult::META_BC_BOOLS] = array_keys( $vals['options'] );
                }
 
                if ( isset( $this->prop['preferencestoken'] ) ) {
@@ -157,10 +176,10 @@ class ApiQueryUserInfo extends ApiQueryBase {
                        $acceptLang = array();
                        foreach ( $langs as $lang => $val ) {
                                $r = array( 'q' => $val );
-                               ApiResult::setContent( $r, $lang );
+                               ApiResult::setContentValue( $r, 'code', $lang );
                                $acceptLang[] = $r;
                        }
-                       $result->setIndexedTagName( $acceptLang, 'lang' );
+                       ApiResult::setIndexedTagName( $acceptLang, 'lang' );
                        $vals['acceptlang'] = $acceptLang;
                }
 
@@ -189,9 +208,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
@@ -211,7 +234,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] ) ) {
@@ -265,6 +287,6 @@ class ApiQueryUserInfo extends ApiQueryBase {
        }
 
        public function getHelpUrls() {
-               return 'https://www.mediawiki.org/wiki/API:Meta#userinfo_.2F_ui';
+               return 'https://www.mediawiki.org/wiki/API:Userinfo';
        }
 }