r103010 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103009‎ | r103010 | r103011 >
Date:19:36, 14 November 2011
Author:aaron
Status:deferred
Tags:
Comment:
* Factored out getAccountRequestBlock() function
* Fixed undefined $result var in acceptRequest()
* Reduced a bit of duplication in rejectRequest()
* Added permission checks to submission classes for sanity (special pages check them)
Modified paths:
  • /trunk/extensions/ConfirmAccount/backend/ConfirmAccount.class.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/business/AccountConfirmSubmission.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/business/AccountRequestSubmission.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/frontend/language/ConfirmAccountPage.i18n.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/frontend/specialpages/actions/RequestAccount_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ConfirmAccount/frontend/specialpages/actions/RequestAccount_body.php
@@ -24,18 +24,15 @@
2525
2626 function execute( $par ) {
2727 global $wgUseRealNamesOnly, $wgAccountRequestToS, $wgAccountRequestExtraInfo;
28 - global $wgAccountRequestTypes, $wgAccountRequestWhileBlocked;
 28+ global $wgAccountRequestTypes;
2929
3030 $reqUser = $this->getUser();
3131 $request = $this->getRequest();
3232
33 - # If a user cannot make accounts, don't let them request them either
34 - if ( !$wgAccountRequestWhileBlocked ) {
35 - if ( ( $block = $reqUser->isBlockedFromCreateAccount() ) ) {
36 - throw new UserBlockedError( $block );
37 - }
38 - }
39 - if ( wfReadOnly() ) {
 33+ $block = ConfirmAccount::getAccountRequestBlock( $reqUser );
 34+ if ( $block ) {
 35+ throw new UserBlockedError( $block );
 36+ } elseif ( wfReadOnly() ) {
4037 throw new ReadOnlyError();
4138 }
4239
Index: trunk/extensions/ConfirmAccount/frontend/language/ConfirmAccountPage.i18n.php
@@ -73,7 +73,7 @@
7474 'confirmaccount-notes' => 'Additional notes:',
7575 'confirmaccount-urls' => 'List of websites:',
7676 'confirmaccount-none-p' => '(not provided)',
77 - 'confirmaccount-confirm' => 'Use the options below to accept, deny, or hold this request:',
 77+ 'confirmaccount-confirm' => 'Use the options below to accept, reject, or hold this request:',
7878 'confirmaccount-econf' => '(confirmed)',
7979 'confirmaccount-reject' => '(rejected by [[User:$1|$1]] on $2)',
8080 'confirmaccount-rational' => 'Rationale given to applicant:',
@@ -90,7 +90,7 @@
9191 'confirmaccount-submit' => 'Confirm',
9292 'confirmaccount-needreason' => 'You must provide a reason in the comment box below.',
9393 'confirmaccount-canthold' => 'This request is already either on hold or deleted.',
94 - 'confirmaccount-badaction' => 'An valid action (accept,reject,hold) must be specified in order to proceed.',
 94+ 'confirmaccount-badaction' => 'An valid action (accept, reject, hold) must be specified in order to proceed.',
9595 'confirmaccount-acc' => 'Account request confirmed successfully;
9696 created new user account [[User:$1|$1]].',
9797 'confirmaccount-rej' => 'Account request rejected successfully.',
Index: trunk/extensions/ConfirmAccount/backend/ConfirmAccount.class.php
@@ -287,4 +287,21 @@
288288 }
289289 return $res;
290290 }
 291+
 292+ /**
 293+ * Get a block for this user if they are blocked from requesting accounts
 294+ * @param User $user
 295+ * @return Block|null
 296+ */
 297+ public static function getAccountRequestBlock( User $user ) {
 298+ global $wgAccountRequestWhileBlocked;
 299+
 300+ $block = false;
 301+ # If a user cannot make accounts, don't let them request them either
 302+ if ( !$wgAccountRequestWhileBlocked ) {
 303+ $block = $user->isBlockedFromCreateAccount();
 304+ }
 305+
 306+ return $block;
 307+ }
291308 }
Index: trunk/extensions/ConfirmAccount/business/AccountRequestSubmission.php
@@ -65,8 +65,17 @@
6666 public function submit( IContextSource $context ) {
6767 global $wgAuth, $wgAccountRequestThrottle, $wgMemc, $wgContLang;
6868 global $wgAccountRequestToS, $wgAccountRequestMinWords;
 69+
6970 $reqUser = $this->requester;
7071
 72+ # Make sure that basic permissions are checked
 73+ $block = ConfirmAccount::getAccountRequestBlock( $reqUser );
 74+ if ( $block ) {
 75+ return array( 'accountreq_permission_denied', wfMsgHtml( 'badaccess-group0' ) );
 76+ } elseif ( wfReadOnly() ) {
 77+ return array( 'accountreq_readonly', wfMsgHtml( 'badaccess-group0' ) );
 78+ }
 79+
7180 # Now create a dummy user ($u) and check if it is valid
7281 if ( $this->userName === '' ) {
7382 return array( 'accountreq_no_name', wfMsgHtml( 'noname' ) );
Index: trunk/extensions/ConfirmAccount/business/AccountConfirmSubmission.php
@@ -32,6 +32,12 @@
3333 * @return array( true or error key string, html error msg or null )
3434 */
3535 public function submit( IContextSource $context ) {
 36+ # Make sure that basic permissions are checked
 37+ if ( !$this->admin->getID() || !$this->admin->isAllowed( 'confirmaccount' ) ) {
 38+ return array( 'accountconf_permission_denied', wfMsgHtml( 'badaccess-group0' ) );
 39+ } elseif ( wfReadOnly() ) {
 40+ return array( 'accountconf_readonly', wfMsgHtml( 'badaccess-group0' ) );
 41+ }
3642 if ( $this->action === 'spam' ) {
3743 return $this->spamRequest( $context );
3844 } elseif ( $this->action === 'reject' ) {
@@ -70,18 +76,16 @@
7177 $u->setEmail( $this->accountReq->getEmail() );
7278 # Send out a rejection email...
7379 if ( $this->reason != '' ) {
74 - $result = $u->sendMail(
75 - wfMsgForContent( 'confirmaccount-email-subj' ),
76 - wfMsgExt( 'confirmaccount-email-body4',
77 - array( 'parsemag', 'content' ), $u->getName(), $this->reason )
78 - );
79 - } else { // no reason given
80 - $result = $u->sendMail(
81 - wfMsgForContent( 'confirmaccount-email-subj' ),
82 - wfMsgExt( 'confirmaccount-email-body3',
83 - array( 'parsemag', 'content' ), $u->getName() )
84 - );
 80+ $emailBody = wfMsgExt( 'confirmaccount-email-body4',
 81+ array( 'parsemag', 'content' ), $u->getName(), $this->reason );
 82+ } else {
 83+ $emailBody = wfMsgExt( 'confirmaccount-email-body3',
 84+ array( 'parsemag', 'content' ), $u->getName() );
8585 }
 86+ $result = $u->sendMail(
 87+ wfMsgForContent( 'confirmaccount-email-subj' ),
 88+ $emailBody
 89+ );
8690 if ( !$result->isOk() ) {
8791 $dbw->rollback();
8892 return array( 'accountconf_mailerror',
@@ -200,7 +204,7 @@
201205 # DELETE new rows in case there was a COMMIT somewhere
202206 $this->acceptRequest_rollback( $dbw, $user->getId(), $acd_id );
203207 return array( 'accountconf_copyfailed',
204 - $context->getOutput()->parse( $result->getWikiText() ) );
 208+ $context->getOutput()->parse( $status->getWikiText() ) );
205209 }
206210 }
207211 $acd_id = $dbw->nextSequenceValue( 'account_credentials_acd_id_seq' );

Status & tagging log