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