Index: trunk/extensions/AntiSpoof/AntiSpoof_body.php |
— | — | @@ -306,29 +306,6 @@ |
307 | 307 | return $out; |
308 | 308 | } |
309 | 309 | |
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 | | - |
333 | 310 | /** |
334 | 311 | * TODO: does too much in one routine, refactor... |
335 | 312 | * @param $testName |
— | — | @@ -344,10 +321,8 @@ |
345 | 322 | return array( "ERROR", wfMsg( 'antispoof-empty' ) ); |
346 | 323 | } |
347 | 324 | |
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' ) ); |
352 | 327 | } |
353 | 328 | |
354 | 329 | # Perform Unicode _compatibility_ decomposition |
— | — | @@ -355,31 +330,23 @@ |
356 | 331 | $testChars = self::stringToList( $testName ); |
357 | 332 | |
358 | 333 | # 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' ) ); |
363 | 336 | } |
364 | 337 | |
365 | 338 | # Check for this: should not happen in any valid Unicode string |
366 | 339 | if ( self::getScriptCode( $testChars[0] ) == "SCRIPT_COMBINING_MARKS" ) { |
367 | | - return self::badCharErr( 'antispoof-combining', $testChars[0] ); |
| 340 | + return array( "ERROR", wfMsg( 'antispoof-combining' ) ); |
368 | 341 | } |
369 | 342 | |
370 | 343 | # Strip all combining characters in order to crudely strip accents |
371 | 344 | # Note: NFKD normalization should have decomposed all accented chars earlier |
372 | 345 | $testChars = self::stripScript( $testChars, "SCRIPT_COMBINING_MARKS" ); |
373 | 346 | |
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' ) ); |
378 | 350 | } |
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 ); |
384 | 351 | |
385 | 352 | # We don't mind ASCII punctuation or digits |
386 | 353 | $testScripts = array_diff( $testScripts, |
Index: trunk/extensions/AntiSpoof/AntiSpoof.i18n.php |
— | — | @@ -15,14 +15,11 @@ |
16 | 16 | 'antispoof-conflict-bottom' => 'Please choose another name.', |
17 | 17 | 'antispoof-name-illegal' => 'The name "$1" is not allowed to prevent confusing or spoofed usernames: $2. |
18 | 18 | Please choose another name.', |
19 | | - 'antispoof-bad-char' => '"$1" ($2)', |
20 | | - 'antispoof-bad-char-non-printable' => '$1', |
21 | 19 | 'antispoof-badtype' => 'Bad data type', |
22 | 20 | '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', |
27 | 24 | 'antispoof-noletters' => 'Does not contain any letters', |
28 | 25 | 'antispoof-mixedscripts' => 'Contains incompatible mixed scripts', |
29 | 26 | 'antispoof-tooshort' => 'Canonicalized name too short', |
— | — | @@ -46,19 +43,11 @@ |
47 | 44 | 'antispoof-name-illegal' => 'Account creation error message because a user account creation rule was violated. Parameters: |
48 | 45 | * $1 is the username that someone wanted to create |
49 | 46 | * $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).', |
53 | 47 | 'antispoof-badtype' => 'Reason for failed account creation.', |
54 | 48 | '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.', |
63 | 52 | 'antispoof-noletters' => 'Reason for failed account creation.', |
64 | 53 | 'antispoof-mixedscripts' => 'Reason for failed account creation.', |
65 | 54 | 'antispoof-tooshort' => 'Reason for failed account creation.', |
Index: trunk/extensions/AntiSpoof/SpoofUser.php |
— | — | @@ -36,7 +36,7 @@ |
37 | 37 | |
38 | 38 | /** |
39 | 39 | * Get the normalized key form |
40 | | - * @return string|null |
| 40 | + * @return string|nuyll |
41 | 41 | */ |
42 | 42 | public function getNormalized() { |
43 | 43 | return $this->mNormalized; |
— | — | @@ -62,7 +62,7 @@ |
63 | 63 | * @return array empty if no conflict, or array containing conflicting usernames |
64 | 64 | */ |
65 | 65 | public function getConflicts() { |
66 | | - $dbr = static::getDBSlave(); |
| 66 | + $dbr = self::getDBSlave(); |
67 | 67 | |
68 | 68 | // Join against the user table to ensure that we skip stray |
69 | 69 | // entries left after an account is renamed or otherwise munged. |
— | — | @@ -122,7 +122,7 @@ |
123 | 123 | foreach ( $items as $item ) { |
124 | 124 | $fields[] = $item->insertFields(); |
125 | 125 | } |
126 | | - $dbw = static::getDBMaster(); |
| 126 | + $dbw = self::getDBMaster(); |
127 | 127 | $dbw->replace( |
128 | 128 | 'spoofuser', |
129 | 129 | array( 'su_name' ), |
— | — | @@ -135,7 +135,7 @@ |
136 | 136 | * @param $oldName |
137 | 137 | */ |
138 | 138 | public function update( $oldName ) { |
139 | | - $dbw = static::getDBMaster(); |
| 139 | + $dbw = self::getDBMaster(); |
140 | 140 | |
141 | 141 | if( $this->record() ) { |
142 | 142 | $dbw->delete( |
Index: trunk/extensions/AntiSpoof/AntiSpoofHooks.php |
— | — | @@ -52,7 +52,7 @@ |
53 | 53 | } |
54 | 54 | |
55 | 55 | $name = $user->getName(); |
56 | | - $spoof = static::makeSpoofUser( $name ); |
| 56 | + $spoof = self::makeSpoofUser( $name ); |
57 | 57 | if ( $spoof->isLegal() ) { |
58 | 58 | $normalized = $spoof->getNormalized(); |
59 | 59 | $conflicts = $spoof->getConflicts(); |
— | — | @@ -108,7 +108,7 @@ |
109 | 109 | * @return bool |
110 | 110 | */ |
111 | 111 | public static function asAddNewAccountHook( $user ) { |
112 | | - $spoof = static::makeSpoofUser( $user->getName() ); |
| 112 | + $spoof = self::makeSpoofUser( $user->getName() ); |
113 | 113 | $spoof->record(); |
114 | 114 | return true; |
115 | 115 | } |
— | — | @@ -123,7 +123,7 @@ |
124 | 124 | * @return bool |
125 | 125 | */ |
126 | 126 | public static function asAddRenameUserHook( $uid, $oldName, $newName ) { |
127 | | - $spoof = static::makeSpoofUser( $newName ); |
| 127 | + $spoof = self::makeSpoofUser( $newName ); |
128 | 128 | $spoof->update( $oldName ); |
129 | 129 | return true; |
130 | 130 | } |