removed debug statement
[lhc/web/wiklou.git] / includes / User.php
index 25e0e52..7e77986 100644 (file)
@@ -301,7 +301,7 @@ class User {
         *    User::getCanonicalName(), except that true is accepted as an alias
         *    for 'valid', for BC.
         *
-        * @return \type{User} The User object, or false if the username is invalid 
+        * @return User The User object, or false if the username is invalid
         *    (e.g. if it contains illegal characters or is an IP address). If the
         *    username is not present in the database, the result will be a user object
         *    with a name, zero user ID and default settings.
@@ -655,8 +655,8 @@ class User {
                ^                      # start of string
                [$rfc5322_atext\\.]+    # user part which is liberal :p
                @                      # 'apostrophe'
-               [$rfc1034_ldh_str]     # Domain first character
-               [$rfc1034_ldh_str\\.]+  # Second char and following can include dot
+               [$rfc1034_ldh_str]+       # First domain part
+               (\\.[$rfc1034_ldh_str]+)+  # Following part prefixed with a dot
                $                      # End of string
                /ix" ; // case Insensitive, eXtended 
 
@@ -1224,34 +1224,10 @@ class User {
                        // Deprecated, but kept for backwards-compatibility config
                        return false;
                }
-
-               wfDebug( "Checking the list of IP addresses excluded from rate limit..\n" );
-
-               // Read list of IP addresses from MediaWiki namespace
-               $message = wfMsgForContentNoTrans( 'ratelimit-excluded-ips' );
-               $lines = explode( "\n", $message );
-               foreach( $lines as $line ) {
-                       // Remove comment lines
-                       $comment = substr( trim( $line ), 0, 1 );
-                       if ( $comment == '#' || $comment == '' ) {
-                               continue;
-                       }
-                       // Remove additional comments after an IP address
-                       $comment = strpos( $line, '#' );
-                       if ( $comment > 0 ) {
-                               $line = trim( substr( $line, 0, $comment-1 ) );
-                               if ( IP::isValid( $line ) ) {
-                                       $wgRateLimitsExcludedIPs[] = IP::sanitizeIP( $line );
-                               }
-                       }
-               }
-
-               $ip = IP::sanitizeIP( wfGetIP() );
-               if( in_array( $ip, $wgRateLimitsExcludedIPs ) ) {
+               if( in_array( wfGetIP(), $wgRateLimitsExcludedIPs ) ) {
                        // No other good way currently to disable rate limits
                        // for specific IPs. :P
                        // But this is a crappy hack and should die.
-                       wfDebug( "IP $ip matches the list of rate limit excluded IPs\n" );
                        return false;
                }
                return !$this->isAllowed('noratelimit');
@@ -1480,7 +1456,7 @@ class User {
 
        /**
         * Get the user's ID.
-        * @return \int The user's ID; 0 if the user is anonymous or nonexistent
+        * @return Integer The user's ID; 0 if the user is anonymous or nonexistent
         */
        function getId() {
                if( $this->mId === null and $this->mName !== null
@@ -2212,11 +2188,12 @@ class User {
        /**
         * Check if user is allowed to access a feature / make an action
         * @param $action \string action to be checked
-        * @return \bool True if action is allowed, else false
+        * @return Boolean: True if action is allowed, else false
         */
        function isAllowed( $action = '' ) {
-               if ( $action === '' )
+               if ( $action === '' ) {
                        return true; // In the spirit of DWIM
+               }
                # Patrolling may not be enabled
                if( $action === 'patrol' || $action === 'autopatrol' ) {
                        global $wgUseRCPatrol, $wgUseNPPatrol;
@@ -2230,7 +2207,7 @@ class User {
 
        /**
         * Check whether to enable recent changes patrol features for this user
-        * @return \bool True or false
+        * @return Boolean: True or false
         */
        public function useRCPatrol() {
                global $wgUseRCPatrol;
@@ -2258,16 +2235,16 @@ class User {
                        $skin->setTitle( $t );
                        return $skin;
                } else {
-                       if ( ! $this->mSkin ) {
+                       if ( !$this->mSkin ) {
                                $this->mSkin = $this->createSkinObject();
                        }
-                       
-                       if ( ! $this->mSkin->getTitle() ) {
+
+                       if ( !$this->mSkin->getTitle() ) {
                                global $wgOut;
                                $t = $wgOut->getTitle();
                                $this->mSkin->setTitle($t);
                        }
-                       
+
                        return $this->mSkin;
                }
        }
@@ -2278,8 +2255,8 @@ class User {
 
                global $wgHiddenPrefs;
                if( !in_array( 'skin', $wgHiddenPrefs ) ) {
-                       # get the user skin
                        global $wgRequest;
+                       # get the user skin
                        $userSkin = $this->getOption( 'skin' );
                        $userSkin = $wgRequest->getVal( 'useskin', $userSkin );
                } else {
@@ -2596,12 +2573,13 @@ class User {
                }
                $dbw = wfGetDB( DB_MASTER );
                $seqVal = $dbw->nextSequenceValue( 'user_user_id_seq' );
+
                $fields = array(
                        'user_id' => $seqVal,
                        'user_name' => $name,
                        'user_password' => $user->mPassword,
                        'user_newpassword' => $user->mNewpassword,
-                       'user_newpass_time' => $dbw->timestamp( $user->mNewpassTime ),
+                       'user_newpass_time' => $dbw->timestampOrNull( $user->mNewpassTime ),
                        'user_email' => $user->mEmail,
                        'user_email_authenticated' => $dbw->timestampOrNull( $user->mEmailAuthenticated ),
                        'user_real_name' => $user->mRealName,
@@ -2635,7 +2613,7 @@ class User {
                                'user_name' => $this->mName,
                                'user_password' => $this->mPassword,
                                'user_newpassword' => $this->mNewpassword,
-                               'user_newpass_time' => $dbw->timestamp( $this->mNewpassTime ),
+                               'user_newpass_time' => $dbw->timestampOrNull( $this->mNewpassTime ),
                                'user_email' => $this->mEmail,
                                'user_email_authenticated' => $dbw->timestampOrNull( $this->mEmailAuthenticated ),
                                'user_real_name' => $this->mRealName,
@@ -2735,7 +2713,7 @@ class User {
 
        /**
         * Get whether the user is blocked from using Special:Emailuser.
-        * @return \bool True if blocked
+        * @return Boolean: True if blocked
         */
        function isBlockedFromEmailuser() {
                $this->getBlockedStatus();
@@ -2744,7 +2722,7 @@ class User {
 
        /**
         * Get whether the user is allowed to create an account.
-        * @return \bool True if allowed
+        * @return Boolean: True if allowed
         */
        function isAllowedToCreateAccount() {
                return $this->isAllowed( 'createaccount' ) && !$this->isBlockedFromCreateAccount();
@@ -2753,7 +2731,7 @@ class User {
        /**
         * Get this user's personal page title.
         *
-        * @return \type{Title} User's personal page title
+        * @return Title: User's personal page title
         */
        function getUserPage() {
                return Title::makeTitle( NS_USER, $this->getName() );
@@ -2762,7 +2740,7 @@ class User {
        /**
         * Get this user's talk page title.
         *
-        * @return \type{Title} User's talk page title
+        * @return Title: User's talk page title
         */
        function getTalkPage() {
                $title = $this->getUserPage();
@@ -2771,7 +2749,7 @@ class User {
 
        /**
         * Get the maximum valid user ID.
-        * @return \int User ID
+        * @return Integer: User ID
         * @static
         */
        function getMaxID() {
@@ -2788,7 +2766,7 @@ class User {
        /**
         * Determine whether the user is a newbie. Newbies are either
         * anonymous IPs, or the most recently created accounts.
-        * @return \bool True if the user is a newbie
+        * @return Boolean: True if the user is a newbie
         */
        function isNewbie() {
                return !$this->isAllowed( 'autoconfirmed' );
@@ -2796,22 +2774,13 @@ class User {
 
        /**
         * Check to see if the given clear-text password is one of the accepted passwords
-        * @param $password \string user password.
-        * @return \bool True if the given password is correct, otherwise False.
+        * @param $password String: user password.
+        * @return Boolean: True if the given password is correct, otherwise False.
         */
        function checkPassword( $password ) {
                global $wgAuth;
                $this->load();
 
-               // Even though we stop people from creating passwords that
-               // are shorter than this, doesn't mean people wont be able
-               // to. Certain authentication plugins do NOT want to save
-               // domain passwords in a mysql database, so we should
-               // check this (incase $wgAuth->strict() is false).
-               if( !$this->isValidPassword( $password ) ) {
-                       return false;
-               }
-
                if( $wgAuth->authenticate( $this->getName(), $password ) ) {
                        return true;
                } elseif( $wgAuth->strict() ) {
@@ -2837,7 +2806,7 @@ class User {
        /**
         * Check if the given clear-text password matches the temporary password
         * sent by e-mail for password reset operations.
-        * @return \bool True if matches, false otherwise
+        * @return Boolean: True if matches, false otherwise
         */
        function checkTemporaryPassword( $plaintext ) {
                global $wgNewPasswordExpiry;
@@ -2895,7 +2864,7 @@ class User {
         *
         * @param $val \string Input value to compare
         * @param $salt \string Optional function-specific data for hashing
-        * @return \bool Whether the token matches
+        * @return Boolean: Whether the token matches
         */
        function matchEditToken( $val, $salt = '' ) {
                $sessionToken = $this->editToken( $salt );
@@ -2911,7 +2880,7 @@ class User {
         *
         * @param $val \string Input value to compare
         * @param $salt \string Optional function-specific data for hashing
-        * @return \bool Whether the token matches
+        * @return Boolean: Whether the token matches
         */
        function matchEditTokenNoSuffix( $val, $salt = '' ) {
                $sessionToken = $this->editToken( $salt );
@@ -2957,12 +2926,13 @@ class User {
         */
        function sendMail( $subject, $body, $from = null, $replyto = null ) {
                if( is_null( $from ) ) {
-                       global $wgPasswordSender;
-                       $from = $wgPasswordSender;
+                       global $wgPasswordSender, $wgPasswordSenderName;
+                       $sender = new MailAddress( $wgPasswordSender, $wgPasswordSenderName );
+               } else {
+                       $sender = new MailAddress( $from );
                }
 
                $to = new MailAddress( $this );
-               $sender = new MailAddress( $from );
                return UserMailer::send( $to, $sender, $subject, $body, $replyto );
        }
 
@@ -3071,7 +3041,7 @@ class User {
        /**
         * Is this user allowed to send e-mails within limits of current
         * site configuration?
-        * @return \bool True if allowed
+        * @return Boolean: True if allowed
         */
        function canSendEmail() {
                global $wgEnableEmail, $wgEnableUserEmail;
@@ -3086,7 +3056,7 @@ class User {
        /**
         * Is this user allowed to receive e-mails within limits of current
         * site configuration?
-        * @return \bool True if allowed
+        * @return Boolean: True if allowed
         */
        function canReceiveEmail() {
                return $this->isEmailConfirmed() && !$this->getOption( 'disablemail' );
@@ -3100,7 +3070,7 @@ class User {
         * confirmed their address by returning a code or using a password
         * sent to the address from the wiki.
         *
-        * @return \bool True if confirmed
+        * @return Boolean: True if confirmed
         */
        function isEmailConfirmed() {
                global $wgEmailAuthentication;
@@ -3121,7 +3091,7 @@ class User {
 
        /**
         * Check whether there is an outstanding request for e-mail confirmation.
-        * @return \bool True if pending
+        * @return Boolean: True if pending
         */
        function isEmailConfirmationPending() {
                global $wgEmailAuthentication;
@@ -3550,7 +3520,7 @@ class User {
         * @param $hash \string Password hash
         * @param $password \string Plain-text password to compare
         * @param $userId \string User ID for old-style password salt
-        * @return \bool
+        * @return Boolean:
         */
        static function comparePasswords( $hash, $password, $userId = false ) {
                $type = substr( $hash, 0, 3 );