Index: trunk/extensions/ConfirmAccount/ConfirmAccount.php |
— | — | @@ -166,6 +166,10 @@ |
167 | 167 | $wgAutoloadClasses['UserCredentialsPage'] = "$dir/actions/UserCredentials_body.php"; |
168 | 168 | $wgSpecialPageGroups['UserCredentials'] = 'users'; |
169 | 169 | |
| 170 | +# Data functions |
| 171 | +$dir = dirname( __FILE__ ) . '/dataclasses'; |
| 172 | +$wgAutoloadClasses['ConfirmAccount'] = "$dir/ConfirmAccount.class.php"; |
| 173 | + |
170 | 174 | $dir = dirname( __FILE__ ) . '/schema'; |
171 | 175 | # Schema changes |
172 | 176 | $wgAutoloadClasses['ConfirmAccountUpdaterHooks'] = "$dir/ConfirmAccountUpdater.hooks.php"; |
Index: trunk/extensions/ConfirmAccount/dataclasses/ConfirmAccount.class.php |
— | — | @@ -0,0 +1,93 @@ |
| 2 | +<?php |
| 3 | +class ConfirmAccount { |
| 4 | + /* |
| 5 | + * Move old stale requests to rejected list. Delete old rejected requests. |
| 6 | + */ |
| 7 | + public static function runAutoMaintenance() { |
| 8 | + global $wgRejectedAccountMaxAge, $wgConfirmAccountFSRepos; |
| 9 | + |
| 10 | + $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 ); |
| 16 | + |
| 17 | + $repo = new FSRepo( $wgConfirmAccountFSRepos['accountreqs'] ); |
| 18 | + # Clear out any associated attachments and delete those rows |
| 19 | + while( $row = $dbw->fetchObject( $res ) ) { |
| 20 | + $key = $row->acr_storage_key; |
| 21 | + if( $key ) { |
| 22 | + $path = $repo->getZonePath( 'public' ).'/'. |
| 23 | + $key[0].'/'.$key[0].$key[1].'/'.$key[0].$key[1].$key[2].'/'.$key; |
| 24 | + if( $path && file_exists($path) ) { |
| 25 | + unlink($path); |
| 26 | + } |
| 27 | + } |
| 28 | + $dbw->query( "DELETE FROM $accountrequests WHERE acr_id = {$row->acr_id}" ); |
| 29 | + } |
| 30 | + |
| 31 | + # Select all items older than time $cutoff |
| 32 | + global $wgConfirmAccountRejectAge; |
| 33 | + $cutoff = $dbw->timestamp( time() - $wgConfirmAccountRejectAge ); |
| 34 | + # Old stale accounts will count as rejected. If the request was held, give it more time. |
| 35 | + $dbw->update( 'account_requests', |
| 36 | + array( 'acr_rejected' => $dbw->timestamp(), |
| 37 | + 'acr_user' => 0, // dummy |
| 38 | + 'acr_comment' => wfMsgForContent('confirmaccount-autorej'), |
| 39 | + 'acr_deleted' => 1 ), |
| 40 | + array( "acr_rejected IS NULL", "acr_registration < '{$cutoff}'", "acr_held < '{$cutoff}'" ), |
| 41 | + __METHOD__ ); |
| 42 | + |
| 43 | + # Clear cache for notice of how many account requests there are |
| 44 | + global $wgMemc; |
| 45 | + $key = wfMemcKey( 'confirmaccount', 'noticecount' ); |
| 46 | + $wgMemc->delete( $key ); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Flag a user's email as confirmed in the db |
| 51 | + * |
| 52 | + * @param sring $name |
| 53 | + */ |
| 54 | + public function confirmEmail( $name ) { |
| 55 | + global $wgMemc; |
| 56 | + $dbw = wfGetDB( DB_MASTER ); |
| 57 | + $dbw->update( 'account_requests', |
| 58 | + array( 'acr_email_authenticated' => $dbw->timestamp() ), |
| 59 | + array( 'acr_name' => $name ), |
| 60 | + __METHOD__ ); |
| 61 | + # Clear cache for notice of how many account requests there are |
| 62 | + $key = wfMemcKey( 'confirmaccount', 'noticecount' ); |
| 63 | + $wgMemc->delete( $key ); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Generate and store a new e-mail confirmation token, and return |
| 68 | + * the URL the user can use to confirm. |
| 69 | + * @param string $token |
| 70 | + * @return string |
| 71 | + */ |
| 72 | + public function confirmationTokenUrl( $token ) { |
| 73 | + $title = SpecialPage::getTitleFor( 'RequestAccount' ); |
| 74 | + return $title->getFullUrl( array( |
| 75 | + 'action' => 'confirmemail', |
| 76 | + 'wpEmailToken' => $token |
| 77 | + ) ); |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * Generate, store, and return a new e-mail confirmation code. |
| 82 | + * A hash (unsalted since it's used as a key) is stored. |
| 83 | + * @param User $user |
| 84 | + * @param string $expiration |
| 85 | + * @return string |
| 86 | + */ |
| 87 | + public function getConfirmationToken( $user, &$expiration ) { |
| 88 | + global $wgConfirmAccountRejectAge; |
| 89 | + $expires = time() + $wgConfirmAccountRejectAge; |
| 90 | + $expiration = wfTimestamp( TS_MW, $expires ); |
| 91 | + $token = $user->generateToken( $user->getName() . $user->getEmail() . $expires ); |
| 92 | + return $token; |
| 93 | + } |
| 94 | +} |
Property changes on: trunk/extensions/ConfirmAccount/dataclasses/ConfirmAccount.class.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 95 | + native |
Index: trunk/extensions/ConfirmAccount/presentation/specialpages/actions/RequestAccount_body.php |
— | — | @@ -350,7 +350,7 @@ |
351 | 351 | $repo->storeBatch( array($triplet) ); // save! |
352 | 352 | } |
353 | 353 | $expires = null; // passed by reference |
354 | | - $token = $this->getConfirmationToken( $u, $expires ); |
| 354 | + $token = ConfirmAccount::getConfirmationToken( $u, $expires ); |
355 | 355 | # Insert into pending requests... |
356 | 356 | $acr_id = $dbw->nextSequenceValue( 'account_requests_acr_id_seq' ); |
357 | 357 | $dbw->begin(); |
— | — | @@ -505,7 +505,7 @@ |
506 | 506 | $name = $this->requestFromEmailToken( $code ); |
507 | 507 | if ( $name !== false ) { |
508 | 508 | # Send confirmation email to prospective user |
509 | | - $this->confirmEmail( $name ); |
| 509 | + ConfirmAccount::confirmEmail( $name ); |
510 | 510 | # Send mail to admin after e-mail has been confirmed |
511 | 511 | if ( $wgConfirmAccountContact != '' ) { |
512 | 512 | $target = new MailAddress( $wgConfirmAccountContact ); |
— | — | @@ -559,23 +559,6 @@ |
560 | 560 | } |
561 | 561 | |
562 | 562 | /** |
563 | | - * Flag a user's email as confirmed in the db |
564 | | - * |
565 | | - * @param sring $name |
566 | | - */ |
567 | | - protected function confirmEmail( $name ) { |
568 | | - $dbw = wfGetDB( DB_MASTER ); |
569 | | - $dbw->update( 'account_requests', |
570 | | - array( 'acr_email_authenticated' => $dbw->timestamp() ), |
571 | | - array( 'acr_name' => $name ), |
572 | | - __METHOD__ ); |
573 | | - # Clear cache for notice of how many account requests there are |
574 | | - global $wgMemc; |
575 | | - $key = wfMemcKey( 'confirmaccount', 'noticecount' ); |
576 | | - $wgMemc->delete( $key ); |
577 | | - } |
578 | | - |
579 | | - /** |
580 | 563 | * Generate a new e-mail confirmation token and send a confirmation |
581 | 564 | * mail to the user's given address. |
582 | 565 | * |
— | — | @@ -586,7 +569,7 @@ |
587 | 570 | */ |
588 | 571 | protected function sendConfirmationMail( $user, $token, $expiration ) { |
589 | 572 | global $wgContLang; |
590 | | - $url = $this->confirmationTokenUrl( $token ); |
| 573 | + $url = ConfirmAccount::confirmationTokenUrl( $token ); |
591 | 574 | return $user->sendMail( wfMsg( 'requestaccount-email-subj' ), |
592 | 575 | wfMsg( 'requestaccount-email-body', |
593 | 576 | wfGetIP(), |
— | — | @@ -596,33 +579,4 @@ |
597 | 580 | $wgContLang->date( $expiration, false ) , |
598 | 581 | $wgContLang->time( $expiration, false ) ) ); |
599 | 582 | } |
600 | | - |
601 | | - /** |
602 | | - * Generate and store a new e-mail confirmation token, and return |
603 | | - * the URL the user can use to confirm. |
604 | | - * @param string $token |
605 | | - * @return string |
606 | | - */ |
607 | | - protected function confirmationTokenUrl( $token ) { |
608 | | - $title = SpecialPage::getTitleFor( 'RequestAccount' ); |
609 | | - return $title->getFullUrl( array( |
610 | | - 'action' => 'confirmemail', |
611 | | - 'wpEmailToken' => $token |
612 | | - ) ); |
613 | | - } |
614 | | - |
615 | | - /** |
616 | | - * Generate, store, and return a new e-mail confirmation code. |
617 | | - * A hash (unsalted since it's used as a key) is stored. |
618 | | - * @param User $user |
619 | | - * @param string $expiration |
620 | | - * @return string |
621 | | - */ |
622 | | - protected function getConfirmationToken( $user, &$expiration ) { |
623 | | - global $wgConfirmAccountRejectAge; |
624 | | - $expires = time() + $wgConfirmAccountRejectAge; |
625 | | - $expiration = wfTimestamp( TS_MW, $expires ); |
626 | | - $token = $user->generateToken( $user->getName() . $user->getEmail() . $expires ); |
627 | | - return $token; |
628 | | - } |
629 | 583 | } |
Index: trunk/extensions/ConfirmAccount/presentation/specialpages/actions/ConfirmAccount_body.php |
— | — | @@ -389,11 +389,11 @@ |
390 | 390 | $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' ); |
391 | 391 | $wgRequest->response()->header( 'Pragma: no-cache' ); |
392 | 392 | |
393 | | - require_once( "$IP/includes/StreamFile.php" ); |
394 | 393 | $repo = new FSRepo( $wgConfirmAccountFSRepos['accountreqs'] ); |
395 | 394 | $path = $repo->getZonePath( 'public' ).'/'. |
396 | 395 | $key[0].'/'.$key[0].$key[1].'/'.$key[0].$key[1].$key[2].'/'.$key; |
397 | | - wfStreamFile( $path ); |
| 396 | + |
| 397 | + StreamFile::stream( $path ); |
398 | 398 | } |
399 | 399 | |
400 | 400 | protected function doSubmit() { |
— | — | @@ -738,6 +738,9 @@ |
739 | 739 | } |
740 | 740 | } |
741 | 741 | |
| 742 | + /* |
| 743 | + * Get requested account request row and load some fields |
| 744 | + */ |
742 | 745 | function getRequest( $forUpdate = false ) { |
743 | 746 | if( !$this->acrID ) return false; |
744 | 747 | |
— | — | @@ -857,55 +860,10 @@ |
858 | 861 | |
859 | 862 | # Every 30th view, prune old deleted items |
860 | 863 | if( 0 == mt_rand( 0, 29 ) ) { |
861 | | - $this->runAutoMaintenance(); |
| 864 | + ConfirmAccount::runAutoMaintenance(); |
862 | 865 | } |
863 | 866 | } |
864 | 867 | |
865 | | - /* |
866 | | - * Move old stale requests to rejected list. Delete old rejected requests. |
867 | | - */ |
868 | | - private function runAutoMaintenance() { |
869 | | - global $wgRejectedAccountMaxAge, $wgConfirmAccountFSRepos; |
870 | | - |
871 | | - $dbw = wfGetDB( DB_MASTER ); |
872 | | - # Select all items older than time $cutoff |
873 | | - $cutoff = $dbw->timestamp( time() - $wgRejectedAccountMaxAge ); |
874 | | - $accountrequests = $dbw->tableName( 'account_requests' ); |
875 | | - $sql = "SELECT acr_storage_key,acr_id FROM $accountrequests WHERE acr_rejected < '{$cutoff}'"; |
876 | | - $res = $dbw->query( $sql ); |
877 | | - |
878 | | - $repo = new FSRepo( $wgConfirmAccountFSRepos['accountreqs'] ); |
879 | | - # Clear out any associated attachments and delete those rows |
880 | | - while( $row = $dbw->fetchObject( $res ) ) { |
881 | | - $key = $row->acr_storage_key; |
882 | | - if( $key ) { |
883 | | - $path = $repo->getZonePath( 'public' ).'/'. |
884 | | - $key[0].'/'.$key[0].$key[1].'/'.$key[0].$key[1].$key[2].'/'.$key; |
885 | | - if( $path && file_exists($path) ) { |
886 | | - unlink($path); |
887 | | - } |
888 | | - } |
889 | | - $dbw->query( "DELETE FROM $accountrequests WHERE acr_id = {$row->acr_id}" ); |
890 | | - } |
891 | | - |
892 | | - # Select all items older than time $cutoff |
893 | | - global $wgConfirmAccountRejectAge; |
894 | | - $cutoff = $dbw->timestamp( time() - $wgConfirmAccountRejectAge ); |
895 | | - # Old stale accounts will count as rejected. If the request was held, give it more time. |
896 | | - $dbw->update( 'account_requests', |
897 | | - array( 'acr_rejected' => $dbw->timestamp(), |
898 | | - 'acr_user' => 0, // dummy |
899 | | - 'acr_comment' => wfMsgForContent('confirmaccount-autorej'), |
900 | | - 'acr_deleted' => 1 ), |
901 | | - array( "acr_rejected IS NULL", "acr_registration < '{$cutoff}'", "acr_held < '{$cutoff}'" ), |
902 | | - __METHOD__ ); |
903 | | - |
904 | | - # Clear cache for notice of how many account requests there are |
905 | | - global $wgMemc; |
906 | | - $key = wfMemcKey( 'confirmaccount', 'noticecount' ); |
907 | | - $wgMemc->delete( $key ); |
908 | | - } |
909 | | - |
910 | 868 | public function formatRow( $row ) { |
911 | 869 | global $wgLang, $wgUser, $wgUseRealNamesOnly, $wgAllowRealName; |
912 | 870 | |
— | — | @@ -977,7 +935,9 @@ |
978 | 936 | class ConfirmAccountsPager extends ReverseChronologicalPager { |
979 | 937 | public $mForm, $mConds; |
980 | 938 | |
981 | | - function __construct( $form, $conds = array(), $type, $rejects=false, $showHeld=false, $showStale=false ) { |
| 939 | + function __construct( |
| 940 | + $form, $conds = array(), $type, $rejects=false, $showHeld=false, $showStale=false |
| 941 | + ) { |
982 | 942 | $this->mForm = $form; |
983 | 943 | $this->mConds = $conds; |
984 | 944 | |