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 foreach ( $elements->getMessages( $elementsType ) as $msg ) {
220 $errors[] = $this->
getMessage( $msg )->parse();
223 } elseif ( $elementsType ===
'error' ) {
224 if ( is_array( $elements ) ) {
225 foreach ( $elements as $error ) {
226 $errors[] = $this->
getMessage( $error )->parse();
228 } elseif ( $elements && $elements !==
true ) {
229 $errors[] = (string)$elements;
233 foreach ( $errors as &$error ) {
234 $error = new \OOUI\HtmlSnippet( $error );
238 if ( $elementsType ===
'error' ) {
239 $this->oouiErrors = $errors;
241 $this->oouiWarnings = $errors;
247 if ( $section ===
null ) {
251 return parent::getHeaderHtml( $section );
256 if ( !( $this->mHeader || $this->oouiErrors || $this->oouiWarnings ) ) {
260 'mw-htmlform-ooui-header',
261 ...$this->oouiErrors ? [
'mw-htmlform-ooui-header-errors' ] : [],
262 ...$this->oouiWarnings ? [
'mw-htmlform-ooui-header-warnings' ] : [],
265 if ( $this->mHeader ) {
266 $element = new \OOUI\LabelWidget( [
'label' =>
new \OOUI\HtmlSnippet( $this->mHeader ) ] );
268 $element = new \OOUI\Widget( [] );
270 return new \OOUI\FieldLayout(
274 'errors' => $this->oouiErrors,
275 'notices' => $this->oouiWarnings,
276 'classes' => $classes,
286 if ( is_string( $this->mWrapperLegend ) ) {
287 $phpClass = $this->mCollapsible ? CollapsibleFieldsetLayout::class : \OOUI\FieldsetLayout::class;
288 $content =
new $phpClass( [
289 'label' => $this->mWrapperLegend,
290 'collapsed' => $this->mCollapsed,
293 'content' =>
new \OOUI\HtmlSnippet( $html )
296 ] + \OOUI\Element::configFromHtmlAttributes( $this->mWrapperAttributes ) );
298 $content = new \OOUI\HtmlSnippet( $html );
302 'classes' => [
'mw-htmlform',
'mw-htmlform-ooui' ],
303 'content' => $content,
307 $form = new \OOUI\PanelLayout( [
308 'classes' => [
'mw-htmlform-ooui-wrapper' ],
310 'padded' => $this->mWrapperLegend !==
false,
311 'framed' => $this->mWrapperLegend !==
false,
320class_alias( OOUIHTMLForm::class,
'OOUIHTMLForm' );
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()