MediaWiki  master
VFormHTMLForm.php
Go to the documentation of this file.
1 <?php
2 
26 
32 class VFormHTMLForm extends HTMLForm {
37  protected $mWrapperLegend = false;
38 
43  protected $displayFormat = 'vform';
44 
45  public static function loadInputFromParameters( $fieldname, $descriptor,
46  HTMLForm $parent = null
47  ) {
48  $field = parent::loadInputFromParameters( $fieldname, $descriptor, $parent );
49  $field->setShowEmptyLabel( false );
50  return $field;
51  }
52 
53  public function getHTML( $submitResult ) {
54  // This is required for VForm HTMLForms that use that style regardless
55  // of wgUseMediaWikiUIEverywhere (since they pre-date it).
56  // When wgUseMediaWikiUIEverywhere is removed, this should be consolidated
57  // with the addModuleStyles in SpecialPage->setHeaders.
58  $this->getOutput()->addModuleStyles( [
59  'mediawiki.ui',
60  'mediawiki.ui.button',
61  'mediawiki.ui.input',
62  'mediawiki.ui.checkbox',
63  ] );
64 
65  return parent::getHTML( $submitResult );
66  }
67 
68  protected function getFormAttributes() {
69  $attribs = parent::getFormAttributes();
70  $attribs['class'] = [ 'mw-htmlform', 'mw-ui-vform', 'mw-ui-container' ];
71  return $attribs;
72  }
73 
74  public function wrapForm( $html ) {
75  // Always discard $this->mWrapperLegend
76  return Html::rawElement( 'form', $this->getFormAttributes(), $html );
77  }
78 
79  public function getButtons() {
80  $buttons = '';
81 
82  if ( $this->mShowSubmit ) {
83  $attribs = [];
84 
85  if ( isset( $this->mSubmitID ) ) {
86  $attribs['id'] = $this->mSubmitID;
87  }
88 
89  if ( isset( $this->mSubmitName ) ) {
90  $attribs['name'] = $this->mSubmitName;
91  }
92 
93  if ( isset( $this->mSubmitTooltip ) ) {
94  $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
95  }
96 
97  $attribs['class'] = [
98  'mw-htmlform-submit',
99  'mw-ui-button mw-ui-big mw-ui-block',
100  ];
101  foreach ( $this->mSubmitFlags as $flag ) {
102  $attribs['class'][] = 'mw-ui-' . $flag;
103  }
104 
105  $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
106  }
107 
108  if ( $this->mShowReset ) {
109  $buttons .= Html::element(
110  'input',
111  [
112  'type' => 'reset',
113  'value' => $this->msg( 'htmlform-reset' )->text(),
114  'class' => 'mw-ui-button mw-ui-big mw-ui-block',
115  ]
116  ) . "\n";
117  }
118 
119  if ( $this->mShowCancel ) {
120  $target = $this->getCancelTargetURL();
121  $buttons .= Html::element(
122  'a',
123  [
124  'class' => 'mw-ui-button mw-ui-big mw-ui-block',
125  'href' => $target,
126  ],
127  $this->msg( 'cancel' )->text()
128  ) . "\n";
129  }
130 
131  foreach ( $this->mButtons as $button ) {
132  $attrs = [
133  'type' => 'submit',
134  'name' => $button['name'],
135  'value' => $button['value']
136  ];
137 
138  // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset Always set in HTMLForm::addButton
139  if ( $button['attribs'] ) {
140  // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset Always set in HTMLForm::addButton
141  $attrs += $button['attribs'];
142  }
143 
144  if ( isset( $button['id'] ) ) {
145  $attrs['id'] = $button['id'];
146  }
147 
148  $attrs['class'] = isset( $attrs['class'] ) ? (array)$attrs['class'] : [];
149  $attrs['class'][] = 'mw-ui-button mw-ui-big mw-ui-block';
150 
151  $buttons .= Html::element( 'input', $attrs ) . "\n";
152  }
153 
154  if ( !$buttons ) {
155  return '';
156  }
157 
158  return Html::rawElement( 'div',
159  [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n";
160  }
161 }
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition: HTMLForm.php:153
getSubmitText()
Get the text for the submit button, either customised or a default.
Definition: HTMLForm.php:1649
getCancelTargetURL()
Definition: HTMLForm.php:1756
This class is a collection of static functions that serve two purposes:
Definition: Html.php:55
Some internal bits split of from Skin.php.
Definition: Linker.php:65
Compact stacked vertical format for forms.
getHTML( $submitResult)
Returns the raw HTML generated by the form.
string $displayFormat
Symbolic display format name.
getFormAttributes()
Get HTML attributes for the <form> tag.
getButtons()
Get the submit and (potentially) reset buttons.
bool $mWrapperLegend
Wrapper and its legend are never generated in VForm mode.
static loadInputFromParameters( $fieldname, $descriptor, HTMLForm $parent=null)
Initialise a new Object for the field.
wrapForm( $html)
Wrap the form innards in an actual "<form>" element.
static submitButton( $value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
Definition: Xml.php:467