r102876 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102875‎ | r102876 | r102877 >
Date:03:59, 13 November 2011
Author:aaron
Status:deferred
Tags:
Comment:
* runAutoMaintenance() fixes:
** Use addQuotes() for DB query.
** Fixed acr_held condition as we want to catch requests that were never held too.
** Use proper DB functions rather than query().
* getUserAreaConfig() comment tweaks.
Modified paths:
  • /trunk/extensions/ConfirmAccount/backend/ConfirmAccount.class.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ConfirmAccount/backend/ConfirmAccount.class.php
@@ -4,40 +4,45 @@
55 * Move old stale requests to rejected list. Delete old rejected requests.
66 */
77 public static function runAutoMaintenance() {
8 - global $wgRejectedAccountMaxAge, $wgConfirmAccountFSRepos;
 8+ global $wgRejectedAccountMaxAge, $wgConfirmAccountRejectAge, $wgConfirmAccountFSRepos;
99
1010 $dbw = wfGetDB( DB_MASTER );
11 - # Select all items older than time $cutoff
12 - $cutoff = $dbw->timestamp( time() - $wgRejectedAccountMaxAge );
13 - $accountrequests = $dbw->tableName( 'account_requests' );
14 - $sql = "SELECT acr_storage_key,acr_id FROM $accountrequests WHERE acr_rejected < '{$cutoff}'";
15 - $res = $dbw->query( $sql );
 11+ $repo = new FSRepo( $wgConfirmAccountFSRepos['accountreqs'] );
1612
17 - $repo = new FSRepo( $wgConfirmAccountFSRepos['accountreqs'] );
 13+ # Select all items older than time $encCutoff
 14+ $encCutoff = $dbw->addQuotes( $dbw->timestamp( time() - $wgRejectedAccountMaxAge ) );
 15+ $res = $dbw->select( 'account_requests',
 16+ array( 'acr_id', 'acr_storage_key' ),
 17+ array( "acr_rejected < {$encCutoff}" ),
 18+ __METHOD__
 19+ );
 20+
1821 # Clear out any associated attachments and delete those rows
19 - foreach( $res as $row ) {
 22+ foreach ( $res as $row ) {
2023 $key = $row->acr_storage_key;
21 - if( $key ) {
 24+ if ( $key ) {
2225 $path = $repo->getZonePath( 'public' ).'/'.
2326 $key[0].'/'.$key[0].$key[1].'/'.$key[0].$key[1].$key[2].'/'.$key;
24 - if( $path && file_exists($path) ) {
 27+ if ( $path && file_exists($path) ) {
2528 unlink($path);
2629 }
2730 }
28 - $dbw->query( "DELETE FROM $accountrequests WHERE acr_id = {$row->acr_id}" );
 31+ $dbw->delete( 'account_requests', array( 'acr_id' => $row->acr_id ), __METHOD__ );
2932 }
3033
31 - # Select all items older than time $cutoff
32 - global $wgConfirmAccountRejectAge;
33 - $cutoff = $dbw->timestamp( time() - $wgConfirmAccountRejectAge );
 34+ # Select all items older than time $encCutoff
 35+ $encCutoff = $dbw->addQuotes( $dbw->timestamp( time() - $wgConfirmAccountRejectAge ) );
3436 # Old stale accounts will count as rejected. If the request was held, give it more time.
3537 $dbw->update( 'account_requests',
3638 array( 'acr_rejected' => $dbw->timestamp(),
3739 'acr_user' => 0, // dummy
3840 'acr_comment' => wfMsgForContent('confirmaccount-autorej'),
3941 'acr_deleted' => 1 ),
40 - array( "acr_rejected IS NULL", "acr_registration < '{$cutoff}'", "acr_held < '{$cutoff}'" ),
41 - __METHOD__ );
 42+ array( "acr_rejected IS NULL",
 43+ "acr_registration < {$encCutoff}",
 44+ "acr_held < {$encCutoff} OR acr_held IS NULL" ),
 45+ __METHOD__
 46+ );
4247
4348 # Clear cache for notice of how many account requests there are
4449 self::clearAccountRequestCountCache();
@@ -240,10 +245,12 @@
241246 }
242247
243248 /**
244 - * Get the category to add to this users page for working in
 249+ * Get the text to add to this users page for describing editing topics
 250+ * for each "area" a user can be in, as defined in MediaWiki:requestaccount-areas.
 251+ *
245252 * @return Array Associative mapping of the format:
246253 * (name => ('project' => x, 'userText' => y, 'grpUserText' => (request type => z)))
247 - * Any of the ultimative values can be empty string
 254+ * Any of the ultimate values can be the empty string
248255 */
249256 public static function getUserAreaConfig() {
250257 static $res; // process cache
@@ -271,9 +278,9 @@
272279 }
273280
274281 $res[$name]['grpUserText'] = array(); // userpage text for certain request types
275 - $categories = array_slice( $set, 3 ); // keys start from 0 now
 282+ $categories = array_slice( $set, 3 ); // keys start from 0 now in $categories
276283 foreach ( $categories as $i => $cat ) {
277 - $res[$name]['grpUserText'][$i] = trim( $cat );
 284+ $res[$name]['grpUserText'][$i] = trim( $cat ); // category for group $i
278285 }
279286 }
280287 }

Status & tagging log