(bug 31363) Expand description URLs for thumbnails to canonical form
[lhc/web/wiklou.git] / includes / User.php
index b011be4..ef724c4 100644 (file)
@@ -1053,6 +1053,8 @@ class User {
        public function loadFromRow( $row ) {
                $all = true;
 
+               $this->mGroups = null; // deferred
+
                if ( isset( $row->user_name ) ) {
                        $this->mName = $row->user_name;
                        $this->mFrom = 'name';
@@ -1076,19 +1078,26 @@ 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;
                        $this->mNewpassTime = wfTimestampOrNull( TS_MW, $row->user_newpass_time );
                        $this->mEmail = $row->user_email;
-                       $this->decodeOptions( $row->user_options );
-                       $this->mTouched = wfTimestamp(TS_MW,$row->user_touched);
+                       if ( isset( $row->user_options ) ) {
+                               $this->decodeOptions( $row->user_options );
+                       }
+                       $this->mTouched = wfTimestamp( TS_MW, $row->user_touched );
                        $this->mToken = $row->user_token;
                        $this->mEmailAuthenticated = wfTimestampOrNull( TS_MW, $row->user_email_authenticated );
                        $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 +1169,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 +1218,8 @@ class User {
                }
                $defOpt['skin'] = $wgDefaultSkin;
 
+               wfRunHooks( 'UserGetDefaultOptions', array( &$defOpt ) );
+
                return $defOpt;
        }
 
@@ -1259,7 +1271,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 +1421,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 +1462,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 +1536,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 +1619,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 +1697,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;
                }
@@ -2294,6 +2316,7 @@ class User {
         */
        public function getGroups() {
                $this->load();
+               $this->loadGroups();
                return $this->mGroups;
        }
 
@@ -2672,6 +2695,8 @@ class User {
        /**
         * Set this user's options from an encoded string
         * @param $str String Encoded options to import
+        *
+        * @deprecated in 1.19 due to removal of user_options from the user table
         */
        private function decodeOptions( $str ) {
                if( !$str )
@@ -2801,7 +2826,6 @@ class User {
                                'user_real_name' => $this->mRealName,
                                'user_email' => $this->mEmail,
                                'user_email_authenticated' => $dbw->timestampOrNull( $this->mEmailAuthenticated ),
-                               'user_options' => '',
                                'user_touched' => $dbw->timestamp( $this->mTouched ),
                                'user_token' => $this->mToken,
                                'user_email_token' => $this->mEmailToken,
@@ -2869,7 +2893,6 @@ class User {
                        'user_email' => $user->mEmail,
                        'user_email_authenticated' => $dbw->timestampOrNull( $user->mEmailAuthenticated ),
                        'user_real_name' => $user->mRealName,
-                       'user_options' => '',
                        'user_token' => $user->mToken,
                        'user_registration' => $dbw->timestamp( $user->mRegistration ),
                        'user_editcount' => 0,
@@ -2903,7 +2926,6 @@ class User {
                                'user_email' => $this->mEmail,
                                'user_email_authenticated' => $dbw->timestampOrNull( $this->mEmailAuthenticated ),
                                'user_real_name' => $this->mRealName,
-                               'user_options' => '',
                                'user_token' => $this->mToken,
                                'user_registration' => $dbw->timestamp( $this->mRegistration ),
                                'user_editcount' => 0,
@@ -2933,7 +2955,7 @@ class User {
                        return;
                }
 
-               $userblock->doAutoblock( wfGetIP() );
+               $userblock->doAutoblock( $this->getRequest()->getIP() );
        }
 
        /**
@@ -3002,7 +3024,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 +3240,7 @@ class User {
 
                return $this->sendMail( wfMsg( 'confirmemail_subject' ),
                        wfMsg( $message,
-                               wfGetIP(),
+                               $this->getRequest()->getIP(),
                                $this->getName(),
                                $url,
                                $wgLang->timeanddate( $expiration, false ),
@@ -3292,7 +3314,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 +3327,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 +3481,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();
 
@@ -3894,7 +3913,7 @@ class User {
         * @param $byEmail Boolean: account made by email?
         * @param $reason String: user supplied reason
         *
-        * @return true
+        * @return int|bool True if not $wgNewUserLog; otherwise ID of log item or 0 on failure
         */
        public function addNewUserLogEntry( $byEmail = false, $reason = '' ) {
                global $wgUser, $wgContLang, $wgNewUserLog;
@@ -3916,13 +3935,12 @@ class User {
                        }
                }
                $log = new LogPage( 'newusers' );
-               $log->addEntry(
+               return (int)$log->addEntry(
                        $action,
                        $this->getUserPage(),
                        $reason,
                        array( $this->getId() )
                );
-               return true;
        }
 
        /**