r37932 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37931‎ | r37932 | r37933 >
Date:03:39, 23 July 2008
Author:sql
Status:old
Tags:
Comment:
Try again at bug 12232 - Return more than one result on attempted spoofing.

Split the spoof message into five messages, one for each number of spoofs detected per the last revert. It's a little less flexible than I would
have liked, but, it works.
Modified paths:
  • /trunk/extensions/AntiSpoof/AntiSpoof.i18n.php (modified) (history)
  • /trunk/extensions/AntiSpoof/AntiSpoof.php (modified) (history)
  • /trunk/extensions/AntiSpoof/SpoofUser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AntiSpoof/AntiSpoof.i18n.php
@@ -9,8 +9,12 @@
1010
1111 $messages['en'] = array(
1212 'antispoof-desc' => 'Blocks the creation of accounts with mixed-script, confusing and similar usernames',
13 - 'antispoof-name-conflict' => 'The name "$1" is too similar to the existing account "$2".
 13+ 'antispoof-name-conflict' => 'The name "$1" is too similar to existing accounts: "$2".
1414 Please choose another name.',
 15+ 'antispoof-name-conflict2' => '$1 $2',
 16+ 'antispoof-name-conflict3' => '$1 $2 $3',
 17+ 'antispoof-name-conflict4' => '$1 $2 $3 $4',
 18+ 'antispoof-name-conflict5' => '$1 $2 $3 $4 $5',
1519 'antispoof-name-illegal' => 'The name "$1" is not allowed to prevent confusing or spoofed usernames: $2.
1620 Please choose another name.',
1721 'antispoof-badtype' => 'Bad data type',
Index: trunk/extensions/AntiSpoof/AntiSpoof.php
@@ -85,9 +85,33 @@
8686 if( $conflict === false ) {
8787 wfDebugLog( 'antispoof', "{$mode}PASS new account '$name' [$normalized]" );
8888 } else {
89 - wfDebugLog( 'antispoof', "{$mode}CONFLICT new account '$name' [$normalized] spoofs '$conflict'" );
 89+ wfDebugLog( 'antispoof', "{$mode}CONFLICT new account '$name' [$normalized] spoofs: '" . implode( ', ', $conflict ) . "'" );
9090 if( $active ) {
91 - $message = wfMsg( 'antispoof-name-conflict', $name, $conflict );
 91+ $numConflicts = count( $conflict );
 92+ switch ( $numConflicts ) {
 93+ case 1:
 94+ $message = wfMsg( 'antispoof-name-conflict', $name, $conflict['0'] );
 95+ break;
 96+ case 2:
 97+ $message = wfMsg( 'antispoof-name-conflict', $name,
 98+ wfMsg( 'antispoof-name-conflict2', $conflict['0'], $conflict['1'] ) );
 99+ break;
 100+ case 3:
 101+ $message = wfMsg( 'antispoof-name-conflict', $name,
 102+ wfMsg( 'antispoof-name-conflict3', $conflict['0'], $conflict['1'], $conflict['2'] ) );
 103+ break;
 104+ case 4:
 105+ $message = wfMsg( 'antispoof-name-conflict', $name,
 106+ wfMsg( 'antispoof-name-conflict4', $conflict['0'], $conflict['1'],
 107+ $conflict['2'], $conflict['3'] ) );
 108+ break;
 109+ case 5:
 110+ $message = wfMsg( 'antispoof-name-conflict', $name,
 111+ wfMsg( 'antispoof-name-conflict5', $conflict['0'], $conflict['1'], $conflict['2'],
 112+ $conflict['3'], $conflict['4'] ) );
 113+ break;
 114+ }
 115+
92116 return false;
93117 }
94118 }
Index: trunk/extensions/AntiSpoof/SpoofUser.php
@@ -39,7 +39,7 @@
4040 /**
4141 * Does the username pass Unicode legality and script-mixing checks?
4242 *
43 - * @return mixed false if no conflict, or string with conflicting username
 43+ * @return mixed false if no conflict, or array with up to five conflicting usernames
4444 */
4545 public function getConflict() {
4646 if( $this->isLegal() ) {
@@ -47,17 +47,26 @@
4848
4949 // Join against the user table to ensure that we skip stray
5050 // entries left after an account is renamed or otherwise munged.
51 - $row = $dbr->selectRow(
 51+ $spoofedUsers = $dbr->select(
5252 array( 'spoofuser', 'user' ),
5353 array( 'user_name' ),
5454 array(
5555 'su_normalized' => $this->mNormalized,
5656 'su_name=user_name',
5757 ),
58 - __METHOD__ );
 58+ __METHOD__,
 59+ array(
 60+ 'LIMIT' => 5
 61+ ) );
5962
60 - if( $row ) {
61 - return $row->user_name;
 63+ $spoofs = array();
 64+
 65+ while( $row = $dbr->fetchObject( $spoofedUsers ) ) {
 66+ array_push( $spoofs, $row->user_name );
 67+ }
 68+
 69+ if( count( $spoofs ) > 0 ) {
 70+ return $spoofs;
6271 } else {
6372 return false;
6473 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r37938Revert r37932, r37933 -- this is just downright bizarre. o_O...brion08:15, 23 July 2008
r42240(bug 12232) AntiSpoof returns more than 1 result, and outputs it in a list. P...soxred9300:28, 20 October 2008

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r36851bug 12232 - Return more than one result on attempted spoofing.demon17:03, 1 July 2008
r36964Revert r36851 for now (bug 12232 - Return more than one result on attempted s...brion00:00, 3 July 2008

Status & tagging log