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', 3 );
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
41 /** Construct using User:loadDefaults() */
43 $this->loadDefaults();
44 $this->mVersion
= MW_USER_VERSION
;
48 * Static factory method
49 * @param string $name Username, validated by Title:newFromText()
53 function newFromName( $name ) {
54 # Force usernames to capital
56 $name = $wgContLang->ucfirst( $name );
58 # Clean up name according to title rules
59 $t = Title
::newFromText( $name );
64 # Reject various classes of invalid names
65 $canonicalName = $t->getText();
67 $canonicalName = $wgAuth->getCanonicalName( $t->getText() );
69 if( !User
::isValidUserName( $canonicalName ) ) {
74 $u->setName( $canonicalName );
75 $u->setId( $u->idFromName( $canonicalName ) );
80 * Factory method to fetch whichever use has a given email confirmation code.
81 * This code is generated when an account is created or its e-mail address
84 * If the code is invalid or has expired, returns NULL.
90 function newFromConfirmationCode( $code ) {
91 $dbr =& wfGetDB( DB_SLAVE
);
92 $name = $dbr->selectField( 'user', 'user_name', array(
93 'user_email_token' => md5( $code ),
94 'user_email_token_expires > ' . $dbr->addQuotes( $dbr->timestamp() ),
96 if( is_string( $name ) ) {
97 return User
::newFromName( $name );
104 * Serialze sleep function, for better cache efficiency and avoidance of
105 * silly "incomplete type" errors when skins are cached
108 return array( 'mId', 'mName', 'mPassword', 'mEmail', 'mNewtalk',
109 'mEmailAuthenticated', 'mRights', 'mOptions', 'mDataLoaded',
110 'mNewpassword', 'mBlockedby', 'mBlockreason', 'mTouched',
111 'mToken', 'mRealName', 'mHash', 'mGroups', 'mRegistration' );
115 * Get username given an id.
116 * @param integer $id Database user id
117 * @return string Nickname of a user
120 function whoIs( $id ) {
121 $dbr =& wfGetDB( DB_SLAVE
);
122 return $dbr->selectField( 'user', 'user_name', array( 'user_id' => $id ), 'User::whoIs' );
126 * Get real username given an id.
127 * @param integer $id Database user id
128 * @return string Realname of a user
131 function whoIsReal( $id ) {
132 $dbr =& wfGetDB( DB_SLAVE
);
133 return $dbr->selectField( 'user', 'user_real_name', array( 'user_id' => $id ), 'User::whoIsReal' );
137 * Get database id given a user name
138 * @param string $name Nickname of a user
139 * @return integer|null Database user id (null: if non existent
142 function idFromName( $name ) {
143 $fname = "User::idFromName";
145 $nt = Title
::newFromText( $name );
146 if( is_null( $nt ) ) {
150 $dbr =& wfGetDB( DB_SLAVE
);
151 $s = $dbr->selectRow( 'user', array( 'user_id' ), array( 'user_name' => $nt->getText() ), $fname );
153 if ( $s === false ) {
161 * does the string match an anonymous IPv4 address?
163 * Note: We match \d{1,3}\.\d{1,3}\.\d{1,3}\.xxx as an anonymous IP
164 * address because the usemod software would "cloak" anonymous IP
165 * addresses like this, if we allowed accounts like this to be created
166 * new users could get the old edits of these anonymous users.
171 * @param string $name Nickname of a user
174 function isIP( $name ) {
175 return preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.(?:xxx|\d{1,3})$/",$name);
176 /*return preg_match("/^
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]))\.
180 (?:[01]?\d{1,2}|2(:?[0-4]\d|5[0-5]))
185 * Is the input a valid username?
187 * Checks if the input is a valid username, we don't want an empty string,
188 * an IP address, anything that containins slashes (would mess up subpages),
189 * is longer than the maximum allowed username size or doesn't begin with
192 * @param string $name
196 function isValidUserName( $name ) {
197 global $wgContLang, $wgMaxNameChars;
200 || User
::isIP( $name )
201 ||
strpos( $name, '/' ) !== false
202 ||
strlen( $name ) > $wgMaxNameChars
203 ||
$name != $wgContLang->ucfirst( $name ) )
206 // Ensure that the name can't be misresolved as a different title,
207 // such as with extra namespace keys at the start.
208 $parsed = Title
::newFromText( $name );
209 if( is_null( $parsed )
210 ||
$parsed->getNamespace()
211 ||
strcmp( $name, $parsed->getPrefixedText() ) )
218 * Is the input a valid password?
220 * @param string $password
224 function isValidPassword( $password ) {
225 global $wgMinimalPasswordLength;
226 return strlen( $password ) >= $wgMinimalPasswordLength;
230 * Does the string match roughly an email address ?
232 * There used to be a regular expression here, it got removed because it
233 * rejected valid addresses. Actually just check if there is '@' somewhere
234 * in the given address.
236 * @todo Check for RFC 2822 compilance
239 * @param string $addr email address
243 function isValidEmailAddr ( $addr ) {
244 return ( trim( $addr ) != '' ) &&
245 (false !== strpos( $addr, '@' ) );
249 * Count the number of edits of a user
251 * @param int $uid The user ID to check
254 function edits( $uid ) {
255 $fname = 'User::edits';
257 $dbr =& wfGetDB( DB_SLAVE
);
258 return $dbr->selectField(
259 'revision', 'count(*)',
260 array( 'rev_user' => $uid ),
266 * probably return a random password
267 * @return string probably a random password
269 * @todo Check what is doing really [AV]
271 function randomPassword() {
272 global $wgMinimalPasswordLength;
273 $pwchars = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz';
274 $l = strlen( $pwchars ) - 1;
276 $pwlength = max( 7, $wgMinimalPasswordLength );
277 $digit = mt_rand(0, $pwlength - 1);
279 for ( $i = 0; $i < $pwlength; $i++
) {
280 $np .= $i == $digit ?
chr( mt_rand(48, 57) ) : $pwchars{ mt_rand(0, $l)};
286 * Set properties to default
287 * Used at construction. It will load per language default settings only
288 * if we have an available language object.
290 function loadDefaults() {
293 $fname = 'User::loadDefaults' . $n;
294 wfProfileIn( $fname );
296 global $wgContLang, $wgDBname;
297 global $wgNamespacesToBeSearchedDefault;
300 $this->mNewtalk
= -1;
301 $this->mName
= false;
302 $this->mRealName
= $this->mEmail
= '';
303 $this->mEmailAuthenticated
= null;
304 $this->mPassword
= $this->mNewpassword
= '';
305 $this->mRights
= array();
306 $this->mGroups
= array();
307 $this->mOptions
= User
::getDefaultOptions();
309 foreach( $wgNamespacesToBeSearchedDefault as $nsnum => $val ) {
310 $this->mOptions
['searchNs'.$nsnum] = $val;
312 unset( $this->mSkin
);
313 $this->mDataLoaded
= false;
314 $this->mBlockedby
= -1; # Unset
315 $this->setToken(); # Random
316 $this->mHash
= false;
318 if ( isset( $_COOKIE[$wgDBname.'LoggedOut'] ) ) {
319 $this->mTouched
= wfTimestamp( TS_MW
, $_COOKIE[$wgDBname.'LoggedOut'] );
322 $this->mTouched
= '0'; # Allow any pages to be cached
325 $this->mRegistration
= wfTimestamp( TS_MW
);
327 wfProfileOut( $fname );
331 * Combine the language default options with any site-specific options
332 * and add the default language variants.
338 function getDefaultOptions() {
340 * Site defaults will override the global/language defaults
342 global $wgContLang, $wgDefaultUserOptions;
343 $defOpt = $wgDefaultUserOptions +
$wgContLang->getDefaultUserOptions();
346 * default language setting
348 $variant = $wgContLang->getPreferredVariant();
349 $defOpt['variant'] = $variant;
350 $defOpt['language'] = $variant;
356 * Get a given default option value.
363 function getDefaultOption( $opt ) {
364 $defOpts = User
::getDefaultOptions();
365 if( isset( $defOpts[$opt] ) ) {
366 return $defOpts[$opt];
373 * Get blocking information
375 * @param bool $bFromSlave Specify whether to check slave or master. To improve performance,
376 * non-critical checks are done against slaves. Check when actually saving should be done against
379 function getBlockedStatus( $bFromSlave = true ) {
380 global $wgEnableSorbs, $wgProxyWhitelist;
382 if ( -1 != $this->mBlockedby
) {
383 wfDebug( "User::getBlockedStatus: already loaded.\n" );
387 $fname = 'User::getBlockedStatus';
388 wfProfileIn( $fname );
389 wfDebug( "$fname: checking...\n" );
391 $this->mBlockedby
= 0;
395 $block = new Block();
396 $block->fromMaster( !$bFromSlave );
397 if ( $block->load( $ip , $this->mId
) ) {
398 wfDebug( "$fname: Found block.\n" );
399 $this->mBlockedby
= $block->mBy
;
400 $this->mBlockreason
= $block->mReason
;
401 if ( $this->isLoggedIn() ) {
402 $this->spreadBlock();
405 wfDebug( "$fname: No block.\n" );
409 if ( !$this->isSysop() && !in_array( $ip, $wgProxyWhitelist ) ) {
412 if ( wfIsLocallyBlockedProxy( $ip ) ) {
413 $this->mBlockedby
= wfMsg( 'proxyblocker' );
414 $this->mBlockreason
= wfMsg( 'proxyblockreason' );
418 if ( !$this->mBlockedby
&& $wgEnableSorbs && !$this->getID() ) {
419 if ( $this->inSorbsBlacklist( $ip ) ) {
420 $this->mBlockedby
= wfMsg( 'sorbs' );
421 $this->mBlockreason
= wfMsg( 'sorbsreason' );
427 wfRunHooks( 'GetBlockedStatus', array( &$this ) );
429 wfProfileOut( $fname );
432 function inSorbsBlacklist( $ip ) {
433 global $wgEnableSorbs;
434 return $wgEnableSorbs &&
435 $this->inDnsBlacklist( $ip, 'http.dnsbl.sorbs.net.' );
438 function inOpmBlacklist( $ip ) {
440 return $wgEnableOpm &&
441 $this->inDnsBlacklist( $ip, 'opm.blitzed.org.' );
444 function inDnsBlacklist( $ip, $base ) {
445 $fname = 'User::inDnsBlacklist';
446 wfProfileIn( $fname );
451 if ( preg_match( '/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/', $ip, $m ) ) {
453 for ( $i=4; $i>=1; $i-- ) {
454 $host .= $m[$i] . '.';
459 $ipList = gethostbynamel( $host );
462 wfDebug( "Hostname $host is {$ipList[0]}, it's a proxy says $base!\n" );
465 wfDebug( "Requested $host, not found in $base.\n" );
469 wfProfileOut( $fname );
474 * Primitive rate limits: enforce maximum actions per time period
475 * to put a brake on flooding.
477 * Note: when using a shared cache like memcached, IP-address
478 * last-hit counters will be shared across wikis.
480 * @return bool true if a rate limiter was tripped
483 function pingLimiter( $action='edit' ) {
484 global $wgRateLimits;
485 if( !isset( $wgRateLimits[$action] ) ) {
488 if( $this->isAllowed( 'delete' ) ) {
493 global $wgMemc, $wgDBname, $wgRateLimitLog;
494 $fname = 'User::pingLimiter';
495 wfProfileIn( $fname );
497 $limits = $wgRateLimits[$action];
499 $id = $this->getId();
502 if( isset( $limits['anon'] ) && $id == 0 ) {
503 $keys["$wgDBname:limiter:$action:anon"] = $limits['anon'];
506 if( isset( $limits['user'] ) && $id != 0 ) {
507 $keys["$wgDBname:limiter:$action:user:$id"] = $limits['user'];
509 if( $this->isNewbie() ) {
510 if( isset( $limits['newbie'] ) && $id != 0 ) {
511 $keys["$wgDBname:limiter:$action:user:$id"] = $limits['newbie'];
513 if( isset( $limits['ip'] ) ) {
514 $keys["mediawiki:limiter:$action:ip:$ip"] = $limits['ip'];
516 if( isset( $limits['subnet'] ) && preg_match( '/^(\d+\.\d+\.\d+)\.\d+$/', $ip, $matches ) ) {
517 $subnet = $matches[1];
518 $keys["mediawiki:limiter:$action:subnet:$subnet"] = $limits['subnet'];
523 foreach( $keys as $key => $limit ) {
524 list( $max, $period ) = $limit;
525 $summary = "(limit $max in {$period}s)";
526 $count = $wgMemc->get( $key );
528 if( $count > $max ) {
529 wfDebug( "$fname: tripped! $key at $count $summary\n" );
530 if( $wgRateLimitLog ) {
531 @error_log
( wfTimestamp( TS_MW
) . ' ' . $wgDBname . ': ' . $this->getName() . " tripped $key at $count $summary\n", 3, $wgRateLimitLog );
535 wfDebug( "$fname: ok. $key at $count $summary\n" );
538 wfDebug( "$fname: adding record for $key $summary\n" );
539 $wgMemc->add( $key, 1, intval( $period ) );
541 $wgMemc->incr( $key );
544 wfProfileOut( $fname );
549 * Check if user is blocked
550 * @return bool True if blocked, false otherwise
552 function isBlocked( $bFromSlave = true ) { // hacked from false due to horrible probs on site
553 wfDebug( "User::isBlocked: enter\n" );
554 $this->getBlockedStatus( $bFromSlave );
555 return $this->mBlockedby
!== 0;
559 * Check if user is blocked from editing a particular article
561 function isBlockedFrom( $title, $bFromSlave = false ) {
562 global $wgBlockAllowsUTEdit;
563 $fname = 'User::isBlockedFrom';
564 wfProfileIn( $fname );
565 wfDebug( "$fname: enter\n" );
567 if ( $wgBlockAllowsUTEdit && $title->getText() === $this->getName() &&
568 $title->getNamespace() == NS_USER_TALK
)
571 wfDebug( "$fname: self-talk page, ignoring any blocks\n" );
573 wfDebug( "$fname: asking isBlocked()\n" );
574 $blocked = $this->isBlocked( $bFromSlave );
576 wfProfileOut( $fname );
581 * Get name of blocker
582 * @return string name of blocker
584 function blockedBy() {
585 $this->getBlockedStatus();
586 return $this->mBlockedby
;
590 * Get blocking reason
591 * @return string Blocking reason
593 function blockedFor() {
594 $this->getBlockedStatus();
595 return $this->mBlockreason
;
599 * Initialise php session
601 function SetupSession() {
602 global $wgSessionsInMemcached, $wgCookiePath, $wgCookieDomain;
603 if( $wgSessionsInMemcached ) {
604 require_once( 'MemcachedSessions.php' );
605 } elseif( 'files' != ini_get( 'session.save_handler' ) ) {
606 # If it's left on 'user' or another setting from another
607 # application, it will end up failing. Try to recover.
608 ini_set ( 'session.save_handler', 'files' );
610 session_set_cookie_params( 0, $wgCookiePath, $wgCookieDomain );
611 session_cache_limiter( 'private, must-revalidate' );
616 * Create a new user object using data from session
619 function loadFromSession() {
620 global $wgMemc, $wgDBname;
622 if ( isset( $_SESSION['wsUserID'] ) ) {
623 if ( 0 != $_SESSION['wsUserID'] ) {
624 $sId = $_SESSION['wsUserID'];
628 } else if ( isset( $_COOKIE["{$wgDBname}UserID"] ) ) {
629 $sId = intval( $_COOKIE["{$wgDBname}UserID"] );
630 $_SESSION['wsUserID'] = $sId;
634 if ( isset( $_SESSION['wsUserName'] ) ) {
635 $sName = $_SESSION['wsUserName'];
636 } else if ( isset( $_COOKIE["{$wgDBname}UserName"] ) ) {
637 $sName = $_COOKIE["{$wgDBname}UserName"];
638 $_SESSION['wsUserName'] = $sName;
643 $passwordCorrect = FALSE;
644 $user = $wgMemc->get( $key = "$wgDBname:user:id:$sId" );
645 if( !is_object( $user ) ||
$user->mVersion
< MW_USER_VERSION
) {
646 # Expire old serialized objects; they may be corrupt.
649 if($makenew = !$user) {
650 wfDebug( "User::loadFromSession() unable to load from memcached\n" );
653 $user->loadFromDatabase();
655 wfDebug( "User::loadFromSession() got from cache!\n" );
658 if ( isset( $_SESSION['wsToken'] ) ) {
659 $passwordCorrect = $_SESSION['wsToken'] == $user->mToken
;
660 } else if ( isset( $_COOKIE["{$wgDBname}Token"] ) ) {
661 $passwordCorrect = $user->mToken
== $_COOKIE["{$wgDBname}Token"];
663 return new User(); # Can't log in from session
666 if ( ( $sName == $user->mName
) && $passwordCorrect ) {
668 if($wgMemc->set( $key, $user ))
669 wfDebug( "User::loadFromSession() successfully saved user\n" );
671 wfDebug( "User::loadFromSession() unable to save to memcached\n" );
675 return new User(); # Can't log in from session
679 * Load a user from the database
681 function loadFromDatabase() {
682 $fname = "User::loadFromDatabase";
684 # Counter-intuitive, breaks various things, use User::setLoaded() if you want to suppress
685 # loading in a command line script, don't assume all command line scripts need it like this
686 #if ( $this->mDataLoaded || $wgCommandLineMode ) {
687 if ( $this->mDataLoaded
) {
692 $this->mId
= intval( $this->mId
);
694 /** Anonymous user */
697 $this->mRights
= $this->getGroupPermissions( array( '*' ) );
698 $this->mDataLoaded
= true;
700 } # the following stuff is for non-anonymous users only
702 $dbr =& wfGetDB( DB_SLAVE
);
703 $s = $dbr->selectRow( 'user', array( 'user_name','user_password','user_newpassword','user_email',
704 'user_email_authenticated',
705 'user_real_name','user_options','user_touched', 'user_token', 'user_registration' ),
706 array( 'user_id' => $this->mId
), $fname );
708 if ( $s !== false ) {
709 $this->mName
= $s->user_name
;
710 $this->mEmail
= $s->user_email
;
711 $this->mEmailAuthenticated
= wfTimestampOrNull( TS_MW
, $s->user_email_authenticated
);
712 $this->mRealName
= $s->user_real_name
;
713 $this->mPassword
= $s->user_password
;
714 $this->mNewpassword
= $s->user_newpassword
;
715 $this->decodeOptions( $s->user_options
);
716 $this->mTouched
= wfTimestamp(TS_MW
,$s->user_touched
);
717 $this->mToken
= $s->user_token
;
718 $this->mRegistration
= wfTimestampOrNull( TS_MW
, $s->user_registration
);
720 $res = $dbr->select( 'user_groups',
722 array( 'ug_user' => $this->mId
),
724 $this->mGroups
= array();
725 while( $row = $dbr->fetchObject( $res ) ) {
726 $this->mGroups
[] = $row->ug_group
;
728 $implicitGroups = array( '*', 'user' );
730 global $wgAutoConfirmAge;
731 $accountAge = time() - wfTimestampOrNull( TS_UNIX
, $this->mRegistration
);
732 if( $accountAge >= $wgAutoConfirmAge ) {
733 $implicitGroups[] = 'autoconfirmed';
736 $effectiveGroups = array_merge( $implicitGroups, $this->mGroups
);
737 $this->mRights
= $this->getGroupPermissions( $effectiveGroups );
740 $this->mDataLoaded
= true;
743 function getID() { return $this->mId
; }
744 function setID( $v ) {
746 $this->mDataLoaded
= false;
750 $this->loadFromDatabase();
751 if ( $this->mName
=== false ) {
752 $this->mName
= wfGetIP();
757 function setName( $str ) {
758 $this->loadFromDatabase();
764 * Return the title dbkey form of the name, for eg user pages.
768 function getTitleKey() {
769 return str_replace( ' ', '_', $this->getName() );
772 function getNewtalk() {
773 $this->loadFromDatabase();
775 # Load the newtalk status if it is unloaded (mNewtalk=-1)
776 if( $this->mNewtalk
=== -1 ) {
777 $this->mNewtalk
= false; # reset talk page status
779 # Check memcached separately for anons, who have no
780 # entire User object stored in there.
782 global $wgDBname, $wgMemc;
783 $key = "$wgDBname:newtalk:ip:" . $this->getName();
784 $newtalk = $wgMemc->get( $key );
785 if( is_integer( $newtalk ) ) {
786 $this->mNewtalk
= (bool)$newtalk;
788 $this->mNewtalk
= $this->checkNewtalk( 'user_ip', $this->getName() );
789 $wgMemc->set( $key, $this->mNewtalk
, time() ); // + 1800 );
792 $this->mNewtalk
= $this->checkNewtalk( 'user_id', $this->mId
);
796 return (bool)$this->mNewtalk
;
800 * Perform a user_newtalk check on current slaves; if the memcached data
801 * is funky we don't want newtalk state to get stuck on save, as that's
804 * @param string $field
809 function checkNewtalk( $field, $id ) {
810 $fname = 'User::checkNewtalk';
811 $dbr =& wfGetDB( DB_SLAVE
);
812 $ok = $dbr->selectField( 'user_newtalk', $field,
813 array( $field => $id ), $fname );
814 return $ok !== false;
819 * @param string $field
823 function updateNewtalk( $field, $id ) {
824 $fname = 'User::updateNewtalk';
825 if( $this->checkNewtalk( $field, $id ) ) {
826 wfDebug( "$fname already set ($field, $id), ignoring\n" );
829 $dbw =& wfGetDB( DB_MASTER
);
830 $dbw->insert( 'user_newtalk',
831 array( $field => $id ),
834 wfDebug( "$fname: set on ($field, $id)\n" );
839 * Clear the new messages flag for the given user
840 * @param string $field
844 function deleteNewtalk( $field, $id ) {
845 $fname = 'User::deleteNewtalk';
846 if( !$this->checkNewtalk( $field, $id ) ) {
847 wfDebug( "$fname: already gone ($field, $id), ignoring\n" );
850 $dbw =& wfGetDB( DB_MASTER
);
851 $dbw->delete( 'user_newtalk',
852 array( $field => $id ),
854 wfDebug( "$fname: killed on ($field, $id)\n" );
859 * Update the 'You have new messages!' status.
862 function setNewtalk( $val ) {
867 $this->loadFromDatabase();
868 $this->mNewtalk
= $val;
870 $fname = 'User::setNewtalk';
872 if( $this->isAnon() ) {
874 $id = $this->getName();
877 $id = $this->getId();
881 $changed = $this->updateNewtalk( $field, $id );
883 $changed = $this->deleteNewtalk( $field, $id );
887 if( $this->isAnon() ) {
888 // Anons have a separate memcached space, since
889 // user records aren't kept for them.
890 global $wgDBname, $wgMemc;
891 $key = "$wgDBname:newtalk:ip:$value";
892 $wgMemc->set( $key, $val ?
1 : 0 );
895 // Make sure the user page is watched, so a notification
896 // will be sent out if enabled.
897 $this->addWatch( $this->getTalkPage() );
900 $this->invalidateCache();
901 $this->saveSettings();
905 function invalidateCache() {
906 global $wgClockSkewFudge;
907 $this->loadFromDatabase();
908 $this->mTouched
= wfTimestamp(TS_MW
, time() +
$wgClockSkewFudge );
909 # Don't forget to save the options after this or
910 # it won't take effect!
913 function validateCache( $timestamp ) {
914 $this->loadFromDatabase();
915 return ($timestamp >= $this->mTouched
);
919 * Encrypt a password.
920 * It can eventuall salt a password @see User::addSalt()
921 * @param string $p clear Password.
922 * @return string Encrypted password.
924 function encryptPassword( $p ) {
925 return wfEncryptPassword( $this->mId
, $p );
928 # Set the password and reset the random token
929 function setPassword( $str ) {
930 $this->loadFromDatabase();
932 $this->mPassword
= $this->encryptPassword( $str );
933 $this->mNewpassword
= '';
936 # Set the random token (used for persistent authentication)
937 function setToken( $token = false ) {
938 global $wgSecretKey, $wgProxyKey, $wgDBname;
940 if ( $wgSecretKey ) {
942 } elseif ( $wgProxyKey ) {
947 $this->mToken
= md5( $key . mt_rand( 0, 0x7fffffff ) . $wgDBname . $this->mId
);
949 $this->mToken
= $token;
954 function setCookiePassword( $str ) {
955 $this->loadFromDatabase();
956 $this->mCookiePassword
= md5( $str );
959 function setNewpassword( $str ) {
960 $this->loadFromDatabase();
961 $this->mNewpassword
= $this->encryptPassword( $str );
964 function getEmail() {
965 $this->loadFromDatabase();
966 return $this->mEmail
;
969 function getEmailAuthenticationTimestamp() {
970 $this->loadFromDatabase();
971 return $this->mEmailAuthenticated
;
974 function setEmail( $str ) {
975 $this->loadFromDatabase();
976 $this->mEmail
= $str;
979 function getRealName() {
980 $this->loadFromDatabase();
981 return $this->mRealName
;
984 function setRealName( $str ) {
985 $this->loadFromDatabase();
986 $this->mRealName
= $str;
989 function getOption( $oname ) {
990 $this->loadFromDatabase();
991 if ( array_key_exists( $oname, $this->mOptions
) ) {
992 return trim( $this->mOptions
[$oname] );
998 function setOption( $oname, $val ) {
999 $this->loadFromDatabase();
1000 if ( $oname == 'skin' ) {
1001 # Clear cached skin, so the new one displays immediately in Special:Preferences
1002 unset( $this->mSkin
);
1004 $this->mOptions
[$oname] = $val;
1005 $this->invalidateCache();
1008 function getRights() {
1009 $this->loadFromDatabase();
1010 return $this->mRights
;
1014 * Get the list of explicit group memberships this user has.
1015 * The implicit * and user groups are not included.
1016 * @return array of strings
1018 function getGroups() {
1019 $this->loadFromDatabase();
1020 return $this->mGroups
;
1024 * Get the list of implicit group memberships this user has.
1025 * This includes all explicit groups, plus 'user' if logged in
1026 * and '*' for all accounts.
1027 * @return array of strings
1029 function getEffectiveGroups() {
1030 $base = array( '*' );
1031 if( $this->isLoggedIn() ) {
1034 return array_merge( $base, $this->getGroups() );
1038 * Add the user to the given group.
1039 * This takes immediate effect.
1042 function addGroup( $group ) {
1043 $dbw =& wfGetDB( DB_MASTER
);
1044 $dbw->insert( 'user_groups',
1046 'ug_user' => $this->getID(),
1047 'ug_group' => $group,
1050 array( 'IGNORE' ) );
1052 $this->mGroups
= array_merge( $this->mGroups
, array( $group ) );
1053 $this->mRights
= User
::getGroupPermissions( $this->getEffectiveGroups() );
1055 $this->invalidateCache();
1056 $this->saveSettings();
1060 * Remove the user from the given group.
1061 * This takes immediate effect.
1064 function removeGroup( $group ) {
1065 $dbw =& wfGetDB( DB_MASTER
);
1066 $dbw->delete( 'user_groups',
1068 'ug_user' => $this->getID(),
1069 'ug_group' => $group,
1071 'User::removeGroup' );
1073 $this->mGroups
= array_diff( $this->mGroups
, array( $group ) );
1074 $this->mRights
= User
::getGroupPermissions( $this->getEffectiveGroups() );
1076 $this->invalidateCache();
1077 $this->saveSettings();
1082 * A more legible check for non-anonymousness.
1083 * Returns true if the user is not an anonymous visitor.
1087 function isLoggedIn() {
1088 return( $this->getID() != 0 );
1092 * A more legible check for anonymousness.
1093 * Returns true if the user is an anonymous visitor.
1098 return !$this->isLoggedIn();
1102 * Check if a user is sysop
1105 function isSysop() {
1106 return $this->isAllowed( 'protect' );
1110 function isDeveloper() {
1111 return $this->isAllowed( 'siteadmin' );
1115 function isBureaucrat() {
1116 return $this->isAllowed( 'makesysop' );
1120 * Whether the user is a bot
1121 * @todo need to be migrated to the new user level management sytem
1124 $this->loadFromDatabase();
1125 return in_array( 'bot', $this->mRights
);
1129 * Check if user is allowed to access a feature / make an action
1130 * @param string $action Action to be checked (see $wgAvailableRights in Defines.php for possible actions).
1131 * @return boolean True: action is allowed, False: action should not be allowed
1133 function isAllowed($action='') {
1134 if ( $action === '' )
1135 // In the spirit of DWIM
1138 $this->loadFromDatabase();
1139 return in_array( $action , $this->mRights
);
1143 * Load a skin if it doesn't exist or return it
1144 * @todo FIXME : need to check the old failback system [AV]
1146 function &getSkin() {
1147 global $IP, $wgRequest;
1148 if ( ! isset( $this->mSkin
) ) {
1149 $fname = 'User::getSkin';
1150 wfProfileIn( $fname );
1152 # get all skin names available
1153 $skinNames = Skin
::getSkinNames();
1156 $userSkin = $this->getOption( 'skin' );
1157 $userSkin = $wgRequest->getVal('useskin', $userSkin);
1159 $this->mSkin
=& Skin
::newFromKey( $userSkin );
1160 wfProfileOut( $fname );
1162 return $this->mSkin
;
1166 * @param string $title Article title to look at
1170 * Check watched status of an article
1171 * @return bool True if article is watched
1173 function isWatched( $title ) {
1174 $wl = WatchedItem
::fromUserTitle( $this, $title );
1175 return $wl->isWatched();
1181 function addWatch( $title ) {
1182 $wl = WatchedItem
::fromUserTitle( $this, $title );
1184 $this->invalidateCache();
1188 * Stop watching an article
1190 function removeWatch( $title ) {
1191 $wl = WatchedItem
::fromUserTitle( $this, $title );
1193 $this->invalidateCache();
1197 * Clear the user's notification timestamp for the given title.
1198 * If e-notif e-mails are on, they will receive notification mails on
1199 * the next change of the page if it's watched etc.
1201 function clearNotification( &$title ) {
1202 global $wgUser, $wgUseEnotif;
1204 if ($title->getNamespace() == NS_USER_TALK
&&
1205 $title->getText() == $this->getName() ) {
1206 $this->setNewtalk( false );
1209 if( !$wgUseEnotif ) {
1213 if( $this->isAnon() ) {
1214 // Nothing else to do...
1218 // Only update the timestamp if the page is being watched.
1219 // The query to find out if it is watched is cached both in memcached and per-invocation,
1220 // and when it does have to be executed, it can be on a slave
1221 // If this is the user's newtalk page, we always update the timestamp
1222 if ($title->getNamespace() == NS_USER_TALK
&&
1223 $title->getText() == $wgUser->getName())
1226 } elseif ( $this->getID() == $wgUser->getID() ) {
1227 $watched = $title->userIsWatching();
1232 // If the page is watched by the user (or may be watched), update the timestamp on any
1233 // any matching rows
1235 $dbw =& wfGetDB( DB_MASTER
);
1236 $success = $dbw->update( 'watchlist',
1238 'wl_notificationtimestamp' => NULL
1239 ), array( /* WHERE */
1240 'wl_title' => $title->getDBkey(),
1241 'wl_namespace' => $title->getNamespace(),
1242 'wl_user' => $this->getID()
1243 ), 'User::clearLastVisited'
1251 * Resets all of the given user's page-change notification timestamps.
1252 * If e-notif e-mails are on, they will receive notification mails on
1253 * the next change of any watched page.
1255 * @param int $currentUser user ID number
1258 function clearAllNotifications( $currentUser ) {
1259 global $wgUseEnotif;
1260 if ( !$wgUseEnotif ) {
1261 $this->setNewtalk( false );
1264 if( $currentUser != 0 ) {
1266 $dbw =& wfGetDB( DB_MASTER
);
1267 $success = $dbw->update( 'watchlist',
1269 'wl_notificationtimestamp' => 0
1270 ), array( /* WHERE */
1271 'wl_user' => $currentUser
1272 ), 'UserMailer::clearAll'
1275 # we also need to clear here the "you have new message" notification for the own user_talk page
1276 # This is cleared one page view later in Article::viewUpdates();
1282 * @return string Encoding options
1284 function encodeOptions() {
1286 foreach ( $this->mOptions
as $oname => $oval ) {
1287 array_push( $a, $oname.'='.$oval );
1289 $s = implode( "\n", $a );
1296 function decodeOptions( $str ) {
1297 $a = explode( "\n", $str );
1298 foreach ( $a as $s ) {
1299 if ( preg_match( "/^(.[^=]*)=(.*)$/", $s, $m ) ) {
1300 $this->mOptions
[$m[1]] = $m[2];
1305 function setCookies() {
1306 global $wgCookieExpiration, $wgCookiePath, $wgCookieDomain, $wgCookieSecure, $wgDBname;
1307 if ( 0 == $this->mId
) return;
1308 $this->loadFromDatabase();
1309 $exp = time() +
$wgCookieExpiration;
1311 $_SESSION['wsUserID'] = $this->mId
;
1312 setcookie( $wgDBname.'UserID', $this->mId
, $exp, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
1314 $_SESSION['wsUserName'] = $this->getName();
1315 setcookie( $wgDBname.'UserName', $this->getName(), $exp, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
1317 $_SESSION['wsToken'] = $this->mToken
;
1318 if ( 1 == $this->getOption( 'rememberpassword' ) ) {
1319 setcookie( $wgDBname.'Token', $this->mToken
, $exp, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
1321 setcookie( $wgDBname.'Token', '', time() - 3600 );
1327 * It will clean the session cookie
1330 global $wgCookiePath, $wgCookieDomain, $wgCookieSecure, $wgDBname;
1331 $this->loadDefaults();
1332 $this->setLoaded( true );
1334 $_SESSION['wsUserID'] = 0;
1336 setcookie( $wgDBname.'UserID', '', time() - 3600, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
1337 setcookie( $wgDBname.'Token', '', time() - 3600, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
1339 # Remember when user logged out, to prevent seeing cached pages
1340 setcookie( $wgDBname.'LoggedOut', wfTimestampNow(), time() +
86400, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
1344 * Save object settings into database
1346 function saveSettings() {
1347 global $wgMemc, $wgDBname, $wgUseEnotif;
1348 $fname = 'User::saveSettings';
1350 if ( wfReadOnly() ) { return; }
1351 if ( 0 == $this->mId
) { return; }
1353 $dbw =& wfGetDB( DB_MASTER
);
1354 $dbw->update( 'user',
1356 'user_name' => $this->mName
,
1357 'user_password' => $this->mPassword
,
1358 'user_newpassword' => $this->mNewpassword
,
1359 'user_real_name' => $this->mRealName
,
1360 'user_email' => $this->mEmail
,
1361 'user_email_authenticated' => $dbw->timestampOrNull( $this->mEmailAuthenticated
),
1362 'user_options' => $this->encodeOptions(),
1363 'user_touched' => $dbw->timestamp($this->mTouched
),
1364 'user_token' => $this->mToken
1365 ), array( /* WHERE */
1366 'user_id' => $this->mId
1369 $wgMemc->delete( "$wgDBname:user:id:$this->mId" );
1374 * Checks if a user with the given name exists, returns the ID
1376 function idForName() {
1377 $fname = 'User::idForName';
1380 $s = trim( $this->getName() );
1381 if ( 0 == strcmp( '', $s ) ) return 0;
1383 $dbr =& wfGetDB( DB_SLAVE
);
1384 $id = $dbr->selectField( 'user', 'user_id', array( 'user_name' => $s ), $fname );
1385 if ( $id === false ) {
1392 * Add user object to the database
1394 function addToDatabase() {
1395 $fname = 'User::addToDatabase';
1396 $dbw =& wfGetDB( DB_MASTER
);
1397 $seqVal = $dbw->nextSequenceValue( 'user_user_id_seq' );
1398 $dbw->insert( 'user',
1400 'user_id' => $seqVal,
1401 'user_name' => $this->mName
,
1402 'user_password' => $this->mPassword
,
1403 'user_newpassword' => $this->mNewpassword
,
1404 'user_email' => $this->mEmail
,
1405 'user_email_authenticated' => $dbw->timestampOrNull( $this->mEmailAuthenticated
),
1406 'user_real_name' => $this->mRealName
,
1407 'user_options' => $this->encodeOptions(),
1408 'user_token' => $this->mToken
,
1409 'user_registration' => $dbw->timestamp( $this->mRegistration
),
1412 $this->mId
= $dbw->insertId();
1415 function spreadBlock() {
1416 # If the (non-anonymous) user is blocked, this function will block any IP address
1417 # that they successfully log on from.
1418 $fname = 'User::spreadBlock';
1420 wfDebug( "User:spreadBlock()\n" );
1421 if ( $this->mId
== 0 ) {
1425 $userblock = Block
::newFromDB( '', $this->mId
);
1426 if ( !$userblock->isValid() ) {
1430 # Check if this IP address is already blocked
1431 $ipblock = Block
::newFromDB( wfGetIP() );
1432 if ( $ipblock->isValid() ) {
1433 # If the user is already blocked. Then check if the autoblock would
1434 # excede the user block. If it would excede, then do nothing, else
1435 # prolong block time
1436 if ($userblock->mExpiry
&&
1437 ($userblock->mExpiry
< Block
::getAutoblockExpiry($ipblock->mTimestamp
))) {
1440 # Just update the timestamp
1441 $ipblock->updateTimestamp();
1445 # Make a new block object with the desired properties
1446 wfDebug( "Autoblocking {$this->mName}@" . wfGetIP() . "\n" );
1447 $ipblock->mAddress
= wfGetIP();
1448 $ipblock->mUser
= 0;
1449 $ipblock->mBy
= $userblock->mBy
;
1450 $ipblock->mReason
= wfMsg( 'autoblocker', $this->getName(), $userblock->mReason
);
1451 $ipblock->mTimestamp
= wfTimestampNow();
1452 $ipblock->mAuto
= 1;
1453 # If the user is already blocked with an expiry date, we don't
1454 # want to pile on top of that!
1455 if($userblock->mExpiry
) {
1456 $ipblock->mExpiry
= min ( $userblock->mExpiry
, Block
::getAutoblockExpiry( $ipblock->mTimestamp
));
1458 $ipblock->mExpiry
= Block
::getAutoblockExpiry( $ipblock->mTimestamp
);
1467 * Generate a string which will be different for any combination of
1468 * user options which would produce different parser output.
1469 * This will be used as part of the hash key for the parser cache,
1470 * so users will the same options can share the same cached data
1473 * Extensions which require it should install 'PageRenderingHash' hook,
1474 * which will give them a chance to modify this key based on their own
1479 function getPageRenderingHash() {
1482 return $this->mHash
;
1485 // stubthreshold is only included below for completeness,
1486 // it will always be 0 when this function is called by parsercache.
1488 $confstr = $this->getOption( 'math' );
1489 $confstr .= '!' . $this->getOption( 'stubthreshold' );
1490 $confstr .= '!' . $this->getOption( 'date' );
1491 $confstr .= '!' . ($this->getOption( 'numberheadings' ) ?
'1' : '');
1492 $confstr .= '!' . $this->getOption( 'language' );
1493 $confstr .= '!' . $this->getOption( 'thumbsize' );
1494 // add in language specific options, if any
1495 $extra = $wgContLang->getExtraHashOptions();
1498 // Give a chance for extensions to modify the hash, if they have
1499 // extra options or other effects on the parser cache.
1500 wfRunHooks( 'PageRenderingHash', array( &$confstr ) );
1502 $this->mHash
= $confstr;
1506 function isAllowedToCreateAccount() {
1507 return $this->isAllowed( 'createaccount' ) && !$this->isBlocked();
1511 * Set mDataLoaded, return previous value
1512 * Use this to prevent DB access in command-line scripts or similar situations
1514 function setLoaded( $loaded ) {
1515 return wfSetVar( $this->mDataLoaded
, $loaded );
1519 * Get this user's personal page title.
1524 function getUserPage() {
1525 return Title
::makeTitle( NS_USER
, $this->getName() );
1529 * Get this user's talk page title.
1534 function getTalkPage() {
1535 $title = $this->getUserPage();
1536 return $title->getTalkPage();
1542 function getMaxID() {
1543 static $res; // cache
1545 if ( isset( $res ) )
1548 $dbr =& wfGetDB( DB_SLAVE
);
1549 return $res = $dbr->selectField( 'user', 'max(user_id)', false, 'User::getMaxID' );
1554 * Determine whether the user is a newbie. Newbies are either
1555 * anonymous IPs, or the most recently created accounts.
1556 * @return bool True if it is a newbie.
1558 function isNewbie() {
1559 return !$this->isAllowed( 'autoconfirmed' );
1563 * Check to see if the given clear-text password is one of the accepted passwords
1564 * @param string $password User password.
1565 * @return bool True if the given password is correct otherwise False.
1567 function checkPassword( $password ) {
1568 global $wgAuth, $wgMinimalPasswordLength;
1569 $this->loadFromDatabase();
1571 // Even though we stop people from creating passwords that
1572 // are shorter than this, doesn't mean people wont be able
1573 // to. Certain authentication plugins do NOT want to save
1574 // domain passwords in a mysql database, so we should
1575 // check this (incase $wgAuth->strict() is false).
1576 if( strlen( $password ) < $wgMinimalPasswordLength ) {
1580 if( $wgAuth->authenticate( $this->getName(), $password ) ) {
1582 } elseif( $wgAuth->strict() ) {
1583 /* Auth plugin doesn't allow local authentication */
1586 $ep = $this->encryptPassword( $password );
1587 if ( 0 == strcmp( $ep, $this->mPassword
) ) {
1589 } elseif ( ($this->mNewpassword
!= '') && (0 == strcmp( $ep, $this->mNewpassword
)) ) {
1591 } elseif ( function_exists( 'iconv' ) ) {
1592 # Some wikis were converted from ISO 8859-1 to UTF-8, the passwords can't be converted
1593 # Check for this with iconv
1594 $cp1252hash = $this->encryptPassword( iconv( 'UTF-8', 'WINDOWS-1252', $password ) );
1595 if ( 0 == strcmp( $cp1252hash, $this->mPassword
) ) {
1603 * Initialize (if necessary) and return a session token value
1604 * which can be used in edit forms to show that the user's
1605 * login credentials aren't being hijacked with a foreign form
1608 * @param mixed $salt - Optional function-specific data for hash.
1609 * Use a string or an array of strings.
1613 function editToken( $salt = '' ) {
1614 if( !isset( $_SESSION['wsEditToken'] ) ) {
1615 $token = $this->generateToken();
1616 $_SESSION['wsEditToken'] = $token;
1618 $token = $_SESSION['wsEditToken'];
1620 if( is_array( $salt ) ) {
1621 $salt = implode( '|', $salt );
1623 return md5( $token . $salt );
1627 * Generate a hex-y looking random token for various uses.
1628 * Could be made more cryptographically sure if someone cares.
1631 function generateToken( $salt = '' ) {
1632 $token = dechex( mt_rand() ) . dechex( mt_rand() );
1633 return md5( $token . $salt );
1637 * Check given value against the token value stored in the session.
1638 * A match should confirm that the form was submitted from the
1639 * user's own login session, not a form submission from a third-party
1642 * @param string $val - the input value to compare
1643 * @param string $salt - Optional function-specific data for hash
1647 function matchEditToken( $val, $salt = '' ) {
1651 if ( !isset( $_SESSION['wsEditToken'] ) ) {
1652 $logfile = '/home/wikipedia/logs/session_debug/session.log';
1653 $mckey = memsess_key( session_id() );
1654 $uname = @posix_uname();
1655 $msg = "wsEditToken not set!\n" .
1656 'apache server=' . $uname['nodename'] . "\n" .
1657 'session_id = ' . session_id() . "\n" .
1658 '$_SESSION=' . var_export( $_SESSION, true ) . "\n" .
1659 '$_COOKIE=' . var_export( $_COOKIE, true ) . "\n" .
1660 "mc get($mckey) = " . var_export( $wgMemc->get( $mckey ), true ) . "\n\n\n";
1662 @error_log( $msg, 3, $logfile );
1665 return ( $val == $this->editToken( $salt ) );
1669 * Generate a new e-mail confirmation token and send a confirmation
1670 * mail to the user's given address.
1672 * @return mixed True on success, a WikiError object on failure.
1674 function sendConfirmationMail() {
1676 $url = $this->confirmationTokenUrl( $expiration );
1677 return $this->sendMail( wfMsg( 'confirmemail_subject' ),
1678 wfMsg( 'confirmemail_body',
1682 $wgContLang->timeanddate( $expiration, false ) ) );
1686 * Send an e-mail to this user's account. Does not check for
1687 * confirmed status or validity.
1689 * @param string $subject
1690 * @param string $body
1691 * @param strong $from Optional from address; default $wgPasswordSender will be used otherwise.
1692 * @return mixed True on success, a WikiError object on failure.
1694 function sendMail( $subject, $body, $from = null ) {
1695 if( is_null( $from ) ) {
1696 global $wgPasswordSender;
1697 $from = $wgPasswordSender;
1700 require_once( 'UserMailer.php' );
1701 $to = new MailAddress( $this );
1702 $sender = new MailAddress( $from );
1703 $error = userMailer( $to, $sender, $subject, $body );
1705 if( $error == '' ) {
1708 return new WikiError( $error );
1713 * Generate, store, and return a new e-mail confirmation code.
1714 * A hash (unsalted since it's used as a key) is stored.
1715 * @param &$expiration mixed output: accepts the expiration time
1719 function confirmationToken( &$expiration ) {
1720 $fname = 'User::confirmationToken';
1723 $expires = $now +
7 * 24 * 60 * 60;
1724 $expiration = wfTimestamp( TS_MW
, $expires );
1726 $token = $this->generateToken( $this->mId
. $this->mEmail
. $expires );
1727 $hash = md5( $token );
1729 $dbw =& wfGetDB( DB_MASTER
);
1730 $dbw->update( 'user',
1731 array( 'user_email_token' => $hash,
1732 'user_email_token_expires' => $dbw->timestamp( $expires ) ),
1733 array( 'user_id' => $this->mId
),
1740 * Generate and store a new e-mail confirmation token, and return
1741 * the URL the user can use to confirm.
1742 * @param &$expiration mixed output: accepts the expiration time
1746 function confirmationTokenUrl( &$expiration ) {
1747 $token = $this->confirmationToken( $expiration );
1748 $title = Title
::makeTitle( NS_SPECIAL
, 'Confirmemail/' . $token );
1749 return $title->getFullUrl();
1753 * Mark the e-mail address confirmed and save.
1755 function confirmEmail() {
1756 $this->loadFromDatabase();
1757 $this->mEmailAuthenticated
= wfTimestampNow();
1758 $this->saveSettings();
1763 * Is this user allowed to send e-mails within limits of current
1764 * site configuration?
1767 function canSendEmail() {
1768 return $this->isEmailConfirmed();
1772 * Is this user allowed to receive e-mails within limits of current
1773 * site configuration?
1776 function canReceiveEmail() {
1777 return $this->canSendEmail() && !$this->getOption( 'disablemail' );
1781 * Is this user's e-mail address valid-looking and confirmed within
1782 * limits of the current site configuration?
1784 * If $wgEmailAuthentication is on, this may require the user to have
1785 * confirmed their address by returning a code or using a password
1786 * sent to the address from the wiki.
1790 function isEmailConfirmed() {
1791 global $wgEmailAuthentication;
1792 $this->loadFromDatabase();
1793 if( $this->isAnon() )
1795 if( !$this->isValidEmailAddr( $this->mEmail
) )
1797 if( $wgEmailAuthentication && !$this->getEmailAuthenticationTimestamp() )
1803 * @param array $groups list of groups
1804 * @return array list of permission key names for given groups combined
1807 function getGroupPermissions( $groups ) {
1808 global $wgGroupPermissions;
1810 foreach( $groups as $group ) {
1811 if( isset( $wgGroupPermissions[$group] ) ) {
1812 $rights = array_merge( $rights,
1813 array_keys( array_filter( $wgGroupPermissions[$group] ) ) );
1820 * @param string $group key name
1821 * @return string localized descriptive name, if provided
1824 function getGroupName( $group ) {
1825 $key = "group-$group-name";
1826 $name = wfMsg( $key );
1827 if( $name == '' ||
$name == "<$key>" ) {
1835 * Return the set of defined explicit groups.
1836 * The * and 'user' groups are not included.
1840 function getAllGroups() {
1841 global $wgGroupPermissions;
1843 array_keys( $wgGroupPermissions ),
1844 array( '*', 'user', 'autoconfirmed' ) );