From c1f9b1f7b1b77776192048005dcc66dcf3df2bfb Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 27 Dec 2014 15:41:37 +0100 Subject: Update to MediaWiki 1.24.1 --- includes/htmlform/HTMLSelectAndOtherField.php | 126 ++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 includes/htmlform/HTMLSelectAndOtherField.php (limited to 'includes/htmlform/HTMLSelectAndOtherField.php') diff --git a/includes/htmlform/HTMLSelectAndOtherField.php b/includes/htmlform/HTMLSelectAndOtherField.php new file mode 100644 index 00000000..65176dd7 --- /dev/null +++ b/includes/htmlform/HTMLSelectAndOtherField.php @@ -0,0 +1,126 @@ + + * * New Optgroup header + * Plus a text field underneath for an additional reason. The 'value' of the field is + * "","") + */ + function loadDataFromRequest( $request ) { + if ( $request->getCheck( $this->mName ) ) { + + $list = $request->getText( $this->mName ); + $text = $request->getText( $this->mName . '-other' ); + + if ( $list == 'other' ) { + $final = $text; + } elseif ( !in_array( $list, $this->mFlatOptions, true ) ) { + # User has spoofed the select form to give an option which wasn't + # in the original offer. Sulk... + $final = $text; + } elseif ( $text == '' ) { + $final = $list; + } else { + $final = $list . $this->msg( 'colon-separator' )->inContentLanguage()->text() . $text; + } + } else { + $final = $this->getDefault(); + + $list = 'other'; + $text = $final; + foreach ( $this->mFlatOptions as $option ) { + $match = $option . $this->msg( 'colon-separator' )->inContentLanguage()->text(); + if ( strpos( $text, $match ) === 0 ) { + $list = $option; + $text = substr( $text, strlen( $match ) ); + break; + } + } + } + + return array( $final, $list, $text ); + } + + function getSize() { + return isset( $this->mParams['size'] ) ? $this->mParams['size'] : 45; + } + + function validate( $value, $alldata ) { + # HTMLSelectField forces $value to be one of the options in the select + # field, which is not useful here. But we do want the validation further up + # the chain + $p = parent::validate( $value[1], $alldata ); + + if ( $p !== true ) { + return $p; + } + + if ( isset( $this->mParams['required'] ) + && $this->mParams['required'] !== false + && $value[1] === '' + ) { + return $this->msg( 'htmlform-required' )->parse(); + } + + return true; + } +} -- cgit v1.2.3-54-g00ecf