MediaWiki master
HTMLForm.php
Go to the documentation of this file.
1<?php
2
24namespace MediaWiki\HTMLForm;
25
26use DomainException;
27use InvalidArgumentException;
28use LogicException;
32use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
80use StatusValue;
81use Stringable;
83
208class HTMLForm extends ContextSource {
209 use ProtectedHookAccessorTrait;
210
212 public static $typeMappings = [
213 'api' => HTMLApiField::class,
214 'text' => HTMLTextField::class,
215 'textwithbutton' => HTMLTextFieldWithButton::class,
216 'textarea' => HTMLTextAreaField::class,
217 'select' => HTMLSelectField::class,
218 'combobox' => HTMLComboboxField::class,
219 'radio' => HTMLRadioField::class,
220 'multiselect' => HTMLMultiSelectField::class,
221 'limitselect' => HTMLSelectLimitField::class,
222 'check' => HTMLCheckField::class,
223 'toggle' => HTMLCheckField::class,
224 'int' => HTMLIntField::class,
225 'file' => HTMLFileField::class,
226 'float' => HTMLFloatField::class,
227 'info' => HTMLInfoField::class,
228 'selectorother' => HTMLSelectOrOtherField::class,
229 'selectandother' => HTMLSelectAndOtherField::class,
230 'namespaceselect' => HTMLSelectNamespace::class,
231 'namespaceselectwithbutton' => HTMLSelectNamespaceWithButton::class,
232 'tagfilter' => HTMLTagFilter::class,
233 'sizefilter' => HTMLSizeFilterField::class,
234 'submit' => HTMLSubmitField::class,
235 'hidden' => HTMLHiddenField::class,
236 'edittools' => HTMLEditTools::class,
237 'checkmatrix' => HTMLCheckMatrix::class,
238 'cloner' => HTMLFormFieldCloner::class,
239 'autocompleteselect' => HTMLAutoCompleteSelectField::class,
240 'language' => HTMLSelectLanguageField::class,
241 'date' => HTMLDateTimeField::class,
242 'time' => HTMLDateTimeField::class,
243 'datetime' => HTMLDateTimeField::class,
244 'expiry' => HTMLExpiryField::class,
245 'timezone' => HTMLTimezoneField::class,
246 // HTMLTextField will output the correct type="" attribute automagically.
247 // There are about four zillion other HTML5 input types, like range, but
248 // we don't use those at the moment, so no point in adding all of them.
249 'email' => HTMLTextField::class,
250 'password' => HTMLTextField::class,
251 'url' => HTMLTextField::class,
252 'title' => HTMLTitleTextField::class,
253 'user' => HTMLUserTextField::class,
254 'tagmultiselect' => HTMLTagMultiselectField::class,
255 'usersmultiselect' => HTMLUsersMultiselectField::class,
256 'titlesmultiselect' => HTMLTitlesMultiselectField::class,
257 'namespacesmultiselect' => HTMLNamespacesMultiselectField::class,
258 ];
259
262
265
267 protected $mFlatFields = [];
269 protected $mFieldTree = [];
271 protected $mShowSubmit = true;
273 protected $mSubmitFlags = [ 'primary', 'progressive' ];
275 protected $mShowCancel = false;
277 protected $mCancelTarget;
278
286
288 protected $mPre = '';
290 protected $mHeader = '';
292 protected $mFooter = '';
294 protected $mSectionHeaders = [];
296 protected $mSectionFooters = [];
298 protected $mPost = '';
300 protected $mId;
302 protected $mName;
304 protected $mTableId = '';
305
307 protected $mSubmitID;
309 protected $mSubmitName;
311 protected $mSubmitText;
314
318 protected $mSingleForm = false;
319
321 protected $mTitle;
323 protected $mMethod = 'post';
325 protected $mWasSubmitted = false;
326
332 protected $mAction = false;
333
339 protected $mCollapsible = false;
340
346 protected $mCollapsed = false;
347
353 protected $mAutocomplete = null;
354
356 protected $mUseMultipart = false;
361 protected $mHiddenFields = [];
366 protected $mButtons = [];
367
369 protected $mWrapperLegend = false;
371 protected $mWrapperAttributes = [];
372
377 protected $mTokenSalt = '';
378
391 protected $mSections = [];
392
401 protected $mSubSectionBeforeFields = true;
402
408 protected $displayFormat = 'table';
409
415 'table',
416 'div',
417 'raw',
418 'inline',
419 ];
420
426 'vform',
427 'codex',
428 'ooui',
429 ];
430
435 private $hiddenTitleAddedToForm = false;
436
450 public static function factory(
451 $displayFormat, $descriptor, IContextSource $context, $messagePrefix = ''
452 ) {
453 switch ( $displayFormat ) {
454 case 'codex':
455 return new CodexHTMLForm( $descriptor, $context, $messagePrefix );
456 case 'vform':
457 return new VFormHTMLForm( $descriptor, $context, $messagePrefix );
458 case 'ooui':
459 return new OOUIHTMLForm( $descriptor, $context, $messagePrefix );
460 default:
461 $form = new self( $descriptor, $context, $messagePrefix );
462 $form->setDisplayFormat( $displayFormat );
463 return $form;
464 }
465 }
466
478 public function __construct(
479 $descriptor, IContextSource $context, $messagePrefix = ''
480 ) {
481 $this->setContext( $context );
482 $this->mMessagePrefix = $messagePrefix;
483 $this->addFields( $descriptor );
484 }
485
495 public function addFields( $descriptor ) {
496 $loadedDescriptor = [];
497
498 foreach ( $descriptor as $fieldname => $info ) {
499 $section = $info['section'] ?? '';
500
501 if ( isset( $info['type'] ) && $info['type'] === 'file' ) {
502 $this->mUseMultipart = true;
503 }
504
505 $field = static::loadInputFromParameters( $fieldname, $info, $this );
506
507 $setSection =& $loadedDescriptor;
508 if ( $section ) {
509 foreach ( explode( '/', $section ) as $newName ) {
510 $setSection[$newName] ??= [];
511 $setSection =& $setSection[$newName];
512 }
513 }
514
515 $setSection[$fieldname] = $field;
516 $this->mFlatFields[$fieldname] = $field;
517 }
518
519 $this->mFieldTree = array_merge_recursive( $this->mFieldTree, $loadedDescriptor );
520
521 return $this;
522 }
523
528 public function hasField( $fieldname ) {
529 return isset( $this->mFlatFields[$fieldname] );
530 }
531
537 public function getField( $fieldname ) {
538 if ( !$this->hasField( $fieldname ) ) {
539 throw new DomainException( __METHOD__ . ': no field named ' . $fieldname );
540 }
541 return $this->mFlatFields[$fieldname];
542 }
543
553 public function setDisplayFormat( $format ) {
554 if (
555 in_array( $format, $this->availableSubclassDisplayFormats, true ) ||
556 in_array( $this->displayFormat, $this->availableSubclassDisplayFormats, true )
557 ) {
558 throw new LogicException( 'Cannot change display format after creation, ' .
559 'use HTMLForm::factory() instead' );
560 }
561
562 if ( !in_array( $format, $this->availableDisplayFormats, true ) ) {
563 throw new InvalidArgumentException( 'Display format must be one of ' .
564 print_r(
565 array_merge(
566 $this->availableDisplayFormats,
567 $this->availableSubclassDisplayFormats
568 ),
569 true
570 ) );
571 }
572
573 $this->displayFormat = $format;
574
575 return $this;
576 }
577
583 public function getDisplayFormat() {
585 }
586
603 public static function getClassFromDescriptor( $fieldname, &$descriptor ) {
604 if ( isset( $descriptor['class'] ) ) {
605 $class = $descriptor['class'];
606 } elseif ( isset( $descriptor['type'] ) ) {
607 $class = static::$typeMappings[$descriptor['type']];
608 $descriptor['class'] = $class;
609 } else {
610 $class = null;
611 }
612
613 if ( !$class ) {
614 throw new InvalidArgumentException( "Descriptor with no class for $fieldname: "
615 . print_r( $descriptor, true ) );
616 }
617
618 return $class;
619 }
620
633 public static function loadInputFromParameters( $fieldname, $descriptor,
634 HTMLForm $parent = null
635 ) {
636 $class = static::getClassFromDescriptor( $fieldname, $descriptor );
637
638 $descriptor['fieldname'] = $fieldname;
639 if ( $parent ) {
640 $descriptor['parent'] = $parent;
641 }
642
643 # @todo This will throw a fatal error whenever someone try to use
644 # 'class' to feed a CSS class instead of 'cssclass'. Would be
645 # great to avoid the fatal error and show a nice error.
646 return new $class( $descriptor );
647 }
648
657 public function prepareForm() {
658 # Load data from the request.
659 if (
660 $this->mFormIdentifier === null ||
661 $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier ||
662 ( $this->mSingleForm && $this->getMethod() === 'get' )
663 ) {
664 $this->loadFieldData();
665 } else {
666 $this->mFieldData = [];
667 }
668
669 return $this;
670 }
671
676 public function tryAuthorizedSubmit() {
677 $result = false;
678
679 if ( $this->mFormIdentifier === null ) {
680 $identOkay = true;
681 } else {
682 $identOkay = $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier;
683 }
684
685 $tokenOkay = false;
686 if ( $this->getMethod() !== 'post' ) {
687 $tokenOkay = true; // no session check needed
688 } elseif ( $this->getRequest()->wasPosted() ) {
689 $editToken = $this->getRequest()->getVal( 'wpEditToken' );
690 if ( $this->getUser()->isRegistered() || $editToken !== null ) {
691 // Session tokens for logged-out users have no security value.
692 // However, if the user gave one, check it in order to give a nice
693 // "session expired" error instead of "permission denied" or such.
694 $tokenOkay = $this->getUser()->matchEditToken( $editToken, $this->mTokenSalt );
695 } else {
696 $tokenOkay = true;
697 }
698 }
699
700 if ( $tokenOkay && $identOkay ) {
701 $this->mWasSubmitted = true;
702 $result = $this->trySubmit();
703 }
704
705 return $result;
706 }
707
715 public function show() {
716 $this->prepareForm();
717
718 $result = $this->tryAuthorizedSubmit();
719 if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
720 return $result;
721 }
722
723 $this->displayForm( $result );
724
725 return false;
726 }
727
733 public function showAlways() {
734 $this->prepareForm();
735
736 $result = $this->tryAuthorizedSubmit();
737
738 $this->displayForm( $result );
739
740 return $result;
741 }
742
754 public function trySubmit() {
755 $valid = true;
756 $hoistedErrors = Status::newGood();
757 if ( $this->mValidationErrorMessage ) {
758 foreach ( $this->mValidationErrorMessage as $error ) {
759 $hoistedErrors->fatal( ...$error );
760 }
761 } else {
762 $hoistedErrors->fatal( 'htmlform-invalid-input' );
763 }
764
765 $this->mWasSubmitted = true;
766
767 # Check for cancelled submission
768 foreach ( $this->mFlatFields as $fieldname => $field ) {
769 if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
770 continue;
771 }
772 if ( $field->cancelSubmit( $this->mFieldData[$fieldname], $this->mFieldData ) ) {
773 $this->mWasSubmitted = false;
774 return false;
775 }
776 }
777
778 # Check for validation
779 $hasNonDefault = false;
780 foreach ( $this->mFlatFields as $fieldname => $field ) {
781 if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
782 continue;
783 }
784 $hasNonDefault = $hasNonDefault || $this->mFieldData[$fieldname] !== $field->getDefault();
785 if ( $field->isDisabled( $this->mFieldData ) ) {
786 continue;
787 }
788 $res = $field->validate( $this->mFieldData[$fieldname], $this->mFieldData );
789 if ( $res !== true ) {
790 $valid = false;
791 if ( $res !== false && !$field->canDisplayErrors() ) {
792 if ( is_string( $res ) ) {
793 $hoistedErrors->fatal( 'rawmessage', $res );
794 } else {
795 $hoistedErrors->fatal( $res );
796 }
797 }
798 }
799 }
800
801 if ( !$valid ) {
802 // Treat as not submitted if got nothing from the user on GET forms.
803 if ( !$hasNonDefault && $this->getMethod() === 'get' &&
804 ( $this->mFormIdentifier === null ||
805 $this->getRequest()->getCheck( 'wpFormIdentifier' ) )
806 ) {
807 $this->mWasSubmitted = false;
808 return false;
809 }
810 return $hoistedErrors;
811 }
812
813 $callback = $this->mSubmitCallback;
814 if ( !is_callable( $callback ) ) {
815 throw new LogicException( 'HTMLForm: no submit callback provided. Use ' .
816 'setSubmitCallback() to set one.' );
817 }
818
819 $data = $this->filterDataForSubmit( $this->mFieldData );
820
821 $res = call_user_func( $callback, $data, $this );
822 if ( $res === false ) {
823 $this->mWasSubmitted = false;
824 } elseif ( $res instanceof StatusValue ) {
825 // DWIM - callbacks are not supposed to return a StatusValue but it's easy to mix up.
826 $res = Status::wrap( $res );
827 }
828
829 return $res;
830 }
831
843 public function wasSubmitted() {
845 }
846
857 public function setSubmitCallback( $cb ) {
858 $this->mSubmitCallback = $cb;
859
860 return $this;
861 }
862
872 public function setValidationErrorMessage( $msg ) {
873 $this->mValidationErrorMessage = $msg;
874
875 return $this;
876 }
877
886 public function setIntro( $msg ) {
887 wfDeprecated( __METHOD__, '1.38' );
888 return $this->setPreHtml( $msg );
889 }
890
899 public function setPreHtml( $html ) {
900 $this->mPre = $html;
901
902 return $this;
903 }
904
913 public function addPreHtml( $html ) {
914 $this->mPre .= $html;
915
916 return $this;
917 }
918
925 public function getPreHtml() {
926 return $this->mPre;
927 }
928
937 public function setPreText( $msg ) {
938 wfDeprecated( __METHOD__, '1.38' );
939 return $this->setPreHtml( $msg );
940 }
941
950 public function addPreText( $msg ) {
951 wfDeprecated( __METHOD__, '1.38' );
952 return $this->addPreHtml( $msg );
953 }
954
962 public function getPreText() {
963 wfDeprecated( __METHOD__, '1.38' );
964 return $this->getPreHtml();
965 }
966
976 public function addHeaderHtml( $html, $section = null ) {
977 if ( $section === null ) {
978 $this->mHeader .= $html;
979 } else {
980 $this->mSectionHeaders[$section] ??= '';
981 $this->mSectionHeaders[$section] .= $html;
982 }
983
984 return $this;
985 }
986
996 public function setHeaderHtml( $html, $section = null ) {
997 if ( $section === null ) {
998 $this->mHeader = $html;
999 } else {
1000 $this->mSectionHeaders[$section] = $html;
1001 }
1002
1003 return $this;
1004 }
1005
1014 public function getHeaderHtml( $section = null ) {
1015 return $section ? $this->mSectionHeaders[$section] ?? '' : $this->mHeader;
1016 }
1017
1027 public function addHeaderText( $msg, $section = null ) {
1028 wfDeprecated( __METHOD__, '1.38' );
1029 return $this->addHeaderHtml( $msg, $section );
1030 }
1031
1042 public function setHeaderText( $msg, $section = null ) {
1043 wfDeprecated( __METHOD__, '1.38' );
1044 return $this->setHeaderHtml( $msg, $section );
1045 }
1046
1056 public function getHeaderText( $section = null ) {
1057 wfDeprecated( __METHOD__, '1.38' );
1058 return $this->getHeaderHtml( $section );
1059 }
1060
1070 public function addFooterHtml( $html, $section = null ) {
1071 if ( $section === null ) {
1072 $this->mFooter .= $html;
1073 } else {
1074 $this->mSectionFooters[$section] ??= '';
1075 $this->mSectionFooters[$section] .= $html;
1076 }
1077
1078 return $this;
1079 }
1080
1090 public function setFooterHtml( $html, $section = null ) {
1091 if ( $section === null ) {
1092 $this->mFooter = $html;
1093 } else {
1094 $this->mSectionFooters[$section] = $html;
1095 }
1096
1097 return $this;
1098 }
1099
1107 public function getFooterHtml( $section = null ) {
1108 return $section ? $this->mSectionFooters[$section] ?? '' : $this->mFooter;
1109 }
1110
1120 public function addFooterText( $msg, $section = null ) {
1121 wfDeprecated( __METHOD__, '1.38' );
1122 return $this->addFooterHtml( $msg, $section );
1123 }
1124
1135 public function setFooterText( $msg, $section = null ) {
1136 wfDeprecated( __METHOD__, '1.38' );
1137 return $this->setFooterHtml( $msg, $section );
1138 }
1139
1148 public function getFooterText( $section = null ) {
1149 wfDeprecated( __METHOD__, '1.38' );
1150 return $this->getFooterHtml( $section );
1151 }
1152
1161 public function addPostHtml( $html ) {
1162 $this->mPost .= $html;
1163
1164 return $this;
1165 }
1166
1175 public function setPostHtml( $html ) {
1176 $this->mPost = $html;
1177
1178 return $this;
1179 }
1180
1187 public function getPostHtml() {
1188 return $this->mPost;
1189 }
1190
1199 public function addPostText( $msg ) {
1200 wfDeprecated( __METHOD__, '1.38' );
1201 return $this->addPostHtml( $msg );
1202 }
1203
1212 public function setPostText( $msg ) {
1213 wfDeprecated( __METHOD__, '1.38' );
1214 return $this->setPostHtml( $msg );
1215 }
1216
1226 public function setSections( $sections ) {
1227 if ( $this->getDisplayFormat() !== 'codex' ) {
1228 throw new \InvalidArgumentException(
1229 "Non-Codex HTMLForms do not support additional section information."
1230 );
1231 }
1232
1233 $this->mSections = $sections;
1234
1235 return $this;
1236 }
1237
1248 public function addHiddenField( $name, $value, array $attribs = [] ) {
1249 if ( !is_array( $value ) ) {
1250 // Per WebRequest::getVal: Array values are discarded for security reasons.
1251 $attribs += [ 'name' => $name ];
1252 $this->mHiddenFields[] = [ $value, $attribs ];
1253 }
1254
1255 return $this;
1256 }
1257
1269 public function addHiddenFields( array $fields ) {
1270 foreach ( $fields as $name => $value ) {
1271 if ( is_array( $value ) ) {
1272 // Per WebRequest::getVal: Array values are discarded for security reasons.
1273 continue;
1274 }
1275 $this->mHiddenFields[] = [ $value, [ 'name' => $name ] ];
1276 }
1277
1278 return $this;
1279 }
1280
1304 public function addButton( $data ) {
1305 if ( !is_array( $data ) ) {
1306 $args = func_get_args();
1307 if ( count( $args ) < 2 || count( $args ) > 4 ) {
1308 throw new InvalidArgumentException(
1309 'Incorrect number of arguments for deprecated calling style'
1310 );
1311 }
1312 $data = [
1313 'name' => $args[0],
1314 'value' => $args[1],
1315 'id' => $args[2] ?? null,
1316 'attribs' => $args[3] ?? null,
1317 ];
1318 } else {
1319 if ( !isset( $data['name'] ) ) {
1320 throw new InvalidArgumentException( 'A name is required' );
1321 }
1322 if ( !isset( $data['value'] ) ) {
1323 throw new InvalidArgumentException( 'A value is required' );
1324 }
1325 }
1326 $this->mButtons[] = $data + [
1327 'id' => null,
1328 'attribs' => null,
1329 'flags' => null,
1330 'framed' => true,
1331 ];
1332
1333 return $this;
1334 }
1335
1345 public function setTokenSalt( $salt ) {
1346 $this->mTokenSalt = $salt;
1347
1348 return $this;
1349 }
1350
1365 public function displayForm( $submitResult ) {
1366 $this->getOutput()->addHTML( $this->getHTML( $submitResult ) );
1367 }
1368
1373 private function getHiddenTitle(): string {
1374 if ( $this->hiddenTitleAddedToForm ) {
1375 return '';
1376 }
1377
1378 $html = '';
1379 if ( $this->getMethod() === 'post' ||
1380 $this->getAction() === $this->getConfig()->get( MainConfigNames::Script )
1381 ) {
1382 $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1383 }
1384 $this->hiddenTitleAddedToForm = true;
1385 return $html;
1386 }
1387
1398 public function getHTML( $submitResult ) {
1399 # For good measure (it is the default)
1400 $this->getOutput()->setPreventClickjacking( true );
1401 $this->getOutput()->addModules( 'mediawiki.htmlform' );
1402 $this->getOutput()->addModuleStyles( 'mediawiki.htmlform.styles' );
1403
1404 if ( $this->mCollapsible ) {
1405 // Preload jquery.makeCollapsible for mediawiki.htmlform
1406 $this->getOutput()->addModules( 'jquery.makeCollapsible' );
1407 }
1408
1409 $headerHtml = MWDebug::detectDeprecatedOverride( $this, __CLASS__, 'getHeaderText', '1.38' )
1410 ? $this->getHeaderText()
1411 : $this->getHeaderHtml();
1412 $footerHtml = MWDebug::detectDeprecatedOverride( $this, __CLASS__, 'getFooterText', '1.38' )
1413 ? $this->getFooterText()
1414 : $this->getFooterHtml();
1415 $html = $this->getErrorsOrWarnings( $submitResult, 'error' )
1416 . $this->getErrorsOrWarnings( $submitResult, 'warning' )
1417 . $headerHtml
1418 . $this->getHiddenTitle()
1419 . $this->getBody()
1420 . $this->getHiddenFields()
1421 . $this->getButtons()
1422 . $footerHtml;
1423
1424 return $this->mPre . $this->wrapForm( $html ) . $this->mPost;
1425 }
1426
1434 public function setCollapsibleOptions( $collapsedByDefault = false ) {
1435 $this->mCollapsible = true;
1436 $this->mCollapsed = $collapsedByDefault;
1437 return $this;
1438 }
1439
1445 protected function getFormAttributes() {
1446 # Use multipart/form-data
1447 $encType = $this->mUseMultipart
1448 ? 'multipart/form-data'
1449 : 'application/x-www-form-urlencoded';
1450 # Attributes
1451 $attribs = [
1452 'class' => 'mw-htmlform',
1453 'action' => $this->getAction(),
1454 'method' => $this->getMethod(),
1455 'enctype' => $encType,
1456 ];
1457 if ( $this->mId ) {
1458 $attribs['id'] = $this->mId;
1459 }
1460 if ( is_string( $this->mAutocomplete ) ) {
1461 $attribs['autocomplete'] = $this->mAutocomplete;
1462 }
1463 if ( $this->mName ) {
1464 $attribs['name'] = $this->mName;
1465 }
1466 if ( $this->needsJSForHtml5FormValidation() ) {
1467 $attribs['novalidate'] = true;
1468 }
1469 return $attribs;
1470 }
1471
1479 public function wrapForm( $html ) {
1480 # Include a <fieldset> wrapper for style, if requested.
1481 if ( $this->mWrapperLegend !== false ) {
1482 $legend = is_string( $this->mWrapperLegend ) ? $this->mWrapperLegend : false;
1483 $html = Xml::fieldset( $legend, $html, $this->mWrapperAttributes );
1484 }
1485
1486 return Html::rawElement(
1487 'form',
1488 $this->getFormAttributes(),
1489 $html
1490 );
1491 }
1492
1497 public function getHiddenFields() {
1498 $html = '';
1499
1500 // add the title as a hidden file if it hasn't been added yet and if it is necessary
1501 // added for backward compatibility with the previous version of this public method
1502 $html .= $this->getHiddenTitle();
1503
1504 if ( $this->mFormIdentifier !== null ) {
1505 $html .= Html::hidden(
1506 'wpFormIdentifier',
1507 $this->mFormIdentifier
1508 ) . "\n";
1509 }
1510 if ( $this->getMethod() === 'post' ) {
1511 $html .= Html::hidden(
1512 'wpEditToken',
1513 $this->getUser()->getEditToken( $this->mTokenSalt ),
1514 [ 'id' => 'wpEditToken' ]
1515 ) . "\n";
1516 }
1517
1518 foreach ( $this->mHiddenFields as [ $value, $attribs ] ) {
1519 $html .= Html::hidden( $attribs['name'], $value, $attribs ) . "\n";
1520 }
1521
1522 return $html;
1523 }
1524
1530 public function getButtons() {
1531 $buttons = '';
1532
1533 if ( $this->mShowSubmit ) {
1534 $attribs = [];
1535
1536 if ( isset( $this->mSubmitID ) ) {
1537 $attribs['id'] = $this->mSubmitID;
1538 }
1539
1540 if ( isset( $this->mSubmitName ) ) {
1541 $attribs['name'] = $this->mSubmitName;
1542 }
1543
1544 if ( isset( $this->mSubmitTooltip ) ) {
1545 $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
1546 }
1547
1548 $attribs['class'] = [ 'mw-htmlform-submit' ];
1549
1550 $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
1551 }
1552
1553 if ( $this->mShowCancel ) {
1554 $target = $this->getCancelTargetURL();
1555 $buttons .= Html::element(
1556 'a',
1557 [
1558 'href' => $target,
1559 ],
1560 $this->msg( 'cancel' )->text()
1561 ) . "\n";
1562 }
1563
1564 foreach ( $this->mButtons as $button ) {
1565 $attrs = [
1566 'type' => 'submit',
1567 'name' => $button['name'],
1568 'value' => $button['value']
1569 ];
1570
1571 if ( isset( $button['label-message'] ) ) {
1572 $label = $this->getMessage( $button['label-message'] )->parse();
1573 } elseif ( isset( $button['label'] ) ) {
1574 $label = htmlspecialchars( $button['label'] );
1575 } elseif ( isset( $button['label-raw'] ) ) {
1576 $label = $button['label-raw'];
1577 } else {
1578 $label = htmlspecialchars( $button['value'] );
1579 }
1580
1581 // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset Always set in self::addButton
1582 if ( $button['attribs'] ) {
1583 // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset Always set in self::addButton
1584 $attrs += $button['attribs'];
1585 }
1586
1587 if ( isset( $button['id'] ) ) {
1588 $attrs['id'] = $button['id'];
1589 }
1590
1591 $buttons .= Html::rawElement( 'button', $attrs, $label ) . "\n";
1592 }
1593
1594 if ( !$buttons ) {
1595 return '';
1596 }
1597
1598 return Html::rawElement( 'span',
1599 [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n";
1600 }
1601
1607 public function getBody() {
1608 return $this->displaySection( $this->mFieldTree, $this->mTableId );
1609 }
1610
1620 public function getErrorsOrWarnings( $elements, $elementsType ) {
1621 if ( !in_array( $elementsType, [ 'error', 'warning' ], true ) ) {
1622 throw new DomainException( $elementsType . ' is not a valid type.' );
1623 }
1624 $elementstr = false;
1625 if ( $elements instanceof Status ) {
1626 [ $errorStatus, $warningStatus ] = $elements->splitByErrorType();
1627 $status = $elementsType === 'error' ? $errorStatus : $warningStatus;
1628 if ( $status->isGood() ) {
1629 $elementstr = '';
1630 } else {
1631 $elementstr = $status
1632 ->getMessage()
1633 ->setContext( $this )
1634 ->setInterfaceMessageFlag( true )
1635 ->parse();
1636 }
1637 } elseif ( $elementsType === 'error' ) {
1638 if ( is_array( $elements ) ) {
1639 $elementstr = $this->formatErrors( $elements );
1640 } elseif ( $elements && $elements !== true ) {
1641 $elementstr = (string)$elements;
1642 }
1643 }
1644
1645 if ( !$elementstr ) {
1646 return '';
1647 } elseif ( $elementsType === 'error' ) {
1648 return Html::errorBox( $elementstr );
1649 } else { // $elementsType can only be 'warning'
1650 return Html::warningBox( $elementstr );
1651 }
1652 }
1653
1661 public function formatErrors( $errors ) {
1662 $errorstr = '';
1663
1664 foreach ( $errors as $error ) {
1665 $errorstr .= Html::rawElement(
1666 'li',
1667 [],
1668 $this->getMessage( $error )->parse()
1669 );
1670 }
1671
1672 return Html::rawElement( 'ul', [], $errorstr );
1673 }
1674
1682 public function setSubmitText( $t ) {
1683 $this->mSubmitText = $t;
1684
1685 return $this;
1686 }
1687
1694 public function setSubmitDestructive() {
1695 $this->mSubmitFlags = [ 'destructive', 'primary' ];
1696
1697 return $this;
1698 }
1699
1708 public function setSubmitTextMsg( $msg ) {
1709 if ( !$msg instanceof Message ) {
1710 $msg = $this->msg( $msg );
1711 }
1712 $this->setSubmitText( $msg->text() );
1713
1714 return $this;
1715 }
1716
1721 public function getSubmitText() {
1722 return $this->mSubmitText ?: $this->msg( 'htmlform-submit' )->text();
1723 }
1724
1730 public function setSubmitName( $name ) {
1731 $this->mSubmitName = $name;
1732
1733 return $this;
1734 }
1735
1741 public function setSubmitTooltip( $name ) {
1742 $this->mSubmitTooltip = $name;
1743
1744 return $this;
1745 }
1746
1755 public function setSubmitID( $t ) {
1756 $this->mSubmitID = $t;
1757
1758 return $this;
1759 }
1760
1779 public function setFormIdentifier( string $ident, bool $single = false ) {
1780 $this->mFormIdentifier = $ident;
1781 $this->mSingleForm = $single;
1782
1783 return $this;
1784 }
1785
1796 public function suppressDefaultSubmit( $suppressSubmit = true ) {
1797 $this->mShowSubmit = !$suppressSubmit;
1798
1799 return $this;
1800 }
1801
1808 public function showCancel( $show = true ) {
1809 $this->mShowCancel = $show;
1810 return $this;
1811 }
1812
1819 public function setCancelTarget( $target ) {
1820 if ( $target instanceof PageReference ) {
1821 $target = TitleValue::castPageToLinkTarget( $target );
1822 }
1823
1824 $this->mCancelTarget = $target;
1825 return $this;
1826 }
1827
1832 protected function getCancelTargetURL() {
1833 if ( is_string( $this->mCancelTarget ) ) {
1834 return $this->mCancelTarget;
1835 } else {
1836 // TODO: use a service to get the local URL for a LinkTarget, see T282283
1837 $target = Title::castFromLinkTarget( $this->mCancelTarget ) ?: Title::newMainPage();
1838 return $target->getLocalURL();
1839 }
1840 }
1841
1851 public function setTableId( $id ) {
1852 $this->mTableId = $id;
1853
1854 return $this;
1855 }
1856
1862 public function setId( $id ) {
1863 $this->mId = $id;
1864
1865 return $this;
1866 }
1867
1872 public function setName( $name ) {
1873 $this->mName = $name;
1874
1875 return $this;
1876 }
1877
1889 public function setWrapperLegend( $legend ) {
1890 $this->mWrapperLegend = $legend;
1891
1892 return $this;
1893 }
1894
1902 public function setWrapperAttributes( $attributes ) {
1903 $this->mWrapperAttributes = $attributes;
1904
1905 return $this;
1906 }
1907
1917 public function setWrapperLegendMsg( $msg ) {
1918 if ( !$msg instanceof Message ) {
1919 $msg = $this->msg( $msg );
1920 }
1921 $this->setWrapperLegend( $msg->text() );
1922
1923 return $this;
1924 }
1925
1935 public function setMessagePrefix( $p ) {
1936 $this->mMessagePrefix = $p;
1937
1938 return $this;
1939 }
1940
1948 public function setTitle( $t ) {
1949 // TODO: make mTitle a PageReference when we have a better way to get URLs, see T282283.
1950 $this->mTitle = Title::castFromPageReference( $t );
1951
1952 return $this;
1953 }
1954
1958 public function getTitle() {
1959 return $this->mTitle ?: $this->getContext()->getTitle();
1960 }
1961
1969 public function setMethod( $method = 'post' ) {
1970 $this->mMethod = strtolower( $method );
1971
1972 return $this;
1973 }
1974
1978 public function getMethod() {
1979 return $this->mMethod;
1980 }
1981
1992 protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
1993 return Xml::fieldset( $legend, $section, $attributes ) . "\n";
1994 }
1995
2014 public function displaySection( $fields,
2015 $sectionName = '',
2016 $fieldsetIDPrefix = '',
2017 &$hasUserVisibleFields = false
2018 ) {
2019 if ( $this->mFieldData === null ) {
2020 throw new LogicException( 'HTMLForm::displaySection() called on uninitialized field data. '
2021 . 'You probably called displayForm() without calling prepareForm() first.' );
2022 }
2023
2024 $html = [];
2025 $subsectionHtml = '';
2026 $hasLabel = false;
2027
2028 foreach ( $fields as $key => $value ) {
2029 if ( $value instanceof HTMLFormField ) {
2030 $v = array_key_exists( $key, $this->mFieldData )
2031 ? $this->mFieldData[$key]
2032 : $value->getDefault();
2033
2034 $retval = $this->formatField( $value, $v ?? '' );
2035
2036 // check, if the form field should be added to
2037 // the output.
2038 if ( $value->hasVisibleOutput() ) {
2039 $html[] = $retval;
2040
2041 $labelValue = trim( $value->getLabel() );
2042 if ( $labelValue !== "\u{00A0}" && $labelValue !== '&#160;' && $labelValue !== '' ) {
2043 $hasLabel = true;
2044 }
2045
2046 $hasUserVisibleFields = true;
2047 }
2048 } elseif ( is_array( $value ) ) {
2049 $subsectionHasVisibleFields = false;
2050 $section =
2051 $this->displaySection( $value,
2052 "mw-htmlform-$key",
2053 "$fieldsetIDPrefix$key-",
2054 $subsectionHasVisibleFields );
2055
2056 if ( $subsectionHasVisibleFields === true ) {
2057 // Display the section with various niceties.
2058 $hasUserVisibleFields = true;
2059
2060 $legend = $this->getLegend( $key );
2061
2062 $headerHtml = MWDebug::detectDeprecatedOverride( $this, __CLASS__, 'getHeaderText', '1.38' )
2063 ? $this->getHeaderText( $key )
2064 : $this->getHeaderHtml( $key );
2065 $footerHtml = MWDebug::detectDeprecatedOverride( $this, __CLASS__, 'getFooterText', '1.38' )
2066 ? $this->getFooterText( $key )
2067 : $this->getFooterHtml( $key );
2068 $section = $headerHtml .
2069 $section .
2070 $footerHtml;
2071
2072 $attributes = [];
2073 if ( $fieldsetIDPrefix ) {
2074 $attributes['id'] = Sanitizer::escapeIdForAttribute( "$fieldsetIDPrefix$key" );
2075 }
2076 $subsectionHtml .= $this->wrapFieldSetSection(
2077 $legend, $section, $attributes, $fields === $this->mFieldTree
2078 );
2079 } else {
2080 // Just return the inputs, nothing fancy.
2081 $subsectionHtml .= $section;
2082 }
2083 }
2084 }
2085
2086 $html = $this->formatSection( $html, $sectionName, $hasLabel );
2087
2088 if ( $subsectionHtml ) {
2089 if ( $this->mSubSectionBeforeFields ) {
2090 return $subsectionHtml . "\n" . $html;
2091 } else {
2092 return $html . "\n" . $subsectionHtml;
2093 }
2094 } else {
2095 return $html;
2096 }
2097 }
2098
2107 protected function formatField( HTMLFormField $field, $value ) {
2108 $displayFormat = $this->getDisplayFormat();
2109 switch ( $displayFormat ) {
2110 case 'table':
2111 return $field->getTableRow( $value );
2112 case 'div':
2113 return $field->getDiv( $value );
2114 case 'raw':
2115 return $field->getRaw( $value );
2116 case 'inline':
2117 return $field->getInline( $value );
2118 default:
2119 throw new LogicException( 'Not implemented' );
2120 }
2121 }
2122
2131 protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
2132 if ( !$fieldsHtml ) {
2133 // Do not generate any wrappers for empty sections. Sections may be empty if they only have
2134 // subsections, but no fields. A legend will still be added in wrapFieldSetSection().
2135 return '';
2136 }
2137
2138 $displayFormat = $this->getDisplayFormat();
2139 $html = implode( '', $fieldsHtml );
2140
2141 if ( $displayFormat === 'raw' ) {
2142 return $html;
2143 }
2144
2145 // Avoid strange spacing when no labels exist
2146 $attribs = $anyFieldHasLabel ? [] : [ 'class' => 'mw-htmlform-nolabel' ];
2147
2148 if ( $sectionName ) {
2149 $attribs['id'] = Sanitizer::escapeIdForAttribute( $sectionName );
2150 }
2151
2152 if ( $displayFormat === 'table' ) {
2153 return Html::rawElement( 'table',
2154 $attribs,
2155 Html::rawElement( 'tbody', [], "\n$html\n" ) ) . "\n";
2156 } elseif ( $displayFormat === 'inline' ) {
2157 return Html::rawElement( 'span', $attribs, "\n$html\n" );
2158 } else {
2159 return Html::rawElement( 'div', $attribs, "\n$html\n" );
2160 }
2161 }
2162
2166 public function loadData() {
2167 $this->prepareForm();
2168 }
2169
2173 protected function loadFieldData() {
2174 $fieldData = [];
2175 $request = $this->getRequest();
2176
2177 foreach ( $this->mFlatFields as $fieldname => $field ) {
2178 if ( $field->skipLoadData( $request ) ) {
2179 continue;
2180 }
2181 if ( $field->mParams['disabled'] ?? false ) {
2182 $fieldData[$fieldname] = $field->getDefault();
2183 } else {
2184 $fieldData[$fieldname] = $field->loadDataFromRequest( $request );
2185 }
2186 }
2187
2188 // Reset to default for fields that are supposed to be disabled.
2189 // FIXME: Handle dependency chains, fields that a field checks on may need a reset too.
2190 foreach ( $fieldData as $name => &$value ) {
2191 $field = $this->mFlatFields[$name];
2192 if ( $field->isDisabled( $fieldData ) ) {
2193 $value = $field->getDefault();
2194 }
2195 }
2196
2197 # Filter data.
2198 foreach ( $fieldData as $name => &$value ) {
2199 $field = $this->mFlatFields[$name];
2200 $value = $field->filter( $value, $fieldData );
2201 }
2202
2203 $this->mFieldData = $fieldData;
2204 }
2205
2216 public function filterDataForSubmit( $data ) {
2217 return $data;
2218 }
2219
2229 public function getLegend( $key ) {
2230 return $this->msg( $this->mMessagePrefix ? "{$this->mMessagePrefix}-$key" : $key )->text();
2231 }
2232
2243 public function setAction( $action ) {
2244 $this->mAction = $action;
2245
2246 return $this;
2247 }
2248
2256 public function getAction() {
2257 // If an action is already provided, return it
2258 if ( $this->mAction !== false ) {
2259 return $this->mAction;
2260 }
2261
2262 $articlePath = $this->getConfig()->get( MainConfigNames::ArticlePath );
2263 // Check whether we are in GET mode and the ArticlePath contains a "?"
2264 // meaning that getLocalURL() would return something like "index.php?title=...".
2265 // As browser remove the query string before submitting GET forms,
2266 // it means that the title would be lost. In such case use script path instead
2267 // and put title in a hidden field (see getHiddenFields()).
2268 if ( str_contains( $articlePath, '?' ) && $this->getMethod() === 'get' ) {
2269 return $this->getConfig()->get( MainConfigNames::Script );
2270 }
2271
2272 return $this->getTitle()->getLocalURL();
2273 }
2274
2285 public function setAutocomplete( $autocomplete ) {
2286 $this->mAutocomplete = $autocomplete;
2287
2288 return $this;
2289 }
2290
2297 protected function getMessage( $value ) {
2298 return Message::newFromSpecifier( $value )->setContext( $this );
2299 }
2300
2311 foreach ( $this->mFlatFields as $field ) {
2312 if ( $field->needsJSForHtml5FormValidation() ) {
2313 return true;
2314 }
2315 }
2316 return false;
2317 }
2318}
2319
2321class_alias( HTMLForm::class, 'HTMLForm' );
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:81
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
setContext(IContextSource $context)
Debug toolbar.
Definition MWDebug.php:48
Text field for selecting a value from a large list of possible values, with auto-completion and optio...
A checkbox matrix Operates similarly to HTMLMultiSelectField, but instead of using an array of option...
A field that will contain a date and/or time.
Expiry Field that allows the user to specify a precise date or a relative date string.
A field that will contain a numeric value.
A container for HTMLFormFields that allows for multiple copies of the set of fields to be displayed t...
An information field (text blob), not a proper input.
A field that must contain a number.
Implements a tag multiselect input field for namespaces.
Double field with a dropdown list constructed from a system message in the format.
A limit dropdown, which accepts any valid number.
Creates a Html::namespaceSelector input field with a button assigned to the input field.
Wrapper for Html::namespaceSelector to use in HTMLForm.
Select dropdown field, with an additional "other" textbox.
A size filter field for use on query-type special pages.
Add a submit button inline in the form (as opposed to HTMLForm::addButton(), which will add it at the...
Wrapper for ChangeTags::buildTagFilterSelector to use in HTMLForm.
Implements a tag multiselect input field for arbitrary values.
Creates a text input field with a button assigned to the input field.
Dropdown widget that allows the user to select a timezone, either by choosing a geographic zone,...
Implements a text input field for page titles.
Implements a tag multiselect input field for titles.
Implements a text input field for user names.
Implements a tag multiselect input field for user names.
The parent class to generate form fields.
getDiv( $value)
Get the complete div for the input, including help text, labels, and whatever.
getTableRow( $value)
Get the complete table row for the input, including help text, labels, and whatever.
getRaw( $value)
Get the complete raw fields for the input, including help text, labels, and whatever.
getInline( $value)
Get the complete field as an inline element.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:208
wrapForm( $html)
Wrap the form innards in an actual "<form>" element.
displayForm( $submitResult)
Display the form (sending to the context's OutputPage object), with an appropriate error message or s...
setHeaderHtml( $html, $section=null)
Set header HTML, inside the form.
Definition HTMLForm.php:996
needsJSForHtml5FormValidation()
Whether this form, with its current fields, requires the user agent to have JavaScript enabled for th...
setWrapperLegendMsg( $msg)
Prompt the whole form to be wrapped in a "<fieldset>", with this message as its "<legend>" element.
showCancel( $show=true)
Show a cancel button (or prevent it).
setMessagePrefix( $p)
Set the prefix for various default messages.
addFooterText( $msg, $section=null)
Add footer text, inside the form.
array[] $mSections
Additional information about form sections.
Definition HTMLForm.php:391
wrapFieldSetSection( $legend, $section, $attributes, $isRoot)
Wraps the given $section into a user-visible fieldset.
callable null $mSubmitCallback
Definition HTMLForm.php:280
setPostText( $msg)
Set text at the end of the display.
addHeaderText( $msg, $section=null)
Add HTML to the header, inside the form.
getHeaderHtml( $section=null)
Get header HTML.
bool $mCollapsed
Whether the form is collapsed by default.
Definition HTMLForm.php:346
setFormIdentifier(string $ident, bool $single=false)
Set an internal identifier for this form.
getHeaderText( $section=null)
Get header text.
trySubmit()
Validate all the fields, and call the submission callback function if everything is kosher.
Definition HTMLForm.php:754
array $availableSubclassDisplayFormats
Available formats in which to display the form.
Definition HTMLForm.php:425
setAction( $action)
Set the value for the action attribute of the form.
setPreHtml( $html)
Set the introductory message HTML, overwriting any existing message.
Definition HTMLForm.php:899
setTokenSalt( $salt)
Set the salt for the edit token.
setFooterHtml( $html, $section=null)
Set footer HTML, inside the form.
suppressDefaultSubmit( $suppressSubmit=true)
Stop a default submit button being shown for this form.
setIntro( $msg)
Set the introductory message, overwriting any existing message.
Definition HTMLForm.php:886
loadFieldData()
Load data of form fields from the request.
tryAuthorizedSubmit()
Try submitting, with edit token check first.
Definition HTMLForm.php:676
wasSubmitted()
Test whether the form was considered to have been submitted or not, i.e.
Definition HTMLForm.php:843
getFormAttributes()
Get HTML attributes for the <form> tag.
static getClassFromDescriptor( $fieldname, &$descriptor)
Get the HTMLFormField subclass for this descriptor.
Definition HTMLForm.php:603
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
prepareForm()
Prepare form for submission.
Definition HTMLForm.php:657
LinkTarget string null $mCancelTarget
Definition HTMLForm.php:277
bool $mCollapsible
Whether the form can be collapsed.
Definition HTMLForm.php:339
addHiddenField( $name, $value, array $attribs=[])
Add a hidden field to the output Array values are discarded for security reasons (per WebRequest::get...
setSubmitTextMsg( $msg)
Set the text for the submit button to a message.
setAutocomplete( $autocomplete)
Set the value for the autocomplete attribute of the form.
getBody()
Get the whole body of the form.
bool $mSubSectionBeforeFields
If true, sections that contain both fields and subsections will render their subsections before their...
Definition HTMLForm.php:401
string $displayFormat
Format in which to display form.
Definition HTMLForm.php:408
addPreText( $msg)
Add HTML to introductory message.
Definition HTMLForm.php:950
setWrapperAttributes( $attributes)
For internal use only.
string null $mAutocomplete
Form attribute autocomplete.
Definition HTMLForm.php:353
getDisplayFormat()
Getter for displayFormat.
Definition HTMLForm.php:583
formatSection(array $fieldsHtml, $sectionName, $anyFieldHasLabel)
Put a form section together from the individual fields' HTML, merging it and wrapping.
setDisplayFormat( $format)
Set format in which to display the form.
Definition HTMLForm.php:553
string array $mTokenSalt
Salt for the edit token.
Definition HTMLForm.php:377
getHTML( $submitResult)
Returns the raw HTML generated by the form.
addButton( $data)
Add a button to the form.
getHiddenFields()
Get the hidden fields that should go inside the form.
setTableId( $id)
Set the id of the <table> or outermost <div> element.
setWrapperLegend( $legend)
Prompt the whole form to be wrapped in a "<fieldset>", with this text as its "<legend>" element.
static loadInputFromParameters( $fieldname, $descriptor, HTMLForm $parent=null)
Initialise a new Object for the field.
Definition HTMLForm.php:633
addFooterHtml( $html, $section=null)
Add footer HTML, inside the form.
showAlways()
Same as self::show with the difference, that the form will be added to the output,...
Definition HTMLForm.php:733
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
addFields( $descriptor)
Add fields to the form.
Definition HTMLForm.php:495
setSubmitText( $t)
Set the text for the submit button.
setPostHtml( $html)
Set HTML at the end of the display.
getFooterHtml( $section=null)
Get footer HTML.
setFooterText( $msg, $section=null)
Set footer text, inside the form.
setTitle( $t)
Set the title for form submission.
setSubmitCallback( $cb)
Set a callback to a function to do something with the form once it's been successfully validated.
Definition HTMLForm.php:857
getSubmitText()
Get the text for the submit button, either customised or a default.
addHiddenFields(array $fields)
Add an array of hidden fields to the output Array values are discarded for security reasons (per WebR...
setHeaderText( $msg, $section=null)
Set header text, inside 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:715
formatField(HTMLFormField $field, $value)
Generate the HTML for an individual field in the current display format.
setSections( $sections)
Set an array of information about sections.
formatErrors( $errors)
Format a stack of error messages into a single HTML string.
setValidationErrorMessage( $msg)
Set a message to display on a validation error.
Definition HTMLForm.php:872
HTMLFormField[] $mFlatFields
Definition HTMLForm.php:267
setSubmitDestructive()
Identify that the submit button in the form has a destructive action.
addPostText( $msg)
Add text to the end of the display.
getFooterText( $section=null)
Get footer text.
getErrorsOrWarnings( $elements, $elementsType)
Returns a formatted list of errors or warnings from the given elements.
addPreHtml( $html)
Add HTML to introductory message.
Definition HTMLForm.php:913
setSubmitID( $t)
Set the id for the submit button.
getPreText()
Get the introductory message HTML.
Definition HTMLForm.php:962
array $availableDisplayFormats
Available formats in which to display the form.
Definition HTMLForm.php:414
getPostHtml()
Get HTML at the end of the display.
getLegend( $key)
Get a string to go in the "<legend>" of a section fieldset.
setCancelTarget( $target)
Sets the target where the user is redirected to after clicking cancel.
addHeaderHtml( $html, $section=null)
Add HTML to the header, inside the form.
Definition HTMLForm.php:976
static factory( $displayFormat, $descriptor, IContextSource $context, $messagePrefix='')
Construct a HTMLForm object for given display type.
Definition HTMLForm.php:450
setCollapsibleOptions( $collapsedByDefault=false)
Enable collapsible mode, and set whether the form is collapsed by default.
setPreText( $msg)
Set the introductory message HTML, overwriting any existing message.
Definition HTMLForm.php:937
getAction()
Get the value for the action attribute of the form.
setMethod( $method='post')
Set the method used to submit the form.
getPreHtml()
Get the introductory message HTML.
Definition HTMLForm.php:925
getButtons()
Get the submit and (potentially) reset buttons.
static string[] $typeMappings
A mapping of 'type' inputs onto standard HTMLFormField subclasses.
Definition HTMLForm.php:212
filterDataForSubmit( $data)
Overload this if you want to apply special filtration routines to the form as a whole,...
__construct( $descriptor, IContextSource $context, $messagePrefix='')
Build a new HTMLForm from an array of field attributes.
Definition HTMLForm.php:478
string false $mAction
Form action URL.
Definition HTMLForm.php:332
addPostHtml( $html)
Add HTML to the end of the display.
Compact stacked vertical format for forms, implemented using OOUI widgets.
Compact stacked vertical format for forms.
This class is a collection of static functions that serve two purposes:
Definition Html.php:56
static submitButton( $contents, array $attrs=[], array $modifiers=[])
Returns an HTML input element in a string.
Definition Html.php:163
Some internal bits split of from Skin.php.
Definition Linker.php:63
A class containing constants representing the names of configuration variables.
const ArticlePath
Name constant for the ArticlePath setting, for use with Config::get()
const Script
Name constant for the Script setting, for use with Config::get()
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition Message.php:150
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition Message.php:452
HTML sanitizer for MediaWiki.
Definition Sanitizer.php:46
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:54
Represents the target of a wiki link.
Represents a title within MediaWiki.
Definition Title.php:78
Module of static functions for generating XML.
Definition Xml.php:37
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.
Interface for objects which can provide a MediaWiki context on request.
Represents the target of a wiki link.
Interface for objects (potentially) representing a page that can be viewable and linked to on a wiki.
element(SerializerNode $parent, SerializerNode $node, $contents)