39 private $oouiWarnings;
45 public function __construct( $descriptor, $context =
null, $messagePrefix =
'' ) {
46 parent::__construct( $descriptor, $context, $messagePrefix );
48 $this->
getOutput()->addModuleStyles(
'mediawiki.htmlform.ooui.styles' );
56 $field = parent::loadInputFromParameters( $fieldname, $descriptor, $parent );
57 $field->setShowEmptyLabel(
false );
64 if ( $this->mShowSubmit ) {
67 'classes' => [
'mw-htmlform-submit' ],
74 if ( isset( $this->mSubmitID ) ) {
78 if ( isset( $this->mSubmitName ) ) {
82 if ( isset( $this->mSubmitTooltip ) ) {
84 'title' => Linker::titleAttrib( $this->mSubmitTooltip ),
85 'accessKey' => Linker::accesskey( $this->mSubmitTooltip ),
89 $buttons .= new \OOUI\ButtonInputWidget( $attribs );
92 if ( $this->mShowCancel ) {
93 $buttons .= new \OOUI\ButtonWidget( [
94 'label' => $this->
msg(
'cancel' )->text(),
99 foreach ( $this->mButtons as $button ) {
103 if ( $button[
'attribs'] ) {
105 $attrs += $button[
'attribs'];
108 if ( isset( $button[
'id'] ) ) {
109 $attrs[
'id'] = $button[
'id'];
112 if ( isset( $button[
'label-message'] ) ) {
113 $label = new \OOUI\HtmlSnippet( $this->
getMessage( $button[
'label-message'] )->parse() );
114 } elseif ( isset( $button[
'label'] ) ) {
115 $label = $button[
'label'];
116 } elseif ( isset( $button[
'label-raw'] ) ) {
117 $label = new \OOUI\HtmlSnippet( $button[
'label-raw'] );
119 $label = $button[
'value'];
122 $attrs[
'classes'] = isset( $attrs[
'class'] ) ? (array)$attrs[
'class'] : [];
124 $buttons .= new \OOUI\ButtonInputWidget( [
126 'name' => $button[
'name'],
127 'value' => $button[
'value'],
130 'flags' => $button[
'flags'],
132 'framed' => $button[
'framed'],
140 return Html::rawElement(
'div',
141 [
'class' =>
'mw-htmlform-submit-buttons' ],
"\n$buttons" ) .
"\n";
150 $layout = new \OOUI\PanelLayout( [
156 $layout->appendContent(
157 new \OOUI\FieldsetLayout( [
161 'content' =>
new \OOUI\HtmlSnippet( $section )
174 return $field->
getOOUI( $value );
184 protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
185 if ( !$fieldsHtml ) {
191 $html = implode(
'', $fieldsHtml );
193 if ( $sectionName ) {
194 return Html::rawElement(
196 [
'id' => Sanitizer::escapeIdForAttribute( $sectionName ) ],
209 if ( $elements ===
'' ) {
213 if ( !in_array( $elementsType, [
'error',
'warning' ],
true ) ) {
214 throw new DomainException( $elementsType .
' is not a valid type.' );
217 if ( $elements instanceof
Status ) {
218 if ( !$elements->isGood() ) {
219 $errors = $elements->getErrorsByType( $elementsType );
220 foreach ( $errors as &$error ) {
221 $error = $this->
getMessage( [ $error[
'message'], ...$error[
'params'] ] )->parse();
224 } elseif ( $elementsType ===
'error' ) {
225 if ( is_array( $elements ) ) {
226 foreach ( $elements as $error ) {
227 $errors[] = $this->
getMessage( $error )->parse();
229 } elseif ( $elements && $elements !==
true ) {
230 $errors[] = (string)$elements;
234 foreach ( $errors as &$error ) {
235 $error = new \OOUI\HtmlSnippet( $error );
239 if ( $elementsType ===
'error' ) {
240 $this->oouiErrors = $errors;
242 $this->oouiWarnings = $errors;
248 if ( $section ===
null ) {
252 return parent::getHeaderHtml( $section );
257 if ( !( $this->mHeader || $this->oouiErrors || $this->oouiWarnings ) ) {
261 'mw-htmlform-ooui-header',
262 ...$this->oouiErrors ? [
'mw-htmlform-ooui-header-errors' ] : [],
263 ...$this->oouiWarnings ? [
'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,
287 if ( is_string( $this->mWrapperLegend ) ) {
288 $phpClass = $this->mCollapsible ? CollapsibleFieldsetLayout::class : \OOUI\FieldsetLayout::class;
289 $content =
new $phpClass( [
290 'label' => $this->mWrapperLegend,
291 'collapsed' => $this->mCollapsed,
294 'content' =>
new \OOUI\HtmlSnippet( $html )
297 ] + \OOUI\Element::configFromHtmlAttributes( $this->mWrapperAttributes ) );
299 $content = new \OOUI\HtmlSnippet( $html );
303 'classes' => [
'mw-htmlform',
'mw-htmlform-ooui' ],
304 'content' => $content,
308 $form = new \OOUI\PanelLayout( [
309 'classes' => [
'mw-htmlform-ooui-wrapper' ],
311 'padded' => $this->mWrapperLegend !==
false,
312 'framed' => $this->mWrapperLegend !==
false,
321class_alias( OOUIHTMLForm::class,
'OOUIHTMLForm' );
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()