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 ) {
105 if ( $button[
'attribs'] ) {
106 $attrs += $button[
'attribs'];
109 if ( isset( $button[
'id'] ) ) {
110 $attrs[
'id'] = $button[
'id'];
113 if ( isset( $button[
'label-message'] ) ) {
114 $label =
new OOUI\HtmlSnippet( $this->
getMessage( $button[
'label-message'] )->parse() );
115 } elseif ( isset( $button[
'label'] ) ) {
116 $label = $button[
'label'];
117 } elseif ( isset( $button[
'label-raw'] ) ) {
118 $label =
new OOUI\HtmlSnippet( $button[
'label-raw'] );
120 $label = $button[
'value'];
123 $attrs[
'classes'] = isset( $attrs[
'class'] ) ? (array)$attrs[
'class'] : [];
125 $buttons .=
new OOUI\ButtonInputWidget( [
127 'name' => $button[
'name'],
128 'value' => $button[
'value'],
130 'flags' => $button[
'flags'],
131 'framed' => $button[
'framed'],
139 return Html::rawElement(
'div',
140 [
'class' =>
'mw-htmlform-submit-buttons' ],
"\n$buttons" ) .
"\n";
149 $layout =
new OOUI\PanelLayout( [
155 $layout->appendContent(
156 new OOUI\FieldsetLayout( [
160 'content' =>
new OOUI\HtmlSnippet( $section )
175 protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
176 if ( !$fieldsHtml ) {
182 $html = implode(
'', $fieldsHtml );
184 if ( $sectionName ) {
185 $html = Html::rawElement(
187 [
'id' => Sanitizer::escapeIdForAttribute( $sectionName ) ],
200 if ( $elements ===
'' ) {
204 if ( !in_array( $elementsType, [
'error',
'warning' ],
true ) ) {
205 throw new DomainException( $elementsType .
' is not a valid type.' );
208 if ( $elements instanceof
Status ) {
209 if ( !$elements->isGood() ) {
210 $errors = $elements->getErrorsByType( $elementsType );
211 foreach ( $errors as &$error ) {
215 array_merge( [ $error[
'message'] ], $error[
'params'] ) )->parse();
218 } elseif ( $elementsType ===
'error' ) {
219 if ( is_array( $elements ) ) {
220 foreach ( $elements as $error ) {
221 $errors[] = $this->
getMessage( $error )->parse();
223 } elseif ( $elements && $elements !==
true ) {
224 $errors[] = (string)$elements;
228 foreach ( $errors as &$error ) {
229 $error =
new OOUI\HtmlSnippet( $error );
233 if ( $elementsType ===
'error' ) {
234 $this->oouiErrors = $errors;
236 $this->oouiWarnings = $errors;
242 if ( $section ===
null ) {
246 return parent::getHeaderText( $section );
251 if ( !( $this->mHeader || $this->oouiErrors || $this->oouiWarnings ) ) {
254 $classes = [
'mw-htmlform-ooui-header' ];
255 if ( $this->oouiErrors ) {
256 $classes[] =
'mw-htmlform-ooui-header-errors';
258 if ( $this->oouiWarnings ) {
259 $classes[] =
'mw-htmlform-ooui-header-warnings';
262 if ( $this->mHeader ) {
263 $element =
new OOUI\LabelWidget( [
'label' =>
new OOUI\HtmlSnippet( $this->mHeader ) ] );
265 $element =
new OOUI\Widget( [] );
267 return new OOUI\FieldLayout(
271 'errors' => $this->oouiErrors,
272 'notices' => $this->oouiWarnings,
273 'classes' => $classes,
279 $html = parent::getBody();
285 if ( is_string( $this->mWrapperLegend ) ) {
286 $phpClass = $this->mCollapsible ? CollapsibleFieldsetLayout::class : OOUI\FieldsetLayout::class;
288 'label' => $this->mWrapperLegend,
289 'collapsed' => $this->mCollapsed,
292 'content' =>
new OOUI\HtmlSnippet( $html )
295 ] + OOUI\Element::configFromHtmlAttributes( $this->mWrapperAttributes ) );
297 $content =
new OOUI\HtmlSnippet( $html );
300 $classes = [
'mw-htmlform',
'mw-htmlform-ooui' ];
302 'classes' => $classes,
307 $form =
new OOUI\PanelLayout( [
308 'classes' => [
'mw-htmlform-ooui-wrapper' ],
310 'padded' => $this->mWrapperLegend !==
false,
311 'framed' => $this->mWrapperLegend !==
false,
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
static titleAttrib( $name, $options=null, array $msgParams=[])
Given the id of an interface element, constructs the appropriate title attribute from the system mess...
static accesskey( $name)
Given the id of an interface element, constructs the appropriate accesskey attribute from the system ...
Generic operation result class Has warning/error list, boolean status and arbitrary value.