From 13ddae7eccae0820e113c7b97e4ac10b6cc69950 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Sun, 23 Mar 2014 09:58:06 +0100 Subject: [PATCH] Misc fixes to UploadSourceField 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 | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index 35bbf0b58c..4dbbdadccc 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -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 ); } -- 2.20.1