r90509 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90508‎ | r90509 | r90510 >
Date:04:01, 21 June 2011
Author:nagelp
Status:ok (Comments)
Tags:todo 
Comment:
Use Html::[rawElement|element|hidden] to generate the HTML form
Modified paths:
  • /trunk/extensions/Notificator/Notificator.body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Notificator/Notificator.body.php
@@ -22,29 +22,52 @@
2323 return array( $output, 'noparse' => true, 'isHTML' => true );
2424 }
2525
 26+ // The rendering is different, depending on whether a valid e-mail address
 27+ // has been provided, or not - the differing part of the HTML form is being
 28+ // built here
2629 if ( Notificator::receiverIsValid( $receiver ) ) {
27 - // Valid e-mail address available, so just show a button
28 - $output = '<form action="' . $wgScript .
29 - '/Special:Notificator" method="post" enctype="multipart/form-data">
30 -<input type="hidden" name="pageId" value="' . $wgTitle->getArticleID() . '" />
31 -<input type="hidden" name="revId" value="' . $wgTitle->getLatestRevID() . '" />
32 -<input type="hidden" name="receiver" value="' . $receiver . '" />
33 -<input type="submit" value="' .
34 -wfMsg( 'notificator-notify-address-or-name', htmlspecialchars( $receiverLabel ) ) . '" />
35 -</form>';
 30+ // Valid e-mail address available, so build a hidden input with that address
 31+ // set, and a button
 32+ $receiverInputAndSubmitButton = Html::hidden( receiver, $receiver ) .
 33+ Html::element(
 34+ 'input',
 35+ array( 'type' => 'submit',
 36+ 'value' => wfMsg( 'notificator-notify-address-or-name', $receiverLabel )
 37+ )
 38+ );
3639 } else {
37 - // No valid e-mail address available, show text entry field and button
38 - $output = '<form action="' . $wgScript .
39 - '/Special:Notificator" method="post" enctype="multipart/form-data">
40 -<input type="hidden" name="pageId" value="' . $wgTitle->getArticleID() . '" />
41 -<input type="hidden" name="revId" value="' . $wgTitle->getLatestRevID() . '" />
42 -<input type="text" name="receiver" value="' . wfMsg( 'notificator-e-mail-address' ) .
43 -'" onfocus="if (this.value == \'' . wfMsg( 'notificator-e-mail-address' ) .
44 -'\') {this.value=\'\'}" />
45 -<input type="submit" value="' . wfMsg( 'notificator-notify' ) . '" />
46 -</form>';
 40+ // No (valid) e-mail address available, build a text input and a button
 41+ $receiverInputAndSubmitButton = Html::element(
 42+ 'input',
 43+ array( 'type' => 'text',
 44+ 'name' => 'receiver',
 45+ 'value' => wfMsg( 'notificator-e-mail-address' ),
 46+ 'onfocus' => 'if (this.value == \'' .
 47+ wfMsg( 'notificator-e-mail-address' ) .
 48+ '\') {this.value=\'\'}'
 49+ )
 50+ ) .
 51+ Html::element(
 52+ 'input',
 53+ array( 'type' => 'submit',
 54+ 'value' => wfMsg( 'notificator-notify' )
 55+ )
 56+ );
4757 }
4858
 59+ // Now we assemble the form, consisting of two hidden inputs for page ID and rev ID,
 60+ // as well as the $receiverInputAndSubmitButton built above
 61+ $output = Html::rawElement(
 62+ 'form',
 63+ array( 'action' => SpecialPage::getTitleFor( 'Notificator' )->getLocalURL(),
 64+ 'method' => 'post',
 65+ 'enctype' => 'multipart/form-data'
 66+ ),
 67+ Html::hidden( pageId, $wgTitle->getArticleID() ) .
 68+ Html::hidden( revId, $wgTitle->getLatestRevID() ) .
 69+ $receiverInputAndSubmitButton
 70+ );
 71+
4972 return $parser->insertStripItem( $output, $parser->mStripState );
5073 }
5174

Comments

#Comment by Nikerabbit (talk | contribs)   10:42, 17 August 2011
                Html::element(
                        'input',
                        array( 'type' => 'submit',

Can be replaced with Xml::submitButton.

Status & tagging log