34 private $oouiWarnings;
40 public function __construct( $descriptor, $context =
null, $messagePrefix =
'' ) {
41 parent::__construct( $descriptor, $context, $messagePrefix );
43 $this->
getOutput()->addModuleStyles(
'mediawiki.htmlform.ooui.styles' );
55 $field = parent::loadInputFromParameters( $fieldname, $descriptor, $parent );
56 $field->setShowEmptyLabel(
false );
63 if ( $this->mShowSubmit ) {
64 $attribs = [
'infusable' =>
true ];
66 if ( isset( $this->mSubmitID ) ) {
70 if ( isset( $this->mSubmitName ) ) {
74 if ( isset( $this->mSubmitTooltip ) ) {
76 'title' => Linker::titleAttrib( $this->mSubmitTooltip ),
77 'accessKey' => Linker::accesskey( $this->mSubmitTooltip ),
81 $attribs[
'classes'] = [
'mw-htmlform-submit' ];
82 $attribs[
'type'] =
'submit';
87 $buttons .=
new OOUI\ButtonInputWidget( $attribs );
90 if ( $this->mShowReset ) {
91 $buttons .=
new OOUI\ButtonInputWidget( [
93 'label' => $this->
msg(
'htmlform-reset' )->text(),
97 if ( $this->mShowCancel ) {
99 $buttons .=
new OOUI\ButtonWidget( [
100 'label' => $this->
msg(
'cancel' )->text(),
105 foreach ( $this->mButtons as $button ) {
109 if ( $button[
'attribs'] ) {
111 $attrs += $button[
'attribs'];
114 if ( isset( $button[
'id'] ) ) {
115 $attrs[
'id'] = $button[
'id'];
118 if ( isset( $button[
'label-message'] ) ) {
119 $label =
new OOUI\HtmlSnippet( $this->
getMessage( $button[
'label-message'] )->parse() );
120 } elseif ( isset( $button[
'label'] ) ) {
121 $label = $button[
'label'];
122 } elseif ( isset( $button[
'label-raw'] ) ) {
123 $label =
new OOUI\HtmlSnippet( $button[
'label-raw'] );
125 $label = $button[
'value'];
128 $attrs[
'classes'] = isset( $attrs[
'class'] ) ? (array)$attrs[
'class'] : [];
130 $buttons .=
new OOUI\ButtonInputWidget( [
132 'name' => $button[
'name'],
133 'value' => $button[
'value'],
136 'flags' => $button[
'flags'],
138 'framed' => $button[
'framed'],
146 return Html::rawElement(
'div',
147 [
'class' =>
'mw-htmlform-submit-buttons' ],
"\n$buttons" ) .
"\n";
156 $layout =
new OOUI\PanelLayout( [
162 $layout->appendContent(
163 new OOUI\FieldsetLayout( [
167 'content' =>
new OOUI\HtmlSnippet( $section )
182 protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
183 if ( !$fieldsHtml ) {
189 $html = implode(
'', $fieldsHtml );
191 if ( $sectionName ) {
192 $html = Html::rawElement(
194 [
'id' => Sanitizer::escapeIdForAttribute( $sectionName ) ],
207 if ( $elements ===
'' ) {
211 if ( !in_array( $elementsType, [
'error',
'warning' ],
true ) ) {
212 throw new DomainException( $elementsType .
' is not a valid type.' );
215 if ( $elements instanceof
Status ) {
216 if ( !$elements->isGood() ) {
217 $errors = $elements->getErrorsByType( $elementsType );
218 foreach ( $errors as &$error ) {
222 array_merge( [ $error[
'message'] ], $error[
'params'] ) )->parse();
225 } elseif ( $elementsType ===
'error' ) {
226 if ( is_array( $elements ) ) {
227 foreach ( $elements as $error ) {
228 $errors[] = $this->
getMessage( $error )->parse();
230 } elseif ( $elements && $elements !==
true ) {
231 $errors[] = (string)$elements;
235 foreach ( $errors as &$error ) {
236 $error =
new OOUI\HtmlSnippet( $error );
240 if ( $elementsType ===
'error' ) {
241 $this->oouiErrors = $errors;
243 $this->oouiWarnings = $errors;
249 if ( $section ===
null ) {
253 return parent::getHeaderHtml( $section );
258 if ( !( $this->mHeader || $this->oouiErrors || $this->oouiWarnings ) ) {
261 $classes = [
'mw-htmlform-ooui-header' ];
262 if ( $this->oouiErrors ) {
263 $classes[] =
'mw-htmlform-ooui-header-errors';
265 if ( $this->oouiWarnings ) {
266 $classes[] =
'mw-htmlform-ooui-header-warnings';
269 if ( $this->mHeader ) {
270 $element =
new OOUI\LabelWidget( [
'label' =>
new OOUI\HtmlSnippet( $this->mHeader ) ] );
272 $element =
new OOUI\Widget( [] );
274 return new OOUI\FieldLayout(
278 'errors' => $this->oouiErrors,
279 'notices' => $this->oouiWarnings,
280 'classes' => $classes,
286 $html = parent::getBody();
292 if ( is_string( $this->mWrapperLegend ) ) {
293 $phpClass = $this->mCollapsible ? CollapsibleFieldsetLayout::class : OOUI\FieldsetLayout::class;
295 'label' => $this->mWrapperLegend,
296 'collapsed' => $this->mCollapsed,
299 'content' =>
new OOUI\HtmlSnippet( $html )
302 ] + OOUI\Element::configFromHtmlAttributes( $this->mWrapperAttributes ) );
304 $content =
new OOUI\HtmlSnippet( $html );
307 $classes = [
'mw-htmlform',
'mw-htmlform-ooui' ];
309 'classes' => $classes,
314 $form =
new OOUI\PanelLayout( [
315 'classes' => [
'mw-htmlform-ooui-wrapper' ],
317 'padded' => $this->mWrapperLegend !==
false,
318 'framed' => $this->mWrapperLegend !==
false,
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Generic operation result class Has warning/error list, boolean status and arbitrary value.