From ea44f2e3b52d00bb8cb74f7189beb9f892421d45 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Sun, 3 Aug 2014 14:52:07 -0700 Subject: [PATCH] SpecialEmailUser: Use Config instead of globals Change-Id: I81f6fb942a9cb12332c4763ab4c26cfcc556ddcb --- includes/api/ApiEmailUser.php | 6 +++++- includes/specials/SpecialEmailuser.php | 25 +++++++++++++------------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/includes/api/ApiEmailUser.php b/includes/api/ApiEmailUser.php index d35b848bc1..9870b2ded8 100644 --- a/includes/api/ApiEmailUser.php +++ b/includes/api/ApiEmailUser.php @@ -40,7 +40,11 @@ class ApiEmailUser extends ApiBase { } // Check permissions and errors - $error = SpecialEmailUser::getPermissionsError( $this->getUser(), $params['token'] ); + $error = SpecialEmailUser::getPermissionsError( + $this->getUser(), + $params['token'], + $this->getConfig() + ); if ( $error ) { $this->dieUsageMsg( array( $error ) ); } diff --git a/includes/specials/SpecialEmailuser.php b/includes/specials/SpecialEmailuser.php index 0958126b20..a4e4c548a6 100644 --- a/includes/specials/SpecialEmailuser.php +++ b/includes/specials/SpecialEmailuser.php @@ -113,7 +113,8 @@ class SpecialEmailUser extends UnlistedSpecialPage { // error out if sending user cannot do this $error = self::getPermissionsError( $this->getUser(), - $this->getRequest()->getVal( 'wpEditToken' ) + $this->getRequest()->getVal( 'wpEditToken' ), + $this->getConfig() ); switch ( $error ) { @@ -208,12 +209,15 @@ class SpecialEmailUser extends UnlistedSpecialPage { * * @param User $user * @param string $editToken Edit token + * @param Config $config optional for backwards compatibility * @return string|null Null on success or string on error */ - public static function getPermissionsError( $user, $editToken ) { - global $wgEnableEmail, $wgEnableUserEmail; - - if ( !$wgEnableEmail || !$wgEnableUserEmail ) { + public static function getPermissionsError( $user, $editToken, Config $config = null ) { + if ( $config === null ) { + wfDebug( __METHOD__ . ' called without a Config instance passed to it' ); + $config = ConfigFactory::getDefaultInstance()->makeConfig( 'main' ); + } + if ( !$config->get( 'EnableEmail' ) || !$config->get( 'EnableUserEmail' ) ) { return 'usermaildisabled'; } @@ -256,10 +260,9 @@ class SpecialEmailUser extends UnlistedSpecialPage { * @return string Form asking for user name. */ protected function userForm( $name ) { - global $wgScript; $string = Xml::openElement( 'form', - array( 'method' => 'get', 'action' => $wgScript, 'id' => 'askusername' ) + array( 'method' => 'get', 'action' => wfScript(), 'id' => 'askusername' ) ) . Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() ) . Xml::openElement( 'fieldset' ) . @@ -302,7 +305,7 @@ class SpecialEmailUser extends UnlistedSpecialPage { * or maybe even true on success if anything uses the EmailUser hook. */ public static function submit( array $data, IContextSource $context ) { - global $wgUserEmailUseReplyTo; + $config = $context->getConfig(); $target = self::getTarget( $data['Target'] ); if ( !$target instanceof User ) { @@ -325,16 +328,14 @@ class SpecialEmailUser extends UnlistedSpecialPage { return $error; } - if ( $wgUserEmailUseReplyTo ) { + if ( $config->get( 'UserEmailUseReplyTo' ) ) { // Put the generic wiki autogenerated address in the From: // header and reserve the user for Reply-To. // // This is a bit ugly, but will serve to differentiate // wiki-borne mails from direct mails and protects against // SPF and bounce problems with some mailers (see below). - global $wgPasswordSender; - - $mailFrom = new MailAddress( $wgPasswordSender, + $mailFrom = new MailAddress( $config->get( 'PasswordSender' ), wfMessage( 'emailsender' )->inContentLanguage()->text() ); $replyTo = $from; } else { -- 2.20.1