new non-stub Indonesian language file
[mediawiki.git] / includes / User.php
bloba38f60c178b07c6dc68afb6e20cbc814a0b79f62
1 <?php
2 /**
3 * See user.doc
5 * @package MediaWiki
6 */
8 /**
11 require_once( 'WatchedItem.php' );
13 /**
15 * @package MediaWiki
17 class User {
18 /**#@+
19 * @access private
21 var $mId, $mName, $mPassword, $mEmail, $mNewtalk;
22 var $mRights, $mOptions;
23 var $mDataLoaded, $mNewpassword;
24 var $mSkin;
25 var $mBlockedby, $mBlockreason;
26 var $mTouched;
27 var $mCookiePassword;
28 var $mRealName;
29 var $mHash;
30 /**#@-*/
32 /** Construct using User:loadDefaults() */
33 function User() {
34 $this->loadDefaults();
37 /**
38 * Static factory method
39 * @static
40 * @param string $name Username, validated by Title:newFromText()
42 function newFromName( $name ) {
43 $u = new User();
45 # Clean up name according to title rules
47 $t = Title::newFromText( $name );
48 if( is_null( $t ) ) {
49 return NULL;
50 } else {
51 $u->setName( $t->getText() );
52 return $u;
56 /**
57 * Get username given an id.
58 * @param integer $id Database user id
59 * @return string Nickname of a user
60 * @static
62 function whoIs( $id ) {
63 $dbr =& wfGetDB( DB_SLAVE );
64 return $dbr->selectField( 'user', 'user_name', array( 'user_id' => $id ) );
67 /**
68 * Get real username given an id.
69 * @param integer $id Database user id
70 * @return string Realname of a user
71 * @static
73 function whoIsReal( $id ) {
74 $dbr =& wfGetDB( DB_SLAVE );
75 return $dbr->selectField( 'user', 'user_real_name', array( 'user_id' => $id ) );
78 /**
79 * Get database id given a user name
80 * @param string $name Nickname of a user
81 * @return integer|null Database user id (null: if non existent
82 * @static
84 function idFromName( $name ) {
85 $fname = "User::idFromName";
87 $nt = Title::newFromText( $name );
88 if( is_null( $nt ) ) {
89 # Illegal name
90 return null;
92 $dbr =& wfGetDB( DB_SLAVE );
93 $s = $dbr->selectRow( 'user', array( 'user_id' ), array( 'user_name' => $nt->getText() ), $fname );
95 if ( $s === false ) {
96 return 0;
97 } else {
98 return $s->user_id;
103 * does the string match an anonymous user IP address?
104 * @param string $name Nickname of a user
105 * @static
107 function isIP( $name ) {
108 return preg_match("/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/",$name);
112 * probably return a random password
113 * @return string probably a random password
114 * @static
115 * @todo Check what is doing really [AV]
117 function randomPassword() {
118 $pwchars = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz';
119 $l = strlen( $pwchars ) - 1;
121 $np = $pwchars{mt_rand( 0, $l )} . $pwchars{mt_rand( 0, $l )} .
122 $pwchars{mt_rand( 0, $l )} . chr( mt_rand(48, 57) ) .
123 $pwchars{mt_rand( 0, $l )} . $pwchars{mt_rand( 0, $l )} .
124 $pwchars{mt_rand( 0, $l )};
125 return $np;
129 * Set properties to default
130 * Used at construction. It will load per language default settings only
131 * if we have an available language object.
133 function loadDefaults() {
134 global $wgLang, $wgIP;
135 global $wgNamespacesToBeSearchedDefault;
137 $this->mId = $this->mNewtalk = 0;
138 $this->mName = $wgIP;
139 $this->mRealName = $this->mEmail = '';
140 $this->mPassword = $this->mNewpassword = '';
141 $this->mRights = array();
142 // Getting user defaults only if we have an available language
143 if(isset($wgLang)) { $this->loadDefaultFromLanguage(); }
145 foreach ($wgNamespacesToBeSearchedDefault as $nsnum => $val) {
146 $this->mOptions['searchNs'.$nsnum] = $val;
148 unset( $this->mSkin );
149 $this->mDataLoaded = false;
150 $this->mBlockedby = -1; # Unset
151 $this->mTouched = '0'; # Allow any pages to be cached
152 $this->cookiePassword = '';
153 $this->mHash = false;
157 * Used to load user options from a language.
158 * This is not in loadDefault() cause we sometime create user before having
159 * a language object.
161 function loadDefaultFromLanguage(){
162 global $wgLang;
163 $defOpt = $wgLang->getDefaultUserOptions() ;
164 foreach ( $defOpt as $oname => $val ) {
165 $this->mOptions[$oname] = $val;
167 /* so that new user will have a default
168 language variant set using info from the http header
170 $this->setOption('variant', $wgLang->getPreferredVariant());
174 * Get blocking information
175 * @access private
177 function getBlockedStatus() {
178 global $wgIP, $wgBlockCache, $wgProxyList;
180 if ( -1 != $this->mBlockedby ) { return; }
182 $this->mBlockedby = 0;
184 # User blocking
185 if ( $this->mId ) {
186 $block = new Block();
187 if ( $block->load( $wgIP , $this->mId ) ) {
188 $this->mBlockedby = $block->mBy;
189 $this->mBlockreason = $block->mReason;
193 # IP/range blocking
194 if ( !$this->mBlockedby ) {
195 $block = $wgBlockCache->get( $wgIP );
196 if ( $block !== false ) {
197 $this->mBlockedby = $block->mBy;
198 $this->mBlockreason = $block->mReason;
202 # Proxy blocking
203 if ( !$this->mBlockedby ) {
204 if ( array_key_exists( $wgIP, $wgProxyList ) ) {
205 $this->mBlockreason = wfMsg( 'proxyblockreason' );
206 $this->mBlockedby = "Proxy blocker";
212 * Check if user is blocked
213 * @return bool True if blocked, false otherwise
215 function isBlocked() {
216 $this->getBlockedStatus();
217 if ( 0 === $this->mBlockedby ) { return false; }
218 return true;
222 * Get name of blocker
223 * @return string name of blocker
225 function blockedBy() {
226 $this->getBlockedStatus();
227 return $this->mBlockedby;
231 * Get blocking reason
232 * @return string Blocking reason
234 function blockedFor() {
235 $this->getBlockedStatus();
236 return $this->mBlockreason;
240 * Initialise php session
242 function SetupSession() {
243 global $wgSessionsInMemcached, $wgCookiePath, $wgCookieDomain;
244 if( $wgSessionsInMemcached ) {
245 require_once( 'MemcachedSessions.php' );
246 } elseif( 'files' != ini_get( 'session.save_handler' ) ) {
247 # If it's left on 'user' or another setting from another
248 # application, it will end up failing. Try to recover.
249 ini_set ( 'session.save_handler', 'files' );
251 session_set_cookie_params( 0, $wgCookiePath, $wgCookieDomain );
252 session_cache_limiter( 'private, must-revalidate' );
253 @session_start();
257 * Read datas from session
258 * @static
260 function loadFromSession() {
261 global $wgMemc, $wgDBname;
263 if ( isset( $_SESSION['wsUserID'] ) ) {
264 if ( 0 != $_SESSION['wsUserID'] ) {
265 $sId = $_SESSION['wsUserID'];
266 } else {
267 return new User();
269 } else if ( isset( $_COOKIE["{$wgDBname}UserID"] ) ) {
270 $sId = IntVal( $_COOKIE["{$wgDBname}UserID"] );
271 $_SESSION['wsUserID'] = $sId;
272 } else {
273 return new User();
275 if ( isset( $_SESSION['wsUserName'] ) ) {
276 $sName = $_SESSION['wsUserName'];
277 } else if ( isset( $_COOKIE["{$wgDBname}UserName"] ) ) {
278 $sName = $_COOKIE["{$wgDBname}UserName"];
279 $_SESSION['wsUserName'] = $sName;
280 } else {
281 return new User();
284 $passwordCorrect = FALSE;
285 $user = $wgMemc->get( $key = "$wgDBname:user:id:$sId" );
286 if($makenew = !$user) {
287 wfDebug( "User::loadFromSession() unable to load from memcached\n" );
288 $user = new User();
289 $user->mId = $sId;
290 $user->loadFromDatabase();
291 } else {
292 wfDebug( "User::loadFromSession() got from cache!\n" );
295 if ( isset( $_SESSION['wsUserPassword'] ) ) {
296 $passwordCorrect = $_SESSION['wsUserPassword'] == $user->mPassword;
297 } else if ( isset( $_COOKIE["{$wgDBname}Password"] ) ) {
298 $user->mCookiePassword = $_COOKIE["{$wgDBname}Password"];
299 $_SESSION['wsUserPassword'] = $user->addSalt( $user->mCookiePassword );
300 $passwordCorrect = $_SESSION['wsUserPassword'] == $user->mPassword;
301 } else {
302 return new User(); # Can't log in from session
305 if ( ( $sName == $user->mName ) && $passwordCorrect ) {
306 if($makenew) {
307 if($wgMemc->set( $key, $user ))
308 wfDebug( "User::loadFromSession() successfully saved user\n" );
309 else
310 wfDebug( "User::loadFromSession() unable to save to memcached\n" );
312 $user->spreadBlock();
313 return $user;
315 return new User(); # Can't log in from session
319 * Load a user from the database
321 function loadFromDatabase() {
322 global $wgCommandLineMode;
323 $fname = "User::loadFromDatabase";
324 if ( $this->mDataLoaded || $wgCommandLineMode ) {
325 return;
328 # Paranoia
329 $this->mId = IntVal( $this->mId );
331 # check in separate table if there are changes to the talk page
332 $this->mNewtalk=0; # reset talk page status
333 $dbr =& wfGetDB( DB_SLAVE );
334 if($this->mId) {
335 $res = $dbr->select( 'user_newtalk', 1, array( 'user_id' => $this->mId ), $fname );
337 if ( $dbr->numRows($res)>0 ) {
338 $this->mNewtalk= 1;
340 $dbr->freeResult( $res );
341 } else {
342 global $wgDBname, $wgMemc;
343 $key = "$wgDBname:newtalk:ip:{$this->mName}";
344 $newtalk = $wgMemc->get( $key );
345 if( ! is_integer( $newtalk ) ){
346 $res = $dbr->select( 'user_newtalk', 1, array( 'user_ip' => $this->mName ), $fname );
348 $this->mNewtalk = $dbr->numRows( $res ) > 0 ? 1 : 0;
349 $dbr->freeResult( $res );
351 $wgMemc->set( $key, $this->mNewtalk, time() ); // + 1800 );
352 } else {
353 $this->mNewtalk = $newtalk ? 1 : 0;
356 if(!$this->mId) {
357 $this->mDataLoaded = true;
358 return;
359 } # the following stuff is for non-anonymous users only
361 $s = $dbr->selectRow( 'user', array( 'user_name','user_password','user_newpassword','user_email',
362 'user_real_name','user_options','user_touched' ),
363 array( 'user_id' => $this->mId ), $fname );
365 if ( $s !== false ) {
366 $this->mName = $s->user_name;
367 $this->mEmail = $s->user_email;
368 $this->mRealName = $s->user_real_name;
369 $this->mPassword = $s->user_password;
370 $this->mNewpassword = $s->user_newpassword;
371 $this->decodeOptions( $s->user_options );
372 $this->mTouched = wfTimestamp(TS_MW,$s->user_touched);
373 $this->mRights = explode( ",", strtolower(
374 $dbr->selectField( 'user_rights', 'user_rights', array( 'user_id' => $this->mId ) )
375 ) );
378 $this->mDataLoaded = true;
381 function getID() { return $this->mId; }
382 function setID( $v ) {
383 $this->mId = $v;
384 $this->mDataLoaded = false;
387 function getName() {
388 $this->loadFromDatabase();
389 return $this->mName;
392 function setName( $str ) {
393 $this->loadFromDatabase();
394 $this->mName = $str;
397 function getNewtalk() {
398 $this->loadFromDatabase();
399 return ( 0 != $this->mNewtalk );
402 function setNewtalk( $val ) {
403 $this->loadFromDatabase();
404 $this->mNewtalk = $val;
405 $this->invalidateCache();
408 function invalidateCache() {
409 $this->loadFromDatabase();
410 $this->mTouched = wfTimestampNow();
411 # Don't forget to save the options after this or
412 # it won't take effect!
415 function validateCache( $timestamp ) {
416 $this->loadFromDatabase();
417 return ($timestamp >= $this->mTouched);
421 * Salt a password.
422 * Will only be salted if $wgPasswordSalt is true
423 * @param string Password.
424 * @return string Salted password or clear password.
426 function addSalt( $p ) {
427 global $wgPasswordSalt;
428 if($wgPasswordSalt)
429 return md5( "{$this->mId}-{$p}" );
430 else
431 return $p;
435 * Encrypt a password.
436 * It can eventuall salt a password @see User::addSalt()
437 * @param string $p clear Password.
438 * @param string Encrypted password.
440 function encryptPassword( $p ) {
441 return $this->addSalt( md5( $p ) );
444 function setPassword( $str ) {
445 $this->loadFromDatabase();
446 $this->setCookiePassword( $str );
447 $this->mPassword = $this->encryptPassword( $str );
448 $this->mNewpassword = '';
451 function setCookiePassword( $str ) {
452 $this->loadFromDatabase();
453 $this->mCookiePassword = md5( $str );
456 function setNewpassword( $str ) {
457 $this->loadFromDatabase();
458 $this->mNewpassword = $this->encryptPassword( $str );
461 function getEmail() {
462 $this->loadFromDatabase();
463 return $this->mEmail;
466 function setEmail( $str ) {
467 $this->loadFromDatabase();
468 $this->mEmail = $str;
471 function getRealName() {
472 $this->loadFromDatabase();
473 return $this->mRealName;
476 function setRealName( $str ) {
477 $this->loadFromDatabase();
478 $this->mRealName = $str;
481 function getOption( $oname ) {
482 $this->loadFromDatabase();
483 if ( array_key_exists( $oname, $this->mOptions ) ) {
484 return $this->mOptions[$oname];
485 } else {
486 return '';
490 function setOption( $oname, $val ) {
491 $this->loadFromDatabase();
492 if ( $oname == 'skin' ) {
493 # Clear cached skin, so the new one displays immediately in Special:Preferences
494 unset( $this->mSkin );
496 $this->mOptions[$oname] = $val;
497 $this->invalidateCache();
500 function getRights() {
501 $this->loadFromDatabase();
502 return $this->mRights;
505 function addRight( $rname ) {
506 $this->loadFromDatabase();
507 array_push( $this->mRights, $rname );
508 $this->invalidateCache();
511 function isSysop() {
512 $this->loadFromDatabase();
513 if ( 0 == $this->mId ) { return false; }
515 return in_array( 'sysop', $this->mRights );
518 function isDeveloper() {
519 $this->loadFromDatabase();
520 if ( 0 == $this->mId ) { return false; }
522 return in_array( 'developer', $this->mRights );
525 function isBureaucrat() {
526 $this->loadFromDatabase();
527 if ( 0 == $this->mId ) { return false; }
529 return in_array( 'bureaucrat', $this->mRights );
533 * Whether the user is a bot
535 function isBot() {
536 $this->loadFromDatabase();
538 # Why was this here? I need a UID=0 conversion script [TS]
539 # if ( 0 == $this->mId ) { return false; }
541 return in_array( 'bot', $this->mRights );
545 * Load a skin if it doesn't exist or return it
546 * @todo FIXME : need to check the old failback system [AV]
548 function &getSkin() {
549 global $IP, $wgUsePHPTal;
550 if ( ! isset( $this->mSkin ) ) {
551 # get all skin names available
552 $skinNames = Skin::getSkinNames();
553 # get the user skin
554 $userSkin = $this->getOption( 'skin' );
555 if ( $userSkin == '' ) { $userSkin = 'standard'; }
557 if ( !isset( $skinNames[$userSkin] ) ) {
558 # in case the user skin could not be found find a replacement
559 $fallback = array(
560 0 => 'Standard',
561 1 => 'Nostalgia',
562 2 => 'CologneBlue');
563 # if phptal is enabled we should have monobook skin that
564 # superseed the good old SkinStandard.
565 if ( isset( $skinNames['monobook'] ) ) {
566 $fallback[0] = 'MonoBook';
569 if(is_numeric($userSkin) && isset( $fallback[$userSkin]) ){
570 $sn = $fallback[$userSkin];
571 } else {
572 $sn = 'Standard';
574 } else {
575 # The user skin is available
576 $sn = $skinNames[$userSkin];
579 # Grab the skin class and initialise it. Each skin checks for PHPTal
580 # and will not load if it's not enabled.
581 require_once( $IP.'/skins/'.$sn.'.php' );
583 # Check if we got if not failback to default skin
584 $sn = 'Skin'.$sn;
585 if(!class_exists($sn)) {
586 # FIXME : should we print an error message instead of loading
587 # standard skin ? Let's die for now. [AV]
588 die("Class $sn doesn't exist in $IP/skins/$sn.php");
589 $sn = 'SkinStandard';
590 require_once( $IP.'/skins/Standard.php' );
592 $this->mSkin = new $sn;
594 return $this->mSkin;
597 /**#@+
598 * @param string $title Article title to look at
602 * Check watched status of an article
603 * @return bool True if article is watched
605 function isWatched( $title ) {
606 $wl = WatchedItem::fromUserTitle( $this, $title );
607 return $wl->isWatched();
611 * Watch an article
613 function addWatch( $title ) {
614 $wl = WatchedItem::fromUserTitle( $this, $title );
615 $wl->addWatch();
616 $this->invalidateCache();
620 * Stop watching an article
622 function removeWatch( $title ) {
623 $wl = WatchedItem::fromUserTitle( $this, $title );
624 $wl->removeWatch();
625 $this->invalidateCache();
627 /**#@-*/
630 * @access private
631 * @return string Encoding options
633 function encodeOptions() {
634 $a = array();
635 foreach ( $this->mOptions as $oname => $oval ) {
636 array_push( $a, $oname.'='.$oval );
638 $s = implode( "\n", $a );
639 return $s;
643 * @access private
645 function decodeOptions( $str ) {
646 $a = explode( "\n", $str );
647 foreach ( $a as $s ) {
648 if ( preg_match( "/^(.[^=]*)=(.*)$/", $s, $m ) ) {
649 $this->mOptions[$m[1]] = $m[2];
654 function setCookies() {
655 global $wgCookieExpiration, $wgCookiePath, $wgCookieDomain, $wgDBname;
656 if ( 0 == $this->mId ) return;
657 $this->loadFromDatabase();
658 $exp = time() + $wgCookieExpiration;
660 $_SESSION['wsUserID'] = $this->mId;
661 setcookie( $wgDBname.'UserID', $this->mId, $exp, $wgCookiePath, $wgCookieDomain );
663 $_SESSION['wsUserName'] = $this->mName;
664 setcookie( $wgDBname.'UserName', $this->mName, $exp, $wgCookiePath, $wgCookieDomain );
666 $_SESSION['wsUserPassword'] = $this->mPassword;
667 if ( 1 == $this->getOption( 'rememberpassword' ) ) {
668 setcookie( $wgDBname.'Password', $this->mCookiePassword, $exp, $wgCookiePath, $wgCookieDomain );
669 } else {
670 setcookie( $wgDBname.'Password', '', time() - 3600 );
675 * Logout user
676 * It will clean the session cookie
678 function logout() {
679 global $wgCookiePath, $wgCookieDomain, $wgDBname;
680 $this->mId = 0;
682 $_SESSION['wsUserID'] = 0;
684 setcookie( $wgDBname.'UserID', '', time() - 3600, $wgCookiePath, $wgCookieDomain );
685 setcookie( $wgDBname.'Password', '', time() - 3600, $wgCookiePath, $wgCookieDomain );
689 * Save object settings into database
691 function saveSettings() {
692 global $wgMemc, $wgDBname;
693 $fname = 'User::saveSettings';
695 $dbw =& wfGetDB( DB_MASTER );
696 if ( ! $this->mNewtalk ) {
697 # Delete user_newtalk row
698 if( $this->mId ) {
699 $dbw->delete( 'user_newtalk', array( 'user_id' => $this->mId ), $fname );
700 } else {
701 $dbw->delete( 'user_newtalk', array( 'user_ip' => $this->mName ), $fname );
702 $wgMemc->delete( "$wgDBname:newtalk:ip:{$this->mName}" );
705 if ( 0 == $this->mId ) { return; }
707 $dbw->update( 'user',
708 array( /* SET */
709 'user_name' => $this->mName,
710 'user_password' => $this->mPassword,
711 'user_newpassword' => $this->mNewpassword,
712 'user_real_name' => $this->mRealName,
713 'user_email' => $this->mEmail,
714 'user_options' => $this->encodeOptions(),
715 'user_touched' => $dbw->timestamp($this->mTouched)
716 ), array( /* WHERE */
717 'user_id' => $this->mId
718 ), $fname
720 $dbw->set( 'user_rights', 'user_rights', implode( ",", $this->mRights ),
721 'user_id='. $this->mId, $fname );
722 $wgMemc->delete( "$wgDBname:user:id:$this->mId" );
726 * Checks if a user with the given name exists, returns the ID
728 function idForName() {
729 $fname = 'User::idForName';
731 $gotid = 0;
732 $s = trim( $this->mName );
733 if ( 0 == strcmp( '', $s ) ) return 0;
735 $dbr =& wfGetDB( DB_SLAVE );
736 $id = $dbr->selectField( 'user', 'user_id', array( 'user_name' => $s ), $fname );
737 if ( $id === false ) {
738 $id = 0;
740 return $id;
744 * Add user object to the database
746 function addToDatabase() {
747 $fname = 'User::addToDatabase';
748 $dbw =& wfGetDB( DB_MASTER );
749 $seqVal = $dbw->nextSequenceValue( 'user_user_id_seq' );
750 $dbw->insert( 'user',
751 array(
752 'user_id' => $seqVal,
753 'user_name' => $this->mName,
754 'user_password' => $this->mPassword,
755 'user_newpassword' => $this->mNewpassword,
756 'user_email' => $this->mEmail,
757 'user_real_name' => $this->mRealName,
758 'user_options' => $this->encodeOptions()
759 ), $fname
761 $this->mId = $dbw->insertId();
762 $dbw->insert( 'user_rights',
763 array(
764 'user_id' => $this->mId,
765 'user_rights' => implode( ',', $this->mRights )
766 ), $fname
771 function spreadBlock() {
772 global $wgIP;
773 # If the (non-anonymous) user is blocked, this function will block any IP address
774 # that they successfully log on from.
775 $fname = 'User::spreadBlock';
777 wfDebug( "User:spreadBlock()\n" );
778 if ( $this->mId == 0 ) {
779 return;
782 $userblock = Block::newFromDB( '', $this->mId );
783 if ( !$userblock->isValid() ) {
784 return;
787 # Check if this IP address is already blocked
788 $ipblock = Block::newFromDB( $wgIP );
789 if ( $ipblock->isValid() ) {
790 # Just update the timestamp
791 $ipblock->updateTimestamp();
792 return;
795 # Make a new block object with the desired properties
796 wfDebug( "Autoblocking {$this->mName}@{$wgIP}\n" );
797 $ipblock->mAddress = $wgIP;
798 $ipblock->mUser = 0;
799 $ipblock->mBy = $userblock->mBy;
800 $ipblock->mReason = wfMsg( 'autoblocker', $this->getName(), $userblock->mReason );
801 $ipblock->mTimestamp = wfTimestampNow();
802 $ipblock->mAuto = 1;
803 # If the user is already blocked with an expiry date, we don't
804 # want to pile on top of that!
805 if($userblock->mExpiry) {
806 $ipblock->mExpiry = min ( $userblock->mExpiry, Block::getAutoblockExpiry( $ipblock->mTimestamp ));
807 } else {
808 $ipblock->mExpiry = Block::getAutoblockExpiry( $ipblock->mTimestamp );
811 # Insert it
812 $ipblock->insert();
816 function getPageRenderingHash() {
817 global $wgLang;
818 if( $this->mHash ){
819 return $this->mHash;
822 // stubthreshold is only included below for completeness,
823 // it will always be 0 when this function is called by parsercache.
825 $confstr = $this->getOption( 'math' );
826 $confstr .= '!' . $this->getOption( 'highlightbroken' );
827 $confstr .= '!' . $this->getOption( 'stubthreshold' );
828 $confstr .= '!' . $this->getOption( 'editsection' );
829 $confstr .= '!' . $this->getOption( 'editsectiononrightclick' );
830 $confstr .= '!' . $this->getOption( 'showtoc' );
831 $confstr .= '!' . $this->getOption( 'date' );
832 $confstr .= '!' . $this->getOption( 'numberheadings' );
834 // add in language variant option if there are multiple variants
835 // supported by the language object
836 if(sizeof($wgLang->getVariants())>1) {
837 $confstr .= '!' . $this->getOption( 'variant' );
840 $this->mHash = $confstr;
841 return $confstr ;
844 function isAllowedToCreateAccount() {
845 global $wgWhitelistAccount;
846 $allowed = false;
848 if (!$wgWhitelistAccount) { return 1; }; // default behaviour
849 foreach ($wgWhitelistAccount as $right => $ok) {
850 $userHasRight = (!strcmp($right, 'user') || in_array($right, $this->getRights()));
851 $allowed |= ($ok && $userHasRight);
853 return $allowed;
857 * Set mDataLoaded, return previous value
858 * Use this to prevent DB access in command-line scripts or similar situations
860 function setLoaded( $loaded ) {
861 return wfSetVar( $this->mDataLoaded, $loaded );
864 function getUserPage() {
865 return Title::makeTitle( NS_USER, $this->mName );
869 * @static
871 function getMaxID() {
872 $dbr =& wfGetDB( DB_SLAVE );
873 return $dbr->selectField( 'user', 'max(user_id)', false );
877 * Determine whether the user is a newbie. Newbies are either
878 * anonymous IPs, or the 1% most recently created accounts.
879 * Bots and sysops are excluded.
880 * @return bool True if it is a newbie.
882 function isNewbie() {
883 return $this->mId > User::getMaxID() * 0.99 && !$this->isSysop() && !$this->isBot() || $this->getID() == 0;
887 * Check to see if the given clear-text password is one of the accepted passwords
888 * @param string $password User password.
889 * @return bool True if the given password is correct otherwise False.
891 function checkPassword( $password ) {
892 $this->loadFromDatabase();
893 $ep = $this->encryptPassword( $password );
894 if ( 0 == strcmp( $ep, $this->mPassword ) ) {
895 return true;
896 } elseif ( 0 == strcmp( $ep, $this->mNewpassword ) ) {
897 return true;
898 } elseif ( function_exists( 'iconv' ) ) {
899 # Some wikis were converted from ISO 8859-1 to UTF-8, the passwords can't be converted
900 # Check for this with iconv
901 /* $cp1252hash = $this->encryptPassword( iconv( 'UTF-8', 'WINDOWS-1252', $password ) );
902 if ( 0 == strcmp( $cp1252hash, $this->mPassword ) ) {
903 return true;
906 return false;