28 private $oouiWarnings;
35 parent::__construct( $descriptor, $context, $messagePrefix );
37 $this->
getOutput()->addModuleStyles(
'mediawiki.htmlform.ooui.styles' );
47 $field = parent::loadInputFromParameters( $fieldname, $descriptor, $parent );
48 $field->setShowEmptyLabel(
false );
56 if ( $this->mShowSubmit ) {
59 'classes' => [
'mw-htmlform-submit' ],
66 if ( $this->mSubmitID !==
null ) {
70 if ( $this->mSubmitName !==
null ) {
74 if ( $this->mSubmitTooltip !==
null ) {
76 'title' => Linker::titleAttrib( $this->mSubmitTooltip ),
77 'accessKey' => Linker::accesskey( $this->mSubmitTooltip ),
81 if ( $this->mSubmitLockIcon ) {
82 $attribs[
'icon'] =
'lock';
85 $buttons .= new \OOUI\ButtonInputWidget( $attribs );
88 if ( $this->mShowCancel ) {
89 $buttons .= new \OOUI\ButtonWidget( [
90 'label' => $this->
msg(
'cancel' )->text(),
95 foreach ( $this->mButtons as $button ) {
98 if ( $button[
'attribs'] ) {
99 $attrs += $button[
'attribs'];
102 if ( isset( $button[
'id'] ) ) {
103 $attrs[
'id'] = $button[
'id'];
106 if ( isset( $button[
'label-message'] ) ) {
107 $label = new \OOUI\HtmlSnippet( $this->
getMessage( $button[
'label-message'] )->parse() );
108 } elseif ( isset( $button[
'label'] ) ) {
109 $label = $button[
'label'];
110 } elseif ( isset( $button[
'label-raw'] ) ) {
111 $label = new \OOUI\HtmlSnippet( $button[
'label-raw'] );
113 $label = $button[
'value'];
116 $attrs[
'classes'] = isset( $attrs[
'class'] ) ? (array)$attrs[
'class'] : [];
118 $buttons .= new \OOUI\ButtonInputWidget( [
120 'name' => $button[
'name'],
121 'value' => $button[
'value'],
123 'flags' => $button[
'flags'],
124 'framed' => $button[
'framed'],
132 return Html::rawElement(
'div',
133 [
'class' =>
'mw-htmlform-submit-buttons' ],
"\n$buttons" ) .
"\n";
143 $layout = new \OOUI\PanelLayout( [
149 $layout->appendContent(
150 new \OOUI\FieldsetLayout( [
154 'content' =>
new \OOUI\HtmlSnippet( $section )
167 return $field->
getOOUI( $value );
177 protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
178 if ( !$fieldsHtml ) {
184 $html = implode(
'', $fieldsHtml );
186 if ( $sectionName ) {
187 return Html::rawElement(
189 [
'id' => Sanitizer::escapeIdForAttribute( $sectionName ) ],
202 if ( $elements ===
'' ) {
206 if ( !in_array( $elementsType, [
'error',
'warning' ],
true ) ) {
207 throw new DomainException( $elementsType .
' is not a valid type.' );
210 if ( $elements instanceof
Status ) {
211 if ( !$elements->isGood() ) {
212 foreach ( $elements->getMessages( $elementsType ) as $msg ) {
213 $errors[] = $this->
getMessage( $msg )->parse();
216 } elseif ( $elementsType ===
'error' ) {
217 if ( is_array( $elements ) ) {
218 foreach ( $elements as $error ) {
219 $errors[] = $this->
getMessage( $error )->parse();
221 } elseif ( $elements && $elements !==
true ) {
222 $errors[] = (string)$elements;
226 foreach ( $errors as &$error ) {
227 $error = new \OOUI\HtmlSnippet( $error );
231 if ( $elementsType ===
'error' ) {
232 $this->oouiErrors = $errors;
234 $this->oouiWarnings = $errors;
241 if ( $section ===
null ) {
245 return parent::getHeaderHtml( $section );
250 if ( !( $this->mHeader || $this->oouiErrors || $this->oouiWarnings ) ) {
254 'mw-htmlform-ooui-header',
255 ...$this->oouiErrors ? [
'mw-htmlform-ooui-header-errors' ] : [],
256 ...$this->oouiWarnings ? [
'mw-htmlform-ooui-header-warnings' ] : [],
259 if ( $this->mHeader ) {
260 $element = new \OOUI\LabelWidget( [
'label' =>
new \OOUI\HtmlSnippet( $this->mHeader ) ] );
263 $element->setAttributes( [
'for' =>
'' ] );
265 $element = new \OOUI\Widget( [] );
267 return (
new \OOUI\FieldLayout(
271 'errors' => $this->oouiErrors,
272 'notices' => $this->oouiWarnings,
273 'classes' => $classes,
280 return $this->formatFormHeader() . parent::getBody();
285 if ( is_string( $this->mWrapperLegend ) ) {
286 $phpClass = $this->mCollapsible ? CollapsibleFieldsetLayout::class : \OOUI\FieldsetLayout::class;
287 $content =
new $phpClass( [
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 $form = new \OOUI\FormLayout( $this->getFormAttributes() + [
301 'classes' => [
'mw-htmlform',
'mw-htmlform-ooui' ],
302 'content' => $content,
306 $form = new \OOUI\PanelLayout( [
307 'classes' => [
'mw-htmlform-ooui-wrapper' ],
309 'padded' => $this->mWrapperLegend !==
false,
310 'framed' => $this->mWrapperLegend !==
false,
319class_alias( OOUIHTMLForm::class,
'OOUIHTMLForm' );
if(!defined('MW_SETUP_CALLBACK'))
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Interface for objects which can provide a MediaWiki context on request.