SpecialEmailUser: Use Config instead of globals
authorKunal Mehta <legoktm@gmail.com>
Sun, 3 Aug 2014 21:52:07 +0000 (14:52 -0700)
committerKunal Mehta <legoktm@gmail.com>
Sat, 13 Sep 2014 06:39:59 +0000 (23:39 -0700)
Change-Id: I81f6fb942a9cb12332c4763ab4c26cfcc556ddcb

includes/api/ApiEmailUser.php
includes/specials/SpecialEmailuser.php

index d35b848..9870b2d 100644 (file)
@@ -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 ) );
                }
index 0958126..a4e4c54 100644 (file)
@@ -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 {