r100512 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100511‎ | r100512 | r100513 >
Date:20:03, 22 October 2011
Author:johnduhart
Status:resolved (Comments)
Tags:
Comment:
Adding functions to HTMLForm for setting the submitText and WrapperLegend to messages instead of having to use wfMsg every single time
Modified paths:
  • /trunk/phase3/includes/HTMLForm.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/HTMLForm.php
@@ -581,6 +581,14 @@
582582 }
583583
584584 /**
 585+ * Set the text for the submit button to a message
 586+ * @param $msg String message key
 587+ */
 588+ public function setSubmitTextMsg( $msg ) {
 589+ return $this->setSubmitText( wfMsg( $msg ) );
 590+ }
 591+
 592+ /**
585593 * Get the text for the submit button, either customised or a default.
586594 * @return unknown_type
587595 */
@@ -619,6 +627,15 @@
620628 public function setWrapperLegend( $legend ) { $this->mWrapperLegend = $legend; }
621629
622630 /**
 631+ * Prompt the whole form to be wrapped in a <fieldset>, with
 632+ * this message as its <legend> element.
 633+ * @param $msg String message key
 634+ */
 635+ public function setWrapperLegendMsg( $msg ) {
 636+ return $this->setWrapperLegend( wfMsg( $msg ) );
 637+ }
 638+
 639+ /**
623640 * Set the prefix for various default messages
624641 * TODO: currently only used for the <fieldset> legend on forms
625642 * with multiple sections; should be used elsewhre?
@@ -1357,6 +1374,8 @@
13581375 return $p;
13591376 }
13601377
 1378+ print_r( $value );
 1379+
13611380 $validOptions = HTMLFormField::flattenOptions( $this->mParams['options'] );
13621381
13631382 if ( in_array( $value, $validOptions ) )
@@ -1382,10 +1401,54 @@
13831402 $select->setAttribute( 'disabled', 'disabled' );
13841403 }
13851404
 1405+ if ( !empty( $this->mParams['multiple'] ) ) {
 1406+ $select->setAttribute( 'name', $this->mName . '[]' );
 1407+ $select->setAttribute( 'multiple', 'multiple' );
 1408+
 1409+ if ( !empty( $this->mParams['size'] ) ) {
 1410+ $select->setAttribute( 'size', $this->mParams['size'] );
 1411+ }
 1412+ }
 1413+
13861414 $select->addOptions( $this->mParams['options'] );
13871415
13881416 return $select->getHTML();
13891417 }
 1418+
 1419+ /**
 1420+ * @param $request WebRequest
 1421+ * @return String
 1422+ */
 1423+ function loadDataFromRequest( $request ) {
 1424+ if ( $this->mParent->getMethod() == 'post' ) {
 1425+ if( $request->wasPosted() ){
 1426+ # Checkboxes are just not added to the request arrays if they're not checked,
 1427+ # so it's perfectly possible for there not to be an entry at all
 1428+ return $request->getArray( $this->mName, array() );
 1429+ } else {
 1430+ # That's ok, the user has not yet submitted the form, so show the defaults
 1431+ return $this->getDefault();
 1432+ }
 1433+ } else {
 1434+ # This is the impossible case: if we look at $_GET and see no data for our
 1435+ # field, is it because the user has not yet submitted the form, or that they
 1436+ # have submitted it with all the options unchecked? We will have to assume the
 1437+ # latter, which basically means that you can't specify 'positive' defaults
 1438+ # for GET forms.
 1439+ # @todo FIXME...
 1440+ return $request->getArray( $this->mName, array() );
 1441+ }
 1442+ }
 1443+
 1444+ public static function keysAreValues( $array ) {
 1445+ $resultArray = array();
 1446+
 1447+ foreach ( $array as $name => $value ) {
 1448+ $resultArray[$value] = $value;
 1449+ }
 1450+
 1451+ return $resultArray;
 1452+ }
13901453 }
13911454
13921455 /**
@@ -1861,7 +1924,7 @@
18621925
18631926 $this->mParent->addHiddenField(
18641927 $this->mName,
1865 - $this->mDefault,
 1928+ $value,
18661929 $params
18671930 );
18681931

Follow-up revisions

RevisionCommit summaryAuthorDate
r100513Removing extra stuff that was committed in r100512johnduhart20:10, 22 October 2011
r100523Follow up r100512, adding @since tags and using wfMessagejohnduhart01:10, 23 October 2011

Comments

#Comment by Johnduhart (talk | contribs)   20:04, 22 October 2011

Crap, that last bit wasn't supposed to be in there, hang on.

#Comment by Johnduhart (talk | contribs)   20:11, 22 October 2011

Removed in r100513

Status & tagging log