* Allow wiki links in "protect-robotspolicy", I imagine people are likely to want...
[lhc/web/wiklou.git] / includes / User.php
index d0c2db6..9b62e2d 100644 (file)
@@ -24,7 +24,14 @@ class PasswordError extends MWException {
 }
 
 /**
- *
+ * The User object encapsulates all of the user-specific settings (user_id,
+ * name, rights, password, email address, options, last login time). Client
+ * classes use the getXXX() functions to access these fields. These functions
+ * do all the work of determining whether the user is logged in,
+ * whether the requested option can be satisfied from cookies or
+ * whether a database query is needed. Most of the settings needed
+ * for rendering normal pages are set in the cookie to minimize use
+ * of the database.
  */
 class User {
 
@@ -480,15 +487,15 @@ class User {
         *
         * @param string $password
         * @return bool
-        * @static
         */
-       static function isValidPassword( $password ) {
-               global $wgMinimalPasswordLength;
+       function isValidPassword( $password ) {
+               global $wgMinimalPasswordLength, $wgContLang;
 
                $result = null;
                if( !wfRunHooks( 'isValidPassword', array( $password, &$result ) ) ) return $result;
-               if ($result === false) return false; 
-               return (strlen( $password ) >= $wgMinimalPasswordLength);
+               if ($result === false) return false;
+               return (strlen( $password ) >= $wgMinimalPasswordLength) &&
+                       ($wgContLang->lc( $password ) !== $wgContLang->lc( $this->mName ));
        }
 
        /**
@@ -524,6 +531,12 @@ class User {
                global $wgContLang;
                $name = $wgContLang->ucfirst( $name );
 
+               # Reject names containing '#'; these will be cleaned up
+               # with title normalisation, but then it's too late to
+               # check elsewhere
+               if( strpos( $name, '#' ) !== false )
+                       return false;
+
                # Clean up name according to title rules
                $t = Title::newFromText( $name );
                if( is_null( $t ) ) {
@@ -666,10 +679,8 @@ class User {
         * Load user data from the session or login cookie. If there are no valid
         * credentials, initialises the user as an anon.
         * @return true if the user is logged in, false otherwise
-        * 
-        * @private
         */
-       function loadFromSession() {
+       private function loadFromSession() {
                global $wgMemc, $wgCookiePrefix;
 
                if ( isset( $_SESSION['wsUserID'] ) ) {
@@ -971,7 +982,7 @@ class User {
         */
        public function isPingLimitable() {
                global $wgRateLimitsExcludedGroups;
-               return array_intersect($this->getEffectiveGroups(), $wgRateLimitsExcludedGroups) != array();
+               return array_intersect($this->getEffectiveGroups(), $wgRateLimitsExcludedGroups) == array();
        }
 
        /**
@@ -1131,10 +1142,10 @@ class User {
                } else {
                        $this->load();
                        if ( $this->mName === false ) {
-                               $this->mName = wfGetIP();
+                               # Clean up IPs
+                               $this->mName = IP::sanitizeIP( wfGetIP() );
                        }
-                       # Clean up IPs
-                       return IP::sanitizeIP($this->mName);
+                       return $this->mName;
                }
        }
 
@@ -2127,6 +2138,8 @@ class User {
                // extra options or other effects on the parser cache.
                wfRunHooks( 'PageRenderingHash', array( &$confstr ) );
 
+               // Make it a valid memcached key fragment
+               $confstr = str_replace( ' ', '_', $confstr );
                $this->mHash = $confstr;
                return $confstr;
        }
@@ -2136,6 +2149,17 @@ class User {
                return $this->mBlock && $this->mBlock->mCreateAccount;
        }
 
+       /**
+        * Determine if the user is blocked from using Special:Emailuser.
+        *
+        * @public
+        * @return boolean
+        */
+       function isBlockedFromEmailuser() {
+               $this->getBlockedStatus();
+               return $this->mBlock && $this->mBlock->mBlockEmail;
+       }
+
        function isAllowedToCreateAccount() {
                return $this->isAllowed( 'createaccount' ) && !$this->isBlockedFromCreateAccount();
        }