summaryrefslogtreecommitdiff
path: root/includes/specials/SpecialEmailuser.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2014-12-27 15:41:37 +0100
committerPierre Schmitz <pierre@archlinux.de>2014-12-31 11:43:28 +0100
commitc1f9b1f7b1b77776192048005dcc66dcf3df2bfb (patch)
tree2b38796e738dd74cb42ecd9bfd151803108386bc /includes/specials/SpecialEmailuser.php
parentb88ab0086858470dd1f644e64cb4e4f62bb2be9b (diff)
Update to MediaWiki 1.24.1
Diffstat (limited to 'includes/specials/SpecialEmailuser.php')
-rw-r--r--includes/specials/SpecialEmailuser.php60
1 files changed, 32 insertions, 28 deletions
diff --git a/includes/specials/SpecialEmailuser.php b/includes/specials/SpecialEmailuser.php
index 2e90d996..20532a92 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 ) {
@@ -138,18 +139,19 @@ class SpecialEmailUser extends UnlistedSpecialPage {
$ret = self::getTarget( $this->mTarget );
if ( !$ret instanceof User ) {
if ( $this->mTarget != '' ) {
+ // Messages used here: notargettext, noemailtext, nowikiemailtext
$ret = ( $ret == 'notarget' ) ? 'emailnotarget' : ( $ret . 'text' );
$out->wrapWikiMsg( "<p class='error'>$1</p>", $ret );
}
$out->addHTML( $this->userForm( $this->mTarget ) );
- return false;
+ return;
}
$this->mTargetObj = $ret;
$context = new DerivativeContext( $this->getContext() );
- $context->setTitle( $this->getTitle() ); // Remove subpage
+ $context->setTitle( $this->getPageTitle() ); // Remove subpage
$form = new HTMLForm( $this->getFormFields(), $context );
// By now we are supposed to be sure that $this->mTarget is a user name
$form->addPreText( $this->msg( 'emailpagetext', $this->mTarget )->parse() );
@@ -159,7 +161,7 @@ class SpecialEmailUser extends UnlistedSpecialPage {
$form->loadData();
if ( !wfRunHooks( 'EmailUserForm', array( &$form ) ) ) {
- return false;
+ return;
}
$result = $form->show();
@@ -174,8 +176,8 @@ class SpecialEmailUser extends UnlistedSpecialPage {
/**
* Validate target User
*
- * @param string $target target user name
- * @return User object on success or a string on error
+ * @param string $target Target user name
+ * @return User User object on success or a string on error
*/
public static function getTarget( $target ) {
if ( $target == '' ) {
@@ -205,14 +207,17 @@ class SpecialEmailUser extends UnlistedSpecialPage {
/**
* Check whether a user is allowed to send email
*
- * @param $user User object
- * @param string $editToken edit token
- * @return null on success or string on error
+ * @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';
}
@@ -251,16 +256,15 @@ class SpecialEmailUser extends UnlistedSpecialPage {
/**
* Form to ask for target user name.
*
- * @param string $name user name submitted.
- * @return String: form asking for user name.
+ * @param string $name User name submitted.
+ * @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->getTitle()->getPrefixedText() ) .
+ Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() ) .
Xml::openElement( 'fieldset' ) .
Html::rawElement( 'legend', null, $this->msg( 'emailtarget' )->parse() ) .
Xml::inputLabel(
@@ -282,8 +286,8 @@ class SpecialEmailUser extends UnlistedSpecialPage {
* Submit callback for an HTMLForm object, will simply call submit().
*
* @since 1.20
- * @param $data array
- * @param $form HTMLForm object
+ * @param array $data
+ * @param HTMLForm $form
* @return Status|string|bool
*/
public static function uiSubmit( array $data, HTMLForm $form ) {
@@ -297,19 +301,20 @@ class SpecialEmailUser extends UnlistedSpecialPage {
*
* @param array $data
* @param IContextSource $context
- * @return Mixed: Status object, or potentially a String on error
+ * @return Status|string|bool Status object, or potentially a String on error
* 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 ) {
+ // Messages used here: notargettext, noemailtext, nowikiemailtext
return $context->msg( $target . 'text' )->parseAsBlock();
}
- $to = new MailAddress( $target );
- $from = new MailAddress( $context->getUser() );
+ $to = MailAddress::newFromUser( $target );
+ $from = MailAddress::newFromUser( $context->getUser() );
$subject = $data['Subject'];
$text = $data['Text'];
@@ -323,16 +328,15 @@ 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, $wgPasswordSenderName;
-
- $mailFrom = new MailAddress( $wgPasswordSender, $wgPasswordSenderName );
+ $mailFrom = new MailAddress( $config->get( 'PasswordSender' ),
+ wfMessage( 'emailsender' )->inContentLanguage()->text() );
$replyTo = $from;
} else {
// Put the sending user's e-mail address in the From: header.