Revert "Convert Special:EmailUser to use OOUIHTMLForm"
authorFlorianschmidtwelzow <florian.schmidt.stargatewissen@gmail.com>
Sun, 10 Jan 2016 14:20:52 +0000 (14:20 +0000)
committerFlorianschmidtwelzow <florian.schmidt.stargatewissen@gmail.com>
Sun, 10 Jan 2016 14:20:52 +0000 (14:20 +0000)
This reverts commit bc9b2162cbfeaabdcbfe8bdf342a33523ea4f3d0.

Just in case, this change[1] isn't merged before the next wmf-release (12 January) to unbreak the form.

[1] I3e0c02155428ae400bc3a6d3ed2e66e69ee441fa

Change-Id: I1a594485fbf8c75b4199df2e255dedc7fb90e74d

includes/htmlform/HTMLForm.php
includes/specials/SpecialEmailuser.php

index 082c0d8..5f05b06 100644 (file)
@@ -1167,8 +1167,6 @@ class HTMLForm extends ContextSource {
         */
        public function setSubmitDestructive() {
                $this->mSubmitFlags = array( 'destructive', 'primary' );
-
-               return $this;
        }
 
        /**
@@ -1177,8 +1175,6 @@ class HTMLForm extends ContextSource {
         */
        public function setSubmitProgressive() {
                $this->mSubmitFlags = array( 'progressive', 'primary' );
-
-               return $this;
        }
 
        /**
index 3aeadc9..618e700 100644 (file)
@@ -85,6 +85,7 @@ class SpecialEmailUser extends UnlistedSpecialPage {
                        'Text' => array(
                                'type' => 'textarea',
                                'rows' => 20,
+                               'cols' => 80,
                                'label-message' => 'emailmessage',
                                'required' => true,
                        ),
@@ -98,16 +99,12 @@ class SpecialEmailUser extends UnlistedSpecialPage {
 
        public function execute( $par ) {
                $out = $this->getOutput();
-               $request = $this->getRequest();
                $out->addModuleStyles( 'mediawiki.special' );
 
                $this->mTarget = is_null( $par )
-                       ? $request->getVal( 'wpTarget', '' )
+                       ? $this->getRequest()->getVal( 'wpTarget', $this->getRequest()->getVal( 'target', '' ) )
                        : $par;
 
-               // make sure, that HTMLForm uses the correct target
-               $request->setVal( 'wpTarget', $this->mTarget );
-
                // This needs to be below assignment of $this->mTarget because
                // getDescription() needs it to determine the correct page title.
                $this->setHeaders();
@@ -138,16 +135,41 @@ class SpecialEmailUser extends UnlistedSpecialPage {
                                list( $title, $msg, $params ) = $error;
                                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 != '' ) {
+                               // 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 ) );
 
-               // a little hack: HTMLForm will check $this->mTarget only, if the form was posted, not
-               // if the user opens Special:EmailUser/Florian (e.g.). So check, if the user did that,
-               // and show the "Send email to user" form directly, if so. Show the "enter username"
-               // form, otherwise.
-               $this->mTargetObj = self::getTarget( $this->mTarget );
-               if ( !$this->mTargetObj instanceof User ) {
-                       $this->userForm( $this->mTarget );
-               } else {
-                       $this->sendEmailForm();
+                       return;
+               }
+
+               $this->mTargetObj = $ret;
+
+               $context = new DerivativeContext( $this->getContext() );
+               $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() );
+               $form->setSubmitTextMsg( 'emailsend' );
+               $form->setSubmitCallback( array( __CLASS__, 'uiSubmit' ) );
+               $form->setWrapperLegendMsg( 'email-legend' );
+               $form->loadData();
+
+               if ( !Hooks::run( 'EmailUserForm', array( &$form ) ) ) {
+                       return;
+               }
+
+               $result = $form->show();
+
+               if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
+                       $out->setPageTitle( $this->msg( 'emailsent' ) );
+                       $out->addWikiMsg( 'emailsenttext', $this->mTarget );
+                       $out->returnToMain( false, $this->mTargetObj->getUserPage() );
                }
        }
 
@@ -238,63 +260,31 @@ class SpecialEmailUser extends UnlistedSpecialPage {
         * @return string Form asking for user name.
         */
        protected function userForm( $name ) {
-               $form = HTMLForm::factory( 'ooui', array(
-                       'Target' => array(
-                               'type' => 'user',
-                               'exists' => true,
-                               'label' => $this->msg( 'emailusername' )->text(),
-                               'id' => 'emailusertarget',
-                               'autofocus' => true,
-                               'value' => $name,
-                       ),
-               ), $this->getContext() );
-
-               $form
-                       ->setMethod( 'post' )
-                       ->setSubmitCallback( array( $this, 'sendEmailForm' ) )
-                       ->setSubmitProgressive()
-                       ->setId( 'askusername' )
-                       ->addHiddenField( 'title', $this->getPageTitle()->getPrefixedText() )
-                       ->setWrapperLegendMsg( 'emailtarget' )
-                       ->setSubmitTextMsg( 'emailusernamesubmit' )
-                       ->show();
-       }
-
-       public function sendEmailForm() {
-               $out = $this->getOutput();
-
-               $ret = $this->mTargetObj;
-               if ( !$ret instanceof User ) {
-                       if ( $this->mTarget != '' ) {
-                               // Messages used here: notargettext, noemailtext, nowikiemailtext
-                               $ret = ( $ret == 'notarget' ) ? 'emailnotarget' : ( $ret . 'text' );
-                               return Status::newFatal( $ret );
-                       }
-                       return false;
-               }
-
-               $context = new DerivativeContext( $this->getContext() );
-               $context->setTitle( $this->getPageTitle() ); // Remove subpage
-               $form = HTMLForm::factory( 'ooui', $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() );
-               $form->setSubmitTextMsg( 'emailsend' );
-               $form->setSubmitCallback( array( __CLASS__, 'uiSubmit' ) );
-               $form->setWrapperLegendMsg( 'email-legend' );
-               $form->loadData();
-
-               if ( !Hooks::run( 'EmailUserForm', array( &$form ) ) ) {
-                       return false;
-               }
-
-               $result = $form->show();
-
-               if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
-                       $out->setPageTitle( $this->msg( 'emailsent' ) );
-                       $out->addWikiMsg( 'emailsenttext', $this->mTarget );
-                       $out->returnToMain( false, $ret->getUserPage() );
-               }
-               return true;
+               $this->getOutput()->addModules( 'mediawiki.userSuggest' );
+               $string = Xml::openElement(
+                       'form',
+                       array( 'method' => 'get', 'action' => wfScript(), 'id' => 'askusername' )
+               ) .
+                       Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() ) .
+                       Xml::openElement( 'fieldset' ) .
+                       Html::rawElement( 'legend', null, $this->msg( 'emailtarget' )->parse() ) .
+                       Xml::inputLabel(
+                               $this->msg( 'emailusername' )->text(),
+                               'target',
+                               'emailusertarget',
+                               30,
+                               $name,
+                               array(
+                                       'class' => 'mw-autocomplete-user',  // used by mediawiki.userSuggest
+                                       'autofocus' => true,
+                               )
+                       ) .
+                       ' ' .
+                       Xml::submitButton( $this->msg( 'emailusernamesubmit' )->text() ) .
+                       Xml::closeElement( 'fieldset' ) .
+                       Xml::closeElement( 'form' ) . "\n";
+
+               return $string;
        }
 
        /**