r99333 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99332‎ | r99333 | r99334 >
Date:05:11, 9 October 2011
Author:aaron
Status:deferred
Tags:
Comment:
* Split out ConfirmAccount::getOpenEmailConfirmedCount() and ConfirmAccount::clearAccountRequestCountCache() functions
* Fixed confirmAccountsNotice() function by checking $title->isSpecial()
* Added UserAccountRequest::newFromName() function
* Cleaned up addRequestLoginText() and checkIfAccountNameIsPending() a bit
* Fixed directory in defineResourceModules()
Modified paths:
  • /trunk/extensions/ConfirmAccount/business/AccountRequestSubmission.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/dataclasses/ConfirmAccount.class.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/dataclasses/UserAccountRequest.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/presentation/ConfirmAccountUI.hooks.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/presentation/ConfirmAccountUI.setup.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/presentation/specialpages/actions/ConfirmAccount_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ConfirmAccount/dataclasses/ConfirmAccount.class.php
@@ -40,9 +40,7 @@
4141 __METHOD__ );
4242
4343 # Clear cache for notice of how many account requests there are
44 - global $wgMemc;
45 - $key = wfMemcKey( 'confirmaccount', 'noticecount' );
46 - $wgMemc->delete( $key );
 44+ self::clearAccountRequestCountCache();
4745 }
4846
4947 /**
@@ -51,16 +49,13 @@
5250 * @param sring $name
5351 */
5452 public static function confirmEmail( $name ) {
55 - global $wgMemc;
56 -
5753 $dbw = wfGetDB( DB_MASTER );
5854 $dbw->update( 'account_requests',
5955 array( 'acr_email_authenticated' => $dbw->timestamp() ),
6056 array( 'acr_name' => $name ),
6157 __METHOD__ );
6258 # Clear cache for notice of how many account requests there are
63 - $key = wfMemcKey( 'confirmaccount', 'noticecount' );
64 - $wgMemc->delete( $key );
 59+ self::clearAccountRequestCountCache();
6560 }
6661
6762 /**
@@ -161,6 +156,49 @@
162157 }
163158
164159 /**
 160+ * Get the number of open email-confirmed account requests for a request type
 161+ * @param $type int|string A request type or '*' for all
 162+ * @return int
 163+ */
 164+ public static function getOpenEmailConfirmedCount( $type = '*' ) {
 165+ global $wgMemc;
 166+
 167+ # Check cached results
 168+ $key = wfMemcKey( 'confirmaccount', 'econfopencount', $type );
 169+ $count = $wgMemc->get( $key );
 170+ # Only show message if there are any such requests
 171+ if ( $count === false ) {
 172+ $conds = array(
 173+ 'acr_deleted' => 0, // not rejected
 174+ 'acr_held IS NULL', // nor held
 175+ 'acr_email_authenticated IS NOT NULL' ); // email confirmed
 176+ if ( $type !== '*' ) {
 177+ $conds['acr_type'] = (int)$type;
 178+ }
 179+ $dbw = wfGetDB( DB_MASTER );
 180+ $count = (int)$dbw->selectField( 'account_requests', 'COUNT(*)', $conds, __METHOD__ );
 181+ # Cache results (invalidated on change )
 182+ $wgMemc->set( $key, $count, 3600 * 24 * 7 );
 183+ }
 184+ return $count;
 185+ }
 186+
 187+ /**
 188+ * Clear account request cache
 189+ * @return void
 190+ */
 191+ public static function clearAccountRequestCountCache() {
 192+ global $wgAccountRequestTypes, $wgMemc;
 193+
 194+ $types = array_keys( $wgAccountRequestTypes );
 195+ $types[] = '*'; // "all" types count
 196+ foreach( $types as $type ) {
 197+ $key = wfMemcKey( 'confirmaccount', 'econfopencount', $type );
 198+ $wgMemc->delete( $key );
 199+ }
 200+ }
 201+
 202+ /**
165203 * Verifies that it's ok to include the uploaded file
166204 *
167205 * @param string $tmpfile the full path of the temporary file to verify
@@ -169,8 +207,8 @@
170208 */
171209 public static function verifyAttachment( $tmpfile, $extension ) {
172210 global $wgVerifyMimeType, $wgMimeTypeBlacklist;
173 - # magically determine mime type
174 - $magic =& MimeMagic::singleton();
 211+
 212+ $magic =& MimeMagic::singleton(); // magically determine mime type
175213 $mime = $magic->guessMimeType( $tmpfile, false );
176214 # check mime type, if desired
177215 if ( $wgVerifyMimeType ) {
Index: trunk/extensions/ConfirmAccount/dataclasses/UserAccountRequest.php
@@ -110,8 +110,8 @@
111111
112112 /**
113113 * @param $id int
114 - * @param $from string|null 'master' to use DB master
115 - * @return UserAccountRequest
 114+ * @param $from string|null 'dbmaster' to use DB master
 115+ * @return UserAccountRequest|null
116116 */
117117 public static function newFromId( $id, $from = null ) {
118118 $db = ( $master == 'dbmaster' )
@@ -125,6 +125,22 @@
126126 }
127127
128128 /**
 129+ * @param $name string
 130+ * @param $from string|null 'dbmaster' to use DB master
 131+ * @return UserAccountRequest|null
 132+ */
 133+ public static function newFromName( $name, $from = null ) {
 134+ $db = ( $master == 'dbmaster' )
 135+ ? wfGetDB( DB_MASTER )
 136+ : wfGetDB( DB_SLAVE );
 137+ $row = $db->selectRow( 'account_requests', array( 'acr_name' => $name ), __METHOD__ );
 138+ if ( !$row ) {
 139+ return null;
 140+ }
 141+ return self::newFromRow( $row );
 142+ }
 143+
 144+ /**
129145 * @return int
130146 */
131147 public function getId() {
Index: trunk/extensions/ConfirmAccount/business/AccountRequestSubmission.php
@@ -209,8 +209,7 @@
210210 $dbw->commit();
211211
212212 # Clear cache for notice of how many account requests there are
213 - $key = wfMemcKey( 'confirmaccount', 'noticecount' );
214 - $wgMemc->delete( $key );
 213+ ConfirmAccount::clearAccountRequestCountCache();
215214 # No request spamming...
216215 if ( $wgAccountRequestThrottle && $reqUser->isPingLimitable() ) {
217216 $key = wfMemcKey( 'acctrequest', 'ip', $ip );
Index: trunk/extensions/ConfirmAccount/presentation/ConfirmAccountUI.hooks.php
@@ -8,11 +8,12 @@
99 * @return bool
1010 */
1111 public static function addRequestLoginText( &$template ) {
12 - global $wgUser, $wgOut;
 12+ $context = RequestContext::getMain();
1313 # Add a link to RequestAccount from UserLogin
14 - if ( !$wgUser->isAllowed( 'createaccount' ) ) {
 14+ if ( !$context->getUser()->isAllowed( 'createaccount' ) ) {
1515 $template->set( 'header', wfMsgExt( 'requestaccount-loginnotice', 'parse' ) );
16 - $wgOut->addModules( 'ext.confirmAccount' ); // CSS
 16+
 17+ $context->getOutput()->addModules( 'ext.confirmAccount' ); // CSS
1718 }
1819 return true;
1920 }
@@ -22,11 +23,11 @@
2324 * @param $title
2425 * @return bool
2526 */
26 - public static function setRequestLoginLinks( &$personal_urls, &$title ) {
 27+ public static function setRequestLoginLinks( array &$personal_urls, &$title ) {
2728 if ( isset( $personal_urls['anonlogin'] ) ) {
28 - $personal_urls['anonlogin']['text'] = wfMsg('nav-login-createaccount');
29 - } elseif ( isset($personal_urls['login'] ) ) {
30 - $personal_urls['login']['text'] = wfMsg('nav-login-createaccount');
 29+ $personal_urls['anonlogin']['text'] = wfMsg( 'nav-login-createaccount' );
 30+ } elseif ( isset( $personal_urls['login'] ) ) {
 31+ $personal_urls['login']['text'] = wfMsg( 'nav-login-createaccount' );
3132 }
3233 return true;
3334 }
@@ -39,11 +40,7 @@
4041 public static function checkIfAccountNameIsPending( User $user, &$abortError ) {
4142 # If an account is made with name X, and one is pending with name X
4243 # we will have problems if the pending one is later confirmed
43 - $dbw = wfGetDB( DB_MASTER );
44 - $dup = $dbw->selectField( 'account_requests', '1',
45 - array( 'acr_name' => $user->getName() ),
46 - __METHOD__ );
47 - if ( $dup ) {
 44+ if ( !UserAccountRequest::acquireUsername( $user->getName() ) ) {
4845 $abortError = wfMsgHtml( 'requestaccount-inuse' );
4946 return false;
5047 }
@@ -51,54 +48,36 @@
5249 }
5350
5451 /**
55 - * FIXME: don't just take on to general site notice
 52+ * FIXME: don't just tack on to general site notice
5653 *
5754 * @param $notice
5855 * @return bool
5956 */
6057 public static function confirmAccountsNotice( &$notice ) {
61 - global $wgConfirmAccountNotice, $wgUser, $wgMemc, $wgOut;
62 - if ( !$wgConfirmAccountNotice || !$wgUser->isAllowed( 'confirmaccount' ) ) {
 58+ global $wgConfirmAccountNotice;
 59+
 60+ $context = RequestContext::getMain();
 61+ if ( !$wgConfirmAccountNotice || !$context->getUser()->isAllowed( 'confirmaccount' ) ) {
6362 return true;
6463 }
6564 # Only show on some special pages
66 - $title = RequestContext::getMain()->getTitle();
67 - if ( !$title->isSpecialPage() ) {
 65+ $title = $context->getTitle();
 66+ if ( !$title->isSpecial( 'RecentChanges' ) && !$title->isSpecial( 'Watchlist' ) ) {
6867 return true;
69 - } elseif (
70 - !$title->equals( SpecialPage::getTitleFor( 'Recentchanges' ) ) &&
71 - !$title->equals( SpecialPage::getTitleFor( 'Watchlist' ) ) )
72 - {
73 - return true;
7468 }
75 - # Check cached results
76 - $key = wfMemcKey( 'confirmaccount', 'noticecount' );
77 - $count = $wgMemc->get( $key );
78 - # Only show message if there are any such requests
79 - if ( !$count ) {
80 - $dbw = wfGetDB( DB_MASTER );
81 - $count = $dbw->selectField( 'account_requests', 'COUNT(*)',
82 - array( 'acr_deleted' => 0,
83 - 'acr_held IS NULL',
84 - 'acr_email_authenticated IS NOT NULL' ),
85 - __METHOD__ );
86 - # Use '-' for zero, to avoid any confusion over key existence
87 - if ( !$count ) {
88 - $count = '-';
89 - }
90 - # Cache results
91 - $wgMemc->set( $key, $count, 3600 * 24 * 7 );
92 - }
93 - if ( $count !== '-' ) {
94 - $message = wfMsgExt( 'confirmaccount-newrequests', array( 'parsemag' ), $count );
 69+ $count = ConfirmAccount::getOpenEmailConfirmedCount( '*' );
 70+ if ( $count > 0 ) {
 71+ $message = wfMsgExt( 'confirmaccount-newrequests', 'parsemag', $count );
9572 $notice .= '<div id="mw-confirmaccount-msg" class="mw-confirmaccount-bar">' .
96 - $wgOut->parse( $message ) . '</div>';
97 - $wgOut->addModules( 'ext.confirmAccount' ); // CSS
 73+ $context->getOutput()->parse( $message ) . '</div>';
 74+
 75+ $context->getOutput()->addModules( 'ext.confirmAccount' ); // CSS
9876 }
9977 return true;
10078 }
10179
10280 /**
 81+ * For AdminLinks extension
10382 * @param $admin_links_tree
10483 * @return bool
10584 */
Index: trunk/extensions/ConfirmAccount/presentation/specialpages/actions/ConfirmAccount_body.php
@@ -488,9 +488,7 @@
489489 $dbw->commit();
490490
491491 # Clear cache for notice of how many account requests there are
492 - global $wgMemc;
493 - $key = wfMemcKey( 'confirmaccount', 'noticecount' );
494 - $wgMemc->delete( $key );
 492+ ConfirmAccount::clearAccountRequestCountCache();
495493
496494 $this->showSuccess( $this->submitType );
497495 } elseif( $this->submitType === 'accept' ) {
@@ -642,9 +640,7 @@
643641 $user->addNewUserLogEntry();
644642
645643 # Clear cache for notice of how many account requests there are
646 - global $wgMemc;
647 - $memKey = wfMemcKey( 'confirmaccount', 'noticecount' );
648 - $wgMemc->delete( $memKey );
 644+ ConfirmAccount::clearAccountRequestCountCache();
649645
650646 # Delete any attached file. Do not stop the whole process if this fails
651647 if( $key ) {
@@ -766,9 +762,7 @@
767763 $dbw->commit();
768764
769765 # Clear cache for notice of how many account requests there are
770 - global $wgMemc;
771 - $key = wfMemcKey( 'confirmaccount', 'noticecount' );
772 - $wgMemc->delete( $key );
 766+ ConfirmAccount::clearAccountRequestCountCache();
773767
774768 $this->showSuccess( $this->submitType );
775769 } else {
Index: trunk/extensions/ConfirmAccount/presentation/ConfirmAccountUI.setup.php
@@ -32,7 +32,7 @@
3333 public static function defineResourceModules( &$modules ) {
3434 $modules['ext.confirmAccount'] = array(
3535 'styles' => 'confirmaccount.css',
36 - 'localBasePath' => dirname( __FILE__ ) . '/presentation/modules',
 36+ 'localBasePath' => dirname( __FILE__ ) . '/modules',
3737 'remoteExtPath' => 'ConfirmAccount/presentation/modules',
3838 );
3939 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r99329* Split config settings off into .config file...aaron23:43, 8 October 2011

Status & tagging log