fix for several problems found by Eloquence:
[lhc/web/wiklou.git] / includes / User.php
index 4bbaa18..a38f60c 100644 (file)
@@ -45,8 +45,12 @@ class User {
                # Clean up name according to title rules
 
                $t = Title::newFromText( $name );
-               $u->setName( $t->getText() );
-               return $u;
+               if( is_null( $t ) ) {
+                       return NULL;
+               } else {
+                       $u->setName( $t->getText() );
+                       return $u;
+               }
        }
 
        /**
@@ -57,7 +61,7 @@ class User {
         */
        function whoIs( $id )   {
                $dbr =& wfGetDB( DB_SLAVE );
-               return $dbr->getField( 'user', 'user_name', array( 'user_id' => $id ) );
+               return $dbr->selectField( 'user', 'user_name', array( 'user_id' => $id ) );
        }
 
        /**
@@ -68,7 +72,7 @@ class User {
         */
        function whoIsReal( $id )       {
                $dbr =& wfGetDB( DB_SLAVE );
-               return $dbr->getField( 'user', 'user_real_name', array( 'user_id' => $id ) );
+               return $dbr->selectField( 'user', 'user_real_name', array( 'user_id' => $id ) );
        }
 
        /**
@@ -86,7 +90,7 @@ class User {
                        return null;
                }
                $dbr =& wfGetDB( DB_SLAVE );
-               $s = $dbr->getArray( 'user', array( 'user_id' ), array( 'user_name' => $nt->getText() ), $fname );
+               $s = $dbr->selectRow( 'user', array( 'user_id' ), array( 'user_name' => $nt->getText() ), $fname );
 
                if ( $s === false ) {
                        return 0;
@@ -160,6 +164,10 @@ class User {
                foreach ( $defOpt as $oname => $val ) {
                        $this->mOptions[$oname] = $val;
                }               
+        /* so that new user will have a default 
+           language variant set using info from the http header 
+        */
+        $this->setOption('variant', $wgLang->getPreferredVariant());
        }
 
        /**
@@ -350,7 +358,7 @@ class User {
                        return;
                } # the following stuff is for non-anonymous users only
 
-               $s = $dbr->getArray( 'user', array( 'user_name','user_password','user_newpassword','user_email',
+               $s = $dbr->selectRow( 'user', array( 'user_name','user_password','user_newpassword','user_email',
                  'user_real_name','user_options','user_touched' ),
                  array( 'user_id' => $this->mId ), $fname );
 
@@ -363,7 +371,7 @@ class User {
                        $this->decodeOptions( $s->user_options );
                        $this->mTouched = wfTimestamp(TS_MW,$s->user_touched);
                        $this->mRights = explode( ",", strtolower( 
-                               $dbr->getField( 'user_rights', 'user_rights', array( 'user_id' => $this->mId ) )
+                               $dbr->selectField( 'user_rights', 'user_rights', array( 'user_id' => $this->mId ) )
                        ) );
                }
 
@@ -575,8 +583,9 @@ class User {
                        # Check if we got if not failback to default skin
                        $sn = 'Skin'.$sn;
                        if(!class_exists($sn)) {
-                               #FIXME : should we print an error message instead of loading
-                               # standard skin ?
+                               # FIXME : should we print an error message instead of loading
+                               # standard skin ? Let's die for now. [AV]
+                               die("Class $sn doesn't exist in $IP/skins/$sn.php");
                                $sn = 'SkinStandard';
                                require_once( $IP.'/skins/Standard.php' );
                        }
@@ -805,6 +814,7 @@ class User {
        }
 
        function getPageRenderingHash() {
+        global $wgLang;
                if( $this->mHash ){
                        return $this->mHash;
                }
@@ -821,6 +831,12 @@ class User {
                $confstr .= '!' . $this->getOption( 'date' );
                $confstr .= '!' . $this->getOption( 'numberheadings' );
 
+        // add in language variant option if there are multiple variants
+        // supported by the language object
+        if(sizeof($wgLang->getVariants())>1) {
+             $confstr .= '!' . $this->getOption( 'variant' );
+        }
+
                $this->mHash = $confstr;
                return $confstr ;
        }