MediaWiki 1.40.4
HTMLForm.php
Go to the documentation of this file.
1<?php
2
24use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
31
153class HTMLForm extends ContextSource {
154 use ProtectedHookAccessorTrait;
155
157 public static $typeMappings = [
158 'api' => HTMLApiField::class,
159 'text' => HTMLTextField::class,
160 'textwithbutton' => HTMLTextFieldWithButton::class,
161 'textarea' => HTMLTextAreaField::class,
162 'select' => HTMLSelectField::class,
163 'combobox' => HTMLComboboxField::class,
164 'radio' => HTMLRadioField::class,
165 'multiselect' => HTMLMultiSelectField::class,
166 'limitselect' => HTMLSelectLimitField::class,
167 'check' => HTMLCheckField::class,
168 'toggle' => HTMLCheckField::class,
169 'int' => HTMLIntField::class,
170 'file' => HTMLFileField::class,
171 'float' => HTMLFloatField::class,
172 'info' => HTMLInfoField::class,
173 'selectorother' => HTMLSelectOrOtherField::class,
174 'selectandother' => HTMLSelectAndOtherField::class,
175 'namespaceselect' => HTMLSelectNamespace::class,
176 'namespaceselectwithbutton' => HTMLSelectNamespaceWithButton::class,
177 'tagfilter' => HTMLTagFilter::class,
178 'sizefilter' => HTMLSizeFilterField::class,
179 'submit' => HTMLSubmitField::class,
180 'hidden' => HTMLHiddenField::class,
181 'edittools' => HTMLEditTools::class,
182 'checkmatrix' => HTMLCheckMatrix::class,
183 'cloner' => HTMLFormFieldCloner::class,
184 'autocompleteselect' => HTMLAutoCompleteSelectField::class,
185 'language' => HTMLSelectLanguageField::class,
186 'date' => HTMLDateTimeField::class,
187 'time' => HTMLDateTimeField::class,
188 'datetime' => HTMLDateTimeField::class,
189 'expiry' => HTMLExpiryField::class,
190 'timezone' => HTMLTimezoneField::class,
191 // HTMLTextField will output the correct type="" attribute automagically.
192 // There are about four zillion other HTML5 input types, like range, but
193 // we don't use those at the moment, so no point in adding all of them.
194 'email' => HTMLTextField::class,
195 'password' => HTMLTextField::class,
196 'url' => HTMLTextField::class,
197 'title' => HTMLTitleTextField::class,
198 'user' => HTMLUserTextField::class,
199 'tagmultiselect' => HTMLTagMultiselectField::class,
200 'usersmultiselect' => HTMLUsersMultiselectField::class,
201 'titlesmultiselect' => HTMLTitlesMultiselectField::class,
202 'namespacesmultiselect' => HTMLNamespacesMultiselectField::class,
203 ];
204
206
208
210 protected $mFlatFields = [];
211 protected $mFieldTree = [];
212 protected $mShowReset = false;
213 protected $mShowSubmit = true;
215 protected $mSubmitFlags = [ 'primary', 'progressive' ];
216 protected $mShowCancel = false;
217 protected $mCancelTarget;
218
225
226 protected $mPre = '';
227 protected $mHeader = '';
228 protected $mFooter = '';
229 protected $mSectionHeaders = [];
230 protected $mSectionFooters = [];
231 protected $mPost = '';
232 protected $mId;
233 protected $mName;
234 protected $mTableId = '';
235
236 protected $mSubmitID;
237 protected $mSubmitName;
238 protected $mSubmitText;
240
243 protected $mTitle;
244 protected $mMethod = 'post';
245 protected $mWasSubmitted = false;
246
252 protected $mAction = false;
253
259 protected $mCollapsible = false;
260
266 protected $mCollapsed = false;
267
273 protected $mAutocomplete = null;
274
275 protected $mUseMultipart = false;
280 protected $mHiddenFields = [];
285 protected $mButtons = [];
286
287 protected $mWrapperLegend = false;
288 protected $mWrapperAttributes = [];
289
294 protected $mTokenSalt = '';
295
304 protected $mSubSectionBeforeFields = true;
305
311 protected $displayFormat = 'table';
312
317 protected $availableDisplayFormats = [
318 'table',
319 'div',
320 'raw',
321 'inline',
322 ];
323
328 protected $availableSubclassDisplayFormats = [
329 'vform',
330 'ooui',
331 ];
332
337 private $hiddenTitleAddedToForm = false;
338
352 public static function factory(
353 $displayFormat, $descriptor, IContextSource $context, $messagePrefix = ''
354 ) {
355 switch ( $displayFormat ) {
356 case 'vform':
357 return new VFormHTMLForm( $descriptor, $context, $messagePrefix );
358 case 'ooui':
359 return new OOUIHTMLForm( $descriptor, $context, $messagePrefix );
360 default:
361 $form = new self( $descriptor, $context, $messagePrefix );
362 $form->setDisplayFormat( $displayFormat );
363 return $form;
364 }
365 }
366
378 public function __construct(
379 $descriptor, IContextSource $context, $messagePrefix = ''
380 ) {
381 $this->setContext( $context );
382 $this->mMessagePrefix = $messagePrefix;
383
384 // Evil hack for mobile :(
385 if (
386 !$this->getConfig()->get( MainConfigNames::HTMLFormAllowTableFormat )
387 && $this->displayFormat === 'table'
388 ) {
389 $this->displayFormat = 'div';
390 }
391
392 $this->addFields( $descriptor );
393 }
394
404 public function addFields( $descriptor ) {
405 $loadedDescriptor = [];
406
407 foreach ( $descriptor as $fieldname => $info ) {
408
409 $section = $info['section'] ?? '';
410
411 if ( isset( $info['type'] ) && $info['type'] === 'file' ) {
412 $this->mUseMultipart = true;
413 }
414
415 $field = static::loadInputFromParameters( $fieldname, $info, $this );
416
417 $setSection =& $loadedDescriptor;
418 if ( $section ) {
419 foreach ( explode( '/', $section ) as $newName ) {
420 if ( !isset( $setSection[$newName] ) ) {
421 $setSection[$newName] = [];
422 }
423
424 $setSection =& $setSection[$newName];
425 }
426 }
427
428 $setSection[$fieldname] = $field;
429 $this->mFlatFields[$fieldname] = $field;
430 }
431
432 $this->mFieldTree = array_merge_recursive( $this->mFieldTree, $loadedDescriptor );
433
434 return $this;
435 }
436
441 public function hasField( $fieldname ) {
442 return isset( $this->mFlatFields[$fieldname] );
443 }
444
450 public function getField( $fieldname ) {
451 if ( !$this->hasField( $fieldname ) ) {
452 throw new DomainException( __METHOD__ . ': no field named ' . $fieldname );
453 }
454 return $this->mFlatFields[$fieldname];
455 }
456
467 public function setDisplayFormat( $format ) {
468 if (
469 in_array( $format, $this->availableSubclassDisplayFormats, true ) ||
470 in_array( $this->displayFormat, $this->availableSubclassDisplayFormats, true )
471 ) {
472 throw new MWException( 'Cannot change display format after creation, ' .
473 'use HTMLForm::factory() instead' );
474 }
475
476 if ( !in_array( $format, $this->availableDisplayFormats, true ) ) {
477 throw new MWException( 'Display format must be one of ' .
478 print_r(
479 array_merge(
480 $this->availableDisplayFormats,
481 $this->availableSubclassDisplayFormats
482 ),
483 true
484 ) );
485 }
486
487 // Evil hack for mobile :(
488 if ( !$this->getConfig()->get( MainConfigNames::HTMLFormAllowTableFormat ) &&
489 $format === 'table' ) {
490 $format = 'div';
491 }
492
493 $this->displayFormat = $format;
494
495 return $this;
496 }
497
503 public function getDisplayFormat() {
504 return $this->displayFormat;
505 }
506
524 public static function getClassFromDescriptor( $fieldname, &$descriptor ) {
525 if ( isset( $descriptor['class'] ) ) {
526 $class = $descriptor['class'];
527 } elseif ( isset( $descriptor['type'] ) ) {
528 $class = static::$typeMappings[$descriptor['type']];
529 $descriptor['class'] = $class;
530 } else {
531 $class = null;
532 }
533
534 if ( !$class ) {
535 throw new MWException( "Descriptor with no class for $fieldname: "
536 . print_r( $descriptor, true ) );
537 }
538
539 return $class;
540 }
541
555 public static function loadInputFromParameters( $fieldname, $descriptor,
556 HTMLForm $parent = null
557 ) {
558 $class = static::getClassFromDescriptor( $fieldname, $descriptor );
559
560 $descriptor['fieldname'] = $fieldname;
561 if ( $parent ) {
562 $descriptor['parent'] = $parent;
563 }
564
565 # @todo This will throw a fatal error whenever someone try to use
566 # 'class' to feed a CSS class instead of 'cssclass'. Would be
567 # great to avoid the fatal error and show a nice error.
568 return new $class( $descriptor );
569 }
570
580 public function prepareForm() {
581 # Load data from the request.
582 if (
583 $this->mFormIdentifier === null ||
584 $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier
585 ) {
586 $this->loadFieldData();
587 } else {
588 $this->mFieldData = [];
589 }
590
591 return $this;
592 }
593
598 public function tryAuthorizedSubmit() {
599 $result = false;
600
601 if ( $this->mFormIdentifier === null ) {
602 $identOkay = true;
603 } else {
604 $identOkay = $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier;
605 }
606
607 $tokenOkay = false;
608 if ( $this->getMethod() !== 'post' ) {
609 $tokenOkay = true; // no session check needed
610 } elseif ( $this->getRequest()->wasPosted() ) {
611 $editToken = $this->getRequest()->getVal( 'wpEditToken' );
612 if ( $this->getUser()->isRegistered() || $editToken !== null ) {
613 // Session tokens for logged-out users have no security value.
614 // However, if the user gave one, check it in order to give a nice
615 // "session expired" error instead of "permission denied" or such.
616 $tokenOkay = $this->getUser()->matchEditToken( $editToken, $this->mTokenSalt );
617 } else {
618 $tokenOkay = true;
619 }
620 }
621
622 if ( $tokenOkay && $identOkay ) {
623 $this->mWasSubmitted = true;
624 $result = $this->trySubmit();
625 }
626
627 return $result;
628 }
629
637 public function show() {
638 $this->prepareForm();
639
640 $result = $this->tryAuthorizedSubmit();
641 if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
642 return $result;
643 }
644
645 $this->displayForm( $result );
646
647 return false;
648 }
649
655 public function showAlways() {
656 $this->prepareForm();
657
658 $result = $this->tryAuthorizedSubmit();
659
660 $this->displayForm( $result );
661
662 return $result;
663 }
664
677 public function trySubmit() {
678 $valid = true;
679 $hoistedErrors = Status::newGood();
680 if ( $this->mValidationErrorMessage ) {
681 foreach ( $this->mValidationErrorMessage as $error ) {
682 $hoistedErrors->fatal( ...$error );
683 }
684 } else {
685 $hoistedErrors->fatal( 'htmlform-invalid-input' );
686 }
687
688 $this->mWasSubmitted = true;
689
690 # Check for cancelled submission
691 foreach ( $this->mFlatFields as $fieldname => $field ) {
692 if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
693 continue;
694 }
695 if ( $field->cancelSubmit( $this->mFieldData[$fieldname], $this->mFieldData ) ) {
696 $this->mWasSubmitted = false;
697 return false;
698 }
699 }
700
701 # Check for validation
702 $hasNonDefault = false;
703 foreach ( $this->mFlatFields as $fieldname => $field ) {
704 if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
705 continue;
706 }
707 $hasNonDefault = $hasNonDefault || $this->mFieldData[$fieldname] !== $field->getDefault();
708 if ( $field->isDisabled( $this->mFieldData ) ) {
709 continue;
710 }
711 $res = $field->validate( $this->mFieldData[$fieldname], $this->mFieldData );
712 if ( $res !== true ) {
713 $valid = false;
714 if ( $res !== false && !$field->canDisplayErrors() ) {
715 if ( is_string( $res ) ) {
716 $hoistedErrors->fatal( 'rawmessage', $res );
717 } else {
718 $hoistedErrors->fatal( $res );
719 }
720 }
721 }
722 }
723
724 if ( !$valid ) {
725 // Treat as not submitted if got nothing from the user on GET forms.
726 if ( !$hasNonDefault && $this->getMethod() === 'get' &&
727 ( $this->mFormIdentifier === null ||
728 $this->getRequest()->getCheck( 'wpFormIdentifier' ) )
729 ) {
730 $this->mWasSubmitted = false;
731 return false;
732 }
733 return $hoistedErrors;
734 }
735
736 $callback = $this->mSubmitCallback;
737 if ( !is_callable( $callback ) ) {
738 throw new MWException( 'HTMLForm: no submit callback provided. Use ' .
739 'setSubmitCallback() to set one.' );
740 }
741
742 $data = $this->filterDataForSubmit( $this->mFieldData );
743
744 $res = call_user_func( $callback, $data, $this );
745 if ( $res === false ) {
746 $this->mWasSubmitted = false;
747 } elseif ( $res instanceof StatusValue ) {
748 // DWIM - callbacks are not supposed to return a StatusValue but it's easy to mix up.
749 $res = Status::wrap( $res );
750 }
751
752 return $res;
753 }
754
766 public function wasSubmitted() {
767 return $this->mWasSubmitted;
768 }
769
780 public function setSubmitCallback( $cb ) {
781 $this->mSubmitCallback = $cb;
782
783 return $this;
784 }
785
795 public function setValidationErrorMessage( $msg ) {
796 $this->mValidationErrorMessage = $msg;
797
798 return $this;
799 }
800
809 public function setIntro( $msg ) {
810 return $this->setPreHtml( $msg );
811 }
812
821 public function setPreHtml( $html ) {
822 $this->mPre = $html;
823
824 return $this;
825 }
826
835 public function addPreHtml( $html ) {
836 $this->mPre .= $html;
837
838 return $this;
839 }
840
847 public function getPreHtml() {
848 return $this->mPre;
849 }
850
859 public function setPreText( $msg ) {
860 return $this->setPreHtml( $msg );
861 }
862
871 public function addPreText( $msg ) {
872 return $this->addPreHtml( $msg );
873 }
874
882 public function getPreText() {
883 return $this->getPreHtml();
884 }
885
895 public function addHeaderHtml( $html, $section = null ) {
896 if ( $section === null ) {
897 $this->mHeader .= $html;
898 } else {
899 if ( !isset( $this->mSectionHeaders[$section] ) ) {
900 $this->mSectionHeaders[$section] = '';
901 }
902 $this->mSectionHeaders[$section] .= $html;
903 }
904
905 return $this;
906 }
907
917 public function setHeaderHtml( $html, $section = null ) {
918 if ( $section === null ) {
919 $this->mHeader = $html;
920 } else {
921 $this->mSectionHeaders[$section] = $html;
922 }
923
924 return $this;
925 }
926
935 public function getHeaderHtml( $section = null ) {
936 if ( $section === null ) {
937 return $this->mHeader;
938 } else {
939 return $this->mSectionHeaders[$section] ?? '';
940 }
941 }
942
952 public function addHeaderText( $msg, $section = null ) {
953 return $this->addHeaderHtml( $msg, $section );
954 }
955
966 public function setHeaderText( $msg, $section = null ) {
967 return $this->setHeaderHtml( $msg, $section );
968 }
969
979 public function getHeaderText( $section = null ) {
980 return $this->getHeaderHtml( $section );
981 }
982
992 public function addFooterHtml( $html, $section = null ) {
993 if ( $section === null ) {
994 $this->mFooter .= $html;
995 } else {
996 if ( !isset( $this->mSectionFooters[$section] ) ) {
997 $this->mSectionFooters[$section] = '';
998 }
999 $this->mSectionFooters[$section] .= $html;
1000 }
1001
1002 return $this;
1003 }
1004
1014 public function setFooterHtml( $html, $section = null ) {
1015 if ( $section === null ) {
1016 $this->mFooter = $html;
1017 } else {
1018 $this->mSectionFooters[$section] = $html;
1019 }
1020
1021 return $this;
1022 }
1023
1031 public function getFooterHtml( $section = null ) {
1032 if ( $section === null ) {
1033 return $this->mFooter;
1034 } else {
1035 return $this->mSectionFooters[$section] ?? '';
1036 }
1037 }
1038
1048 public function addFooterText( $msg, $section = null ) {
1049 return $this->addFooterHtml( $msg, $section );
1050 }
1051
1062 public function setFooterText( $msg, $section = null ) {
1063 return $this->setFooterHtml( $msg, $section );
1064 }
1065
1074 public function getFooterText( $section = null ) {
1075 return $this->getFooterHtml( $section );
1076 }
1077
1086 public function addPostHtml( $html ) {
1087 $this->mPost .= $html;
1088
1089 return $this;
1090 }
1091
1100 public function setPostHtml( $html ) {
1101 $this->mPost = $html;
1102
1103 return $this;
1104 }
1105
1112 public function getPostHtml() {
1113 return $this->mPost;
1114 }
1115
1124 public function addPostText( $msg ) {
1125 return $this->addPostHtml( $msg );
1126 }
1127
1136 public function setPostText( $msg ) {
1137 return $this->setPostHtml( $msg );
1138 }
1139
1150 public function addHiddenField( $name, $value, array $attribs = [] ) {
1151 if ( !is_array( $value ) ) {
1152 // Per WebRequest::getVal: Array values are discarded for security reasons.
1153 $attribs += [ 'name' => $name ];
1154 $this->mHiddenFields[] = [ $value, $attribs ];
1155 }
1156
1157 return $this;
1158 }
1159
1171 public function addHiddenFields( array $fields ) {
1172 foreach ( $fields as $name => $value ) {
1173 if ( is_array( $value ) ) {
1174 // Per WebRequest::getVal: Array values are discarded for security reasons.
1175 continue;
1176 }
1177 $this->mHiddenFields[] = [ $value, [ 'name' => $name ] ];
1178 }
1179
1180 return $this;
1181 }
1182
1206 public function addButton( $data ) {
1207 if ( !is_array( $data ) ) {
1208 $args = func_get_args();
1209 if ( count( $args ) < 2 || count( $args ) > 4 ) {
1210 throw new InvalidArgumentException(
1211 'Incorrect number of arguments for deprecated calling style'
1212 );
1213 }
1214 $data = [
1215 'name' => $args[0],
1216 'value' => $args[1],
1217 'id' => $args[2] ?? null,
1218 'attribs' => $args[3] ?? null,
1219 ];
1220 } else {
1221 if ( !isset( $data['name'] ) ) {
1222 throw new InvalidArgumentException( 'A name is required' );
1223 }
1224 if ( !isset( $data['value'] ) ) {
1225 throw new InvalidArgumentException( 'A value is required' );
1226 }
1227 }
1228 $this->mButtons[] = $data + [
1229 'id' => null,
1230 'attribs' => null,
1231 'flags' => null,
1232 'framed' => true,
1233 ];
1234
1235 return $this;
1236 }
1237
1247 public function setTokenSalt( $salt ) {
1248 $this->mTokenSalt = $salt;
1249
1250 return $this;
1251 }
1252
1267 public function displayForm( $submitResult ) {
1268 $this->getOutput()->addHTML( $this->getHTML( $submitResult ) );
1269 }
1270
1275 private function getHiddenTitle(): string {
1276 if ( $this->hiddenTitleAddedToForm ) {
1277 return '';
1278 }
1279
1280 $html = '';
1281 if ( $this->getMethod() === 'post' ||
1282 $this->getAction() === $this->getConfig()->get( MainConfigNames::Script )
1283 ) {
1284 $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1285 }
1286 $this->hiddenTitleAddedToForm = true;
1287 return $html;
1288 }
1289
1300 public function getHTML( $submitResult ) {
1301 # For good measure (it is the default)
1302 $this->getOutput()->setPreventClickjacking( true );
1303 $this->getOutput()->addModules( 'mediawiki.htmlform' );
1304 $this->getOutput()->addModuleStyles( 'mediawiki.htmlform.styles' );
1305
1306 if ( $this->mCollapsible ) {
1307 // Preload jquery.makeCollapsible for mediawiki.htmlform
1308 $this->getOutput()->addModules( 'jquery.makeCollapsible' );
1309 }
1310
1311 $html = ''
1312 . $this->getErrorsOrWarnings( $submitResult, 'error' )
1313 . $this->getErrorsOrWarnings( $submitResult, 'warning' )
1314 . $this->getHeaderText()
1315 . $this->getHiddenTitle()
1316 . $this->getBody()
1317 . $this->getHiddenFields()
1318 . $this->getButtons()
1319 . $this->getFooterText();
1320
1321 $html = $this->wrapForm( $html );
1322
1323 return '' . $this->mPre . $html . $this->mPost;
1324 }
1325
1333 public function setCollapsibleOptions( $collapsedByDefault = false ) {
1334 $this->mCollapsible = true;
1335 $this->mCollapsed = $collapsedByDefault;
1336 return $this;
1337 }
1338
1344 protected function getFormAttributes() {
1345 # Use multipart/form-data
1346 $encType = $this->mUseMultipart
1347 ? 'multipart/form-data'
1348 : 'application/x-www-form-urlencoded';
1349 # Attributes
1350 $attribs = [
1351 'class' => 'mw-htmlform',
1352 'action' => $this->getAction(),
1353 'method' => $this->getMethod(),
1354 'enctype' => $encType,
1355 ];
1356 if ( $this->mId ) {
1357 $attribs['id'] = $this->mId;
1358 }
1359 if ( is_string( $this->mAutocomplete ) ) {
1360 $attribs['autocomplete'] = $this->mAutocomplete;
1361 }
1362 if ( $this->mName ) {
1363 $attribs['name'] = $this->mName;
1364 }
1365 if ( $this->needsJSForHtml5FormValidation() ) {
1366 $attribs['novalidate'] = true;
1367 }
1368 return $attribs;
1369 }
1370
1379 public function wrapForm( $html ) {
1380 # Include a <fieldset> wrapper for style, if requested.
1381 if ( $this->mWrapperLegend !== false ) {
1382 $legend = is_string( $this->mWrapperLegend ) ? $this->mWrapperLegend : false;
1383 $html = Xml::fieldset( $legend, $html, $this->mWrapperAttributes );
1384 }
1385
1386 return Html::rawElement(
1387 'form',
1388 $this->getFormAttributes(),
1389 $html
1390 );
1391 }
1392
1397 public function getHiddenFields() {
1398 $html = '';
1399
1400 // add the title as a hidden file if it hasn't been added yet and if it is necessary
1401 // added for backward compatibility with the previous version of this public method
1402 $html .= $this->getHiddenTitle();
1403
1404 if ( $this->mFormIdentifier !== null ) {
1405 $html .= Html::hidden(
1406 'wpFormIdentifier',
1407 $this->mFormIdentifier
1408 ) . "\n";
1409 }
1410 if ( $this->getMethod() === 'post' ) {
1411 $html .= Html::hidden(
1412 'wpEditToken',
1413 $this->getUser()->getEditToken( $this->mTokenSalt ),
1414 [ 'id' => 'wpEditToken' ]
1415 ) . "\n";
1416 }
1417
1418 foreach ( $this->mHiddenFields as [ $value, $attribs ] ) {
1419 $html .= Html::hidden( $attribs['name'], $value, $attribs ) . "\n";
1420 }
1421
1422 return $html;
1423 }
1424
1430 public function getButtons() {
1431 $buttons = '';
1432 $useMediaWikiUIEverywhere =
1433 $this->getConfig()->get( MainConfigNames::UseMediaWikiUIEverywhere );
1434
1435 if ( $this->mShowSubmit ) {
1436 $attribs = [];
1437
1438 if ( isset( $this->mSubmitID ) ) {
1439 $attribs['id'] = $this->mSubmitID;
1440 }
1441
1442 if ( isset( $this->mSubmitName ) ) {
1443 $attribs['name'] = $this->mSubmitName;
1444 }
1445
1446 if ( isset( $this->mSubmitTooltip ) ) {
1447 $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
1448 }
1449
1450 $attribs['class'] = [ 'mw-htmlform-submit' ];
1451
1452 if ( $useMediaWikiUIEverywhere ) {
1453 foreach ( $this->mSubmitFlags as $flag ) {
1454 $attribs['class'][] = 'mw-ui-' . $flag;
1455 }
1456 $attribs['class'][] = 'mw-ui-button';
1457 }
1458
1459 $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
1460 }
1461
1462 if ( $this->mShowReset ) {
1463 $buttons .= Html::element(
1464 'input',
1465 [
1466 'type' => 'reset',
1467 'value' => $this->msg( 'htmlform-reset' )->text(),
1468 'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null,
1469 ]
1470 ) . "\n";
1471 }
1472
1473 if ( $this->mShowCancel ) {
1474 $target = $this->getCancelTargetURL();
1475 $buttons .= Html::element(
1476 'a',
1477 [
1478 'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null,
1479 'href' => $target,
1480 ],
1481 $this->msg( 'cancel' )->text()
1482 ) . "\n";
1483 }
1484
1485 foreach ( $this->mButtons as $button ) {
1486 $attrs = [
1487 'type' => 'submit',
1488 'name' => $button['name'],
1489 'value' => $button['value']
1490 ];
1491
1492 if ( isset( $button['label-message'] ) ) {
1493 $label = $this->getMessage( $button['label-message'] )->parse();
1494 } elseif ( isset( $button['label'] ) ) {
1495 $label = htmlspecialchars( $button['label'] );
1496 } elseif ( isset( $button['label-raw'] ) ) {
1497 $label = $button['label-raw'];
1498 } else {
1499 $label = htmlspecialchars( $button['value'] );
1500 }
1501
1502 // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset Always set in self::addButton
1503 if ( $button['attribs'] ) {
1504 // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset Always set in self::addButton
1505 $attrs += $button['attribs'];
1506 }
1507
1508 if ( isset( $button['id'] ) ) {
1509 $attrs['id'] = $button['id'];
1510 }
1511
1512 if ( $useMediaWikiUIEverywhere ) {
1513 $attrs['class'] = isset( $attrs['class'] ) ? (array)$attrs['class'] : [];
1514 $attrs['class'][] = 'mw-ui-button';
1515 }
1516
1517 $buttons .= Html::rawElement( 'button', $attrs, $label ) . "\n";
1518 }
1519
1520 if ( !$buttons ) {
1521 return '';
1522 }
1523
1524 return Html::rawElement( 'span',
1525 [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n";
1526 }
1527
1533 public function getBody() {
1534 return $this->displaySection( $this->mFieldTree, $this->mTableId );
1535 }
1536
1546 public function getErrorsOrWarnings( $elements, $elementsType ) {
1547 if ( !in_array( $elementsType, [ 'error', 'warning' ], true ) ) {
1548 throw new DomainException( $elementsType . ' is not a valid type.' );
1549 }
1550 $elementstr = false;
1551 if ( $elements instanceof Status ) {
1552 [ $errorStatus, $warningStatus ] = $elements->splitByErrorType();
1553 $status = $elementsType === 'error' ? $errorStatus : $warningStatus;
1554 if ( $status->isGood() ) {
1555 $elementstr = '';
1556 } else {
1557 $elementstr = $status
1558 ->getMessage()
1559 ->setContext( $this )
1560 ->setInterfaceMessageFlag( true )
1561 ->parse();
1562 }
1563 } elseif ( $elementsType === 'error' ) {
1564 if ( is_array( $elements ) ) {
1565 $elementstr = $this->formatErrors( $elements );
1566 } elseif ( $elements && $elements !== true ) {
1567 $elementstr = (string)$elements;
1568 }
1569 }
1570
1571 if ( !$elementstr ) {
1572 return '';
1573 } elseif ( $elementsType === 'error' ) {
1574 return Html::errorBox( $elementstr );
1575 } else { // $elementsType can only be 'warning'
1576 return Html::warningBox( $elementstr );
1577 }
1578 }
1579
1587 public function formatErrors( $errors ) {
1588 $errorstr = '';
1589
1590 foreach ( $errors as $error ) {
1591 $errorstr .= Html::rawElement(
1592 'li',
1593 [],
1594 $this->getMessage( $error )->parse()
1595 );
1596 }
1597
1598 $errorstr = Html::rawElement( 'ul', [], $errorstr );
1599
1600 return $errorstr;
1601 }
1602
1610 public function setSubmitText( $t ) {
1611 $this->mSubmitText = $t;
1612
1613 return $this;
1614 }
1615
1622 public function setSubmitDestructive() {
1623 $this->mSubmitFlags = [ 'destructive', 'primary' ];
1624
1625 return $this;
1626 }
1627
1636 public function setSubmitTextMsg( $msg ) {
1637 if ( !$msg instanceof Message ) {
1638 $msg = $this->msg( $msg );
1639 }
1640 $this->setSubmitText( $msg->text() );
1641
1642 return $this;
1643 }
1644
1649 public function getSubmitText() {
1650 return $this->mSubmitText ?: $this->msg( 'htmlform-submit' )->text();
1651 }
1652
1658 public function setSubmitName( $name ) {
1659 $this->mSubmitName = $name;
1660
1661 return $this;
1662 }
1663
1669 public function setSubmitTooltip( $name ) {
1670 $this->mSubmitTooltip = $name;
1671
1672 return $this;
1673 }
1674
1683 public function setSubmitID( $t ) {
1684 $this->mSubmitID = $t;
1685
1686 return $this;
1687 }
1688
1704 public function setFormIdentifier( $ident ) {
1705 $this->mFormIdentifier = $ident;
1706
1707 return $this;
1708 }
1709
1720 public function suppressDefaultSubmit( $suppressSubmit = true ) {
1721 $this->mShowSubmit = !$suppressSubmit;
1722
1723 return $this;
1724 }
1725
1732 public function showCancel( $show = true ) {
1733 $this->mShowCancel = $show;
1734 return $this;
1735 }
1736
1743 public function setCancelTarget( $target ) {
1744 if ( $target instanceof PageReference ) {
1745 $target = TitleValue::castPageToLinkTarget( $target );
1746 }
1747
1748 $this->mCancelTarget = $target;
1749 return $this;
1750 }
1751
1756 protected function getCancelTargetURL() {
1757 if ( is_string( $this->mCancelTarget ) ) {
1758 return $this->mCancelTarget;
1759 } else {
1760 // TODO: use a service to get the local URL for a LinkTarget, see T282283
1761 $target = Title::castFromLinkTarget( $this->mCancelTarget ) ?: Title::newMainPage();
1762 return $target->getLocalURL();
1763 }
1764 }
1765
1775 public function setTableId( $id ) {
1776 $this->mTableId = $id;
1777
1778 return $this;
1779 }
1780
1786 public function setId( $id ) {
1787 $this->mId = $id;
1788
1789 return $this;
1790 }
1791
1796 public function setName( $name ) {
1797 $this->mName = $name;
1798
1799 return $this;
1800 }
1801
1813 public function setWrapperLegend( $legend ) {
1814 $this->mWrapperLegend = $legend;
1815
1816 return $this;
1817 }
1818
1826 public function setWrapperAttributes( $attributes ) {
1827 $this->mWrapperAttributes = $attributes;
1828
1829 return $this;
1830 }
1831
1841 public function setWrapperLegendMsg( $msg ) {
1842 if ( !$msg instanceof Message ) {
1843 $msg = $this->msg( $msg );
1844 }
1845 $this->setWrapperLegend( $msg->text() );
1846
1847 return $this;
1848 }
1849
1859 public function setMessagePrefix( $p ) {
1860 $this->mMessagePrefix = $p;
1861
1862 return $this;
1863 }
1864
1872 public function setTitle( $t ) {
1873 // TODO: make mTitle a PageReference when we have a better way to get URLs, see T282283.
1874 $this->mTitle = Title::castFromPageReference( $t );
1875
1876 return $this;
1877 }
1878
1882 public function getTitle() {
1883 return $this->mTitle ?: $this->getContext()->getTitle();
1884 }
1885
1893 public function setMethod( $method = 'post' ) {
1894 $this->mMethod = strtolower( $method );
1895
1896 return $this;
1897 }
1898
1902 public function getMethod() {
1903 return $this->mMethod;
1904 }
1905
1916 protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
1917 return Xml::fieldset( $legend, $section, $attributes ) . "\n";
1918 }
1919
1937 public function displaySection( $fields,
1938 $sectionName = '',
1939 $fieldsetIDPrefix = '',
1940 &$hasUserVisibleFields = false
1941 ) {
1942 if ( $this->mFieldData === null ) {
1943 throw new LogicException( 'HTMLForm::displaySection() called on uninitialized field data. '
1944 . 'You probably called displayForm() without calling prepareForm() first.' );
1945 }
1946
1947 $displayFormat = $this->getDisplayFormat();
1948
1949 $html = [];
1950 $subsectionHtml = '';
1951 $hasLabel = false;
1952
1953 // Conveniently, PHP method names are case-insensitive.
1954 // For grep: this can call getDiv, getRaw, getInline, getVForm, getOOUI
1955 $getFieldHtmlMethod = $displayFormat === 'table' ? 'getTableRow' : ( 'get' . $displayFormat );
1956
1957 foreach ( $fields as $key => $value ) {
1958 if ( $value instanceof HTMLFormField ) {
1959 $v = array_key_exists( $key, $this->mFieldData )
1960 ? $this->mFieldData[$key]
1961 : $value->getDefault();
1962
1963 $retval = $value->$getFieldHtmlMethod( $v ?? '' );
1964
1965 // check, if the form field should be added to
1966 // the output.
1967 if ( $value->hasVisibleOutput() ) {
1968 $html[] = $retval;
1969
1970 $labelValue = trim( $value->getLabel() );
1971 if ( $labelValue !== "\u{00A0}" && $labelValue !== '&#160;' && $labelValue !== '' ) {
1972 $hasLabel = true;
1973 }
1974
1975 $hasUserVisibleFields = true;
1976 }
1977 } elseif ( is_array( $value ) ) {
1978 $subsectionHasVisibleFields = false;
1979 $section =
1980 $this->displaySection( $value,
1981 "mw-htmlform-$key",
1982 "$fieldsetIDPrefix$key-",
1983 $subsectionHasVisibleFields );
1984
1985 if ( $subsectionHasVisibleFields === true ) {
1986 // Display the section with various niceties.
1987 $hasUserVisibleFields = true;
1988
1989 $legend = $this->getLegend( $key );
1990
1991 $section = $this->getHeaderText( $key ) .
1992 $section .
1993 $this->getFooterText( $key );
1994
1995 $attributes = [];
1996 if ( $fieldsetIDPrefix ) {
1997 $attributes['id'] = Sanitizer::escapeIdForAttribute( "$fieldsetIDPrefix$key" );
1998 }
1999 $subsectionHtml .= $this->wrapFieldSetSection(
2000 $legend, $section, $attributes, $fields === $this->mFieldTree
2001 );
2002 } else {
2003 // Just return the inputs, nothing fancy.
2004 $subsectionHtml .= $section;
2005 }
2006 }
2007 }
2008
2009 $html = $this->formatSection( $html, $sectionName, $hasLabel );
2010
2011 if ( $subsectionHtml ) {
2012 if ( $this->mSubSectionBeforeFields ) {
2013 return $subsectionHtml . "\n" . $html;
2014 } else {
2015 return $html . "\n" . $subsectionHtml;
2016 }
2017 } else {
2018 return $html;
2019 }
2020 }
2021
2030 protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
2031 if ( !$fieldsHtml ) {
2032 // Do not generate any wrappers for empty sections. Sections may be empty if they only have
2033 // subsections, but no fields. A legend will still be added in wrapFieldSetSection().
2034 return '';
2035 }
2036
2037 $displayFormat = $this->getDisplayFormat();
2038 $html = implode( '', $fieldsHtml );
2039
2040 if ( $displayFormat === 'raw' ) {
2041 return $html;
2042 }
2043
2044 $classes = [];
2045
2046 if ( !$anyFieldHasLabel ) { // Avoid strange spacing when no labels exist
2047 $classes[] = 'mw-htmlform-nolabel';
2048 }
2049
2050 $attribs = [ 'class' => $classes ];
2051
2052 if ( $sectionName ) {
2053 $attribs['id'] = Sanitizer::escapeIdForAttribute( $sectionName );
2054 }
2055
2056 if ( $displayFormat === 'table' ) {
2057 return Html::rawElement( 'table',
2058 $attribs,
2059 Html::rawElement( 'tbody', [], "\n$html\n" ) ) . "\n";
2060 } elseif ( $displayFormat === 'inline' ) {
2061 return Html::rawElement( 'span', $attribs, "\n$html\n" );
2062 } else {
2063 return Html::rawElement( 'div', $attribs, "\n$html\n" );
2064 }
2065 }
2066
2070 public function loadData() {
2071 $this->prepareForm();
2072 }
2073
2077 protected function loadFieldData() {
2078 $fieldData = [];
2079 $request = $this->getRequest();
2080
2081 foreach ( $this->mFlatFields as $fieldname => $field ) {
2082 if ( $field->skipLoadData( $request ) ) {
2083 continue;
2084 }
2085 if ( $field->mParams['disabled'] ?? false ) {
2086 $fieldData[$fieldname] = $field->getDefault();
2087 } else {
2088 $fieldData[$fieldname] = $field->loadDataFromRequest( $request );
2089 }
2090 }
2091
2092 // Reset to default for fields that are supposed to be disabled.
2093 // FIXME: Handle dependency chains, fields that a field checks on may need a reset too.
2094 foreach ( $fieldData as $name => &$value ) {
2095 $field = $this->mFlatFields[$name];
2096 if ( $field->isDisabled( $fieldData ) ) {
2097 $value = $field->getDefault();
2098 }
2099 }
2100
2101 # Filter data.
2102 foreach ( $fieldData as $name => &$value ) {
2103 $field = $this->mFlatFields[$name];
2104 $value = $field->filter( $value, $fieldData );
2105 }
2106
2107 $this->mFieldData = $fieldData;
2108 }
2109
2117 public function suppressReset( $suppressReset = true ) {
2118 $this->mShowReset = !$suppressReset;
2119
2120 return $this;
2121 }
2122
2133 public function filterDataForSubmit( $data ) {
2134 return $data;
2135 }
2136
2146 public function getLegend( $key ) {
2147 return $this->msg( $this->mMessagePrefix ? "{$this->mMessagePrefix}-$key" : $key )->text();
2148 }
2149
2160 public function setAction( $action ) {
2161 $this->mAction = $action;
2162
2163 return $this;
2164 }
2165
2173 public function getAction() {
2174 // If an action is already provided, return it
2175 if ( $this->mAction !== false ) {
2176 return $this->mAction;
2177 }
2178
2179 $articlePath = $this->getConfig()->get( MainConfigNames::ArticlePath );
2180 // Check whether we are in GET mode and the ArticlePath contains a "?"
2181 // meaning that getLocalURL() would return something like "index.php?title=...".
2182 // As browser remove the query string before submitting GET forms,
2183 // it means that the title would be lost. In such case use script path instead
2184 // and put title in an hidden field (see getHiddenFields()).
2185 if ( str_contains( $articlePath, '?' ) && $this->getMethod() === 'get' ) {
2186 return $this->getConfig()->get( MainConfigNames::Script );
2187 }
2188
2189 return $this->getTitle()->getLocalURL();
2190 }
2191
2202 public function setAutocomplete( $autocomplete ) {
2203 $this->mAutocomplete = $autocomplete;
2204
2205 return $this;
2206 }
2207
2214 protected function getMessage( $value ) {
2215 return Message::newFromSpecifier( $value )->setContext( $this );
2216 }
2217
2228 foreach ( $this->mFlatFields as $field ) {
2229 if ( $field->needsJSForHtml5FormValidation() ) {
2230 return true;
2231 }
2232 }
2233 return false;
2234 }
2235}
getUser()
addFields( $fields)
getContext()
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
Definition WebStart.php:88
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
setContext(IContextSource $context)
The parent class to generate form fields.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:153
needsJSForHtml5FormValidation()
Whether this form, with its current fields, requires the user agent to have JavaScript enabled for th...
setSubmitCallback( $cb)
Set a callback to a function to do something with the form once it's been successfully validated.
Definition HTMLForm.php:780
setHeaderText( $msg, $section=null)
Set header text, inside the form.
Definition HTMLForm.php:966
string false $mAction
Form action URL.
Definition HTMLForm.php:252
displayForm( $submitResult)
Display the form (sending to the context's OutputPage object), with an appropriate error message or s...
string null $mAutocomplete
Form attribute autocomplete.
Definition HTMLForm.php:273
setAction( $action)
Set the value for the action attribute of the form.
string array $mTokenSalt
Salt for the edit token.
Definition HTMLForm.php:294
setFooterHtml( $html, $section=null)
Set footer HTML, inside the form.
string[] $mSubmitFlags
Definition HTMLForm.php:215
addPreHtml( $html)
Add HTML to introductory message.
Definition HTMLForm.php:835
getSubmitText()
Get the text for the submit button, either customised or a default.
setMethod( $method='post')
Set the method used to submit the form.
setValidationErrorMessage( $msg)
Set a message to display on a validation error.
Definition HTMLForm.php:795
getCancelTargetURL()
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
getHeaderHtml( $section=null)
Get header HTML.
Definition HTMLForm.php:935
addHeaderHtml( $html, $section=null)
Add HTML to the header, inside the form.
Definition HTMLForm.php:895
setAutocomplete( $autocomplete)
Set the value for the autocomplete attribute of the form.
static loadInputFromParameters( $fieldname, $descriptor, HTMLForm $parent=null)
Initialise a new Object for the field.
Definition HTMLForm.php:555
setSubmitName( $name)
setTitle( $t)
Set the title for form submission.
static getClassFromDescriptor( $fieldname, &$descriptor)
Get the HTMLFormField subclass for this descriptor.
Definition HTMLForm.php:524
array $availableSubclassDisplayFormats
Available formats in which to display the form.
Definition HTMLForm.php:328
string $displayFormat
Format in which to display form.
Definition HTMLForm.php:311
addPostHtml( $html)
Add HTML to the end of the display.
bool $mSubSectionBeforeFields
If true, sections that contain both fields and subsections will render their subsections before their...
Definition HTMLForm.php:304
setTableId( $id)
Set the id of the <table> or outermost <div> element.
getHTML( $submitResult)
Returns the raw HTML generated by the form.
getLegend( $key)
Get a string to go in the "<legend>" of a section fieldset.
setSubmitTextMsg( $msg)
Set the text for the submit button to a message.
wrapFieldSetSection( $legend, $section, $attributes, $isRoot)
Wraps the given $section into an user-visible fieldset.
filterDataForSubmit( $data)
Overload this if you want to apply special filtration routines to the form as a whole,...
setWrapperLegendMsg( $msg)
Prompt the whole form to be wrapped in a "<fieldset>", with this message as its "<legend>" element.
setId( $id)
setWrapperLegend( $legend)
Prompt the whole form to be wrapped in a "<fieldset>", with this text as its "<legend>" element.
formatErrors( $errors)
Format a stack of error messages into a single HTML string.
setDisplayFormat( $format)
Set format in which to display the form.
Definition HTMLForm.php:467
addButton( $data)
Add a button to the form.
addFooterHtml( $html, $section=null)
Add footer HTML, inside the form.
Definition HTMLForm.php:992
setPreHtml( $html)
Set the introductory message HTML, overwriting any existing message.
Definition HTMLForm.php:821
getPreHtml()
Get the introductory message HTML.
Definition HTMLForm.php:847
setPostHtml( $html)
Set HTML at the end of the display.
getPreText()
Get the introductory message HTML.
Definition HTMLForm.php:882
static string[] $typeMappings
A mapping of 'type' inputs onto standard HTMLFormField subclasses.
Definition HTMLForm.php:157
getHiddenFields()
Get the hidden fields that should go inside the form.
setSubmitDestructive()
Identify that the submit button in the form has a destructive action.
suppressDefaultSubmit( $suppressSubmit=true)
Stop a default submit button being shown for this form.
setSubmitID( $t)
Set the id for the submit button.
getDisplayFormat()
Getter for displayFormat.
Definition HTMLForm.php:503
getAction()
Get the value for the action attribute of the form.
show()
The here's-one-I-made-earlier option: do the submission if posted, or display the form with or withou...
Definition HTMLForm.php:637
hasField( $fieldname)
Definition HTMLForm.php:441
$mWrapperAttributes
Definition HTMLForm.php:288
addFooterText( $msg, $section=null)
Add footer text, inside the form.
addPostText( $msg)
Add text to the end of the display.
getFooterText( $section=null)
Get footer text.
addHeaderText( $msg, $section=null)
Add HTML to the header, inside the form.
Definition HTMLForm.php:952
setWrapperAttributes( $attributes)
For internal use only.
prepareForm()
Prepare form for submission.
Definition HTMLForm.php:580
array[] $mValidationErrorMessage
Definition HTMLForm.php:224
setCollapsibleOptions( $collapsedByDefault=false)
Enable collapsible mode, and set whether the form is collapsed by default.
wasSubmitted()
Test whether the form was considered to have been submitted or not, i.e.
Definition HTMLForm.php:766
getHeaderText( $section=null)
Get header text.
Definition HTMLForm.php:979
array[] $mButtons
Definition HTMLForm.php:285
tryAuthorizedSubmit()
Try submitting, with edit token check first.
Definition HTMLForm.php:598
setSubmitTooltip( $name)
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
array[] $mHiddenFields
Definition HTMLForm.php:280
setPreText( $msg)
Set the introductory message HTML, overwriting any existing message.
Definition HTMLForm.php:859
bool $mCollapsible
Whether the form can be collapsed.
Definition HTMLForm.php:259
addHiddenField( $name, $value, array $attribs=[])
Add a hidden field to the output Array values are discarded for security reasons (per WebRequest::get...
setFooterText( $msg, $section=null)
Set footer text, inside the form.
setMessagePrefix( $p)
Set the prefix for various default messages.
getField( $fieldname)
Definition HTMLForm.php:450
bool $mCollapsed
Whether the form is collapsed by default.
Definition HTMLForm.php:266
wrapForm( $html)
Wrap the form innards in an actual "<form>" element.
getFormAttributes()
Get HTML attributes for the <form> tag.
getBody()
Get the whole body of the form.
showAlways()
Same as self::show with the difference, that the form will be added to the output,...
Definition HTMLForm.php:655
getFooterHtml( $section=null)
Get footer HTML.
loadFieldData()
Load data of form fields from the request.
setHeaderHtml( $html, $section=null)
Set header HTML, inside the form.
Definition HTMLForm.php:917
setTokenSalt( $salt)
Set the salt for the edit token.
__construct( $descriptor, IContextSource $context, $messagePrefix='')
Build a new HTMLForm from an array of field attributes.
Definition HTMLForm.php:378
addPreText( $msg)
Add HTML to introductory message.
Definition HTMLForm.php:871
setFormIdentifier( $ident)
Set an internal identifier for this form.
setName( $name)
suppressReset( $suppressReset=true)
Stop a reset button being shown for this form.
setPostText( $msg)
Set text at the end of the display.
formatSection(array $fieldsHtml, $sectionName, $anyFieldHasLabel)
Put a form section together from the individual fields' HTML, merging it and wrapping.
setCancelTarget( $target)
Sets the target where the user is redirected to after clicking cancel.
array $availableDisplayFormats
Available formats in which to display the form.
Definition HTMLForm.php:317
showCancel( $show=true)
Show a cancel button (or prevent it).
Title null $mTitle
Definition HTMLForm.php:243
setSubmitText( $t)
Set the text for the submit button.
setIntro( $msg)
Set the introductory message, overwriting any existing message.
Definition HTMLForm.php:809
getButtons()
Get the submit and (potentially) reset buttons.
static factory( $displayFormat, $descriptor, IContextSource $context, $messagePrefix='')
Construct a HTMLForm object for given display type.
Definition HTMLForm.php:352
trySubmit()
Validate all the fields, and call the submission callback function if everything is kosher.
Definition HTMLForm.php:677
HTMLFormField[] $mFlatFields
Definition HTMLForm.php:210
getErrorsOrWarnings( $elements, $elementsType)
Returns a formatted list of errors or warnings from the given elements.
addHiddenFields(array $fields)
Add an array of hidden fields to the output Array values are discarded for security reasons (per WebR...
getPostHtml()
Get HTML at the end of the display.
addFields( $descriptor)
Add fields to the form.
Definition HTMLForm.php:404
MediaWiki exception.
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:67
A class containing constants representing the names of configuration variables.
Represents a title within MediaWiki.
Definition Title.php:82
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition Message.php:144
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition Message.php:426
Compact stacked vertical format for forms, implemented using OOUI widgets.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
isGood()
Returns whether the operation completed and didn't have any error or warnings.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:46
Compact stacked vertical format for forms.
Interface for objects which can provide a MediaWiki context on request.
Interface for objects (potentially) representing a page that can be viewable and linked to on a wiki.