| Index: trunk/extensions/AntiSpoof/AntiSpoof_body.php |
| — | — | @@ -152,6 +152,10 @@ |
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | 155 | |
| | 156 | + /** |
| | 157 | + * @param $ch |
| | 158 | + * @return string |
| | 159 | + */ |
| 156 | 160 | private static function getScriptCode( $ch ) { |
| 157 | 161 | # Linear search: binary chop would be faster... |
| 158 | 162 | foreach ( self::$script_ranges as $range ) { |
| — | — | @@ -163,8 +167,13 @@ |
| 164 | 168 | return "SCRIPT_UNASSIGNED"; |
| 165 | 169 | } |
| 166 | 170 | |
| 167 | | - # From the name of a script, get a script descriptor, if valid, |
| 168 | | - # otherwise return None |
| | 171 | + /** |
| | 172 | + * From the name of a script, get a script descriptor, if valid, |
| | 173 | + * otherwise return None |
| | 174 | + * |
| | 175 | + * @param $name |
| | 176 | + * @return null|string |
| | 177 | + */ |
| 169 | 178 | private static function getScriptTag( $name ) { |
| 170 | 179 | $name = "SCRIPT_" . strtoupper( trim( $name ) ); |
| 171 | 180 | # Linear search |
| — | — | @@ -177,11 +186,21 @@ |
| 178 | 187 | return null; |
| 179 | 188 | } |
| 180 | 189 | |
| | 190 | + /** |
| | 191 | + * @param $aList array |
| | 192 | + * @param $bList array |
| | 193 | + * @return bool |
| | 194 | + */ |
| 181 | 195 | private static function isSubsetOf( $aList, $bList ) { |
| 182 | 196 | return count( array_diff( $aList, $bList ) ) == 0; |
| 183 | 197 | } |
| 184 | 198 | |
| 185 | | - # Is this an allowed script mixture? |
| | 199 | + /** |
| | 200 | + * Is this an allowed script mixture? |
| | 201 | + * |
| | 202 | + * @param $scriptList |
| | 203 | + * @return bool |
| | 204 | + */ |
| 186 | 205 | private static function isAllowedScriptCombination( $scriptList ) { |
| 187 | 206 | $allowedScriptCombinations = array( |
| 188 | 207 | array( "SCRIPT_COPTIC", "SCRIPT_COPTIC_EXTRAS" ), # Coptic, using old Greek chars |
| — | — | @@ -200,6 +219,8 @@ |
| 201 | 220 | |
| 202 | 221 | /** |
| 203 | 222 | * Convert string into array of Unicode code points as integers |
| | 223 | + * @param $str |
| | 224 | + * @return array |
| 204 | 225 | */ |
| 205 | 226 | public static function stringToList( $str ) { |
| 206 | 227 | $ar = array(); |
| — | — | @@ -213,6 +234,10 @@ |
| 214 | 235 | return $out; |
| 215 | 236 | } |
| 216 | 237 | |
| | 238 | + /** |
| | 239 | + * @param $list array |
| | 240 | + * @return string |
| | 241 | + */ |
| 217 | 242 | public static function listToString( $list ) { |
| 218 | 243 | $out = ''; |
| 219 | 244 | foreach ( $list as $cp ) { |
| — | — | @@ -221,10 +246,18 @@ |
| 222 | 247 | return $out; |
| 223 | 248 | } |
| 224 | 249 | |
| | 250 | + /** |
| | 251 | + * @param $a_list array |
| | 252 | + * @return string |
| | 253 | + */ |
| 225 | 254 | private static function hardjoin( $a_list ) { |
| 226 | 255 | return implode( '', $a_list ); |
| 227 | 256 | } |
| 228 | 257 | |
| | 258 | + /** |
| | 259 | + * @param $testName |
| | 260 | + * @return array |
| | 261 | + */ |
| 229 | 262 | public static function equivString( $testName ) { |
| 230 | 263 | $out = array(); |
| 231 | 264 | self::initEquivSet(); |
| — | — | @@ -238,6 +271,12 @@ |
| 239 | 272 | return $out; |
| 240 | 273 | } |
| 241 | 274 | |
| | 275 | + /** |
| | 276 | + * @param $text |
| | 277 | + * @param $pair |
| | 278 | + * @param $result |
| | 279 | + * @return array |
| | 280 | + */ |
| 242 | 281 | private static function mergePairs( $text, $pair, $result ) { |
| 243 | 282 | $out = array(); |
| 244 | 283 | for ( $i = 0; $i < count( $text ); $i++ ) { |
| — | — | @@ -251,6 +290,11 @@ |
| 252 | 291 | return $out; |
| 253 | 292 | } |
| 254 | 293 | |
| | 294 | + /** |
| | 295 | + * @param $text |
| | 296 | + * @param $script |
| | 297 | + * @return array |
| | 298 | + */ |
| 255 | 299 | private static function stripScript( $text, $script ) { |
| 256 | 300 | $scripts = array_map( array( 'AntiSpoof', 'getScriptCode' ), $text ); |
| 257 | 301 | $out = array(); |
| — | — | @@ -262,7 +306,11 @@ |
| 263 | 307 | return $out; |
| 264 | 308 | } |
| 265 | 309 | |
| 266 | | - # TODO: does too much in one routine, refactor... |
| | 310 | + /** |
| | 311 | + * TODO: does too much in one routine, refactor... |
| | 312 | + * @param $testName |
| | 313 | + * @return array |
| | 314 | + */ |
| 267 | 315 | public static function checkUnicodeString( $testName ) { |
| 268 | 316 | # Start with some sanity checking |
| 269 | 317 | if ( !is_string( $testName ) ) { |
| Index: trunk/extensions/AntiSpoof/generateEquivset.php |
| — | — | @@ -1,8 +1,8 @@ |
| 2 | 2 | <?php |
| 3 | 3 | |
| 4 | 4 | require_once ( getenv( 'MW_INSTALL_PATH' ) !== false |
| 5 | | - ? getenv( 'MW_INSTALL_PATH' ) . "/maintenance/commandLine.inc" |
| 6 | | - : dirname( __FILE__ ) . '/../../maintenance/commandLine.inc' ); |
| | 5 | + ? getenv( 'MW_INSTALL_PATH' ) . "/maintenance/commandLine.inc" |
| | 6 | + : dirname( __FILE__ ) . '/../../maintenance/commandLine.inc' ); |
| 7 | 7 | |
| 8 | 8 | $dir = dirname( __FILE__ ); |
| 9 | 9 | |
| Index: trunk/extensions/AntiSpoof/AntiSpoof.php |
| — | — | @@ -42,6 +42,10 @@ |
| 43 | 43 | $wgHooks['AddNewAccount'][] = 'asAddNewAccountHook'; |
| 44 | 44 | $wgHooks['RenameUserComplete'][] = 'asAddRenameUserHook'; |
| 45 | 45 | |
| | 46 | +/** |
| | 47 | + * @param $updater DatabaseUpdater |
| | 48 | + * @return bool |
| | 49 | + */ |
| 46 | 50 | function asUpdateSchema( $updater = null ) { |
| 47 | 51 | if ( $updater === null ) { |
| 48 | 52 | global $wgExtNewTables, $wgDBtype; |
| — | — | @@ -56,9 +60,10 @@ |
| 57 | 61 | } |
| 58 | 62 | |
| 59 | 63 | /** |
| 60 | | - * Hook for user creation form submissions. |
| 61 | | - * @param User $u |
| 62 | | - * @param string $message |
| | 64 | + * Can be used to cancel user account creation |
| | 65 | + * |
| | 66 | + * @param $user User |
| | 67 | + * @param $message string |
| 63 | 68 | * @return bool true to continue, false to abort user creation |
| 64 | 69 | */ |
| 65 | 70 | function asAbortNewAccountHook( $user, &$message ) { |
| — | — | @@ -109,20 +114,28 @@ |
| 110 | 115 | |
| 111 | 116 | /** |
| 112 | 117 | * Set the ignore spoof thingie |
| | 118 | + * (Manipulate the user create form) |
| | 119 | + * |
| | 120 | + * @param $template UsercreateTemplate |
| | 121 | + * @return bool |
| 113 | 122 | */ |
| 114 | 123 | function asUserCreateFormHook( &$template ) { |
| 115 | 124 | global $wgRequest, $wgAntiSpoofAccounts, $wgUser; |
| 116 | 125 | |
| 117 | | - |
| 118 | | - if ( $wgAntiSpoofAccounts && $wgUser->isAllowed( 'override-antispoof' ) ) |
| | 126 | + if ( $wgAntiSpoofAccounts && $wgUser->isAllowed( 'override-antispoof' ) ) { |
| 119 | 127 | $template->addInputItem( 'wpIgnoreAntiSpoof', |
| 120 | 128 | $wgRequest->getCheck( 'wpIgnoreAntiSpoof' ), |
| 121 | 129 | 'checkbox', 'antispoof-ignore' ); |
| | 130 | + } |
| 122 | 131 | return true; |
| 123 | 132 | } |
| 124 | 133 | |
| 125 | 134 | /** |
| 126 | 135 | * On new account creation, record the username's thing-bob. |
| | 136 | + * (Called after a user account is created) |
| | 137 | + * |
| | 138 | + * @param $user User |
| | 139 | + * @return bool |
| 127 | 140 | */ |
| 128 | 141 | function asAddNewAccountHook( $user ) { |
| 129 | 142 | $spoof = new SpoofUser( $user->getName() ); |
| — | — | @@ -132,6 +145,12 @@ |
| 133 | 146 | |
| 134 | 147 | /** |
| 135 | 148 | * On rename, remove the old entry and add the new |
| | 149 | + * (After a sucessful user rename) |
| | 150 | + * |
| | 151 | + * @param $uid |
| | 152 | + * @param $oldName |
| | 153 | + * @param $newName |
| | 154 | + * @return bool |
| 136 | 155 | */ |
| 137 | 156 | function asAddRenameUserHook( $uid, $oldName, $newName ) { |
| 138 | 157 | $spoof = new SpoofUser( $newName ); |
| Index: trunk/extensions/AntiSpoof/SpoofUser.php |
| — | — | @@ -68,11 +68,15 @@ |
| 69 | 69 | /** |
| 70 | 70 | * Record the username's normalized form into the database |
| 71 | 71 | * for later comparison of future names... |
| | 72 | + * @return bool |
| 72 | 73 | */ |
| 73 | 74 | public function record() { |
| 74 | 75 | return self::batchRecord( array( $this ) ); |
| 75 | 76 | } |
| 76 | 77 | |
| | 78 | + /** |
| | 79 | + * @return array |
| | 80 | + */ |
| 77 | 81 | private function insertFields() { |
| 78 | 82 | return array( |
| 79 | 83 | 'su_name' => $this->mName, |
| — | — | @@ -85,24 +89,28 @@ |
| 86 | 90 | /** |
| 87 | 91 | * Insert a batch of spoof normalization records into the database. |
| 88 | 92 | * @param $items array of SpoofUser |
| | 93 | + * @return bool |
| 89 | 94 | */ |
| 90 | 95 | public static function batchRecord( $items ) { |
| 91 | | - if ( count( $items ) ) { |
| 92 | | - $fields = array(); |
| 93 | | - foreach ( $items as $item ) { |
| 94 | | - $fields[] = $item->insertFields(); |
| 95 | | - } |
| 96 | | - $dbw = wfGetDB( DB_MASTER ); |
| 97 | | - return $dbw->replace( |
| 98 | | - 'spoofuser', |
| 99 | | - array( 'su_name' ), |
| 100 | | - $fields, |
| 101 | | - __METHOD__ ); |
| 102 | | - } else { |
| | 96 | + if ( !count( $items ) ) { |
| 103 | 97 | return false; |
| 104 | 98 | } |
| | 99 | + $fields = array(); |
| | 100 | + foreach ( $items as $item ) { |
| | 101 | + $fields[] = $item->insertFields(); |
| | 102 | + } |
| | 103 | + $dbw = wfGetDB( DB_MASTER ); |
| | 104 | + $dbw->replace( |
| | 105 | + 'spoofuser', |
| | 106 | + array( 'su_name' ), |
| | 107 | + $fields, |
| | 108 | + __METHOD__ ); |
| | 109 | + return true; |
| 105 | 110 | } |
| 106 | | - |
| | 111 | + |
| | 112 | + /** |
| | 113 | + * @param $oldName |
| | 114 | + */ |
| 107 | 115 | public function update( $oldName ) { |
| 108 | 116 | |
| 109 | 117 | $dbw = wfGetDB( DB_MASTER ); |