Index: trunk/phase3/includes/HTMLForm.php |
— | — | @@ -42,6 +42,10 @@ |
43 | 43 | * 'validation-callback' -- a function name to give you the chance |
44 | 44 | * to impose extra validation on the field input. |
45 | 45 | * @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. |
46 | 50 | * |
47 | 51 | * TODO: Document 'section' / 'subsection' stuff |
48 | 52 | */ |
— | — | @@ -117,15 +121,11 @@ |
118 | 122 | ? $info['section'] |
119 | 123 | : ''; |
120 | 124 | |
121 | | - $info['name'] = isset( $info['name'] ) |
122 | | - ? $info['name'] |
123 | | - : $fieldname; |
124 | | - |
125 | 125 | if ( isset( $info['type'] ) && $info['type'] == 'file' ) { |
126 | 126 | $this->mUseMultipart = true; |
127 | 127 | } |
128 | 128 | |
129 | | - $field = self::loadInputFromParameters( $info ); |
| 129 | + $field = self::loadInputFromParameters( $fieldname, $info ); |
130 | 130 | $field->mParent = $this; |
131 | 131 | |
132 | 132 | $setSection =& $loadedDescriptor; |
— | — | @@ -167,7 +167,7 @@ |
168 | 168 | * @param $descriptor input Descriptor, as described above |
169 | 169 | * @return HTMLFormField subclass |
170 | 170 | */ |
171 | | - static function loadInputFromParameters( $descriptor ) { |
| 171 | + static function loadInputFromParameters( $fieldname, $descriptor ) { |
172 | 172 | if ( isset( $descriptor['class'] ) ) { |
173 | 173 | $class = $descriptor['class']; |
174 | 174 | } elseif ( isset( $descriptor['type'] ) ) { |
— | — | @@ -178,6 +178,8 @@ |
179 | 179 | if ( !$class ) { |
180 | 180 | throw new MWException( "Descriptor with no class: " . print_r( $descriptor, true ) ); |
181 | 181 | } |
| 182 | + |
| 183 | + $descriptor['fieldname'] = $fieldname; |
182 | 184 | |
183 | 185 | $obj = new $class( $descriptor ); |
184 | 186 | |
— | — | @@ -319,7 +321,7 @@ |
320 | 322 | |
321 | 323 | /** |
322 | 324 | * Add a hidden field to the output |
323 | | - * @param $name String field name |
| 325 | + * @param $name String field name. This will be used exactly as entered |
324 | 326 | * @param $value String field value |
325 | 327 | * @param $attribs Array |
326 | 328 | */ |
— | — | @@ -794,17 +796,17 @@ |
795 | 797 | $this->mLabel = $params['label']; |
796 | 798 | } |
797 | 799 | |
| 800 | + $this->mName = "wp{$params['fieldname']}"; |
798 | 801 | if ( isset( $params['name'] ) ) { |
799 | | - $name = $params['name']; |
800 | | - $validName = Sanitizer::escapeId( $name ); |
801 | | - |
802 | | - if ( $name != $validName ) { |
803 | | - throw new MWException( "Invalid name '$name' passed to " . __METHOD__ ); |
804 | | - } |
805 | | - |
806 | | - $this->mName = 'wp' . $name; |
807 | | - $this->mID = 'mw-input-' . $name; |
| 802 | + $this->mName = $params['name']; |
808 | 803 | } |
| 804 | + |
| 805 | + $validName = Sanitizer::escapeId( $this->mName ); |
| 806 | + if ( $this->mName != $validName && !isset( $params['nodata'] ) ) { |
| 807 | + throw new MWException( "Invalid name '{$this->mName}' passed to " . __METHOD__ ); |
| 808 | + } |
| 809 | + |
| 810 | + $this->mID = "mw-input-{$this->mName}"; |
809 | 811 | |
810 | 812 | if ( isset( $params['default'] ) ) { |
811 | 813 | $this->mDefault = $params['default']; |
— | — | @@ -1498,9 +1500,6 @@ |
1499 | 1501 | class HTMLHiddenField extends HTMLFormField { |
1500 | 1502 | public function __construct( $params ) { |
1501 | 1503 | parent::__construct( $params ); |
1502 | | - # forcing the 'wp' prefix on hidden field names |
1503 | | - # is undesirable |
1504 | | - $this->mName = substr( $this->mName, 2 ); |
1505 | 1504 | |
1506 | 1505 | # Per HTML5 spec, hidden fields cannot be 'required' |
1507 | 1506 | # http://dev.w3.org/html5/spec/states-of-the-type-attribute.html#hidden-state |
Index: trunk/phase3/includes/specials/SpecialUploadStash.php |
— | — | @@ -329,7 +329,13 @@ |
330 | 330 | // create the form, which will also be used to execute a callback to process incoming form data |
331 | 331 | // this design is extremely dubious, but supposedly HTMLForm is our standard now? |
332 | 332 | |
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' ); |
334 | 340 | $form->setSubmitCallback( array( __CLASS__, 'tryClearStashedUploads' ) ); |
335 | 341 | $form->setTitle( $this->getTitle() ); |
336 | 342 | $form->addHiddenField( 'clear', true, array( 'type' => 'boolean' ) ); |
Index: trunk/phase3/includes/specials/SpecialUpload.php |
— | — | @@ -1033,14 +1033,14 @@ |
1034 | 1034 | ); |
1035 | 1035 | } |
1036 | 1036 | |
1037 | | - $descriptor['wpDestFileWarningAck'] = array( |
| 1037 | + $descriptor['DestFileWarningAck'] = array( |
1038 | 1038 | 'type' => 'hidden', |
1039 | 1039 | 'id' => 'wpDestFileWarningAck', |
1040 | 1040 | 'default' => $this->mDestWarningAck ? '1' : '', |
1041 | 1041 | ); |
1042 | 1042 | |
1043 | 1043 | if ( $this->mForReUpload ) { |
1044 | | - $descriptor['wpForReUpload'] = array( |
| 1044 | + $descriptor['ForReUpload'] = array( |
1045 | 1045 | 'type' => 'hidden', |
1046 | 1046 | 'id' => 'wpForReUpload', |
1047 | 1047 | 'default' => '1', |
Index: trunk/phase3/includes/specials/SpecialEmailuser.php |
— | — | @@ -57,7 +57,6 @@ |
58 | 58 | 'id' => 'mw-emailuser-recipient', |
59 | 59 | ), |
60 | 60 | 'Target' => array( |
61 | | - 'name' => 'wpTarget', |
62 | 61 | 'type' => 'hidden', |
63 | 62 | 'default' => $this->mTargetObj->getName(), |
64 | 63 | ), |
Index: trunk/phase3/includes/Preferences.php |
— | — | @@ -67,7 +67,7 @@ |
68 | 68 | ## Prod in defaults from the user |
69 | 69 | foreach ( $defaultPreferences as $name => &$info ) { |
70 | 70 | $prefFromUser = self::getOptionFromUser( $name, $info, $user ); |
71 | | - $field = HTMLForm::loadInputFromParameters( $info ); // For validation |
| 71 | + $field = HTMLForm::loadInputFromParameters( $name, $info ); // For validation |
72 | 72 | $defaultOptions = User::getDefaultOptions(); |
73 | 73 | $globalDefault = isset( $defaultOptions[$name] ) |
74 | 74 | ? $defaultOptions[$name] |