MediaWiki r22816 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r22815‎ | r22816 (on ViewVC)‎ | r22817 >
Date:17:31, 7 June 2007
Author:amidaniel
Status:old
Tags:
Comment:
(bug 7997) Added ability to Special:Blockip to block users from using Special:Emailuser.
Modified paths:

Diff [purge]

Index: trunk/phase3/maintenance/archives/patch-ipb_emailban.sql
===================================================================
--- trunk/phase3/maintenance/archives/patch-ipb_emailban.sql	(revision 0)
+++ trunk/phase3/maintenance/archives/patch-ipb_emailban.sql	(revision 22816)
@@ -0,0 +1,4 @@
+-- Add row for email blocks --
+
+ALTER TABLE /*$wgDBprefix*/ipblocks
+	ADD ipb_block_email tinyint(1) NOT NULL default '0';

Property changes on: trunk/phase3/maintenance/archives/patch-ipb_emailban.sql
___________________________________________________________________
Added: svn:eol-style
   + native

Index: trunk/phase3/maintenance/updaters.inc
===================================================================
--- trunk/phase3/maintenance/updaters.inc	(revision 22815)
+++ trunk/phase3/maintenance/updaters.inc	(revision 22816)
@@ -76,6 +76,7 @@
 	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 ) {
Index: trunk/phase3/maintenance/tables.sql
===================================================================
--- trunk/phase3/maintenance/tables.sql	(revision 22815)
+++ trunk/phase3/maintenance/tables.sql	(revision 22816)
@@ -622,6 +622,9 @@
 
   -- 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),
 
Index: trunk/phase3/includes/User.php
===================================================================
--- trunk/phase3/includes/User.php	(revision 22815)
+++ trunk/phase3/includes/User.php	(revision 22816)
@@ -2149,6 +2149,17 @@
 		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();
 	}
Index: trunk/phase3/includes/SpecialBlockip.php
===================================================================
--- trunk/phase3/includes/SpecialBlockip.php	(revision 22815)
+++ trunk/phase3/includes/SpecialBlockip.php	(revision 22816)
@@ -43,6 +43,7 @@
  */
 class IPBlockForm {
 	var $BlockAddress, $BlockExpiry, $BlockReason;
+#	var $BlockEmail;
 
 	function IPBlockForm( $par ) {
 		global $wgRequest, $wgUser;
@@ -60,6 +61,7 @@
 		$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 @@
 			</tr>
 			");
 		}
+
+		global $wgSysopEmailBans;
+
+		if ( $wgSysopEmailBans ) {
+			$wgOut->addHTML("
+			<tr>
+			<td>&nbsp;</td>
+				<td>
+					" . wfCheckLabel( wfMsgHtml( 'ipbemailban' ),
+							'wpEmailBan', 'wpEmailBan', $this->BlockEmail,
+								array( 'tabindex' => '10' )) . "
+				</td>
+			</tr>
+			");
+		}
 		$wgOut->addHTML("
 		<tr>
 			<td style='padding-top: 1em'>&nbsp;</td>
 			<td style='padding-top: 1em'>
 				" . Xml::submitButton( wfMsg( 'ipbsubmit' ),
-							array( 'name' => 'wpBlock', 'tabindex' => '10' ) ) . "
+							array( 'name' => 'wpBlock', 'tabindex' => '11' ) ) . "
 			</td>
 		</tr>
 	</table>" .
@@ -356,10 +373,10 @@
 
 		# 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 @@
 			$flags[] = 'nocreate';
 		if( !$this->BlockEnableAutoblock )
 			$flags[] = 'noautoblock';
+		if ( $this->BlockEmail )
+			$flags[] = 'noemail';
 		return implode( ',', $flags );
 	}
 
Index: trunk/phase3/includes/SpecialEmailuser.php
===================================================================
--- trunk/phase3/includes/SpecialEmailuser.php	(revision 22815)
+++ trunk/phase3/includes/SpecialEmailuser.php	(revision 22816)
@@ -45,6 +45,13 @@
 		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 ) {
Index: trunk/phase3/includes/SpecialIpblocklist.php
===================================================================
--- trunk/phase3/includes/SpecialIpblocklist.php	(revision 22815)
+++ trunk/phase3/includes/SpecialIpblocklist.php	(revision 22816)
@@ -265,7 +265,7 @@
 		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 @@
 			$properties[] = $msg['noautoblockblock'];
 		}
 
+		if ( $block->mBlockEmail && $block->mUser ) {
+			$properties[] = $msg['emailblock'];
+		}
+
 		$properties = implode( ', ', $properties );
 
 		$line = wfMsgReplaceArgs( $msg['blocklistline'], array( $formattedTime, $blocker, $target, $properties ) );
Index: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 22815)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 22816)
@@ -971,9 +971,10 @@
 
 # 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");
Index: trunk/phase3/includes/Block.php
===================================================================
--- trunk/phase3/includes/Block.php	(revision 22815)
+++ trunk/phase3/includes/Block.php	(revision 22816)
@@ -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 @@
 
 	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 @@
 		$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 @@
 		$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 @@
 		$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 @@
 		# 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 @@
 				'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();
Index: trunk/phase3/languages/messages/MessagesEn.php
===================================================================
--- trunk/phase3/languages/messages/MessagesEn.php	(revision 22815)
+++ trunk/phase3/languages/messages/MessagesEn.php	(revision 22816)
@@ -939,7 +939,8 @@
 
 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 @@
 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 @@
 ** 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 @@
 '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 @@
 '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',
Index: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES	(revision 22815)
+++ trunk/phase3/RELEASE-NOTES	(revision 22816)
@@ -64,6 +64,9 @@
 * 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 ==
 

Follow-up revisions

Rev.Commit summaryAuthorDate
r22826* (bug 8989) Blacklist 'mhtml' and 'mht' files from upload...robchurch20:49, 7 June 2007
r22857Merged revisions 22811-22855 via svnmerge from...david00:48, 9 June 2007

Status & tagging log

  • 15:16, 12 September 2011 Meno25 (Talk | contribs) changed the status of r22816 [removed: ok added: old]
Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox