r83907 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83906‎ | r83907 | r83908 >
Date:15:50, 14 March 2011
Author:happy-melon
Status:ok (Comments)
Tags:
Comment:
Some tweaks to HTMLMultiSelect form to make it play nicely with GET forms, and also to allow a 'flat list' of options
Modified paths:
  • /trunk/phase3/includes/HTMLForm.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/HTMLForm.php
@@ -1444,7 +1444,7 @@
14451445 $attribs + $thisAttribs );
14461446 $checkbox .= ' ' . Html::rawElement( 'label', array( 'for' => "{$this->mID}-$info" ), $label );
14471447
1448 - $html .= $checkbox . '<br />';
 1448+ $html .= Html::rawElement( 'div', array( 'class' => 'mw-htmlform-multiselect-item' ), $checkbox );
14491449 }
14501450 }
14511451
@@ -1452,17 +1452,22 @@
14531453 }
14541454
14551455 function loadDataFromRequest( $request ) {
1456 - # won't work with getCheck
1457 - if ( $request->getCheck( 'wpEditToken' ) ) {
1458 - $arr = $request->getArray( $this->mName );
1459 -
1460 - if ( !$arr ) {
1461 - $arr = array();
 1456+ if ( $this->mParent->getMethod() == 'post' ) {
 1457+ if( $request->wasPosted() ){
 1458+ # Checkboxes are just not added to the request arrays if they're not checked,
 1459+ # so it's perfectly possible for there not to be an entry at all
 1460+ return $request->getArray( $this->mName, array() );
 1461+ } else {
 1462+ # That's ok, the user has not yet submitted the form, so show the defaults
 1463+ return $this->getDefault();
14621464 }
1463 -
1464 - return $arr;
14651465 } else {
1466 - return $this->getDefault();
 1466+ # This is the impossible case: if we look at $_GET and see no data for our
 1467+ # field, is it because the user has not yet submitted the form, or that they
 1468+ # have submitted it with all the options unchecked? We will have to assume the
 1469+ # latter, which basically means that you can't specify 'positive' defaults
 1470+ # for GET forms. FIXME...
 1471+ return $request->getArray( $this->mName, array() );
14671472 }
14681473 }
14691474

Sign-offs

UserFlagDate
Hasharinspected13:41, 18 March 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r83908Follow-up r83907: some CSS to achieve flat listshappy-melon15:56, 14 March 2011
r84891Follow-up r83907: abstract the flatlist mode into a descriptor option, and ma...happy-melon22:45, 27 March 2011

Comments

#Comment by Nikerabbit (talk | contribs)   22:10, 28 June 2011

Can you make a hidden value to GET forms that would tell if the the form has been submitted or not?

#Comment by Happy-melon (talk | contribs)   23:44, 28 June 2011

It wouldn't stay hidden for very long, since all the GET parameters are munged into the url on form submission. That's broadly what is happening in action=edit verses action=submit, and it's always seemed a very clunky method to me.

#Comment by Nikerabbit (talk | contribs)   23:49, 28 June 2011

It doesn't need to stay hidden. As long ad it is there we know the form is "posted",

Status & tagging log