Fix {{NUMBEROFADMINS}} magic word
[lhc/web/wiklou.git] / includes / User.php
index 5d6e2e8..f695d1d 100644 (file)
@@ -5,11 +5,6 @@
  * @package MediaWiki
  */
 
-/**
- *
- */
-require_once( 'WatchedItem.php' );
-
 # Number of characters in user_token field
 define( 'USER_TOKEN_LENGTH', 32 );
 
@@ -27,26 +22,26 @@ class User {
        /**@{{
         * @private
         */
-       private $mBlockedby;    //!<
-       private $mBlockreason;  //!<
-       private $mDataLoaded;   //!<
-       private $mEmail;                //!<
-       private $mEmailAuthenticated; //!<
-       private $mGroups;               //!<
-       private $mHash;                 //!<
-       private $mId;                   //!<
-       private $mName;                 //!<
-       private $mNewpassword;  //!<
-       private $mNewtalk;              //!<
-       private $mOptions;              //!<
-       private $mPassword;             //!<
-       private $mRealName;             //!<
-       private $mRegistration; //!<
-       private $mRights;               //!<
-       private $mSkin;                 //!<
-       private $mToken;                //!<
-       private $mTouched;              //!<
-       private $mVersion;              //!< serialized version
+       var $mBlockedby;        //!<
+       var $mBlockreason;      //!<
+       var $mDataLoaded;       //!<
+       var $mEmail;            //!<
+       var $mEmailAuthenticated; //!<
+       var $mGroups;           //!<
+       var $mHash;                     //!<
+       var $mId;                       //!<
+       var $mName;                     //!<
+       var $mNewpassword;      //!<
+       var $mNewtalk;          //!<
+       var $mOptions;          //!<
+       var $mPassword;         //!<
+       var $mRealName;         //!<
+       var $mRegistration;     //!<
+       var $mRights;           //!<
+       var $mSkin;                     //!<
+       var $mToken;            //!<
+       var $mTouched;          //!<
+       var $mVersion;          //!< serialized version
        /**@}} */
 
        /** Constructor using User:loadDefaults() */
@@ -58,10 +53,11 @@ class User {
        /**
         * Static factory method
         * @param string $name Username, validated by Title:newFromText()
+        * @param bool $validate Validate username
         * @return User
         * @static
         */
-       function newFromName( $name ) {
+       function newFromName( $name, $validate = true ) {
                # Force usernames to capital
                global $wgContLang;
                $name = $wgContLang->ucfirst( $name );
@@ -77,7 +73,7 @@ class User {
                global $wgAuth;
                $canonicalName = $wgAuth->getCanonicalName( $t->getText() );
 
-               if( !User::isValidUserName( $canonicalName ) ) {
+               if( $validate && !User::isValidUserName( $canonicalName ) ) {
                        return null;
                }
 
@@ -187,9 +183,14 @@ class User {
        }
 
        /**
-        * does the string match an anonymous IPv4 address?
+        * Does the string match an anonymous IPv4 address?
         *
-        * Note: We match \d{1,3}\.\d{1,3}\.\d{1,3}\.xxx as an anonymous IP
+        * This function exists for username validation, in order to reject
+        * usernames which are similar in form to IP addresses. Strings such
+        * as 300.300.300.300 will return true because it looks like an IP 
+        * address, despite not being strictly valid.
+        * 
+        * We match \d{1,3}\.\d{1,3}\.\d{1,3}\.xxx as an anonymous IP
         * address because the usemod software would "cloak" anonymous IP
         * addresses like this, if we allowed accounts like this to be created
         * new users could get the old edits of these anonymous users.
@@ -479,12 +480,6 @@ class User {
                        $this->inDnsBlacklist( $ip, 'http.dnsbl.sorbs.net.' );
        }
 
-       function inOpmBlacklist( $ip ) {
-               global $wgEnableOpm;
-               return $wgEnableOpm &&
-                       $this->inDnsBlacklist( $ip, 'opm.blitzed.org.' );
-       }
-
        function inDnsBlacklist( $ip, $base ) {
                $fname = 'User::inDnsBlacklist';
                wfProfileIn( $fname );
@@ -525,15 +520,17 @@ class User {
         * @public
         */
        function pingLimiter( $action='edit' ) {
-               global $wgRateLimits;
+               global $wgRateLimits, $wgRateLimitsExcludedGroups;
                if( !isset( $wgRateLimits[$action] ) ) {
                        return false;
                }
-               if( $this->isAllowed( 'delete' ) ) {
-                       // goddam cabal
-                       return false;
+               
+               # Some groups shouldn't trigger the ping limiter, ever
+               foreach( $this->getGroups() as $group ) {
+                       if( array_search( $group, $wgRateLimitsExcludedGroups ) !== false )
+                               return false;
                }
-
+               
                global $wgMemc, $wgDBname, $wgRateLimitLog;
                $fname = 'User::pingLimiter';
                wfProfileIn( $fname );
@@ -1067,6 +1064,20 @@ class User {
        function getBoolOption( $oname ) {
                return (bool)$this->getOption( $oname );
        }
+       
+       /**
+        * Get an option as an integer value from the source string.
+        * @param string $oname The option to check
+        * @param int $default Optional value to return if option is unset/blank.
+        * @return int
+        */
+       function getIntOption( $oname, $default=0 ) {
+               $val = $this->getOption( $oname );
+               if( $val == '' ) {
+                       $val = $default;
+               }
+               return intval( $val );
+       }
 
        function setOption( $oname, $val ) {
                $this->loadFromDatabase();
@@ -1074,6 +1085,11 @@ class User {
                        # Clear cached skin, so the new one displays immediately in Special:Preferences
                        unset( $this->mSkin );
                }
+               // Filter out any newlines that may have passed through input validation.
+               // Newlines are used to separate items in the options blob.
+               $val = str_replace( "\r\n", "\n", $val );
+               $val = str_replace( "\r", "\n", $val );
+               $val = str_replace( "\n", " ", $val );
                $this->mOptions[$oname] = $val;
                $this->invalidateCache();
        }
@@ -1176,7 +1192,7 @@ class User {
         * @deprecated
         */
        function isSysop() {
-               wfDebugDieBacktrace( "Call to deprecated (v1.7) User::isSysop() method\n" );
+               throw new MWException( "Call to deprecated (v1.7) User::isSysop() method\n" );
                #return $this->isAllowed( 'protect' );
        }
 
@@ -1185,7 +1201,7 @@ class User {
         * @deprecated
         */
        function isDeveloper() {
-               wfDebugDieBacktrace( "Call to deprecated (v1.7) User::isDeveloper() method\n" );
+               throw new MWException( "Call to deprecated (v1.7) User::isDeveloper() method\n" );
                #return $this->isAllowed( 'siteadmin' );
        }
 
@@ -1194,7 +1210,7 @@ class User {
         * @deprecated
         */
        function isBureaucrat() {
-               wfDebugDieBacktrace( "Call to deprecated (v1.7) User::isBureaucrat() method\n" );
+               throw new MWException( "Call to deprecated (v1.7) User::isBureaucrat() method\n" );
                #return $this->isAllowed( 'makesysop' );
        }