Index: trunk/extensions/ConfirmAccount/UserCredentials_body.php |
— | — | @@ -183,7 +183,7 @@ |
184 | 184 | * Show a private file requested by the visitor. |
185 | 185 | */ |
186 | 186 | function showFile( $key ) { |
187 | | - global $wgOut, $wgRequest; |
| 187 | + global $wgOut, $wgRequest, $wgConfirmAccountFSRepos, $IP; |
188 | 188 | $wgOut->disable(); |
189 | 189 | |
190 | 190 | # We mustn't allow the output to be Squid cached, otherwise |
— | — | @@ -194,12 +194,11 @@ |
195 | 195 | $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' ); |
196 | 196 | $wgRequest->response()->header( 'Pragma: no-cache' ); |
197 | 197 | |
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 ); |
204 | 203 | } |
205 | 204 | |
206 | 205 | function getRequest() { |
Index: trunk/extensions/ConfirmAccount/SpecialConfirmAccount.php |
— | — | @@ -77,17 +77,30 @@ |
78 | 78 | # inject catpchas for requests too? |
79 | 79 | $wgConfirmAccountCaptchas = true; |
80 | 80 | |
81 | | -# Location of attached files for pending requests |
82 | 81 | $wgAllowAccountRequestFiles = true; |
83 | 82 | $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; |
87 | 83 | |
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 | +); |
92 | 105 | |
93 | 106 | # Restrict account creation |
94 | 107 | $wgGroupPermissions['*']['createaccount'] = false; |
Index: trunk/extensions/ConfirmAccount/RequestAccount_body.php |
— | — | @@ -342,26 +342,12 @@ |
343 | 343 | return false; |
344 | 344 | } |
345 | 345 | # 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! |
366 | 352 | } |
367 | 353 | $expires = null; // passed by reference |
368 | 354 | $token = $this->getConfirmationToken( $u, $expires ); |
— | — | @@ -398,11 +384,6 @@ |
399 | 385 | return false; |
400 | 386 | } |
401 | 387 | $dbw->commit(); |
402 | | - if ( isset( $transaction ) ) { |
403 | | - wfDebug( __METHOD__ . ": set db items, applying file transactions\n" ); |
404 | | - $transaction->commit(); |
405 | | - FileStore::unlock(); |
406 | | - } |
407 | 388 | # Clear cache for notice of how many account requests there are |
408 | 389 | global $wgMemc; |
409 | 390 | $key = wfMemcKey( 'confirmaccount', 'noticecount' ); |
Index: trunk/extensions/ConfirmAccount/ConfirmAccount_body.php |
— | — | @@ -372,7 +372,7 @@ |
373 | 373 | * Show a private file requested by the visitor. |
374 | 374 | */ |
375 | 375 | function showFile( $key ) { |
376 | | - global $wgOut, $wgRequest; |
| 376 | + global $wgOut, $wgRequest, $wgConfirmAccountFSRepos, $IP; |
377 | 377 | $wgOut->disable(); |
378 | 378 | |
379 | 379 | # We mustn't allow the output to be Squid cached, otherwise |
— | — | @@ -383,12 +383,11 @@ |
384 | 384 | $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' ); |
385 | 385 | $wgRequest->response()->header( 'Pragma: no-cache' ); |
386 | 386 | |
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 ); |
393 | 392 | } |
394 | 393 | |
395 | 394 | function doSubmit() { |
— | — | @@ -475,29 +474,19 @@ |
476 | 475 | __METHOD__ |
477 | 476 | ); |
478 | 477 | # Move to credentials if configured to do so |
| 478 | + global $wgConfirmAccountFSRepos; |
| 479 | + $key = $row->acr_storage_key; |
479 | 480 | if( $wgConfirmAccountSaveInfo ) { |
480 | 481 | # Copy any attached files to new storage group |
481 | | - $key = $row->acr_storage_key; |
482 | 482 | 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! |
490 | 490 | } |
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 | | - } |
502 | 491 | } |
503 | 492 | $acd_id = $dbw->nextSequenceValue( 'account_credentials_acd_id_seq' ); |
504 | 493 | # Move request data into a separate table |
— | — | @@ -525,10 +514,6 @@ |
526 | 515 | if( !$wgAuth->addUser( $user, $p, $row->acr_email, $row->acr_real_name ) ) { |
527 | 516 | $dbw->delete( 'user', array( 'user_id' => $user->getID() ) ); |
528 | 517 | $dbw->rollback(); |
529 | | - # Rollback file and row copies from credentials table on failure |
530 | | - if( isset($transaction) ) { |
531 | | - $transaction->rollback(); |
532 | | - } |
533 | 518 | $this->showForm( wfMsgHtml( 'externaldberror' ) ); |
534 | 519 | return false; |
535 | 520 | } |
— | — | @@ -553,9 +538,6 @@ |
554 | 539 | # and the groups are added. Next step is sending out an |
555 | 540 | # email, which we cannot take back... |
556 | 541 | $dbw->commit(); |
557 | | - if( isset($transaction) ) { |
558 | | - $transaction->commit(); |
559 | | - } |
560 | 542 | |
561 | 543 | # Send out password |
562 | 544 | if( $this->reason ) { |
— | — | @@ -587,24 +569,15 @@ |
588 | 570 | $user->addNewUserLogEntry(); |
589 | 571 | # Clear cache for notice of how many account requests there are |
590 | 572 | global $wgMemc; |
591 | | - $key = wfMemcKey( 'confirmaccount', 'noticecount' ); |
592 | | - $wgMemc->delete( $key ); |
| 573 | + $memKey = wfMemcKey( 'confirmaccount', 'noticecount' ); |
| 574 | + $wgMemc->delete( $memKey ); |
593 | 575 | # Delete any attached file. Do not stop the whole process if this fails |
594 | | - $key = $row->acr_storage_key; |
595 | 576 | 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! |
609 | 582 | } |
610 | 583 | } |
611 | 584 | # Start up the user's (presumedly brand new) userpages |
— | — | @@ -657,14 +630,15 @@ |
658 | 631 | global $wgAutoWelcomeNewUsers; |
659 | 632 | if( $wgAutoWelcomeNewUsers ) { |
660 | 633 | $utalk = new Article( $user->getTalkPage() ); |
| 634 | + $msg = "confirmaccount-welc-pos{$this->mType}"; |
661 | 635 | # 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); |
664 | 638 | # Add user welcome message! |
665 | 639 | $utalk->doEdit( $welcome . ' ~~~~', wfMsg('confirmaccount-wsum'), EDIT_MINOR ); |
666 | 640 | } |
667 | 641 | # Finally, done!!! |
668 | | - $this->showSuccess( $this->submitType, $user->getName(), $error ); |
| 642 | + $this->showSuccess( $this->submitType, $user->getName(), array($error) ); |
669 | 643 | } else if( $this->submitType === 'hold' ) { |
670 | 644 | global $wgUser; |
671 | 645 | # Make proxy user to email a message |
— | — | @@ -714,8 +688,7 @@ |
715 | 689 | } |
716 | 690 | |
717 | 691 | function getRequest( $forUpdate = false ) { |
718 | | - if( !$this->acrID ) |
719 | | - return false; |
| 692 | + if( !$this->acrID ) return false; |
720 | 693 | |
721 | 694 | $db = $forUpdate ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); |
722 | 695 | $row = $db->selectRow( 'account_requests', '*', |
— | — | @@ -833,9 +806,9 @@ |
834 | 807 | } |
835 | 808 | } |
836 | 809 | |
837 | | - # Every 50th view, prune old deleted items |
| 810 | + # Every 30th view, prune old deleted items |
838 | 811 | wfSeedRandom(); |
839 | | - if( 0 == mt_rand( 0, 49 ) ) { |
| 812 | + if( 0 == mt_rand( 0, 29 ) ) { |
840 | 813 | $this->runAutoMaintenance(); |
841 | 814 | } |
842 | 815 | } |
— | — | @@ -844,37 +817,28 @@ |
845 | 818 | * Move old stale requests to rejected list. Delete old rejected requests. |
846 | 819 | */ |
847 | 820 | private function runAutoMaintenance() { |
848 | | - global $wgRejectedAccountMaxAge; |
| 821 | + global $wgRejectedAccountMaxAge, $wgConfirmAccountFSRepos; |
849 | 822 | |
850 | 823 | $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 | | - } |
856 | 824 | # Select all items older than time $cutoff |
857 | 825 | $cutoff = $dbw->timestamp( time() - $wgRejectedAccountMaxAge ); |
858 | 826 | $accountrequests = $dbw->tableName( 'account_requests' ); |
859 | 827 | $sql = "SELECT acr_storage_key,acr_id FROM $accountrequests WHERE acr_rejected < '{$cutoff}'"; |
860 | 828 | $res = $dbw->query( $sql ); |
861 | 829 | |
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'] ); |
867 | 831 | # Clear out any associated attachments and delete those rows |
868 | 832 | while( $row = $dbw->fetchObject( $res ) ) { |
869 | 833 | $key = $row->acr_storage_key; |
870 | 834 | 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; |
872 | 837 | if( $path && file_exists($path) ) { |
873 | | - $transaction->addCommit( FSTransaction::DELETE_FILE, $path ); |
| 838 | + unlink($path); |
874 | 839 | } |
875 | 840 | } |
876 | 841 | $dbw->query( "DELETE FROM $accountrequests WHERE acr_id = {$row->acr_id}" ); |
877 | 842 | } |
878 | | - $transaction->commit(); |
879 | 843 | |
880 | 844 | # Select all items older than time $cutoff |
881 | 845 | global $wgConfirmAccountRejectAge; |