https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114392
Revision: 114392 Author: catrope Date: 2012-03-21 19:12:39 +0000 (Wed, 21 Mar 2012) Log Message: ----------- 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 trunk/extensions/AntiSpoof/AntiSpoofHooks.php trunk/extensions/AntiSpoof/AntiSpoof_body.php trunk/extensions/AntiSpoof/SpoofUser.php Modified: trunk/extensions/AntiSpoof/AntiSpoof.i18n.php =================================================================== --- trunk/extensions/AntiSpoof/AntiSpoof.i18n.php 2012-03-21 18:56:52 UTC (rev 114391) +++ trunk/extensions/AntiSpoof/AntiSpoof.i18n.php 2012-03-21 19:12:39 UTC (rev 114392) @@ -15,14 +15,11 @@ '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-bad-char' => '"$1" ($2)', - 'antispoof-bad-char-non-printable' => '$1', 'antispoof-badtype' => 'Bad data type', 'antispoof-empty' => 'Empty string', - 'antispoof-blacklisted' => 'Contains blacklisted character $1', - 'antispoof-combining' => 'Begins with combining mark $1', - 'antispoof-unassigned' => 'Contains unassigned character $1', - 'antispoof-deprecated' => 'Contains deprecated character $1', + 'antispoof-blacklisted' => 'Contains blacklisted character', + 'antispoof-combining' => 'Begins with combining mark', + 'antispoof-unassigned' => 'Contains unassigned or deprecated character', 'antispoof-noletters' => 'Does not contain any letters', 'antispoof-mixedscripts' => 'Contains incompatible mixed scripts', 'antispoof-tooshort' => 'Canonicalized name too short', @@ -46,19 +43,11 @@ 'antispoof-name-illegal' => 'Account creation error message because a user account creation rule was violated. Parameters: * $1 is the username that someone wanted to create * $2 is the error message. One of {{msg-mw|antispoof-badtype}}, {{msg-mw|antispoof-empty}}, {{msg-mw|antispoof-blacklisted}} and others.', - '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: -* $1 is the bad character itself. -* $2 is the Unicode code point of bad character ("U+" followed by hex number).', 'antispoof-badtype' => 'Reason for failed account creation.', 'antispoof-empty' => 'Reason for failed account creation.', - 'antispoof-blacklisted' => 'Reason for failed account creation. Parameters: -* $1 — bad character designator (built with either antispoof-bad-char or …-non-printable).', - 'antispoof-combining' => 'Reason for failed account creation. Parameters: -* $1 — bad character designator (built with either antispoof-bad-char or …-non-printable).', - 'antispoof-unassigned' => 'Reason for failed account creation. Parameters: -* $1 — bad character designator (built with either antispoof-bad-char or …-non-printable).', - 'antispoof-deprecated' => 'Reason for failed account creation. Parameters: -* $1 — bad character designator (built with either antispoof-bad-char or …-non-printable).', + 'antispoof-blacklisted' => 'Reason for failed account creation.', + 'antispoof-combining' => 'Reason for failed account creation.', + 'antispoof-unassigned' => 'Reason for failed account creation.', 'antispoof-noletters' => 'Reason for failed account creation.', 'antispoof-mixedscripts' => 'Reason for failed account creation.', 'antispoof-tooshort' => 'Reason for failed account creation.', Modified: trunk/extensions/AntiSpoof/AntiSpoofHooks.php =================================================================== --- trunk/extensions/AntiSpoof/AntiSpoofHooks.php 2012-03-21 18:56:52 UTC (rev 114391) +++ trunk/extensions/AntiSpoof/AntiSpoofHooks.php 2012-03-21 19:12:39 UTC (rev 114392) @@ -52,7 +52,7 @@ } $name = $user->getName(); - $spoof = static::makeSpoofUser( $name ); + $spoof = self::makeSpoofUser( $name ); if ( $spoof->isLegal() ) { $normalized = $spoof->getNormalized(); $conflicts = $spoof->getConflicts(); @@ -108,7 +108,7 @@ * @return bool */ public static function asAddNewAccountHook( $user ) { - $spoof = static::makeSpoofUser( $user->getName() ); + $spoof = self::makeSpoofUser( $user->getName() ); $spoof->record(); return true; } @@ -123,7 +123,7 @@ * @return bool */ public static function asAddRenameUserHook( $uid, $oldName, $newName ) { - $spoof = static::makeSpoofUser( $newName ); + $spoof = self::makeSpoofUser( $newName ); $spoof->update( $oldName ); return true; } Modified: trunk/extensions/AntiSpoof/AntiSpoof_body.php =================================================================== --- trunk/extensions/AntiSpoof/AntiSpoof_body.php 2012-03-21 18:56:52 UTC (rev 114391) +++ trunk/extensions/AntiSpoof/AntiSpoof_body.php 2012-03-21 19:12:39 UTC (rev 114392) @@ -306,29 +306,6 @@ return $out; } - /* - * Helper function for checkUnicodeString: Return an error on a bad character. - * TODO: I would like to show Unicode character name, but it is not clear how to get it. - * @param $msgId -- string, message identifier. - * @param $point -- number, codepoint of the bad character. - * @return Formatted error message. - */ - private static function badCharErr( $msgId, $point ) { - $symbol = codepointToUtf8( $point ); - // Combining marks are combined with the previous character. If abusing character is a - // combining mark, prepend it with space to show them correctly. - if ( self::getScriptCode( $point ) == "SCRIPT_COMBINING_MARKS" ) { - $symbol = ' ' . $symbol; - } - $code = sprintf( 'U+%04X', $point ); - if ( preg_match( '/\A\p{C}\z/u', $symbol ) ) { - $char = wfMsg( 'antispoof-bad-char-non-printable', $code ); - } else { - $char = wfMsg( 'antispoof-bad-char', $symbol, $code ); - } - return array( "ERROR", wfMsg( $msgId, $char ) ); - } - /** * TODO: does too much in one routine, refactor... * @param $testName @@ -344,10 +321,8 @@ return array( "ERROR", wfMsg( 'antispoof-empty' ) ); } - foreach ( self::stringToList( $testName ) as $char ) { - if ( in_array( $char, self::$character_blacklist ) ) { - return self::badCharErr( 'antispoof-blacklisted', $char ); - } + if ( array_intersect( self::stringToList( $testName ), self::$character_blacklist ) ) { + return array( "ERROR", wfMsg( 'antispoof-blacklisted' ) ); } # Perform Unicode _compatibility_ decomposition @@ -355,31 +330,23 @@ $testChars = self::stringToList( $testName ); # Be paranoid: check again, just in case Unicode normalization code changes... - foreach ( $testChars as $char ) { - if ( in_array( $char, self::$character_blacklist ) ) { - return self::badCharErr( 'antispoof-blacklisted', $char ); - } + if ( array_intersect( $testChars, self::$character_blacklist ) ) { + return array( "ERROR", wfMsg( 'antispoof-blacklisted' ) ); } # Check for this: should not happen in any valid Unicode string if ( self::getScriptCode( $testChars[0] ) == "SCRIPT_COMBINING_MARKS" ) { - return self::badCharErr( 'antispoof-combining', $testChars[0] ); + return array( "ERROR", wfMsg( 'antispoof-combining' ) ); } # Strip all combining characters in order to crudely strip accents # Note: NFKD normalization should have decomposed all accented chars earlier $testChars = self::stripScript( $testChars, "SCRIPT_COMBINING_MARKS" ); - $testScripts = array_map( array( 'AntiSpoof', 'getScriptCode' ), $testChars ); - $unassigned = array_search( "SCRIPT_UNASSIGNED", $testScripts ); - if ( $unassigned !== False ) { - return self::badCharErr( 'antispoof-unassigned', $testChars[$unassigned] ); + $testScripts = array_unique( array_map( array( 'AntiSpoof', 'getScriptCode' ), $testChars ) ); + if ( in_array( "SCRIPT_UNASSIGNED", $testScripts ) || in_array( "SCRIPT_DEPRECATED", $testScripts ) ) { + return array( "ERROR", wfMsg( 'antispoof-unassigned' ) ); } - $deprecated = array_search( "SCRIPT_DEPRECTED", $testScripts ); - if ( $deprecated !== False ) { - return self::badCharErr( 'antispoof-deprecated', $testChars[$deprecated] ); - } - $testScripts = array_unique( $testScripts ); # We don't mind ASCII punctuation or digits $testScripts = array_diff( $testScripts, Modified: trunk/extensions/AntiSpoof/SpoofUser.php =================================================================== --- trunk/extensions/AntiSpoof/SpoofUser.php 2012-03-21 18:56:52 UTC (rev 114391) +++ trunk/extensions/AntiSpoof/SpoofUser.php 2012-03-21 19:12:39 UTC (rev 114392) @@ -36,7 +36,7 @@ /** * Get the normalized key form - * @return string|null + * @return string|nuyll */ public function getNormalized() { return $this->mNormalized; @@ -62,7 +62,7 @@ * @return array empty if no conflict, or array containing conflicting usernames */ public function getConflicts() { - $dbr = static::getDBSlave(); + $dbr = self::getDBSlave(); // Join against the user table to ensure that we skip stray // entries left after an account is renamed or otherwise munged. @@ -122,7 +122,7 @@ foreach ( $items as $item ) { $fields[] = $item->insertFields(); } - $dbw = static::getDBMaster(); + $dbw = self::getDBMaster(); $dbw->replace( 'spoofuser', array( 'su_name' ), @@ -135,7 +135,7 @@ * @param $oldName */ public function update( $oldName ) { - $dbw = static::getDBMaster(); + $dbw = self::getDBMaster(); if( $this->record() ) { $dbw->delete( _______________________________________________ MediaWiki-CVS mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs
