32 parent::__construct( $descriptor,
$context, $messagePrefix );
34 $this->
getOutput()->addModuleStyles(
'mediawiki.htmlform.ooui.styles' );
46 $field = parent::loadInputFromParameters( $fieldname, $descriptor, $parent );
47 $field->setShowEmptyLabel(
false );
55 $isBadIE = preg_match(
'/MSIE [1-7]\./i', $this->
getRequest()->getHeader(
'User-Agent' ) );
57 if ( $this->mShowSubmit ) {
58 $attribs = [
'infusable' =>
true ];
60 if ( isset( $this->mSubmitID ) ) {
64 if ( isset( $this->mSubmitName ) ) {
68 if ( isset( $this->mSubmitTooltip ) ) {
75 $attribs[
'classes'] = [
'mw-htmlform-submit' ];
76 $attribs[
'type'] =
'submit';
80 $attribs[
'useInputTag'] = $isBadIE;
82 $buttons .=
new OOUI\ButtonInputWidget( $attribs );
85 if ( $this->mShowReset ) {
86 $buttons .=
new OOUI\ButtonInputWidget( [
88 'label' => $this->
msg(
'htmlform-reset' )->text(),
89 'useInputTag' => $isBadIE,
93 if ( $this->mShowCancel ) {
95 if ( $target instanceof
Title ) {
96 $target = $target->getLocalURL();
98 $buttons .=
new OOUI\ButtonWidget( [
99 'label' => $this->
msg(
'cancel' )->text(),
104 foreach ( $this->mButtons as $button ) {
107 if ( $button[
'attribs'] ) {
108 $attrs += $button[
'attribs'];
111 if ( isset( $button[
'id'] ) ) {
112 $attrs[
'id'] = $button[
'id'];
116 $label = $button[
'value'];
117 } elseif ( isset( $button[
'label-message'] ) ) {
118 $label =
new OOUI\HtmlSnippet( $this->
getMessage( $button[
'label-message'] )->parse() );
119 } elseif ( isset( $button[
'label'] ) ) {
120 $label = $button[
'label'];
121 } elseif ( isset( $button[
'label-raw'] ) ) {
122 $label =
new OOUI\HtmlSnippet( $button[
'label-raw'] );
124 $label = $button[
'value'];
127 $attrs[
'classes'] = isset( $attrs[
'class'] ) ? (array)$attrs[
'class'] : [];
129 $buttons .=
new OOUI\ButtonInputWidget( [
131 'name' => $button[
'name'],
132 'value' => $button[
'value'],
134 'flags' => $button[
'flags'],
135 'framed' => $button[
'framed'],
136 'useInputTag' => $isBadIE,
144 return Html::rawElement(
'div',
145 [
'class' =>
'mw-htmlform-submit-buttons' ],
"\n$buttons" ) .
"\n";
154 $layout =
new OOUI\PanelLayout( [
160 $layout->appendContent(
161 new OOUI\FieldsetLayout( [
165 'content' =>
new OOUI\HtmlSnippet( $section )
180 protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
181 if ( !$fieldsHtml ) {
187 $html = implode(
'', $fieldsHtml );
189 if ( $sectionName ) {
190 $html = Html::rawElement(
192 [
'id' => Sanitizer::escapeIdForAttribute( $sectionName ) ],
205 if ( $elements ===
'' ) {
209 if ( !in_array( $elementsType, [
'error',
'warning' ],
true ) ) {
210 throw new DomainException( $elementsType .
' is not a valid type.' );
213 if ( $elements instanceof
Status ) {
214 if ( !$elements->isGood() ) {
215 $errors = $elements->getErrorsByType( $elementsType );
216 foreach ( $errors as &$error ) {
219 $error = array_merge( [ $error[
'message'] ], $error[
'params'] );
222 } elseif ( $elementsType ===
'error' ) {
223 if ( is_array( $elements ) ) {
225 } elseif ( is_string( $elements ) ) {
226 $errors = [ $elements ];
230 foreach ( $errors as &$error ) {
231 $error = $this->
getMessage( $error )->parse();
232 $error =
new OOUI\HtmlSnippet( $error );
236 if ( $elementsType ===
'error' ) {
237 $this->oouiErrors = $errors;
239 $this->oouiWarnings = $errors;
245 if ( is_null( $section ) ) {
249 return parent::getHeaderText( $section );
254 $html = parent::getBody();
255 if ( $this->mHeader || $this->oouiErrors || $this->oouiWarnings ) {
256 $classes = [
'mw-htmlform-ooui-header' ];
257 if ( $this->oouiErrors ) {
258 $classes[] =
'mw-htmlform-ooui-header-errors';
260 if ( $this->oouiWarnings ) {
261 $classes[] =
'mw-htmlform-ooui-header-warnings';
264 if ( $this->mHeader ) {
265 $element =
new OOUI\LabelWidget( [
'label' =>
new OOUI\HtmlSnippet( $this->mHeader ) ] );
267 $element =
new OOUI\Widget( [] );
269 $html =
new OOUI\FieldLayout(
273 'errors' => $this->oouiErrors,
274 'notices' => $this->oouiWarnings,
275 'classes' => $classes,
283 if ( is_string( $this->mWrapperLegend ) ) {
284 $phpClass = $this->mCollapsible ? CollapsibleFieldsetLayout::class : OOUI\FieldsetLayout::class;
286 'label' => $this->mWrapperLegend,
287 'collapsed' => $this->mCollapsed,
290 'content' =>
new OOUI\HtmlSnippet( $html )
293 ] + OOUI\Element::configFromHtmlAttributes( $this->mWrapperAttributes ) );
295 $content =
new OOUI\HtmlSnippet( $html );
298 $classes = [
'mw-htmlform',
'mw-htmlform-ooui' ];
300 'classes' => $classes,
305 $form =
new OOUI\PanelLayout( [
306 'classes' => [
'mw-htmlform-ooui-wrapper' ],
308 'padded' => $this->mWrapperLegend !==
false,
309 'framed' => $this->mWrapperLegend !==
false,