Misc fixes to UploadSourceField
authorAlexandre Emsenhuber <mediawiki@emsenhuber.ch>
Sun, 23 Mar 2014 08:58:06 +0000 (09:58 +0100)
committerAlexandre Emsenhuber <mediawiki@emsenhuber.ch>
Sun, 23 Mar 2014 08:58:06 +0000 (09:58 +0100)
Follow-up I7c15fd4250 (00ca365).

- Added 'radio-id' configuration option to set the id of the radio button,
  and changed Special:Upload to use it. Had to keep the old way to set it
  since this class is used by some extensions.
- Always set the "for" attribute of the label to the field and the not the
  radio, since the text it contains does not describes the radio button.

Change-Id: I524f8743fd03546024f8c97852a2bcb3c23c6019

includes/specials/SpecialUpload.php

index 35bbf0b..4dbbdad 100644 (file)
@@ -834,6 +834,7 @@ class UploadForm extends HTMLForm {
                        'section' => 'source',
                        'type' => 'file',
                        'id' => 'wpUploadFile',
+                       'radio-id' => 'wpSourceTypeFile',
                        'label-message' => 'sourcefilename',
                        'upload-type' => 'File',
                        'radio' => &$radio,
@@ -851,6 +852,7 @@ class UploadForm extends HTMLForm {
                                'class' => 'UploadSourceField',
                                'section' => 'source',
                                'id' => 'wpUploadFileURL',
+                               'radio-id' => 'wpSourceTypeurl',
                                'label-message' => 'sourceurl',
                                'upload-type' => 'url',
                                'radio' => &$radio,
@@ -1113,23 +1115,32 @@ class UploadSourceField extends HTMLTextField {
         * @return string
         */
        function getLabelHtml( $cellAttributes = array() ) {
+               $id = $this->mParams['id'];
+               $label = Html::rawElement( 'label', array( 'for' => $id ), $this->mLabel );
+
                if ( !empty( $this->mParams['radio'] ) ) {
-                       $id = "wpSourceType{$this->mParams['upload-type']}";
+                       if ( isset( $this->mParams['radio-id'] ) ) {
+                               $radioId = $this->mParams['radio-id'];
+                       } else {
+                               // Old way. For the benefit of extensions that do not define
+                               // the 'radio-id' key.
+                               $radioId = 'wpSourceType' . $this->mParams['upload-type'];
+                       }
+
                        $attribs = array(
                                'name' => 'wpSourceType',
                                'type' => 'radio',
-                               'id' => $id,
+                               'id' => $radioId,
                                'value' => $this->mParams['upload-type'],
                        );
+
                        if ( !empty( $this->mParams['checked'] ) ) {
                                $attribs['checked'] = 'checked';
                        }
-                       $label = Html::rawElement( 'label', array( 'for' => $id ), $this->mLabel );
+
                        $label .= Html::element( 'input', $attribs );
-               } else {
-                       $id = $this->mParams['id'];
-                       $label = Html::rawElement( 'label', array( 'for' => $id ), $this->mLabel );
                }
+
                return Html::rawElement( 'td', array( 'class' => 'mw-label' ) + $cellAttributes, $label );
        }