Add support for Number grouping(commafy) based on CLDR number grouping patterns like...
[lhc/web/wiklou.git] / includes / User.php
index 5685d9d..7df864f 100644 (file)
@@ -282,7 +282,7 @@ class User {
         * Load user table data, given mId has already been set.
         * @return Bool false if the ID does not exist, true otherwise
         */
-       private function loadFromId() {
+       public function loadFromId() {
                global $wgMemc;
                if ( $this->mId == 0 ) {
                        $this->loadDefaults();
@@ -859,7 +859,7 @@ class User {
         *
         * @param $name string
         */
-       private function loadDefaults( $name = false ) {
+       public function loadDefaults( $name = false ) {
                wfProfileIn( __METHOD__ );
 
                $this->mId = 0;
@@ -1016,7 +1016,7 @@ class User {
         *
         * @return Bool True if the user exists, false if the user is anonymous
         */
-       private function loadFromDatabase() {
+       public function loadFromDatabase() {
                # Paranoia
                $this->mId = intval( $this->mId );
 
@@ -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;
                }
@@ -1339,7 +1347,17 @@ class User {
 
                        foreach( (array)$bases as $base ) {
                                # Make hostname
-                               $host = "$ipReversed.$base";
+                               # If we have an access key, use that too (ProjectHoneypot, etc.)
+                               if( is_array( $base ) ) {
+                                       if( count( $base ) >= 2 ) {
+                                               # Access key is 1, base URL is 0
+                                               $host = "{$base[1]}.$ipReversed.{$base[0]}";
+                                       } else {
+                                               $host = "$ipReversed.{$base[0]}";
+                                       }
+                               } else {
+                                       $host = "$ipReversed.$base";
+                               }
 
                                # Send query
                                $ipList = gethostbynamel( $host );
@@ -1399,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.
@@ -1440,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 ) {
@@ -1514,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;
        }
 
        /**
@@ -1587,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 ) );
@@ -1665,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;
                }
@@ -2663,7 +2691,7 @@ class User {
         * Set this user's options from an encoded string
         * @param $str String Encoded options to import
         */
-       private function decodeOptions( $str ) {
+       public function decodeOptions( $str ) {
                if( !$str )
                        return;
 
@@ -2758,7 +2786,7 @@ class User {
         * Clear the user's cookies and session, and reset the instance cache.
         * @see logout()
         */
-       private function doLogout() {
+       public function doLogout() {
                $this->clearInstanceCache( 'defaults' );
 
                $this->getRequest()->setSessionData( 'wsUserID', 0 );
@@ -2923,7 +2951,7 @@ class User {
                        return;
                }
 
-               $userblock->doAutoblock( wfGetIP() );
+               $userblock->doAutoblock( $this->getRequest()->getIP() );
        }
 
        /**
@@ -2992,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
@@ -3208,7 +3236,7 @@ class User {
 
                return $this->sendMail( wfMsg( 'confirmemail_subject' ),
                        wfMsg( $message,
-                               wfGetIP(),
+                               $this->getRequest()->getIP(),
                                $this->getName(),
                                $url,
                                $wgLang->timeanddate( $expiration, false ),
@@ -3282,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
@@ -3295,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();
        }
 
        /**
@@ -3452,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();