Clean up the running mess that is r64866, r65040, and then r67277. Implement and...
authorHappy-melon <happy-melon@users.mediawiki.org>
Wed, 15 Dec 2010 21:14:36 +0000 (21:14 +0000)
committerHappy-melon <happy-melon@users.mediawiki.org>
Wed, 15 Dec 2010 21:14:36 +0000 (21:14 +0000)
includes/HTMLForm.php
includes/Preferences.php
includes/specials/SpecialEmailuser.php
includes/specials/SpecialUpload.php
includes/specials/SpecialUploadStash.php

index d1a5438..30e62ad 100644 (file)
  *     'validation-callback' -- a function name to give you the chance
  *                              to impose extra validation on the field input.
  *                              @see HTMLForm::validate()
+ *  'name'                -- By default, the 'name' attribute of the input field
+ *                           is "wp{$fieldname}".  If you want a different name
+ *                           (eg one without the "wp" prefix), specify it here and
+ *                           it will be used without modification.
  *
  * TODO: Document 'section' / 'subsection' stuff
  */
@@ -117,15 +121,11 @@ class HTMLForm {
                                ? $info['section']
                                : '';
 
-                       $info['name'] = isset( $info['name'] )
-                               ? $info['name']
-                               : $fieldname;
-
                        if ( isset( $info['type'] ) && $info['type'] == 'file' ) {
                                $this->mUseMultipart = true;
                        }
 
-                       $field = self::loadInputFromParameters( $info );
+                       $field = self::loadInputFromParameters( $fieldname, $info );
                        $field->mParent = $this;
 
                        $setSection =& $loadedDescriptor;
@@ -167,7 +167,7 @@ class HTMLForm {
         * @param $descriptor input Descriptor, as described above
         * @return HTMLFormField subclass
         */
-       static function loadInputFromParameters( $descriptor ) {
+       static function loadInputFromParameters( $fieldname, $descriptor ) {
                if ( isset( $descriptor['class'] ) ) {
                        $class = $descriptor['class'];
                } elseif ( isset( $descriptor['type'] ) ) {
@@ -178,6 +178,8 @@ class HTMLForm {
                if ( !$class ) {
                        throw new MWException( "Descriptor with no class: " . print_r( $descriptor, true ) );
                }
+               
+               $descriptor['fieldname'] = $fieldname;
 
                $obj = new $class( $descriptor );
 
@@ -319,7 +321,7 @@ class HTMLForm {
 
        /**
         * Add a hidden field to the output
-        * @param $name String field name
+        * @param $name String field name.  This will be used exactly as entered
         * @param $value String field value
         * @param $attribs Array
         */
@@ -794,17 +796,17 @@ abstract class HTMLFormField {
                        $this->mLabel = $params['label'];
                }
 
+               $this->mName = "wp{$params['fieldname']}";
                if ( isset( $params['name'] ) ) {
-                       $name = $params['name'];
-                       $validName = Sanitizer::escapeId( $name );
-
-                       if ( $name != $validName ) {
-                               throw new MWException( "Invalid name '$name' passed to " . __METHOD__ );
-                       }
-
-                       $this->mName = 'wp' . $name;
-                       $this->mID = 'mw-input-' . $name;
+                       $this->mName = $params['name'];
+               }
+               
+               $validName = Sanitizer::escapeId( $this->mName );
+               if ( $this->mName != $validName && !isset( $params['nodata'] ) ) {
+                       throw new MWException( "Invalid name '{$this->mName}' passed to " . __METHOD__ );
                }
+               
+               $this->mID = "mw-input-{$this->mName}";
 
                if ( isset( $params['default'] ) ) {
                        $this->mDefault = $params['default'];
@@ -1498,9 +1500,6 @@ class HTMLInfoField extends HTMLFormField {
 class HTMLHiddenField extends HTMLFormField {
        public function __construct( $params ) {
                parent::__construct( $params );
-               # forcing the 'wp' prefix on hidden field names
-               # is undesirable
-               $this->mName = substr( $this->mName, 2 );
                
                # Per HTML5 spec, hidden fields cannot be 'required'
                # http://dev.w3.org/html5/spec/states-of-the-type-attribute.html#hidden-state
index 3d68fa9..0916040 100644 (file)
@@ -67,7 +67,7 @@ class Preferences {
                ## Prod in defaults from the user
                foreach ( $defaultPreferences as $name => &$info ) {
                        $prefFromUser = self::getOptionFromUser( $name, $info, $user );
-                       $field = HTMLForm::loadInputFromParameters( $info ); // For validation
+                       $field = HTMLForm::loadInputFromParameters( $name, $info ); // For validation
                        $defaultOptions = User::getDefaultOptions();
                        $globalDefault = isset( $defaultOptions[$name] )
                                ? $defaultOptions[$name]
index c512044..7c3d5c1 100644 (file)
@@ -57,7 +57,6 @@ class SpecialEmailUser extends UnlistedSpecialPage {
                                'id' => 'mw-emailuser-recipient',
                        ),
                        'Target' => array(
-                               'name' => 'wpTarget',
                                'type' => 'hidden',
                                'default' => $this->mTargetObj->getName(),
                        ),
index 48e700c..4c74449 100644 (file)
@@ -1033,14 +1033,14 @@ class UploadForm extends HTMLForm {
                        );
                }
 
-               $descriptor['wpDestFileWarningAck'] = array(
+               $descriptor['DestFileWarningAck'] = array(
                        'type' => 'hidden',
                        'id' => 'wpDestFileWarningAck',
                        'default' => $this->mDestWarningAck ? '1' : '',
                );
                
                if ( $this->mForReUpload ) {
-                       $descriptor['wpForReUpload'] = array(
+                       $descriptor['ForReUpload'] = array(
                                'type' => 'hidden',
                                'id' => 'wpForReUpload',
                                'default' => '1',
index 0bf72b9..6386240 100644 (file)
@@ -329,7 +329,13 @@ class SpecialUploadStash extends UnlistedSpecialPage {
                // create the form, which will also be used to execute a callback to process incoming form data
                // this design is extremely dubious, but supposedly HTMLForm is our standard now?
 
-               $form = new HTMLForm( array( 'clear' => array( 'class' => 'HTMLHiddenField', 'default' => true ) ), 'clearStashedUploads' );
+               $form = new HTMLForm( array( 
+                       'Clear' => array( 
+                               'type' => 'hidden', 
+                               'default' => true,
+                               'name' => 'clear',
+                       ) 
+               ), 'clearStashedUploads' );
                $form->setSubmitCallback( array( __CLASS__, 'tryClearStashedUploads' ) ); 
                $form->setTitle( $this->getTitle() );
                $form->addHiddenField( 'clear', true, array( 'type' => 'boolean' ) );