r79140 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79139‎ | r79140 | r79141 >
Date:23:10, 28 December 2010
Author:platonides
Status:ok
Tags:
Comment:
MFT HTMLForm saga (r78452, r78454, r78566, r78574)
Modified paths:
  • /branches/REL1_17/phase3/includes/HTMLForm.php (modified) (history)
  • /branches/REL1_17/phase3/includes/Preferences.php (modified) (history)
  • /branches/REL1_17/phase3/includes/specials/SpecialEmailuser.php (modified) (history)
  • /branches/REL1_17/phase3/includes/specials/SpecialUpload.php (modified) (history)
  • /branches/REL1_17/phase3/includes/specials/SpecialUploadStash.php (modified) (history)

Diff [purge]

Index: branches/REL1_17/phase3/includes/HTMLForm.php
@@ -42,6 +42,10 @@
4343 * 'validation-callback' -- a function name to give you the chance
4444 * to impose extra validation on the field input.
4545 * @see HTMLForm::validate()
 46+ * 'name' -- By default, the 'name' attribute of the input field
 47+ * is "wp{$fieldname}". If you want a different name
 48+ * (eg one without the "wp" prefix), specify it here and
 49+ * it will be used without modification.
4650 *
4751 * TODO: Document 'section' / 'subsection' stuff
4852 */
@@ -116,15 +120,11 @@
117121 ? $info['section']
118122 : '';
119123
120 - $info['name'] = isset( $info['name'] )
121 - ? $info['name']
122 - : $fieldname;
123 -
124124 if ( isset( $info['type'] ) && $info['type'] == 'file' ) {
125125 $this->mUseMultipart = true;
126126 }
127127
128 - $field = self::loadInputFromParameters( $info );
 128+ $field = self::loadInputFromParameters( $fieldname, $info );
129129 $field->mParent = $this;
130130
131131 $setSection =& $loadedDescriptor;
@@ -166,7 +166,7 @@
167167 * @param $descriptor input Descriptor, as described above
168168 * @return HTMLFormField subclass
169169 */
170 - static function loadInputFromParameters( $descriptor ) {
 170+ static function loadInputFromParameters( $fieldname, $descriptor ) {
171171 if ( isset( $descriptor['class'] ) ) {
172172 $class = $descriptor['class'];
173173 } elseif ( isset( $descriptor['type'] ) ) {
@@ -177,6 +177,8 @@
178178 if ( !$class ) {
179179 throw new MWException( "Descriptor with no class: " . print_r( $descriptor, true ) );
180180 }
 181+
 182+ $descriptor['fieldname'] = $fieldname;
181183
182184 $obj = new $class( $descriptor );
183185
@@ -205,7 +207,7 @@
206208 $editToken = $wgRequest->getVal( 'wpEditToken' );
207209
208210 $result = false;
209 - if ( $wgUser->matchEditToken( $editToken ) ) {
 211+ if ( $this->getMethod() != 'post' || $wgUser->matchEditToken( $editToken ) ) {
210212 $result = $this->trySubmit();
211213 }
212214
@@ -304,7 +306,7 @@
305307
306308 /**
307309 * Add a hidden field to the output
308 - * @param $name String field name
 310+ * @param $name String field name. This will be used exactly as entered
309311 * @param $value String field value
310312 * @param $attribs Array
311313 */
@@ -380,8 +382,11 @@
381383 global $wgUser;
382384
383385 $html = '';
384 - $html .= Html::hidden( 'wpEditToken', $wgUser->editToken(), array( 'id' => 'wpEditToken' ) ) . "\n";
385 - $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
 386+
 387+ if( $this->getMethod() == 'post' ){
 388+ $html .= Html::hidden( 'wpEditToken', $wgUser->editToken(), array( 'id' => 'wpEditToken' ) ) . "\n";
 389+ $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
 390+ }
386391
387392 foreach ( $this->mHiddenFields as $data ) {
388393 list( $value, $attribs ) = $data;
@@ -768,17 +773,17 @@
769774 $this->mLabel = $params['label'];
770775 }
771776
 777+ $this->mName = "wp{$params['fieldname']}";
772778 if ( isset( $params['name'] ) ) {
773 - $name = $params['name'];
774 - $validName = Sanitizer::escapeId( $name );
775 -
776 - if ( $name != $validName ) {
777 - throw new MWException( "Invalid name '$name' passed to " . __METHOD__ );
778 - }
779 -
780 - $this->mName = 'wp' . $name;
781 - $this->mID = 'mw-input-' . $name;
 779+ $this->mName = $params['name'];
782780 }
 781+
 782+ $validName = Sanitizer::escapeId( $this->mName );
 783+ if ( $this->mName != $validName && !isset( $params['nodata'] ) ) {
 784+ throw new MWException( "Invalid name '{$this->mName}' passed to " . __METHOD__ );
 785+ }
 786+
 787+ $this->mID = "mw-input-{$this->mName}";
783788
784789 if ( isset( $params['default'] ) ) {
785790 $this->mDefault = $params['default'];
@@ -1191,13 +1196,18 @@
11921197 # If one of the options' 'name' is int(0), it is automatically selected.
11931198 # because PHP sucks and things int(0) == 'some string'.
11941199 # Working around this by forcing all of them to strings.
1195 - $options = array_map( 'strval', $this->mParams['options'] );
 1200+ foreach( $this->mParams['options'] as $key => &$opt ){
 1201+ if( is_int( $opt ) ){
 1202+ $opt = strval( $opt );
 1203+ }
 1204+ }
 1205+ unset( $opt ); # PHP keeps $opt around as a reference, which is a bit scary
11961206
11971207 if ( !empty( $this->mParams['disabled'] ) ) {
11981208 $select->setAttribute( 'disabled', 'disabled' );
11991209 }
12001210
1201 - $select->addOptions( $options );
 1211+ $select->addOptions( $this->mParams['options'] );
12021212
12031213 return $select->getHTML();
12041214 }
@@ -1472,9 +1482,6 @@
14731483 class HTMLHiddenField extends HTMLFormField {
14741484 public function __construct( $params ) {
14751485 parent::__construct( $params );
1476 - # forcing the 'wp' prefix on hidden field names
1477 - # is undesirable
1478 - $this->mName = substr( $this->mName, 2 );
14791486
14801487 # Per HTML5 spec, hidden fields cannot be 'required'
14811488 # http://dev.w3.org/html5/spec/states-of-the-type-attribute.html#hidden-state
Index: branches/REL1_17/phase3/includes/specials/SpecialUploadStash.php
@@ -329,7 +329,13 @@
330330 // create the form, which will also be used to execute a callback to process incoming form data
331331 // this design is extremely dubious, but supposedly HTMLForm is our standard now?
332332
333 - $form = new HTMLForm( array( 'clear' => array( 'class' => 'HTMLHiddenField', 'default' => true ) ), 'clearStashedUploads' );
 333+ $form = new HTMLForm( array(
 334+ 'Clear' => array(
 335+ 'type' => 'hidden',
 336+ 'default' => true,
 337+ 'name' => 'clear',
 338+ )
 339+ ), 'clearStashedUploads' );
334340 $form->setSubmitCallback( array( __CLASS__, 'tryClearStashedUploads' ) );
335341 $form->setTitle( $this->getTitle() );
336342 $form->addHiddenField( 'clear', true, array( 'type' => 'boolean' ) );
Property changes on: branches/REL1_17/phase3/includes/specials/SpecialUploadStash.php
___________________________________________________________________
Modified: svn:mergeinfo
337343 Merged /trunk/phase3/includes/specials/SpecialUploadStash.php:r78452,78454,78566,78924
Index: branches/REL1_17/phase3/includes/specials/SpecialUpload.php
@@ -1030,14 +1030,14 @@
10311031 );
10321032 }
10331033
1034 - $descriptor['wpDestFileWarningAck'] = array(
 1034+ $descriptor['DestFileWarningAck'] = array(
10351035 'type' => 'hidden',
10361036 'id' => 'wpDestFileWarningAck',
10371037 'default' => $this->mDestWarningAck ? '1' : '',
10381038 );
10391039
10401040 if ( $this->mForReUpload ) {
1041 - $descriptor['wpForReUpload'] = array(
 1041+ $descriptor['ForReUpload'] = array(
10421042 'type' => 'hidden',
10431043 'id' => 'wpForReUpload',
10441044 'default' => '1',
Index: branches/REL1_17/phase3/includes/specials/SpecialEmailuser.php
@@ -57,7 +57,6 @@
5858 'id' => 'mw-emailuser-recipient',
5959 ),
6060 'Target' => array(
61 - 'name' => 'wpTarget',
6261 'type' => 'hidden',
6362 'default' => $this->mTargetObj->getName(),
6463 ),
Index: branches/REL1_17/phase3/includes/Preferences.php
@@ -67,7 +67,7 @@
6868 ## Prod in defaults from the user
6969 foreach ( $defaultPreferences as $name => &$info ) {
7070 $prefFromUser = self::getOptionFromUser( $name, $info, $user );
71 - $field = HTMLForm::loadInputFromParameters( $info ); // For validation
 71+ $field = HTMLForm::loadInputFromParameters( $name, $info ); // For validation
7272 $defaultOptions = User::getDefaultOptions();
7373 $globalDefault = isset( $defaultOptions[$name] )
7474 ? $defaultOptions[$name]

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r78452Clean up the running mess that is r64866, r65040, and then r67277. Implement...happy-melon21:14, 15 December 2010
r78454Follow-up r78445: don't spam a useless edit token into the URL for GET requests.happy-melon21:37, 15 December 2010
r78566r52070 breaks the use of optgroups etc: array(...) is cast to 'Array'. Need ...happy-melon16:25, 18 December 2010
r78574Nicer way of doing r78566, and also one which won't incur Tim's wrath... :Dhappy-melon19:08, 18 December 2010

Status & tagging log