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 global $wgDefaultUserOptions;
174 # Site defaults will override the global/language defaults
175 $defOpt = $wgDefaultUserOptions +
$wgContLang->getDefaultUserOptions();
176 foreach ( $defOpt as $oname => $val ) {
177 $this->mOptions
[$oname] = $val;
180 default language setting
182 $this->setOption('variant', $wgContLang->getPreferredVariant());
183 $this->setOption('language', $wgContLang->getPreferredVariant());
187 * Get blocking information
190 function getBlockedStatus() {
191 global $wgIP, $wgBlockCache, $wgProxyList;
193 if ( -1 != $this->mBlockedby
) { return; }
195 $this->mBlockedby
= 0;
199 $block = new Block();
200 if ( $block->load( $wgIP , $this->mId
) ) {
201 $this->mBlockedby
= $block->mBy
;
202 $this->mBlockreason
= $block->mReason
;
207 if ( !$this->mBlockedby
) {
208 $block = $wgBlockCache->get( $wgIP );
209 if ( $block !== false ) {
210 $this->mBlockedby
= $block->mBy
;
211 $this->mBlockreason
= $block->mReason
;
216 if ( !$this->mBlockedby
) {
217 if ( array_key_exists( $wgIP, $wgProxyList ) ) {
218 $this->mBlockreason
= wfMsg( 'proxyblockreason' );
219 $this->mBlockedby
= "Proxy blocker";
225 * Check if user is blocked
226 * @return bool True if blocked, false otherwise
228 function isBlocked() {
229 $this->getBlockedStatus();
230 if ( 0 === $this->mBlockedby
) { return false; }
235 * Get name of blocker
236 * @return string name of blocker
238 function blockedBy() {
239 $this->getBlockedStatus();
240 return $this->mBlockedby
;
244 * Get blocking reason
245 * @return string Blocking reason
247 function blockedFor() {
248 $this->getBlockedStatus();
249 return $this->mBlockreason
;
253 * Initialise php session
255 function SetupSession() {
256 global $wgSessionsInMemcached, $wgCookiePath, $wgCookieDomain;
257 if( $wgSessionsInMemcached ) {
258 require_once( 'MemcachedSessions.php' );
259 } elseif( 'files' != ini_get( 'session.save_handler' ) ) {
260 # If it's left on 'user' or another setting from another
261 # application, it will end up failing. Try to recover.
262 ini_set ( 'session.save_handler', 'files' );
264 session_set_cookie_params( 0, $wgCookiePath, $wgCookieDomain );
265 session_cache_limiter( 'private, must-revalidate' );
270 * Read datas from session
273 function loadFromSession() {
274 global $wgMemc, $wgDBname;
276 if ( isset( $_SESSION['wsUserID'] ) ) {
277 if ( 0 != $_SESSION['wsUserID'] ) {
278 $sId = $_SESSION['wsUserID'];
282 } else if ( isset( $_COOKIE["{$wgDBname}UserID"] ) ) {
283 $sId = IntVal( $_COOKIE["{$wgDBname}UserID"] );
284 $_SESSION['wsUserID'] = $sId;
288 if ( isset( $_SESSION['wsUserName'] ) ) {
289 $sName = $_SESSION['wsUserName'];
290 } else if ( isset( $_COOKIE["{$wgDBname}UserName"] ) ) {
291 $sName = $_COOKIE["{$wgDBname}UserName"];
292 $_SESSION['wsUserName'] = $sName;
297 $passwordCorrect = FALSE;
298 $user = $wgMemc->get( $key = "$wgDBname:user:id:$sId" );
299 if($makenew = !$user) {
300 wfDebug( "User::loadFromSession() unable to load from memcached\n" );
303 $user->loadFromDatabase();
305 wfDebug( "User::loadFromSession() got from cache!\n" );
308 if ( isset( $_SESSION['wsToken'] ) ) {
309 $passwordCorrect = $_SESSION['wsToken'] == $user->mToken
;
310 } else if ( isset( $_COOKIE["{$wgDBname}Token"] ) ) {
311 $passwordCorrect = $user->mToken
== $_COOKIE["{$wgDBname}Token"];
313 return new User(); # Can't log in from session
316 if ( ( $sName == $user->mName
) && $passwordCorrect ) {
318 if($wgMemc->set( $key, $user ))
319 wfDebug( "User::loadFromSession() successfully saved user\n" );
321 wfDebug( "User::loadFromSession() unable to save to memcached\n" );
323 $user->spreadBlock();
326 return new User(); # Can't log in from session
330 * Load a user from the database
332 function loadFromDatabase() {
333 global $wgCommandLineMode, $wgAnonGroupId, $wgLoggedInGroupId;
334 $fname = "User::loadFromDatabase";
335 if ( $this->mDataLoaded ||
$wgCommandLineMode ) {
340 $this->mId
= IntVal( $this->mId
);
342 /** Anonymous user */
345 $anong = Group
::newFromId($wgAnonGroupId);
347 wfDebugDieBacktrace("Please update your database schema "
348 ."and populate initial group data from "
349 ."maintenance/archives patches");
350 $anong->loadFromDatabase();
351 $this->mRights
= explode(',', $anong->getRights());
352 $this->mDataLoaded
= true;
354 } # the following stuff is for non-anonymous users only
356 $dbr =& wfGetDB( DB_SLAVE
);
357 $s = $dbr->selectRow( 'user', array( 'user_name','user_password','user_newpassword','user_email',
358 'user_real_name','user_options','user_touched', 'user_token' ),
359 array( 'user_id' => $this->mId
), $fname );
361 if ( $s !== false ) {
362 $this->mName
= $s->user_name
;
363 $this->mEmail
= $s->user_email
;
364 $this->mRealName
= $s->user_real_name
;
365 $this->mPassword
= $s->user_password
;
366 $this->mNewpassword
= $s->user_newpassword
;
367 $this->decodeOptions( $s->user_options
);
368 $this->mTouched
= wfTimestamp(TS_MW
,$s->user_touched
);
369 $this->mToken
= $s->user_token
;
372 $res = $dbr->select( 'user_groups', array( 'ug_group' ), array( 'ug_user' => $this->mId
) );
374 while($group = $dbr->fetchRow($res)) {
375 $this->mGroups
[] = $group[0];
378 // add the default group for logged in user
379 $this->mGroups
[] = $wgLoggedInGroupId;
381 $this->mRights
= array();
382 // now we merge groups rights to get this user rights
383 foreach($this->mGroups
as $aGroupId) {
384 $g = Group
::newFromId($aGroupId);
385 $g->loadFromDatabase();
386 $this->mRights
= array_merge($this->mRights
, explode(',', $g->getRights()));
389 // array merge duplicate rights which are part of several groups
390 $this->mRights
= array_unique($this->mRights
);
392 $dbr->freeResult($res);
395 $this->mDataLoaded
= true;
398 function getID() { return $this->mId
; }
399 function setID( $v ) {
401 $this->mDataLoaded
= false;
405 $this->loadFromDatabase();
409 function setName( $str ) {
410 $this->loadFromDatabase();
414 function getNewtalk() {
415 $fname = 'User::getNewtalk';
416 $this->loadFromDatabase();
418 # Load the newtalk status if it is unloaded (mNewtalk=-1)
419 if ( $this->mNewtalk
== -1 ) {
420 $this->mNewtalk
=0; # reset talk page status
421 $dbr =& wfGetDB( DB_SLAVE
);
423 $res = $dbr->select( 'user_newtalk', 1, array( 'user_id' => $this->mId
), $fname );
425 if ( $dbr->numRows($res)>0 ) {
428 $dbr->freeResult( $res );
430 global $wgDBname, $wgMemc;
431 $key = "$wgDBname:newtalk:ip:{$this->mName}";
432 $newtalk = $wgMemc->get( $key );
433 if( ! is_integer( $newtalk ) ){
434 $res = $dbr->select( 'user_newtalk', 1, array( 'user_ip' => $this->mName
), $fname );
436 $this->mNewtalk
= $dbr->numRows( $res ) > 0 ?
1 : 0;
437 $dbr->freeResult( $res );
439 $wgMemc->set( $key, $this->mNewtalk
, time() ); // + 1800 );
441 $this->mNewtalk
= $newtalk ?
1 : 0;
446 return ( 0 != $this->mNewtalk
);
449 function setNewtalk( $val ) {
450 $this->loadFromDatabase();
451 $this->mNewtalk
= $val;
452 $this->invalidateCache();
455 function invalidateCache() {
456 $this->loadFromDatabase();
457 $this->mTouched
= wfTimestampNow();
458 # Don't forget to save the options after this or
459 # it won't take effect!
462 function validateCache( $timestamp ) {
463 $this->loadFromDatabase();
464 return ($timestamp >= $this->mTouched
);
469 * Will only be salted if $wgPasswordSalt is true
470 * @param string Password.
471 * @return string Salted password or clear password.
473 function addSalt( $p ) {
474 global $wgPasswordSalt;
476 return md5( "{$this->mId}-{$p}" );
482 * Encrypt a password.
483 * It can eventuall salt a password @see User::addSalt()
484 * @param string $p clear Password.
485 * @param string Encrypted password.
487 function encryptPassword( $p ) {
488 return $this->addSalt( md5( $p ) );
491 # Set the password and reset the random token
492 function setPassword( $str ) {
493 $this->loadFromDatabase();
495 $this->mPassword
= $this->encryptPassword( $str );
496 $this->mNewpassword
= '';
499 # Set the random token (used for persistent authentication)
500 function setToken( $token = false ) {
503 # Take random data from PRNG
504 # This is reasonably secure if the PRNG has been seeded correctly
505 for ($i = 0; $i<USER_TOKEN_LENGTH
/ 4; $i++
) {
506 $this->mToken
.= sprintf( "%04X", mt_rand( 0, 65535 ) );
509 $this->mToken
= $token;
514 function setCookiePassword( $str ) {
515 $this->loadFromDatabase();
516 $this->mCookiePassword
= md5( $str );
519 function setNewpassword( $str ) {
520 $this->loadFromDatabase();
521 $this->mNewpassword
= $this->encryptPassword( $str );
524 function getEmail() {
525 $this->loadFromDatabase();
526 return $this->mEmail
;
529 function setEmail( $str ) {
530 $this->loadFromDatabase();
531 $this->mEmail
= $str;
534 function getRealName() {
535 $this->loadFromDatabase();
536 return $this->mRealName
;
539 function setRealName( $str ) {
540 $this->loadFromDatabase();
541 $this->mRealName
= $str;
544 function getOption( $oname ) {
545 $this->loadFromDatabase();
546 if ( array_key_exists( $oname, $this->mOptions
) ) {
547 return $this->mOptions
[$oname];
553 function setOption( $oname, $val ) {
554 $this->loadFromDatabase();
555 if ( $oname == 'skin' ) {
556 # Clear cached skin, so the new one displays immediately in Special:Preferences
557 unset( $this->mSkin
);
559 $this->mOptions
[$oname] = $val;
560 $this->invalidateCache();
563 function getRights() {
564 $this->loadFromDatabase();
565 return $this->mRights
;
568 function addRight( $rname ) {
569 $this->loadFromDatabase();
570 array_push( $this->mRights
, $rname );
571 $this->invalidateCache();
574 function getGroups() {
575 $this->loadFromDatabase();
576 return $this->mGroups
;
579 function setGroups($groups) {
580 $this->loadFromDatabase();
581 $this->mGroups
= $groups;
582 $this->invalidateCache();
586 * Check if a user is sysop
587 * Die with backtrace. Use User:isAllowed() instead.
592 $this->loadFromDatabase();
593 if ( 0 == $this->mId ) { return false; }
595 return in_array( 'sysop', $this->mRights );
597 wfDebugDieBacktrace("User::isSysop() is deprecated. Use User::isAllowed() instead");
601 function isDeveloper() {
603 $this->loadFromDatabase();
604 if ( 0 == $this->mId ) { return false; }
606 return in_array( 'developer', $this->mRights );
608 wfDebugDieBacktrace("User::isDeveloper() is deprecated. Use User::isAllowed() instead");
612 function isBureaucrat() {
614 $this->loadFromDatabase();
615 if ( 0 == $this->mId ) { return false; }
617 return in_array( 'bureaucrat', $this->mRights );
619 wfDebugDieBacktrace("User::isBureaucrat() is deprecated. Use User::isAllowed() instead");
623 * Whether the user is a bot
624 * @todo need to be migrated to the new user level management sytem
627 $this->loadFromDatabase();
629 # Why was this here? I need a UID=0 conversion script [TS]
630 # if ( 0 == $this->mId ) { return false; }
632 return in_array( 'bot', $this->mRights
);
636 * Check if user is allowed to access a feature / make an action
637 * @param string $action Action to be checked (see $wgAvailableRights in Defines.php for possible actions).
638 * @return boolean True: action is allowed, False: action should not be allowed
640 function isAllowed($action='') {
641 $this->loadFromDatabase();
642 return in_array( $action , $this->mRights
);
646 * Load a skin if it doesn't exist or return it
647 * @todo FIXME : need to check the old failback system [AV]
649 function &getSkin() {
651 if ( ! isset( $this->mSkin
) ) {
652 # get all skin names available
653 $skinNames = Skin
::getSkinNames();
655 $userSkin = $this->getOption( 'skin' );
656 if ( $userSkin == '' ) { $userSkin = 'standard'; }
658 if ( !isset( $skinNames[$userSkin] ) ) {
659 # in case the user skin could not be found find a replacement
664 # if phptal is enabled we should have monobook skin that
665 # superseed the good old SkinStandard.
666 if ( isset( $skinNames['monobook'] ) ) {
667 $fallback[0] = 'MonoBook';
670 if(is_numeric($userSkin) && isset( $fallback[$userSkin]) ){
671 $sn = $fallback[$userSkin];
676 # The user skin is available
677 $sn = $skinNames[$userSkin];
680 # Grab the skin class and initialise it. Each skin checks for PHPTal
681 # and will not load if it's not enabled.
682 require_once( $IP.'/skins/'.$sn.'.php' );
684 # Check if we got if not failback to default skin
685 $className = 'Skin'.$sn;
686 if( !class_exists( $className ) ) {
687 # DO NOT die if the class isn't found. This breaks maintenance
688 # scripts and can cause a user account to be unrecoverable
689 # except by SQL manipulation if a previously valid skin name
690 # is no longer valid.
691 $className = 'SkinStandard';
692 require_once( $IP.'/skins/Standard.php' );
694 $this->mSkin
= new $className;
700 * @param string $title Article title to look at
704 * Check watched status of an article
705 * @return bool True if article is watched
707 function isWatched( $title ) {
708 $wl = WatchedItem
::fromUserTitle( $this, $title );
709 return $wl->isWatched();
715 function addWatch( $title ) {
716 $wl = WatchedItem
::fromUserTitle( $this, $title );
718 $this->invalidateCache();
722 * Stop watching an article
724 function removeWatch( $title ) {
725 $wl = WatchedItem
::fromUserTitle( $this, $title );
727 $this->invalidateCache();
733 * @return string Encoding options
735 function encodeOptions() {
737 foreach ( $this->mOptions
as $oname => $oval ) {
738 array_push( $a, $oname.'='.$oval );
740 $s = implode( "\n", $a );
747 function decodeOptions( $str ) {
748 $a = explode( "\n", $str );
749 foreach ( $a as $s ) {
750 if ( preg_match( "/^(.[^=]*)=(.*)$/", $s, $m ) ) {
751 $this->mOptions
[$m[1]] = $m[2];
756 function setCookies() {
757 global $wgCookieExpiration, $wgCookiePath, $wgCookieDomain, $wgDBname;
758 if ( 0 == $this->mId
) return;
759 $this->loadFromDatabase();
760 $exp = time() +
$wgCookieExpiration;
762 $_SESSION['wsUserID'] = $this->mId
;
763 setcookie( $wgDBname.'UserID', $this->mId
, $exp, $wgCookiePath, $wgCookieDomain );
765 $_SESSION['wsUserName'] = $this->mName
;
766 setcookie( $wgDBname.'UserName', $this->mName
, $exp, $wgCookiePath, $wgCookieDomain );
768 $_SESSION['wsToken'] = $this->mToken
;
769 if ( 1 == $this->getOption( 'rememberpassword' ) ) {
770 setcookie( $wgDBname.'Token', $this->mToken
, $exp, $wgCookiePath, $wgCookieDomain );
772 setcookie( $wgDBname.'Token', '', time() - 3600 );
778 * It will clean the session cookie
781 global $wgCookiePath, $wgCookieDomain, $wgDBname, $wgIP;
782 $this->loadDefaults();
783 $this->setLoaded( true );
785 $_SESSION['wsUserID'] = 0;
787 setcookie( $wgDBname.'UserID', '', time() - 3600, $wgCookiePath, $wgCookieDomain );
788 setcookie( $wgDBname.'Token', '', time() - 3600, $wgCookiePath, $wgCookieDomain );
792 * Save object settings into database
794 function saveSettings() {
795 global $wgMemc, $wgDBname;
796 $fname = 'User::saveSettings';
798 $dbw =& wfGetDB( DB_MASTER
);
799 if ( ! $this->getNewtalk() ) {
800 # Delete user_newtalk row
802 $dbw->delete( 'user_newtalk', array( 'user_id' => $this->mId
), $fname );
804 $dbw->delete( 'user_newtalk', array( 'user_ip' => $this->mName
), $fname );
805 $wgMemc->delete( "$wgDBname:newtalk:ip:{$this->mName}" );
808 if ( 0 == $this->mId
) { return; }
810 $dbw->update( 'user',
812 'user_name' => $this->mName
,
813 'user_password' => $this->mPassword
,
814 'user_newpassword' => $this->mNewpassword
,
815 'user_real_name' => $this->mRealName
,
816 'user_email' => $this->mEmail
,
817 'user_options' => $this->encodeOptions(),
818 'user_touched' => $dbw->timestamp($this->mTouched
),
819 'user_token' => $this->mToken
820 ), array( /* WHERE */
821 'user_id' => $this->mId
824 $dbw->set( 'user_rights', 'ur_rights', implode( ',', $this->mRights
),
825 'ur_user='. $this->mId
, $fname );
826 $wgMemc->delete( "$wgDBname:user:id:$this->mId" );
829 $dbw->delete( 'user_groups', array( 'ug_user' => $this->mId
), $fname);
832 foreach ($this->mGroups
as $group) {
833 $dbw->replace( 'user_groups',
834 array(array('ug_user','ug_group')),
836 'ug_user' => $this->mId
,
844 * Checks if a user with the given name exists, returns the ID
846 function idForName() {
847 $fname = 'User::idForName';
850 $s = trim( $this->mName
);
851 if ( 0 == strcmp( '', $s ) ) return 0;
853 $dbr =& wfGetDB( DB_SLAVE
);
854 $id = $dbr->selectField( 'user', 'user_id', array( 'user_name' => $s ), $fname );
855 if ( $id === false ) {
862 * Add user object to the database
864 function addToDatabase() {
865 $fname = 'User::addToDatabase';
866 $dbw =& wfGetDB( DB_MASTER
);
867 $seqVal = $dbw->nextSequenceValue( 'user_user_id_seq' );
868 $dbw->insert( 'user',
870 'user_id' => $seqVal,
871 'user_name' => $this->mName
,
872 'user_password' => $this->mPassword
,
873 'user_newpassword' => $this->mNewpassword
,
874 'user_email' => $this->mEmail
,
875 'user_real_name' => $this->mRealName
,
876 'user_options' => $this->encodeOptions(),
877 'user_token' => $this->mToken
880 $this->mId
= $dbw->insertId();
881 $dbw->insert( 'user_rights',
883 'ur_user' => $this->mId
,
884 'ur_rights' => implode( ',', $this->mRights
)
888 foreach ($this->mGroups
as $group) {
889 $dbw->insert( 'user_groups',
891 'ug_user' => $this->mId
,
898 function spreadBlock() {
900 # If the (non-anonymous) user is blocked, this function will block any IP address
901 # that they successfully log on from.
902 $fname = 'User::spreadBlock';
904 wfDebug( "User:spreadBlock()\n" );
905 if ( $this->mId
== 0 ) {
909 $userblock = Block
::newFromDB( '', $this->mId
);
910 if ( !$userblock->isValid() ) {
914 # Check if this IP address is already blocked
915 $ipblock = Block
::newFromDB( $wgIP );
916 if ( $ipblock->isValid() ) {
917 # Just update the timestamp
918 $ipblock->updateTimestamp();
922 # Make a new block object with the desired properties
923 wfDebug( "Autoblocking {$this->mName}@{$wgIP}\n" );
924 $ipblock->mAddress
= $wgIP;
926 $ipblock->mBy
= $userblock->mBy
;
927 $ipblock->mReason
= wfMsg( 'autoblocker', $this->getName(), $userblock->mReason
);
928 $ipblock->mTimestamp
= wfTimestampNow();
930 # If the user is already blocked with an expiry date, we don't
931 # want to pile on top of that!
932 if($userblock->mExpiry
) {
933 $ipblock->mExpiry
= min ( $userblock->mExpiry
, Block
::getAutoblockExpiry( $ipblock->mTimestamp
));
935 $ipblock->mExpiry
= Block
::getAutoblockExpiry( $ipblock->mTimestamp
);
943 function getPageRenderingHash() {
949 // stubthreshold is only included below for completeness,
950 // it will always be 0 when this function is called by parsercache.
952 $confstr = $this->getOption( 'math' );
953 $confstr .= '!' . $this->getOption( 'highlightbroken' );
954 $confstr .= '!' . $this->getOption( 'stubthreshold' );
955 $confstr .= '!' . $this->getOption( 'editsection' );
956 $confstr .= '!' . $this->getOption( 'editsectiononrightclick' );
957 $confstr .= '!' . $this->getOption( 'showtoc' );
958 $confstr .= '!' . $this->getOption( 'date' );
959 $confstr .= '!' . $this->getOption( 'numberheadings' );
960 $confstr .= '!' . $this->getOption( 'language' );
961 // add in language variant option if there are multiple variants
962 // supported by the language object
963 if(sizeof($wgContLang->getVariants())>1) {
964 $confstr .= '!' . $this->getOption( 'variant' );
967 $this->mHash
= $confstr;
971 function isAllowedToCreateAccount() {
972 global $wgWhitelistAccount;
975 if (!$wgWhitelistAccount) { return 1; }; // default behaviour
976 foreach ($wgWhitelistAccount as $right => $ok) {
977 $userHasRight = (!strcmp($right, 'user') ||
in_array($right, $this->getRights()));
978 $allowed |
= ($ok && $userHasRight);
984 * Set mDataLoaded, return previous value
985 * Use this to prevent DB access in command-line scripts or similar situations
987 function setLoaded( $loaded ) {
988 return wfSetVar( $this->mDataLoaded
, $loaded );
991 function getUserPage() {
992 return Title
::makeTitle( NS_USER
, $this->mName
);
998 function getMaxID() {
999 $dbr =& wfGetDB( DB_SLAVE
);
1000 return $dbr->selectField( 'user', 'max(user_id)', false );
1004 * Determine whether the user is a newbie. Newbies are either
1005 * anonymous IPs, or the 1% most recently created accounts.
1006 * Bots and sysops are excluded.
1007 * @return bool True if it is a newbie.
1009 function isNewbie() {
1010 return $this->mId
> User
::getMaxID() * 0.99 && !$this->isSysop() && !$this->isBot() ||
$this->getID() == 0;
1014 * Check to see if the given clear-text password is one of the accepted passwords
1015 * @param string $password User password.
1016 * @return bool True if the given password is correct otherwise False.
1018 function checkPassword( $password ) {
1019 $this->loadFromDatabase();
1022 if( $wgAuth->authenticate( $this->getName(), $password ) ) {
1024 } elseif( $wgAuth->strict() ) {
1025 /* Auth plugin doesn't allow local authentication */
1029 $ep = $this->encryptPassword( $password );
1030 if ( 0 == strcmp( $ep, $this->mPassword
) ) {
1032 } elseif ( 0 == strcmp( $ep, $this->mNewpassword
) ) {
1034 } elseif ( function_exists( 'iconv' ) ) {
1035 # Some wikis were converted from ISO 8859-1 to UTF-8, the passwords can't be converted
1036 # Check for this with iconv
1037 /* $cp1252hash = $this->encryptPassword( iconv( 'UTF-8', 'WINDOWS-1252', $password ) );
1038 if ( 0 == strcmp( $cp1252hash, $this->mPassword ) ) {