r85876 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85875‎ | r85876 | r85877 >
Date:12:49, 12 April 2011
Author:purodha
Status:resolved (Comments)
Tags:
Comment:
(bug 13879) Special:Emailuser now asks for suitable target user if called without.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/specials/SpecialEmailuser.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialEmailuser.php
@@ -89,19 +89,10 @@
9090 $this->setHeaders();
9191 $this->outputHeader();
9292 $wgOut->addModuleStyles( 'mediawiki.special' );
93 -
9493 $this->mTarget = is_null( $par )
9594 ? $wgRequest->getVal( 'wpTarget', $wgRequest->getVal( 'target', '' ) )
9695 : $par;
97 -
98 - $ret = self::getTarget( $this->mTarget );
99 - if( $ret instanceof User ){
100 - $this->mTargetObj = $ret;
101 - } else {
102 - $wgOut->showErrorPage( "{$ret}title", "{$ret}text" );
103 - return false;
104 - }
105 -
 96+ // error out if sending user cannot do this
10697 $error = self::getPermissionsError( $wgUser, $wgRequest->getVal( 'wpEditToken' ) );
10798 switch ( $error ) {
10899 case null:
@@ -126,7 +117,19 @@
127118 $wgOut->showErrorPage( $title, $msg, $params );
128119 return;
129120 }
 121+ // Got a valid target user name? Else ask for one.
 122+ $ret = self::getTarget( $this->mTarget );
 123+ if( ! $ret instanceof User ){
 124+ if( $this->mTarget != '' ) {
 125+ $ret = ( $ret == 'notarget' ) ? 'emailnotarget' : ( $ret . 'text' ) ;
 126+ $wgOut->addHtml ( '<p class="error">' . wfMessage( $ret )->parse() . '</p>' );
 127+ }
 128+ $wgOut->addHtml (self::userForm( $this->mTarget ) );
 129+ return false;
 130+ }
130131
 132+ $this->mTargetObj = $ret;
 133+
131134 $form = new HTMLForm( $this->getFormFields() );
132135 $form->addPreText( wfMsgExt( 'emailpagetext', 'parseinline' ) );
133136 $form->setSubmitText( wfMsg( 'emailsend' ) );
@@ -216,6 +219,23 @@
217220
218221 return null;
219222 }
 223+
 224+ /**
 225+ * Form to ask for target user name.
 226+ * @author purodha
 227+ * @param $name string User name submitted.
 228+ * @return string form asking for user name.
 229+ */
 230+ static function userForm( $name ) {
 231+ $string = Xml::openElement( 'form', array( 'method' => 'get', 'action' => '', 'id' => 'askusername' ) ) .
 232+ Xml::openElement( 'fieldset' ) .
 233+ Html::rawElement( 'legend', null, wfMessage( 'emailtarget' )->parse() ) .
 234+ Xml::inputLabel( wfMessage('emailusername')->text(), 'target', 'emailusertarget', 30, $name ) . ' ' .
 235+ Xml::submitButton( wfMessage('emailusernamesubmit')->text() ) .
 236+ Xml::closeElement( 'fieldset' ) .
 237+ Xml::closeElement( 'form' ) . "\n";
 238+ return $string;
 239+ }
220240
221241 /**
222242 * Really send a mail. Permissions should have been checked using
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2679,6 +2679,10 @@
26802680 'noemailtext' => 'This user has not specified a valid e-mail address.',
26812681 'nowikiemailtitle' => 'No e-mail allowed',
26822682 'nowikiemailtext' => 'This user has chosen not to receive e-mail from other users.',
 2683+'emailnotarget' => 'Nonexistent or invalid user name to receive e-mail.',
 2684+'emailtarget' => 'Enter user to receive e-mail',
 2685+'emailusername' => 'User name:',
 2686+'emailusernamesubmit' => 'Submit',
26832687 'email-legend' => 'Send an e-mail to another {{SITENAME}} user',
26842688 'emailfrom' => 'From:',
26852689 'emailto' => 'To:',
Index: trunk/phase3/RELEASE-NOTES
@@ -130,6 +130,7 @@
131131 to avoid loops and confusion; auth plugins like CentralAuth need to handle
132132 AbortNewAccount separately.
133133 * Special:ListFiles is now transcludable.
 134+* (bug 13879) Special:Emailuser asks for suitable target user if called without.
134135
135136
136137 === Bug fixes in 1.18 ===

Follow-up revisions

RevisionCommit summaryAuthorDate
r85877Add new message of r85876 to messge maintenance list.purodha13:01, 12 April 2011
r85882follow-up to r85876: fix some coding style issues (some of which were not int...ashley15:46, 12 April 2011
r85887Update wording for messages added in r85976.siebrand16:58, 12 April 2011
r92065Fix for r85876 by doing away with a potentially invalid user name parameter b...purodha15:57, 13 July 2011
r95410Followup r85876...reedy18:35, 24 August 2011

Comments

#Comment by Raymond (talk | contribs)   12:51, 12 April 2011

Please add new message keys to maintenance/languages/messages.inc. Thanks.

#Comment by Purodha (talk | contribs)   13:02, 12 April 2011

Thank you for the hint. I was not aware of the need. Done with r85877.

#Comment by Mormegil (talk | contribs)   13:55, 13 April 2011

The code using Emailnotarget is broken: Since target is used only if $par is not received, you are not able to override a bad username by submitting a corrected one, the original is still checked. Try going to e.g. translatewiki:Special:Emailuser/NonexistentUser and submitting a different valid username.

You either need to change userForm so that it submits to the special page without the optional username parameter, or invert the order when retrieving $this->mTarget in execute.

#Comment by Purodha (talk | contribs)   15:58, 13 July 2011

Fixed by not sending $par any more from the input form in r92065

#Comment by Nikerabbit (talk | contribs)   14:07, 15 April 2011

Use wrapWikiMsg here:

+$wgOut->addHtml ( '

' . wfMessage( $ret )->parse() . '

' );

I think this is very poor usability still. It should provide the full form immediately with incremental user name search and immediate feedback if the user can or cannot be emailed.

Status & tagging log