r114392 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114391‎ | r114392 | r114393 >
Date:19:12, 21 March 2012
Author:catrope
Status:ok
Tags:
Comment:
Revert r111688, r111690, r114156. Unreviewed revisions in AntiSpoof.

All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
Modified paths:
  • /trunk/extensions/AntiSpoof/AntiSpoof.i18n.php (modified) (history)
  • /trunk/extensions/AntiSpoof/AntiSpoofHooks.php (modified) (history)
  • /trunk/extensions/AntiSpoof/AntiSpoof_body.php (modified) (history)
  • /trunk/extensions/AntiSpoof/SpoofUser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AntiSpoof/AntiSpoof_body.php
@@ -306,29 +306,6 @@
307307 return $out;
308308 }
309309
310 - /*
311 - * Helper function for checkUnicodeString: Return an error on a bad character.
312 - * TODO: I would like to show Unicode character name, but it is not clear how to get it.
313 - * @param $msgId -- string, message identifier.
314 - * @param $point -- number, codepoint of the bad character.
315 - * @return Formatted error message.
316 - */
317 - private static function badCharErr( $msgId, $point ) {
318 - $symbol = codepointToUtf8( $point );
319 - // Combining marks are combined with the previous character. If abusing character is a
320 - // combining mark, prepend it with space to show them correctly.
321 - if ( self::getScriptCode( $point ) == "SCRIPT_COMBINING_MARKS" ) {
322 - $symbol = ' ' . $symbol;
323 - }
324 - $code = sprintf( 'U+%04X', $point );
325 - if ( preg_match( '/\A\p{C}\z/u', $symbol ) ) {
326 - $char = wfMsg( 'antispoof-bad-char-non-printable', $code );
327 - } else {
328 - $char = wfMsg( 'antispoof-bad-char', $symbol, $code );
329 - }
330 - return array( "ERROR", wfMsg( $msgId, $char ) );
331 - }
332 -
333310 /**
334311 * TODO: does too much in one routine, refactor...
335312 * @param $testName
@@ -344,10 +321,8 @@
345322 return array( "ERROR", wfMsg( 'antispoof-empty' ) );
346323 }
347324
348 - foreach ( self::stringToList( $testName ) as $char ) {
349 - if ( in_array( $char, self::$character_blacklist ) ) {
350 - return self::badCharErr( 'antispoof-blacklisted', $char );
351 - }
 325+ if ( array_intersect( self::stringToList( $testName ), self::$character_blacklist ) ) {
 326+ return array( "ERROR", wfMsg( 'antispoof-blacklisted' ) );
352327 }
353328
354329 # Perform Unicode _compatibility_ decomposition
@@ -355,31 +330,23 @@
356331 $testChars = self::stringToList( $testName );
357332
358333 # Be paranoid: check again, just in case Unicode normalization code changes...
359 - foreach ( $testChars as $char ) {
360 - if ( in_array( $char, self::$character_blacklist ) ) {
361 - return self::badCharErr( 'antispoof-blacklisted', $char );
362 - }
 334+ if ( array_intersect( $testChars, self::$character_blacklist ) ) {
 335+ return array( "ERROR", wfMsg( 'antispoof-blacklisted' ) );
363336 }
364337
365338 # Check for this: should not happen in any valid Unicode string
366339 if ( self::getScriptCode( $testChars[0] ) == "SCRIPT_COMBINING_MARKS" ) {
367 - return self::badCharErr( 'antispoof-combining', $testChars[0] );
 340+ return array( "ERROR", wfMsg( 'antispoof-combining' ) );
368341 }
369342
370343 # Strip all combining characters in order to crudely strip accents
371344 # Note: NFKD normalization should have decomposed all accented chars earlier
372345 $testChars = self::stripScript( $testChars, "SCRIPT_COMBINING_MARKS" );
373346
374 - $testScripts = array_map( array( 'AntiSpoof', 'getScriptCode' ), $testChars );
375 - $unassigned = array_search( "SCRIPT_UNASSIGNED", $testScripts );
376 - if ( $unassigned !== False ) {
377 - return self::badCharErr( 'antispoof-unassigned', $testChars[$unassigned] );
 347+ $testScripts = array_unique( array_map( array( 'AntiSpoof', 'getScriptCode' ), $testChars ) );
 348+ if ( in_array( "SCRIPT_UNASSIGNED", $testScripts ) || in_array( "SCRIPT_DEPRECATED", $testScripts ) ) {
 349+ return array( "ERROR", wfMsg( 'antispoof-unassigned' ) );
378350 }
379 - $deprecated = array_search( "SCRIPT_DEPRECTED", $testScripts );
380 - if ( $deprecated !== False ) {
381 - return self::badCharErr( 'antispoof-deprecated', $testChars[$deprecated] );
382 - }
383 - $testScripts = array_unique( $testScripts );
384351
385352 # We don't mind ASCII punctuation or digits
386353 $testScripts = array_diff( $testScripts,
Index: trunk/extensions/AntiSpoof/AntiSpoof.i18n.php
@@ -15,14 +15,11 @@
1616 'antispoof-conflict-bottom' => 'Please choose another name.',
1717 'antispoof-name-illegal' => 'The name "$1" is not allowed to prevent confusing or spoofed usernames: $2.
1818 Please choose another name.',
19 - 'antispoof-bad-char' => '"$1" ($2)',
20 - 'antispoof-bad-char-non-printable' => '$1',
2119 'antispoof-badtype' => 'Bad data type',
2220 'antispoof-empty' => 'Empty string',
23 - 'antispoof-blacklisted' => 'Contains blacklisted character $1',
24 - 'antispoof-combining' => 'Begins with combining mark $1',
25 - 'antispoof-unassigned' => 'Contains unassigned character $1',
26 - 'antispoof-deprecated' => 'Contains deprecated character $1',
 21+ 'antispoof-blacklisted' => 'Contains blacklisted character',
 22+ 'antispoof-combining' => 'Begins with combining mark',
 23+ 'antispoof-unassigned' => 'Contains unassigned or deprecated character',
2724 'antispoof-noletters' => 'Does not contain any letters',
2825 'antispoof-mixedscripts' => 'Contains incompatible mixed scripts',
2926 'antispoof-tooshort' => 'Canonicalized name too short',
@@ -46,19 +43,11 @@
4744 'antispoof-name-illegal' => 'Account creation error message because a user account creation rule was violated. Parameters:
4845 * $1 is the username that someone wanted to create
4946 * $2 is the error message. One of {{msg-mw|antispoof-badtype}}, {{msg-mw|antispoof-empty}}, {{msg-mw|antispoof-blacklisted}} and others.',
50 - 'antispoof-bad-char' => 'It is not a complete message but a template for designator of a bad character, so localization can format it properly. Parameters:
51 -* $1 is the bad character itself.
52 -* $2 is the Unicode code point of bad character ("U+" followed by hex number).',
5347 'antispoof-badtype' => 'Reason for failed account creation.',
5448 'antispoof-empty' => 'Reason for failed account creation.',
55 - 'antispoof-blacklisted' => 'Reason for failed account creation. Parameters:
56 -* $1 — bad character designator (built with either antispoof-bad-char or …-non-printable).',
57 - 'antispoof-combining' => 'Reason for failed account creation. Parameters:
58 -* $1 — bad character designator (built with either antispoof-bad-char or …-non-printable).',
59 - 'antispoof-unassigned' => 'Reason for failed account creation. Parameters:
60 -* $1 — bad character designator (built with either antispoof-bad-char or …-non-printable).',
61 - 'antispoof-deprecated' => 'Reason for failed account creation. Parameters:
62 -* $1 — bad character designator (built with either antispoof-bad-char or …-non-printable).',
 49+ 'antispoof-blacklisted' => 'Reason for failed account creation.',
 50+ 'antispoof-combining' => 'Reason for failed account creation.',
 51+ 'antispoof-unassigned' => 'Reason for failed account creation.',
6352 'antispoof-noletters' => 'Reason for failed account creation.',
6453 'antispoof-mixedscripts' => 'Reason for failed account creation.',
6554 'antispoof-tooshort' => 'Reason for failed account creation.',
Index: trunk/extensions/AntiSpoof/SpoofUser.php
@@ -36,7 +36,7 @@
3737
3838 /**
3939 * Get the normalized key form
40 - * @return string|null
 40+ * @return string|nuyll
4141 */
4242 public function getNormalized() {
4343 return $this->mNormalized;
@@ -62,7 +62,7 @@
6363 * @return array empty if no conflict, or array containing conflicting usernames
6464 */
6565 public function getConflicts() {
66 - $dbr = static::getDBSlave();
 66+ $dbr = self::getDBSlave();
6767
6868 // Join against the user table to ensure that we skip stray
6969 // entries left after an account is renamed or otherwise munged.
@@ -122,7 +122,7 @@
123123 foreach ( $items as $item ) {
124124 $fields[] = $item->insertFields();
125125 }
126 - $dbw = static::getDBMaster();
 126+ $dbw = self::getDBMaster();
127127 $dbw->replace(
128128 'spoofuser',
129129 array( 'su_name' ),
@@ -135,7 +135,7 @@
136136 * @param $oldName
137137 */
138138 public function update( $oldName ) {
139 - $dbw = static::getDBMaster();
 139+ $dbw = self::getDBMaster();
140140
141141 if( $this->record() ) {
142142 $dbw->delete(
Index: trunk/extensions/AntiSpoof/AntiSpoofHooks.php
@@ -52,7 +52,7 @@
5353 }
5454
5555 $name = $user->getName();
56 - $spoof = static::makeSpoofUser( $name );
 56+ $spoof = self::makeSpoofUser( $name );
5757 if ( $spoof->isLegal() ) {
5858 $normalized = $spoof->getNormalized();
5959 $conflicts = $spoof->getConflicts();
@@ -108,7 +108,7 @@
109109 * @return bool
110110 */
111111 public static function asAddNewAccountHook( $user ) {
112 - $spoof = static::makeSpoofUser( $user->getName() );
 112+ $spoof = self::makeSpoofUser( $user->getName() );
113113 $spoof->record();
114114 return true;
115115 }
@@ -123,7 +123,7 @@
124124 * @return bool
125125 */
126126 public static function asAddRenameUserHook( $uid, $oldName, $newName ) {
127 - $spoof = static::makeSpoofUser( $newName );
 127+ $spoof = self::makeSpoofUser( $newName );
128128 $spoof->update( $oldName );
129129 return true;
130130 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r111688Fix targets by using LSBreedy22:09, 16 February 2012
r111690Few more LSB for good measurereedy22:14, 16 February 2012
r114156Fix for bug 12500, almost reviewed there.van-de-bugger17:15, 19 March 2012

Status & tagging log