Quick fix to categoriesHtml() given new skin changes
[lhc/web/wiklou.git] / includes / api / ApiQueryUserInfo.php
index 5fa4059..f6e9bad 100644 (file)
@@ -1,9 +1,8 @@
 <?php
-
 /**
- * Created on July 30, 2007
  *
- * API for MediaWiki 1.8+
+ *
+ * Created on July 30, 2007
  *
  * Copyright © 2007 Yuri Astrakhan <Firstname><Lastname>@gmail.com
  *
  *
  * You should have received a copy of the GNU General Public License along
  * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
  */
 
 if ( !defined( 'MEDIAWIKI' ) ) {
@@ -35,6 +36,8 @@ if ( !defined( 'MEDIAWIKI' ) ) {
  */
 class ApiQueryUserInfo extends ApiQueryBase {
 
+       private $prop = array();
+
        public function __construct( $query, $moduleName ) {
                parent::__construct( $query, $moduleName, 'ui' );
        }
@@ -42,19 +45,17 @@ class ApiQueryUserInfo extends ApiQueryBase {
        public function execute() {
                $params = $this->extractRequestParams();
                $result = $this->getResult();
-               $r = array();
 
                if ( !is_null( $params['prop'] ) ) {
                        $this->prop = array_flip( $params['prop'] );
-               } else {
-                       $this->prop = array();
                }
+
                $r = $this->getCurrentUserInfo();
                $result->addValue( 'query', $this->getModuleName(), $r );
        }
 
        protected function getCurrentUserInfo() {
-               global $wgUser;
+               global $wgUser, $wgRequest, $wgHiddenPrefs;
                $result = $this->getResult();
                $vals = array();
                $vals['id'] = intval( $wgUser->getId() );
@@ -76,7 +77,9 @@ class ApiQueryUserInfo extends ApiQueryBase {
                }
 
                if ( isset( $this->prop['groups'] ) ) {
-                       $vals['groups'] = $wgUser->getGroups();
+                       $autolist = ApiQueryUsers::getAutoGroups( $wgUser );
+
+                       $vals['groups'] = array_merge( $autolist, $wgUser->getGroups() );
                        $result->setIndexedTagName( $vals['groups'], 'g' );     // even if empty
                }
 
@@ -98,12 +101,10 @@ class ApiQueryUserInfo extends ApiQueryBase {
                        $vals['options'] = $wgUser->getOptions();
                }
 
-               if (
-                       isset( $this->prop['preferencestoken'] ) &&
+               if ( isset( $this->prop['preferencestoken'] ) &&
                        is_null( $this->getMain()->getRequest()->getVal( 'callback' ) )
-               )
-               {
-                       $vals['preferencestoken'] = $wgUser->editToken();
+               ) {
+                       $vals['preferencestoken'] = $wgUser->editToken( '', $this->getMain()->getRequest() );
                }
 
                if ( isset( $this->prop['editcount'] ) ) {
@@ -114,6 +115,10 @@ class ApiQueryUserInfo extends ApiQueryBase {
                        $vals['ratelimits'] = $this->getRateLimits();
                }
 
+               if ( isset( $this->prop['realname'] ) && !in_array( 'realname', $wgHiddenPrefs ) ) {
+                       $vals['realname'] = $wgUser->getRealName();
+               }
+
                if ( isset( $this->prop['email'] ) ) {
                        $vals['email'] = $wgUser->getEmail();
                        $auth = $wgUser->getEmailAuthenticationTimestamp();
@@ -121,47 +126,19 @@ class ApiQueryUserInfo extends ApiQueryBase {
                                $vals['emailauthenticated'] = wfTimestamp( TS_ISO_8601, $auth );
                        }
                }
-               
+
                if ( isset( $this->prop['acceptlang'] ) ) {
-                       $vals['acceptlang'] = $this->getAcceptLang();
-                       $result->setIndexedTagName( $vals['acceptlang'], 'lang' );
-               }
-               return $vals;
-       }
-       
-       protected function getAcceptLang() {
-               // Modified version of code found at http://www.thefutureoftheweb.com/blog/use-accept-language-header
-               if ( !isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) {
-                       return array();
-               }
-               
-               // Break up string into pieces (languages and q factors)
-               $lang_parse = null;
-               preg_match_all( '/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0(\.[0-9]+))?)?/i',
-                       $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse );
-               
-               if ( !count( $lang_parse[1] ) ) {
-                       return array();
-               }
-               // Create a list like "en" => 0.8
-               $langs = array_combine( $lang_parse[1], $lang_parse[4] );
-               // Set default q factor to 1
-               foreach ( $langs as $lang => $val ) {
-                       if ( $val === '' ) {
-                               $langs[$lang] = 1;
+                       $langs = $wgRequest->getAcceptLang();
+                       $acceptLang = array();
+                       foreach ( $langs as $lang => $val ) {
+                               $r = array( 'q' => $val );
+                               ApiResult::setContent( $r, $lang );
+                               $acceptLang[] = $r;
                        }
+                       $result->setIndexedTagName( $acceptLang, 'lang' );
+                       $vals['acceptlang'] = $acceptLang;
                }
-               // Sort list
-               arsort( $langs, SORT_NUMERIC );
-               
-               // Format for API output
-               $retval = array();
-               foreach ( $langs as $lang => $val ) {
-                       $r = array( 'q' => $val );
-                       ApiResult::setContent( $r, $lang );
-                       $retval[] = $r;
-               }
-               return $retval;
+               return $vals;
        }
 
        protected function getRateLimits() {
@@ -214,6 +191,7 @@ class ApiQueryUserInfo extends ApiQueryBase {
                                        'editcount',
                                        'ratelimits',
                                        'email',
+                                       'realname',
                                        'acceptlang',
                                )
                        )
@@ -224,16 +202,18 @@ class ApiQueryUserInfo extends ApiQueryBase {
                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',
-                               '  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',
-                               '  editcount  - adds the current user\'s edit count',
-                               '  ratelimits - lists all rate limits applying to the current user',
-                               '  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',
+                               '  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',
+                               '  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 - 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',
                        )
                );
        }