41 private $oouiWarnings;
47 public function __construct( $descriptor, $context =
null, $messagePrefix =
'' ) {
48 parent::__construct( $descriptor, $context, $messagePrefix );
50 $this->
getOutput()->addModuleStyles(
'mediawiki.htmlform.ooui.styles' );
59 $field = parent::loadInputFromParameters( $fieldname, $descriptor, $parent );
60 $field->setShowEmptyLabel(
false );
67 if ( $this->mShowSubmit ) {
70 'classes' => [
'mw-htmlform-submit' ],
77 if ( isset( $this->mSubmitID ) ) {
81 if ( isset( $this->mSubmitName ) ) {
85 if ( isset( $this->mSubmitTooltip ) ) {
87 'title' => Linker::titleAttrib( $this->mSubmitTooltip ),
88 'accessKey' => Linker::accesskey( $this->mSubmitTooltip ),
92 $buttons .= new \OOUI\ButtonInputWidget( $attribs );
95 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 )
177 return $field->
getOOUI( $value );
187 protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
188 if ( !$fieldsHtml ) {
194 $html = implode(
'', $fieldsHtml );
196 if ( $sectionName ) {
197 return Html::rawElement(
199 [
'id' => Sanitizer::escapeIdForAttribute( $sectionName ) ],
212 if ( $elements ===
'' ) {
216 if ( !in_array( $elementsType, [
'error',
'warning' ],
true ) ) {
217 throw new DomainException( $elementsType .
' is not a valid type.' );
220 if ( $elements instanceof
Status ) {
221 if ( !$elements->isGood() ) {
222 foreach ( $elements->getMessages( $elementsType ) as $msg ) {
223 $errors[] = $this->
getMessage( $msg )->parse();
226 } elseif ( $elementsType ===
'error' ) {
227 if ( is_array( $elements ) ) {
228 foreach ( $elements as $error ) {
229 $errors[] = $this->
getMessage( $error )->parse();
231 } elseif ( $elements && $elements !==
true ) {
232 $errors[] = (string)$elements;
236 foreach ( $errors as &$error ) {
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::getHeaderHtml( $section );
259 if ( !( $this->mHeader || $this->oouiErrors || $this->oouiWarnings ) ) {
263 'mw-htmlform-ooui-header',
264 ...$this->oouiErrors ? [
'mw-htmlform-ooui-header-errors' ] : [],
265 ...$this->oouiWarnings ? [
'mw-htmlform-ooui-header-warnings' ] : [],
268 if ( $this->mHeader ) {
269 $element = new \OOUI\LabelWidget( [
'label' =>
new \OOUI\HtmlSnippet( $this->mHeader ) ] );
271 $element = new \OOUI\Widget( [] );
273 return new \OOUI\FieldLayout(
277 'errors' => $this->oouiErrors,
278 'notices' => $this->oouiWarnings,
279 'classes' => $classes,
289 if ( is_string( $this->mWrapperLegend ) ) {
290 $phpClass = $this->mCollapsible ? CollapsibleFieldsetLayout::class : \OOUI\FieldsetLayout::class;
291 $content =
new $phpClass( [
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 );
305 'classes' => [
'mw-htmlform',
'mw-htmlform-ooui' ],
306 'content' => $content,
310 $form = new \OOUI\PanelLayout( [
311 'classes' => [
'mw-htmlform-ooui-wrapper' ],
313 'padded' => $this->mWrapperLegend !==
false,
314 'framed' => $this->mWrapperLegend !==
false,
323class_alias( OOUIHTMLForm::class,
'OOUIHTMLForm' );
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()