From a3d9f524dbbcf94157c87432bc9179e6bf0b53e1 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Fri, 13 Apr 2012 12:54:52 +0200 Subject: [PATCH] Removed usage of global objects in SpecialEmailUser * Added $context parameter to SpecialEmailUser::submit() to replace usage of $wgUser and wfMsg*() calls; added SpecialEmailUser::uiSubmit() as wrapper for HTMLForm submission and updated the call in ApiEmailUser * Use local context to get messages Change-Id: Id5a7330486b9ccd5325293590eeefeba1c0f0536 --- includes/api/ApiEmailUser.php | 2 +- includes/specials/SpecialEmailuser.php | 49 +++++++++++++++----------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/includes/api/ApiEmailUser.php b/includes/api/ApiEmailUser.php index d9eed60cee..0032bd81d8 100644 --- a/includes/api/ApiEmailUser.php +++ b/includes/api/ApiEmailUser.php @@ -55,7 +55,7 @@ class ApiEmailUser extends ApiBase { 'Subject' => $params['subject'], 'CCMe' => $params['ccme'], ); - $retval = SpecialEmailUser::submit( $data ); + $retval = SpecialEmailUser::submit( $data, $this->getContext() ); if ( $retval instanceof Status ) { // SpecialEmailUser sometimes returns a status diff --git a/includes/specials/SpecialEmailuser.php b/includes/specials/SpecialEmailuser.php index 314da7274c..55b500df37 100644 --- a/includes/specials/SpecialEmailuser.php +++ b/includes/specials/SpecialEmailuser.php @@ -61,7 +61,8 @@ class SpecialEmailUser extends UnlistedSpecialPage { ), 'Subject' => array( 'type' => 'text', - 'default' => wfMsgExt( 'defemailsubject', array( 'content', 'parsemag' ), $this->getUser()->getName() ), + 'default' => $this->msg( 'defemailsubject', + $this->getUser()->getName() )->inContentLanguage()->text(), 'label-message' => 'emailsubject', 'maxlength' => 200, 'size' => 60, @@ -124,11 +125,11 @@ class SpecialEmailUser extends UnlistedSpecialPage { $this->mTargetObj = $ret; $form = new HTMLForm( $this->getFormFields(), $this->getContext() ); - $form->addPreText( wfMsgExt( 'emailpagetext', 'parseinline' ) ); - $form->setSubmitText( wfMsg( 'emailsend' ) ); + $form->addPreText( $this->msg( 'emailpagetext' )->parse() ); + $form->setSubmitTextMsg( 'emailsend' ); $form->setTitle( $this->getTitle() ); - $form->setSubmitCallback( array( __CLASS__, 'submit' ) ); - $form->setWrapperLegend( wfMsgExt( 'email-legend', 'parsemag' ) ); + $form->setSubmitCallback( array( __CLASS__, 'uiSubmit' ) ); + $form->setWrapperLegendMsg( 'email-legend' ); $form->loadData(); if( !wfRunHooks( 'EmailUserForm', array( &$form ) ) ) { @@ -224,14 +225,26 @@ class SpecialEmailUser extends UnlistedSpecialPage { $string = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'askusername' ) ) . Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . Xml::openElement( 'fieldset' ) . - Html::rawElement( 'legend', null, wfMessage( 'emailtarget' )->parse() ) . - Xml::inputLabel( wfMessage( 'emailusername' )->text(), 'target', 'emailusertarget', 30, $name ) . ' ' . - Xml::submitButton( wfMessage( 'emailusernamesubmit' )->text() ) . + Html::rawElement( 'legend', null, $this->msg( 'emailtarget' )->parse() ) . + Xml::inputLabel( $this->msg( 'emailusername' )->text(), 'target', 'emailusertarget', 30, $name ) . ' ' . + Xml::submitButton( $this->msg( 'emailusernamesubmit' )->text() ) . Xml::closeElement( 'fieldset' ) . Xml::closeElement( 'form' ) . "\n"; return $string; } + /** + * Submit callback for an HTMLForm object, will simply call submit(). + * + * @since 1.20 + * @param $data array + * @param $form HTMLForm object + * @return Status|string|bool + */ + public static function uiSubmit( array $data, HTMLForm $form ) { + return self::submit( $data, $form->getContext() ); + } + /** * Really send a mail. Permissions should have been checked using * getPermissionsError(). It is probably also a good @@ -240,25 +253,22 @@ class SpecialEmailUser extends UnlistedSpecialPage { * @return Mixed: Status object, or potentially a String on error * or maybe even true on success if anything uses the EmailUser hook. */ - public static function submit( $data ) { + public static function submit( array $data, IContextSource $context ) { global $wgUser, $wgUserEmailUseReplyTo; $target = self::getTarget( $data['Target'] ); if( !$target instanceof User ) { - return wfMsgExt( $target . 'text', 'parse' ); + return $context->msg( $target . 'text' )->parseAsBlock(); } $to = new MailAddress( $target ); - $from = new MailAddress( $wgUser ); + $from = new MailAddress( $context->getUser() ); $subject = $data['Subject']; $text = $data['Text']; // Add a standard footer and trim up trailing newlines $text = rtrim( $text ) . "\n\n-- \n"; - $text .= wfMsgExt( - 'emailuserfooter', - array( 'content', 'parsemag' ), - array( $from->name, $to->name ) - ); + $text .= $context->msg( 'emailuserfooter', + $from->name, $to->name )->inContentLanguage()->text(); $error = ''; if( !wfRunHooks( 'EmailUser', array( &$to, &$from, &$subject, &$text, &$error ) ) ) { @@ -302,11 +312,8 @@ class SpecialEmailUser extends UnlistedSpecialPage { // unless they are emailing themselves, in which case one // copy of the message is sufficient. if ( $data['CCMe'] && $to != $from ) { - $cc_subject = wfMsg( - 'emailccsubject', - $target->getName(), - $subject - ); + $cc_subject = $context->msg( 'emailccsubject' )->rawParams( + $target->getName(), $subject )->text(); wfRunHooks( 'EmailUserCC', array( &$from, &$from, &$cc_subject, &$text ) ); $ccStatus = UserMailer::send( $from, $from, $cc_subject, $text ); $status->merge( $ccStatus ); -- 2.20.1