9e96e924be663e334c1b7e9d23b87edf94797c4f
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 $wgProxyList, $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 ( array_key_exists( $ip, $wgProxyList ) ) {
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() {
762 $fname = 'User::getNewtalk';
763 $this->loadFromDatabase();
765 # Load the newtalk status if it is unloaded (mNewtalk=-1)
766 if( $this->mNewtalk
== -1 ) {
767 $this->mNewtalk
= 0; # reset talk page status
769 # Check memcached separately for anons, who have no
770 # entire User object stored in there.
772 global $wgDBname, $wgMemc;
773 $key = "$wgDBname:newtalk:ip:" . $this->getName();
774 $newtalk = $wgMemc->get( $key );
775 if( is_integer( $newtalk ) ) {
776 $this->mNewtalk
= $newtalk ?
1 : 0;
777 return (bool)$this->mNewtalk
;
781 $dbr =& wfGetDB( DB_SLAVE
);
782 if ( $wgUseEnotif ) {
783 $res = $dbr->select( 'watchlist',
785 array( 'wl_title' => $this->getTitleKey(),
786 'wl_namespace' => NS_USER_TALK
,
787 'wl_user' => $this->mId
,
788 'wl_notificationtimestamp ' . $dbr->notNullTimestamp() ),
789 'User::getNewtalk' );
790 if( $dbr->numRows($res) > 0 ) {
793 $dbr->freeResult( $res );
794 } elseif ( $this->mId
) {
795 $res = $dbr->select( 'user_newtalk', 1, array( 'user_id' => $this->mId
), $fname );
797 if ( $dbr->numRows($res)>0 ) {
800 $dbr->freeResult( $res );
802 $res = $dbr->select( 'user_newtalk', 1, array( 'user_ip' => $this->getName() ), $fname );
803 $this->mNewtalk
= $dbr->numRows( $res ) > 0 ?
1 : 0;
804 $dbr->freeResult( $res );
808 $wgMemc->set( $key, $this->mNewtalk
, time() ); // + 1800 );
812 return ( 0 != $this->mNewtalk
);
815 function setNewtalk( $val ) {
816 $this->loadFromDatabase();
817 $this->mNewtalk
= $val;
818 $this->invalidateCache();
821 function invalidateCache() {
822 global $wgClockSkewFudge;
823 $this->loadFromDatabase();
824 $this->mTouched
= wfTimestamp(TS_MW
, time() +
$wgClockSkewFudge );
825 # Don't forget to save the options after this or
826 # it won't take effect!
829 function validateCache( $timestamp ) {
830 $this->loadFromDatabase();
831 return ($timestamp >= $this->mTouched
);
835 * Encrypt a password.
836 * It can eventuall salt a password @see User::addSalt()
837 * @param string $p clear Password.
838 * @return string Encrypted password.
840 function encryptPassword( $p ) {
841 return wfEncryptPassword( $this->mId
, $p );
844 # Set the password and reset the random token
845 function setPassword( $str ) {
846 $this->loadFromDatabase();
848 $this->mPassword
= $this->encryptPassword( $str );
849 $this->mNewpassword
= '';
852 # Set the random token (used for persistent authentication)
853 function setToken( $token = false ) {
854 global $wgSecretKey, $wgProxyKey, $wgDBname;
856 if ( $wgSecretKey ) {
858 } elseif ( $wgProxyKey ) {
863 $this->mToken
= md5( $key . mt_rand( 0, 0x7fffffff ) . $wgDBname . $this->mId
);
865 $this->mToken
= $token;
870 function setCookiePassword( $str ) {
871 $this->loadFromDatabase();
872 $this->mCookiePassword
= md5( $str );
875 function setNewpassword( $str ) {
876 $this->loadFromDatabase();
877 $this->mNewpassword
= $this->encryptPassword( $str );
880 function getEmail() {
881 $this->loadFromDatabase();
882 return $this->mEmail
;
885 function getEmailAuthenticationTimestamp() {
886 $this->loadFromDatabase();
887 return $this->mEmailAuthenticated
;
890 function setEmail( $str ) {
891 $this->loadFromDatabase();
892 $this->mEmail
= $str;
895 function getRealName() {
896 $this->loadFromDatabase();
897 return $this->mRealName
;
900 function setRealName( $str ) {
901 $this->loadFromDatabase();
902 $this->mRealName
= $str;
905 function getOption( $oname ) {
906 $this->loadFromDatabase();
907 if ( array_key_exists( $oname, $this->mOptions
) ) {
908 return trim( $this->mOptions
[$oname] );
914 function setOption( $oname, $val ) {
915 $this->loadFromDatabase();
916 if ( $oname == 'skin' ) {
917 # Clear cached skin, so the new one displays immediately in Special:Preferences
918 unset( $this->mSkin
);
920 $this->mOptions
[$oname] = $val;
921 $this->invalidateCache();
924 function getRights() {
925 $this->loadFromDatabase();
926 return $this->mRights
;
930 * Get the list of explicit group memberships this user has.
931 * The implicit * and user groups are not included.
932 * @return array of strings
934 function getGroups() {
935 $this->loadFromDatabase();
936 return $this->mGroups
;
940 * Get the list of implicit group memberships this user has.
941 * This includes all explicit groups, plus 'user' if logged in
942 * and '*' for all accounts.
943 * @return array of strings
945 function getEffectiveGroups() {
946 $base = array( '*' );
947 if( $this->isLoggedIn() ) {
950 return array_merge( $base, $this->getGroups() );
954 * Remove the user from the given group.
955 * This takes immediate effect.
958 function addGroup( $group ) {
959 $dbw =& wfGetDB( DB_MASTER
);
960 $dbw->insert( 'user_groups',
962 'ug_user' => $this->getID(),
963 'ug_group' => $group,
968 $this->mGroups
= array_merge( $this->mGroups
, array( $group ) );
969 $this->mRights
= User
::getGroupPermissions( $this->getEffectiveGroups() );
971 $this->invalidateCache();
972 $this->saveSettings();
976 * Remove the user from the given group.
977 * This takes immediate effect.
980 function removeGroup( $group ) {
981 $dbw =& wfGetDB( DB_MASTER
);
982 $dbw->delete( 'user_groups',
984 'ug_user' => $this->getID(),
985 'ug_group' => $group,
987 'User::removeGroup' );
989 $this->mGroups
= array_diff( $this->mGroups
, array( $group ) );
990 $this->mRights
= User
::getGroupPermissions( $this->getEffectiveGroups() );
992 $this->invalidateCache();
993 $this->saveSettings();
998 * A more legible check for non-anonymousness.
999 * Returns true if the user is not an anonymous visitor.
1003 function isLoggedIn() {
1004 return( $this->getID() != 0 );
1008 * A more legible check for anonymousness.
1009 * Returns true if the user is an anonymous visitor.
1014 return !$this->isLoggedIn();
1018 * Check if a user is sysop
1021 function isSysop() {
1022 return $this->isAllowed( 'protect' );
1026 function isDeveloper() {
1027 return $this->isAllowed( 'siteadmin' );
1031 function isBureaucrat() {
1032 return $this->isAllowed( 'makesysop' );
1036 * Whether the user is a bot
1037 * @todo need to be migrated to the new user level management sytem
1040 $this->loadFromDatabase();
1041 return in_array( 'bot', $this->mRights
);
1045 * Check if user is allowed to access a feature / make an action
1046 * @param string $action Action to be checked (see $wgAvailableRights in Defines.php for possible actions).
1047 * @return boolean True: action is allowed, False: action should not be allowed
1049 function isAllowed($action='') {
1050 $this->loadFromDatabase();
1051 return in_array( $action , $this->mRights
);
1055 * Load a skin if it doesn't exist or return it
1056 * @todo FIXME : need to check the old failback system [AV]
1058 function &getSkin() {
1059 global $IP, $wgRequest;
1060 if ( ! isset( $this->mSkin
) ) {
1061 $fname = 'User::getSkin';
1062 wfProfileIn( $fname );
1064 # get all skin names available
1065 $skinNames = Skin
::getSkinNames();
1068 $userSkin = $this->getOption( 'skin' );
1069 $userSkin = $wgRequest->getText('useskin', $userSkin);
1070 if ( $userSkin == '' ) { $userSkin = 'standard'; }
1072 if ( !isset( $skinNames[$userSkin] ) ) {
1073 # in case the user skin could not be found find a replacement
1077 2 => 'CologneBlue');
1078 # if phptal is enabled we should have monobook skin that
1079 # superseed the good old SkinStandard.
1080 if ( isset( $skinNames['monobook'] ) ) {
1081 $fallback[0] = 'MonoBook';
1084 if(is_numeric($userSkin) && isset( $fallback[$userSkin]) ){
1085 $sn = $fallback[$userSkin];
1090 # The user skin is available
1091 $sn = $skinNames[$userSkin];
1094 # Grab the skin class and initialise it. Each skin checks for PHPTal
1095 # and will not load if it's not enabled.
1096 require_once( $IP.'/skins/'.$sn.'.php' );
1098 # Check if we got if not failback to default skin
1099 $className = 'Skin'.$sn;
1100 if( !class_exists( $className ) ) {
1101 # DO NOT die if the class isn't found. This breaks maintenance
1102 # scripts and can cause a user account to be unrecoverable
1103 # except by SQL manipulation if a previously valid skin name
1104 # is no longer valid.
1105 $className = 'SkinStandard';
1106 require_once( $IP.'/skins/Standard.php' );
1108 $this->mSkin
=& new $className;
1109 wfProfileOut( $fname );
1111 return $this->mSkin
;
1115 * @param string $title Article title to look at
1119 * Check watched status of an article
1120 * @return bool True if article is watched
1122 function isWatched( $title ) {
1123 $wl = WatchedItem
::fromUserTitle( $this, $title );
1124 return $wl->isWatched();
1130 function addWatch( $title ) {
1131 $wl = WatchedItem
::fromUserTitle( $this, $title );
1133 $this->invalidateCache();
1137 * Stop watching an article
1139 function removeWatch( $title ) {
1140 $wl = WatchedItem
::fromUserTitle( $this, $title );
1142 $this->invalidateCache();
1146 * Clear the user's notification timestamp for the given title.
1147 * If e-notif e-mails are on, they will receive notification mails on
1148 * the next change of the page if it's watched etc.
1150 function clearNotification( &$title ) {
1151 global $wgUser, $wgUseEnotif;
1153 if ( !$wgUseEnotif ) {
1157 $userid = $this->getID();
1162 // Only update the timestamp if the page is being watched.
1163 // The query to find out if it is watched is cached both in memcached and per-invocation,
1164 // and when it does have to be executed, it can be on a slave
1165 // If this is the user's newtalk page, we always update the timestamp
1166 if ($title->getNamespace() == NS_USER_TALK
&&
1167 $title->getText() == $wgUser->getName())
1170 } elseif ( $this->getID() == $wgUser->getID() ) {
1171 $watched = $title->userIsWatching();
1176 // If the page is watched by the user (or may be watched), update the timestamp on any
1177 // any matching rows
1179 $dbw =& wfGetDB( DB_MASTER
);
1180 $success = $dbw->update( 'watchlist',
1182 'wl_notificationtimestamp' => NULL
1183 ), array( /* WHERE */
1184 'wl_title' => $title->getDBkey(),
1185 'wl_namespace' => $title->getNamespace(),
1186 'wl_user' => $this->getID()
1187 ), 'User::clearLastVisited'
1195 * Resets all of the given user's page-change notification timestamps.
1196 * If e-notif e-mails are on, they will receive notification mails on
1197 * the next change of any watched page.
1199 * @param int $currentUser user ID number
1202 function clearAllNotifications( $currentUser ) {
1203 global $wgUseEnotif;
1204 if ( !$wgUseEnotif ) {
1207 if( $currentUser != 0 ) {
1209 $dbw =& wfGetDB( DB_MASTER
);
1210 $success = $dbw->update( 'watchlist',
1212 'wl_notificationtimestamp' => 0
1213 ), array( /* WHERE */
1214 'wl_user' => $currentUser
1215 ), 'UserMailer::clearAll'
1218 # we also need to clear here the "you have new message" notification for the own user_talk page
1219 # This is cleared one page view later in Article::viewUpdates();
1225 * @return string Encoding options
1227 function encodeOptions() {
1229 foreach ( $this->mOptions
as $oname => $oval ) {
1230 array_push( $a, $oname.'='.$oval );
1232 $s = implode( "\n", $a );
1239 function decodeOptions( $str ) {
1240 $a = explode( "\n", $str );
1241 foreach ( $a as $s ) {
1242 if ( preg_match( "/^(.[^=]*)=(.*)$/", $s, $m ) ) {
1243 $this->mOptions
[$m[1]] = $m[2];
1248 function setCookies() {
1249 global $wgCookieExpiration, $wgCookiePath, $wgCookieDomain, $wgDBname;
1250 if ( 0 == $this->mId
) return;
1251 $this->loadFromDatabase();
1252 $exp = time() +
$wgCookieExpiration;
1254 $_SESSION['wsUserID'] = $this->mId
;
1255 setcookie( $wgDBname.'UserID', $this->mId
, $exp, $wgCookiePath, $wgCookieDomain );
1257 $_SESSION['wsUserName'] = $this->getName();
1258 setcookie( $wgDBname.'UserName', $this->getName(), $exp, $wgCookiePath, $wgCookieDomain );
1260 $_SESSION['wsToken'] = $this->mToken
;
1261 if ( 1 == $this->getOption( 'rememberpassword' ) ) {
1262 setcookie( $wgDBname.'Token', $this->mToken
, $exp, $wgCookiePath, $wgCookieDomain );
1264 setcookie( $wgDBname.'Token', '', time() - 3600 );
1270 * It will clean the session cookie
1273 global $wgCookiePath, $wgCookieDomain, $wgDBname;
1274 $this->loadDefaults();
1275 $this->setLoaded( true );
1277 $_SESSION['wsUserID'] = 0;
1279 setcookie( $wgDBname.'UserID', '', time() - 3600, $wgCookiePath, $wgCookieDomain );
1280 setcookie( $wgDBname.'Token', '', time() - 3600, $wgCookiePath, $wgCookieDomain );
1282 # Remember when user logged out, to prevent seeing cached pages
1283 setcookie( $wgDBname.'LoggedOut', wfTimestampNow(), time() +
86400, $wgCookiePath, $wgCookieDomain );
1287 * Save object settings into database
1289 function saveSettings() {
1290 global $wgMemc, $wgDBname, $wgUseEnotif;
1291 $fname = 'User::saveSettings';
1293 if ( wfReadOnly() ) { return; }
1294 $this->saveNewtalk();
1295 if ( 0 == $this->mId
) { return; }
1297 $dbw =& wfGetDB( DB_MASTER
);
1298 $dbw->update( 'user',
1300 'user_name' => $this->mName
,
1301 'user_password' => $this->mPassword
,
1302 'user_newpassword' => $this->mNewpassword
,
1303 'user_real_name' => $this->mRealName
,
1304 'user_email' => $this->mEmail
,
1305 'user_email_authenticated' => $dbw->timestampOrNull( $this->mEmailAuthenticated
),
1306 'user_options' => $this->encodeOptions(),
1307 'user_touched' => $dbw->timestamp($this->mTouched
),
1308 'user_token' => $this->mToken
1309 ), array( /* WHERE */
1310 'user_id' => $this->mId
1313 $wgMemc->delete( "$wgDBname:user:id:$this->mId" );
1317 * Save value of new talk flag.
1319 function saveNewtalk() {
1320 global $wgDBname, $wgMemc, $wgUseEnotif;
1322 $fname = 'User::saveNewtalk';
1326 if ( wfReadOnly() ) { return ; }
1327 $dbr =& wfGetDB( DB_SLAVE
);
1328 $dbw =& wfGetDB( DB_MASTER
);
1330 if ( $wgUseEnotif ) {
1331 if ( ! $this->getNewtalk() ) {
1332 # Delete the watchlist entry for user_talk page X watched by user X
1333 $dbw->delete( 'watchlist',
1334 array( 'wl_user' => $this->mId
,
1335 'wl_title' => $this->getTitleKey(),
1336 'wl_namespace' => NS_USER_TALK
),
1338 if ( $dbw->affectedRows() ) {
1342 # Anon users have a separate memcache space for newtalk
1343 # since they don't store their own info. Trim...
1344 $wgMemc->delete( "$wgDBname:newtalk:ip:" . $this->getName() );
1348 if ($this->getID() != 0) {
1350 $value = $this->getID();
1354 $value = $this->getName();
1355 $key = "$wgDBname:newtalk:ip:$value";
1358 $dbr =& wfGetDB( DB_SLAVE
);
1359 $dbw =& wfGetDB( DB_MASTER
);
1361 $res = $dbr->selectField('user_newtalk', $field,
1362 array($field => $value), $fname);
1365 if ($res !== false && $this->mNewtalk
== 0) {
1366 $dbw->delete('user_newtalk', array($field => $value), $fname);
1368 $wgMemc->set( $key, 0 );
1370 } else if ($res === false && $this->mNewtalk
== 1) {
1371 $dbw->insert('user_newtalk', array($field => $value), $fname);
1373 $wgMemc->set( $key, 1 );
1380 # Update user_touched, so that newtalk notifications in the client cache are invalidated
1381 if ( $changed && $this->getID() ) {
1382 $dbw->update('user',
1383 /*SET*/ array( 'user_touched' => $this->mTouched
),
1384 /*WHERE*/ array( 'user_id' => $this->getID() ),
1386 $wgMemc->set( "$wgDBname:user:id:{$this->mId}", $this, 86400 );
1391 * Checks if a user with the given name exists, returns the ID
1393 function idForName() {
1394 $fname = 'User::idForName';
1397 $s = trim( $this->getName() );
1398 if ( 0 == strcmp( '', $s ) ) return 0;
1400 $dbr =& wfGetDB( DB_SLAVE
);
1401 $id = $dbr->selectField( 'user', 'user_id', array( 'user_name' => $s ), $fname );
1402 if ( $id === false ) {
1409 * Add user object to the database
1411 function addToDatabase() {
1412 $fname = 'User::addToDatabase';
1413 $dbw =& wfGetDB( DB_MASTER
);
1414 $seqVal = $dbw->nextSequenceValue( 'user_user_id_seq' );
1415 $dbw->insert( 'user',
1417 'user_id' => $seqVal,
1418 'user_name' => $this->mName
,
1419 'user_password' => $this->mPassword
,
1420 'user_newpassword' => $this->mNewpassword
,
1421 'user_email' => $this->mEmail
,
1422 'user_email_authenticated' => $dbw->timestampOrNull( $this->mEmailAuthenticated
),
1423 'user_real_name' => $this->mRealName
,
1424 'user_options' => $this->encodeOptions(),
1425 'user_token' => $this->mToken
1428 $this->mId
= $dbw->insertId();
1431 function spreadBlock() {
1432 # If the (non-anonymous) user is blocked, this function will block any IP address
1433 # that they successfully log on from.
1434 $fname = 'User::spreadBlock';
1436 wfDebug( "User:spreadBlock()\n" );
1437 if ( $this->mId
== 0 ) {
1441 $userblock = Block
::newFromDB( '', $this->mId
);
1442 if ( !$userblock->isValid() ) {
1446 # Check if this IP address is already blocked
1447 $ipblock = Block
::newFromDB( wfGetIP() );
1448 if ( $ipblock->isValid() ) {
1449 # If the user is already blocked. Then check if the autoblock would
1450 # excede the user block. If it would excede, then do nothing, else
1451 # prolong block time
1452 if ($userblock->mExpiry
&&
1453 ($userblock->mExpiry
< Block
::getAutoblockExpiry($ipblock->mTimestamp
))) {
1456 # Just update the timestamp
1457 $ipblock->updateTimestamp();
1461 # Make a new block object with the desired properties
1462 wfDebug( "Autoblocking {$this->mName}@" . wfGetIP() . "\n" );
1463 $ipblock->mAddress
= wfGetIP();
1464 $ipblock->mUser
= 0;
1465 $ipblock->mBy
= $userblock->mBy
;
1466 $ipblock->mReason
= wfMsg( 'autoblocker', $this->getName(), $userblock->mReason
);
1467 $ipblock->mTimestamp
= wfTimestampNow();
1468 $ipblock->mAuto
= 1;
1469 # If the user is already blocked with an expiry date, we don't
1470 # want to pile on top of that!
1471 if($userblock->mExpiry
) {
1472 $ipblock->mExpiry
= min ( $userblock->mExpiry
, Block
::getAutoblockExpiry( $ipblock->mTimestamp
));
1474 $ipblock->mExpiry
= Block
::getAutoblockExpiry( $ipblock->mTimestamp
);
1482 function getPageRenderingHash() {
1485 return $this->mHash
;
1488 // stubthreshold is only included below for completeness,
1489 // it will always be 0 when this function is called by parsercache.
1491 $confstr = $this->getOption( 'math' );
1492 $confstr .= '!' . $this->getOption( 'stubthreshold' );
1493 $confstr .= '!' . $this->getOption( 'date' );
1494 $confstr .= '!' . ($this->getOption( 'numberheadings' ) ?
'1' : '');
1495 $confstr .= '!' . $this->getOption( 'language' );
1496 $confstr .= '!' . $this->getOption( 'thumbsize' );
1497 // add in language specific options, if any
1498 $extra = $wgContLang->getExtraHashOptions();
1501 $this->mHash
= $confstr;
1505 function isAllowedToCreateAccount() {
1506 return $this->isAllowed( 'createaccount' ) && !$this->isBlocked();
1510 * Set mDataLoaded, return previous value
1511 * Use this to prevent DB access in command-line scripts or similar situations
1513 function setLoaded( $loaded ) {
1514 return wfSetVar( $this->mDataLoaded
, $loaded );
1518 * Get this user's personal page title.
1523 function getUserPage() {
1524 return Title
::makeTitle( NS_USER
, $this->getName() );
1528 * Get this user's talk page title.
1533 function getTalkPage() {
1534 $title = $this->getUserPage();
1535 return $title->getTalkPage();
1541 function getMaxID() {
1542 $dbr =& wfGetDB( DB_SLAVE
);
1543 return $dbr->selectField( 'user', 'max(user_id)', false, 'User::getMaxID' );
1547 * Determine whether the user is a newbie. Newbies are either
1548 * anonymous IPs, or the 1% most recently created accounts.
1549 * Bots and sysops are excluded.
1550 * @return bool True if it is a newbie.
1552 function isNewbie() {
1553 return $this->isAnon() ||
$this->mId
> User
::getMaxID() * 0.99 && !$this->isAllowed( 'delete' ) && !$this->isBot();
1557 * Check to see if the given clear-text password is one of the accepted passwords
1558 * @param string $password User password.
1559 * @return bool True if the given password is correct otherwise False.
1561 function checkPassword( $password ) {
1562 global $wgAuth, $wgMinimalPasswordLength;
1563 $this->loadFromDatabase();
1565 // Even though we stop people from creating passwords that
1566 // are shorter than this, doesn't mean people wont be able
1567 // to. Certain authentication plugins do NOT want to save
1568 // domain passwords in a mysql database, so we should
1569 // check this (incase $wgAuth->strict() is false).
1570 if( strlen( $password ) < $wgMinimalPasswordLength ) {
1574 if( $wgAuth->authenticate( $this->getName(), $password ) ) {
1576 } elseif( $wgAuth->strict() ) {
1577 /* Auth plugin doesn't allow local authentication */
1580 $ep = $this->encryptPassword( $password );
1581 if ( 0 == strcmp( $ep, $this->mPassword
) ) {
1583 } elseif ( ($this->mNewpassword
!= '') && (0 == strcmp( $ep, $this->mNewpassword
)) ) {
1585 } elseif ( function_exists( 'iconv' ) ) {
1586 # Some wikis were converted from ISO 8859-1 to UTF-8, the passwords can't be converted
1587 # Check for this with iconv
1588 $cp1252hash = $this->encryptPassword( iconv( 'UTF-8', 'WINDOWS-1252', $password ) );
1589 if ( 0 == strcmp( $cp1252hash, $this->mPassword
) ) {
1597 * Initialize (if necessary) and return a session token value
1598 * which can be used in edit forms to show that the user's
1599 * login credentials aren't being hijacked with a foreign form
1602 * @param mixed $salt - Optional function-specific data for hash.
1603 * Use a string or an array of strings.
1607 function editToken( $salt = '' ) {
1608 if( !isset( $_SESSION['wsEditToken'] ) ) {
1609 $token = $this->generateToken();
1610 $_SESSION['wsEditToken'] = $token;
1612 $token = $_SESSION['wsEditToken'];
1614 if( is_array( $salt ) ) {
1615 $salt = implode( '|', $salt );
1617 return md5( $token . $salt );
1621 * Generate a hex-y looking random token for various uses.
1622 * Could be made more cryptographically sure if someone cares.
1625 function generateToken( $salt = '' ) {
1626 $token = dechex( mt_rand() ) . dechex( mt_rand() );
1627 return md5( $token . $salt );
1631 * Check given value against the token value stored in the session.
1632 * A match should confirm that the form was submitted from the
1633 * user's own login session, not a form submission from a third-party
1636 * @param string $val - the input value to compare
1637 * @param string $salt - Optional function-specific data for hash
1641 function matchEditToken( $val, $salt = '' ) {
1645 if ( !isset( $_SESSION['wsEditToken'] ) ) {
1646 $logfile = '/home/wikipedia/logs/session_debug/session.log';
1647 $mckey = memsess_key( session_id() );
1648 $uname = @posix_uname();
1649 $msg = "wsEditToken not set!\n" .
1650 'apache server=' . $uname['nodename'] . "\n" .
1651 'session_id = ' . session_id() . "\n" .
1652 '$_SESSION=' . var_export( $_SESSION, true ) . "\n" .
1653 '$_COOKIE=' . var_export( $_COOKIE, true ) . "\n" .
1654 "mc get($mckey) = " . var_export( $wgMemc->get( $mckey ), true ) . "\n\n\n";
1656 @error_log( $msg, 3, $logfile );
1659 return ( $val == $this->editToken( $salt ) );
1663 * Generate a new e-mail confirmation token and send a confirmation
1664 * mail to the user's given address.
1666 * @return mixed True on success, a WikiError object on failure.
1668 function sendConfirmationMail() {
1670 $url = $this->confirmationTokenUrl( $expiration );
1671 return $this->sendMail( wfMsg( 'confirmemail_subject' ),
1672 wfMsg( 'confirmemail_body',
1676 $wgContLang->timeanddate( $expiration, false ) ) );
1680 * Send an e-mail to this user's account. Does not check for
1681 * confirmed status or validity.
1683 * @param string $subject
1684 * @param string $body
1685 * @param strong $from Optional from address; default $wgPasswordSender will be used otherwise.
1686 * @return mixed True on success, a WikiError object on failure.
1688 function sendMail( $subject, $body, $from = null ) {
1689 if( is_null( $from ) ) {
1690 global $wgPasswordSender;
1691 $from = $wgPasswordSender;
1694 require_once( 'UserMailer.php' );
1695 $error = userMailer( $this->getEmail(), $from, $subject, $body );
1697 if( $error == '' ) {
1700 return new WikiError( $error );
1705 * Generate, store, and return a new e-mail confirmation code.
1706 * A hash (unsalted since it's used as a key) is stored.
1707 * @param &$expiration mixed output: accepts the expiration time
1711 function confirmationToken( &$expiration ) {
1712 $fname = 'User::confirmationToken';
1715 $expires = $now +
7 * 24 * 60 * 60;
1716 $expiration = wfTimestamp( TS_MW
, $expires );
1718 $token = $this->generateToken( $this->mId
. $this->mEmail
. $expires );
1719 $hash = md5( $token );
1721 $dbw =& wfGetDB( DB_MASTER
);
1722 $dbw->update( 'user',
1723 array( 'user_email_token' => $hash,
1724 'user_email_token_expires' => $dbw->timestamp( $expires ) ),
1725 array( 'user_id' => $this->mId
),
1732 * Generate and store a new e-mail confirmation token, and return
1733 * the URL the user can use to confirm.
1734 * @param &$expiration mixed output: accepts the expiration time
1738 function confirmationTokenUrl( &$expiration ) {
1739 $token = $this->confirmationToken( $expiration );
1740 $title = Title
::makeTitle( NS_SPECIAL
, 'Confirmemail/' . $token );
1741 return $title->getFullUrl();
1745 * Mark the e-mail address confirmed and save.
1747 function confirmEmail() {
1748 $this->loadFromDatabase();
1749 $this->mEmailAuthenticated
= wfTimestampNow();
1750 $this->saveSettings();
1755 * Is this user allowed to send e-mails within limits of current
1756 * site configuration?
1759 function canSendEmail() {
1760 return $this->isEmailConfirmed();
1764 * Is this user allowed to receive e-mails within limits of current
1765 * site configuration?
1768 function canReceiveEmail() {
1769 return $this->canSendEmail() && !$this->getOption( 'disablemail' );
1773 * Is this user's e-mail address valid-looking and confirmed within
1774 * limits of the current site configuration?
1776 * If $wgEmailAuthentication is on, this may require the user to have
1777 * confirmed their address by returning a code or using a password
1778 * sent to the address from the wiki.
1782 function isEmailConfirmed() {
1783 global $wgEmailAuthentication;
1784 $this->loadFromDatabase();
1785 if( $this->isAnon() )
1787 if( !$this->isValidEmailAddr( $this->mEmail
) )
1789 if( $wgEmailAuthentication && !$this->getEmailAuthenticationTimestamp() )
1795 * @param array $groups list of groups
1796 * @return array list of permission key names for given groups combined
1799 function getGroupPermissions( $groups ) {
1800 global $wgGroupPermissions;
1802 foreach( $groups as $group ) {
1803 if( isset( $wgGroupPermissions[$group] ) ) {
1804 $rights = array_merge( $rights,
1805 array_keys( array_filter( $wgGroupPermissions[$group] ) ) );
1812 * @param string $group key name
1813 * @return string localized descriptive name, if provided
1816 function getGroupName( $group ) {
1817 $key = "group-$group-name";
1818 $name = wfMsg( $key );
1819 if( $name == '' ||
$name == "<$key>" ) {
1827 * Return the set of defined explicit groups.
1828 * The * and 'user' groups are not included.
1832 function getAllGroups() {
1833 global $wgGroupPermissions;
1835 array_keys( $wgGroupPermissions ),
1836 array( '*', 'user' ) );