11 require_once( 'WatchedItem.php' );
12 require_once( 'Group.php' );
14 # Number of characters in user_token field
15 define( 'USER_TOKEN_LENGTH', 32 );
25 var $mId, $mName, $mPassword, $mEmail, $mNewtalk;
26 var $mRights, $mOptions;
27 var $mDataLoaded, $mNewpassword;
29 var $mBlockedby, $mBlockreason;
34 /** Array of group id the user belong to */
38 /** Construct using User:loadDefaults() */
40 $this->loadDefaults();
44 * Static factory method
46 * @param string $name Username, validated by Title:newFromText()
48 function newFromName( $name ) {
51 # Clean up name according to title rules
53 $t = Title
::newFromText( $name );
57 $u->setName( $t->getText() );
63 * Get username given an id.
64 * @param integer $id Database user id
65 * @return string Nickname of a user
68 function whoIs( $id ) {
69 $dbr =& wfGetDB( DB_SLAVE
);
70 return $dbr->selectField( 'user', 'user_name', array( 'user_id' => $id ) );
74 * Get real username given an id.
75 * @param integer $id Database user id
76 * @return string Realname of a user
79 function whoIsReal( $id ) {
80 $dbr =& wfGetDB( DB_SLAVE
);
81 return $dbr->selectField( 'user', 'user_real_name', array( 'user_id' => $id ) );
85 * Get database id given a user name
86 * @param string $name Nickname of a user
87 * @return integer|null Database user id (null: if non existent
90 function idFromName( $name ) {
91 $fname = "User::idFromName";
93 $nt = Title
::newFromText( $name );
94 if( is_null( $nt ) ) {
98 $dbr =& wfGetDB( DB_SLAVE
);
99 $s = $dbr->selectRow( 'user', array( 'user_id' ), array( 'user_name' => $nt->getText() ), $fname );
101 if ( $s === false ) {
109 * does the string match an anonymous user IP address?
110 * @param string $name Nickname of a user
113 function isIP( $name ) {
114 return preg_match("/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/",$name);
118 * probably return a random password
119 * @return string probably a random password
121 * @todo Check what is doing really [AV]
123 function randomPassword() {
124 $pwchars = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz';
125 $l = strlen( $pwchars ) - 1;
127 $np = $pwchars{mt_rand( 0, $l )} . $pwchars{mt_rand( 0, $l )} .
128 $pwchars{mt_rand( 0, $l )} . chr( mt_rand(48, 57) ) .
129 $pwchars{mt_rand( 0, $l )} . $pwchars{mt_rand( 0, $l )} .
130 $pwchars{mt_rand( 0, $l )};
135 * Set properties to default
136 * Used at construction. It will load per language default settings only
137 * if we have an available language object.
139 function loadDefaults() {
140 global $wgContLang, $wgIP;
141 global $wgNamespacesToBeSearchedDefault;
144 $this->mNewtalk
= -1;
145 $this->mName
= $wgIP;
146 $this->mRealName
= $this->mEmail
= '';
147 $this->mPassword
= $this->mNewpassword
= '';
148 $this->mRights
= array();
149 $this->mGroups
= array();
151 // Getting user defaults only if we have an available language
152 if(isset($wgContLang)) { $this->loadDefaultFromLanguage(); }
154 foreach ($wgNamespacesToBeSearchedDefault as $nsnum => $val) {
155 $this->mOptions
['searchNs'.$nsnum] = $val;
157 unset( $this->mSkin
);
158 $this->mDataLoaded
= false;
159 $this->mBlockedby
= -1; # Unset
160 $this->mTouched
= '0'; # Allow any pages to be cached
161 $this->setToken(); # Random
162 $this->mHash
= false;
166 * Used to load user options from a language.
167 * This is not in loadDefault() cause we sometime create user before having
170 function loadDefaultFromLanguage(){
172 $defOpt = $wgContLang->getDefaultUserOptions() ;
173 foreach ( $defOpt as $oname => $val ) {
174 $this->mOptions
[$oname] = $val;
177 default language setting
179 $this->setOption('variant', $wgContLang->getPreferredVariant());
180 $this->setOption('language', $wgContLang->getPreferredVariant());
184 * Get blocking information
187 function getBlockedStatus() {
188 global $wgIP, $wgBlockCache, $wgProxyList;
190 if ( -1 != $this->mBlockedby
) { return; }
192 $this->mBlockedby
= 0;
196 $block = new Block();
197 if ( $block->load( $wgIP , $this->mId
) ) {
198 $this->mBlockedby
= $block->mBy
;
199 $this->mBlockreason
= $block->mReason
;
204 if ( !$this->mBlockedby
) {
205 $block = $wgBlockCache->get( $wgIP );
206 if ( $block !== false ) {
207 $this->mBlockedby
= $block->mBy
;
208 $this->mBlockreason
= $block->mReason
;
213 if ( !$this->mBlockedby
) {
214 if ( array_key_exists( $wgIP, $wgProxyList ) ) {
215 $this->mBlockreason
= wfMsg( 'proxyblockreason' );
216 $this->mBlockedby
= "Proxy blocker";
222 * Check if user is blocked
223 * @return bool True if blocked, false otherwise
225 function isBlocked() {
226 $this->getBlockedStatus();
227 if ( 0 === $this->mBlockedby
) { return false; }
232 * Get name of blocker
233 * @return string name of blocker
235 function blockedBy() {
236 $this->getBlockedStatus();
237 return $this->mBlockedby
;
241 * Get blocking reason
242 * @return string Blocking reason
244 function blockedFor() {
245 $this->getBlockedStatus();
246 return $this->mBlockreason
;
250 * Initialise php session
252 function SetupSession() {
253 global $wgSessionsInMemcached, $wgCookiePath, $wgCookieDomain;
254 if( $wgSessionsInMemcached ) {
255 require_once( 'MemcachedSessions.php' );
256 } elseif( 'files' != ini_get( 'session.save_handler' ) ) {
257 # If it's left on 'user' or another setting from another
258 # application, it will end up failing. Try to recover.
259 ini_set ( 'session.save_handler', 'files' );
261 session_set_cookie_params( 0, $wgCookiePath, $wgCookieDomain );
262 session_cache_limiter( 'private, must-revalidate' );
267 * Read datas from session
270 function loadFromSession() {
271 global $wgMemc, $wgDBname;
273 if ( isset( $_SESSION['wsUserID'] ) ) {
274 if ( 0 != $_SESSION['wsUserID'] ) {
275 $sId = $_SESSION['wsUserID'];
279 } else if ( isset( $_COOKIE["{$wgDBname}UserID"] ) ) {
280 $sId = IntVal( $_COOKIE["{$wgDBname}UserID"] );
281 $_SESSION['wsUserID'] = $sId;
285 if ( isset( $_SESSION['wsUserName'] ) ) {
286 $sName = $_SESSION['wsUserName'];
287 } else if ( isset( $_COOKIE["{$wgDBname}UserName"] ) ) {
288 $sName = $_COOKIE["{$wgDBname}UserName"];
289 $_SESSION['wsUserName'] = $sName;
294 $passwordCorrect = FALSE;
295 $user = $wgMemc->get( $key = "$wgDBname:user:id:$sId" );
296 if($makenew = !$user) {
297 wfDebug( "User::loadFromSession() unable to load from memcached\n" );
300 $user->loadFromDatabase();
302 wfDebug( "User::loadFromSession() got from cache!\n" );
305 if ( isset( $_SESSION['wsToken'] ) ) {
306 $passwordCorrect = $_SESSION['wsToken'] == $user->mToken
;
307 } else if ( isset( $_COOKIE["{$wgDBname}Token"] ) ) {
308 $passwordCorrect = $user->mToken
== $_COOKIE["{$wgDBname}Token"];
310 return new User(); # Can't log in from session
313 if ( ( $sName == $user->mName
) && $passwordCorrect ) {
315 if($wgMemc->set( $key, $user ))
316 wfDebug( "User::loadFromSession() successfully saved user\n" );
318 wfDebug( "User::loadFromSession() unable to save to memcached\n" );
320 $user->spreadBlock();
323 return new User(); # Can't log in from session
327 * Load a user from the database
329 function loadFromDatabase() {
330 global $wgCommandLineMode, $wgAnonGroupId, $wgLoggedInGroupId;
331 $fname = "User::loadFromDatabase";
332 if ( $this->mDataLoaded ||
$wgCommandLineMode ) {
337 $this->mId
= IntVal( $this->mId
);
339 /** Anonymous user */
342 $anong = Group
::newFromId($wgAnonGroupId);
344 wfDebugDieBacktrace("Please update your database schema "
345 ."and populate initial group data from "
346 ."maintenance/archives patches");
347 $anong->loadFromDatabase();
348 $this->mRights
= explode(',', $anong->getRights());
349 $this->mDataLoaded
= true;
351 } # the following stuff is for non-anonymous users only
353 $dbr =& wfGetDB( DB_SLAVE
);
354 $s = $dbr->selectRow( 'user', array( 'user_name','user_password','user_newpassword','user_email',
355 'user_real_name','user_options','user_touched', 'user_token' ),
356 array( 'user_id' => $this->mId
), $fname );
358 if ( $s !== false ) {
359 $this->mName
= $s->user_name
;
360 $this->mEmail
= $s->user_email
;
361 $this->mRealName
= $s->user_real_name
;
362 $this->mPassword
= $s->user_password
;
363 $this->mNewpassword
= $s->user_newpassword
;
364 $this->decodeOptions( $s->user_options
);
365 $this->mTouched
= wfTimestamp(TS_MW
,$s->user_touched
);
366 $this->mToken
= $s->user_token
;
369 $res = $dbr->select( 'user_groups', array( 'ug_group' ), array( 'ug_user' => $this->mId
) );
371 while($group = $dbr->fetchRow($res)) {
372 $this->mGroups
[] = $group[0];
375 // add the default group for logged in user
376 $this->mGroups
[] = $wgLoggedInGroupId;
378 $this->mRights
= array();
379 // now we merge groups rights to get this user rights
380 foreach($this->mGroups
as $aGroupId) {
381 $g = Group
::newFromId($aGroupId);
382 $g->loadFromDatabase();
383 $this->mRights
= array_merge($this->mRights
, explode(',', $g->getRights()));
386 // array merge duplicate rights which are part of several groups
387 $this->mRights
= array_unique($this->mRights
);
389 $dbr->freeResult($res);
392 $this->mDataLoaded
= true;
395 function getID() { return $this->mId
; }
396 function setID( $v ) {
398 $this->mDataLoaded
= false;
402 $this->loadFromDatabase();
406 function setName( $str ) {
407 $this->loadFromDatabase();
411 function getNewtalk() {
412 $fname = 'User::getNewtalk';
413 $this->loadFromDatabase();
415 # Load the newtalk status if it is unloaded (mNewtalk=-1)
416 if ( $this->mNewtalk
== -1 ) {
417 $this->mNewtalk
=0; # reset talk page status
418 $dbr =& wfGetDB( DB_SLAVE
);
420 $res = $dbr->select( 'user_newtalk', 1, array( 'user_id' => $this->mId
), $fname );
422 if ( $dbr->numRows($res)>0 ) {
425 $dbr->freeResult( $res );
427 global $wgDBname, $wgMemc;
428 $key = "$wgDBname:newtalk:ip:{$this->mName}";
429 $newtalk = $wgMemc->get( $key );
430 if( ! is_integer( $newtalk ) ){
431 $res = $dbr->select( 'user_newtalk', 1, array( 'user_ip' => $this->mName
), $fname );
433 $this->mNewtalk
= $dbr->numRows( $res ) > 0 ?
1 : 0;
434 $dbr->freeResult( $res );
436 $wgMemc->set( $key, $this->mNewtalk
, time() ); // + 1800 );
438 $this->mNewtalk
= $newtalk ?
1 : 0;
443 return ( 0 != $this->mNewtalk
);
446 function setNewtalk( $val ) {
447 $this->loadFromDatabase();
448 $this->mNewtalk
= $val;
449 $this->invalidateCache();
452 function invalidateCache() {
453 $this->loadFromDatabase();
454 $this->mTouched
= wfTimestampNow();
455 # Don't forget to save the options after this or
456 # it won't take effect!
459 function validateCache( $timestamp ) {
460 $this->loadFromDatabase();
461 return ($timestamp >= $this->mTouched
);
466 * Will only be salted if $wgPasswordSalt is true
467 * @param string Password.
468 * @return string Salted password or clear password.
470 function addSalt( $p ) {
471 global $wgPasswordSalt;
473 return md5( "{$this->mId}-{$p}" );
479 * Encrypt a password.
480 * It can eventuall salt a password @see User::addSalt()
481 * @param string $p clear Password.
482 * @param string Encrypted password.
484 function encryptPassword( $p ) {
485 return $this->addSalt( md5( $p ) );
488 # Set the password and reset the random token
489 function setPassword( $str ) {
490 $this->loadFromDatabase();
492 $this->mPassword
= $this->encryptPassword( $str );
493 $this->mNewpassword
= '';
496 # Set the random token (used for persistent authentication)
497 function setToken( $token = false ) {
500 # Take random data from PRNG
501 # This is reasonably secure if the PRNG has been seeded correctly
502 for ($i = 0; $i<USER_TOKEN_LENGTH
/ 4; $i++
) {
503 $this->mToken
.= sprintf( "%04X", mt_rand( 0, 65535 ) );
506 $this->mToken
= $token;
511 function setCookiePassword( $str ) {
512 $this->loadFromDatabase();
513 $this->mCookiePassword
= md5( $str );
516 function setNewpassword( $str ) {
517 $this->loadFromDatabase();
518 $this->mNewpassword
= $this->encryptPassword( $str );
521 function getEmail() {
522 $this->loadFromDatabase();
523 return $this->mEmail
;
526 function setEmail( $str ) {
527 $this->loadFromDatabase();
528 $this->mEmail
= $str;
531 function getRealName() {
532 $this->loadFromDatabase();
533 return $this->mRealName
;
536 function setRealName( $str ) {
537 $this->loadFromDatabase();
538 $this->mRealName
= $str;
541 function getOption( $oname ) {
542 $this->loadFromDatabase();
543 if ( array_key_exists( $oname, $this->mOptions
) ) {
544 return $this->mOptions
[$oname];
550 function setOption( $oname, $val ) {
551 $this->loadFromDatabase();
552 if ( $oname == 'skin' ) {
553 # Clear cached skin, so the new one displays immediately in Special:Preferences
554 unset( $this->mSkin
);
556 $this->mOptions
[$oname] = $val;
557 $this->invalidateCache();
560 function getRights() {
561 $this->loadFromDatabase();
562 return $this->mRights
;
565 function addRight( $rname ) {
566 $this->loadFromDatabase();
567 array_push( $this->mRights
, $rname );
568 $this->invalidateCache();
571 function getGroups() {
572 $this->loadFromDatabase();
573 return $this->mGroups
;
576 function setGroups($groups) {
577 $this->loadFromDatabase();
578 $this->mGroups
= $groups;
579 $this->invalidateCache();
583 * Check if a user is sysop
584 * Die with backtrace. Use User:isAllowed() instead.
589 $this->loadFromDatabase();
590 if ( 0 == $this->mId ) { return false; }
592 return in_array( 'sysop', $this->mRights );
594 wfDebugDieBacktrace("User::isSysop() is deprecated. Use User::isAllowed() instead");
598 function isDeveloper() {
600 $this->loadFromDatabase();
601 if ( 0 == $this->mId ) { return false; }
603 return in_array( 'developer', $this->mRights );
605 wfDebugDieBacktrace("User::isDeveloper() is deprecated. Use User::isAllowed() instead");
609 function isBureaucrat() {
611 $this->loadFromDatabase();
612 if ( 0 == $this->mId ) { return false; }
614 return in_array( 'bureaucrat', $this->mRights );
616 wfDebugDieBacktrace("User::isBureaucrat() is deprecated. Use User::isAllowed() instead");
620 * Whether the user is a bot
621 * @todo need to be migrated to the new user level management sytem
624 $this->loadFromDatabase();
626 # Why was this here? I need a UID=0 conversion script [TS]
627 # if ( 0 == $this->mId ) { return false; }
629 return in_array( 'bot', $this->mRights
);
633 * Check if user is allowed to access a feature / make an action
634 * @param string $action Action to be checked (see $wgAvailableRights in Defines.php for possible actions).
635 * @return boolean True: action is allowed, False: action should not be allowed
637 function isAllowed($action='') {
638 $this->loadFromDatabase();
639 return in_array( $action , $this->mRights
);
643 * Load a skin if it doesn't exist or return it
644 * @todo FIXME : need to check the old failback system [AV]
646 function &getSkin() {
647 global $IP, $wgUsePHPTal;
648 if ( ! isset( $this->mSkin
) ) {
649 # get all skin names available
650 $skinNames = Skin
::getSkinNames();
652 $userSkin = $this->getOption( 'skin' );
653 if ( $userSkin == '' ) { $userSkin = 'standard'; }
655 if ( !isset( $skinNames[$userSkin] ) ) {
656 # in case the user skin could not be found find a replacement
661 # if phptal is enabled we should have monobook skin that
662 # superseed the good old SkinStandard.
663 if ( isset( $skinNames['monobook'] ) ) {
664 $fallback[0] = 'MonoBook';
667 if(is_numeric($userSkin) && isset( $fallback[$userSkin]) ){
668 $sn = $fallback[$userSkin];
673 # The user skin is available
674 $sn = $skinNames[$userSkin];
677 # Grab the skin class and initialise it. Each skin checks for PHPTal
678 # and will not load if it's not enabled.
679 require_once( $IP.'/skins/'.$sn.'.php' );
681 # Check if we got if not failback to default skin
682 $className = 'Skin'.$sn;
683 if( !class_exists( $className ) ) {
684 # DO NOT die if the class isn't found. This breaks maintenance
685 # scripts and can cause a user account to be unrecoverable
686 # except by SQL manipulation if a previously valid skin name
687 # is no longer valid.
688 $className = 'SkinStandard';
689 require_once( $IP.'/skins/Standard.php' );
691 $this->mSkin
= new $className;
697 * @param string $title Article title to look at
701 * Check watched status of an article
702 * @return bool True if article is watched
704 function isWatched( $title ) {
705 $wl = WatchedItem
::fromUserTitle( $this, $title );
706 return $wl->isWatched();
712 function addWatch( $title ) {
713 $wl = WatchedItem
::fromUserTitle( $this, $title );
715 $this->invalidateCache();
719 * Stop watching an article
721 function removeWatch( $title ) {
722 $wl = WatchedItem
::fromUserTitle( $this, $title );
724 $this->invalidateCache();
730 * @return string Encoding options
732 function encodeOptions() {
734 foreach ( $this->mOptions
as $oname => $oval ) {
735 array_push( $a, $oname.'='.$oval );
737 $s = implode( "\n", $a );
744 function decodeOptions( $str ) {
745 $a = explode( "\n", $str );
746 foreach ( $a as $s ) {
747 if ( preg_match( "/^(.[^=]*)=(.*)$/", $s, $m ) ) {
748 $this->mOptions
[$m[1]] = $m[2];
753 function setCookies() {
754 global $wgCookieExpiration, $wgCookiePath, $wgCookieDomain, $wgDBname;
755 if ( 0 == $this->mId
) return;
756 $this->loadFromDatabase();
757 $exp = time() +
$wgCookieExpiration;
759 $_SESSION['wsUserID'] = $this->mId
;
760 setcookie( $wgDBname.'UserID', $this->mId
, $exp, $wgCookiePath, $wgCookieDomain );
762 $_SESSION['wsUserName'] = $this->mName
;
763 setcookie( $wgDBname.'UserName', $this->mName
, $exp, $wgCookiePath, $wgCookieDomain );
765 $_SESSION['wsToken'] = $this->mToken
;
766 if ( 1 == $this->getOption( 'rememberpassword' ) ) {
767 setcookie( $wgDBname.'Token', $this->mToken
, $exp, $wgCookiePath, $wgCookieDomain );
769 setcookie( $wgDBname.'Token', '', time() - 3600 );
775 * It will clean the session cookie
778 global $wgCookiePath, $wgCookieDomain, $wgDBname, $wgIP;
779 $this->loadDefaults();
780 $this->setLoaded( true );
782 $_SESSION['wsUserID'] = 0;
784 setcookie( $wgDBname.'UserID', '', time() - 3600, $wgCookiePath, $wgCookieDomain );
785 setcookie( $wgDBname.'Token', '', time() - 3600, $wgCookiePath, $wgCookieDomain );
789 * Save object settings into database
791 function saveSettings() {
792 global $wgMemc, $wgDBname;
793 $fname = 'User::saveSettings';
795 $dbw =& wfGetDB( DB_MASTER
);
796 if ( ! $this->getNewtalk() ) {
797 # Delete user_newtalk row
799 $dbw->delete( 'user_newtalk', array( 'user_id' => $this->mId
), $fname );
801 $dbw->delete( 'user_newtalk', array( 'user_ip' => $this->mName
), $fname );
802 $wgMemc->delete( "$wgDBname:newtalk:ip:{$this->mName}" );
805 if ( 0 == $this->mId
) { return; }
807 $dbw->update( 'user',
809 'user_name' => $this->mName
,
810 'user_password' => $this->mPassword
,
811 'user_newpassword' => $this->mNewpassword
,
812 'user_real_name' => $this->mRealName
,
813 'user_email' => $this->mEmail
,
814 'user_options' => $this->encodeOptions(),
815 'user_touched' => $dbw->timestamp($this->mTouched
),
816 'user_token' => $this->mToken
817 ), array( /* WHERE */
818 'user_id' => $this->mId
821 $dbw->set( 'user_rights', 'ur_rights', implode( ',', $this->mRights
),
822 'ur_user='. $this->mId
, $fname );
823 $wgMemc->delete( "$wgDBname:user:id:$this->mId" );
826 $dbw->delete( 'user_groups', array( 'ug_user' => $this->mId
), $fname);
829 foreach ($this->mGroups
as $group) {
830 $dbw->replace( 'user_groups',
831 array(array('ug_user','ug_group')),
833 'ug_user' => $this->mId
,
841 * Checks if a user with the given name exists, returns the ID
843 function idForName() {
844 $fname = 'User::idForName';
847 $s = trim( $this->mName
);
848 if ( 0 == strcmp( '', $s ) ) return 0;
850 $dbr =& wfGetDB( DB_SLAVE
);
851 $id = $dbr->selectField( 'user', 'user_id', array( 'user_name' => $s ), $fname );
852 if ( $id === false ) {
859 * Add user object to the database
861 function addToDatabase() {
862 $fname = 'User::addToDatabase';
863 $dbw =& wfGetDB( DB_MASTER
);
864 $seqVal = $dbw->nextSequenceValue( 'user_user_id_seq' );
865 $dbw->insert( 'user',
867 'user_id' => $seqVal,
868 'user_name' => $this->mName
,
869 'user_password' => $this->mPassword
,
870 'user_newpassword' => $this->mNewpassword
,
871 'user_email' => $this->mEmail
,
872 'user_real_name' => $this->mRealName
,
873 'user_options' => $this->encodeOptions(),
874 'user_token' => $this->mToken
877 $this->mId
= $dbw->insertId();
878 $dbw->insert( 'user_rights',
880 'ur_user' => $this->mId
,
881 'ur_rights' => implode( ',', $this->mRights
)
885 foreach ($this->mGroups
as $group) {
886 $dbw->insert( 'user_groups',
888 'ug_user' => $this->mId
,
895 function spreadBlock() {
897 # If the (non-anonymous) user is blocked, this function will block any IP address
898 # that they successfully log on from.
899 $fname = 'User::spreadBlock';
901 wfDebug( "User:spreadBlock()\n" );
902 if ( $this->mId
== 0 ) {
906 $userblock = Block
::newFromDB( '', $this->mId
);
907 if ( !$userblock->isValid() ) {
911 # Check if this IP address is already blocked
912 $ipblock = Block
::newFromDB( $wgIP );
913 if ( $ipblock->isValid() ) {
914 # Just update the timestamp
915 $ipblock->updateTimestamp();
919 # Make a new block object with the desired properties
920 wfDebug( "Autoblocking {$this->mName}@{$wgIP}\n" );
921 $ipblock->mAddress
= $wgIP;
923 $ipblock->mBy
= $userblock->mBy
;
924 $ipblock->mReason
= wfMsg( 'autoblocker', $this->getName(), $userblock->mReason
);
925 $ipblock->mTimestamp
= wfTimestampNow();
927 # If the user is already blocked with an expiry date, we don't
928 # want to pile on top of that!
929 if($userblock->mExpiry
) {
930 $ipblock->mExpiry
= min ( $userblock->mExpiry
, Block
::getAutoblockExpiry( $ipblock->mTimestamp
));
932 $ipblock->mExpiry
= Block
::getAutoblockExpiry( $ipblock->mTimestamp
);
940 function getPageRenderingHash() {
946 // stubthreshold is only included below for completeness,
947 // it will always be 0 when this function is called by parsercache.
949 $confstr = $this->getOption( 'math' );
950 $confstr .= '!' . $this->getOption( 'highlightbroken' );
951 $confstr .= '!' . $this->getOption( 'stubthreshold' );
952 $confstr .= '!' . $this->getOption( 'editsection' );
953 $confstr .= '!' . $this->getOption( 'editsectiononrightclick' );
954 $confstr .= '!' . $this->getOption( 'showtoc' );
955 $confstr .= '!' . $this->getOption( 'date' );
956 $confstr .= '!' . $this->getOption( 'numberheadings' );
957 $confstr .= '!' . $this->getOption( 'language' );
958 // add in language variant option if there are multiple variants
959 // supported by the language object
960 if(sizeof($wgContLang->getVariants())>1) {
961 $confstr .= '!' . $this->getOption( 'variant' );
964 $this->mHash
= $confstr;
968 function isAllowedToCreateAccount() {
969 global $wgWhitelistAccount;
972 if (!$wgWhitelistAccount) { return 1; }; // default behaviour
973 foreach ($wgWhitelistAccount as $right => $ok) {
974 $userHasRight = (!strcmp($right, 'user') ||
in_array($right, $this->getRights()));
975 $allowed |
= ($ok && $userHasRight);
981 * Set mDataLoaded, return previous value
982 * Use this to prevent DB access in command-line scripts or similar situations
984 function setLoaded( $loaded ) {
985 return wfSetVar( $this->mDataLoaded
, $loaded );
988 function getUserPage() {
989 return Title
::makeTitle( NS_USER
, $this->mName
);
995 function getMaxID() {
996 $dbr =& wfGetDB( DB_SLAVE
);
997 return $dbr->selectField( 'user', 'max(user_id)', false );
1001 * Determine whether the user is a newbie. Newbies are either
1002 * anonymous IPs, or the 1% most recently created accounts.
1003 * Bots and sysops are excluded.
1004 * @return bool True if it is a newbie.
1006 function isNewbie() {
1007 return $this->mId
> User
::getMaxID() * 0.99 && !$this->isSysop() && !$this->isBot() ||
$this->getID() == 0;
1011 * Check to see if the given clear-text password is one of the accepted passwords
1012 * @param string $password User password.
1013 * @return bool True if the given password is correct otherwise False.
1015 function checkPassword( $password ) {
1016 $this->loadFromDatabase();
1019 if( $wgAuth->authenticate( $this->getName(), $password ) ) {
1021 } elseif( $wgAuth->strict() ) {
1022 /* Auth plugin doesn't allow local authentication */
1026 $ep = $this->encryptPassword( $password );
1027 if ( 0 == strcmp( $ep, $this->mPassword
) ) {
1029 } elseif ( 0 == strcmp( $ep, $this->mNewpassword
) ) {
1031 } elseif ( function_exists( 'iconv' ) ) {
1032 # Some wikis were converted from ISO 8859-1 to UTF-8, the passwords can't be converted
1033 # Check for this with iconv
1034 /* $cp1252hash = $this->encryptPassword( iconv( 'UTF-8', 'WINDOWS-1252', $password ) );
1035 if ( 0 == strcmp( $cp1252hash, $this->mPassword ) ) {