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