11 require_once( 'WatchedItem.php' );
13 # Number of characters in user_token field
14 define( 'USER_TOKEN_LENGTH', 32 );
16 # Serialized record version
17 define( 'MW_USER_VERSION', 2 );
27 var $mId, $mName, $mPassword, $mEmail, $mNewtalk;
28 var $mEmailAuthenticated;
29 var $mRights, $mOptions;
30 var $mDataLoaded, $mNewpassword;
32 var $mBlockedby, $mBlockreason;
38 var $mVersion; // serialized version
40 /** Construct using User:loadDefaults() */
42 $this->loadDefaults();
43 $this->mVersion
= MW_USER_VERSION
;
47 * Static factory method
48 * @param string $name Username, validated by Title:newFromText()
52 function newFromName( $name ) {
53 # Force usernames to capital
55 $name = $wgContLang->ucfirst( $name );
57 # Clean up name according to title rules
58 $t = Title
::newFromText( $name );
63 # Reject various classes of invalid names
64 $canonicalName = $t->getText();
66 $canonicalName = $wgAuth->getCanonicalName( $t->getText() );
68 if( !User
::isValidUserName( $canonicalName ) ) {
73 $u->setName( $canonicalName );
74 $u->setId( $u->idFromName( $canonicalName ) );
79 * Factory method to fetch whichever use has a given email confirmation code.
80 * This code is generated when an account is created or its e-mail address
83 * If the code is invalid or has expired, returns NULL.
89 function newFromConfirmationCode( $code ) {
90 $dbr =& wfGetDB( DB_SLAVE
);
91 $name = $dbr->selectField( 'user', 'user_name', array(
92 'user_email_token' => md5( $code ),
93 'user_email_token_expires > ' . $dbr->addQuotes( $dbr->timestamp() ),
95 if( is_string( $name ) ) {
96 return User
::newFromName( $name );
103 * Serialze sleep function, for better cache efficiency and avoidance of
104 * silly "incomplete type" errors when skins are cached
107 return array( 'mId', 'mName', 'mPassword', 'mEmail', 'mNewtalk',
108 'mEmailAuthenticated', 'mRights', 'mOptions', 'mDataLoaded',
109 'mNewpassword', 'mBlockedby', 'mBlockreason', 'mTouched',
110 'mToken', 'mRealName', 'mHash', 'mGroups' );
114 * Get username given an id.
115 * @param integer $id Database user id
116 * @return string Nickname of a user
119 function whoIs( $id ) {
120 $dbr =& wfGetDB( DB_SLAVE
);
121 return $dbr->selectField( 'user', 'user_name', array( 'user_id' => $id ), 'User::whoIs' );
125 * Get real username given an id.
126 * @param integer $id Database user id
127 * @return string Realname of a user
130 function whoIsReal( $id ) {
131 $dbr =& wfGetDB( DB_SLAVE
);
132 return $dbr->selectField( 'user', 'user_real_name', array( 'user_id' => $id ), 'User::whoIsReal' );
136 * Get database id given a user name
137 * @param string $name Nickname of a user
138 * @return integer|null Database user id (null: if non existent
141 function idFromName( $name ) {
142 $fname = "User::idFromName";
144 $nt = Title
::newFromText( $name );
145 if( is_null( $nt ) ) {
149 $dbr =& wfGetDB( DB_SLAVE
);
150 $s = $dbr->selectRow( 'user', array( 'user_id' ), array( 'user_name' => $nt->getText() ), $fname );
152 if ( $s === false ) {
160 * does the string match an anonymous IPv4 address?
162 * Note: We match \d{1,3}\.\d{1,3}\.\d{1,3}\.xxx as an anonymous IP
163 * address because the usemod software would "cloak" anonymous IP
164 * addresses like this, if we allowed accounts like this to be created
165 * new users could get the old edits of these anonymous users.
170 * @param string $name Nickname of a user
173 function isIP( $name ) {
174 return preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.(?:xxx|\d{1,3})$/",$name);
175 /*return preg_match("/^
176 (?:[01]?\d{1,2}|2(:?[0-4]\d|5[0-5]))\.
177 (?:[01]?\d{1,2}|2(:?[0-4]\d|5[0-5]))\.
178 (?:[01]?\d{1,2}|2(:?[0-4]\d|5[0-5]))\.
179 (?:[01]?\d{1,2}|2(:?[0-4]\d|5[0-5]))
184 * Is the input a valid username?
186 * Checks if the input is a valid username, we don't want an empty string,
187 * an IP address, anything that containins slashes (would mess up subpages),
188 * is longer than the maximum allowed username size or doesn't begin with
191 * @param string $name
195 function isValidUserName( $name ) {
196 global $wgContLang, $wgMaxNameChars;
199 || User
::isIP( $name )
200 ||
strpos( $name, '/' ) !== false
201 ||
strlen( $name ) > $wgMaxNameChars
202 ||
$name != $wgContLang->ucfirst( $name ) )
205 // Ensure that the name can't be misresolved as a different title,
206 // such as with extra namespace keys at the start.
207 $parsed = Title
::newFromText( $name );
208 if( is_null( $parsed )
209 ||
$parsed->getNamespace()
210 ||
strcmp( $name, $parsed->getPrefixedText() ) )
217 * Is the input a valid password?
219 * @param string $password
223 function isValidPassword( $password ) {
224 global $wgMinimalPasswordLength;
225 return strlen( $password ) >= $wgMinimalPasswordLength;
229 * Does the string match roughly an email address ?
231 * There used to be a regular expression here, it got removed because it
232 * rejected valid addresses. Actually just check if there is '@' somewhere
233 * in the given address.
235 * @todo Check for RFC 2822 compilance
238 * @param string $addr email address
242 function isValidEmailAddr ( $addr ) {
243 return ( trim( $addr ) != '' ) &&
244 (false !== strpos( $addr, '@' ) );
248 * Count the number of edits of a user
250 * @param int $uid The user ID to check
253 function edits( $uid ) {
254 $fname = 'User::edits';
256 $dbr =& wfGetDB( DB_SLAVE
);
257 return $dbr->selectField(
258 'revision', 'count(*)',
259 array( 'rev_user' => $uid ),
265 * probably return a random password
266 * @return string probably a random password
268 * @todo Check what is doing really [AV]
270 function randomPassword() {
271 global $wgMinimalPasswordLength;
272 $pwchars = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz';
273 $l = strlen( $pwchars ) - 1;
275 $pwlength = max( 7, $wgMinimalPasswordLength );
276 $digit = mt_rand(0, $pwlength - 1);
278 for ( $i = 0; $i < $pwlength; $i++
) {
279 $np .= $i == $digit ?
chr( mt_rand(48, 57) ) : $pwchars{ mt_rand(0, $l)};
285 * Set properties to default
286 * Used at construction. It will load per language default settings only
287 * if we have an available language object.
289 function loadDefaults() {
292 $fname = 'User::loadDefaults' . $n;
293 wfProfileIn( $fname );
295 global $wgContLang, $wgDBname;
296 global $wgNamespacesToBeSearchedDefault;
299 $this->mNewtalk
= -1;
300 $this->mName
= false;
301 $this->mRealName
= $this->mEmail
= '';
302 $this->mEmailAuthenticated
= null;
303 $this->mPassword
= $this->mNewpassword
= '';
304 $this->mRights
= array();
305 $this->mGroups
= array();
306 $this->mOptions
= User
::getDefaultOptions();
308 foreach( $wgNamespacesToBeSearchedDefault as $nsnum => $val ) {
309 $this->mOptions
['searchNs'.$nsnum] = $val;
311 unset( $this->mSkin
);
312 $this->mDataLoaded
= false;
313 $this->mBlockedby
= -1; # Unset
314 $this->setToken(); # Random
315 $this->mHash
= false;
317 if ( isset( $_COOKIE[$wgDBname.'LoggedOut'] ) ) {
318 $this->mTouched
= wfTimestamp( TS_MW
, $_COOKIE[$wgDBname.'LoggedOut'] );
321 $this->mTouched
= '0'; # Allow any pages to be cached
324 wfProfileOut( $fname );
328 * Combine the language default options with any site-specific options
329 * and add the default language variants.
335 function getDefaultOptions() {
337 * Site defaults will override the global/language defaults
339 global $wgContLang, $wgDefaultUserOptions;
340 $defOpt = $wgDefaultUserOptions +
$wgContLang->getDefaultUserOptions();
343 * default language setting
345 $variant = $wgContLang->getPreferredVariant();
346 $defOpt['variant'] = $variant;
347 $defOpt['language'] = $variant;
353 * Get a given default option value.
360 function getDefaultOption( $opt ) {
361 $defOpts = User
::getDefaultOptions();
362 if( isset( $defOpts[$opt] ) ) {
363 return $defOpts[$opt];
370 * Get blocking information
372 * @param bool $bFromSlave Specify whether to check slave or master. To improve performance,
373 * non-critical checks are done against slaves. Check when actually saving should be done against
376 function getBlockedStatus( $bFromSlave = true ) {
377 global $wgEnableSorbs, $wgProxyWhitelist;
379 if ( -1 != $this->mBlockedby
) {
380 wfDebug( "User::getBlockedStatus: already loaded.\n" );
384 $fname = 'User::getBlockedStatus';
385 wfProfileIn( $fname );
386 wfDebug( "$fname: checking...\n" );
388 $this->mBlockedby
= 0;
392 $block = new Block();
393 $block->fromMaster( !$bFromSlave );
394 if ( $block->load( $ip , $this->mId
) ) {
395 wfDebug( "$fname: Found block.\n" );
396 $this->mBlockedby
= $block->mBy
;
397 $this->mBlockreason
= $block->mReason
;
398 if ( $this->isLoggedIn() ) {
399 $this->spreadBlock();
402 wfDebug( "$fname: No block.\n" );
406 if ( !$this->isSysop() && !in_array( $ip, $wgProxyWhitelist ) ) {
409 if ( wfIsLocallyBlockedProxy( $ip ) ) {
410 $this->mBlockedby
= wfMsg( 'proxyblocker' );
411 $this->mBlockreason
= wfMsg( 'proxyblockreason' );
415 if ( !$this->mBlockedby
&& $wgEnableSorbs && !$this->getID() ) {
416 if ( $this->inSorbsBlacklist( $ip ) ) {
417 $this->mBlockedby
= wfMsg( 'sorbs' );
418 $this->mBlockreason
= wfMsg( 'sorbsreason' );
424 wfRunHooks( 'GetBlockedStatus', array( &$this ) );
426 wfProfileOut( $fname );
429 function inSorbsBlacklist( $ip ) {
430 global $wgEnableSorbs;
431 return $wgEnableSorbs &&
432 $this->inDnsBlacklist( $ip, 'http.dnsbl.sorbs.net.' );
435 function inOpmBlacklist( $ip ) {
437 return $wgEnableOpm &&
438 $this->inDnsBlacklist( $ip, 'opm.blitzed.org.' );
441 function inDnsBlacklist( $ip, $base ) {
442 $fname = 'User::inDnsBlacklist';
443 wfProfileIn( $fname );
448 if ( preg_match( '/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/', $ip, $m ) ) {
450 for ( $i=4; $i>=1; $i-- ) {
451 $host .= $m[$i] . '.';
456 $ipList = gethostbynamel( $host );
459 wfDebug( "Hostname $host is {$ipList[0]}, it's a proxy says $base!\n" );
462 wfDebug( "Requested $host, not found in $base.\n" );
466 wfProfileOut( $fname );
471 * Primitive rate limits: enforce maximum actions per time period
472 * to put a brake on flooding.
474 * Note: when using a shared cache like memcached, IP-address
475 * last-hit counters will be shared across wikis.
477 * @return bool true if a rate limiter was tripped
480 function pingLimiter( $action='edit' ) {
481 global $wgRateLimits;
482 if( !isset( $wgRateLimits[$action] ) ) {
485 if( $this->isAllowed( 'delete' ) ) {
490 global $wgMemc, $wgDBname, $wgRateLimitLog;
491 $fname = 'User::pingLimiter';
492 wfProfileIn( $fname );
494 $limits = $wgRateLimits[$action];
496 $id = $this->getId();
499 if( isset( $limits['anon'] ) && $id == 0 ) {
500 $keys["$wgDBname:limiter:$action:anon"] = $limits['anon'];
503 if( isset( $limits['user'] ) && $id != 0 ) {
504 $keys["$wgDBname:limiter:$action:user:$id"] = $limits['user'];
506 if( $this->isNewbie() ) {
507 if( isset( $limits['newbie'] ) && $id != 0 ) {
508 $keys["$wgDBname:limiter:$action:user:$id"] = $limits['newbie'];
510 if( isset( $limits['ip'] ) ) {
511 $keys["mediawiki:limiter:$action:ip:$ip"] = $limits['ip'];
513 if( isset( $limits['subnet'] ) && preg_match( '/^(\d+\.\d+\.\d+)\.\d+$/', $ip, $matches ) ) {
514 $subnet = $matches[1];
515 $keys["mediawiki:limiter:$action:subnet:$subnet"] = $limits['subnet'];
520 foreach( $keys as $key => $limit ) {
521 list( $max, $period ) = $limit;
522 $summary = "(limit $max in {$period}s)";
523 $count = $wgMemc->get( $key );
525 if( $count > $max ) {
526 wfDebug( "$fname: tripped! $key at $count $summary\n" );
527 if( $wgRateLimitLog ) {
528 @error_log
( wfTimestamp( TS_MW
) . ' ' . $wgDBname . ': ' . $this->getName() . " tripped $key at $count $summary\n", 3, $wgRateLimitLog );
532 wfDebug( "$fname: ok. $key at $count $summary\n" );
535 wfDebug( "$fname: adding record for $key $summary\n" );
536 $wgMemc->add( $key, 1, intval( $period ) );
538 $wgMemc->incr( $key );
541 wfProfileOut( $fname );
546 * Check if user is blocked
547 * @return bool True if blocked, false otherwise
549 function isBlocked( $bFromSlave = true ) { // hacked from false due to horrible probs on site
550 wfDebug( "User::isBlocked: enter\n" );
551 $this->getBlockedStatus( $bFromSlave );
552 return $this->mBlockedby
!== 0;
556 * Check if user is blocked from editing a particular article
558 function isBlockedFrom( $title, $bFromSlave = false ) {
559 global $wgBlockAllowsUTEdit;
560 $fname = 'User::isBlockedFrom';
561 wfProfileIn( $fname );
562 wfDebug( "$fname: enter\n" );
564 if ( $wgBlockAllowsUTEdit && $title->getText() === $this->getName() &&
565 $title->getNamespace() == NS_USER_TALK
)
568 wfDebug( "$fname: self-talk page, ignoring any blocks\n" );
570 wfDebug( "$fname: asking isBlocked()\n" );
571 $blocked = $this->isBlocked( $bFromSlave );
573 wfProfileOut( $fname );
578 * Get name of blocker
579 * @return string name of blocker
581 function blockedBy() {
582 $this->getBlockedStatus();
583 return $this->mBlockedby
;
587 * Get blocking reason
588 * @return string Blocking reason
590 function blockedFor() {
591 $this->getBlockedStatus();
592 return $this->mBlockreason
;
596 * Initialise php session
598 function SetupSession() {
599 global $wgSessionsInMemcached, $wgCookiePath, $wgCookieDomain;
600 if( $wgSessionsInMemcached ) {
601 require_once( 'MemcachedSessions.php' );
602 } elseif( 'files' != ini_get( 'session.save_handler' ) ) {
603 # If it's left on 'user' or another setting from another
604 # application, it will end up failing. Try to recover.
605 ini_set ( 'session.save_handler', 'files' );
607 session_set_cookie_params( 0, $wgCookiePath, $wgCookieDomain );
608 session_cache_limiter( 'private, must-revalidate' );
613 * Create a new user object using data from session
616 function loadFromSession() {
617 global $wgMemc, $wgDBname;
619 if ( isset( $_SESSION['wsUserID'] ) ) {
620 if ( 0 != $_SESSION['wsUserID'] ) {
621 $sId = $_SESSION['wsUserID'];
625 } else if ( isset( $_COOKIE["{$wgDBname}UserID"] ) ) {
626 $sId = intval( $_COOKIE["{$wgDBname}UserID"] );
627 $_SESSION['wsUserID'] = $sId;
631 if ( isset( $_SESSION['wsUserName'] ) ) {
632 $sName = $_SESSION['wsUserName'];
633 } else if ( isset( $_COOKIE["{$wgDBname}UserName"] ) ) {
634 $sName = $_COOKIE["{$wgDBname}UserName"];
635 $_SESSION['wsUserName'] = $sName;
640 $passwordCorrect = FALSE;
641 $user = $wgMemc->get( $key = "$wgDBname:user:id:$sId" );
642 if( !is_object( $user ) ||
$user->mVersion
< MW_USER_VERSION
) {
643 # Expire old serialized objects; they may be corrupt.
646 if($makenew = !$user) {
647 wfDebug( "User::loadFromSession() unable to load from memcached\n" );
650 $user->loadFromDatabase();
652 wfDebug( "User::loadFromSession() got from cache!\n" );
655 if ( isset( $_SESSION['wsToken'] ) ) {
656 $passwordCorrect = $_SESSION['wsToken'] == $user->mToken
;
657 } else if ( isset( $_COOKIE["{$wgDBname}Token"] ) ) {
658 $passwordCorrect = $user->mToken
== $_COOKIE["{$wgDBname}Token"];
660 return new User(); # Can't log in from session
663 if ( ( $sName == $user->mName
) && $passwordCorrect ) {
665 if($wgMemc->set( $key, $user ))
666 wfDebug( "User::loadFromSession() successfully saved user\n" );
668 wfDebug( "User::loadFromSession() unable to save to memcached\n" );
672 return new User(); # Can't log in from session
676 * Load a user from the database
678 function loadFromDatabase() {
679 $fname = "User::loadFromDatabase";
681 # Counter-intuitive, breaks various things, use User::setLoaded() if you want to suppress
682 # loading in a command line script, don't assume all command line scripts need it like this
683 #if ( $this->mDataLoaded || $wgCommandLineMode ) {
684 if ( $this->mDataLoaded
) {
689 $this->mId
= intval( $this->mId
);
691 /** Anonymous user */
694 $this->mRights
= $this->getGroupPermissions( array( '*' ) );
695 $this->mDataLoaded
= true;
697 } # the following stuff is for non-anonymous users only
699 $dbr =& wfGetDB( DB_SLAVE
);
700 $s = $dbr->selectRow( 'user', array( 'user_name','user_password','user_newpassword','user_email',
701 'user_email_authenticated',
702 'user_real_name','user_options','user_touched', 'user_token' ),
703 array( 'user_id' => $this->mId
), $fname );
705 if ( $s !== false ) {
706 $this->mName
= $s->user_name
;
707 $this->mEmail
= $s->user_email
;
708 $this->mEmailAuthenticated
= wfTimestampOrNull( TS_MW
, $s->user_email_authenticated
);
709 $this->mRealName
= $s->user_real_name
;
710 $this->mPassword
= $s->user_password
;
711 $this->mNewpassword
= $s->user_newpassword
;
712 $this->decodeOptions( $s->user_options
);
713 $this->mTouched
= wfTimestamp(TS_MW
,$s->user_touched
);
714 $this->mToken
= $s->user_token
;
716 $res = $dbr->select( 'user_groups',
718 array( 'ug_user' => $this->mId
),
720 $this->mGroups
= array();
721 while( $row = $dbr->fetchObject( $res ) ) {
722 $this->mGroups
[] = $row->ug_group
;
724 $effectiveGroups = array_merge( array( '*', 'user' ), $this->mGroups
);
725 $this->mRights
= $this->getGroupPermissions( $effectiveGroups );
728 $this->mDataLoaded
= true;
731 function getID() { return $this->mId
; }
732 function setID( $v ) {
734 $this->mDataLoaded
= false;
738 $this->loadFromDatabase();
739 if ( $this->mName
=== false ) {
740 $this->mName
= wfGetIP();
745 function setName( $str ) {
746 $this->loadFromDatabase();
752 * Return the title dbkey form of the name, for eg user pages.
756 function getTitleKey() {
757 return str_replace( ' ', '_', $this->getName() );
760 function getNewtalk() {
761 $this->loadFromDatabase();
763 # Load the newtalk status if it is unloaded (mNewtalk=-1)
764 if( $this->mNewtalk
=== -1 ) {
765 $this->mNewtalk
= false; # reset talk page status
767 # Check memcached separately for anons, who have no
768 # entire User object stored in there.
770 global $wgDBname, $wgMemc;
771 $key = "$wgDBname:newtalk:ip:" . $this->getName();
772 $newtalk = $wgMemc->get( $key );
773 if( is_integer( $newtalk ) ) {
774 $this->mNewtalk
= (bool)$newtalk;
776 $this->mNewtalk
= $this->checkNewtalk( 'user_ip', $this->getName() );
777 $wgMemc->set( $key, $this->mNewtalk
, time() ); // + 1800 );
780 $this->mNewtalk
= $this->checkNewtalk( 'user_id', $this->mId
);
784 return (bool)$this->mNewtalk
;
788 * Perform a user_newtalk check on current slaves; if the memcached data
789 * is funky we don't want newtalk state to get stuck on save, as that's
792 * @param string $field
797 function checkNewtalk( $field, $id ) {
798 $fname = 'User::checkNewtalk';
799 $dbr =& wfGetDB( DB_SLAVE
);
800 $ok = $dbr->selectField( 'user_newtalk', $field,
801 array( $field => $id ), $fname );
802 return $ok !== false;
807 * @param string $field
811 function updateNewtalk( $field, $id ) {
812 $fname = 'User::updateNewtalk';
813 if( $this->checkNewtalk( $field, $id ) ) {
814 wfDebug( "$fname already set ($field, $id), ignoring\n" );
817 $dbw =& wfGetDB( DB_MASTER
);
818 $dbw->insert( 'user_newtalk',
819 array( $field => $id ),
822 wfDebug( "$fname: set on ($field, $id)\n" );
827 * @param string $field
831 function deleteNewtalk( $field, $id ) {
832 $fname = 'User::deleteNewtalk';
833 if( !$this->checkNewtalk( $field, $id ) ) {
834 wfDebug( "$fname: already gone ($field, $id), ignoring\n" );
837 $dbw =& wfGetDB( DB_MASTER
);
838 $dbw->delete( 'user_newtalk',
839 array( $field => $id ),
841 wfDebug( "$fname: killed on ($field, $id)\n" );
846 * Update the 'You have new messages!' status.
849 function setNewtalk( $val ) {
854 $this->loadFromDatabase();
855 $this->mNewtalk
= $val;
857 $fname = 'User::setNewtalk';
859 if( $this->isAnon() ) {
861 $id = $this->getName();
864 $id = $this->getId();
868 $changed = $this->updateNewtalk( $field, $id );
870 $changed = $this->deleteNewtalk( $field, $id );
874 if( $this->isAnon() ) {
875 // Anons have a separate memcached space, since
876 // user records aren't kept for them.
877 global $wgDBname, $wgMemc;
878 $key = "$wgDBname:newtalk:ip:$value";
879 $wgMemc->set( $key, $val ?
1 : 0 );
882 // Make sure the user page is watched, so a notification
883 // will be sent out if enabled.
884 $this->addWatch( $this->getTalkPage() );
887 $this->invalidateCache();
888 $this->saveSettings();
892 function invalidateCache() {
893 global $wgClockSkewFudge;
894 $this->loadFromDatabase();
895 $this->mTouched
= wfTimestamp(TS_MW
, time() +
$wgClockSkewFudge );
896 # Don't forget to save the options after this or
897 # it won't take effect!
900 function validateCache( $timestamp ) {
901 $this->loadFromDatabase();
902 return ($timestamp >= $this->mTouched
);
906 * Encrypt a password.
907 * It can eventuall salt a password @see User::addSalt()
908 * @param string $p clear Password.
909 * @return string Encrypted password.
911 function encryptPassword( $p ) {
912 return wfEncryptPassword( $this->mId
, $p );
915 # Set the password and reset the random token
916 function setPassword( $str ) {
917 $this->loadFromDatabase();
919 $this->mPassword
= $this->encryptPassword( $str );
920 $this->mNewpassword
= '';
923 # Set the random token (used for persistent authentication)
924 function setToken( $token = false ) {
925 global $wgSecretKey, $wgProxyKey, $wgDBname;
927 if ( $wgSecretKey ) {
929 } elseif ( $wgProxyKey ) {
934 $this->mToken
= md5( $key . mt_rand( 0, 0x7fffffff ) . $wgDBname . $this->mId
);
936 $this->mToken
= $token;
941 function setCookiePassword( $str ) {
942 $this->loadFromDatabase();
943 $this->mCookiePassword
= md5( $str );
946 function setNewpassword( $str ) {
947 $this->loadFromDatabase();
948 $this->mNewpassword
= $this->encryptPassword( $str );
951 function getEmail() {
952 $this->loadFromDatabase();
953 return $this->mEmail
;
956 function getEmailAuthenticationTimestamp() {
957 $this->loadFromDatabase();
958 return $this->mEmailAuthenticated
;
961 function setEmail( $str ) {
962 $this->loadFromDatabase();
963 $this->mEmail
= $str;
966 function getRealName() {
967 $this->loadFromDatabase();
968 return $this->mRealName
;
971 function setRealName( $str ) {
972 $this->loadFromDatabase();
973 $this->mRealName
= $str;
976 function getOption( $oname ) {
977 $this->loadFromDatabase();
978 if ( array_key_exists( $oname, $this->mOptions
) ) {
979 return trim( $this->mOptions
[$oname] );
985 function setOption( $oname, $val ) {
986 $this->loadFromDatabase();
987 if ( $oname == 'skin' ) {
988 # Clear cached skin, so the new one displays immediately in Special:Preferences
989 unset( $this->mSkin
);
991 $this->mOptions
[$oname] = $val;
992 $this->invalidateCache();
995 function getRights() {
996 $this->loadFromDatabase();
997 return $this->mRights
;
1001 * Get the list of explicit group memberships this user has.
1002 * The implicit * and user groups are not included.
1003 * @return array of strings
1005 function getGroups() {
1006 $this->loadFromDatabase();
1007 return $this->mGroups
;
1011 * Get the list of implicit group memberships this user has.
1012 * This includes all explicit groups, plus 'user' if logged in
1013 * and '*' for all accounts.
1014 * @return array of strings
1016 function getEffectiveGroups() {
1017 $base = array( '*' );
1018 if( $this->isLoggedIn() ) {
1021 return array_merge( $base, $this->getGroups() );
1025 * Remove the user from the given group.
1026 * This takes immediate effect.
1029 function addGroup( $group ) {
1030 $dbw =& wfGetDB( DB_MASTER
);
1031 $dbw->insert( 'user_groups',
1033 'ug_user' => $this->getID(),
1034 'ug_group' => $group,
1037 array( 'IGNORE' ) );
1039 $this->mGroups
= array_merge( $this->mGroups
, array( $group ) );
1040 $this->mRights
= User
::getGroupPermissions( $this->getEffectiveGroups() );
1042 $this->invalidateCache();
1043 $this->saveSettings();
1047 * Remove the user from the given group.
1048 * This takes immediate effect.
1051 function removeGroup( $group ) {
1052 $dbw =& wfGetDB( DB_MASTER
);
1053 $dbw->delete( 'user_groups',
1055 'ug_user' => $this->getID(),
1056 'ug_group' => $group,
1058 'User::removeGroup' );
1060 $this->mGroups
= array_diff( $this->mGroups
, array( $group ) );
1061 $this->mRights
= User
::getGroupPermissions( $this->getEffectiveGroups() );
1063 $this->invalidateCache();
1064 $this->saveSettings();
1069 * A more legible check for non-anonymousness.
1070 * Returns true if the user is not an anonymous visitor.
1074 function isLoggedIn() {
1075 return( $this->getID() != 0 );
1079 * A more legible check for anonymousness.
1080 * Returns true if the user is an anonymous visitor.
1085 return !$this->isLoggedIn();
1089 * Check if a user is sysop
1092 function isSysop() {
1093 return $this->isAllowed( 'protect' );
1097 function isDeveloper() {
1098 return $this->isAllowed( 'siteadmin' );
1102 function isBureaucrat() {
1103 return $this->isAllowed( 'makesysop' );
1107 * Whether the user is a bot
1108 * @todo need to be migrated to the new user level management sytem
1111 $this->loadFromDatabase();
1112 return in_array( 'bot', $this->mRights
);
1116 * Check if user is allowed to access a feature / make an action
1117 * @param string $action Action to be checked (see $wgAvailableRights in Defines.php for possible actions).
1118 * @return boolean True: action is allowed, False: action should not be allowed
1120 function isAllowed($action='') {
1121 $this->loadFromDatabase();
1122 return in_array( $action , $this->mRights
);
1126 * Load a skin if it doesn't exist or return it
1127 * @todo FIXME : need to check the old failback system [AV]
1129 function &getSkin() {
1130 global $IP, $wgRequest;
1131 if ( ! isset( $this->mSkin
) ) {
1132 $fname = 'User::getSkin';
1133 wfProfileIn( $fname );
1135 # get all skin names available
1136 $skinNames = Skin
::getSkinNames();
1139 $userSkin = $this->getOption( 'skin' );
1140 $userSkin = $wgRequest->getText('useskin', $userSkin);
1141 if ( $userSkin == '' ) { $userSkin = 'standard'; }
1143 if ( !isset( $skinNames[$userSkin] ) ) {
1144 # in case the user skin could not be found find a replacement
1148 2 => 'CologneBlue');
1149 # if phptal is enabled we should have monobook skin that
1150 # superseed the good old SkinStandard.
1151 if ( isset( $skinNames['monobook'] ) ) {
1152 $fallback[0] = 'MonoBook';
1155 if(is_numeric($userSkin) && isset( $fallback[$userSkin]) ){
1156 $sn = $fallback[$userSkin];
1161 # The user skin is available
1162 $sn = $skinNames[$userSkin];
1165 # Grab the skin class and initialise it. Each skin checks for PHPTal
1166 # and will not load if it's not enabled.
1167 require_once( $IP.'/skins/'.$sn.'.php' );
1169 # Check if we got if not failback to default skin
1170 $className = 'Skin'.$sn;
1171 if( !class_exists( $className ) ) {
1172 # DO NOT die if the class isn't found. This breaks maintenance
1173 # scripts and can cause a user account to be unrecoverable
1174 # except by SQL manipulation if a previously valid skin name
1175 # is no longer valid.
1176 $className = 'SkinStandard';
1177 require_once( $IP.'/skins/Standard.php' );
1179 $this->mSkin
=& new $className;
1180 wfProfileOut( $fname );
1182 return $this->mSkin
;
1186 * @param string $title Article title to look at
1190 * Check watched status of an article
1191 * @return bool True if article is watched
1193 function isWatched( $title ) {
1194 $wl = WatchedItem
::fromUserTitle( $this, $title );
1195 return $wl->isWatched();
1201 function addWatch( $title ) {
1202 $wl = WatchedItem
::fromUserTitle( $this, $title );
1204 $this->invalidateCache();
1208 * Stop watching an article
1210 function removeWatch( $title ) {
1211 $wl = WatchedItem
::fromUserTitle( $this, $title );
1213 $this->invalidateCache();
1217 * Clear the user's notification timestamp for the given title.
1218 * If e-notif e-mails are on, they will receive notification mails on
1219 * the next change of the page if it's watched etc.
1221 function clearNotification( &$title ) {
1222 global $wgUser, $wgUseEnotif;
1224 if ($title->getNamespace() == NS_USER_TALK
&&
1225 $title->getText() == $this->getName() ) {
1226 $this->setNewtalk( false );
1229 if( !$wgUseEnotif ) {
1233 if( $this->isAnon() ) {
1234 // Nothing else to do...
1238 // Only update the timestamp if the page is being watched.
1239 // The query to find out if it is watched is cached both in memcached and per-invocation,
1240 // and when it does have to be executed, it can be on a slave
1241 // If this is the user's newtalk page, we always update the timestamp
1242 if ($title->getNamespace() == NS_USER_TALK
&&
1243 $title->getText() == $wgUser->getName())
1246 } elseif ( $this->getID() == $wgUser->getID() ) {
1247 $watched = $title->userIsWatching();
1252 // If the page is watched by the user (or may be watched), update the timestamp on any
1253 // any matching rows
1255 $dbw =& wfGetDB( DB_MASTER
);
1256 $success = $dbw->update( 'watchlist',
1258 'wl_notificationtimestamp' => NULL
1259 ), array( /* WHERE */
1260 'wl_title' => $title->getDBkey(),
1261 'wl_namespace' => $title->getNamespace(),
1262 'wl_user' => $this->getID()
1263 ), 'User::clearLastVisited'
1271 * Resets all of the given user's page-change notification timestamps.
1272 * If e-notif e-mails are on, they will receive notification mails on
1273 * the next change of any watched page.
1275 * @param int $currentUser user ID number
1278 function clearAllNotifications( $currentUser ) {
1279 global $wgUseEnotif;
1280 if ( !$wgUseEnotif ) {
1281 $this->setNewtalk( false );
1284 if( $currentUser != 0 ) {
1286 $dbw =& wfGetDB( DB_MASTER
);
1287 $success = $dbw->update( 'watchlist',
1289 'wl_notificationtimestamp' => 0
1290 ), array( /* WHERE */
1291 'wl_user' => $currentUser
1292 ), 'UserMailer::clearAll'
1295 # we also need to clear here the "you have new message" notification for the own user_talk page
1296 # This is cleared one page view later in Article::viewUpdates();
1302 * @return string Encoding options
1304 function encodeOptions() {
1306 foreach ( $this->mOptions
as $oname => $oval ) {
1307 array_push( $a, $oname.'='.$oval );
1309 $s = implode( "\n", $a );
1316 function decodeOptions( $str ) {
1317 $a = explode( "\n", $str );
1318 foreach ( $a as $s ) {
1319 if ( preg_match( "/^(.[^=]*)=(.*)$/", $s, $m ) ) {
1320 $this->mOptions
[$m[1]] = $m[2];
1325 function setCookies() {
1326 global $wgCookieExpiration, $wgCookiePath, $wgCookieDomain, $wgDBname;
1327 if ( 0 == $this->mId
) return;
1328 $this->loadFromDatabase();
1329 $exp = time() +
$wgCookieExpiration;
1331 $_SESSION['wsUserID'] = $this->mId
;
1332 setcookie( $wgDBname.'UserID', $this->mId
, $exp, $wgCookiePath, $wgCookieDomain );
1334 $_SESSION['wsUserName'] = $this->getName();
1335 setcookie( $wgDBname.'UserName', $this->getName(), $exp, $wgCookiePath, $wgCookieDomain );
1337 $_SESSION['wsToken'] = $this->mToken
;
1338 if ( 1 == $this->getOption( 'rememberpassword' ) ) {
1339 setcookie( $wgDBname.'Token', $this->mToken
, $exp, $wgCookiePath, $wgCookieDomain );
1341 setcookie( $wgDBname.'Token', '', time() - 3600 );
1347 * It will clean the session cookie
1350 global $wgCookiePath, $wgCookieDomain, $wgDBname;
1351 $this->loadDefaults();
1352 $this->setLoaded( true );
1354 $_SESSION['wsUserID'] = 0;
1356 setcookie( $wgDBname.'UserID', '', time() - 3600, $wgCookiePath, $wgCookieDomain );
1357 setcookie( $wgDBname.'Token', '', time() - 3600, $wgCookiePath, $wgCookieDomain );
1359 # Remember when user logged out, to prevent seeing cached pages
1360 setcookie( $wgDBname.'LoggedOut', wfTimestampNow(), time() +
86400, $wgCookiePath, $wgCookieDomain );
1364 * Save object settings into database
1366 function saveSettings() {
1367 global $wgMemc, $wgDBname, $wgUseEnotif;
1368 $fname = 'User::saveSettings';
1370 if ( wfReadOnly() ) { return; }
1371 if ( 0 == $this->mId
) { return; }
1373 $dbw =& wfGetDB( DB_MASTER
);
1374 $dbw->update( 'user',
1376 'user_name' => $this->mName
,
1377 'user_password' => $this->mPassword
,
1378 'user_newpassword' => $this->mNewpassword
,
1379 'user_real_name' => $this->mRealName
,
1380 'user_email' => $this->mEmail
,
1381 'user_email_authenticated' => $dbw->timestampOrNull( $this->mEmailAuthenticated
),
1382 'user_options' => $this->encodeOptions(),
1383 'user_touched' => $dbw->timestamp($this->mTouched
),
1384 'user_token' => $this->mToken
1385 ), array( /* WHERE */
1386 'user_id' => $this->mId
1389 $wgMemc->delete( "$wgDBname:user:id:$this->mId" );
1394 * Checks if a user with the given name exists, returns the ID
1396 function idForName() {
1397 $fname = 'User::idForName';
1400 $s = trim( $this->getName() );
1401 if ( 0 == strcmp( '', $s ) ) return 0;
1403 $dbr =& wfGetDB( DB_SLAVE
);
1404 $id = $dbr->selectField( 'user', 'user_id', array( 'user_name' => $s ), $fname );
1405 if ( $id === false ) {
1412 * Add user object to the database
1414 function addToDatabase() {
1415 $fname = 'User::addToDatabase';
1416 $dbw =& wfGetDB( DB_MASTER
);
1417 $seqVal = $dbw->nextSequenceValue( 'user_user_id_seq' );
1418 $dbw->insert( 'user',
1420 'user_id' => $seqVal,
1421 'user_name' => $this->mName
,
1422 'user_password' => $this->mPassword
,
1423 'user_newpassword' => $this->mNewpassword
,
1424 'user_email' => $this->mEmail
,
1425 'user_email_authenticated' => $dbw->timestampOrNull( $this->mEmailAuthenticated
),
1426 'user_real_name' => $this->mRealName
,
1427 'user_options' => $this->encodeOptions(),
1428 'user_token' => $this->mToken
1431 $this->mId
= $dbw->insertId();
1434 function spreadBlock() {
1435 # If the (non-anonymous) user is blocked, this function will block any IP address
1436 # that they successfully log on from.
1437 $fname = 'User::spreadBlock';
1439 wfDebug( "User:spreadBlock()\n" );
1440 if ( $this->mId
== 0 ) {
1444 $userblock = Block
::newFromDB( '', $this->mId
);
1445 if ( !$userblock->isValid() ) {
1449 # Check if this IP address is already blocked
1450 $ipblock = Block
::newFromDB( wfGetIP() );
1451 if ( $ipblock->isValid() ) {
1452 # If the user is already blocked. Then check if the autoblock would
1453 # excede the user block. If it would excede, then do nothing, else
1454 # prolong block time
1455 if ($userblock->mExpiry
&&
1456 ($userblock->mExpiry
< Block
::getAutoblockExpiry($ipblock->mTimestamp
))) {
1459 # Just update the timestamp
1460 $ipblock->updateTimestamp();
1464 # Make a new block object with the desired properties
1465 wfDebug( "Autoblocking {$this->mName}@" . wfGetIP() . "\n" );
1466 $ipblock->mAddress
= wfGetIP();
1467 $ipblock->mUser
= 0;
1468 $ipblock->mBy
= $userblock->mBy
;
1469 $ipblock->mReason
= wfMsg( 'autoblocker', $this->getName(), $userblock->mReason
);
1470 $ipblock->mTimestamp
= wfTimestampNow();
1471 $ipblock->mAuto
= 1;
1472 # If the user is already blocked with an expiry date, we don't
1473 # want to pile on top of that!
1474 if($userblock->mExpiry
) {
1475 $ipblock->mExpiry
= min ( $userblock->mExpiry
, Block
::getAutoblockExpiry( $ipblock->mTimestamp
));
1477 $ipblock->mExpiry
= Block
::getAutoblockExpiry( $ipblock->mTimestamp
);
1485 function getPageRenderingHash() {
1488 return $this->mHash
;
1491 // stubthreshold is only included below for completeness,
1492 // it will always be 0 when this function is called by parsercache.
1494 $confstr = $this->getOption( 'math' );
1495 $confstr .= '!' . $this->getOption( 'stubthreshold' );
1496 $confstr .= '!' . $this->getOption( 'date' );
1497 $confstr .= '!' . ($this->getOption( 'numberheadings' ) ?
'1' : '');
1498 $confstr .= '!' . $this->getOption( 'language' );
1499 $confstr .= '!' . $this->getOption( 'thumbsize' );
1500 // add in language specific options, if any
1501 $extra = $wgContLang->getExtraHashOptions();
1504 $this->mHash
= $confstr;
1508 function isAllowedToCreateAccount() {
1509 return $this->isAllowed( 'createaccount' ) && !$this->isBlocked();
1513 * Set mDataLoaded, return previous value
1514 * Use this to prevent DB access in command-line scripts or similar situations
1516 function setLoaded( $loaded ) {
1517 return wfSetVar( $this->mDataLoaded
, $loaded );
1521 * Get this user's personal page title.
1526 function getUserPage() {
1527 return Title
::makeTitle( NS_USER
, $this->getName() );
1531 * Get this user's talk page title.
1536 function getTalkPage() {
1537 $title = $this->getUserPage();
1538 return $title->getTalkPage();
1544 function getMaxID() {
1545 static $res; // cache
1547 if ( isset( $res ) )
1550 $dbr =& wfGetDB( DB_SLAVE
);
1551 return $res = $dbr->selectField( 'user', 'max(user_id)', false, 'User::getMaxID' );
1556 * Determine whether the user is a newbie. Newbies are either
1557 * anonymous IPs, or the 1% most recently created accounts.
1558 * Bots and sysops are excluded.
1559 * @return bool True if it is a newbie.
1561 function isNewbie() {
1562 return $this->isAnon() ||
$this->mId
> User
::getMaxID() * 0.99 && !$this->isAllowed( 'delete' ) && !$this->isBot();
1566 * Check to see if the given clear-text password is one of the accepted passwords
1567 * @param string $password User password.
1568 * @return bool True if the given password is correct otherwise False.
1570 function checkPassword( $password ) {
1571 global $wgAuth, $wgMinimalPasswordLength;
1572 $this->loadFromDatabase();
1574 // Even though we stop people from creating passwords that
1575 // are shorter than this, doesn't mean people wont be able
1576 // to. Certain authentication plugins do NOT want to save
1577 // domain passwords in a mysql database, so we should
1578 // check this (incase $wgAuth->strict() is false).
1579 if( strlen( $password ) < $wgMinimalPasswordLength ) {
1583 if( $wgAuth->authenticate( $this->getName(), $password ) ) {
1585 } elseif( $wgAuth->strict() ) {
1586 /* Auth plugin doesn't allow local authentication */
1589 $ep = $this->encryptPassword( $password );
1590 if ( 0 == strcmp( $ep, $this->mPassword
) ) {
1592 } elseif ( ($this->mNewpassword
!= '') && (0 == strcmp( $ep, $this->mNewpassword
)) ) {
1594 } elseif ( function_exists( 'iconv' ) ) {
1595 # Some wikis were converted from ISO 8859-1 to UTF-8, the passwords can't be converted
1596 # Check for this with iconv
1597 $cp1252hash = $this->encryptPassword( iconv( 'UTF-8', 'WINDOWS-1252', $password ) );
1598 if ( 0 == strcmp( $cp1252hash, $this->mPassword
) ) {
1606 * Initialize (if necessary) and return a session token value
1607 * which can be used in edit forms to show that the user's
1608 * login credentials aren't being hijacked with a foreign form
1611 * @param mixed $salt - Optional function-specific data for hash.
1612 * Use a string or an array of strings.
1616 function editToken( $salt = '' ) {
1617 if( !isset( $_SESSION['wsEditToken'] ) ) {
1618 $token = $this->generateToken();
1619 $_SESSION['wsEditToken'] = $token;
1621 $token = $_SESSION['wsEditToken'];
1623 if( is_array( $salt ) ) {
1624 $salt = implode( '|', $salt );
1626 return md5( $token . $salt );
1630 * Generate a hex-y looking random token for various uses.
1631 * Could be made more cryptographically sure if someone cares.
1634 function generateToken( $salt = '' ) {
1635 $token = dechex( mt_rand() ) . dechex( mt_rand() );
1636 return md5( $token . $salt );
1640 * Check given value against the token value stored in the session.
1641 * A match should confirm that the form was submitted from the
1642 * user's own login session, not a form submission from a third-party
1645 * @param string $val - the input value to compare
1646 * @param string $salt - Optional function-specific data for hash
1650 function matchEditToken( $val, $salt = '' ) {
1654 if ( !isset( $_SESSION['wsEditToken'] ) ) {
1655 $logfile = '/home/wikipedia/logs/session_debug/session.log';
1656 $mckey = memsess_key( session_id() );
1657 $uname = @posix_uname();
1658 $msg = "wsEditToken not set!\n" .
1659 'apache server=' . $uname['nodename'] . "\n" .
1660 'session_id = ' . session_id() . "\n" .
1661 '$_SESSION=' . var_export( $_SESSION, true ) . "\n" .
1662 '$_COOKIE=' . var_export( $_COOKIE, true ) . "\n" .
1663 "mc get($mckey) = " . var_export( $wgMemc->get( $mckey ), true ) . "\n\n\n";
1665 @error_log( $msg, 3, $logfile );
1668 return ( $val == $this->editToken( $salt ) );
1672 * Generate a new e-mail confirmation token and send a confirmation
1673 * mail to the user's given address.
1675 * @return mixed True on success, a WikiError object on failure.
1677 function sendConfirmationMail() {
1679 $url = $this->confirmationTokenUrl( $expiration );
1680 return $this->sendMail( wfMsg( 'confirmemail_subject' ),
1681 wfMsg( 'confirmemail_body',
1685 $wgContLang->timeanddate( $expiration, false ) ) );
1689 * Send an e-mail to this user's account. Does not check for
1690 * confirmed status or validity.
1692 * @param string $subject
1693 * @param string $body
1694 * @param strong $from Optional from address; default $wgPasswordSender will be used otherwise.
1695 * @return mixed True on success, a WikiError object on failure.
1697 function sendMail( $subject, $body, $from = null ) {
1698 if( is_null( $from ) ) {
1699 global $wgPasswordSender;
1700 $from = $wgPasswordSender;
1703 require_once( 'UserMailer.php' );
1704 $error = userMailer( $this->getEmail(), $from, $subject, $body );
1706 if( $error == '' ) {
1709 return new WikiError( $error );
1714 * Generate, store, and return a new e-mail confirmation code.
1715 * A hash (unsalted since it's used as a key) is stored.
1716 * @param &$expiration mixed output: accepts the expiration time
1720 function confirmationToken( &$expiration ) {
1721 $fname = 'User::confirmationToken';
1724 $expires = $now +
7 * 24 * 60 * 60;
1725 $expiration = wfTimestamp( TS_MW
, $expires );
1727 $token = $this->generateToken( $this->mId
. $this->mEmail
. $expires );
1728 $hash = md5( $token );
1730 $dbw =& wfGetDB( DB_MASTER
);
1731 $dbw->update( 'user',
1732 array( 'user_email_token' => $hash,
1733 'user_email_token_expires' => $dbw->timestamp( $expires ) ),
1734 array( 'user_id' => $this->mId
),
1741 * Generate and store a new e-mail confirmation token, and return
1742 * the URL the user can use to confirm.
1743 * @param &$expiration mixed output: accepts the expiration time
1747 function confirmationTokenUrl( &$expiration ) {
1748 $token = $this->confirmationToken( $expiration );
1749 $title = Title
::makeTitle( NS_SPECIAL
, 'Confirmemail/' . $token );
1750 return $title->getFullUrl();
1754 * Mark the e-mail address confirmed and save.
1756 function confirmEmail() {
1757 $this->loadFromDatabase();
1758 $this->mEmailAuthenticated
= wfTimestampNow();
1759 $this->saveSettings();
1764 * Is this user allowed to send e-mails within limits of current
1765 * site configuration?
1768 function canSendEmail() {
1769 return $this->isEmailConfirmed();
1773 * Is this user allowed to receive e-mails within limits of current
1774 * site configuration?
1777 function canReceiveEmail() {
1778 return $this->canSendEmail() && !$this->getOption( 'disablemail' );
1782 * Is this user's e-mail address valid-looking and confirmed within
1783 * limits of the current site configuration?
1785 * If $wgEmailAuthentication is on, this may require the user to have
1786 * confirmed their address by returning a code or using a password
1787 * sent to the address from the wiki.
1791 function isEmailConfirmed() {
1792 global $wgEmailAuthentication;
1793 $this->loadFromDatabase();
1794 if( $this->isAnon() )
1796 if( !$this->isValidEmailAddr( $this->mEmail
) )
1798 if( $wgEmailAuthentication && !$this->getEmailAuthenticationTimestamp() )
1804 * @param array $groups list of groups
1805 * @return array list of permission key names for given groups combined
1808 function getGroupPermissions( $groups ) {
1809 global $wgGroupPermissions;
1811 foreach( $groups as $group ) {
1812 if( isset( $wgGroupPermissions[$group] ) ) {
1813 $rights = array_merge( $rights,
1814 array_keys( array_filter( $wgGroupPermissions[$group] ) ) );
1821 * @param string $group key name
1822 * @return string localized descriptive name, if provided
1825 function getGroupName( $group ) {
1826 $key = "group-$group-name";
1827 $name = wfMsg( $key );
1828 if( $name == '' ||
$name == "<$key>" ) {
1836 * Return the set of defined explicit groups.
1837 * The * and 'user' groups are not included.
1841 function getAllGroups() {
1842 global $wgGroupPermissions;
1844 array_keys( $wgGroupPermissions ),
1845 array( '*', 'user' ) );