Index: trunk/extensions/ConfirmAccount/dataclasses/ConfirmAccount.class.php |
— | — | @@ -40,9 +40,7 @@ |
41 | 41 | __METHOD__ ); |
42 | 42 | |
43 | 43 | # 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(); |
47 | 45 | } |
48 | 46 | |
49 | 47 | /** |
— | — | @@ -51,16 +49,13 @@ |
52 | 50 | * @param sring $name |
53 | 51 | */ |
54 | 52 | public static function confirmEmail( $name ) { |
55 | | - global $wgMemc; |
56 | | - |
57 | 53 | $dbw = wfGetDB( DB_MASTER ); |
58 | 54 | $dbw->update( 'account_requests', |
59 | 55 | array( 'acr_email_authenticated' => $dbw->timestamp() ), |
60 | 56 | array( 'acr_name' => $name ), |
61 | 57 | __METHOD__ ); |
62 | 58 | # Clear cache for notice of how many account requests there are |
63 | | - $key = wfMemcKey( 'confirmaccount', 'noticecount' ); |
64 | | - $wgMemc->delete( $key ); |
| 59 | + self::clearAccountRequestCountCache(); |
65 | 60 | } |
66 | 61 | |
67 | 62 | /** |
— | — | @@ -161,6 +156,49 @@ |
162 | 157 | } |
163 | 158 | |
164 | 159 | /** |
| 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 | + /** |
165 | 203 | * Verifies that it's ok to include the uploaded file |
166 | 204 | * |
167 | 205 | * @param string $tmpfile the full path of the temporary file to verify |
— | — | @@ -169,8 +207,8 @@ |
170 | 208 | */ |
171 | 209 | public static function verifyAttachment( $tmpfile, $extension ) { |
172 | 210 | global $wgVerifyMimeType, $wgMimeTypeBlacklist; |
173 | | - # magically determine mime type |
174 | | - $magic =& MimeMagic::singleton(); |
| 211 | + |
| 212 | + $magic =& MimeMagic::singleton(); // magically determine mime type |
175 | 213 | $mime = $magic->guessMimeType( $tmpfile, false ); |
176 | 214 | # check mime type, if desired |
177 | 215 | if ( $wgVerifyMimeType ) { |
Index: trunk/extensions/ConfirmAccount/dataclasses/UserAccountRequest.php |
— | — | @@ -110,8 +110,8 @@ |
111 | 111 | |
112 | 112 | /** |
113 | 113 | * @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 |
116 | 116 | */ |
117 | 117 | public static function newFromId( $id, $from = null ) { |
118 | 118 | $db = ( $master == 'dbmaster' ) |
— | — | @@ -125,6 +125,22 @@ |
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
| 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 | + /** |
129 | 145 | * @return int |
130 | 146 | */ |
131 | 147 | public function getId() { |
Index: trunk/extensions/ConfirmAccount/business/AccountRequestSubmission.php |
— | — | @@ -209,8 +209,7 @@ |
210 | 210 | $dbw->commit(); |
211 | 211 | |
212 | 212 | # Clear cache for notice of how many account requests there are |
213 | | - $key = wfMemcKey( 'confirmaccount', 'noticecount' ); |
214 | | - $wgMemc->delete( $key ); |
| 213 | + ConfirmAccount::clearAccountRequestCountCache(); |
215 | 214 | # No request spamming... |
216 | 215 | if ( $wgAccountRequestThrottle && $reqUser->isPingLimitable() ) { |
217 | 216 | $key = wfMemcKey( 'acctrequest', 'ip', $ip ); |
Index: trunk/extensions/ConfirmAccount/presentation/ConfirmAccountUI.hooks.php |
— | — | @@ -8,11 +8,12 @@ |
9 | 9 | * @return bool |
10 | 10 | */ |
11 | 11 | public static function addRequestLoginText( &$template ) { |
12 | | - global $wgUser, $wgOut; |
| 12 | + $context = RequestContext::getMain(); |
13 | 13 | # Add a link to RequestAccount from UserLogin |
14 | | - if ( !$wgUser->isAllowed( 'createaccount' ) ) { |
| 14 | + if ( !$context->getUser()->isAllowed( 'createaccount' ) ) { |
15 | 15 | $template->set( 'header', wfMsgExt( 'requestaccount-loginnotice', 'parse' ) ); |
16 | | - $wgOut->addModules( 'ext.confirmAccount' ); // CSS |
| 16 | + |
| 17 | + $context->getOutput()->addModules( 'ext.confirmAccount' ); // CSS |
17 | 18 | } |
18 | 19 | return true; |
19 | 20 | } |
— | — | @@ -22,11 +23,11 @@ |
23 | 24 | * @param $title |
24 | 25 | * @return bool |
25 | 26 | */ |
26 | | - public static function setRequestLoginLinks( &$personal_urls, &$title ) { |
| 27 | + public static function setRequestLoginLinks( array &$personal_urls, &$title ) { |
27 | 28 | 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' ); |
31 | 32 | } |
32 | 33 | return true; |
33 | 34 | } |
— | — | @@ -39,11 +40,7 @@ |
40 | 41 | public static function checkIfAccountNameIsPending( User $user, &$abortError ) { |
41 | 42 | # If an account is made with name X, and one is pending with name X |
42 | 43 | # 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() ) ) { |
48 | 45 | $abortError = wfMsgHtml( 'requestaccount-inuse' ); |
49 | 46 | return false; |
50 | 47 | } |
— | — | @@ -51,54 +48,36 @@ |
52 | 49 | } |
53 | 50 | |
54 | 51 | /** |
55 | | - * FIXME: don't just take on to general site notice |
| 52 | + * FIXME: don't just tack on to general site notice |
56 | 53 | * |
57 | 54 | * @param $notice |
58 | 55 | * @return bool |
59 | 56 | */ |
60 | 57 | 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' ) ) { |
63 | 62 | return true; |
64 | 63 | } |
65 | 64 | # 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' ) ) { |
68 | 67 | return true; |
69 | | - } elseif ( |
70 | | - !$title->equals( SpecialPage::getTitleFor( 'Recentchanges' ) ) && |
71 | | - !$title->equals( SpecialPage::getTitleFor( 'Watchlist' ) ) ) |
72 | | - { |
73 | | - return true; |
74 | 68 | } |
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 ); |
95 | 72 | $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 |
98 | 76 | } |
99 | 77 | return true; |
100 | 78 | } |
101 | 79 | |
102 | 80 | /** |
| 81 | + * For AdminLinks extension |
103 | 82 | * @param $admin_links_tree |
104 | 83 | * @return bool |
105 | 84 | */ |
Index: trunk/extensions/ConfirmAccount/presentation/specialpages/actions/ConfirmAccount_body.php |
— | — | @@ -488,9 +488,7 @@ |
489 | 489 | $dbw->commit(); |
490 | 490 | |
491 | 491 | # 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(); |
495 | 493 | |
496 | 494 | $this->showSuccess( $this->submitType ); |
497 | 495 | } elseif( $this->submitType === 'accept' ) { |
— | — | @@ -642,9 +640,7 @@ |
643 | 641 | $user->addNewUserLogEntry(); |
644 | 642 | |
645 | 643 | # 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(); |
649 | 645 | |
650 | 646 | # Delete any attached file. Do not stop the whole process if this fails |
651 | 647 | if( $key ) { |
— | — | @@ -766,9 +762,7 @@ |
767 | 763 | $dbw->commit(); |
768 | 764 | |
769 | 765 | # 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(); |
773 | 767 | |
774 | 768 | $this->showSuccess( $this->submitType ); |
775 | 769 | } else { |
Index: trunk/extensions/ConfirmAccount/presentation/ConfirmAccountUI.setup.php |
— | — | @@ -32,7 +32,7 @@ |
33 | 33 | public static function defineResourceModules( &$modules ) { |
34 | 34 | $modules['ext.confirmAccount'] = array( |
35 | 35 | 'styles' => 'confirmaccount.css', |
36 | | - 'localBasePath' => dirname( __FILE__ ) . '/presentation/modules', |
| 36 | + 'localBasePath' => dirname( __FILE__ ) . '/modules', |
37 | 37 | 'remoteExtPath' => 'ConfirmAccount/presentation/modules', |
38 | 38 | ); |
39 | 39 | } |