r104207 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104206‎ | r104207 | r104208 >
Date:00:10, 25 November 2011
Author:reedy
Status:ok
Tags:
Comment:
Documentation

De-indent some code, actually return something too
Modified paths:
  • /trunk/extensions/AntiSpoof/AntiSpoof.php (modified) (history)
  • /trunk/extensions/AntiSpoof/AntiSpoof_body.php (modified) (history)
  • /trunk/extensions/AntiSpoof/SpoofUser.php (modified) (history)
  • /trunk/extensions/AntiSpoof/generateEquivset.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AntiSpoof/AntiSpoof_body.php
@@ -152,6 +152,10 @@
153153 }
154154 }
155155
 156+ /**
 157+ * @param $ch
 158+ * @return string
 159+ */
156160 private static function getScriptCode( $ch ) {
157161 # Linear search: binary chop would be faster...
158162 foreach ( self::$script_ranges as $range ) {
@@ -163,8 +167,13 @@
164168 return "SCRIPT_UNASSIGNED";
165169 }
166170
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+ */
169178 private static function getScriptTag( $name ) {
170179 $name = "SCRIPT_" . strtoupper( trim( $name ) );
171180 # Linear search
@@ -177,11 +186,21 @@
178187 return null;
179188 }
180189
 190+ /**
 191+ * @param $aList array
 192+ * @param $bList array
 193+ * @return bool
 194+ */
181195 private static function isSubsetOf( $aList, $bList ) {
182196 return count( array_diff( $aList, $bList ) ) == 0;
183197 }
184198
185 - # Is this an allowed script mixture?
 199+ /**
 200+ * Is this an allowed script mixture?
 201+ *
 202+ * @param $scriptList
 203+ * @return bool
 204+ */
186205 private static function isAllowedScriptCombination( $scriptList ) {
187206 $allowedScriptCombinations = array(
188207 array( "SCRIPT_COPTIC", "SCRIPT_COPTIC_EXTRAS" ), # Coptic, using old Greek chars
@@ -200,6 +219,8 @@
201220
202221 /**
203222 * Convert string into array of Unicode code points as integers
 223+ * @param $str
 224+ * @return array
204225 */
205226 public static function stringToList( $str ) {
206227 $ar = array();
@@ -213,6 +234,10 @@
214235 return $out;
215236 }
216237
 238+ /**
 239+ * @param $list array
 240+ * @return string
 241+ */
217242 public static function listToString( $list ) {
218243 $out = '';
219244 foreach ( $list as $cp ) {
@@ -221,10 +246,18 @@
222247 return $out;
223248 }
224249
 250+ /**
 251+ * @param $a_list array
 252+ * @return string
 253+ */
225254 private static function hardjoin( $a_list ) {
226255 return implode( '', $a_list );
227256 }
228257
 258+ /**
 259+ * @param $testName
 260+ * @return array
 261+ */
229262 public static function equivString( $testName ) {
230263 $out = array();
231264 self::initEquivSet();
@@ -238,6 +271,12 @@
239272 return $out;
240273 }
241274
 275+ /**
 276+ * @param $text
 277+ * @param $pair
 278+ * @param $result
 279+ * @return array
 280+ */
242281 private static function mergePairs( $text, $pair, $result ) {
243282 $out = array();
244283 for ( $i = 0; $i < count( $text ); $i++ ) {
@@ -251,6 +290,11 @@
252291 return $out;
253292 }
254293
 294+ /**
 295+ * @param $text
 296+ * @param $script
 297+ * @return array
 298+ */
255299 private static function stripScript( $text, $script ) {
256300 $scripts = array_map( array( 'AntiSpoof', 'getScriptCode' ), $text );
257301 $out = array();
@@ -262,7 +306,11 @@
263307 return $out;
264308 }
265309
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+ */
267315 public static function checkUnicodeString( $testName ) {
268316 # Start with some sanity checking
269317 if ( !is_string( $testName ) ) {
Index: trunk/extensions/AntiSpoof/generateEquivset.php
@@ -1,8 +1,8 @@
22 <?php
33
44 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' );
77
88 $dir = dirname( __FILE__ );
99
Index: trunk/extensions/AntiSpoof/AntiSpoof.php
@@ -42,6 +42,10 @@
4343 $wgHooks['AddNewAccount'][] = 'asAddNewAccountHook';
4444 $wgHooks['RenameUserComplete'][] = 'asAddRenameUserHook';
4545
 46+/**
 47+ * @param $updater DatabaseUpdater
 48+ * @return bool
 49+ */
4650 function asUpdateSchema( $updater = null ) {
4751 if ( $updater === null ) {
4852 global $wgExtNewTables, $wgDBtype;
@@ -56,9 +60,10 @@
5761 }
5862
5963 /**
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
6368 * @return bool true to continue, false to abort user creation
6469 */
6570 function asAbortNewAccountHook( $user, &$message ) {
@@ -109,20 +114,28 @@
110115
111116 /**
112117 * Set the ignore spoof thingie
 118+ * (Manipulate the user create form)
 119+ *
 120+ * @param $template UsercreateTemplate
 121+ * @return bool
113122 */
114123 function asUserCreateFormHook( &$template ) {
115124 global $wgRequest, $wgAntiSpoofAccounts, $wgUser;
116125
117 -
118 - if ( $wgAntiSpoofAccounts && $wgUser->isAllowed( 'override-antispoof' ) )
 126+ if ( $wgAntiSpoofAccounts && $wgUser->isAllowed( 'override-antispoof' ) ) {
119127 $template->addInputItem( 'wpIgnoreAntiSpoof',
120128 $wgRequest->getCheck( 'wpIgnoreAntiSpoof' ),
121129 'checkbox', 'antispoof-ignore' );
 130+ }
122131 return true;
123132 }
124133
125134 /**
126135 * 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
127140 */
128141 function asAddNewAccountHook( $user ) {
129142 $spoof = new SpoofUser( $user->getName() );
@@ -132,6 +145,12 @@
133146
134147 /**
135148 * 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
136155 */
137156 function asAddRenameUserHook( $uid, $oldName, $newName ) {
138157 $spoof = new SpoofUser( $newName );
Index: trunk/extensions/AntiSpoof/SpoofUser.php
@@ -68,11 +68,15 @@
6969 /**
7070 * Record the username's normalized form into the database
7171 * for later comparison of future names...
 72+ * @return bool
7273 */
7374 public function record() {
7475 return self::batchRecord( array( $this ) );
7576 }
7677
 78+ /**
 79+ * @return array
 80+ */
7781 private function insertFields() {
7882 return array(
7983 'su_name' => $this->mName,
@@ -85,24 +89,28 @@
8690 /**
8791 * Insert a batch of spoof normalization records into the database.
8892 * @param $items array of SpoofUser
 93+ * @return bool
8994 */
9095 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 ) ) {
10397 return false;
10498 }
 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;
105110 }
106 -
 111+
 112+ /**
 113+ * @param $oldName
 114+ */
107115 public function update( $oldName ) {
108116
109117 $dbw = wfGetDB( DB_MASTER );

Status & tagging log