c7610d5e59069722fb22c9ceb328aea62dfffbbd
[lhc/web/wiklou.git] / includes / User.php
1 <?php
2 /**
3 * See user.doc
4 *
5 */
6
7 /**
8 *
9 */
10 require_once( 'WatchedItem.php' );
11
12 /**
13 *
14 */
15 class User {
16 /* private */ var $mId, $mName, $mPassword, $mEmail, $mNewtalk;
17 /* private */ var $mRights, $mOptions;
18 /* private */ var $mDataLoaded, $mNewpassword;
19 /* private */ var $mSkin;
20 /* private */ var $mBlockedby, $mBlockreason;
21 /* private */ var $mTouched;
22 /* private */ var $mCookiePassword;
23 /* private */ var $mRealName;
24 /* private */ var $mHash;
25
26 function User() {
27 $this->loadDefaults();
28 }
29
30 /**
31 * Static factory method
32 * @static
33 */
34 function newFromName( $name ) {
35 $u = new User();
36
37 # Clean up name according to title rules
38
39 $t = Title::newFromText( $name );
40 $u->setName( $t->getText() );
41 return $u;
42 }
43
44 /**
45 * @static
46 */
47 function whoIs( $id ) {
48 $dbr =& wfGetDB( DB_SLAVE );
49 return $dbr->getField( 'user', 'user_name', array( 'user_id' => $id ) );
50 }
51
52 /**
53 * @static
54 */
55 function whoIsReal( $id ) {
56 $dbr =& wfGetDB( DB_SLAVE );
57 return $dbr->getField( 'user', 'user_real_name', array( 'user_id' => $id ) );
58 }
59
60 /**
61 * @static
62 */
63 function idFromName( $name ) {
64 $fname = "User::idFromName";
65
66 $nt = Title::newFromText( $name );
67 if( is_null( $nt ) ) {
68 # Illegal name
69 return null;
70 }
71 $dbr =& wfGetDB( DB_SLAVE );
72 $s = $dbr->getArray( 'user', array( 'user_id' ), array( 'user_name' => $nt->getText() ), $fname );
73
74 if ( $s === false ) {
75 return 0;
76 } else {
77 return $s->user_id;
78 }
79 }
80
81 /**
82 * does the string match an anonymous user IP address?
83 * @static
84 */
85 function isIP( $name ) {
86 return preg_match("/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/",$name);
87 }
88
89 /**
90 * static
91 */
92 function randomPassword() {
93 $pwchars = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz';
94 $l = strlen( $pwchars ) - 1;
95
96 $np = $pwchars{mt_rand( 0, $l )} . $pwchars{mt_rand( 0, $l )} .
97 $pwchars{mt_rand( 0, $l )} . chr( mt_rand(48, 57) ) .
98 $pwchars{mt_rand( 0, $l )} . $pwchars{mt_rand( 0, $l )} .
99 $pwchars{mt_rand( 0, $l )};
100 return $np;
101 }
102
103 /**
104 *
105 */
106 function loadDefaults() {
107 global $wgLang, $wgIP;
108 global $wgNamespacesToBeSearchedDefault;
109
110 $this->mId = $this->mNewtalk = 0;
111 $this->mName = $wgIP;
112 $this->mRealName = $this->mEmail = '';
113 $this->mPassword = $this->mNewpassword = '';
114 $this->mRights = array();
115 $defOpt = $wgLang->getDefaultUserOptions() ;
116 foreach ( $defOpt as $oname => $val ) {
117 $this->mOptions[$oname] = $val;
118 }
119 foreach ($wgNamespacesToBeSearchedDefault as $nsnum => $val) {
120 $this->mOptions['searchNs'.$nsnum] = $val;
121 }
122 unset( $this->mSkin );
123 $this->mDataLoaded = false;
124 $this->mBlockedby = -1; # Unset
125 $this->mTouched = '0'; # Allow any pages to be cached
126 $this->cookiePassword = '';
127 $this->mHash = false;
128 }
129
130 /**
131 * @access private
132 */
133 function getBlockedStatus() {
134 global $wgIP, $wgBlockCache, $wgProxyList;
135
136 if ( -1 != $this->mBlockedby ) { return; }
137
138 $this->mBlockedby = 0;
139
140 # User blocking
141 if ( $this->mId ) {
142 $block = new Block();
143 if ( $block->load( $wgIP , $this->mId ) ) {
144 $this->mBlockedby = $block->mBy;
145 $this->mBlockreason = $block->mReason;
146 }
147 }
148
149 # IP/range blocking
150 if ( !$this->mBlockedby ) {
151 $block = $wgBlockCache->get( $wgIP );
152 if ( $block !== false ) {
153 $this->mBlockedby = $block->mBy;
154 $this->mBlockreason = $block->mReason;
155 }
156 }
157
158 # Proxy blocking
159 if ( !$this->mBlockedby ) {
160 if ( array_key_exists( $wgIP, $wgProxyList ) ) {
161 $this->mBlockreason = wfMsg( 'proxyblockreason' );
162 $this->mBlockedby = "Proxy blocker";
163 }
164 }
165 }
166
167 function isBlocked() {
168 $this->getBlockedStatus();
169 if ( 0 === $this->mBlockedby ) { return false; }
170 return true;
171 }
172
173 function blockedBy() {
174 $this->getBlockedStatus();
175 return $this->mBlockedby;
176 }
177
178 function blockedFor() {
179 $this->getBlockedStatus();
180 return $this->mBlockreason;
181 }
182
183 function SetupSession() {
184 global $wgSessionsInMemcached, $wgCookiePath, $wgCookieDomain;
185 if( $wgSessionsInMemcached ) {
186 require_once( 'MemcachedSessions.php' );
187 } elseif( 'files' != ini_get( 'session.save_handler' ) ) {
188 # If it's left on 'user' or another setting from another
189 # application, it will end up failing. Try to recover.
190 ini_set ( 'session.save_handler', 'files' );
191 }
192 session_set_cookie_params( 0, $wgCookiePath, $wgCookieDomain );
193 session_cache_limiter( 'private, must-revalidate' );
194 @session_start();
195 }
196
197 /**
198 * @static
199 */
200 function loadFromSession() {
201 global $wgMemc, $wgDBname;
202
203 if ( isset( $_SESSION['wsUserID'] ) ) {
204 if ( 0 != $_SESSION['wsUserID'] ) {
205 $sId = $_SESSION['wsUserID'];
206 } else {
207 return new User();
208 }
209 } else if ( isset( $_COOKIE["{$wgDBname}UserID"] ) ) {
210 $sId = IntVal( $_COOKIE["{$wgDBname}UserID"] );
211 $_SESSION['wsUserID'] = $sId;
212 } else {
213 return new User();
214 }
215 if ( isset( $_SESSION['wsUserName'] ) ) {
216 $sName = $_SESSION['wsUserName'];
217 } else if ( isset( $_COOKIE["{$wgDBname}UserName"] ) ) {
218 $sName = $_COOKIE["{$wgDBname}UserName"];
219 $_SESSION['wsUserName'] = $sName;
220 } else {
221 return new User();
222 }
223
224 $passwordCorrect = FALSE;
225 $user = $wgMemc->get( $key = "$wgDBname:user:id:$sId" );
226 if($makenew = !$user) {
227 wfDebug( "User::loadFromSession() unable to load from memcached\n" );
228 $user = new User();
229 $user->mId = $sId;
230 $user->loadFromDatabase();
231 } else {
232 wfDebug( "User::loadFromSession() got from cache!\n" );
233 }
234
235 if ( isset( $_SESSION['wsUserPassword'] ) ) {
236 $passwordCorrect = $_SESSION['wsUserPassword'] == $user->mPassword;
237 } else if ( isset( $_COOKIE["{$wgDBname}Password"] ) ) {
238 $user->mCookiePassword = $_COOKIE["{$wgDBname}Password"];
239 $_SESSION['wsUserPassword'] = $user->addSalt( $user->mCookiePassword );
240 $passwordCorrect = $_SESSION['wsUserPassword'] == $user->mPassword;
241 } else {
242 return new User(); # Can't log in from session
243 }
244
245 if ( ( $sName == $user->mName ) && $passwordCorrect ) {
246 if($makenew) {
247 if($wgMemc->set( $key, $user ))
248 wfDebug( "User::loadFromSession() successfully saved user\n" );
249 else
250 wfDebug( "User::loadFromSession() unable to save to memcached\n" );
251 }
252 $user->spreadBlock();
253 return $user;
254 }
255 return new User(); # Can't log in from session
256 }
257
258 /**
259 *
260 */
261 function loadFromDatabase() {
262 global $wgCommandLineMode;
263 $fname = "User::loadFromDatabase";
264 if ( $this->mDataLoaded || $wgCommandLineMode ) {
265 return;
266 }
267
268 # Paranoia
269 $this->mId = IntVal( $this->mId );
270
271 # check in separate table if there are changes to the talk page
272 $this->mNewtalk=0; # reset talk page status
273 $dbr =& wfGetDB( DB_SLAVE );
274 if($this->mId) {
275 $res = $dbr->select( 'user_newtalk', 1, array( 'user_id' => $this->mId ), $fname );
276
277 if ( $dbr->numRows($res)>0 ) {
278 $this->mNewtalk= 1;
279 }
280 $dbr->freeResult( $res );
281 } else {
282 global $wgDBname, $wgMemc;
283 $key = "$wgDBname:newtalk:ip:{$this->mName}";
284 $newtalk = $wgMemc->get( $key );
285 if( ! is_integer( $newtalk ) ){
286 $res = $dbr->select( 'user_newtalk', 1, array( 'user_ip' => $this->mName ), $fname );
287
288 $this->mNewtalk = $dbr->numRows( $res ) > 0 ? 1 : 0;
289 $dbr->freeResult( $res );
290
291 $wgMemc->set( $key, $this->mNewtalk, time() ); // + 1800 );
292 } else {
293 $this->mNewtalk = $newtalk ? 1 : 0;
294 }
295 }
296 if(!$this->mId) {
297 $this->mDataLoaded = true;
298 return;
299 } # the following stuff is for non-anonymous users only
300
301 $s = $dbr->getArray( 'user', array( 'user_name','user_password','user_newpassword','user_email',
302 'user_real_name','user_options','user_touched' ),
303 array( 'user_id' => $this->mId ), $fname );
304
305 if ( $s !== false ) {
306 $this->mName = $s->user_name;
307 $this->mEmail = $s->user_email;
308 $this->mRealName = $s->user_real_name;
309 $this->mPassword = $s->user_password;
310 $this->mNewpassword = $s->user_newpassword;
311 $this->decodeOptions( $s->user_options );
312 $this->mTouched = wfTimestamp(TS_MW,$s->user_touched);
313 $this->mRights = explode( ",", strtolower(
314 $dbr->getField( 'user_rights', 'user_rights', array( 'user_id' => $this->mId ) )
315 ) );
316 }
317
318 $this->mDataLoaded = true;
319 }
320
321 function getID() { return $this->mId; }
322 function setID( $v ) {
323 $this->mId = $v;
324 $this->mDataLoaded = false;
325 }
326
327 function getName() {
328 $this->loadFromDatabase();
329 return $this->mName;
330 }
331
332 function setName( $str ) {
333 $this->loadFromDatabase();
334 $this->mName = $str;
335 }
336
337 function getNewtalk() {
338 $this->loadFromDatabase();
339 return ( 0 != $this->mNewtalk );
340 }
341
342 function setNewtalk( $val )
343 {
344 $this->loadFromDatabase();
345 $this->mNewtalk = $val;
346 $this->invalidateCache();
347 }
348
349 function invalidateCache() {
350 $this->loadFromDatabase();
351 $this->mTouched = wfTimestampNow();
352 # Don't forget to save the options after this or
353 # it won't take effect!
354 }
355
356 function validateCache( $timestamp ) {
357 $this->loadFromDatabase();
358 return ($timestamp >= $this->mTouched);
359 }
360
361 function addSalt( $p ) {
362 global $wgPasswordSalt;
363 if($wgPasswordSalt)
364 return md5( "{$this->mId}-{$p}" );
365 else
366 return $p;
367 }
368
369 function encryptPassword( $p ) {
370 return $this->addSalt( md5( $p ) );
371 }
372
373 function setPassword( $str ) {
374 $this->loadFromDatabase();
375 $this->setCookiePassword( $str );
376 $this->mPassword = $this->encryptPassword( $str );
377 $this->mNewpassword = '';
378 }
379
380 function setCookiePassword( $str ) {
381 $this->loadFromDatabase();
382 $this->mCookiePassword = md5( $str );
383 }
384
385 function setNewpassword( $str ) {
386 $this->loadFromDatabase();
387 $this->mNewpassword = $this->encryptPassword( $str );
388 }
389
390 function getEmail() {
391 $this->loadFromDatabase();
392 return $this->mEmail;
393 }
394
395 function setEmail( $str ) {
396 $this->loadFromDatabase();
397 $this->mEmail = $str;
398 }
399
400 function getRealName() {
401 $this->loadFromDatabase();
402 return $this->mRealName;
403 }
404
405 function setRealName( $str ) {
406 $this->loadFromDatabase();
407 $this->mRealName = $str;
408 }
409
410 function getOption( $oname ) {
411 $this->loadFromDatabase();
412 if ( array_key_exists( $oname, $this->mOptions ) ) {
413 return $this->mOptions[$oname];
414 } else {
415 return '';
416 }
417 }
418
419 function setOption( $oname, $val ) {
420 $this->loadFromDatabase();
421 if ( $oname == 'skin' ) {
422 # Clear cached skin, so the new one displays immediately in Special:Preferences
423 unset( $this->mSkin );
424 }
425 $this->mOptions[$oname] = $val;
426 $this->invalidateCache();
427 }
428
429 function getRights() {
430 $this->loadFromDatabase();
431 return $this->mRights;
432 }
433
434 function addRight( $rname ) {
435 $this->loadFromDatabase();
436 array_push( $this->mRights, $rname );
437 $this->invalidateCache();
438 }
439
440 function isSysop() {
441 $this->loadFromDatabase();
442 if ( 0 == $this->mId ) { return false; }
443
444 return in_array( 'sysop', $this->mRights );
445 }
446
447 function isDeveloper() {
448 $this->loadFromDatabase();
449 if ( 0 == $this->mId ) { return false; }
450
451 return in_array( 'developer', $this->mRights );
452 }
453
454 function isBureaucrat() {
455 $this->loadFromDatabase();
456 if ( 0 == $this->mId ) { return false; }
457
458 return in_array( 'bureaucrat', $this->mRights );
459 }
460
461 function isBot() {
462 $this->loadFromDatabase();
463
464 # Why was this here? I need a UID=0 conversion script [TS]
465 # if ( 0 == $this->mId ) { return false; }
466
467 return in_array( 'bot', $this->mRights );
468 }
469
470 /**
471 * Load a skin if it doesn't exist or return it
472 * @todo FIXME : need to check the old failback system [AV]
473 */
474 function &getSkin() {
475 global $IP, $wgUsePHPTal;
476 if ( ! isset( $this->mSkin ) ) {
477 # get all skin names available
478 $skinNames = Skin::getSkinNames();
479 # get the user skin
480 $userSkin = $this->getOption( 'skin' );
481 if ( $userSkin == '' ) { $userSkin = 'standard'; }
482
483 if ( !isset( $skinNames[$userSkin] ) ) {
484 # in case the user skin could not be found find a replacement
485 $fallback = array(
486 0 => 'Standard',
487 1 => 'Nostalgia',
488 2 => 'CologneBlue');
489 # if phptal is enabled we should have monobook skin that
490 # superseed the good old SkinStandard.
491 if ( isset( $skinNames['monobook'] ) ) {
492 $fallback[0] = 'MonoBook';
493 }
494
495 if(is_numeric($userSkin) && isset( $fallback[$userSkin]) ){
496 $sn = $fallback[$userSkin];
497 } else {
498 $sn = 'Standard';
499 }
500 } else {
501 # The user skin is available
502 $sn = $skinNames[$userSkin];
503 }
504
505 # Grab the skin class and initialise it. Each skin checks for PHPTal
506 # and will not load if it's not enabled.
507 require_once( $IP.'/skins/'.$sn.'.php' );
508
509 # Check if we got if not failback to default skin
510 $sn = 'Skin'.$sn;
511 if(!class_exists($sn)) {
512 #FIXME : should we print an error message instead of loading
513 # standard skin ?
514 $sn = 'SkinStandard';
515 require_once( $IP.'/skins/Standard.php' );
516 }
517 $this->mSkin = new $sn;
518 }
519 return $this->mSkin;
520 }
521
522 function isWatched( $title ) {
523 $wl = WatchedItem::fromUserTitle( $this, $title );
524 return $wl->isWatched();
525 }
526
527 function addWatch( $title ) {
528 $wl = WatchedItem::fromUserTitle( $this, $title );
529 $wl->addWatch();
530 $this->invalidateCache();
531 }
532
533 function removeWatch( $title ) {
534 $wl = WatchedItem::fromUserTitle( $this, $title );
535 $wl->removeWatch();
536 $this->invalidateCache();
537 }
538
539
540 /**
541 * @access private
542 */
543 function encodeOptions() {
544 $a = array();
545 foreach ( $this->mOptions as $oname => $oval ) {
546 array_push( $a, $oname.'='.$oval );
547 }
548 $s = implode( "\n", $a );
549 return $s;
550 }
551
552 /**
553 * @access private
554 */
555 function decodeOptions( $str ) {
556 $a = explode( "\n", $str );
557 foreach ( $a as $s ) {
558 if ( preg_match( "/^(.[^=]*)=(.*)$/", $s, $m ) ) {
559 $this->mOptions[$m[1]] = $m[2];
560 }
561 }
562 }
563
564 function setCookies() {
565 global $wgCookieExpiration, $wgCookiePath, $wgCookieDomain, $wgDBname;
566 if ( 0 == $this->mId ) return;
567 $this->loadFromDatabase();
568 $exp = time() + $wgCookieExpiration;
569
570 $_SESSION['wsUserID'] = $this->mId;
571 setcookie( $wgDBname.'UserID', $this->mId, $exp, $wgCookiePath, $wgCookieDomain );
572
573 $_SESSION['wsUserName'] = $this->mName;
574 setcookie( $wgDBname.'UserName', $this->mName, $exp, $wgCookiePath, $wgCookieDomain );
575
576 $_SESSION['wsUserPassword'] = $this->mPassword;
577 if ( 1 == $this->getOption( 'rememberpassword' ) ) {
578 setcookie( $wgDBname.'Password', $this->mCookiePassword, $exp, $wgCookiePath, $wgCookieDomain );
579 } else {
580 setcookie( $wgDBname.'Password', '', time() - 3600 );
581 }
582 }
583
584 function logout() {
585 global $wgCookiePath, $wgCookieDomain, $wgDBname;
586 $this->mId = 0;
587
588 $_SESSION['wsUserID'] = 0;
589
590 setcookie( $wgDBname.'UserID', '', time() - 3600, $wgCookiePath, $wgCookieDomain );
591 setcookie( $wgDBname.'Password', '', time() - 3600, $wgCookiePath, $wgCookieDomain );
592 }
593
594 function saveSettings() {
595 global $wgMemc, $wgDBname;
596 $fname = 'User::saveSettings';
597
598 $dbw =& wfGetDB( DB_MASTER );
599 if ( ! $this->mNewtalk ) {
600 # Delete user_newtalk row
601 if( $this->mId ) {
602 $dbw->delete( 'user_newtalk', array( 'user_id' => $this->mId ), $fname );
603 } else {
604 $dbw->delete( 'user_newtalk', array( 'user_ip' => $this->mName ), $fname );
605 $wgMemc->delete( "$wgDBname:newtalk:ip:{$this->mName}" );
606 }
607 }
608 if ( 0 == $this->mId ) { return; }
609
610 $dbw->update( 'user',
611 array( /* SET */
612 'user_name' => $this->mName,
613 'user_password' => $this->mPassword,
614 'user_newpassword' => $this->mNewpassword,
615 'user_real_name' => $this->mRealName,
616 'user_email' => $this->mEmail,
617 'user_options' => $this->encodeOptions(),
618 'user_touched' => $dbw->timestamp($this->mTouched)
619 ), array( /* WHERE */
620 'user_id' => $this->mId
621 ), $fname
622 );
623 $dbw->set( 'user_rights', 'user_rights', implode( ",", $this->mRights ),
624 'user_id='. $this->mId, $fname );
625 $wgMemc->delete( "$wgDBname:user:id:$this->mId" );
626 }
627
628 /**
629 * Checks if a user with the given name exists, returns the ID
630 */
631 function idForName() {
632 $fname = 'User::idForName';
633
634 $gotid = 0;
635 $s = trim( $this->mName );
636 if ( 0 == strcmp( '', $s ) ) return 0;
637
638 $dbr =& wfGetDB( DB_SLAVE );
639 $id = $dbr->selectField( 'user', 'user_id', array( 'user_name' => $s ), $fname );
640 if ( $id === false ) {
641 $id = 0;
642 }
643 return $id;
644 }
645
646 function addToDatabase() {
647 $fname = 'User::addToDatabase';
648 $dbw =& wfGetDB( DB_MASTER );
649 $seqVal = $dbw->nextSequenceValue( 'user_user_id_seq' );
650 $dbw->insert( 'user',
651 array(
652 'user_id' => $seqVal,
653 'user_name' => $this->mName,
654 'user_password' => $this->mPassword,
655 'user_newpassword' => $this->mNewpassword,
656 'user_email' => $this->mEmail,
657 'user_real_name' => $this->mRealName,
658 'user_options' => $this->encodeOptions()
659 ), $fname
660 );
661 $this->mId = $dbw->insertId();
662 $dbw->insert( 'user_rights',
663 array(
664 'user_id' => $this->mId,
665 'user_rights' => implode( ',', $this->mRights )
666 ), $fname
667 );
668
669 }
670
671 function spreadBlock() {
672 global $wgIP;
673 # If the (non-anonymous) user is blocked, this function will block any IP address
674 # that they successfully log on from.
675 $fname = 'User::spreadBlock';
676
677 wfDebug( "User:spreadBlock()\n" );
678 if ( $this->mId == 0 ) {
679 return;
680 }
681
682 $userblock = Block::newFromDB( '', $this->mId );
683 if ( !$userblock->isValid() ) {
684 return;
685 }
686
687 # Check if this IP address is already blocked
688 $ipblock = Block::newFromDB( $wgIP );
689 if ( $ipblock->isValid() ) {
690 # Just update the timestamp
691 $ipblock->updateTimestamp();
692 return;
693 }
694
695 # Make a new block object with the desired properties
696 wfDebug( "Autoblocking {$this->mName}@{$wgIP}\n" );
697 $ipblock->mAddress = $wgIP;
698 $ipblock->mUser = 0;
699 $ipblock->mBy = $userblock->mBy;
700 $ipblock->mReason = wfMsg( 'autoblocker', $this->getName(), $userblock->mReason );
701 $ipblock->mTimestamp = wfTimestampNow();
702 $ipblock->mAuto = 1;
703 # If the user is already blocked with an expiry date, we don't
704 # want to pile on top of that!
705 if($userblock->mExpiry) {
706 $ipblock->mExpiry = min ( $userblock->mExpiry, Block::getAutoblockExpiry( $ipblock->mTimestamp ));
707 } else {
708 $ipblock->mExpiry = Block::getAutoblockExpiry( $ipblock->mTimestamp );
709 }
710
711 # Insert it
712 $ipblock->insert();
713
714 }
715
716 function getPageRenderingHash() {
717 if( $this->mHash ){
718 return $this->mHash;
719 }
720
721 // stubthreshold is only included below for completeness,
722 // it will always be 0 when this function is called by parsercache.
723
724 $confstr = $this->getOption( 'math' );
725 $confstr .= '!' . $this->getOption( 'highlightbroken' );
726 $confstr .= '!' . $this->getOption( 'stubthreshold' );
727 $confstr .= '!' . $this->getOption( 'editsection' );
728 $confstr .= '!' . $this->getOption( 'editsectiononrightclick' );
729 $confstr .= '!' . $this->getOption( 'showtoc' );
730 $confstr .= '!' . $this->getOption( 'date' );
731 $confstr .= '!' . $this->getOption( 'numberheadings' );
732
733 $this->mHash = $confstr;
734 return $confstr ;
735 }
736
737 function isAllowedToCreateAccount() {
738 global $wgWhitelistAccount;
739 $allowed = false;
740
741 if (!$wgWhitelistAccount) { return 1; }; // default behaviour
742 foreach ($wgWhitelistAccount as $right => $ok) {
743 $userHasRight = (!strcmp($right, 'user') || in_array($right, $this->getRights()));
744 $allowed |= ($ok && $userHasRight);
745 }
746 return $allowed;
747 }
748
749 /**
750 * Set mDataLoaded, return previous value
751 * Use this to prevent DB access in command-line scripts or similar situations
752 */
753 function setLoaded( $loaded ) {
754 return wfSetVar( $this->mDataLoaded, $loaded );
755 }
756
757 function getUserPage() {
758 return Title::makeTitle( NS_USER, $this->mName );
759 }
760
761 /**
762 * @static
763 */
764 function getMaxID() {
765 $dbr =& wfGetDB( DB_SLAVE );
766 return $dbr->selectField( 'user', 'max(user_id)', false );
767 }
768
769 function isNewbie() {
770 return $this->mId > User::getMaxID() * 0.99 && !$this->isSysop() && !$this->isBot() || $this->getID() == 0;
771 }
772
773 /**
774 * Check to see if the given clear-text password is one of the accepted passwords
775 */
776 function checkPassword( $password ) {
777 $this->loadFromDatabase();
778 $ep = $this->encryptPassword( $password );
779 if ( 0 == strcmp( $ep, $this->mPassword ) ) {
780 return true;
781 } elseif ( 0 == strcmp( $ep, $this->mNewpassword ) ) {
782 return true;
783 } elseif ( function_exists( 'iconv' ) ) {
784 # Some wikis were converted from ISO 8859-1 to UTF-8, the passwords can't be converted
785 # Check for this with iconv
786 /* $cp1252hash = $this->encryptPassword( iconv( 'UTF-8', 'WINDOWS-1252', $password ) );
787 if ( 0 == strcmp( $cp1252hash, $this->mPassword ) ) {
788 return true;
789 }*/
790 }
791 return false;
792 }
793 }
794
795 ?>