MediaWiki r42240 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r42239‎ | r42240 (on ViewVC)‎ | r42241 >
Date:00:28, 20 October 2008
Author:soxred93
Status:old (Comments)
Tags:
Comment:
(bug 12232) AntiSpoof returns more than 1 result, and outputs it in a list. Patch by Brent G/OverlordQ
Modified paths:

Diff [purge]

Index: trunk/extensions/AntiSpoof/AntiSpoof.i18n.php
===================================================================
--- trunk/extensions/AntiSpoof/AntiSpoof.i18n.php	(revision 42239)
+++ trunk/extensions/AntiSpoof/AntiSpoof.i18n.php	(revision 42240)
@@ -9,8 +9,9 @@
 
 $messages['en'] = array(
 	'antispoof-desc'          => 'Blocks the creation of accounts with mixed-script, confusing and similar usernames',
-	'antispoof-name-conflict' => 'The name "$1" is too similar to the existing account "$2".
-Please choose another name.',
+	'antispoof-conflict-top'  => 'The name "$1" is too similar to {{PLURAL:$2|the existing account|the following $2 accounts}}:',
+	'antispoof-conflict-item' => '$1',
+	'antispoof-conflict-bottom' => 'Please choose another name.', 
 	'antispoof-name-illegal'  => 'The name "$1" is not allowed to prevent confusing or spoofed usernames: $2.
 Please choose another name.',
 	'antispoof-badtype'       => 'Bad data type',
Index: trunk/extensions/AntiSpoof/AntiSpoof.php
===================================================================
--- trunk/extensions/AntiSpoof/AntiSpoof.php	(revision 42239)
+++ trunk/extensions/AntiSpoof/AntiSpoof.php	(revision 42240)
@@ -81,13 +81,19 @@
 	$spoof = new SpoofUser( $name );
 	if( $spoof->isLegal() ) {
 		$normalized = $spoof->getNormalized();
-		$conflict = $spoof->getConflict();
-		if( $conflict === false ) {
+		$conflicts = $spoof->getConflicts();
+		if( empty($conflicts) ) {
 			wfDebugLog( 'antispoof', "{$mode}PASS new account '$name' [$normalized]" );
 		} else {
-			wfDebugLog( 'antispoof', "{$mode}CONFLICT new account '$name' [$normalized] spoofs '$conflict'" );
+			wfDebugLog( 'antispoof', "{$mode}CONFLICT new account '$name' [$normalized] spoofs " . implode( ',', $conflicts ) );
 			if( $active ) {
-				$message = wfMsg( 'antispoof-name-conflict', $name, $conflict );
+				$numConflicts = count( $conflicts );
+				$message = wfMsgExt( 'antispoof-conflict-top', array('parsemag'), $name, $numConflicts );
+				$message .= '<ul>';
+				foreach( $conflicts as $simUser ) {
+					$message .= '<li>' . wfMsg( 'antispoof-conflict-item', $simUser ) . '</li>';
+				}
+				$message .= '</ul>' . wfMsg( 'antispoof-conflict-bottom' );
 				return false;
 			}
 		}
Index: trunk/extensions/AntiSpoof/SpoofUser.php
===================================================================
--- trunk/extensions/AntiSpoof/SpoofUser.php	(revision 42239)
+++ trunk/extensions/AntiSpoof/SpoofUser.php	(revision 42240)
@@ -39,31 +39,30 @@
 	/**
 	 * Does the username pass Unicode legality and script-mixing checks?
 	 *
-	 * @return mixed false if no conflict, or string with conflicting username
+	 * @return array empty if no conflict, or array containing conflicting usernames
 	 */
-	public function getConflict() {
-		if( $this->isLegal() ) {
-			$dbr = wfGetDB( DB_SLAVE );
+	public function getConflicts() {
+		$dbr = wfGetDB( DB_SLAVE );
 
-			// Join against the user table to ensure that we skip stray
-			// entries left after an account is renamed or otherwise munged.
-			$row = $dbr->selectRow(
-				array( 'spoofuser', 'user' ),
-				array( 'user_name' ),
-				array(
-					'su_normalized' => $this->mNormalized,
-					'su_name=user_name',
-				),
-				__METHOD__ );
+		// Join against the user table to ensure that we skip stray
+		// entries left after an account is renamed or otherwise munged.
+		$spoofedUsers = $dbr->select(
+			array( 'spoofuser', 'user' ),
+			array( 'user_name' ),
+			array(
+				'su_normalized' => $this->mNormalized,
+				'su_name=user_name',
+			),
+			__METHOD__,
+			array(
+				'LIMIT' => 5
+			) );
 
-			if( $row ) {
-				return $row->user_name;
-			} else {
-				return false;
-			}
-		} else {
-			return false;
+		$spoofs = array();
+		while( $row = $dbr->fetchObject( $spoofedUsers ) ) {
+			array_push( $spoofs, $row->user_name );
 		}
+		return $spoofs;
 	}
 
 	/**

Follow-up revisions

Rev.Commit summaryAuthorDate
r42258Per r42240: 'antispoof-conflict-item' to be ignoredraymond07:19, 20 October 2008

Comments

#Comment by Brion VIBBER (Talk | contribs)   01:30, 20 October 2008

Looks good!

Status & tagging log

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