Expose $wgMaxArticleSize in siteinfo query api
[mediawiki.git] / includes / htmlform / HTMLSelectOrOtherField.php
blob8f7750c06d51b37d5cc9d20dcf49fda50b0097ce
1 <?php
3 /**
4 * Select dropdown field, with an additional "other" textbox.
6 * HTMLComboboxField implements the same functionality using a single form field
7 * and should be used instead.
8 */
9 class HTMLSelectOrOtherField extends HTMLTextField {
10 function __construct( $params ) {
11 parent::__construct( $params );
12 $this->getOptions();
13 if ( !in_array( 'other', $this->mOptions, true ) ) {
14 $msg =
15 isset( $params['other'] )
16 ? $params['other']
17 : wfMessage( 'htmlform-selectorother-other' )->text();
18 // Have 'other' always as first element
19 $this->mOptions = [ $msg => 'other' ] + $this->mOptions;
24 function getInputHTML( $value ) {
25 $valInSelect = false;
27 if ( $value !== false ) {
28 $value = strval( $value );
29 $valInSelect = in_array(
30 $value, HTMLFormField::flattenOptions( $this->getOptions() ), true
34 $selected = $valInSelect ? $value : 'other';
36 $select = new XmlSelect( $this->mName, $this->mID, $selected );
37 $select->addOptions( $this->getOptions() );
39 $select->setAttribute( 'class', 'mw-htmlform-select-or-other' );
41 $tbAttribs = [ 'id' => $this->mID . '-other', 'size' => $this->getSize() ];
43 if ( !empty( $this->mParams['disabled'] ) ) {
44 $select->setAttribute( 'disabled', 'disabled' );
45 $tbAttribs['disabled'] = 'disabled';
48 if ( isset( $this->mParams['tabindex'] ) ) {
49 $select->setAttribute( 'tabindex', $this->mParams['tabindex'] );
50 $tbAttribs['tabindex'] = $this->mParams['tabindex'];
53 $select = $select->getHTML();
55 if ( isset( $this->mParams['maxlength'] ) ) {
56 $tbAttribs['maxlength'] = $this->mParams['maxlength'];
59 if ( $this->mClass !== '' ) {
60 $tbAttribs['class'] = $this->mClass;
63 $textbox = Html::input( $this->mName . '-other', $valInSelect ? '' : $value, 'text', $tbAttribs );
65 return "$select<br />\n$textbox";
68 function getInputOOUI( $value ) {
69 return false;
72 /**
73 * @param WebRequest $request
75 * @return string
77 function loadDataFromRequest( $request ) {
78 if ( $request->getCheck( $this->mName ) ) {
79 $val = $request->getText( $this->mName );
81 if ( $val === 'other' ) {
82 $val = $request->getText( $this->mName . '-other' );
85 return $val;
86 } else {
87 return $this->getDefault();