From 7d3eb4accdd826045b6c94a38d2435c99dbbc10a Mon Sep 17 00:00:00 2001 From: Daniel Cannon Date: Thu, 7 Jun 2007 17:31:08 +0000 Subject: [PATCH] (bug 7997) Added ability to Special:Blockip to block users from using Special:Emailuser. --- RELEASE-NOTES | 3 +++ includes/Block.php | 14 +++++++----- includes/DefaultSettings.php | 5 +++-- includes/SpecialBlockip.php | 25 ++++++++++++++++++--- includes/SpecialEmailuser.php | 7 ++++++ includes/SpecialIpblocklist.php | 6 ++++- includes/User.php | 11 +++++++++ languages/messages/MessagesEn.php | 9 ++++++-- maintenance/archives/patch-ipb_emailban.sql | 4 ++++ maintenance/tables.sql | 3 +++ maintenance/updaters.inc | 1 + 11 files changed, 75 insertions(+), 13 deletions(-) create mode 100644 maintenance/archives/patch-ipb_emailban.sql diff --git a/RELEASE-NOTES b/RELEASE-NOTES index e6a21abf27..ab6672cccd 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -64,6 +64,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Show result of Special:Booksources in wiki content language always, it's normally better maintained than the generic list from the standard message files +* (bug 7997) Added ability of sysops to block users from sending e-mail via + Special:Emailuser. This can be disabled by setting $wgSysopEmailBans to + false. == Bugfixes since 1.10 == diff --git a/includes/Block.php b/includes/Block.php index fa98692c83..c2fc1516ab 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -15,7 +15,8 @@ class Block { /* public*/ var $mAddress, $mUser, $mBy, $mReason, $mTimestamp, $mAuto, $mId, $mExpiry, - $mRangeStart, $mRangeEnd, $mAnonOnly, $mEnableAutoblock, $mHideName; + $mRangeStart, $mRangeEnd, $mAnonOnly, $mEnableAutoblock, $mHideName, + $mBlockEmail; /* private */ var $mNetworkBits, $mIntegerAddr, $mForUpdate, $mFromMaster, $mByName; const EB_KEEP_EXPIRED = 1; @@ -24,7 +25,7 @@ class Block function __construct( $address = '', $user = 0, $by = 0, $reason = '', $timestamp = '' , $auto = 0, $expiry = '', $anonOnly = 0, $createAccount = 0, $enableAutoblock = 0, - $hideName = 0 ) + $hideName = 0, $blockEmail = 0 ) { $this->mId = 0; # Expand valid IPv6 addresses @@ -40,7 +41,7 @@ class Block $this->mExpiry = self::decodeExpiry( $expiry ); $this->mEnableAutoblock = $enableAutoblock; $this->mHideName = $hideName; - + $this->mBlockEmail = $blockEmail; $this->mForUpdate = false; $this->mFromMaster = false; $this->mByName = false; @@ -76,7 +77,7 @@ class Block $this->mAddress = $this->mReason = $this->mTimestamp = ''; $this->mId = $this->mAnonOnly = $this->mCreateAccount = $this->mEnableAutoblock = $this->mAuto = $this->mUser = - $this->mBy = $this->mHideName = 0; + $this->mBy = $this->mHideName = $this->mBlockEmail = 0; $this->mByName = false; } @@ -262,6 +263,7 @@ class Block $this->mAnonOnly = $row->ipb_anon_only; $this->mCreateAccount = $row->ipb_create_account; $this->mEnableAutoblock = $row->ipb_enable_autoblock; + $this->mBlockEmail = $row->ipb_block_email; $this->mHideName = $row->ipb_deleted; $this->mId = $row->ipb_id; $this->mExpiry = self::decodeExpiry( $row->ipb_expiry ); @@ -371,6 +373,7 @@ class Block # Unset ipb_enable_autoblock for IP blocks, makes no sense if ( !$this->mUser ) { $this->mEnableAutoblock = 0; + $this->mBlockEmail = 0; //Same goes for email... } # Don't collide with expired blocks @@ -392,7 +395,8 @@ class Block 'ipb_expiry' => self::encodeExpiry( $this->mExpiry, $dbw ), 'ipb_range_start' => $this->mRangeStart, 'ipb_range_end' => $this->mRangeEnd, - 'ipb_deleted' => $this->mHideName + 'ipb_deleted' => $this->mHideName, + 'ipb_block_email' => $this->mBlockEmail ), 'Block::insert', array( 'IGNORE' ) ); $affected = $dbw->affectedRows(); diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 542b6b2ba7..9830af409b 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -971,9 +971,10 @@ $wgHitcounterUpdateFreq = 1; # Basic user rights and block settings $wgSysopUserBans = true; # Allow sysops to ban logged-in users -$wgSysopRangeBans = true; # Allow sysops to ban IP ranges -$wgAutoblockExpiry = 86400; # Number of seconds before autoblock entries expire +$wgSysopRangeBans = true; # Allow sysops to ban IP ranges +$wgAutoblockExpiry = 86400; # Number of seconds before autoblock entries expire $wgBlockAllowsUTEdit = false; # Blocks allow users to edit their own user talk page +$wgSysopEmailBans = true; # Allow sysops to ban users from accessing Emailuser # Pages anonymous user may see as an array, e.g.: # array ( "Main Page", "Special:Userlogin", "Wikipedia:Help"); diff --git a/includes/SpecialBlockip.php b/includes/SpecialBlockip.php index b434c0a02d..1211f3f130 100644 --- a/includes/SpecialBlockip.php +++ b/includes/SpecialBlockip.php @@ -43,6 +43,7 @@ function wfSpecialBlockip( $par ) { */ class IPBlockForm { var $BlockAddress, $BlockExpiry, $BlockReason; +# var $BlockEmail; function IPBlockForm( $par ) { global $wgRequest, $wgUser; @@ -60,6 +61,7 @@ class IPBlockForm { $this->BlockAnonOnly = $wgRequest->getBool( 'wpAnonOnly', $byDefault ); $this->BlockCreateAccount = $wgRequest->getBool( 'wpCreateAccount', $byDefault ); $this->BlockEnableAutoblock = $wgRequest->getBool( 'wpEnableAutoblock', $byDefault ); + $this->BlockEmail = $wgRequest->getBool( 'wpEmailBan', false ); # Re-check user's rights to hide names, very serious, defaults to 0 $this->BlockHideName = ( $wgRequest->getBool( 'wpHideName', 0 ) && $wgUser->isAllowed( 'hideuser' ) ) ? 1 : 0; } @@ -238,12 +240,27 @@ class IPBlockForm { "); } + + global $wgSysopEmailBans; + + if ( $wgSysopEmailBans ) { + $wgOut->addHTML(" + +   + + " . wfCheckLabel( wfMsgHtml( 'ipbemailban' ), + 'wpEmailBan', 'wpEmailBan', $this->BlockEmail, + array( 'tabindex' => '10' )) . " + + + "); + } $wgOut->addHTML("   " . Xml::submitButton( wfMsg( 'ipbsubmit' ), - array( 'name' => 'wpBlock', 'tabindex' => '10' ) ) . " + array( 'name' => 'wpBlock', 'tabindex' => '11' ) ) . " " . @@ -356,10 +373,10 @@ class IPBlockForm { # Create block # Note: for a user block, ipb_address is only for display purposes - $block = new Block( $this->BlockAddress, $userId, $wgUser->getID(), $reasonstr, wfTimestampNow(), 0, $expiry, $this->BlockAnonOnly, - $this->BlockCreateAccount, $this->BlockEnableAutoblock, $this->BlockHideName); + $this->BlockCreateAccount, $this->BlockEnableAutoblock, $this->BlockHideName, + $this->BlockEmail); if (wfRunHooks('BlockIp', array(&$block, &$wgUser))) { @@ -420,6 +437,8 @@ class IPBlockForm { $flags[] = 'nocreate'; if( !$this->BlockEnableAutoblock ) $flags[] = 'noautoblock'; + if ( $this->BlockEmail ) + $flags[] = 'noemail'; return implode( ',', $flags ); } diff --git a/includes/SpecialEmailuser.php b/includes/SpecialEmailuser.php index 900a2c328b..ca14bd6e5a 100644 --- a/includes/SpecialEmailuser.php +++ b/includes/SpecialEmailuser.php @@ -45,6 +45,13 @@ function wfSpecialEmailuser( $par ) { return; } + if ( $wgUser->isBlockedFromEmailUser() ) { + // User has been blocked from sending e-mail. Show the std blocked form. + wfDebug( "User is blocked from sending e-mail.\n" ); + $wgOut->blockedPage(); + return; + } + $f = new EmailUserForm( $nu ); if ( "success" == $action ) { diff --git a/includes/SpecialIpblocklist.php b/includes/SpecialIpblocklist.php index c947cb515a..3530642d5d 100644 --- a/includes/SpecialIpblocklist.php +++ b/includes/SpecialIpblocklist.php @@ -265,7 +265,7 @@ class IPUnblockForm { if( is_null( $msg ) ) { $msg = array(); $keys = array( 'infiniteblock', 'expiringblock', 'contribslink', 'unblocklink', - 'anononlyblock', 'createaccountblock', 'noautoblockblock' ); + 'anononlyblock', 'createaccountblock', 'noautoblockblock', 'emailblock' ); foreach( $keys as $key ) { $msg[$key] = wfMsgHtml( $key ); } @@ -306,6 +306,10 @@ class IPUnblockForm { $properties[] = $msg['noautoblockblock']; } + if ( $block->mBlockEmail && $block->mUser ) { + $properties[] = $msg['emailblock']; + } + $properties = implode( ', ', $properties ); $line = wfMsgReplaceArgs( $msg['blocklistline'], array( $formattedTime, $blocker, $target, $properties ) ); diff --git a/includes/User.php b/includes/User.php index f60c4298c6..9b62e2da42 100644 --- a/includes/User.php +++ b/includes/User.php @@ -2149,6 +2149,17 @@ class User { return $this->mBlock && $this->mBlock->mCreateAccount; } + /** + * Determine if the user is blocked from using Special:Emailuser. + * + * @public + * @return boolean + */ + function isBlockedFromEmailuser() { + $this->getBlockedStatus(); + return $this->mBlock && $this->mBlock->mBlockEmail; + } + function isAllowedToCreateAccount() { return $this->isAllowed( 'createaccount' ) && !$this->isBlockedFromCreateAccount(); } diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 0b4f7a8614..ab56af0430 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -939,7 +939,8 @@ Intended blockee: $7 You can contact $1 or another [[{{MediaWiki:grouppage-sysop}}|administrator]] to discuss the block. You cannot use the 'email this user' feature unless a valid email address is specified in your -[[Special:Preferences|account preferences]]. Your current IP address is $3, and the block ID is #$5. Please include either or both of these in any queries.", +[[Special:Preferences|account preferences]] and you have not been blocked from using it. +Your current IP address is $3, and the block ID is #$5. Please include either or both of these in any queries.", 'autoblockedtext' => 'Your IP address has been automatically blocked because it was used by another user, who was blocked by $1. The reason given is this: @@ -950,7 +951,8 @@ Expiry of block: $6 You may contact $1 or one of the other [[{{MediaWiki:grouppage-sysop}}|administrators]] to discuss the block. -Note that you may not use the "e-mail this user" feature unless you have a valid e-mail address registered in your [[Special:Preferences|user preferences]]. +Note that you may not use the "e-mail this user" feature unless you have a valid e-mail address +registered in your [[Special:Preferences|user preferences]] and you have not been blocked from using it. Your block ID is $5. Please include this ID in any queries you make.', 'blockedoriginalsource' => "The source of '''$1''' is shown below:", @@ -1967,6 +1969,7 @@ pages that were vandalized).', ** Unacceptable username', 'ipbanononly' => 'Block anonymous users only', 'ipbcreateaccount' => 'Prevent account creation', +'ipbemailban' => 'Prevent user from sending e-mail', 'ipbenableautoblock' => 'Automatically block the last IP address used by this user, and any subsequent IPs they try to edit from', 'ipbsubmit' => 'Block this user', 'ipbother' => 'Other time:', @@ -1998,6 +2001,7 @@ to a previously blocked IP address or username.', 'anononlyblock' => 'anon. only', 'noautoblockblock' => 'autoblock disabled', 'createaccountblock' => 'account creation blocked', +'emailblock' => 'e-mail blocked', 'ipblocklist-empty' => 'The blocklist is empty.', 'ipblocklist-no-results' => 'The requested IP address or username is not blocked.', 'blocklink' => 'block', @@ -2013,6 +2017,7 @@ the list of currently operational bans and blocks.', 'block-log-flags-anononly' => 'anonymous users only', 'block-log-flags-nocreate' => 'account creation disabled', 'block-log-flags-noautoblock' => 'autoblock disabled', +'block-log-flags-noemail' => 'e-mail blocked', 'range_block_disabled' => 'The sysop ability to create range blocks is disabled.', 'ipb_expiry_invalid' => 'Expiry time invalid.', 'ipb_already_blocked' => '"$1" is already blocked', diff --git a/maintenance/archives/patch-ipb_emailban.sql b/maintenance/archives/patch-ipb_emailban.sql new file mode 100644 index 0000000000..b990e4236e --- /dev/null +++ b/maintenance/archives/patch-ipb_emailban.sql @@ -0,0 +1,4 @@ +-- Add row for email blocks -- + +ALTER TABLE /*$wgDBprefix*/ipblocks + ADD ipb_block_email tinyint(1) NOT NULL default '0'; diff --git a/maintenance/tables.sql b/maintenance/tables.sql index 5818543ec3..0fc53aab05 100644 --- a/maintenance/tables.sql +++ b/maintenance/tables.sql @@ -622,6 +622,9 @@ CREATE TABLE /*$wgDBprefix*/ipblocks ( -- Flag for entries hidden from users and Sysops ipb_deleted bool NOT NULL default 0, + + -- Block prevents user from accessing Special:Emailuser + ipb_block_email bool NOT NULL default 0, PRIMARY KEY ipb_id (ipb_id), diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index e46ec69b9a..c2a69c9b6b 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -76,6 +76,7 @@ $wgNewFields = array( array( 'archive', 'ar_len', 'patch-ar_len.sql' ), array( 'revision', 'rev_parent_id', 'patch-rev_parent_id.sql' ), array( 'page_restrictions', 'pr_id', 'patch-page_restrictions_sortkey.sql' ), + array( 'ipblocks', 'ipb_block_email', 'patch-ipb_emailban.sql' ), ); function rename_table( $from, $to, $patch ) { -- 2.20.1