Merge "Use Xml::element instead of Html::element for empty elements"
[lhc/web/wiklou.git] / includes / api / ApiQueryUserInfo.php
index ee5e458..6d70241 100644 (file)
@@ -31,6 +31,8 @@
  */
 class ApiQueryUserInfo extends ApiQueryBase {
 
+       const WL_UNREAD_LIMIT = 1000;
+
        private $prop = array();
 
        public function __construct( ApiQuery $query, $moduleName ) {
@@ -50,7 +52,6 @@ class ApiQueryUserInfo extends ApiQueryBase {
        }
 
        protected function getCurrentUserInfo() {
-               global $wgHiddenPrefs;
                $user = $this->getUser();
                $result = $this->getResult();
                $vals = array();
@@ -120,7 +121,7 @@ class ApiQueryUserInfo extends ApiQueryBase {
                        $vals['ratelimits'] = $this->getRateLimits();
                }
 
-               if ( isset( $this->prop['realname'] ) && !in_array( 'realname', $wgHiddenPrefs ) ) {
+               if ( isset( $this->prop['realname'] ) && !in_array( 'realname', $this->getConfig()->get( 'HiddenPrefs' ) ) ) {
                        $vals['realname'] = $user->getRealName();
                }
 
@@ -153,11 +154,32 @@ class ApiQueryUserInfo extends ApiQueryBase {
                        $vals['acceptlang'] = $acceptLang;
                }
 
+               if ( isset( $this->prop['unreadcount'] ) ) {
+                       $dbr = $this->getQuery()->getNamedDB( 'watchlist', DB_SLAVE, 'watchlist' );
+
+                       $sql = $dbr->selectSQLText(
+                               'watchlist',
+                               array( 'dummy' => 1 ),
+                               array(
+                                       'wl_user' => $user->getId(),
+                                       'wl_notificationtimestamp IS NOT NULL',
+                               ),
+                               __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;
+                       }
+               }
+
                return $vals;
        }
 
        protected function getRateLimits() {
-               global $wgRateLimits;
                $user = $this->getUser();
                if ( !$user->isPingLimitable() ) {
                        return array(); // No limits
@@ -181,7 +203,7 @@ class ApiQueryUserInfo extends ApiQueryBase {
 
                // Now get the actual limits
                $retval = array();
-               foreach ( $wgRateLimits as $action => $limits ) {
+               foreach ( $this->getConfig()->get( 'RateLimits' ) as $action => $limits ) {
                        foreach ( $categories as $cat ) {
                                if ( isset( $limits[$cat] ) && !is_null( $limits[$cat] ) ) {
                                        $retval[$action][$cat]['hits'] = intval( $limits[$cat][0] );
@@ -212,7 +234,8 @@ class ApiQueryUserInfo extends ApiQueryBase {
                                        'email',
                                        'realname',
                                        'acceptlang',
-                                       'registrationdate'
+                                       'registrationdate',
+                                       'unreadcount',
                                )
                        )
                );
@@ -237,63 +260,9 @@ class ApiQueryUserInfo extends ApiQueryBase {
                                '  acceptlang       - Echoes the Accept-Language header sent by ' .
                                        'the client in a structured format',
                                '  registrationdate - Adds the user\'s registration date',
-                       )
-               );
-       }
-
-       public function getResultProperties() {
-               return array(
-                       ApiBase::PROP_LIST => false,
-                       '' => array(
-                               'id' => 'integer',
-                               'name' => 'string',
-                               'anon' => 'boolean'
-                       ),
-                       'blockinfo' => array(
-                               'blockid' => array(
-                                       ApiBase::PROP_TYPE => 'integer',
-                                       ApiBase::PROP_NULLABLE => true
-                               ),
-                               'blockedby' => array(
-                                       ApiBase::PROP_TYPE => 'string',
-                                       ApiBase::PROP_NULLABLE => true
-                               ),
-                               'blockedbyid' => array(
-                                       ApiBase::PROP_TYPE => 'integer',
-                                       ApiBase::PROP_NULLABLE => true
-                               ),
-                               'blockedreason' => array(
-                                       ApiBase::PROP_TYPE => 'string',
-                                       ApiBase::PROP_NULLABLE => true
-                               )
-                       ),
-                       'hasmsg' => array(
-                               'messages' => 'boolean'
-                       ),
-                       'preferencestoken' => array(
-                               'preferencestoken' => 'string'
-                       ),
-                       'editcount' => array(
-                               'editcount' => 'integer'
-                       ),
-                       'realname' => array(
-                               'realname' => array(
-                                       ApiBase::PROP_TYPE => 'string',
-                                       ApiBase::PROP_NULLABLE => true
-                               )
-                       ),
-                       'email' => array(
-                               'email' => 'string',
-                               'emailauthenticated' => array(
-                                       ApiBase::PROP_TYPE => 'timestamp',
-                                       ApiBase::PROP_NULLABLE => true
-                               )
-                       ),
-                       'registrationdate' => array(
-                               'registrationdate' => array(
-                                       ApiBase::PROP_TYPE => 'timestamp',
-                                       ApiBase::PROP_NULLABLE => true
-                               )
+                               '  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)',
                        )
                );
        }