r26941 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r26940‎ | r26941 | r26942 >
Date:07:35, 25 October 2007
Author:aaron
Status:old
Tags:
Comment:
*Cleanup
Modified paths:
  • /trunk/extensions/ConfirmAccount/ConfirmAccount_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ConfirmAccount/ConfirmAccount_body.php
@@ -265,8 +265,14 @@
266266 }
267267 # Insert into pending requests...
268268 $dbw->begin();
 269+
 270+ $expires = null; // passed by reference
 271+ $token = $this->getConfirmationToken( $u, $expires );
 272+
 273+ $acr_id = $dbw->nextSequenceValue( 'account_requests_acr_id_seq' );
269274 $dbw->insert( 'account_requests',
270275 array(
 276+ 'acr_id' => $acr_id,
271277 'acr_name' => $u->mName,
272278 'acr_email' => $u->mEmail,
273279 'acr_real_name' => $u->mRealName,
@@ -276,15 +282,17 @@
277283 'acr_urls' => $this->mUrls,
278284 'acr_filename' => isset($this->mSrcName) ? $this->mSrcName : null,
279285 'acr_storage_key' => isset($key) ? $key : null,
 286+ 'acr_comment' => '',
 287+ 'acr_email_token' => md5($token),
 288+ 'acr_email_token_expires' => $dbw->timestamp( $expires ),
280289 'acr_ip' => wfGetIP() // Possible use for spam blocking
281290 ),
282291 __METHOD__
283292 );
284293 # Send confirmation, required!
285 - $result = $this->sendConfirmationMail( $u );
 294+ $result = $this->sendConfirmationMail( $u, $token, $expires );
286295 if( WikiError::isError( $result ) ) {
287296 $dbw->rollback(); // Nevermind
288 - $transaction->rollback();
289297 $error = wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
290298 $this->showForm( $error );
291299 return false;
@@ -458,7 +466,7 @@
459467 function requestFromEmailToken( $code ) {
460468 $dbr = wfGetDB( DB_SLAVE );
461469 $reqID = $dbr->selectField( 'account_requests', 'acr_name',
462 - array( 'acr_email_token' => md5( $code ),
 470+ array( 'acr_email_token' => md5($code),
463471 'acr_email_token_expires > ' . $dbr->addQuotes( $dbr->timestamp() ),
464472 )
465473 );
@@ -468,7 +476,7 @@
469477 /**
470478 * Flag a user's email as confirmed in the db
471479 *
472 - * @param Sring $name
 480+ * @param sring $name
473481 */
474482 function confirmEmail( $name ) {
475483 $dbw = wfGetDB( DB_MASTER );
@@ -483,12 +491,13 @@
484492 * mail to the user's given address.
485493 *
486494 * @param User $user
 495+ * @param string $token
 496+ * @param string $expiration
487497 * @return mixed True on success, a WikiError object on failure.
488498 */
489 - function sendConfirmationMail( $user ) {
 499+ function sendConfirmationMail( $user, $token, $expiration ) {
490500 global $wgContLang;
491 - $expiration = null; // gets passed-by-ref and defined in next line.
492 - $url = $this->confirmationTokenUrl( $user, $expiration );
 501+ $url = $this->confirmationTokenUrl( $token );
493502 return $user->sendMail( wfMsg( 'requestaccount-email-subj' ),
494503 wfMsg( 'requestaccount-email-body',
495504 wfGetIP(),
@@ -500,12 +509,11 @@
501510 /**
502511 * Generate and store a new e-mail confirmation token, and return
503512 * the URL the user can use to confirm.
504 - * @param User $user
 513+ * @param string $token
505514 * @return string
506515 * @private
507516 */
508 - function confirmationTokenUrl( $user, &$expiration ) {
509 - $token = $this->confirmationToken( $user, $expiration );
 517+ function confirmationTokenUrl( $token ) {
510518 $title = Title::makeTitle( NS_SPECIAL, 'RequestAccount' );
511519 return $title->getFullUrl( 'action=confirmemail&wpEmailToken='.$token );
512520 }
@@ -514,24 +522,16 @@
515523 * Generate, store, and return a new e-mail confirmation code.
516524 * A hash (unsalted since it's used as a key) is stored.
517525 * @param User $user
 526+ * @param string $expiration
518527 * @return string
519528 * @private
520529 */
521 - function confirmationToken( $user, &$expiration ) {
522 - $now = time();
523 - $expires = $now + 7 * 24 * 60 * 60;
 530+ function getConfirmationToken( $user, &$expiration ) {
 531+ $expires = time() + 7 * 24 * 60 * 60;
524532 $expiration = wfTimestamp( TS_MW, $expires );
525533
526534 $token = $user->generateToken( $user->getName() . $user->getEmail() . $expires );
527 - $hash = md5( $token );
528535
529 - $dbw = wfGetDB( DB_MASTER );
530 - $dbw->update( 'account_requests',
531 - array( 'acr_email_token' => $hash,
532 - 'acr_email_token_expires' => $dbw->timestamp( $expires ) ),
533 - array( 'acr_name' => $user->getName() ),
534 - __METHOD__ );
535 -
536536 return $token;
537537 }
538538
@@ -562,7 +562,7 @@
563563 $this->mUsername = $wgRequest->getText( 'wpNewName' );
564564 # For viewing rejects
565565 $this->showRejects = $wgRequest->getBool( 'wpShowRejects' );
566 -
 566+
567567 $this->submitType = $wgRequest->getVal( 'wpSubmitType' );
568568 $this->reason = $wgRequest->getText( 'wpReason' );
569569
@@ -754,7 +754,6 @@
755755 if( $msg ) {
756756 $wgOut->addHTML( '<div class="errorbox">' . $msg . '</div><div class="visualClear"></div>' );
757757 }
758 -
759758 $row = $this->getRequest();
760759 if( !$row || $row->acr_rejected && !$this->showRejects ) {
761760 $wgOut->addHTML( wfMsgHtml('confirmaccount-badid') );
@@ -807,10 +806,11 @@
808807
809808 $form .= '<fieldset>';
810809 $form .= '<legend>' . wfMsgHtml('requestaccount-legend3') . '</legend>';
811 - $form .= '<p>'.wfMsgHtml('confirmaccount-attach') . ' ' .
812 - $this->skin->makeKnownLinkObj( $wgTitle, htmlspecialchars($row->acr_filename),
 810+ if( $row->acr_filename ) {
 811+ $form .= '<p>'.wfMsgHtml('confirmaccount-attach') . ' ' .
 812+ $this->skin->makeKnownLinkObj( $wgTitle, htmlspecialchars($row->acr_filename),
813813 'file=' . $row->acr_storage_key );
814 -
 814+ }
815815 $form .= "<p>".wfMsgHtml('confirmaccount-notes')."</p>\n";
816816 $form .= "<p><textarea tabindex='1' readonly name='wpNotes' id='wpNotes' rows='3' cols='80' style='width:100%'>" .
817817 htmlspecialchars($row->acr_notes) .

Status & tagging log