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->mShowReset ) {
93 $buttons .= new \OOUI\ButtonInputWidget( [
95 'label' => $this->
msg(
'htmlform-reset' )->text(),
99 if ( $this->mShowCancel ) {
100 $buttons .= new \OOUI\ButtonWidget( [
101 'label' => $this->
msg(
'cancel' )->text(),
106 foreach ( $this->mButtons as $button ) {
110 if ( $button[
'attribs'] ) {
112 $attrs += $button[
'attribs'];
115 if ( isset( $button[
'id'] ) ) {
116 $attrs[
'id'] = $button[
'id'];
119 if ( isset( $button[
'label-message'] ) ) {
120 $label = new \OOUI\HtmlSnippet( $this->
getMessage( $button[
'label-message'] )->parse() );
121 } elseif ( isset( $button[
'label'] ) ) {
122 $label = $button[
'label'];
123 } elseif ( isset( $button[
'label-raw'] ) ) {
124 $label = new \OOUI\HtmlSnippet( $button[
'label-raw'] );
126 $label = $button[
'value'];
129 $attrs[
'classes'] = isset( $attrs[
'class'] ) ? (array)$attrs[
'class'] : [];
131 $buttons .= new \OOUI\ButtonInputWidget( [
133 'name' => $button[
'name'],
134 'value' => $button[
'value'],
137 'flags' => $button[
'flags'],
139 'framed' => $button[
'framed'],
147 return Html::rawElement(
'div',
148 [
'class' =>
'mw-htmlform-submit-buttons' ],
"\n$buttons" ) .
"\n";
157 $layout = new \OOUI\PanelLayout( [
163 $layout->appendContent(
164 new \OOUI\FieldsetLayout( [
168 'content' =>
new \OOUI\HtmlSnippet( $section )
181 return $field->
getOOUI( $value );
191 protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
192 if ( !$fieldsHtml ) {
198 $html = implode(
'', $fieldsHtml );
200 if ( $sectionName ) {
201 return Html::rawElement(
203 [
'id' => Sanitizer::escapeIdForAttribute( $sectionName ) ],
216 if ( $elements ===
'' ) {
220 if ( !in_array( $elementsType, [
'error',
'warning' ],
true ) ) {
221 throw new DomainException( $elementsType .
' is not a valid type.' );
224 if ( $elements instanceof
Status ) {
225 if ( !$elements->isGood() ) {
226 $errors = $elements->getErrorsByType( $elementsType );
227 foreach ( $errors as &$error ) {
228 $error = $this->
getMessage( [ $error[
'message'], ...$error[
'params'] ] )->parse();
231 } elseif ( $elementsType ===
'error' ) {
232 if ( is_array( $elements ) ) {
233 foreach ( $elements as $error ) {
234 $errors[] = $this->
getMessage( $error )->parse();
236 } elseif ( $elements && $elements !==
true ) {
237 $errors[] = (string)$elements;
241 foreach ( $errors as &$error ) {
242 $error = new \OOUI\HtmlSnippet( $error );
246 if ( $elementsType ===
'error' ) {
247 $this->oouiErrors = $errors;
249 $this->oouiWarnings = $errors;
255 if ( $section ===
null ) {
259 return parent::getHeaderHtml( $section );
264 if ( !( $this->mHeader || $this->oouiErrors || $this->oouiWarnings ) ) {
268 'mw-htmlform-ooui-header',
269 ...$this->oouiErrors ? [
'mw-htmlform-ooui-header-errors' ] : [],
270 ...$this->oouiWarnings ? [
'mw-htmlform-ooui-header-warnings' ] : [],
273 if ( $this->mHeader ) {
274 $element = new \OOUI\LabelWidget( [
'label' =>
new \OOUI\HtmlSnippet( $this->mHeader ) ] );
276 $element = new \OOUI\Widget( [] );
278 return new \OOUI\FieldLayout(
282 'errors' => $this->oouiErrors,
283 'notices' => $this->oouiWarnings,
284 'classes' => $classes,
294 if ( is_string( $this->mWrapperLegend ) ) {
295 $phpClass = $this->mCollapsible ? CollapsibleFieldsetLayout::class : \OOUI\FieldsetLayout::class;
296 $content =
new $phpClass( [
297 'label' => $this->mWrapperLegend,
298 'collapsed' => $this->mCollapsed,
301 'content' =>
new \OOUI\HtmlSnippet( $html )
304 ] + \OOUI\Element::configFromHtmlAttributes( $this->mWrapperAttributes ) );
306 $content = new \OOUI\HtmlSnippet( $html );
310 'classes' => [
'mw-htmlform',
'mw-htmlform-ooui' ],
311 'content' => $content,
315 $form = new \OOUI\PanelLayout( [
316 'classes' => [
'mw-htmlform-ooui-wrapper' ],
318 'padded' => $this->mWrapperLegend !==
false,
319 'framed' => $this->mWrapperLegend !==
false,
328class_alias( OOUIHTMLForm::class,
'OOUIHTMLForm' );
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()