36 private $oouiWarnings;
42 public function __construct( $descriptor, $context =
null, $messagePrefix =
'' ) {
43 parent::__construct( $descriptor, $context, $messagePrefix );
45 $this->
getOutput()->addModuleStyles(
'mediawiki.htmlform.ooui.styles' );
53 $field = parent::loadInputFromParameters( $fieldname, $descriptor, $parent );
54 $field->setShowEmptyLabel(
false );
61 if ( $this->mShowSubmit ) {
64 'classes' => [
'mw-htmlform-submit' ],
68 'flags' => $this->mSubmitFlags,
71 if ( isset( $this->mSubmitID ) ) {
72 $attribs[
'id'] = $this->mSubmitID;
75 if ( isset( $this->mSubmitName ) ) {
76 $attribs[
'name'] = $this->mSubmitName;
79 if ( isset( $this->mSubmitTooltip ) ) {
81 'title' => Linker::titleAttrib( $this->mSubmitTooltip ),
82 'accessKey' => Linker::accesskey( $this->mSubmitTooltip ),
86 $buttons .=
new OOUI\ButtonInputWidget( $attribs );
89 if ( $this->mShowReset ) {
90 $buttons .=
new OOUI\ButtonInputWidget( [
92 'label' => $this->
msg(
'htmlform-reset' )->text(),
96 if ( $this->mShowCancel ) {
97 $buttons .=
new OOUI\ButtonWidget( [
98 'label' => $this->
msg(
'cancel' )->text(),
103 foreach ( $this->mButtons as $button ) {
107 if ( $button[
'attribs'] ) {
109 $attrs += $button[
'attribs'];
112 if ( isset( $button[
'id'] ) ) {
113 $attrs[
'id'] = $button[
'id'];
116 if ( isset( $button[
'label-message'] ) ) {
117 $label =
new OOUI\HtmlSnippet( $this->
getMessage( $button[
'label-message'] )->parse() );
118 } elseif ( isset( $button[
'label'] ) ) {
119 $label = $button[
'label'];
120 } elseif ( isset( $button[
'label-raw'] ) ) {
121 $label =
new OOUI\HtmlSnippet( $button[
'label-raw'] );
123 $label = $button[
'value'];
126 $attrs[
'classes'] = isset( $attrs[
'class'] ) ? (array)$attrs[
'class'] : [];
128 $buttons .=
new OOUI\ButtonInputWidget( [
130 'name' => $button[
'name'],
131 'value' => $button[
'value'],
134 'flags' => $button[
'flags'],
136 'framed' => $button[
'framed'],
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 )
178 return $field->
getOOUI( $value );
188 protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
189 if ( !$fieldsHtml ) {
195 $html = implode(
'', $fieldsHtml );
197 if ( $sectionName ) {
198 return Html::rawElement(
200 [
'id' => Sanitizer::escapeIdForAttribute( $sectionName ) ],
213 if ( $elements ===
'' ) {
217 if ( !in_array( $elementsType, [
'error',
'warning' ],
true ) ) {
218 throw new DomainException( $elementsType .
' is not a valid type.' );
221 if ( $elements instanceof
Status ) {
222 if ( !$elements->isGood() ) {
223 $errors = $elements->getErrorsByType( $elementsType );
224 foreach ( $errors as &$error ) {
228 array_merge( [ $error[
'message'] ], $error[
'params'] ) )->parse();
231 } elseif ( $elementsType ===
'error' ) {
232 if ( is_array( $elements ) ) {
233 foreach ( $elements as $error ) {
234 $errors[] = $this->
getMessage( $error )->parse();
236 } elseif ( $elements && $elements !==
true ) {
237 $errors[] = (string)$elements;
241 foreach ( $errors as &$error ) {
242 $error =
new OOUI\HtmlSnippet( $error );
246 if ( $elementsType ===
'error' ) {
247 $this->oouiErrors = $errors;
249 $this->oouiWarnings = $errors;
255 if ( $section ===
null ) {
259 return parent::getHeaderHtml( $section );
264 if ( !( $this->mHeader || $this->oouiErrors || $this->oouiWarnings ) ) {
268 'mw-htmlform-ooui-header',
269 ...$this->oouiErrors ? [
'mw-htmlform-ooui-header-errors' ] : [],
270 ...$this->oouiWarnings ? [
'mw-htmlform-ooui-header-warnings' ] : [],
273 if ( $this->mHeader ) {
274 $element =
new OOUI\LabelWidget( [
'label' =>
new OOUI\HtmlSnippet( $this->mHeader ) ] );
276 $element =
new OOUI\Widget( [] );
278 return new OOUI\FieldLayout(
282 'errors' => $this->oouiErrors,
283 'notices' => $this->oouiWarnings,
284 'classes' => $classes,
294 if ( is_string( $this->mWrapperLegend ) ) {
295 $phpClass = $this->mCollapsible ? CollapsibleFieldsetLayout::class : OOUI\FieldsetLayout::class;
297 'label' => $this->mWrapperLegend,
298 'collapsed' => $this->mCollapsed,
301 'content' =>
new OOUI\HtmlSnippet( $html )
304 ] + OOUI\Element::configFromHtmlAttributes( $this->mWrapperAttributes ) );
306 $content =
new OOUI\HtmlSnippet( $html );
310 'classes' => [
'mw-htmlform',
'mw-htmlform-ooui' ],
315 $form =
new OOUI\PanelLayout( [
316 'classes' => [
'mw-htmlform-ooui-wrapper' ],
318 'padded' => $this->mWrapperLegend !==
false,
319 'framed' => $this->mWrapperLegend !==
false,
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()