Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
UploadSourceField
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 getLabelHtml
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
12
 getSize
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21use MediaWiki\Html\Html;
22
23/**
24 * A form field that contains a radio box in the label
25 */
26class UploadSourceField extends HTMLTextField {
27
28    /**
29     * @param array $cellAttributes
30     * @return string
31     */
32    public function getLabelHtml( $cellAttributes = [] ) {
33        $id = $this->mParams['id'];
34        $label = Html::rawElement( 'label', [ 'for' => $id ], $this->mLabel );
35
36        if ( !empty( $this->mParams['radio'] ) ) {
37            $radioId = $this->mParams['radio-id'] ??
38                // Old way. For the benefit of extensions that do not define
39                // the 'radio-id' key.
40                'wpSourceType' . $this->mParams['upload-type'];
41
42            $attribs = [
43                'name' => 'wpSourceType',
44                'type' => 'radio',
45                'id' => $radioId,
46                'value' => $this->mParams['upload-type'],
47            ];
48
49            if ( !empty( $this->mParams['checked'] ) ) {
50                $attribs['checked'] = 'checked';
51            }
52
53            $label .= Html::element( 'input', $attribs );
54        }
55
56        return Html::rawElement( 'td', [ 'class' => 'mw-label' ] + $cellAttributes, $label );
57    }
58
59    /**
60     * @return int
61     */
62    public function getSize() {
63        return $this->mParams['size'] ?? 60;
64    }
65}