31 private $oouiWarnings;
37 public function __construct( $descriptor, $context =
null, $messagePrefix =
'' ) {
38 parent::__construct( $descriptor, $context, $messagePrefix );
40 $this->
getOutput()->addModuleStyles(
'mediawiki.htmlform.ooui.styles' );
52 $field = parent::loadInputFromParameters( $fieldname, $descriptor, $parent );
53 $field->setShowEmptyLabel(
false );
60 if ( $this->mShowSubmit ) {
61 $attribs = [
'infusable' =>
true ];
63 if ( isset( $this->mSubmitID ) ) {
67 if ( isset( $this->mSubmitName ) ) {
71 if ( isset( $this->mSubmitTooltip ) ) {
78 $attribs[
'classes'] = [
'mw-htmlform-submit' ];
79 $attribs[
'type'] =
'submit';
84 $buttons .=
new OOUI\ButtonInputWidget( $attribs );
87 if ( $this->mShowReset ) {
88 $buttons .=
new OOUI\ButtonInputWidget( [
90 'label' => $this->
msg(
'htmlform-reset' )->text(),
94 if ( $this->mShowCancel ) {
96 $buttons .=
new OOUI\ButtonWidget( [
97 'label' => $this->
msg(
'cancel' )->text(),
102 foreach ( $this->mButtons as $button ) {
106 if ( $button[
'attribs'] ) {
108 $attrs += $button[
'attribs'];
111 if ( isset( $button[
'id'] ) ) {
112 $attrs[
'id'] = $button[
'id'];
115 if ( isset( $button[
'label-message'] ) ) {
116 $label =
new OOUI\HtmlSnippet( $this->
getMessage( $button[
'label-message'] )->parse() );
117 } elseif ( isset( $button[
'label'] ) ) {
118 $label = $button[
'label'];
119 } elseif ( isset( $button[
'label-raw'] ) ) {
120 $label =
new OOUI\HtmlSnippet( $button[
'label-raw'] );
122 $label = $button[
'value'];
125 $attrs[
'classes'] = isset( $attrs[
'class'] ) ? (array)$attrs[
'class'] : [];
127 $buttons .=
new OOUI\ButtonInputWidget( [
129 'name' => $button[
'name'],
130 'value' => $button[
'value'],
133 'flags' => $button[
'flags'],
135 'framed' => $button[
'framed'],
143 return Html::rawElement(
'div',
144 [
'class' =>
'mw-htmlform-submit-buttons' ],
"\n$buttons" ) .
"\n";
153 $layout =
new OOUI\PanelLayout( [
159 $layout->appendContent(
160 new OOUI\FieldsetLayout( [
164 'content' =>
new OOUI\HtmlSnippet( $section )
179 protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
180 if ( !$fieldsHtml ) {
186 $html = implode(
'', $fieldsHtml );
188 if ( $sectionName ) {
189 $html = Html::rawElement(
191 [
'id' => Sanitizer::escapeIdForAttribute( $sectionName ) ],
204 if ( $elements ===
'' ) {
208 if ( !in_array( $elementsType, [
'error',
'warning' ],
true ) ) {
209 throw new DomainException( $elementsType .
' is not a valid type.' );
212 if ( $elements instanceof
Status ) {
213 if ( !$elements->isGood() ) {
214 $errors = $elements->getErrorsByType( $elementsType );
215 foreach ( $errors as &$error ) {
219 array_merge( [ $error[
'message'] ], $error[
'params'] ) )->parse();
222 } elseif ( $elementsType ===
'error' ) {
223 if ( is_array( $elements ) ) {
224 foreach ( $elements as $error ) {
225 $errors[] = $this->
getMessage( $error )->parse();
227 } elseif ( $elements && $elements !==
true ) {
228 $errors[] = (string)$elements;
232 foreach ( $errors as &$error ) {
233 $error =
new OOUI\HtmlSnippet( $error );
237 if ( $elementsType ===
'error' ) {
238 $this->oouiErrors = $errors;
240 $this->oouiWarnings = $errors;
246 if ( $section ===
null ) {
250 return parent::getHeaderHtml( $section );
255 if ( !( $this->mHeader || $this->oouiErrors || $this->oouiWarnings ) ) {
258 $classes = [
'mw-htmlform-ooui-header' ];
259 if ( $this->oouiErrors ) {
260 $classes[] =
'mw-htmlform-ooui-header-errors';
262 if ( $this->oouiWarnings ) {
263 $classes[] =
'mw-htmlform-ooui-header-warnings';
266 if ( $this->mHeader ) {
267 $element =
new OOUI\LabelWidget( [
'label' =>
new OOUI\HtmlSnippet( $this->mHeader ) ] );
269 $element =
new OOUI\Widget( [] );
271 return new OOUI\FieldLayout(
275 'errors' => $this->oouiErrors,
276 'notices' => $this->oouiWarnings,
277 'classes' => $classes,
283 $html = parent::getBody();
289 if ( is_string( $this->mWrapperLegend ) ) {
290 $phpClass = $this->mCollapsible ? CollapsibleFieldsetLayout::class : OOUI\FieldsetLayout::class;
292 'label' => $this->mWrapperLegend,
293 'collapsed' => $this->mCollapsed,
296 'content' =>
new OOUI\HtmlSnippet( $html )
299 ] + OOUI\Element::configFromHtmlAttributes( $this->mWrapperAttributes ) );
301 $content =
new OOUI\HtmlSnippet( $html );
304 $classes = [
'mw-htmlform',
'mw-htmlform-ooui' ];
306 'classes' => $classes,
311 $form =
new OOUI\PanelLayout( [
312 'classes' => [
'mw-htmlform-ooui-wrapper' ],
314 'padded' => $this->mWrapperLegend !==
false,
315 'framed' => $this->mWrapperLegend !==
false,
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
static accesskey( $name, $localizer=null)
Given the id of an interface element, constructs the appropriate accesskey attribute from the system ...
static titleAttrib( $name, $options=null, array $msgParams=[], $localizer=null)
Given the id of an interface element, constructs the appropriate title attribute from the system mess...
Generic operation result class Has warning/error list, boolean status and arbitrary value.