* Fixed unclosed <p> tag
[lhc/web/wiklou.git] / includes / User.php
index 2a7a9b5..42a6a89 100644 (file)
@@ -52,16 +52,25 @@ class User {
        function newFromName( $name ) {
                $u = new User();
 
+               # Force usernames to capital
+               global $wgContLang;
+               $name = $wgContLang->ucfirst( $name );
+               
                # Clean up name according to title rules
-
                $t = Title::newFromText( $name );
                if( is_null( $t ) ) {
-                       return NULL;
-               } else {
-                       $u->setName( $t->getText() );
-                       $u->setId( $u->idFromName( $t->getText() ) );
-                       return $u;
+                       return null;
+               }
+               
+               # Reject various classes of invalid names
+               $canonicalName = $t->getText();
+               if( !User::isValidUserName( $canonicalName ) ) {
+                       return null;
                }
+               
+               $u->setName( $canonicalName );
+               $u->setId( $u->idFromName( $t->getText() ) );
+               return $u;
        }
        
        /**
@@ -172,12 +181,13 @@ class User {
         *
         * @param string $name
         * @return bool
+        * @static
         */
        function isValidUserName( $name ) {
                global $wgContLang, $wgMaxNameChars;
                
                if ( $name == ''
-               || $this->isIP( $name )
+               || User::isIP( $name )
                || strpos( $name, '/' ) !== false
                || strlen( $name ) > $wgMaxNameChars
                || $name != $wgContLang->ucfirst( $name ) )
@@ -191,6 +201,7 @@ class User {
         *
         * @param string $password
         * @return bool
+        * @static
         */
        function isValidPassword( $password ) {
                global $wgMinimalPasswordLength;
@@ -214,6 +225,23 @@ class User {
                        (false !== strpos( $addr, '@' ) );
        }
 
+       /**
+        * Count the number of edits of a user 
+        *
+        * @param int $uid The user ID to check
+        * @return int
+        */
+       function edits( $uid ) {
+               $fname = 'User::editCount';
+               
+               $dbr =& wfGetDB( DB_SLAVE );
+               return $dbr->selectField(
+                       'revision', 'count(*)',
+                       array( 'rev_user' => $uid ),
+                       $fname
+               );
+       }
+
        /**
         * probably return a random password
         * @return string probably a random password
@@ -501,6 +529,20 @@ class User {
                $this->getBlockedStatus( $bFromSlave );
                return $this->mBlockedby !== 0;
        }
+
+       /**
+        * Check if user is blocked from editing a particular article
+        */
+       function isBlockedFrom( $title, $bFromSlave = false ) {
+               global $wgBlockAllowsUTEdit;
+               if ( $wgBlockAllowsUTEdit && $title->getText() === $this->getName() && 
+                 $title->getNamespace() == NS_USER_TALK )
+               {
+                       return false;
+               } else {
+                       return $this->isBlocked( $bFromSlave );
+               }
+       }
        
        /**
         * Get name of blocker
@@ -1424,7 +1466,6 @@ class User {
 
                $confstr =        $this->getOption( 'math' );
                $confstr .= '!' . $this->getOption( 'stubthreshold' );
-               $confstr .= '!' . $this->getOption( 'editsection' );
                $confstr .= '!' . $this->getOption( 'date' );
                $confstr .= '!' . $this->getOption( 'numberheadings' );
                $confstr .= '!' . $this->getOption( 'language' );