Movatterモバイル変換


[0]ホーム

URL:


MediaWiki master
CodexHTMLForm.php
Go to the documentation of this file.
1<?php
2
10namespaceMediaWiki\HTMLForm;
11
12useMediaWiki\Html\Html;
13useMediaWiki\HTMLForm\Field\HTMLButtonField;
14useMediaWiki\Linker\Linker;
15useMediaWiki\Parser\Sanitizer;
16
22classCodexHTMLFormextendsHTMLForm {
23
25protected$displayFormat ='codex';
26
28publicstaticfunctionloadInputFromParameters( $fieldname, $descriptor,
29 ?HTMLForm $parent =null
30 ) {
31 $field = parent::loadInputFromParameters( $fieldname, $descriptor, $parent );
32 $field->setShowEmptyLabel(false );
33return $field;
34 }
35
37publicfunctiongetHTML( $submitResult ) {
38 $this->getOutput()->addModuleStyles( [
39'mediawiki.htmlform.codex.styles',
40 ] );
41
42return parent::getHTML( $submitResult );
43 }
44
48protectedfunctionformatField(HTMLFormField $field, $value ) {
49return $field->getCodex( $value );
50 }
51
53protectedfunctiongetFormAttributes() {
54 $attribs = parent::getFormAttributes();
55 $attribs['class'] = ['mw-htmlform','mw-htmlform-codex' ];
56return $attribs;
57 }
58
60publicfunctionwrapForm( $html ) {
61return Html::rawElement('form', $this->getFormAttributes(), $html );
62 }
63
65protectedfunctionwrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
66 $attributes['class'] ='cdx-field cdx-field--is-fieldset';
67 $legendElement = Html::rawElement('legend', ['class' => ['cdx-label' ] ], $legend );
68return Html::rawElement('fieldset', $attributes,"$legendElement\n$section" ) ."\n";
69 }
70
78publicfunctiongetLegend( $key ) {
79 $legendText = $this->msg(
80 $this->mMessagePrefix ?"{$this->mMessagePrefix}-$key" : $key
81 )->text();
82 $legendTextMarkup =Html::element(
83'span',
84 ['class' => ['cdx-label__label__text' ] ],
85 $legendText
86 );
87
88 $isOptional = $this->mSections[$key]['optional'] ??false;
89 $optionalFlagMarkup ='';
90if ( $isOptional ) {
91 $optionalFlagMarkup =Html::element(
92'span',
93 ['class' => ['cdx-label__label__optional-flag' ] ],
94 $this->msg('word-separator' )->text() . $this->msg('htmlform-optional-flag' )->text()
95 );
96 }
97
98 $descriptionMarkup ='';
99if ( isset( $this->mSections[$key]['description-message'] ) ) {
100 $needsParse = $this->mSections[ $key ]['description-message-parse' ] ??false;
101 $descriptionMessage = $this->msg( $this->mSections[ $key ]['description-message' ] );
102 $descriptionMarkup = Html::rawElement(
103'span',
104 ['class' => ['cdx-label__description' ] ],
105 $needsParse ? $descriptionMessage->parse() : $descriptionMessage->escaped()
106 );
107 } elseif ( isset( $this->mSections[$key]['description'] ) ) {
108 $descriptionMarkup =Html::element(
109'span',
110 ['class' => ['cdx-label__description' ] ],
111 $this->mSections[ $key ]['description' ]
112 );
113 }
114
115return Html::rawElement(
116'span',
117 ['class' => ['cdx-label__label' ] ],
118 $legendTextMarkup . $optionalFlagMarkup
119 ) . $descriptionMarkup;
120 }
121
123protectedfunctionformatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
124if ( !$fieldsHtml ) {
125// Do not generate any wrappers for empty sections. Sections may be empty if they only
126// have subsections, but no fields. A legend will still be added in
127// wrapFieldSetSection().
128return'';
129 }
130
131 $html = implode('', $fieldsHtml );
132
133if ( $sectionName ) {
134 $attribs = [
135'id' => Sanitizer::escapeIdForAttribute( $sectionName ),
136'class' => ['cdx-field__control' ]
137 ];
138
139return Html::rawElement('div', $attribs, $html );
140 }
141
142return $html;
143 }
144
150publicfunctiongetButtons() {
151 $buttons = [];
152
153if ( $this->mShowSubmit ) {
154 $value = $this->getSubmitText();
155// Define flag classes for the submit button
156 $submitFlags =$this->mSubmitFlags;
157 $submitClasses = ['mw-htmlform-submit','cdx-button' ];
158 $submitButtonLabel = $this->getSubmitText();
159 $submitID =$this->mSubmitID;
160 $submitName =$this->mSubmitName;
161 $submitTooltip = [];
162
163if ( $this->mSubmitTooltip !==null ) {
164 $submitTooltip += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
165 }
166
167 $buttonAttribs = [
168'value' => $value,
169'type' =>'submit',
170'name' => $submitName,
171'id' => $submitID,
172'class' => $submitClasses,
173'formnovalidate' =>false,
174 ] + $submitTooltip;
175
177 $submitFlags,
178 htmlspecialchars( $submitButtonLabel ),
179 $buttonAttribs
180 );
181 $buttons[] = $button;
182 }
183
184// The reset button is unused and will be removed from HTMLForm (T361032).
185
186if ( $this->mShowCancel ) {
187 $target = $this->getCancelTargetURL();
188 $buttonClasses = [
189'cdx-button',
190'cdx-button--fake-button',
191'cdx-button--fake-button--enabled',
192 ];
193 $attr = [
194'href' => $target,
195'class' => $buttonClasses,
196'role' =>'button',
197 ];
198 $cancelButton =Html::element(
199'a', $attr, $this->msg('cancel' )->text()
200 );
201 $buttons[] = $cancelButton;
202 }
203
204foreach ( $this->mButtons as $button ) {
205 $attrs = [
206'type' =>'submit',
207'name' => $button['name'],
208'value' => $button['value']
209 ];
210
211if ( isset( $button['label-message'] ) ) {
212 $label = $this->getMessage( $button['label-message'] )->parse();
213 } elseif ( isset( $button['label'] ) ) {
214 $label = htmlspecialchars( $button['label'] );
215 } elseif ( isset( $button['label-raw'] ) ) {
216 $label = $button['label-raw'];
217 }else {
218 $label = htmlspecialchars( $button['value'] );
219 }
220
221// @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset Always set in self::addButton
222if ( $button['attribs'] ) {
223// @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset Always set in self::addButton
224 $attrs += $button['attribs'];
225 }
226
227if ( isset( $button['id'] ) ) {
228 $attrs['id'] = $button['id'];
229 }
230
231 Html::addClass( $attrs['class'],'cdx-button' );
232
233 $buttons[] = Html::rawElement('button', $attrs, $label ) ."\n";
234 }
235
236if ( !$buttons ) {
237return'';
238 }
239
240return Html::rawElement(
241'div',
242 ['class' =>'mw-htmlform-submit-buttons' ],
243 implode("\n", $buttons )
244 ) ."\n";
245 }
246}
247
249class_alias( CodexHTMLForm::class,'CodexHTMLForm' );
MediaWiki\Context\ContextSource\msg
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
DefinitionContextSource.php:210
MediaWiki\Context\ContextSource\getOutput
getOutput()
DefinitionContextSource.php:138
MediaWiki\HTMLForm\CodexHTMLForm
Codex based HTML form.
DefinitionCodexHTMLForm.php:22
MediaWiki\HTMLForm\CodexHTMLForm\$displayFormat
$displayFormat
DefinitionCodexHTMLForm.php:25
MediaWiki\HTMLForm\CodexHTMLForm\wrapForm
wrapForm( $html)
Wrap the form innards in an actual "<form>" element.to override string|\OOUI\Tag Wrapped HTML.
DefinitionCodexHTMLForm.php:60
MediaWiki\HTMLForm\CodexHTMLForm\getHTML
getHTML( $submitResult)
Returns the raw HTML generated by the form.to overridestring HTML
DefinitionCodexHTMLForm.php:37
MediaWiki\HTMLForm\CodexHTMLForm\loadInputFromParameters
static loadInputFromParameters( $fieldname, $descriptor, ?HTMLForm $parent=null)
Initialise a new Object for the field.to overrideNot passing (or passing null) for $parent is depreca...
DefinitionCodexHTMLForm.php:28
MediaWiki\HTMLForm\CodexHTMLForm\getButtons
getButtons()
Get the submit and cancel buttons.
DefinitionCodexHTMLForm.php:150
MediaWiki\HTMLForm\CodexHTMLForm\formatSection
formatSection(array $fieldsHtml, $sectionName, $anyFieldHasLabel)
Put a form section together from the individual fields' HTML, merging it and wrapping....
DefinitionCodexHTMLForm.php:123
MediaWiki\HTMLForm\CodexHTMLForm\getLegend
getLegend( $key)
Note that this method returns HTML, while the parent method specifies that it should return a plain s...
DefinitionCodexHTMLForm.php:78
MediaWiki\HTMLForm\CodexHTMLForm\getFormAttributes
getFormAttributes()
Get HTML attributes for the <form> tag.to override array
DefinitionCodexHTMLForm.php:53
MediaWiki\HTMLForm\CodexHTMLForm\formatField
formatField(HTMLFormField $field, $value)
Generate the HTML for an individual field in the current display format.1.41 to override string|Strin...
DefinitionCodexHTMLForm.php:48
MediaWiki\HTMLForm\CodexHTMLForm\wrapFieldSetSection
wrapFieldSetSection( $legend, $section, $attributes, $isRoot)
Wraps the given $section into a user-visible fieldset.to overridestring The fieldset's Html
DefinitionCodexHTMLForm.php:65
MediaWiki\HTMLForm\Field\HTMLButtonField
Adds a generic button inline to the form.
DefinitionHTMLButtonField.php:30
MediaWiki\HTMLForm\Field\HTMLButtonField\buildCodexComponent
static buildCodexComponent( $flags, $buttonLabel, $attribs)
Build the markup of the Codex component.
DefinitionHTMLButtonField.php:153
MediaWiki\HTMLForm\HTMLFormField
The parent class to generate form fields.
DefinitionHTMLFormField.php:27
MediaWiki\HTMLForm\HTMLFormField\getCodex
getCodex( $value)
Get the Codex version of the div.
DefinitionHTMLFormField.php:841
MediaWiki\HTMLForm\HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
DefinitionHTMLForm.php:195
MediaWiki\HTMLForm\HTMLForm\$mSubmitID
string null $mSubmitID
DefinitionHTMLForm.php:295
MediaWiki\HTMLForm\HTMLForm\getCancelTargetURL
getCancelTargetURL()
DefinitionHTMLForm.php:1664
MediaWiki\HTMLForm\HTMLForm\getMessage
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
DefinitionHTMLForm.php:2129
MediaWiki\HTMLForm\HTMLForm\$mSubmitFlags
string[] $mSubmitFlags
DefinitionHTMLForm.php:261
MediaWiki\HTMLForm\HTMLForm\getSubmitText
getSubmitText()
Get the text for the submit button, either customised or a default.
DefinitionHTMLForm.php:1553
MediaWiki\HTMLForm\HTMLForm\$mSubmitName
string null $mSubmitName
DefinitionHTMLForm.php:297
MediaWiki\Html\Html
This class is a collection of static functions that serve two purposes:
DefinitionHtml.php:43
MediaWiki\Linker\Linker
Some internal bits split of from Skin.php.
DefinitionLinker.php:47
MediaWiki\Parser\Sanitizer
HTML sanitizer for MediaWiki.
DefinitionSanitizer.php:32
MediaWiki\HTMLForm
DefinitionCodexHTMLForm.php:10
MediaWiki\Html\element
element(SerializerNode $parent, SerializerNode $node, $contents)
DefinitionHtmlHelperTrait.php:38

[8]ページ先頭

©2009-2025 Movatter.jp