Minor whitespace change.
[lhc/web/wiklou.git] / includes / User.php
index 9720283..63b1a6a 100644 (file)
@@ -248,7 +248,7 @@ class User {
                }
 
                if ( !$data ) {
-                       wfDebug( "Cache miss for user {$this->mId}\n" );
+                       wfDebug( "User: cache miss for user {$this->mId}\n" );
                        # Load from DB
                        if ( !$this->loadFromDatabase() ) {
                                # Can't load from ID, user is anonymous
@@ -256,7 +256,7 @@ class User {
                        }
                        $this->saveToCache();
                } else {
-                       wfDebug( "Got user {$this->mId} from cache\n" );
+                       wfDebug( "User: got user {$this->mId} from cache\n" );
                        # Restore from cache
                        foreach ( self::$mCacheVars as $name ) {
                                $this->$name = $data[$name];
@@ -601,18 +601,22 @@ class User {
         * @return mixed: true on success, string of error message on failure
         */
        function getPasswordValidity( $password ) {
-               global $wgMinimalPasswordLength, $wgContLang;
+               global $wgMinimalPasswordLength, $wgWeakPasswords, $wgContLang;
 
                $result = false; //init $result to false for the internal checks
 
                if( !wfRunHooks( 'isValidPassword', array( $password, &$result, $this ) ) )
                        return $result;
 
+               $lcPassword = $wgContLang->lc( $password );
+
                if ( $result === false ) {
                        if( strlen( $password ) < $wgMinimalPasswordLength ) {
                                return 'passwordtooshort';
-                       } elseif ( $wgContLang->lc( $password ) == $wgContLang->lc( $this->mName ) ) {
+                       } elseif ( $lcPassword == $wgContLang->lc( $this->mName ) ) {
                                return 'password-name-match';
+                       } elseif ( in_array( $lcPassword, $wgWeakPasswords ) ) {                        
+                               return 'password-too-weak';
                        } else {
                                //it seems weird returning true here, but this is because of the
                                //initialization of $result to false above. If the hook is never run or it
@@ -644,8 +648,19 @@ class User {
                if( !wfRunHooks( 'isValidEmailAddr', array( $addr, &$result ) ) ) {
                        return $result;
                }
+               $rfc5322_atext   = "a-z0-9!#$%&'*+-\/=?^_`{|}—~" ;
+               $rfc1034_ldh_str = "a-z0-9-" ;
+
+               $HTML5_email_regexp = "/
+               ^                      # start of string
+               [$rfc5322_atext\\.]+    # user part which is liberal :p
+               @                      # 'apostrophe'
+               [$rfc1034_ldh_str]+       # First domain part
+               (\\.[$rfc1034_ldh_str]+)+  # Following part prefixed with a dot
+               $                      # End of string
+               /ix" ; // case Insensitive, eXtended 
 
-               return strpos( $addr, '@' ) !== false;
+               return (bool) preg_match( $HTML5_email_regexp, $addr );
        }
 
        /**
@@ -678,7 +693,6 @@ class User {
                }
 
                # Reject various classes of invalid names
-               $name = $t->getText();
                global $wgAuth;
                $name = $wgAuth->getCanonicalName( $t->getText() );
 
@@ -890,11 +904,11 @@ class User {
 
                if ( ( $sName == $this->mName ) && $passwordCorrect ) {
                        $_SESSION['wsToken'] = $this->mToken;
-                       wfDebug( "Logged in from $from\n" );
+                       wfDebug( "User: logged in from $from\n" );
                        return true;
                } else {
                        # Invalid credentials
-                       wfDebug( "Can't log in from $from, invalid credentials\n" );
+                       wfDebug( "User: can't log in from $from, invalid credentials\n" );
                        $this->loadDefaults();
                        return false;
                }
@@ -1020,7 +1034,7 @@ class User {
                /**
                 * default language setting
                 */
-               $variant = $wgContLang->getPreferredVariant( false );
+               $variant = $wgContLang->getDefaultVariant();
                $defOpt['variant'] = $variant;
                $defOpt['language'] = $variant;
                foreach( SearchEngine::searchableNamespaces() as $nsnum => $nsname ) {
@@ -2244,16 +2258,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;
                }
        }
@@ -2264,8 +2278,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 {
@@ -2669,6 +2683,7 @@ class User {
         * which will give them a chance to modify this key based on their own
         * settings.
         *
+        * @deprecated use the ParserOptions object to get the relevant options
         * @return \string Page rendering hash
         */
        function getPageRenderingHash() {
@@ -2676,6 +2691,7 @@ class User {
                if( $this->mHash ){
                        return $this->mHash;
                }
+               wfDeprecated( __METHOD__ );
 
                // stubthreshold is only included below for completeness,
                // since it disables the parser cache, its value will always 
@@ -2941,12 +2957,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 );
        }
 
@@ -3615,12 +3632,12 @@ class User {
 
                // Maybe load from the object
                if ( !is_null( $this->mOptionOverrides ) ) {
-                       wfDebug( "Loading options for user " . $this->getId() . " from override cache.\n" );
+                       wfDebug( "User: loading options for user " . $this->getId() . " from override cache.\n" );
                        foreach( $this->mOptionOverrides as $key => $value ) {
                                $this->mOptions[$key] = $value;
                        }
                } else {
-                       wfDebug( "Loading options for user " . $this->getId() . " from database.\n" );
+                       wfDebug( "User: loading options for user " . $this->getId() . " from database.\n" );
                        // Load from database
                        $dbr = wfGetDB( DB_SLAVE );