r52514 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52513‎ | r52514 | r52515 >
Date:15:47, 28 June 2009
Author:aaron
Status:deferred
Tags:
Comment:
*Updated ConfirmAccount to use FileRepo (bug 19084)
*Increased prune rate
*A few other minor fixes
Modified paths:
  • /trunk/extensions/ConfirmAccount/ConfirmAccount_body.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/RequestAccount_body.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/SpecialConfirmAccount.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/UserCredentials_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ConfirmAccount/UserCredentials_body.php
@@ -183,7 +183,7 @@
184184 * Show a private file requested by the visitor.
185185 */
186186 function showFile( $key ) {
187 - global $wgOut, $wgRequest;
 187+ global $wgOut, $wgRequest, $wgConfirmAccountFSRepos, $IP;
188188 $wgOut->disable();
189189
190190 # We mustn't allow the output to be Squid cached, otherwise
@@ -194,12 +194,11 @@
195195 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
196196 $wgRequest->response()->header( 'Pragma: no-cache' );
197197
198 - $store = FileStore::get( 'accountcreds' );
199 - if ( !$store ) {
200 - wfDebug( __METHOD__ . ": invalid storage group '{$store}'.\n" );
201 - return false;
202 - }
203 - $store->stream( $key );
 198+ require_once( "$IP/includes/StreamFile.php" );
 199+ $repo = new FSRepo( $wgConfirmAccountFSRepos['accountcreds'] );
 200+ $path = $repo->getZonePath( 'public' ).'/'.
 201+ $key[0].'/'.$key[0].$key[1].'/'.$key[0].$key[1].$key[2].'/'.$key;
 202+ wfStreamFile( $path );
204203 }
205204
206205 function getRequest() {
Index: trunk/extensions/ConfirmAccount/SpecialConfirmAccount.php
@@ -77,17 +77,30 @@
7878 # inject catpchas for requests too?
7979 $wgConfirmAccountCaptchas = true;
8080
81 -# Location of attached files for pending requests
8281 $wgAllowAccountRequestFiles = true;
8382 $wgAccountRequestExts = array( 'txt', 'pdf', 'doc', 'latex', 'rtf', 'text', 'wp', 'wpd', 'sxw' );
84 -$wgFileStore['accountreqs']['directory'] = "{$wgUploadDirectory}/accountreqs";
85 -$wgFileStore['accountreqs']['url'] = null; // Private
86 -$wgFileStore['accountreqs']['hash'] = 3;
8783
88 -# Location of credential files
89 -$wgFileStore['accountcreds']['directory'] = "{$wgUploadDirectory}/accountcreds";
90 -$wgFileStore['accountcreds']['url'] = null; // Private
91 -$wgFileStore['accountcreds']['hash'] = 3;
 84+# Storage repos. B/C for when this used FileStore.
 85+$wgConfirmAccountFSRepos = array(
 86+ 'accountreqs' => array( # Location of attached files for pending requests
 87+ 'name' => 'accountreqs',
 88+ 'directory' => isset($wgFileStore['accountreqs']) ?
 89+ $wgFileStore['accountreqs']['directory'] : "{$IP}/images/accountreqs",
 90+ 'url' => isset($wgFileStore['accountreqs']) ?
 91+ $wgFileStore['accountreqs']['url'] : null,
 92+ 'hashLevels' => isset($wgFileStore['accountreqs']) ?
 93+ $wgFileStore['accountreqs']['hash'] : 3
 94+ ),
 95+ 'accountcreds' => array( # Location of credential files
 96+ 'name' => 'accountcreds',
 97+ 'directory' => isset($wgFileStore['accountcreds']) ?
 98+ $wgFileStore['accountcreds']['directory'] : "{$IP}/images/accountcreds",
 99+ 'url' => isset($wgFileStore['accountcreds']) ?
 100+ $wgFileStore['accountcreds']['url'] : null,
 101+ 'hashLevels' => isset($wgFileStore['accountcreds']) ?
 102+ $wgFileStore['accountcreds']['hash'] : 3
 103+ )
 104+);
92105
93106 # Restrict account creation
94107 $wgGroupPermissions['*']['createaccount'] = false;
Index: trunk/extensions/ConfirmAccount/RequestAccount_body.php
@@ -342,26 +342,12 @@
343343 return false;
344344 }
345345 # Start a transaction, move file from temp to account request directory.
346 - $transaction = new FSTransaction();
347 - if ( !FileStore::lock() ) {
348 - wfDebug( __METHOD__ . ": failed to acquire file store lock, aborting\n" );
349 - return false;
350 - }
351 - $store = FileStore::get( 'accountreqs' );
352 - if ( !$store ) {
353 - wfDebug( __METHOD__ . ": invalid storage group '{$store}'.\n" );
354 - return false;
355 - }
356 -
357 - $key = FileStore::calculateKey( $this->mTempPath, $finalExt );
358 -
359 - $transaction->add( $store->insert( $key, $this->mTempPath, FileStore::DELETE_ORIGINAL ) );
360 - if ( $transaction === false ) {
361 - // Failed to move?
362 - wfDebug( __METHOD__ . ": import to file store failed, aborting\n" );
363 - throw new MWException( "Could not insert file {$this->mTempPath}" );
364 - return false;
365 - }
 346+ global $wgConfirmAccountFSRepos;
 347+ $repo = new FSRepo( $wgConfirmAccountFSRepos['accountreqs'] );
 348+ $key = sha1_file($this->mTempPath) . '.' . $finalExt;
 349+ $pathRel = $key[0].'/'.$key[0].$key[1].'/'.$key[0].$key[1].$key[2].'/'.$key;
 350+ $triplet = array( $this->mTempPath, 'public', $pathRel );
 351+ $repo->storeBatch( array($triplet) ); // save!
366352 }
367353 $expires = null; // passed by reference
368354 $token = $this->getConfirmationToken( $u, $expires );
@@ -398,11 +384,6 @@
399385 return false;
400386 }
401387 $dbw->commit();
402 - if ( isset( $transaction ) ) {
403 - wfDebug( __METHOD__ . ": set db items, applying file transactions\n" );
404 - $transaction->commit();
405 - FileStore::unlock();
406 - }
407388 # Clear cache for notice of how many account requests there are
408389 global $wgMemc;
409390 $key = wfMemcKey( 'confirmaccount', 'noticecount' );
Index: trunk/extensions/ConfirmAccount/ConfirmAccount_body.php
@@ -372,7 +372,7 @@
373373 * Show a private file requested by the visitor.
374374 */
375375 function showFile( $key ) {
376 - global $wgOut, $wgRequest;
 376+ global $wgOut, $wgRequest, $wgConfirmAccountFSRepos, $IP;
377377 $wgOut->disable();
378378
379379 # We mustn't allow the output to be Squid cached, otherwise
@@ -383,12 +383,11 @@
384384 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
385385 $wgRequest->response()->header( 'Pragma: no-cache' );
386386
387 - $store = FileStore::get( 'accountreqs' );
388 - if( !$store ) {
389 - wfDebug( __METHOD__.": invalid storage group '{$store}'.\n" );
390 - return false;
391 - }
392 - $store->stream( $key );
 387+ require_once( "$IP/includes/StreamFile.php" );
 388+ $repo = new FSRepo( $wgConfirmAccountFSRepos['accountreqs'] );
 389+ $path = $repo->getZonePath( 'public' ).'/'.
 390+ $key[0].'/'.$key[0].$key[1].'/'.$key[0].$key[1].$key[2].'/'.$key;
 391+ wfStreamFile( $path );
393392 }
394393
395394 function doSubmit() {
@@ -475,29 +474,19 @@
476475 __METHOD__
477476 );
478477 # Move to credentials if configured to do so
 478+ global $wgConfirmAccountFSRepos;
 479+ $key = $row->acr_storage_key;
479480 if( $wgConfirmAccountSaveInfo ) {
480481 # Copy any attached files to new storage group
481 - $key = $row->acr_storage_key;
482482 if( $wgAllowAccountRequestFiles && $key ) {
483 - $storeOld = FileStore::get( 'accountreqs' );
484 - $storeNew = FileStore::get( 'accountcreds' );
485 - if( !$storeOld || !$storeNew ) {
486 - $dbw->delete( 'user', array( 'user_id' => $user->getID() ) );
487 - $dbw->rollback();
488 - wfDebug( __METHOD__.": invalid storage group '{$store}'.\n" );
489 - return false;
 483+ $repoOld = new FSRepo( $wgConfirmAccountFSRepos['accountreqs'] );
 484+ $repoNew = new FSRepo( $wgConfirmAccountFSRepos['accountcreds'] );
 485+ $pathRel = $key[0].'/'.$key[0].$key[1].'/'.$key[0].$key[1].$key[2].'/'.$key;
 486+ $oldPath = $repoOld->getZonePath( 'public' ) . '/' . $pathRel;
 487+ if( file_exists($oldPath) ) {
 488+ $triplet = array( $oldPath, 'public', $pathRel );
 489+ $repoNew->storeBatch( array($triplet) /*,FSRepo::DELETE_SOURCE*/ ); // move!
490490 }
491 - $transaction = new FSTransaction();
492 - if( !FileStore::lock() ) {
493 - $dbw->delete( 'user', array( 'user_id' => $user->getID() ) );
494 - $dbw->rollback();
495 - wfDebug( __METHOD__.": failed to acquire file store lock, aborting\n" );
496 - return false;
497 - }
498 - $path = $storeOld->filePath( $key );
499 - if( $path && file_exists($path) ) {
500 - $transaction->add( $storeNew->insert( $key, $path, 0 ) );
501 - }
502491 }
503492 $acd_id = $dbw->nextSequenceValue( 'account_credentials_acd_id_seq' );
504493 # Move request data into a separate table
@@ -525,10 +514,6 @@
526515 if( !$wgAuth->addUser( $user, $p, $row->acr_email, $row->acr_real_name ) ) {
527516 $dbw->delete( 'user', array( 'user_id' => $user->getID() ) );
528517 $dbw->rollback();
529 - # Rollback file and row copies from credentials table on failure
530 - if( isset($transaction) ) {
531 - $transaction->rollback();
532 - }
533518 $this->showForm( wfMsgHtml( 'externaldberror' ) );
534519 return false;
535520 }
@@ -553,9 +538,6 @@
554539 # and the groups are added. Next step is sending out an
555540 # email, which we cannot take back...
556541 $dbw->commit();
557 - if( isset($transaction) ) {
558 - $transaction->commit();
559 - }
560542
561543 # Send out password
562544 if( $this->reason ) {
@@ -587,24 +569,15 @@
588570 $user->addNewUserLogEntry();
589571 # Clear cache for notice of how many account requests there are
590572 global $wgMemc;
591 - $key = wfMemcKey( 'confirmaccount', 'noticecount' );
592 - $wgMemc->delete( $key );
 573+ $memKey = wfMemcKey( 'confirmaccount', 'noticecount' );
 574+ $wgMemc->delete( $memKey );
593575 # Delete any attached file. Do not stop the whole process if this fails
594 - $key = $row->acr_storage_key;
595576 if( $key ) {
596 - $store = FileStore::get( 'accountreqs' );
597 - if( !$store ) {
598 - wfDebug( __METHOD__.": invalid storage group '{$store}'.\n" );
599 - } else {
600 - $transaction = new FSTransaction();
601 - if( !FileStore::lock() ) {
602 - wfDebug( __METHOD__.": failed to acquire file store lock, aborting\n" );
603 - }
604 - $path = $store->filePath( $key );
605 - if( $path && file_exists($path) ) {
606 - $transaction->addCommit( FSTransaction::DELETE_FILE, $path );
607 - }
608 - $transaction->commit();
 577+ $repoOld = new FSRepo( $wgConfirmAccountFSRepos['accountreqs'] );
 578+ $pathRel = $key[0].'/'.$key[0].$key[1].'/'.$key[0].$key[1].$key[2].'/'.$key;
 579+ $oldPath = $repoOld->getZonePath( 'public' ) . '/' . $pathRel;
 580+ if( file_exists($oldPath) ) {
 581+ unlink($oldPath); // delete!
609582 }
610583 }
611584 # Start up the user's (presumedly brand new) userpages
@@ -657,14 +630,15 @@
658631 global $wgAutoWelcomeNewUsers;
659632 if( $wgAutoWelcomeNewUsers ) {
660633 $utalk = new Article( $user->getTalkPage() );
 634+ $msg = "confirmaccount-welc-pos{$this->mType}";
661635 # Is there a custom message?
662 - $welcome = wfEmptyMsg( "confirmaccount-welc-pos{$this->mType}", wfMsg("confirmaccount-welc-pos{$this->mType}") ) ?
663 - wfMsg('confirmaccount-welc') : wfMsg("confirmaccount-welc-pos{$this->mType}");
 636+ $welcome = wfEmptyMsg( $msg, wfMsg($msg) ) ?
 637+ wfMsg('confirmaccount-welc') : wfMsg($msg);
664638 # Add user welcome message!
665639 $utalk->doEdit( $welcome . ' ~~~~', wfMsg('confirmaccount-wsum'), EDIT_MINOR );
666640 }
667641 # Finally, done!!!
668 - $this->showSuccess( $this->submitType, $user->getName(), $error );
 642+ $this->showSuccess( $this->submitType, $user->getName(), array($error) );
669643 } else if( $this->submitType === 'hold' ) {
670644 global $wgUser;
671645 # Make proxy user to email a message
@@ -714,8 +688,7 @@
715689 }
716690
717691 function getRequest( $forUpdate = false ) {
718 - if( !$this->acrID )
719 - return false;
 692+ if( !$this->acrID ) return false;
720693
721694 $db = $forUpdate ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
722695 $row = $db->selectRow( 'account_requests', '*',
@@ -833,9 +806,9 @@
834807 }
835808 }
836809
837 - # Every 50th view, prune old deleted items
 810+ # Every 30th view, prune old deleted items
838811 wfSeedRandom();
839 - if( 0 == mt_rand( 0, 49 ) ) {
 812+ if( 0 == mt_rand( 0, 29 ) ) {
840813 $this->runAutoMaintenance();
841814 }
842815 }
@@ -844,37 +817,28 @@
845818 * Move old stale requests to rejected list. Delete old rejected requests.
846819 */
847820 private function runAutoMaintenance() {
848 - global $wgRejectedAccountMaxAge;
 821+ global $wgRejectedAccountMaxAge, $wgConfirmAccountFSRepos;
849822
850823 $dbw = wfGetDB( DB_MASTER );
851 - $transaction = new FSTransaction();
852 - if( !FileStore::lock() ) {
853 - wfDebug( __METHOD__.": failed to acquire file store lock, aborting\n" );
854 - return;
855 - }
856824 # Select all items older than time $cutoff
857825 $cutoff = $dbw->timestamp( time() - $wgRejectedAccountMaxAge );
858826 $accountrequests = $dbw->tableName( 'account_requests' );
859827 $sql = "SELECT acr_storage_key,acr_id FROM $accountrequests WHERE acr_rejected < '{$cutoff}'";
860828 $res = $dbw->query( $sql );
861829
862 - $store = FileStore::get( 'accountreqs' );
863 - if( !$store ) {
864 - wfDebug( __METHOD__.": invalid storage group '{$store}'.\n" );
865 - return false;
866 - }
 830+ $repo = new FSRepo( $wgConfirmAccountFSRepos['accountreqs'] );
867831 # Clear out any associated attachments and delete those rows
868832 while( $row = $dbw->fetchObject( $res ) ) {
869833 $key = $row->acr_storage_key;
870834 if( $key ) {
871 - $path = $store->filePath( $key );
 835+ $path = $repo->getZonePath( 'public' ).'/'.
 836+ $key[0].'/'.$key[0].$key[1].'/'.$key[0].$key[1].$key[2].'/'.$key;
872837 if( $path && file_exists($path) ) {
873 - $transaction->addCommit( FSTransaction::DELETE_FILE, $path );
 838+ unlink($path);
874839 }
875840 }
876841 $dbw->query( "DELETE FROM $accountrequests WHERE acr_id = {$row->acr_id}" );
877842 }
878 - $transaction->commit();
879843
880844 # Select all items older than time $cutoff
881845 global $wgConfirmAccountRejectAge;

Status & tagging log