'mEditCount',
// user_group table
'mGroups',
+ // user_restrictions table
+ 'mRestrictions',
);
/**
'proxyunbannable',
'purge',
'read',
+ 'restrict',
'reupload',
'reupload-shared',
'rollback',
//@{
var $mId, $mName, $mRealName, $mPassword, $mNewpassword, $mNewpassTime,
$mEmail, $mOptions, $mTouched, $mToken, $mEmailAuthenticated,
- $mEmailToken, $mEmailTokenExpires, $mRegistration, $mGroups;
+ $mEmailToken, $mEmailTokenExpires, $mRegistration, $mGroups,
+ $mRestrictions;
//@}
/**
function saveToCache() {
$this->load();
$this->loadGroups();
+ $this->loadRestrictions();
if ( $this->isAnon() ) {
// Anonymous users are uncached
return;
return false;
# Clean up name according to title rules
- $t = Title::newFromText( $name );
+ $t = ($validate === 'valid') ?
+ Title::newFromText( $name ) : Title::makeTitle( NS_USER, $name );
+ # Check for invalid titles
if( is_null( $t ) ) {
return false;
}
# Initialise user table data
$this->loadFromRow( $s );
$this->mGroups = null; // deferred
+ $this->mRestrictions = null;
$this->getEditCount(); // revalidation for nulls
return true;
} else {
$this->mBlockedby = 0;
$this->mHideName = 0;
+ $this->mAllowUsertalk = 0;
$ip = wfGetIP();
if ($this->isAllowed( 'ipblock-exempt' ) ) {
$this->mBlockedby = $this->mBlock->mBy;
$this->mBlockreason = $this->mBlock->mReason;
$this->mHideName = $this->mBlock->mHideName;
+ $this->mAllowUsertalk = $this->mBlock->mAllowUsertalk;
if ( $this->isLoggedIn() ) {
$this->spreadBlock();
}
} else {
- $this->mBlock = null;
- wfDebug( __METHOD__.": No block.\n" );
+ // Bug 13611: don't remove mBlock here, to allow account creation blocks to
+ // apply to users. Note that the existence of $this->mBlock is not used to
+ // check for edit blocks, $this->mBlockedby is instead.
}
# Proxy blocking
$found = false;
$host = '';
- // FIXME: IPv6 ???
- $m = array();
- if ( preg_match( '/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/', $ip, $m ) ) {
+ // FIXME: IPv6 ??? (http://bugs.php.net/bug.php?id=33170)
+ if( IP::isIPv4($ip) ) {
# Make hostname
- for ( $i=4; $i>=1; $i-- ) {
- $host .= $m[$i] . '.';
- }
- $host .= $base;
+ $host = "$ip.$base";
# Send query
$ipList = gethostbynamel( $host );
- if ( $ipList ) {
+ if( $ipList ) {
wfDebug( "Hostname $host is {$ipList[0]}, it's a proxy says $base!\n" );
$found = true;
} else {
wfDebug( __METHOD__.": asking isBlocked()\n" );
$blocked = $this->isBlocked( $bFromSlave );
# If a user's name is suppressed, they cannot make edits anywhere
- if ( !$this->mHideName && $wgBlockAllowsUTEdit && $title->getText() === $this->getName() &&
+ if ( !$this->mHideName && $this->mAllowUsertalk && $title->getText() === $this->getName() &&
$title->getNamespace() == NS_USER_TALK ) {
$blocked = false;
wfDebug( __METHOD__.": self-talk page, ignoring any blocks\n" );
// In the spirit of DWIM
return true;
- return in_array( $action, $this->getRights() );
+ # Use strict parameter to avoid matching numeric 0 accidentally inserted
+ # by misconfiguration: 0 == 'foo'
+ return in_array( $action, $this->getRights(), true );
}
/**
* @return \type{\string} Page rendering hash
*/
function getPageRenderingHash() {
- global $wgContLang, $wgUseDynamicDates, $wgLang;
+ global $wgUseDynamicDates, $wgRenderHashAppend, $wgLang, $wgContLang;
if( $this->mHash ){
return $this->mHash;
}
$extra = $wgContLang->getExtraHashOptions();
$confstr .= $extra;
+ $confstr .= $wgRenderHashAppend;
+
// Give a chance for extensions to modify the hash, if they have
// extra options or other effects on the parser cache.
wfRunHooks( 'PageRenderingHash', array( &$confstr ) );
* Add an autocreate newuser log entry for this user
* Used by things like CentralAuth and perhaps other authplugins.
*/
- public static function addNewUserLogEntryAutoCreate() {
+ public function addNewUserLogEntryAutoCreate() {
global $wgNewUserLog;
if( empty($wgNewUserLog) ) {
return true; // disabled
return true;
}
+ // Restrictions-related block
+
+ public function loadRestrictions() {
+ if( !$this->mRestrictions )
+ $this->mRestrictions = UserRestriction::fetchForUser( $this->isLoggedIn() ?
+ intval( $this->getId() ) : $this->getName() );
+ }
+
+ public function getRestrictions() {
+ $this->loadRestrictions();
+
+ // Check for expired restrictions. Recache if found expired ones
+ static $checked = false;
+ if( !$checked ) {
+ $expired = false;
+ $old = $this->mRestrictions;
+ $this->mRestrictions = array();
+ foreach( $old as $restriction ) {
+ if( $restriction->deleteIfExpired() )
+ $expired = true;
+ else
+ $this->mRestrictions[] = $restriction;
+ }
+ if( $expired )
+ $this->saveToCache();
+ $checked = true;
+ }
+
+ return $this->mRestrictions;
+ }
+
+ public function getRestrictionForPage( Title $page ) {
+ foreach( $this->getRestrictions() as $r ) {
+ if( $r->isPage() && $page->equals( $r->getPage() ) )
+ return $r;
+ }
+ return null;
+ }
+
+ public function getRestrictionForNamespace( $nsid ) {
+ foreach( $this->getRestrictions() as $r ) {
+ if( $r->isNamespace() && $r->getNamespace() == $nsid )
+ return $r;
+ }
+ return null;
+ }
}