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() {
142 $fname = 'User::loadDefaults' . $n;
143 wfProfileIn( $fname );
145 global $wgContLang, $wgIP;
146 global $wgNamespacesToBeSearchedDefault;
149 $this->mNewtalk
= -1;
150 $this->mName
= $wgIP;
151 $this->mRealName
= $this->mEmail
= '';
152 $this->mPassword
= $this->mNewpassword
= '';
153 $this->mRights
= array();
154 $this->mGroups
= array();
156 // Getting user defaults only if we have an available language
157 if( isset( $wgContLang ) ) {
158 $this->loadDefaultFromLanguage();
161 foreach( $wgNamespacesToBeSearchedDefault as $nsnum => $val ) {
162 $this->mOptions
['searchNs'.$nsnum] = $val;
164 unset( $this->mSkin
);
165 $this->mDataLoaded
= false;
166 $this->mBlockedby
= -1; # Unset
167 $this->mTouched
= '0'; # Allow any pages to be cached
168 $this->setToken(); # Random
169 $this->mHash
= false;
170 wfProfileOut( $fname );
174 * Used to load user options from a language.
175 * This is not in loadDefault() cause we sometime create user before having
178 function loadDefaultFromLanguage(){
179 $fname = 'User::loadDefaultFromLanguage';
180 wfProfileIn( $fname );
183 * Site defaults will override the global/language defaults
185 global $wgContLang, $wgDefaultUserOptions;
186 $defOpt = $wgDefaultUserOptions +
$wgContLang->getDefaultUserOptions();
189 * default language setting
191 $variant = $wgContLang->getPreferredVariant();
192 $defOpt['variant'] = $variant;
193 $defOpt['language'] = $variant;
195 $this->mOptions
= $defOpt;
201 * Get blocking information
204 function getBlockedStatus() {
205 global $wgIP, $wgBlockCache, $wgProxyList;
207 if ( -1 != $this->mBlockedby
) { return; }
209 $this->mBlockedby
= 0;
213 $block = new Block();
214 if ( $block->load( $wgIP , $this->mId
) ) {
215 $this->mBlockedby
= $block->mBy
;
216 $this->mBlockreason
= $block->mReason
;
221 if ( !$this->mBlockedby
) {
222 $block = $wgBlockCache->get( $wgIP );
223 if ( $block !== false ) {
224 $this->mBlockedby
= $block->mBy
;
225 $this->mBlockreason
= $block->mReason
;
230 if ( !$this->mBlockedby
) {
231 if ( array_key_exists( $wgIP, $wgProxyList ) ) {
232 $this->mBlockreason
= wfMsg( 'proxyblockreason' );
233 $this->mBlockedby
= "Proxy blocker";
239 * Check if user is blocked
240 * @return bool True if blocked, false otherwise
242 function isBlocked() {
243 $this->getBlockedStatus();
244 if ( 0 === $this->mBlockedby
) { return false; }
249 * Get name of blocker
250 * @return string name of blocker
252 function blockedBy() {
253 $this->getBlockedStatus();
254 return $this->mBlockedby
;
258 * Get blocking reason
259 * @return string Blocking reason
261 function blockedFor() {
262 $this->getBlockedStatus();
263 return $this->mBlockreason
;
267 * Initialise php session
269 function SetupSession() {
270 global $wgSessionsInMemcached, $wgCookiePath, $wgCookieDomain;
271 if( $wgSessionsInMemcached ) {
272 require_once( 'MemcachedSessions.php' );
273 } elseif( 'files' != ini_get( 'session.save_handler' ) ) {
274 # If it's left on 'user' or another setting from another
275 # application, it will end up failing. Try to recover.
276 ini_set ( 'session.save_handler', 'files' );
278 session_set_cookie_params( 0, $wgCookiePath, $wgCookieDomain );
279 session_cache_limiter( 'private, must-revalidate' );
284 * Read datas from session
287 function loadFromSession() {
288 global $wgMemc, $wgDBname;
290 if ( isset( $_SESSION['wsUserID'] ) ) {
291 if ( 0 != $_SESSION['wsUserID'] ) {
292 $sId = $_SESSION['wsUserID'];
296 } else if ( isset( $_COOKIE["{$wgDBname}UserID"] ) ) {
297 $sId = IntVal( $_COOKIE["{$wgDBname}UserID"] );
298 $_SESSION['wsUserID'] = $sId;
302 if ( isset( $_SESSION['wsUserName'] ) ) {
303 $sName = $_SESSION['wsUserName'];
304 } else if ( isset( $_COOKIE["{$wgDBname}UserName"] ) ) {
305 $sName = $_COOKIE["{$wgDBname}UserName"];
306 $_SESSION['wsUserName'] = $sName;
311 $passwordCorrect = FALSE;
312 $user = $wgMemc->get( $key = "$wgDBname:user:id:$sId" );
313 if($makenew = !$user) {
314 wfDebug( "User::loadFromSession() unable to load from memcached\n" );
317 $user->loadFromDatabase();
319 wfDebug( "User::loadFromSession() got from cache!\n" );
322 if ( isset( $_SESSION['wsToken'] ) ) {
323 $passwordCorrect = $_SESSION['wsToken'] == $user->mToken
;
324 } else if ( isset( $_COOKIE["{$wgDBname}Token"] ) ) {
325 $passwordCorrect = $user->mToken
== $_COOKIE["{$wgDBname}Token"];
327 return new User(); # Can't log in from session
330 if ( ( $sName == $user->mName
) && $passwordCorrect ) {
332 if($wgMemc->set( $key, $user ))
333 wfDebug( "User::loadFromSession() successfully saved user\n" );
335 wfDebug( "User::loadFromSession() unable to save to memcached\n" );
337 $user->spreadBlock();
340 return new User(); # Can't log in from session
344 * Load a user from the database
346 function loadFromDatabase() {
347 global $wgCommandLineMode, $wgAnonGroupId, $wgLoggedInGroupId;
348 $fname = "User::loadFromDatabase";
349 if ( $this->mDataLoaded ||
$wgCommandLineMode ) {
354 $this->mId
= IntVal( $this->mId
);
356 /** Anonymous user */
359 $anong = Group
::newFromId($wgAnonGroupId);
361 wfDebugDieBacktrace("Please update your database schema "
362 ."and populate initial group data from "
363 ."maintenance/archives patches");
364 $anong->loadFromDatabase();
365 $this->mRights
= explode(',', $anong->getRights());
366 $this->mDataLoaded
= true;
368 } # the following stuff is for non-anonymous users only
370 $dbr =& wfGetDB( DB_SLAVE
);
371 $s = $dbr->selectRow( 'user', array( 'user_name','user_password','user_newpassword','user_email',
372 'user_real_name','user_options','user_touched', 'user_token' ),
373 array( 'user_id' => $this->mId
), $fname );
375 if ( $s !== false ) {
376 $this->mName
= $s->user_name
;
377 $this->mEmail
= $s->user_email
;
378 $this->mRealName
= $s->user_real_name
;
379 $this->mPassword
= $s->user_password
;
380 $this->mNewpassword
= $s->user_newpassword
;
381 $this->decodeOptions( $s->user_options
);
382 $this->mTouched
= wfTimestamp(TS_MW
,$s->user_touched
);
383 $this->mToken
= $s->user_token
;
386 $res = $dbr->select( 'user_groups', array( 'ug_group' ), array( 'ug_user' => $this->mId
) );
388 while($group = $dbr->fetchRow($res)) {
389 $this->mGroups
[] = $group[0];
392 // add the default group for logged in user
393 $this->mGroups
[] = $wgLoggedInGroupId;
395 $this->mRights
= array();
396 // now we merge groups rights to get this user rights
397 foreach($this->mGroups
as $aGroupId) {
398 $g = Group
::newFromId($aGroupId);
399 $g->loadFromDatabase();
400 $this->mRights
= array_merge($this->mRights
, explode(',', $g->getRights()));
403 // array merge duplicate rights which are part of several groups
404 $this->mRights
= array_unique($this->mRights
);
406 $dbr->freeResult($res);
409 $this->mDataLoaded
= true;
412 function getID() { return $this->mId
; }
413 function setID( $v ) {
415 $this->mDataLoaded
= false;
419 $this->loadFromDatabase();
423 function setName( $str ) {
424 $this->loadFromDatabase();
428 function getNewtalk() {
429 $fname = 'User::getNewtalk';
430 $this->loadFromDatabase();
432 # Load the newtalk status if it is unloaded (mNewtalk=-1)
433 if ( $this->mNewtalk
== -1 ) {
434 $this->mNewtalk
=0; # reset talk page status
435 $dbr =& wfGetDB( DB_SLAVE
);
437 $res = $dbr->select( 'user_newtalk', 1, array( 'user_id' => $this->mId
), $fname );
439 if ( $dbr->numRows($res)>0 ) {
442 $dbr->freeResult( $res );
444 global $wgDBname, $wgMemc;
445 $key = "$wgDBname:newtalk:ip:{$this->mName}";
446 $newtalk = $wgMemc->get( $key );
447 if( ! is_integer( $newtalk ) ){
448 $res = $dbr->select( 'user_newtalk', 1, array( 'user_ip' => $this->mName
), $fname );
450 $this->mNewtalk
= $dbr->numRows( $res ) > 0 ?
1 : 0;
451 $dbr->freeResult( $res );
453 $wgMemc->set( $key, $this->mNewtalk
, time() ); // + 1800 );
455 $this->mNewtalk
= $newtalk ?
1 : 0;
460 return ( 0 != $this->mNewtalk
);
463 function setNewtalk( $val ) {
464 $this->loadFromDatabase();
465 $this->mNewtalk
= $val;
466 $this->invalidateCache();
469 function invalidateCache() {
470 $this->loadFromDatabase();
471 $this->mTouched
= wfTimestampNow();
472 # Don't forget to save the options after this or
473 # it won't take effect!
476 function validateCache( $timestamp ) {
477 $this->loadFromDatabase();
478 return ($timestamp >= $this->mTouched
);
483 * Will only be salted if $wgPasswordSalt is true
484 * @param string Password.
485 * @return string Salted password or clear password.
487 function addSalt( $p ) {
488 global $wgPasswordSalt;
490 return md5( "{$this->mId}-{$p}" );
496 * Encrypt a password.
497 * It can eventuall salt a password @see User::addSalt()
498 * @param string $p clear Password.
499 * @param string Encrypted password.
501 function encryptPassword( $p ) {
502 return $this->addSalt( md5( $p ) );
505 # Set the password and reset the random token
506 function setPassword( $str ) {
507 $this->loadFromDatabase();
509 $this->mPassword
= $this->encryptPassword( $str );
510 $this->mNewpassword
= '';
513 # Set the random token (used for persistent authentication)
514 function setToken( $token = false ) {
517 # Take random data from PRNG
518 # This is reasonably secure if the PRNG has been seeded correctly
519 for ($i = 0; $i<USER_TOKEN_LENGTH
/ 4; $i++
) {
520 $this->mToken
.= sprintf( "%04X", mt_rand( 0, 65535 ) );
523 $this->mToken
= $token;
528 function setCookiePassword( $str ) {
529 $this->loadFromDatabase();
530 $this->mCookiePassword
= md5( $str );
533 function setNewpassword( $str ) {
534 $this->loadFromDatabase();
535 $this->mNewpassword
= $this->encryptPassword( $str );
538 function getEmail() {
539 $this->loadFromDatabase();
540 return $this->mEmail
;
543 function setEmail( $str ) {
544 $this->loadFromDatabase();
545 $this->mEmail
= $str;
548 function getRealName() {
549 $this->loadFromDatabase();
550 return $this->mRealName
;
553 function setRealName( $str ) {
554 $this->loadFromDatabase();
555 $this->mRealName
= $str;
558 function getOption( $oname ) {
559 $this->loadFromDatabase();
560 if ( array_key_exists( $oname, $this->mOptions
) ) {
561 return $this->mOptions
[$oname];
567 function setOption( $oname, $val ) {
568 $this->loadFromDatabase();
569 if ( $oname == 'skin' ) {
570 # Clear cached skin, so the new one displays immediately in Special:Preferences
571 unset( $this->mSkin
);
573 $this->mOptions
[$oname] = $val;
574 $this->invalidateCache();
577 function getRights() {
578 $this->loadFromDatabase();
579 return $this->mRights
;
582 function addRight( $rname ) {
583 $this->loadFromDatabase();
584 array_push( $this->mRights
, $rname );
585 $this->invalidateCache();
588 function getGroups() {
589 $this->loadFromDatabase();
590 return $this->mGroups
;
593 function setGroups($groups) {
594 $this->loadFromDatabase();
595 $this->mGroups
= $groups;
596 $this->invalidateCache();
600 * Check if a user is sysop
601 * Die with backtrace. Use User:isAllowed() instead.
606 $this->loadFromDatabase();
607 if ( 0 == $this->mId ) { return false; }
609 return in_array( 'sysop', $this->mRights );
611 wfDebugDieBacktrace("User::isSysop() is deprecated. Use User::isAllowed() instead");
615 function isDeveloper() {
617 $this->loadFromDatabase();
618 if ( 0 == $this->mId ) { return false; }
620 return in_array( 'developer', $this->mRights );
622 wfDebugDieBacktrace("User::isDeveloper() is deprecated. Use User::isAllowed() instead");
626 function isBureaucrat() {
628 $this->loadFromDatabase();
629 if ( 0 == $this->mId ) { return false; }
631 return in_array( 'bureaucrat', $this->mRights );
633 wfDebugDieBacktrace("User::isBureaucrat() is deprecated. Use User::isAllowed() instead");
637 * Whether the user is a bot
638 * @todo need to be migrated to the new user level management sytem
641 $this->loadFromDatabase();
643 # Why was this here? I need a UID=0 conversion script [TS]
644 # if ( 0 == $this->mId ) { return false; }
646 return in_array( 'bot', $this->mRights
);
650 * Check if user is allowed to access a feature / make an action
651 * @param string $action Action to be checked (see $wgAvailableRights in Defines.php for possible actions).
652 * @return boolean True: action is allowed, False: action should not be allowed
654 function isAllowed($action='') {
655 $this->loadFromDatabase();
656 return in_array( $action , $this->mRights
);
660 * Load a skin if it doesn't exist or return it
661 * @todo FIXME : need to check the old failback system [AV]
663 function &getSkin() {
665 if ( ! isset( $this->mSkin
) ) {
666 $fname = 'User::getSkin';
667 wfProfileIn( $fname );
669 # get all skin names available
670 $skinNames = Skin
::getSkinNames();
673 $userSkin = $this->getOption( 'skin' );
674 if ( $userSkin == '' ) { $userSkin = 'standard'; }
676 if ( !isset( $skinNames[$userSkin] ) ) {
677 # in case the user skin could not be found find a replacement
682 # if phptal is enabled we should have monobook skin that
683 # superseed the good old SkinStandard.
684 if ( isset( $skinNames['monobook'] ) ) {
685 $fallback[0] = 'MonoBook';
688 if(is_numeric($userSkin) && isset( $fallback[$userSkin]) ){
689 $sn = $fallback[$userSkin];
694 # The user skin is available
695 $sn = $skinNames[$userSkin];
698 # Grab the skin class and initialise it. Each skin checks for PHPTal
699 # and will not load if it's not enabled.
700 require_once( $IP.'/skins/'.$sn.'.php' );
702 # Check if we got if not failback to default skin
703 $className = 'Skin'.$sn;
704 if( !class_exists( $className ) ) {
705 # DO NOT die if the class isn't found. This breaks maintenance
706 # scripts and can cause a user account to be unrecoverable
707 # except by SQL manipulation if a previously valid skin name
708 # is no longer valid.
709 $className = 'SkinStandard';
710 require_once( $IP.'/skins/Standard.php' );
712 $this->mSkin
=& new $className;
713 wfProfileOut( $fname );
719 * @param string $title Article title to look at
723 * Check watched status of an article
724 * @return bool True if article is watched
726 function isWatched( $title ) {
727 $wl = WatchedItem
::fromUserTitle( $this, $title );
728 return $wl->isWatched();
734 function addWatch( $title ) {
735 $wl = WatchedItem
::fromUserTitle( $this, $title );
737 $this->invalidateCache();
741 * Stop watching an article
743 function removeWatch( $title ) {
744 $wl = WatchedItem
::fromUserTitle( $this, $title );
746 $this->invalidateCache();
752 * @return string Encoding options
754 function encodeOptions() {
756 foreach ( $this->mOptions
as $oname => $oval ) {
757 array_push( $a, $oname.'='.$oval );
759 $s = implode( "\n", $a );
766 function decodeOptions( $str ) {
767 $a = explode( "\n", $str );
768 foreach ( $a as $s ) {
769 if ( preg_match( "/^(.[^=]*)=(.*)$/", $s, $m ) ) {
770 $this->mOptions
[$m[1]] = $m[2];
775 function setCookies() {
776 global $wgCookieExpiration, $wgCookiePath, $wgCookieDomain, $wgDBname;
777 if ( 0 == $this->mId
) return;
778 $this->loadFromDatabase();
779 $exp = time() +
$wgCookieExpiration;
781 $_SESSION['wsUserID'] = $this->mId
;
782 setcookie( $wgDBname.'UserID', $this->mId
, $exp, $wgCookiePath, $wgCookieDomain );
784 $_SESSION['wsUserName'] = $this->mName
;
785 setcookie( $wgDBname.'UserName', $this->mName
, $exp, $wgCookiePath, $wgCookieDomain );
787 $_SESSION['wsToken'] = $this->mToken
;
788 if ( 1 == $this->getOption( 'rememberpassword' ) ) {
789 setcookie( $wgDBname.'Token', $this->mToken
, $exp, $wgCookiePath, $wgCookieDomain );
791 setcookie( $wgDBname.'Token', '', time() - 3600 );
797 * It will clean the session cookie
800 global $wgCookiePath, $wgCookieDomain, $wgDBname, $wgIP;
801 $this->loadDefaults();
802 $this->setLoaded( true );
804 $_SESSION['wsUserID'] = 0;
806 setcookie( $wgDBname.'UserID', '', time() - 3600, $wgCookiePath, $wgCookieDomain );
807 setcookie( $wgDBname.'Token', '', time() - 3600, $wgCookiePath, $wgCookieDomain );
811 * Save object settings into database
813 function saveSettings() {
814 global $wgMemc, $wgDBname;
815 $fname = 'User::saveSettings';
817 $this->saveNewtalk();
819 if ( 0 == $this->mId
) { return; }
821 $dbw =& wfGetDB( DB_MASTER
);
823 $dbw->update( 'user',
825 'user_name' => $this->mName
,
826 'user_password' => $this->mPassword
,
827 'user_newpassword' => $this->mNewpassword
,
828 'user_real_name' => $this->mRealName
,
829 'user_email' => $this->mEmail
,
830 'user_options' => $this->encodeOptions(),
831 'user_touched' => $dbw->timestamp($this->mTouched
),
832 'user_token' => $this->mToken
833 ), array( /* WHERE */
834 'user_id' => $this->mId
837 $dbw->set( 'user_rights', 'ur_rights', implode( ',', $this->mRights
),
838 'ur_user='. $this->mId
, $fname );
839 $wgMemc->delete( "$wgDBname:user:id:$this->mId" );
842 $dbw->delete( 'user_groups', array( 'ug_user' => $this->mId
), $fname);
845 foreach ($this->mGroups
as $group) {
846 $dbw->replace( 'user_groups',
847 array(array('ug_user','ug_group')),
849 'ug_user' => $this->mId
,
857 * Save value of new talk flag.
859 function saveNewtalk() {
860 global $wgDBname, $wgMemc;
862 $fname = 'User::saveNewtalk';
864 if ($this->getID() != 0) {
866 $value = $this->getID();
867 $key = "$wgDBname:user:id:$this->mId";
870 $value = $this->mName
;
871 $key = "$wgDBname:newtalk:ip:$this->mName";
874 $dbr =& wfGetDB( DB_SLAVE
);
875 $dbw =& wfGetDB( DB_MASTER
);
877 $res = $dbr->selectField('user_newtalk', $field,
878 array($field => $value), $fname);
880 if ($res !== false && $this->mNewtalk
== 0) {
881 $dbw->delete('user_newtalk', array($field => $value), $fname);
882 $wgMemc->delete($key);
883 } else if ($res === false && $this->mNewtalk
== 1) {
884 $dbw->insert('user_newtalk', array($field => $value), $fname);
885 $wgMemc->delete($key);
890 * Checks if a user with the given name exists, returns the ID
892 function idForName() {
893 $fname = 'User::idForName';
896 $s = trim( $this->mName
);
897 if ( 0 == strcmp( '', $s ) ) return 0;
899 $dbr =& wfGetDB( DB_SLAVE
);
900 $id = $dbr->selectField( 'user', 'user_id', array( 'user_name' => $s ), $fname );
901 if ( $id === false ) {
908 * Add user object to the database
910 function addToDatabase() {
911 $fname = 'User::addToDatabase';
912 $dbw =& wfGetDB( DB_MASTER
);
913 $seqVal = $dbw->nextSequenceValue( 'user_user_id_seq' );
914 $dbw->insert( 'user',
916 'user_id' => $seqVal,
917 'user_name' => $this->mName
,
918 'user_password' => $this->mPassword
,
919 'user_newpassword' => $this->mNewpassword
,
920 'user_email' => $this->mEmail
,
921 'user_real_name' => $this->mRealName
,
922 'user_options' => $this->encodeOptions(),
923 'user_token' => $this->mToken
926 $this->mId
= $dbw->insertId();
927 $dbw->insert( 'user_rights',
929 'ur_user' => $this->mId
,
930 'ur_rights' => implode( ',', $this->mRights
)
934 foreach ($this->mGroups
as $group) {
935 $dbw->insert( 'user_groups',
937 'ug_user' => $this->mId
,
944 function spreadBlock() {
946 # If the (non-anonymous) user is blocked, this function will block any IP address
947 # that they successfully log on from.
948 $fname = 'User::spreadBlock';
950 wfDebug( "User:spreadBlock()\n" );
951 if ( $this->mId
== 0 ) {
955 $userblock = Block
::newFromDB( '', $this->mId
);
956 if ( !$userblock->isValid() ) {
960 # Check if this IP address is already blocked
961 $ipblock = Block
::newFromDB( $wgIP );
962 if ( $ipblock->isValid() ) {
963 # Just update the timestamp
964 $ipblock->updateTimestamp();
968 # Make a new block object with the desired properties
969 wfDebug( "Autoblocking {$this->mName}@{$wgIP}\n" );
970 $ipblock->mAddress
= $wgIP;
972 $ipblock->mBy
= $userblock->mBy
;
973 $ipblock->mReason
= wfMsg( 'autoblocker', $this->getName(), $userblock->mReason
);
974 $ipblock->mTimestamp
= wfTimestampNow();
976 # If the user is already blocked with an expiry date, we don't
977 # want to pile on top of that!
978 if($userblock->mExpiry
) {
979 $ipblock->mExpiry
= min ( $userblock->mExpiry
, Block
::getAutoblockExpiry( $ipblock->mTimestamp
));
981 $ipblock->mExpiry
= Block
::getAutoblockExpiry( $ipblock->mTimestamp
);
989 function getPageRenderingHash() {
995 // stubthreshold is only included below for completeness,
996 // it will always be 0 when this function is called by parsercache.
998 $confstr = $this->getOption( 'math' );
999 $confstr .= '!' . $this->getOption( 'highlightbroken' );
1000 $confstr .= '!' . $this->getOption( 'stubthreshold' );
1001 $confstr .= '!' . $this->getOption( 'editsection' );
1002 $confstr .= '!' . $this->getOption( 'editsectiononrightclick' );
1003 $confstr .= '!' . $this->getOption( 'showtoc' );
1004 $confstr .= '!' . $this->getOption( 'date' );
1005 $confstr .= '!' . $this->getOption( 'numberheadings' );
1006 $confstr .= '!' . $this->getOption( 'language' );
1007 // add in language variant option if there are multiple variants
1008 // supported by the language object
1009 if(sizeof($wgContLang->getVariants())>1) {
1010 $confstr .= '!' . $this->getOption( 'variant' );
1013 $this->mHash
= $confstr;
1017 function isAllowedToCreateAccount() {
1018 global $wgWhitelistAccount;
1021 if (!$wgWhitelistAccount) { return 1; }; // default behaviour
1022 foreach ($wgWhitelistAccount as $right => $ok) {
1023 $userHasRight = (!strcmp($right, 'user') ||
in_array($right, $this->getRights()));
1024 $allowed |
= ($ok && $userHasRight);
1030 * Set mDataLoaded, return previous value
1031 * Use this to prevent DB access in command-line scripts or similar situations
1033 function setLoaded( $loaded ) {
1034 return wfSetVar( $this->mDataLoaded
, $loaded );
1037 function getUserPage() {
1038 return Title
::makeTitle( NS_USER
, $this->mName
);
1044 function getMaxID() {
1045 $dbr =& wfGetDB( DB_SLAVE
);
1046 return $dbr->selectField( 'user', 'max(user_id)', false );
1050 * Determine whether the user is a newbie. Newbies are either
1051 * anonymous IPs, or the 1% most recently created accounts.
1052 * Bots and sysops are excluded.
1053 * @return bool True if it is a newbie.
1055 function isNewbie() {
1056 return $this->mId
> User
::getMaxID() * 0.99 && !$this->isSysop() && !$this->isBot() ||
$this->getID() == 0;
1060 * Check to see if the given clear-text password is one of the accepted passwords
1061 * @param string $password User password.
1062 * @return bool True if the given password is correct otherwise False.
1064 function checkPassword( $password ) {
1065 $this->loadFromDatabase();
1068 if( $wgAuth->authenticate( $this->getName(), $password ) ) {
1070 } elseif( $wgAuth->strict() ) {
1071 /* Auth plugin doesn't allow local authentication */
1075 $ep = $this->encryptPassword( $password );
1076 if ( 0 == strcmp( $ep, $this->mPassword
) ) {
1078 } elseif ( 0 == strcmp( $ep, $this->mNewpassword
) ) {
1080 } elseif ( function_exists( 'iconv' ) ) {
1081 # Some wikis were converted from ISO 8859-1 to UTF-8, the passwords can't be converted
1082 # Check for this with iconv
1083 /* $cp1252hash = $this->encryptPassword( iconv( 'UTF-8', 'WINDOWS-1252', $password ) );
1084 if ( 0 == strcmp( $cp1252hash, $this->mPassword ) ) {