Big oops - merged to wrong branch.
[lhc/web/wiklou.git] / includes / specials / SpecialEmailuser.php
index 22bc254..2ab02cb 100644 (file)
@@ -34,14 +34,13 @@ class SpecialEmailUser extends UnlistedSpecialPage {
        }
 
        protected function getFormFields() {
-               global $wgUser;
                return array(
                        'From' => array(
                                'type' => 'info',
                                'raw' => 1,
-                               'default' => $wgUser->getSkin()->link(
-                                       $wgUser->getUserPage(),
-                                       htmlspecialchars( $wgUser->getName() )
+                               'default' => Linker::link(
+                                       $this->getUser()->getUserPage(),
+                                       htmlspecialchars( $this->getUser()->getName() )
                                ),
                                'label-message' => 'emailfrom',
                                'id' => 'mw-emailuser-sender',
@@ -49,7 +48,7 @@ class SpecialEmailUser extends UnlistedSpecialPage {
                        'To' => array(
                                'type' => 'info',
                                'raw' => 1,
-                               'default' => $wgUser->getSkin()->link(
+                               'default' => Linker::link(
                                        $this->mTargetObj->getUserPage(),
                                        htmlspecialchars( $this->mTargetObj->getName() )
                                ),
@@ -62,7 +61,8 @@ class SpecialEmailUser extends UnlistedSpecialPage {
                        ),
                        'Subject' => array(
                                'type' => 'text',
-                               'default' => wfMsgExt( 'defemailsubject', array( 'content', 'parsemag' ) ),
+                               'default' => $this->msg( 'defemailsubject',
+                                       $this->getUser()->getName() )->inContentLanguage()->text(),
                                'label-message' => 'emailsubject',
                                'maxlength' => 200,
                                'size' => 60,
@@ -78,88 +78,72 @@ class SpecialEmailUser extends UnlistedSpecialPage {
                        'CCMe' => array(
                                'type' => 'check',
                                'label-message' => 'emailccme',
-                               'default' => $wgUser->getBoolOption( 'ccmeonemails' ),
+                               'default' => $this->getUser()->getBoolOption( 'ccmeonemails' ),
                        ),
                );
        }
 
        public function execute( $par ) {
-               global $wgRequest, $wgOut, $wgUser;
-
                $this->setHeaders();
                $this->outputHeader();
-               $wgOut->addModuleStyles( 'mediawiki.special' );
+               $out = $this->getOutput();
+               $out->addModuleStyles( 'mediawiki.special' );
                $this->mTarget = is_null( $par )
-                       ? $wgRequest->getVal( 'wpTarget', $wgRequest->getVal( 'target', '' ) )
+                       ? $this->getRequest()->getVal( 'wpTarget', $this->getRequest()->getVal( 'target', '' ) )
                        : $par;
                // error out if sending user cannot do this
-               $error = self::getPermissionsError( $wgUser, $wgRequest->getVal( 'wpEditToken' ) );
+               $error = self::getPermissionsError( $this->getUser(), $this->getRequest()->getVal( 'wpEditToken' ) );
                switch ( $error ) {
                        case null:
                                # Wahey!
                                break;
                        case 'badaccess':
-                               $wgOut->permissionRequired( 'sendemail' );
-                               return;
+                               throw new PermissionsError( 'sendemail' );
                        case 'blockedemailuser':
-                               $wgOut->blockedPage();
-                               return;
+                               throw new UserBlockedError( $this->getUser()->mBlock );
                        case 'actionthrottledtext':
-                               $wgOut->rateLimited();
-                               return;
+                               throw new ThrottledError;
                        case 'mailnologin':
                        case 'usermaildisabled':
-                               $wgOut->showErrorPage( $error, "{$error}text" );
-                               return;
+                               throw new  ErrorPageError( $error, "{$error}text" );
                        default:
                                # It's a hook error
                                list( $title, $msg, $params ) = $error;
-                               $wgOut->showErrorPage( $title, $msg, $params );
-                               return;
+                               throw new  ErrorPageError( $title, $msg, $params );
                }
                // Got a valid target user name? Else ask for one.
                $ret = self::getTarget( $this->mTarget );
                if( !$ret instanceof User ) {
                        if( $this->mTarget != '' ) {
                                $ret = ( $ret == 'notarget' ) ? 'emailnotarget' : ( $ret . 'text' );
-                               $wgOut->addHTML( '<p class="error">' . wfMessage( $ret )->parse() . '</p>' );
+                               $out->wrapWikiMsg( "<p class='error'>$1</p>", $ret );
                        }
-                       $wgOut->addHTML( self::userForm( $this->mTarget ) );
+                       $out->addHTML( $this->userForm( $this->mTarget ) );
                        return false;
                }
 
                $this->mTargetObj = $ret;
 
-               $form = new HTMLForm( $this->getFormFields() );
-               $form->addPreText( wfMsgExt( 'emailpagetext', 'parseinline' ) );
-               $form->setSubmitText( wfMsg( 'emailsend' ) );
+               $form = new HTMLForm( $this->getFormFields(), $this->getContext() );
+               $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 ) ) ) {
                        return false;
                }
 
-               $wgOut->setPageTitle( wfMsg( 'emailpage' ) );
+               $out->setPageTitle( $this->msg( 'emailpage' ) );
                $result = $form->show();
 
                if( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
-                       $wgOut->setPageTitle( wfMsg( 'emailsent' ) );
-                       $wgOut->addWikiMsg( 'emailsenttext' );
-                       if ( $status->successCount > 1 ) $wgOut->addWikiMsg( 'emailyougotcopy' );
-               } elseif ( $result instanceof Status ) {
-                       if ( $status->successCount == 0 ) {
-                               $wgOut->setPageTitle( wfMsg( 'emailnotsent' ) );
-                               $wgOut->addWikiMsg( $result->getWikiText( 'emailfailed' ) );
-                       } elseif ( $status->failCount ) {
-                               $wgOut->setPageTitle( wfMsg( 'emailsent' ) );
-                               $wgOut->addWikiMsg( 'emailsenttext' );
-                               $wgOut->addWikiMsg( $result->getWikiText( 'emailccfailed' ) );
-                       }
+                       $out->setPageTitle( $this->msg( 'emailsent' ) );
+                       $out->addWikiMsg( 'emailsenttext' );
+                       $out->returnToMain( false, $this->mTargetObj->getUserPage() );
                }
-               $wgOut->returnToMain( false, $this->mTargetObj->getUserPage() );
        }
 
        /**
@@ -236,17 +220,31 @@ class SpecialEmailUser extends UnlistedSpecialPage {
         * @param $name String: user name submitted.
         * @return String: form asking for user name.
         */
-       static function userForm( $name ) {
-               $string = Xml::openElement( 'form', array( 'method' => 'get', 'action' => '', 'id' => 'askusername' ) ) .
-                               Xml::openElement( 'fieldset' ) .
-                               Html::rawElement( 'legend', null, wfMessage( 'emailtarget' )->parse() ) .
-                               Xml::inputLabel( wfMessage( 'emailusername' )->text(), 'target', 'emailusertarget', 30, $name ) . ' ' .
-                               Xml::submitButton( wfMessage( 'emailusernamesubmit' )->text() ) .
-                               Xml::closeElement( 'fieldset' ) .
-                               Xml::closeElement( 'form' ) . "\n";
+       protected function userForm( $name ) {
+               global $wgScript;
+               $string = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'askusername' ) ) .
+                       Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
+                       Xml::openElement( 'fieldset' ) .
+                       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
@@ -255,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 ) {
-               global $wgUser, $wgUserEmailUseReplyTo;
+       public static function submit( array $data, IContextSource $context ) {
+               global $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 ) ) ) {
@@ -313,24 +308,14 @@ class SpecialEmailUser extends UnlistedSpecialPage {
                if( !$status->isGood() ) {
                        return $status;
                } else {
-                       $status->successCount++;
-                       
                        // if the user requested a copy of this mail, do this now,
                        // 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 );
-                               if ( $ccStatus->isGood() ) {
-                                       $ccStatus->successCount++;
-                               } else {
-                                       $ccStatus->failCount++;
-                               }
                                $status->merge( $ccStatus );
                        }