* @package MediaWiki
*/
-/**
- *
- */
-require_once( 'WatchedItem.php' );
-
# Number of characters in user_token field
define( 'USER_TOKEN_LENGTH', 32 );
/**
* Static factory method
* @param string $name Username, validated by Title:newFromText()
+ * @param bool $validate Validate username
* @return User
* @static
*/
- function newFromName( $name ) {
+ function newFromName( $name, $validate = true ) {
# Force usernames to capital
global $wgContLang;
$name = $wgContLang->ucfirst( $name );
global $wgAuth;
$canonicalName = $wgAuth->getCanonicalName( $t->getText() );
- if( !User::isValidUserName( $canonicalName ) ) {
+ if( $validate && !User::isValidUserName( $canonicalName ) ) {
return null;
}
}
/**
- * does the string match an anonymous IPv4 address?
+ * Does the string match an anonymous IPv4 address?
*
- * Note: We match \d{1,3}\.\d{1,3}\.\d{1,3}\.xxx as an anonymous IP
+ * This function exists for username validation, in order to reject
+ * usernames which are similar in form to IP addresses. Strings such
+ * as 300.300.300.300 will return true because it looks like an IP
+ * address, despite not being strictly valid.
+ *
+ * We match \d{1,3}\.\d{1,3}\.\d{1,3}\.xxx as an anonymous IP
* address because the usemod software would "cloak" anonymous IP
* addresses like this, if we allowed accounts like this to be created
* new users could get the old edits of these anonymous users.
}
# Proxy blocking
- if ( !$this->isSysop() && !in_array( $ip, $wgProxyWhitelist ) ) {
+ # FIXME ? proxyunbannable is to deprecate the old isSysop()
+ if ( !$this->isAllowed('proxyunbannable') && !in_array( $ip, $wgProxyWhitelist ) ) {
# Local list
if ( wfIsLocallyBlockedProxy( $ip ) ) {
$this->inDnsBlacklist( $ip, 'http.dnsbl.sorbs.net.' );
}
- function inOpmBlacklist( $ip ) {
- global $wgEnableOpm;
- return $wgEnableOpm &&
- $this->inDnsBlacklist( $ip, 'opm.blitzed.org.' );
- }
-
function inDnsBlacklist( $ip, $base ) {
$fname = 'User::inDnsBlacklist';
wfProfileIn( $fname );
* @public
*/
function pingLimiter( $action='edit' ) {
- global $wgRateLimits;
+ global $wgRateLimits, $wgRateLimitsExcludedGroups;
if( !isset( $wgRateLimits[$action] ) ) {
return false;
}
- if( $this->isAllowed( 'delete' ) ) {
- // goddam cabal
- return false;
+
+ # Some groups shouldn't trigger the ping limiter, ever
+ foreach( $this->getGroups() as $group ) {
+ if( array_search( $group, $wgRateLimitsExcludedGroups ) !== false )
+ return false;
}
-
+
global $wgMemc, $wgDBname, $wgRateLimitLog;
$fname = 'User::pingLimiter';
wfProfileIn( $fname );
function getBoolOption( $oname ) {
return (bool)$this->getOption( $oname );
}
+
+ /**
+ * Get an option as an integer value from the source string.
+ * @param string $oname The option to check
+ * @param int $default Optional value to return if option is unset/blank.
+ * @return int
+ */
+ function getIntOption( $oname, $default=0 ) {
+ $val = $this->getOption( $oname );
+ if( $val == '' ) {
+ $val = $default;
+ }
+ return intval( $val );
+ }
function setOption( $oname, $val ) {
$this->loadFromDatabase();
# Clear cached skin, so the new one displays immediately in Special:Preferences
unset( $this->mSkin );
}
+ // Filter out any newlines that may have passed through input validation.
+ // Newlines are used to separate items in the options blob.
+ $val = str_replace( "\r\n", "\n", $val );
+ $val = str_replace( "\r", "\n", $val );
+ $val = str_replace( "\n", " ", $val );
$this->mOptions[$oname] = $val;
$this->invalidateCache();
}
}
/**
- * Check if a user is sysop
+ * Deprecated in 1.6, die in 1.7, to be removed in 1.8
* @deprecated
*/
function isSysop() {
- return $this->isAllowed( 'protect' );
+ throw new MWException( "Call to deprecated (v1.7) User::isSysop() method\n" );
+ #return $this->isAllowed( 'protect' );
}
- /** @deprecated */
+ /**
+ * Deprecated in 1.6, die in 1.7, to be removed in 1.8
+ * @deprecated
+ */
function isDeveloper() {
- return $this->isAllowed( 'siteadmin' );
+ throw new MWException( "Call to deprecated (v1.7) User::isDeveloper() method\n" );
+ #return $this->isAllowed( 'siteadmin' );
}
- /** @deprecated */
+ /**
+ * Deprecated in 1.6, die in 1.7, to be removed in 1.8
+ * @deprecated
+ */
function isBureaucrat() {
- return $this->isAllowed( 'makesysop' );
+ throw new MWException( "Call to deprecated (v1.7) User::isBureaucrat() method\n" );
+ #return $this->isAllowed( 'makesysop' );
}
/**
function isEmailConfirmed() {
global $wgEmailAuthentication;
$this->loadFromDatabase();
- if( $this->isAnon() )
- return false;
- if( !$this->isValidEmailAddr( $this->mEmail ) )
- return false;
- if( $wgEmailAuthentication && !$this->getEmailAuthenticationTimestamp() )
- return false;
- return true;
+ $confirmed = true;
+ if( wfRunHooks( 'EmailConfirmed', array( &$this, &$confirmed ) ) ) {
+ if( $this->isAnon() )
+ return false;
+ if( !$this->isValidEmailAddr( $this->mEmail ) )
+ return false;
+ if( $wgEmailAuthentication && !$this->getEmailAuthenticationTimestamp() )
+ return false;
+ return true;
+ } else {
+ return $confirmed;
+ }
}
/**
/**
* @param string $group key name
- * @return string localized descriptive name, if provided
+ * @return string localized descriptive name for group, if provided
* @static
*/
function getGroupName( $group ) {
- $key = "group-$group-name";
+ $key = "group-$group";
+ $name = wfMsg( $key );
+ if( $name == '' || $name == "<$key>" ) {
+ return $group;
+ } else {
+ return $name;
+ }
+ }
+
+ /**
+ * @param string $group key name
+ * @return string localized descriptive name for member of a group, if provided
+ * @static
+ */
+ function getGroupMember( $group ) {
+ $key = "group-$group-member";
$name = wfMsg( $key );
if( $name == '' || $name == "<$key>" ) {
return $group;
}
}
+
/**
* Return the set of defined explicit groups.
* The * and 'user' groups are not included.
array_keys( $wgGroupPermissions ),
array( '*', 'user', 'autoconfirmed' ) );
}
+
+ /**
+ * Get the title of a page describing a particular group
+ *
+ * @param $group Name of the group
+ * @return mixed
+ */
+ function getGroupPage( $group ) {
+ $page = wfMsgForContent( 'grouppage-' . $group );
+ if( !wfEmptyMsg( 'grouppage-' . $group, $page ) ) {
+ $title = Title::newFromText( $page );
+ if( is_object( $title ) )
+ return $title;
+ }
+ return false;
+ }
+
+
}
?>