http://www.mediawiki.org/wiki/Special:Code/MediaWiki/98043

Revision: 98043
Author:   aaron
Date:     2011-09-24 23:41:23 +0000 (Sat, 24 Sep 2011)
Log Message:
-----------
Split out some backend function into a new ConfirmAccount.class.php file

Modified Paths:
--------------
    trunk/extensions/ConfirmAccount/ConfirmAccount.php
    
trunk/extensions/ConfirmAccount/presentation/specialpages/actions/ConfirmAccount_body.php
    
trunk/extensions/ConfirmAccount/presentation/specialpages/actions/RequestAccount_body.php

Added Paths:
-----------
    trunk/extensions/ConfirmAccount/dataclasses/
    trunk/extensions/ConfirmAccount/dataclasses/ConfirmAccount.class.php

Modified: trunk/extensions/ConfirmAccount/ConfirmAccount.php
===================================================================
--- trunk/extensions/ConfirmAccount/ConfirmAccount.php  2011-09-24 23:03:32 UTC 
(rev 98042)
+++ trunk/extensions/ConfirmAccount/ConfirmAccount.php  2011-09-24 23:41:23 UTC 
(rev 98043)
@@ -166,6 +166,10 @@
 $wgAutoloadClasses['UserCredentialsPage'] = 
"$dir/actions/UserCredentials_body.php";
 $wgSpecialPageGroups['UserCredentials'] = 'users';
 
+# Data functions
+$dir = dirname( __FILE__ ) . '/dataclasses';
+$wgAutoloadClasses['ConfirmAccount'] = "$dir/ConfirmAccount.class.php";
+
 $dir = dirname( __FILE__ ) . '/schema';
 # Schema changes
 $wgAutoloadClasses['ConfirmAccountUpdaterHooks'] = 
"$dir/ConfirmAccountUpdater.hooks.php";

Added: trunk/extensions/ConfirmAccount/dataclasses/ConfirmAccount.class.php
===================================================================
--- trunk/extensions/ConfirmAccount/dataclasses/ConfirmAccount.class.php        
                        (rev 0)
+++ trunk/extensions/ConfirmAccount/dataclasses/ConfirmAccount.class.php        
2011-09-24 23:41:23 UTC (rev 98043)
@@ -0,0 +1,93 @@
+<?php
+class ConfirmAccount {
+       /*
+       * Move old stale requests to rejected list. Delete old rejected 
requests.
+       */
+       public static function runAutoMaintenance() {
+               global $wgRejectedAccountMaxAge, $wgConfirmAccountFSRepos;
+
+               $dbw = wfGetDB( DB_MASTER );
+               # Select all items older than time $cutoff
+               $cutoff = $dbw->timestamp( time() - $wgRejectedAccountMaxAge );
+               $accountrequests = $dbw->tableName( 'account_requests' );
+               $sql = "SELECT acr_storage_key,acr_id FROM $accountrequests 
WHERE acr_rejected < '{$cutoff}'";
+               $res = $dbw->query( $sql );
+
+               $repo = new FSRepo( $wgConfirmAccountFSRepos['accountreqs'] );
+               # Clear out any associated attachments and delete those rows
+               while( $row = $dbw->fetchObject( $res ) ) {
+                       $key = $row->acr_storage_key;
+                       if( $key ) {
+                               $path = $repo->getZonePath( 'public' ).'/'.
+                                       
$key[0].'/'.$key[0].$key[1].'/'.$key[0].$key[1].$key[2].'/'.$key;
+                               if( $path && file_exists($path) ) {
+                                       unlink($path);
+                               }
+                       }
+                       $dbw->query( "DELETE FROM $accountrequests WHERE acr_id 
= {$row->acr_id}" );
+               }
+
+               # Select all items older than time $cutoff
+               global $wgConfirmAccountRejectAge;
+               $cutoff = $dbw->timestamp( time() - $wgConfirmAccountRejectAge 
);
+               # Old stale accounts will count as rejected. If the request was 
held, give it more time.
+               $dbw->update( 'account_requests',
+                       array( 'acr_rejected' => $dbw->timestamp(),
+                               'acr_user' => 0, // dummy
+                               'acr_comment' => 
wfMsgForContent('confirmaccount-autorej'),
+                               'acr_deleted' => 1 ),
+                       array( "acr_rejected IS NULL", "acr_registration < 
'{$cutoff}'", "acr_held < '{$cutoff}'" ),
+                       __METHOD__ );
+
+               # Clear cache for notice of how many account requests there are
+               global $wgMemc;
+               $key = wfMemcKey( 'confirmaccount', 'noticecount' );
+               $wgMemc->delete( $key );
+       }
+
+       /**
+        * Flag a user's email as confirmed in the db
+        *
+        * @param sring $name
+        */
+       public function confirmEmail( $name ) {
+               global $wgMemc;
+               $dbw = wfGetDB( DB_MASTER );
+               $dbw->update( 'account_requests',
+                       array( 'acr_email_authenticated' => $dbw->timestamp() ),
+                       array( 'acr_name' => $name ),
+                       __METHOD__ );
+               # Clear cache for notice of how many account requests there are
+               $key = wfMemcKey( 'confirmaccount', 'noticecount' );
+               $wgMemc->delete( $key );
+       }
+
+       /**
+        * Generate and store a new e-mail confirmation token, and return
+        * the URL the user can use to confirm.
+        * @param string $token
+        * @return string
+        */
+       public function confirmationTokenUrl( $token ) {
+               $title = SpecialPage::getTitleFor( 'RequestAccount' );
+               return $title->getFullUrl( array(
+                       'action' => 'confirmemail',
+                       'wpEmailToken' => $token
+               ) );
+       }
+
+       /**
+        * Generate, store, and return a new e-mail confirmation code.
+        * A hash (unsalted since it's used as a key) is stored.
+        * @param User $user
+        * @param string $expiration
+        * @return string
+        */
+       public function getConfirmationToken( $user, &$expiration ) {
+               global $wgConfirmAccountRejectAge;
+               $expires = time() + $wgConfirmAccountRejectAge;
+               $expiration = wfTimestamp( TS_MW, $expires );
+               $token = $user->generateToken( $user->getName() . 
$user->getEmail() . $expires );
+               return $token;
+       }
+}


Property changes on: 
trunk/extensions/ConfirmAccount/dataclasses/ConfirmAccount.class.php
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: 
trunk/extensions/ConfirmAccount/presentation/specialpages/actions/ConfirmAccount_body.php
===================================================================
--- 
trunk/extensions/ConfirmAccount/presentation/specialpages/actions/ConfirmAccount_body.php
   2011-09-24 23:03:32 UTC (rev 98042)
+++ 
trunk/extensions/ConfirmAccount/presentation/specialpages/actions/ConfirmAccount_body.php
   2011-09-24 23:41:23 UTC (rev 98043)
@@ -389,11 +389,11 @@
                $wgRequest->response()->header( 'Cache-Control: no-cache, 
no-store, max-age=0, must-revalidate' );
                $wgRequest->response()->header( 'Pragma: no-cache' );
 
-               require_once( "$IP/includes/StreamFile.php" );
                $repo = new FSRepo( $wgConfirmAccountFSRepos['accountreqs'] );
                $path = $repo->getZonePath( 'public' ).'/'.
                        
$key[0].'/'.$key[0].$key[1].'/'.$key[0].$key[1].$key[2].'/'.$key;
-               wfStreamFile( $path );
+
+               StreamFile::stream( $path );
        }
 
        protected function doSubmit() {
@@ -738,6 +738,9 @@
                }
        }
 
+       /*
+        * Get requested account request row and load some fields
+        */
        function getRequest( $forUpdate = false ) {
                if( !$this->acrID ) return false;
 
@@ -857,55 +860,10 @@
 
                # Every 30th view, prune old deleted items
                if( 0 == mt_rand( 0, 29 ) ) {
-                       $this->runAutoMaintenance();
+                       ConfirmAccount::runAutoMaintenance();
                }
        }
 
-       /*
-       * Move old stale requests to rejected list. Delete old rejected 
requests.
-       */
-       private function runAutoMaintenance() {
-               global $wgRejectedAccountMaxAge, $wgConfirmAccountFSRepos;
-
-               $dbw = wfGetDB( DB_MASTER );
-               # Select all items older than time $cutoff
-               $cutoff = $dbw->timestamp( time() - $wgRejectedAccountMaxAge );
-               $accountrequests = $dbw->tableName( 'account_requests' );
-               $sql = "SELECT acr_storage_key,acr_id FROM $accountrequests 
WHERE acr_rejected < '{$cutoff}'";
-               $res = $dbw->query( $sql );
-
-               $repo = new FSRepo( $wgConfirmAccountFSRepos['accountreqs'] );
-               # Clear out any associated attachments and delete those rows
-               while( $row = $dbw->fetchObject( $res ) ) {
-                       $key = $row->acr_storage_key;
-                       if( $key ) {
-                               $path = $repo->getZonePath( 'public' ).'/'.
-                                       
$key[0].'/'.$key[0].$key[1].'/'.$key[0].$key[1].$key[2].'/'.$key;
-                               if( $path && file_exists($path) ) {
-                                       unlink($path);
-                               }
-                       }
-                       $dbw->query( "DELETE FROM $accountrequests WHERE acr_id 
= {$row->acr_id}" );
-               }
-
-               # Select all items older than time $cutoff
-               global $wgConfirmAccountRejectAge;
-               $cutoff = $dbw->timestamp( time() - $wgConfirmAccountRejectAge 
);
-               # Old stale accounts will count as rejected. If the request was 
held, give it more time.
-               $dbw->update( 'account_requests',
-                       array( 'acr_rejected' => $dbw->timestamp(),
-                               'acr_user' => 0, // dummy
-                               'acr_comment' => 
wfMsgForContent('confirmaccount-autorej'),
-                               'acr_deleted' => 1 ),
-                       array( "acr_rejected IS NULL", "acr_registration < 
'{$cutoff}'", "acr_held < '{$cutoff}'" ),
-                       __METHOD__ );
-
-               # Clear cache for notice of how many account requests there are
-               global $wgMemc;
-               $key = wfMemcKey( 'confirmaccount', 'noticecount' );
-               $wgMemc->delete( $key );
-       }
-
        public function formatRow( $row ) {
                global $wgLang, $wgUser, $wgUseRealNamesOnly, $wgAllowRealName;
 
@@ -977,7 +935,9 @@
 class ConfirmAccountsPager extends ReverseChronologicalPager {
        public $mForm, $mConds;
 
-       function __construct( $form, $conds = array(), $type, $rejects=false, 
$showHeld=false, $showStale=false ) {
+       function __construct(
+               $form, $conds = array(), $type, $rejects=false, 
$showHeld=false, $showStale=false
+       ) {
                $this->mForm = $form;
                $this->mConds = $conds;
 

Modified: 
trunk/extensions/ConfirmAccount/presentation/specialpages/actions/RequestAccount_body.php
===================================================================
--- 
trunk/extensions/ConfirmAccount/presentation/specialpages/actions/RequestAccount_body.php
   2011-09-24 23:03:32 UTC (rev 98042)
+++ 
trunk/extensions/ConfirmAccount/presentation/specialpages/actions/RequestAccount_body.php
   2011-09-24 23:41:23 UTC (rev 98043)
@@ -350,7 +350,7 @@
                        $repo->storeBatch( array($triplet) ); // save!
                }
                $expires = null; // passed by reference
-               $token = $this->getConfirmationToken( $u, $expires );
+               $token = ConfirmAccount::getConfirmationToken( $u, $expires );
                # Insert into pending requests...
                $acr_id = $dbw->nextSequenceValue( 
'account_requests_acr_id_seq' );
                $dbw->begin();
@@ -505,7 +505,7 @@
                $name = $this->requestFromEmailToken( $code );
                if ( $name !== false ) {
                        # Send confirmation email to prospective user
-                       $this->confirmEmail( $name );
+                       ConfirmAccount::confirmEmail( $name );
                        # Send mail to admin after e-mail has been confirmed
                        if ( $wgConfirmAccountContact != '' ) {
                                $target = new MailAddress( 
$wgConfirmAccountContact );
@@ -559,23 +559,6 @@
        }
 
        /**
-        * Flag a user's email as confirmed in the db
-        *
-        * @param sring $name
-        */
-       protected function confirmEmail( $name ) {
-               $dbw = wfGetDB( DB_MASTER );
-               $dbw->update( 'account_requests',
-                       array( 'acr_email_authenticated' => $dbw->timestamp() ),
-                       array( 'acr_name' => $name ),
-                       __METHOD__ );
-               # Clear cache for notice of how many account requests there are
-               global $wgMemc;
-               $key = wfMemcKey( 'confirmaccount', 'noticecount' );
-               $wgMemc->delete( $key );
-       }
-
-       /**
         * Generate a new e-mail confirmation token and send a confirmation
         * mail to the user's given address.
         *
@@ -586,7 +569,7 @@
         */
        protected function sendConfirmationMail( $user, $token, $expiration ) {
                global $wgContLang;
-               $url = $this->confirmationTokenUrl( $token );
+               $url = ConfirmAccount::confirmationTokenUrl( $token );
                return $user->sendMail( wfMsg( 'requestaccount-email-subj' ),
                        wfMsg( 'requestaccount-email-body',
                                wfGetIP(),
@@ -596,33 +579,4 @@
                                $wgContLang->date( $expiration, false ) ,
                                $wgContLang->time( $expiration, false ) ) );
        }
-
-       /**
-        * Generate and store a new e-mail confirmation token, and return
-        * the URL the user can use to confirm.
-        * @param string $token
-        * @return string
-        */
-       protected function confirmationTokenUrl( $token ) {
-               $title = SpecialPage::getTitleFor( 'RequestAccount' );
-               return $title->getFullUrl( array(
-                       'action' => 'confirmemail',
-                       'wpEmailToken' => $token
-               ) );
-       }
-
-       /**
-        * Generate, store, and return a new e-mail confirmation code.
-        * A hash (unsalted since it's used as a key) is stored.
-        * @param User $user
-        * @param string $expiration
-        * @return string
-        */
-       protected function getConfirmationToken( $user, &$expiration ) {
-               global $wgConfirmAccountRejectAge;
-               $expires = time() + $wgConfirmAccountRejectAge;
-               $expiration = wfTimestamp( TS_MW, $expires );
-               $token = $user->generateToken( $user->getName() . 
$user->getEmail() . $expires );
-               return $token;
-       }
 }


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to