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;
84
209class HTMLForm extends ContextSource {
210 use ProtectedHookAccessorTrait;
211
213 public static $typeMappings = [
214 'api' => HTMLApiField::class,
215 'text' => HTMLTextField::class,
216 'textwithbutton' => HTMLTextFieldWithButton::class,
217 'textarea' => HTMLTextAreaField::class,
218 'select' => HTMLSelectField::class,
219 'combobox' => HTMLComboboxField::class,
220 'radio' => HTMLRadioField::class,
221 'multiselect' => HTMLMultiSelectField::class,
222 'limitselect' => HTMLSelectLimitField::class,
223 'check' => HTMLCheckField::class,
224 'toggle' => HTMLCheckField::class,
225 'int' => HTMLIntField::class,
226 'file' => HTMLFileField::class,
227 'float' => HTMLFloatField::class,
228 'info' => HTMLInfoField::class,
229 'selectorother' => HTMLSelectOrOtherField::class,
230 'selectandother' => HTMLSelectAndOtherField::class,
231 'namespaceselect' => HTMLSelectNamespace::class,
232 'namespaceselectwithbutton' => HTMLSelectNamespaceWithButton::class,
233 'tagfilter' => HTMLTagFilter::class,
234 'sizefilter' => HTMLSizeFilterField::class,
235 'submit' => HTMLSubmitField::class,
236 'hidden' => HTMLHiddenField::class,
237 'edittools' => HTMLEditTools::class,
238 'checkmatrix' => HTMLCheckMatrix::class,
239 'cloner' => HTMLFormFieldCloner::class,
240 'autocompleteselect' => HTMLAutoCompleteSelectField::class,
241 'language' => HTMLSelectLanguageField::class,
242 'date' => HTMLDateTimeField::class,
243 'time' => HTMLDateTimeField::class,
244 'datetime' => HTMLDateTimeField::class,
245 'expiry' => HTMLExpiryField::class,
246 'timezone' => HTMLTimezoneField::class,
247 // HTMLTextField will output the correct type="" attribute automagically.
248 // There are about four zillion other HTML5 input types, like range, but
249 // we don't use those at the moment, so no point in adding all of them.
250 'email' => HTMLTextField::class,
251 'password' => HTMLTextField::class,
252 'url' => HTMLTextField::class,
253 'title' => HTMLTitleTextField::class,
254 'user' => HTMLUserTextField::class,
255 'tagmultiselect' => HTMLTagMultiselectField::class,
256 'usersmultiselect' => HTMLUsersMultiselectField::class,
257 'titlesmultiselect' => HTMLTitlesMultiselectField::class,
258 'namespacesmultiselect' => HTMLNamespacesMultiselectField::class,
259 ];
260
263
266
268 protected $mFlatFields = [];
270 protected $mFieldTree = [];
272 protected $mShowSubmit = true;
274 protected $mSubmitFlags = [ 'primary', 'progressive' ];
276 protected $mShowCancel = false;
278 protected $mCancelTarget;
279
287
289 protected $mPre = '';
291 protected $mHeader = '';
293 protected $mFooter = '';
295 protected $mSectionHeaders = [];
297 protected $mSectionFooters = [];
299 protected $mPost = '';
301 protected $mId;
303 protected $mName;
305 protected $mTableId = '';
306
308 protected $mSubmitID;
310 protected $mSubmitName;
312 protected $mSubmitText;
315
319 protected $mSingleForm = false;
320
322 protected $mTitle;
324 protected $mMethod = 'post';
326 protected $mWasSubmitted = false;
327
333 protected $mAction = false;
334
340 protected $mCollapsible = false;
341
347 protected $mCollapsed = false;
348
354 protected $mAutocomplete = null;
355
357 protected $mUseMultipart = false;
362 protected $mHiddenFields = [];
367 protected $mButtons = [];
368
370 protected $mWrapperLegend = false;
372 protected $mWrapperAttributes = [];
373
378 protected $mTokenSalt = '';
379
392 protected $mSections = [];
393
402 protected $mSubSectionBeforeFields = true;
403
409 protected $displayFormat = 'table';
410
416 'table',
417 'div',
418 'raw',
419 'inline',
420 ];
421
427 'vform',
428 'codex',
429 'ooui',
430 ];
431
436 private $hiddenTitleAddedToForm = false;
437
451 public static function factory(
452 $displayFormat, $descriptor, IContextSource $context, $messagePrefix = ''
453 ) {
454 switch ( $displayFormat ) {
455 case 'codex':
456 return new CodexHTMLForm( $descriptor, $context, $messagePrefix );
457 case 'vform':
458 return new VFormHTMLForm( $descriptor, $context, $messagePrefix );
459 case 'ooui':
460 return new OOUIHTMLForm( $descriptor, $context, $messagePrefix );
461 default:
462 $form = new self( $descriptor, $context, $messagePrefix );
463 $form->setDisplayFormat( $displayFormat );
464 return $form;
465 }
466 }
467
479 public function __construct(
480 $descriptor, IContextSource $context, $messagePrefix = ''
481 ) {
482 $this->setContext( $context );
483 $this->mMessagePrefix = $messagePrefix;
484 $this->addFields( $descriptor );
485 }
486
496 public function addFields( $descriptor ) {
497 $loadedDescriptor = [];
498
499 foreach ( $descriptor as $fieldname => $info ) {
500 $section = $info['section'] ?? '';
501
502 if ( isset( $info['type'] ) && $info['type'] === 'file' ) {
503 $this->mUseMultipart = true;
504 }
505
506 $field = static::loadInputFromParameters( $fieldname, $info, $this );
507
508 $setSection =& $loadedDescriptor;
509 if ( $section ) {
510 foreach ( explode( '/', $section ) as $newName ) {
511 $setSection[$newName] ??= [];
512 $setSection =& $setSection[$newName];
513 }
514 }
515
516 $setSection[$fieldname] = $field;
517 $this->mFlatFields[$fieldname] = $field;
518 }
519
520 $this->mFieldTree = array_merge_recursive( $this->mFieldTree, $loadedDescriptor );
521
522 return $this;
523 }
524
529 public function hasField( $fieldname ) {
530 return isset( $this->mFlatFields[$fieldname] );
531 }
532
538 public function getField( $fieldname ) {
539 if ( !$this->hasField( $fieldname ) ) {
540 throw new DomainException( __METHOD__ . ': no field named ' . $fieldname );
541 }
542 return $this->mFlatFields[$fieldname];
543 }
544
554 public function setDisplayFormat( $format ) {
555 if (
556 in_array( $format, $this->availableSubclassDisplayFormats, true ) ||
557 in_array( $this->displayFormat, $this->availableSubclassDisplayFormats, true )
558 ) {
559 throw new LogicException( 'Cannot change display format after creation, ' .
560 'use HTMLForm::factory() instead' );
561 }
562
563 if ( !in_array( $format, $this->availableDisplayFormats, true ) ) {
564 throw new InvalidArgumentException( 'Display format must be one of ' .
565 print_r(
566 array_merge(
567 $this->availableDisplayFormats,
568 $this->availableSubclassDisplayFormats
569 ),
570 true
571 ) );
572 }
573
574 $this->displayFormat = $format;
575
576 return $this;
577 }
578
584 public function getDisplayFormat() {
586 }
587
604 public static function getClassFromDescriptor( $fieldname, &$descriptor ) {
605 if ( isset( $descriptor['class'] ) ) {
606 $class = $descriptor['class'];
607 } elseif ( isset( $descriptor['type'] ) ) {
608 $class = static::$typeMappings[$descriptor['type']];
609 $descriptor['class'] = $class;
610 } else {
611 $class = null;
612 }
613
614 if ( !$class ) {
615 throw new InvalidArgumentException( "Descriptor with no class for $fieldname: "
616 . print_r( $descriptor, true ) );
617 }
618
619 return $class;
620 }
621
634 public static function loadInputFromParameters( $fieldname, $descriptor,
635 ?HTMLForm $parent = null
636 ) {
637 $class = static::getClassFromDescriptor( $fieldname, $descriptor );
638
639 $descriptor['fieldname'] = $fieldname;
640 if ( $parent ) {
641 $descriptor['parent'] = $parent;
642 }
643
644 # @todo This will throw a fatal error whenever someone try to use
645 # 'class' to feed a CSS class instead of 'cssclass'. Would be
646 # great to avoid the fatal error and show a nice error.
647 return new $class( $descriptor );
648 }
649
658 public function prepareForm() {
659 # Load data from the request.
660 if (
661 $this->mFormIdentifier === null ||
662 $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier ||
663 ( $this->mSingleForm && $this->getMethod() === 'get' )
664 ) {
665 $this->loadFieldData();
666 } else {
667 $this->mFieldData = [];
668 }
669
670 return $this;
671 }
672
677 public function tryAuthorizedSubmit() {
678 $result = false;
679
680 if ( $this->mFormIdentifier === null ) {
681 $identOkay = true;
682 } else {
683 $identOkay = $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier;
684 }
685
686 $tokenOkay = false;
687 if ( $this->getMethod() !== 'post' ) {
688 $tokenOkay = true; // no session check needed
689 } elseif ( $this->getRequest()->wasPosted() ) {
690 $editToken = $this->getRequest()->getVal( 'wpEditToken' );
691 if ( $this->getUser()->isRegistered() || $editToken !== null ) {
692 // Session tokens for logged-out users have no security value.
693 // However, if the user gave one, check it in order to give a nice
694 // "session expired" error instead of "permission denied" or such.
695 $tokenOkay = $this->getUser()->matchEditToken( $editToken, $this->mTokenSalt );
696 } else {
697 $tokenOkay = true;
698 }
699 }
700
701 if ( $tokenOkay && $identOkay ) {
702 $this->mWasSubmitted = true;
703 $result = $this->trySubmit();
704 }
705
706 return $result;
707 }
708
716 public function show() {
717 $this->prepareForm();
718
719 $result = $this->tryAuthorizedSubmit();
720 if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
721 return $result;
722 }
723
724 $this->displayForm( $result );
725
726 return false;
727 }
728
734 public function showAlways() {
735 $this->prepareForm();
736
737 $result = $this->tryAuthorizedSubmit();
738
739 $this->displayForm( $result );
740
741 return $result;
742 }
743
755 public function trySubmit() {
756 $valid = true;
757 $hoistedErrors = Status::newGood();
758 if ( $this->mValidationErrorMessage ) {
759 foreach ( $this->mValidationErrorMessage as $error ) {
760 $hoistedErrors->fatal( ...$error );
761 }
762 } else {
763 $hoistedErrors->fatal( 'htmlform-invalid-input' );
764 }
765
766 $this->mWasSubmitted = true;
767
768 # Check for cancelled submission
769 foreach ( $this->mFlatFields as $fieldname => $field ) {
770 if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
771 continue;
772 }
773 if ( $field->cancelSubmit( $this->mFieldData[$fieldname], $this->mFieldData ) ) {
774 $this->mWasSubmitted = false;
775 return false;
776 }
777 }
778
779 # Check for validation
780 $hasNonDefault = false;
781 foreach ( $this->mFlatFields as $fieldname => $field ) {
782 if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
783 continue;
784 }
785 $hasNonDefault = $hasNonDefault || $this->mFieldData[$fieldname] !== $field->getDefault();
786 if ( $field->isDisabled( $this->mFieldData ) ) {
787 continue;
788 }
789 $res = $field->validate( $this->mFieldData[$fieldname], $this->mFieldData );
790 if ( $res !== true ) {
791 $valid = false;
792 if ( $res !== false && !$field->canDisplayErrors() ) {
793 if ( is_string( $res ) ) {
794 $hoistedErrors->fatal( 'rawmessage', $res );
795 } else {
796 $hoistedErrors->fatal( $res );
797 }
798 }
799 }
800 }
801
802 if ( !$valid ) {
803 // Treat as not submitted if got nothing from the user on GET forms.
804 if ( !$hasNonDefault && $this->getMethod() === 'get' &&
805 ( $this->mFormIdentifier === null ||
806 $this->getRequest()->getCheck( 'wpFormIdentifier' ) )
807 ) {
808 $this->mWasSubmitted = false;
809 return false;
810 }
811 return $hoistedErrors;
812 }
813
814 $callback = $this->mSubmitCallback;
815 if ( !is_callable( $callback ) ) {
816 throw new LogicException( 'HTMLForm: no submit callback provided. Use ' .
817 'setSubmitCallback() to set one.' );
818 }
819
820 $data = $this->filterDataForSubmit( $this->mFieldData );
821
822 $res = call_user_func( $callback, $data, $this );
823 if ( $res === false ) {
824 $this->mWasSubmitted = false;
825 } elseif ( $res instanceof StatusValue ) {
826 // DWIM - callbacks are not supposed to return a StatusValue but it's easy to mix up.
827 $res = Status::wrap( $res );
828 }
829
830 return $res;
831 }
832
844 public function wasSubmitted() {
846 }
847
858 public function setSubmitCallback( $cb ) {
859 $this->mSubmitCallback = $cb;
860
861 return $this;
862 }
863
873 public function setValidationErrorMessage( $msg ) {
874 $this->mValidationErrorMessage = $msg;
875
876 return $this;
877 }
878
887 public function setIntro( $msg ) {
888 wfDeprecated( __METHOD__, '1.38' );
889 return $this->setPreHtml( $msg );
890 }
891
900 public function setPreHtml( $html ) {
901 $this->mPre = $html;
902
903 return $this;
904 }
905
914 public function addPreHtml( $html ) {
915 $this->mPre .= $html;
916
917 return $this;
918 }
919
926 public function getPreHtml() {
927 return $this->mPre;
928 }
929
938 public function setPreText( $msg ) {
939 wfDeprecated( __METHOD__, '1.38' );
940 return $this->setPreHtml( $msg );
941 }
942
951 public function addPreText( $msg ) {
952 wfDeprecated( __METHOD__, '1.38' );
953 return $this->addPreHtml( $msg );
954 }
955
963 public function getPreText() {
964 wfDeprecated( __METHOD__, '1.38' );
965 return $this->getPreHtml();
966 }
967
977 public function addHeaderHtml( $html, $section = null ) {
978 if ( $section === null ) {
979 $this->mHeader .= $html;
980 } else {
981 $this->mSectionHeaders[$section] ??= '';
982 $this->mSectionHeaders[$section] .= $html;
983 }
984
985 return $this;
986 }
987
997 public function setHeaderHtml( $html, $section = null ) {
998 if ( $section === null ) {
999 $this->mHeader = $html;
1000 } else {
1001 $this->mSectionHeaders[$section] = $html;
1002 }
1003
1004 return $this;
1005 }
1006
1015 public function getHeaderHtml( $section = null ) {
1016 return $section ? $this->mSectionHeaders[$section] ?? '' : $this->mHeader;
1017 }
1018
1028 public function addHeaderText( $msg, $section = null ) {
1029 wfDeprecated( __METHOD__, '1.38' );
1030 return $this->addHeaderHtml( $msg, $section );
1031 }
1032
1043 public function setHeaderText( $msg, $section = null ) {
1044 wfDeprecated( __METHOD__, '1.38' );
1045 return $this->setHeaderHtml( $msg, $section );
1046 }
1047
1057 public function getHeaderText( $section = null ) {
1058 wfDeprecated( __METHOD__, '1.38' );
1059 return $this->getHeaderHtml( $section );
1060 }
1061
1071 public function addFooterHtml( $html, $section = null ) {
1072 if ( $section === null ) {
1073 $this->mFooter .= $html;
1074 } else {
1075 $this->mSectionFooters[$section] ??= '';
1076 $this->mSectionFooters[$section] .= $html;
1077 }
1078
1079 return $this;
1080 }
1081
1091 public function setFooterHtml( $html, $section = null ) {
1092 if ( $section === null ) {
1093 $this->mFooter = $html;
1094 } else {
1095 $this->mSectionFooters[$section] = $html;
1096 }
1097
1098 return $this;
1099 }
1100
1108 public function getFooterHtml( $section = null ) {
1109 return $section ? $this->mSectionFooters[$section] ?? '' : $this->mFooter;
1110 }
1111
1121 public function addFooterText( $msg, $section = null ) {
1122 wfDeprecated( __METHOD__, '1.38' );
1123 return $this->addFooterHtml( $msg, $section );
1124 }
1125
1136 public function setFooterText( $msg, $section = null ) {
1137 wfDeprecated( __METHOD__, '1.38' );
1138 return $this->setFooterHtml( $msg, $section );
1139 }
1140
1149 public function getFooterText( $section = null ) {
1150 wfDeprecated( __METHOD__, '1.38' );
1151 return $this->getFooterHtml( $section );
1152 }
1153
1162 public function addPostHtml( $html ) {
1163 $this->mPost .= $html;
1164
1165 return $this;
1166 }
1167
1176 public function setPostHtml( $html ) {
1177 $this->mPost = $html;
1178
1179 return $this;
1180 }
1181
1188 public function getPostHtml() {
1189 return $this->mPost;
1190 }
1191
1200 public function addPostText( $msg ) {
1201 wfDeprecated( __METHOD__, '1.38' );
1202 return $this->addPostHtml( $msg );
1203 }
1204
1213 public function setPostText( $msg ) {
1214 wfDeprecated( __METHOD__, '1.38' );
1215 return $this->setPostHtml( $msg );
1216 }
1217
1227 public function setSections( $sections ) {
1228 if ( $this->getDisplayFormat() !== 'codex' ) {
1229 throw new \InvalidArgumentException(
1230 "Non-Codex HTMLForms do not support additional section information."
1231 );
1232 }
1233
1234 $this->mSections = $sections;
1235
1236 return $this;
1237 }
1238
1249 public function addHiddenField( $name, $value, array $attribs = [] ) {
1250 if ( !is_array( $value ) ) {
1251 // Per WebRequest::getVal: Array values are discarded for security reasons.
1252 $attribs += [ 'name' => $name ];
1253 $this->mHiddenFields[] = [ $value, $attribs ];
1254 }
1255
1256 return $this;
1257 }
1258
1270 public function addHiddenFields( array $fields ) {
1271 foreach ( $fields as $name => $value ) {
1272 if ( is_array( $value ) ) {
1273 // Per WebRequest::getVal: Array values are discarded for security reasons.
1274 continue;
1275 }
1276 $this->mHiddenFields[] = [ $value, [ 'name' => $name ] ];
1277 }
1278
1279 return $this;
1280 }
1281
1305 public function addButton( $data ) {
1306 if ( !is_array( $data ) ) {
1307 $args = func_get_args();
1308 if ( count( $args ) < 2 || count( $args ) > 4 ) {
1309 throw new InvalidArgumentException(
1310 'Incorrect number of arguments for deprecated calling style'
1311 );
1312 }
1313 $data = [
1314 'name' => $args[0],
1315 'value' => $args[1],
1316 'id' => $args[2] ?? null,
1317 'attribs' => $args[3] ?? null,
1318 ];
1319 } else {
1320 if ( !isset( $data['name'] ) ) {
1321 throw new InvalidArgumentException( 'A name is required' );
1322 }
1323 if ( !isset( $data['value'] ) ) {
1324 throw new InvalidArgumentException( 'A value is required' );
1325 }
1326 }
1327 $this->mButtons[] = $data + [
1328 'id' => null,
1329 'attribs' => null,
1330 'flags' => null,
1331 'framed' => true,
1332 ];
1333
1334 return $this;
1335 }
1336
1346 public function setTokenSalt( $salt ) {
1347 $this->mTokenSalt = $salt;
1348
1349 return $this;
1350 }
1351
1366 public function displayForm( $submitResult ) {
1367 $this->getOutput()->addHTML( $this->getHTML( $submitResult ) );
1368 }
1369
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()->getMetadata()->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 ( $this->mSubmitID !== null ) {
1537 $attribs['id'] = $this->mSubmitID;
1538 }
1539
1540 if ( $this->mSubmitName !== null ) {
1541 $attribs['name'] = $this->mSubmitName;
1542 }
1543
1544 if ( $this->mSubmitTooltip !== null ) {
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:49
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:209
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:997
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:392
wrapFieldSetSection( $legend, $section, $attributes, $isRoot)
Wraps the given $section into a user-visible fieldset.
callable null $mSubmitCallback
Definition HTMLForm.php:281
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:347
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:755
array $availableSubclassDisplayFormats
Available formats in which to display the form.
Definition HTMLForm.php:426
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:900
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:887
loadFieldData()
Load data of form fields from the request.
tryAuthorizedSubmit()
Try submitting, with edit token check first.
Definition HTMLForm.php:677
wasSubmitted()
Test whether the form was considered to have been submitted or not, i.e.
Definition HTMLForm.php:844
getFormAttributes()
Get HTML attributes for the <form> tag.
static getClassFromDescriptor( $fieldname, &$descriptor)
Get the HTMLFormField subclass for this descriptor.
Definition HTMLForm.php:604
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
prepareForm()
Prepare form for submission.
Definition HTMLForm.php:658
LinkTarget string null $mCancelTarget
Definition HTMLForm.php:278
bool $mCollapsible
Whether the form can be collapsed.
Definition HTMLForm.php:340
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:402
string $displayFormat
Format in which to display form.
Definition HTMLForm.php:409
addPreText( $msg)
Add HTML to introductory message.
Definition HTMLForm.php:951
setWrapperAttributes( $attributes)
For internal use only.
string null $mAutocomplete
Form attribute autocomplete.
Definition HTMLForm.php:354
getDisplayFormat()
Getter for displayFormat.
Definition HTMLForm.php:584
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:554
string array $mTokenSalt
Salt for the edit token.
Definition HTMLForm.php:378
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.
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:734
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
addFields( $descriptor)
Add fields to the form.
Definition HTMLForm.php:496
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:858
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:716
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:873
HTMLFormField[] $mFlatFields
Definition HTMLForm.php:268
setSubmitDestructive()
Identify that the submit button in the form has a destructive action.
addPostText( $msg)
Add text to the end of the display.
static loadInputFromParameters( $fieldname, $descriptor, ?HTMLForm $parent=null)
Initialise a new Object for the field.
Definition HTMLForm.php:634
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:914
setSubmitID( $t)
Set the id for the submit button.
getPreText()
Get the introductory message HTML.
Definition HTMLForm.php:963
array $availableDisplayFormats
Available formats in which to display the form.
Definition HTMLForm.php:415
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:977
static factory( $displayFormat, $descriptor, IContextSource $context, $messagePrefix='')
Construct a HTMLForm object for given display type.
Definition HTMLForm.php:451
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:938
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:926
getButtons()
Get the submit and (potentially) reset buttons.
static string[] $typeMappings
A mapping of 'type' inputs onto standard HTMLFormField subclasses.
Definition HTMLForm.php:213
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:479
string false $mAction
Form action URL.
Definition HTMLForm.php:333
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:155
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition Message.php:470
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.
Value object representing a message parameter that consists of a list of values.
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)