Merge "Fix variable name and use isset() to shut up a stupid notice"
[lhc/web/wiklou.git] / includes / api / ApiQueryUserInfo.php
index fd5f47b..fd095fc 100644 (file)
@@ -52,6 +52,8 @@ class ApiQueryUserInfo extends ApiQueryBase {
        }
 
        protected function getCurrentUserInfo() {
+               global $wgContLang;
+
                $user = $this->getUser();
                $result = $this->getResult();
                $vals = array();
@@ -70,9 +72,9 @@ class ApiQueryUserInfo extends ApiQueryBase {
                                $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() );
+                               $vals['blockexpiry'] = $wgContLang->formatExpiry(
+                                       $block->getExpiry(), TS_ISO_8601, 'infinite'
+                               );
                        }
                }
 
@@ -82,26 +84,26 @@ class ApiQueryUserInfo extends ApiQueryBase {
 
                if ( isset( $this->prop['groups'] ) ) {
                        $vals['groups'] = $user->getEffectiveGroups();
-                       $result->setIndexedTagName( $vals['groups'], 'g' ); // 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::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::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'] ) ) {
@@ -115,7 +117,7 @@ class ApiQueryUserInfo extends ApiQueryBase {
                        );
                }
                if ( isset( $this->prop['preferencestoken'] ) &&
-                       is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) &&
+                       !$this->lacksSameOriginSecurity() &&
                        $user->isAllowed( 'editmyoptions' )
                ) {
                        $vals['preferencestoken'] = $user->getEditToken( '', $this->getMain()->getRequest() );
@@ -157,19 +159,19 @@ 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;
                }
 
                if ( isset( $this->prop['unreadcount'] ) ) {
                        $dbr = $this->getQuery()->getNamedDB( 'watchlist', DB_SLAVE, 'watchlist' );
 
-                       $sql = $dbr->selectSQLText(
+                       $count = $dbr->selectRowCount(
                                'watchlist',
-                               array( 'dummy' => 1 ),
+                               '1',
                                array(
                                        'wl_user' => $user->getId(),
                                        'wl_notificationtimestamp IS NOT NULL',
@@ -177,12 +179,11 @@ class ApiQueryUserInfo extends ApiQueryBase {
                                __METHOD__,
                                array( 'LIMIT' => self::WL_UNREAD_LIMIT )
                        );
-                       $count = $dbr->selectField( array( 'c' => "($sql)" ), 'COUNT(*)' );
 
                        if ( $count >= self::WL_UNREAD_LIMIT ) {
                                $vals['unreadcount'] = self::WL_UNREAD_LIMIT . '+';
                        } else {
-                               $vals['unreadcount'] = (int)$count;
+                               $vals['unreadcount'] = $count;
                        }
                }
 
@@ -246,45 +247,22 @@ class ApiQueryUserInfo extends ApiQueryBase {
                                        'acceptlang',
                                        'registrationdate',
                                        'unreadcount',
-                               )
-                       )
-               );
-       }
-
-       public function getParamDescription() {
-               return array(
-                       'prop' => array(
-                               'What pieces of information to include',
-                               '  blockinfo        - Tags if the current user is blocked, by whom, and for what reason',
-                               '  hasmsg           - Adds a tag "message" if the current user has pending messages',
-                               '  groups           - Lists all the groups the current user belongs to',
-                               '  implicitgroups   - Lists all the groups the current user is automatically a member of',
-                               '  rights           - Lists all the rights the current user has',
-                               '  changeablegroups - Lists the groups the current user can add to and remove from',
-                               '  options          - Lists all preferences the current user has set',
-                               '  preferencestoken - DEPRECATED! Get a token to change current user\'s preferences',
-                               '  editcount        - Adds the current user\'s edit count',
-                               '  ratelimits       - Lists all rate limits applying to the current user',
-                               '  realname         - Adds the user\'s real name',
-                               '  email            - Adds the user\'s email address and email authentication date',
-                               '  acceptlang       - Echoes the Accept-Language header sent by ' .
-                                       'the client in a structured format',
-                               '  registrationdate - Adds the user\'s registration date',
-                               '  unreadcount      - Adds the count of unread pages on the user\'s watchlist ' .
-                                       '(maximum ' . ( self::WL_UNREAD_LIMIT - 1 ) . '; returns "' .
-                                       self::WL_UNREAD_LIMIT . '+" if more)',
+                               ),
+                               ApiBase::PARAM_HELP_MSG => array(
+                                       'apihelp-query+userinfo-param-prop',
+                                       self::WL_UNREAD_LIMIT - 1,
+                                       self::WL_UNREAD_LIMIT . '+',
+                               ),
                        )
                );
        }
 
-       public function getDescription() {
-               return 'Get information about the current user.';
-       }
-
-       public function getExamples() {
+       protected function getExamplesMessages() {
                return array(
-                       'api.php?action=query&meta=userinfo',
-                       'api.php?action=query&meta=userinfo&uiprop=blockinfo|groups|rights|hasmsg',
+                       'action=query&meta=userinfo'
+                               => 'apihelp-query+userinfo-example-simple',
+                       'action=query&meta=userinfo&uiprop=blockinfo|groups|rights|hasmsg'
+                               => 'apihelp-query+userinfo-example-data',
                );
        }