Add support for Number grouping(commafy) based on CLDR number grouping patterns like...
[lhc/web/wiklou.git] / includes / User.php
index f353e09..7df864f 100644 (file)
@@ -1076,6 +1076,12 @@ class User {
                        $all = false;
                }
 
+               if ( isset( $row->user_editcount ) ) {
+                       $this->mEditCount = $row->user_editcount;
+               } else {
+                       $all = false;
+               }
+
                if ( isset( $row->user_password ) ) {
                        $this->mPassword = $row->user_password;
                        $this->mNewpassword = $row->user_newpassword;
@@ -1088,7 +1094,6 @@ class User {
                        $this->mEmailToken = $row->user_email_token;
                        $this->mEmailTokenExpires = wfTimestampOrNull( TS_MW, $row->user_email_token_expires );
                        $this->mRegistration = wfTimestampOrNull( TS_MW, $row->user_registration );
-                       $this->mEditCount = $row->user_editcount;
                } else {
                        $all = false;
                }
@@ -1160,6 +1165,7 @@ class User {
                                $log->addEntry( 'autopromote',
                                        $this->getUserPage(),
                                        '', // no comment
+                                       // These group names are "list to texted"-ed in class LogPage.
                                        array( implode( ', ', $oldGroups ), implode( ', ', $newGroups ) )
                                );
                        }
@@ -1208,6 +1214,8 @@ class User {
                }
                $defOpt['skin'] = $wgDefaultSkin;
 
+               wfRunHooks( 'UserGetDefaultOptions', array( &$defOpt ) );
+
                return $defOpt;
        }
 
@@ -1259,7 +1267,7 @@ class User {
                # user is not immune to autoblocks/hardblocks, and they are the current user so we
                # know which IP address they're actually coming from
                if ( !$this->isAllowed( 'ipblock-exempt' ) && $this->getID() == $wgUser->getID() ) {
-                       $ip = wfGetIP();
+                       $ip = $this->getRequest()->getIP();
                } else {
                        $ip = null;
                }
@@ -1409,7 +1417,7 @@ class User {
         */
        public function isPingLimitable() {
                global $wgRateLimitsExcludedIPs;
-               if( in_array( wfGetIP(), $wgRateLimitsExcludedIPs ) ) {
+               if( in_array( $this->getRequest()->getIP(), $wgRateLimitsExcludedIPs ) ) {
                        // No other good way currently to disable rate limits
                        // for specific IPs. :P
                        // But this is a crappy hack and should die.
@@ -1450,7 +1458,7 @@ class User {
                $limits = $wgRateLimits[$action];
                $keys = array();
                $id = $this->getId();
-               $ip = wfGetIP();
+               $ip = $this->getRequest()->getIP();
                $userLimit = false;
 
                if( isset( $limits['anon'] ) && $id == 0 ) {
@@ -1524,8 +1532,18 @@ class User {
         * @return Bool True if blocked, false otherwise
         */
        public function isBlocked( $bFromSlave = true ) { // hacked from false due to horrible probs on site
+               return $this->getBlock( $bFromSlave ) instanceof Block && $this->getBlock()->prevents( 'edit' );
+       }
+
+       /**
+        * Get the block affecting the user, or null if the user is not blocked
+        *
+        * @param $bFromSlave Bool Whether to check the slave database instead of the master
+        * @return Block|null
+        */
+       public function getBlock( $bFromSlave = true ){
                $this->getBlockedStatus( $bFromSlave );
-               return $this->mBlock instanceof Block && $this->mBlock->prevents( 'edit' );
+               return $this->mBlock instanceof Block ? $this->mBlock : null;
        }
 
        /**
@@ -1597,7 +1615,7 @@ class User {
                if( IP::isIPAddress( $this->getName() ) ) {
                        $ip = $this->getName();
                } elseif( !$ip ) {
-                       $ip = wfGetIP();
+                       $ip = $this->getRequest()->getIP();
                }
                $blocked = false;
                wfRunHooks( 'UserIsBlockedGlobally', array( &$this, $ip, &$blocked ) );
@@ -1675,7 +1693,7 @@ class User {
                        $this->load();
                        if ( $this->mName === false ) {
                                # Clean up IPs
-                               $this->mName = IP::sanitizeIP( wfGetIP() );
+                               $this->mName = IP::sanitizeIP( $this->getRequest()->getIP() );
                        }
                        return $this->mName;
                }
@@ -2933,7 +2951,7 @@ class User {
                        return;
                }
 
-               $userblock->doAutoblock( wfGetIP() );
+               $userblock->doAutoblock( $this->getRequest()->getIP() );
        }
 
        /**
@@ -3002,7 +3020,7 @@ class User {
                # blocked with createaccount disabled, prevent new account creation there even
                # when the user is logged in
                if( $this->mBlockedFromCreateAccount === false ){
-                       $this->mBlockedFromCreateAccount = Block::newFromTarget( null, wfGetIP() );
+                       $this->mBlockedFromCreateAccount = Block::newFromTarget( null, $this->getRequest()->getIP() );
                }
                return $this->mBlockedFromCreateAccount instanceof Block && $this->mBlockedFromCreateAccount->prevents( 'createaccount' )
                        ? $this->mBlockedFromCreateAccount
@@ -3218,7 +3236,7 @@ class User {
 
                return $this->sendMail( wfMsg( 'confirmemail_subject' ),
                        wfMsg( $message,
-                               wfGetIP(),
+                               $this->getRequest()->getIP(),
                                $this->getName(),
                                $url,
                                $wgLang->timeanddate( $expiration, false ),
@@ -3292,7 +3310,7 @@ class User {
 
        /**
         * Internal function to format the e-mail validation/invalidation URLs.
-        * This uses $wgArticlePath directly as a quickie hack to use the
+        * This uses a quickie hack to use the
         * hardcoded English names of the Special: pages, for ASCII safety.
         *
         * @note Since these URLs get dropped directly into emails, using the
@@ -3305,12 +3323,9 @@ class User {
         * @return String Formatted URL
         */
        protected function getTokenUrl( $page, $token ) {
-               global $wgArticlePath;
-               return wfExpandUrl(
-                       str_replace(
-                               '$1',
-                               "Special:$page/$token",
-                               $wgArticlePath ) );
+               // Hack to bypass localization of 'Special:'
+               $title = Title::makeTitle( NS_MAIN, "Special:$page/$token" );
+               return $title->getCanonicalUrl();
        }
 
        /**
@@ -3462,7 +3477,7 @@ class User {
         *
         * @return Array of Strings List of permission key names for given groups combined
         */
-       public static function getGroupPermissions( $groups, $ns = null ) {
+       public static function getGroupPermissions( array $groups, $ns = null ) {
                global $wgGroupPermissions, $wgRevokePermissions;
                $rights = array();