http://www.mediawiki.org/wiki/Special:Code/MediaWiki/99333
Revision: 99333 Author: aaron Date: 2011-10-09 05:11:25 +0000 (Sun, 09 Oct 2011) Log Message: ----------- * 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 trunk/extensions/ConfirmAccount/dataclasses/ConfirmAccount.class.php trunk/extensions/ConfirmAccount/dataclasses/UserAccountRequest.php trunk/extensions/ConfirmAccount/presentation/ConfirmAccountUI.hooks.php trunk/extensions/ConfirmAccount/presentation/ConfirmAccountUI.setup.php trunk/extensions/ConfirmAccount/presentation/specialpages/actions/ConfirmAccount_body.php Modified: trunk/extensions/ConfirmAccount/business/AccountRequestSubmission.php =================================================================== --- trunk/extensions/ConfirmAccount/business/AccountRequestSubmission.php 2011-10-09 03:50:03 UTC (rev 99332) +++ trunk/extensions/ConfirmAccount/business/AccountRequestSubmission.php 2011-10-09 05:11:25 UTC (rev 99333) @@ -209,8 +209,7 @@ $dbw->commit(); # Clear cache for notice of how many account requests there are - $key = wfMemcKey( 'confirmaccount', 'noticecount' ); - $wgMemc->delete( $key ); + ConfirmAccount::clearAccountRequestCountCache(); # No request spamming... if ( $wgAccountRequestThrottle && $reqUser->isPingLimitable() ) { $key = wfMemcKey( 'acctrequest', 'ip', $ip ); Modified: trunk/extensions/ConfirmAccount/dataclasses/ConfirmAccount.class.php =================================================================== --- trunk/extensions/ConfirmAccount/dataclasses/ConfirmAccount.class.php 2011-10-09 03:50:03 UTC (rev 99332) +++ trunk/extensions/ConfirmAccount/dataclasses/ConfirmAccount.class.php 2011-10-09 05:11:25 UTC (rev 99333) @@ -40,9 +40,7 @@ __METHOD__ ); # Clear cache for notice of how many account requests there are - global $wgMemc; - $key = wfMemcKey( 'confirmaccount', 'noticecount' ); - $wgMemc->delete( $key ); + self::clearAccountRequestCountCache(); } /** @@ -51,16 +49,13 @@ * @param sring $name */ public static 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 ); + self::clearAccountRequestCountCache(); } /** @@ -161,6 +156,49 @@ } /** + * Get the number of open email-confirmed account requests for a request type + * @param $type int|string A request type or '*' for all + * @return int + */ + public static function getOpenEmailConfirmedCount( $type = '*' ) { + global $wgMemc; + + # Check cached results + $key = wfMemcKey( 'confirmaccount', 'econfopencount', $type ); + $count = $wgMemc->get( $key ); + # Only show message if there are any such requests + if ( $count === false ) { + $conds = array( + 'acr_deleted' => 0, // not rejected + 'acr_held IS NULL', // nor held + 'acr_email_authenticated IS NOT NULL' ); // email confirmed + if ( $type !== '*' ) { + $conds['acr_type'] = (int)$type; + } + $dbw = wfGetDB( DB_MASTER ); + $count = (int)$dbw->selectField( 'account_requests', 'COUNT(*)', $conds, __METHOD__ ); + # Cache results (invalidated on change ) + $wgMemc->set( $key, $count, 3600 * 24 * 7 ); + } + return $count; + } + + /** + * Clear account request cache + * @return void + */ + public static function clearAccountRequestCountCache() { + global $wgAccountRequestTypes, $wgMemc; + + $types = array_keys( $wgAccountRequestTypes ); + $types[] = '*'; // "all" types count + foreach( $types as $type ) { + $key = wfMemcKey( 'confirmaccount', 'econfopencount', $type ); + $wgMemc->delete( $key ); + } + } + + /** * Verifies that it's ok to include the uploaded file * * @param string $tmpfile the full path of the temporary file to verify @@ -169,8 +207,8 @@ */ public static function verifyAttachment( $tmpfile, $extension ) { global $wgVerifyMimeType, $wgMimeTypeBlacklist; - # magically determine mime type - $magic =& MimeMagic::singleton(); + + $magic =& MimeMagic::singleton(); // magically determine mime type $mime = $magic->guessMimeType( $tmpfile, false ); # check mime type, if desired if ( $wgVerifyMimeType ) { Modified: trunk/extensions/ConfirmAccount/dataclasses/UserAccountRequest.php =================================================================== --- trunk/extensions/ConfirmAccount/dataclasses/UserAccountRequest.php 2011-10-09 03:50:03 UTC (rev 99332) +++ trunk/extensions/ConfirmAccount/dataclasses/UserAccountRequest.php 2011-10-09 05:11:25 UTC (rev 99333) @@ -110,8 +110,8 @@ /** * @param $id int - * @param $from string|null 'master' to use DB master - * @return UserAccountRequest + * @param $from string|null 'dbmaster' to use DB master + * @return UserAccountRequest|null */ public static function newFromId( $id, $from = null ) { $db = ( $master == 'dbmaster' ) @@ -125,6 +125,22 @@ } /** + * @param $name string + * @param $from string|null 'dbmaster' to use DB master + * @return UserAccountRequest|null + */ + public static function newFromName( $name, $from = null ) { + $db = ( $master == 'dbmaster' ) + ? wfGetDB( DB_MASTER ) + : wfGetDB( DB_SLAVE ); + $row = $db->selectRow( 'account_requests', array( 'acr_name' => $name ), __METHOD__ ); + if ( !$row ) { + return null; + } + return self::newFromRow( $row ); + } + + /** * @return int */ public function getId() { Modified: trunk/extensions/ConfirmAccount/presentation/ConfirmAccountUI.hooks.php =================================================================== --- trunk/extensions/ConfirmAccount/presentation/ConfirmAccountUI.hooks.php 2011-10-09 03:50:03 UTC (rev 99332) +++ trunk/extensions/ConfirmAccount/presentation/ConfirmAccountUI.hooks.php 2011-10-09 05:11:25 UTC (rev 99333) @@ -8,11 +8,12 @@ * @return bool */ public static function addRequestLoginText( &$template ) { - global $wgUser, $wgOut; + $context = RequestContext::getMain(); # Add a link to RequestAccount from UserLogin - if ( !$wgUser->isAllowed( 'createaccount' ) ) { + if ( !$context->getUser()->isAllowed( 'createaccount' ) ) { $template->set( 'header', wfMsgExt( 'requestaccount-loginnotice', 'parse' ) ); - $wgOut->addModules( 'ext.confirmAccount' ); // CSS + + $context->getOutput()->addModules( 'ext.confirmAccount' ); // CSS } return true; } @@ -22,11 +23,11 @@ * @param $title * @return bool */ - public static function setRequestLoginLinks( &$personal_urls, &$title ) { + public static function setRequestLoginLinks( array &$personal_urls, &$title ) { if ( isset( $personal_urls['anonlogin'] ) ) { - $personal_urls['anonlogin']['text'] = wfMsg('nav-login-createaccount'); - } elseif ( isset($personal_urls['login'] ) ) { - $personal_urls['login']['text'] = wfMsg('nav-login-createaccount'); + $personal_urls['anonlogin']['text'] = wfMsg( 'nav-login-createaccount' ); + } elseif ( isset( $personal_urls['login'] ) ) { + $personal_urls['login']['text'] = wfMsg( 'nav-login-createaccount' ); } return true; } @@ -39,11 +40,7 @@ public static function checkIfAccountNameIsPending( User $user, &$abortError ) { # If an account is made with name X, and one is pending with name X # we will have problems if the pending one is later confirmed - $dbw = wfGetDB( DB_MASTER ); - $dup = $dbw->selectField( 'account_requests', '1', - array( 'acr_name' => $user->getName() ), - __METHOD__ ); - if ( $dup ) { + if ( !UserAccountRequest::acquireUsername( $user->getName() ) ) { $abortError = wfMsgHtml( 'requestaccount-inuse' ); return false; } @@ -51,54 +48,36 @@ } /** - * FIXME: don't just take on to general site notice + * FIXME: don't just tack on to general site notice * * @param $notice * @return bool */ public static function confirmAccountsNotice( &$notice ) { - global $wgConfirmAccountNotice, $wgUser, $wgMemc, $wgOut; - if ( !$wgConfirmAccountNotice || !$wgUser->isAllowed( 'confirmaccount' ) ) { + global $wgConfirmAccountNotice; + + $context = RequestContext::getMain(); + if ( !$wgConfirmAccountNotice || !$context->getUser()->isAllowed( 'confirmaccount' ) ) { return true; } # Only show on some special pages - $title = RequestContext::getMain()->getTitle(); - if ( !$title->isSpecialPage() ) { + $title = $context->getTitle(); + if ( !$title->isSpecial( 'RecentChanges' ) && !$title->isSpecial( 'Watchlist' ) ) { return true; - } elseif ( - !$title->equals( SpecialPage::getTitleFor( 'Recentchanges' ) ) && - !$title->equals( SpecialPage::getTitleFor( 'Watchlist' ) ) ) - { - return true; } - # Check cached results - $key = wfMemcKey( 'confirmaccount', 'noticecount' ); - $count = $wgMemc->get( $key ); - # Only show message if there are any such requests - if ( !$count ) { - $dbw = wfGetDB( DB_MASTER ); - $count = $dbw->selectField( 'account_requests', 'COUNT(*)', - array( 'acr_deleted' => 0, - 'acr_held IS NULL', - 'acr_email_authenticated IS NOT NULL' ), - __METHOD__ ); - # Use '-' for zero, to avoid any confusion over key existence - if ( !$count ) { - $count = '-'; - } - # Cache results - $wgMemc->set( $key, $count, 3600 * 24 * 7 ); - } - if ( $count !== '-' ) { - $message = wfMsgExt( 'confirmaccount-newrequests', array( 'parsemag' ), $count ); + $count = ConfirmAccount::getOpenEmailConfirmedCount( '*' ); + if ( $count > 0 ) { + $message = wfMsgExt( 'confirmaccount-newrequests', 'parsemag', $count ); $notice .= '<div id="mw-confirmaccount-msg" class="mw-confirmaccount-bar">' . - $wgOut->parse( $message ) . '</div>'; - $wgOut->addModules( 'ext.confirmAccount' ); // CSS + $context->getOutput()->parse( $message ) . '</div>'; + + $context->getOutput()->addModules( 'ext.confirmAccount' ); // CSS } return true; } /** + * For AdminLinks extension * @param $admin_links_tree * @return bool */ Modified: trunk/extensions/ConfirmAccount/presentation/ConfirmAccountUI.setup.php =================================================================== --- trunk/extensions/ConfirmAccount/presentation/ConfirmAccountUI.setup.php 2011-10-09 03:50:03 UTC (rev 99332) +++ trunk/extensions/ConfirmAccount/presentation/ConfirmAccountUI.setup.php 2011-10-09 05:11:25 UTC (rev 99333) @@ -32,7 +32,7 @@ public static function defineResourceModules( &$modules ) { $modules['ext.confirmAccount'] = array( 'styles' => 'confirmaccount.css', - 'localBasePath' => dirname( __FILE__ ) . '/presentation/modules', + 'localBasePath' => dirname( __FILE__ ) . '/modules', 'remoteExtPath' => 'ConfirmAccount/presentation/modules', ); } Modified: trunk/extensions/ConfirmAccount/presentation/specialpages/actions/ConfirmAccount_body.php =================================================================== --- trunk/extensions/ConfirmAccount/presentation/specialpages/actions/ConfirmAccount_body.php 2011-10-09 03:50:03 UTC (rev 99332) +++ trunk/extensions/ConfirmAccount/presentation/specialpages/actions/ConfirmAccount_body.php 2011-10-09 05:11:25 UTC (rev 99333) @@ -488,9 +488,7 @@ $dbw->commit(); # Clear cache for notice of how many account requests there are - global $wgMemc; - $key = wfMemcKey( 'confirmaccount', 'noticecount' ); - $wgMemc->delete( $key ); + ConfirmAccount::clearAccountRequestCountCache(); $this->showSuccess( $this->submitType ); } elseif( $this->submitType === 'accept' ) { @@ -642,9 +640,7 @@ $user->addNewUserLogEntry(); # Clear cache for notice of how many account requests there are - global $wgMemc; - $memKey = wfMemcKey( 'confirmaccount', 'noticecount' ); - $wgMemc->delete( $memKey ); + ConfirmAccount::clearAccountRequestCountCache(); # Delete any attached file. Do not stop the whole process if this fails if( $key ) { @@ -766,9 +762,7 @@ $dbw->commit(); # Clear cache for notice of how many account requests there are - global $wgMemc; - $key = wfMemcKey( 'confirmaccount', 'noticecount' ); - $wgMemc->delete( $key ); + ConfirmAccount::clearAccountRequestCountCache(); $this->showSuccess( $this->submitType ); } else { _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs