37 parent::__construct( $descriptor,
$context, $messagePrefix );
39 $this->
getOutput()->addModuleStyles(
'mediawiki.htmlform.ooui.styles' );
51 $field = parent::loadInputFromParameters( $fieldname, $descriptor, $parent );
52 $field->setShowEmptyLabel(
false );
60 $isBadIE = preg_match(
'/MSIE [1-7]\./i', $this->
getRequest()->getHeader(
'User-Agent' ) );
62 if ( $this->mShowSubmit ) {
63 $attribs = [
'infusable' =>
true ];
65 if ( isset( $this->mSubmitID ) ) {
69 if ( isset( $this->mSubmitName ) ) {
73 if ( isset( $this->mSubmitTooltip ) ) {
80 $attribs[
'classes'] = [
'mw-htmlform-submit' ];
81 $attribs[
'type'] =
'submit';
85 $attribs[
'useInputTag'] = $isBadIE;
87 $buttons .=
new OOUI\ButtonInputWidget( $attribs );
90 if ( $this->mShowReset ) {
91 $buttons .=
new OOUI\ButtonInputWidget( [
93 'label' => $this->
msg(
'htmlform-reset' )->text(),
94 'useInputTag' => $isBadIE,
98 if ( $this->mShowCancel ) {
99 $target = $this->mCancelTarget ?: Title::newMainPage();
100 if ( $target instanceof
Title ) {
101 $target = $target->getLocalURL();
103 $buttons .=
new OOUI\ButtonWidget( [
104 'label' => $this->
msg(
'cancel' )->text(),
109 foreach ( $this->mButtons as $button ) {
112 if ( $button[
'attribs'] ) {
113 $attrs += $button[
'attribs'];
116 if ( isset( $button[
'id'] ) ) {
117 $attrs[
'id'] = $button[
'id'];
121 $label = $button[
'value'];
122 } elseif ( isset( $button[
'label-message'] ) ) {
123 $label =
new OOUI\HtmlSnippet( $this->
getMessage( $button[
'label-message'] )->parse() );
124 } elseif ( isset( $button[
'label'] ) ) {
125 $label = $button[
'label'];
126 } elseif ( isset( $button[
'label-raw'] ) ) {
127 $label =
new OOUI\HtmlSnippet( $button[
'label-raw'] );
129 $label = $button[
'value'];
132 $attrs[
'classes'] = isset( $attrs[
'class'] ) ? (array)$attrs[
'class'] : [];
134 $buttons .=
new OOUI\ButtonInputWidget( [
136 'name' => $button[
'name'],
137 'value' => $button[
'value'],
139 'flags' => $button[
'flags'],
140 'framed' => $button[
'framed'],
141 'useInputTag' => $isBadIE,
149 return Html::rawElement(
'div',
150 [
'class' =>
'mw-htmlform-submit-buttons' ],
"\n$buttons" ) .
"\n";
159 $layout =
new OOUI\PanelLayout( [
165 $layout->appendContent(
166 new OOUI\FieldsetLayout( [
170 'content' =>
new OOUI\HtmlSnippet( $section )
185 protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
186 if ( !$fieldsHtml ) {
192 $html = implode(
'', $fieldsHtml );
194 if ( $sectionName ) {
195 $html = Html::rawElement(
197 [
'id' => Sanitizer::escapeIdForAttribute( $sectionName ) ],
210 if ( $elements ===
'' ) {
214 if ( !in_array( $elementsType, [
'error',
'warning' ],
true ) ) {
215 throw new DomainException( $elementsType .
' is not a valid type.' );
218 if ( $elements instanceof
Status ) {
219 if ( !$elements->isGood() ) {
220 $errors = $elements->getErrorsByType( $elementsType );
221 foreach ( $errors as &$error ) {
224 $error = array_merge( [ $error[
'message'] ], $error[
'params'] );
227 } elseif ( $elementsType ===
'error' ) {
228 if ( is_array( $elements ) ) {
230 } elseif ( is_string( $elements ) ) {
231 $errors = [ $elements ];
235 foreach ( $errors as &$error ) {
236 $error = $this->
getMessage( $error )->parse();
237 $error =
new OOUI\HtmlSnippet( $error );
241 if ( $elementsType ===
'error' ) {
242 $this->oouiErrors = $errors;
244 $this->oouiWarnings = $errors;
250 if ( $section ===
null ) {
254 return parent::getHeaderText( $section );
259 if ( !( $this->mHeader || $this->oouiErrors || $this->oouiWarnings ) ) {
262 $classes = [
'mw-htmlform-ooui-header' ];
263 if ( $this->oouiErrors ) {
264 $classes[] =
'mw-htmlform-ooui-header-errors';
266 if ( $this->oouiWarnings ) {
267 $classes[] =
'mw-htmlform-ooui-header-warnings';
270 if ( $this->mHeader ) {
271 $element =
new OOUI\LabelWidget( [
'label' =>
new OOUI\HtmlSnippet( $this->mHeader ) ] );
273 $element =
new OOUI\Widget( [] );
275 return new OOUI\FieldLayout(
279 'errors' => $this->oouiErrors,
280 'notices' => $this->oouiWarnings,
281 'classes' => $classes,
287 $html = parent::getBody();
293 if ( is_string( $this->mWrapperLegend ) ) {
294 $phpClass = $this->mCollapsible ? CollapsibleFieldsetLayout::class : OOUI\FieldsetLayout::class;
296 'label' => $this->mWrapperLegend,
297 'collapsed' => $this->mCollapsed,
300 'content' =>
new OOUI\HtmlSnippet( $html )
303 ] + OOUI\Element::configFromHtmlAttributes( $this->mWrapperAttributes ) );
305 $content =
new OOUI\HtmlSnippet( $html );
308 $classes = [
'mw-htmlform',
'mw-htmlform-ooui' ];
310 'classes' => $classes,
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()
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.
Represents a title within MediaWiki.