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;
81use StatusValue;
82use 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
261
263
265 protected $mFlatFields = [];
266 protected $mFieldTree = [];
267 protected $mShowSubmit = true;
269 protected $mSubmitFlags = [ 'primary', 'progressive' ];
270 protected $mShowCancel = false;
271 protected $mCancelTarget;
272
279
280 protected $mPre = '';
281 protected $mHeader = '';
282 protected $mFooter = '';
283 protected $mSectionHeaders = [];
284 protected $mSectionFooters = [];
285 protected $mPost = '';
286 protected $mId;
287 protected $mName;
288 protected $mTableId = '';
289
290 protected $mSubmitID;
291 protected $mSubmitName;
292 protected $mSubmitText;
294
296 protected $mSingleForm = false;
297
299 protected $mTitle;
300 protected $mMethod = 'post';
301 protected $mWasSubmitted = false;
302
308 protected $mAction = false;
309
315 protected $mCollapsible = false;
316
322 protected $mCollapsed = false;
323
329 protected $mAutocomplete = null;
330
331 protected $mUseMultipart = false;
336 protected $mHiddenFields = [];
341 protected $mButtons = [];
342
343 protected $mWrapperLegend = false;
344 protected $mWrapperAttributes = [];
345
350 protected $mTokenSalt = '';
351
364 protected $mSections = [];
365
374 protected $mSubSectionBeforeFields = true;
375
381 protected $displayFormat = 'table';
382
388 'table',
389 'div',
390 'raw',
391 'inline',
392 ];
393
399 'vform',
400 'codex',
401 'ooui',
402 ];
403
408 private $hiddenTitleAddedToForm = false;
409
423 public static function factory(
424 $displayFormat, $descriptor, IContextSource $context, $messagePrefix = ''
425 ) {
426 switch ( $displayFormat ) {
427 case 'codex':
428 return new CodexHTMLForm( $descriptor, $context, $messagePrefix );
429 case 'vform':
430 return new VFormHTMLForm( $descriptor, $context, $messagePrefix );
431 case 'ooui':
432 return new OOUIHTMLForm( $descriptor, $context, $messagePrefix );
433 default:
434 $form = new self( $descriptor, $context, $messagePrefix );
435 $form->setDisplayFormat( $displayFormat );
436 return $form;
437 }
438 }
439
451 public function __construct(
452 $descriptor, IContextSource $context, $messagePrefix = ''
453 ) {
454 $this->setContext( $context );
455 $this->mMessagePrefix = $messagePrefix;
456 $this->addFields( $descriptor );
457 }
458
468 public function addFields( $descriptor ) {
469 $loadedDescriptor = [];
470
471 foreach ( $descriptor as $fieldname => $info ) {
472 $section = $info['section'] ?? '';
473
474 if ( isset( $info['type'] ) && $info['type'] === 'file' ) {
475 $this->mUseMultipart = true;
476 }
477
478 $field = static::loadInputFromParameters( $fieldname, $info, $this );
479
480 $setSection =& $loadedDescriptor;
481 if ( $section ) {
482 foreach ( explode( '/', $section ) as $newName ) {
483 $setSection[$newName] ??= [];
484 $setSection =& $setSection[$newName];
485 }
486 }
487
488 $setSection[$fieldname] = $field;
489 $this->mFlatFields[$fieldname] = $field;
490 }
491
492 $this->mFieldTree = array_merge_recursive( $this->mFieldTree, $loadedDescriptor );
493
494 return $this;
495 }
496
501 public function hasField( $fieldname ) {
502 return isset( $this->mFlatFields[$fieldname] );
503 }
504
510 public function getField( $fieldname ) {
511 if ( !$this->hasField( $fieldname ) ) {
512 throw new DomainException( __METHOD__ . ': no field named ' . $fieldname );
513 }
514 return $this->mFlatFields[$fieldname];
515 }
516
526 public function setDisplayFormat( $format ) {
527 if (
528 in_array( $format, $this->availableSubclassDisplayFormats, true ) ||
529 in_array( $this->displayFormat, $this->availableSubclassDisplayFormats, true )
530 ) {
531 throw new LogicException( 'Cannot change display format after creation, ' .
532 'use HTMLForm::factory() instead' );
533 }
534
535 if ( !in_array( $format, $this->availableDisplayFormats, true ) ) {
536 throw new InvalidArgumentException( 'Display format must be one of ' .
537 print_r(
538 array_merge(
539 $this->availableDisplayFormats,
540 $this->availableSubclassDisplayFormats
541 ),
542 true
543 ) );
544 }
545
546 $this->displayFormat = $format;
547
548 return $this;
549 }
550
556 public function getDisplayFormat() {
558 }
559
576 public static function getClassFromDescriptor( $fieldname, &$descriptor ) {
577 if ( isset( $descriptor['class'] ) ) {
578 $class = $descriptor['class'];
579 } elseif ( isset( $descriptor['type'] ) ) {
580 $class = static::$typeMappings[$descriptor['type']];
581 $descriptor['class'] = $class;
582 } else {
583 $class = null;
584 }
585
586 if ( !$class ) {
587 throw new InvalidArgumentException( "Descriptor with no class for $fieldname: "
588 . print_r( $descriptor, true ) );
589 }
590
591 return $class;
592 }
593
606 public static function loadInputFromParameters( $fieldname, $descriptor,
607 HTMLForm $parent = null
608 ) {
609 $class = static::getClassFromDescriptor( $fieldname, $descriptor );
610
611 $descriptor['fieldname'] = $fieldname;
612 if ( $parent ) {
613 $descriptor['parent'] = $parent;
614 }
615
616 # @todo This will throw a fatal error whenever someone try to use
617 # 'class' to feed a CSS class instead of 'cssclass'. Would be
618 # great to avoid the fatal error and show a nice error.
619 return new $class( $descriptor );
620 }
621
630 public function prepareForm() {
631 # Load data from the request.
632 if (
633 $this->mFormIdentifier === null ||
634 $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier ||
635 ( $this->mSingleForm && $this->getMethod() === 'get' )
636 ) {
637 $this->loadFieldData();
638 } else {
639 $this->mFieldData = [];
640 }
641
642 return $this;
643 }
644
649 public function tryAuthorizedSubmit() {
650 $result = false;
651
652 if ( $this->mFormIdentifier === null ) {
653 $identOkay = true;
654 } else {
655 $identOkay = $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier;
656 }
657
658 $tokenOkay = false;
659 if ( $this->getMethod() !== 'post' ) {
660 $tokenOkay = true; // no session check needed
661 } elseif ( $this->getRequest()->wasPosted() ) {
662 $editToken = $this->getRequest()->getVal( 'wpEditToken' );
663 if ( $this->getUser()->isRegistered() || $editToken !== null ) {
664 // Session tokens for logged-out users have no security value.
665 // However, if the user gave one, check it in order to give a nice
666 // "session expired" error instead of "permission denied" or such.
667 $tokenOkay = $this->getUser()->matchEditToken( $editToken, $this->mTokenSalt );
668 } else {
669 $tokenOkay = true;
670 }
671 }
672
673 if ( $tokenOkay && $identOkay ) {
674 $this->mWasSubmitted = true;
675 $result = $this->trySubmit();
676 }
677
678 return $result;
679 }
680
688 public function show() {
689 $this->prepareForm();
690
691 $result = $this->tryAuthorizedSubmit();
692 if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
693 return $result;
694 }
695
696 $this->displayForm( $result );
697
698 return false;
699 }
700
706 public function showAlways() {
707 $this->prepareForm();
708
709 $result = $this->tryAuthorizedSubmit();
710
711 $this->displayForm( $result );
712
713 return $result;
714 }
715
727 public function trySubmit() {
728 $valid = true;
729 $hoistedErrors = Status::newGood();
730 if ( $this->mValidationErrorMessage ) {
731 foreach ( $this->mValidationErrorMessage as $error ) {
732 $hoistedErrors->fatal( ...$error );
733 }
734 } else {
735 $hoistedErrors->fatal( 'htmlform-invalid-input' );
736 }
737
738 $this->mWasSubmitted = true;
739
740 # Check for cancelled submission
741 foreach ( $this->mFlatFields as $fieldname => $field ) {
742 if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
743 continue;
744 }
745 if ( $field->cancelSubmit( $this->mFieldData[$fieldname], $this->mFieldData ) ) {
746 $this->mWasSubmitted = false;
747 return false;
748 }
749 }
750
751 # Check for validation
752 $hasNonDefault = false;
753 foreach ( $this->mFlatFields as $fieldname => $field ) {
754 if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
755 continue;
756 }
757 $hasNonDefault = $hasNonDefault || $this->mFieldData[$fieldname] !== $field->getDefault();
758 if ( $field->isDisabled( $this->mFieldData ) ) {
759 continue;
760 }
761 $res = $field->validate( $this->mFieldData[$fieldname], $this->mFieldData );
762 if ( $res !== true ) {
763 $valid = false;
764 if ( $res !== false && !$field->canDisplayErrors() ) {
765 if ( is_string( $res ) ) {
766 $hoistedErrors->fatal( 'rawmessage', $res );
767 } else {
768 $hoistedErrors->fatal( $res );
769 }
770 }
771 }
772 }
773
774 if ( !$valid ) {
775 // Treat as not submitted if got nothing from the user on GET forms.
776 if ( !$hasNonDefault && $this->getMethod() === 'get' &&
777 ( $this->mFormIdentifier === null ||
778 $this->getRequest()->getCheck( 'wpFormIdentifier' ) )
779 ) {
780 $this->mWasSubmitted = false;
781 return false;
782 }
783 return $hoistedErrors;
784 }
785
786 $callback = $this->mSubmitCallback;
787 if ( !is_callable( $callback ) ) {
788 throw new LogicException( 'HTMLForm: no submit callback provided. Use ' .
789 'setSubmitCallback() to set one.' );
790 }
791
792 $data = $this->filterDataForSubmit( $this->mFieldData );
793
794 $res = call_user_func( $callback, $data, $this );
795 if ( $res === false ) {
796 $this->mWasSubmitted = false;
797 } elseif ( $res instanceof StatusValue ) {
798 // DWIM - callbacks are not supposed to return a StatusValue but it's easy to mix up.
799 $res = Status::wrap( $res );
800 }
801
802 return $res;
803 }
804
816 public function wasSubmitted() {
818 }
819
830 public function setSubmitCallback( $cb ) {
831 $this->mSubmitCallback = $cb;
832
833 return $this;
834 }
835
845 public function setValidationErrorMessage( $msg ) {
846 $this->mValidationErrorMessage = $msg;
847
848 return $this;
849 }
850
859 public function setIntro( $msg ) {
860 wfDeprecated( __METHOD__, '1.38' );
861 return $this->setPreHtml( $msg );
862 }
863
872 public function setPreHtml( $html ) {
873 $this->mPre = $html;
874
875 return $this;
876 }
877
886 public function addPreHtml( $html ) {
887 $this->mPre .= $html;
888
889 return $this;
890 }
891
898 public function getPreHtml() {
899 return $this->mPre;
900 }
901
910 public function setPreText( $msg ) {
911 wfDeprecated( __METHOD__, '1.38' );
912 return $this->setPreHtml( $msg );
913 }
914
923 public function addPreText( $msg ) {
924 wfDeprecated( __METHOD__, '1.38' );
925 return $this->addPreHtml( $msg );
926 }
927
935 public function getPreText() {
936 wfDeprecated( __METHOD__, '1.38' );
937 return $this->getPreHtml();
938 }
939
949 public function addHeaderHtml( $html, $section = null ) {
950 if ( $section === null ) {
951 $this->mHeader .= $html;
952 } else {
953 $this->mSectionHeaders[$section] ??= '';
954 $this->mSectionHeaders[$section] .= $html;
955 }
956
957 return $this;
958 }
959
969 public function setHeaderHtml( $html, $section = null ) {
970 if ( $section === null ) {
971 $this->mHeader = $html;
972 } else {
973 $this->mSectionHeaders[$section] = $html;
974 }
975
976 return $this;
977 }
978
987 public function getHeaderHtml( $section = null ) {
988 return $section ? $this->mSectionHeaders[$section] ?? '' : $this->mHeader;
989 }
990
1000 public function addHeaderText( $msg, $section = null ) {
1001 wfDeprecated( __METHOD__, '1.38' );
1002 return $this->addHeaderHtml( $msg, $section );
1003 }
1004
1015 public function setHeaderText( $msg, $section = null ) {
1016 wfDeprecated( __METHOD__, '1.38' );
1017 return $this->setHeaderHtml( $msg, $section );
1018 }
1019
1029 public function getHeaderText( $section = null ) {
1030 wfDeprecated( __METHOD__, '1.38' );
1031 return $this->getHeaderHtml( $section );
1032 }
1033
1043 public function addFooterHtml( $html, $section = null ) {
1044 if ( $section === null ) {
1045 $this->mFooter .= $html;
1046 } else {
1047 $this->mSectionFooters[$section] ??= '';
1048 $this->mSectionFooters[$section] .= $html;
1049 }
1050
1051 return $this;
1052 }
1053
1063 public function setFooterHtml( $html, $section = null ) {
1064 if ( $section === null ) {
1065 $this->mFooter = $html;
1066 } else {
1067 $this->mSectionFooters[$section] = $html;
1068 }
1069
1070 return $this;
1071 }
1072
1080 public function getFooterHtml( $section = null ) {
1081 return $section ? $this->mSectionFooters[$section] ?? '' : $this->mFooter;
1082 }
1083
1093 public function addFooterText( $msg, $section = null ) {
1094 wfDeprecated( __METHOD__, '1.38' );
1095 return $this->addFooterHtml( $msg, $section );
1096 }
1097
1108 public function setFooterText( $msg, $section = null ) {
1109 wfDeprecated( __METHOD__, '1.38' );
1110 return $this->setFooterHtml( $msg, $section );
1111 }
1112
1121 public function getFooterText( $section = null ) {
1122 wfDeprecated( __METHOD__, '1.38' );
1123 return $this->getFooterHtml( $section );
1124 }
1125
1134 public function addPostHtml( $html ) {
1135 $this->mPost .= $html;
1136
1137 return $this;
1138 }
1139
1148 public function setPostHtml( $html ) {
1149 $this->mPost = $html;
1150
1151 return $this;
1152 }
1153
1160 public function getPostHtml() {
1161 return $this->mPost;
1162 }
1163
1172 public function addPostText( $msg ) {
1173 wfDeprecated( __METHOD__, '1.38' );
1174 return $this->addPostHtml( $msg );
1175 }
1176
1185 public function setPostText( $msg ) {
1186 wfDeprecated( __METHOD__, '1.38' );
1187 return $this->setPostHtml( $msg );
1188 }
1189
1199 public function setSections( $sections ) {
1200 if ( $this->getDisplayFormat() !== 'codex' ) {
1201 throw new \InvalidArgumentException(
1202 "Non-Codex HTMLForms do not support additional section information."
1203 );
1204 }
1205
1206 $this->mSections = $sections;
1207
1208 return $this;
1209 }
1210
1221 public function addHiddenField( $name, $value, array $attribs = [] ) {
1222 if ( !is_array( $value ) ) {
1223 // Per WebRequest::getVal: Array values are discarded for security reasons.
1224 $attribs += [ 'name' => $name ];
1225 $this->mHiddenFields[] = [ $value, $attribs ];
1226 }
1227
1228 return $this;
1229 }
1230
1242 public function addHiddenFields( array $fields ) {
1243 foreach ( $fields as $name => $value ) {
1244 if ( is_array( $value ) ) {
1245 // Per WebRequest::getVal: Array values are discarded for security reasons.
1246 continue;
1247 }
1248 $this->mHiddenFields[] = [ $value, [ 'name' => $name ] ];
1249 }
1250
1251 return $this;
1252 }
1253
1277 public function addButton( $data ) {
1278 if ( !is_array( $data ) ) {
1279 $args = func_get_args();
1280 if ( count( $args ) < 2 || count( $args ) > 4 ) {
1281 throw new InvalidArgumentException(
1282 'Incorrect number of arguments for deprecated calling style'
1283 );
1284 }
1285 $data = [
1286 'name' => $args[0],
1287 'value' => $args[1],
1288 'id' => $args[2] ?? null,
1289 'attribs' => $args[3] ?? null,
1290 ];
1291 } else {
1292 if ( !isset( $data['name'] ) ) {
1293 throw new InvalidArgumentException( 'A name is required' );
1294 }
1295 if ( !isset( $data['value'] ) ) {
1296 throw new InvalidArgumentException( 'A value is required' );
1297 }
1298 }
1299 $this->mButtons[] = $data + [
1300 'id' => null,
1301 'attribs' => null,
1302 'flags' => null,
1303 'framed' => true,
1304 ];
1305
1306 return $this;
1307 }
1308
1318 public function setTokenSalt( $salt ) {
1319 $this->mTokenSalt = $salt;
1320
1321 return $this;
1322 }
1323
1338 public function displayForm( $submitResult ) {
1339 $this->getOutput()->addHTML( $this->getHTML( $submitResult ) );
1340 }
1341
1346 private function getHiddenTitle(): string {
1347 if ( $this->hiddenTitleAddedToForm ) {
1348 return '';
1349 }
1350
1351 $html = '';
1352 if ( $this->getMethod() === 'post' ||
1353 $this->getAction() === $this->getConfig()->get( MainConfigNames::Script )
1354 ) {
1355 $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1356 }
1357 $this->hiddenTitleAddedToForm = true;
1358 return $html;
1359 }
1360
1371 public function getHTML( $submitResult ) {
1372 # For good measure (it is the default)
1373 $this->getOutput()->setPreventClickjacking( true );
1374 $this->getOutput()->addModules( 'mediawiki.htmlform' );
1375 $this->getOutput()->addModuleStyles( 'mediawiki.htmlform.styles' );
1376
1377 if ( $this->mCollapsible ) {
1378 // Preload jquery.makeCollapsible for mediawiki.htmlform
1379 $this->getOutput()->addModules( 'jquery.makeCollapsible' );
1380 }
1381
1382 $headerHtml = MWDebug::detectDeprecatedOverride( $this, __CLASS__, 'getHeaderText', '1.38' )
1383 ? $this->getHeaderText()
1384 : $this->getHeaderHtml();
1385 $footerHtml = MWDebug::detectDeprecatedOverride( $this, __CLASS__, 'getFooterText', '1.38' )
1386 ? $this->getFooterText()
1387 : $this->getFooterHtml();
1388 $html = $this->getErrorsOrWarnings( $submitResult, 'error' )
1389 . $this->getErrorsOrWarnings( $submitResult, 'warning' )
1390 . $headerHtml
1391 . $this->getHiddenTitle()
1392 . $this->getBody()
1393 . $this->getHiddenFields()
1394 . $this->getButtons()
1395 . $footerHtml;
1396
1397 return $this->mPre . $this->wrapForm( $html ) . $this->mPost;
1398 }
1399
1407 public function setCollapsibleOptions( $collapsedByDefault = false ) {
1408 $this->mCollapsible = true;
1409 $this->mCollapsed = $collapsedByDefault;
1410 return $this;
1411 }
1412
1418 protected function getFormAttributes() {
1419 # Use multipart/form-data
1420 $encType = $this->mUseMultipart
1421 ? 'multipart/form-data'
1422 : 'application/x-www-form-urlencoded';
1423 # Attributes
1424 $attribs = [
1425 'class' => 'mw-htmlform',
1426 'action' => $this->getAction(),
1427 'method' => $this->getMethod(),
1428 'enctype' => $encType,
1429 ];
1430 if ( $this->mId ) {
1431 $attribs['id'] = $this->mId;
1432 }
1433 if ( is_string( $this->mAutocomplete ) ) {
1434 $attribs['autocomplete'] = $this->mAutocomplete;
1435 }
1436 if ( $this->mName ) {
1437 $attribs['name'] = $this->mName;
1438 }
1439 if ( $this->needsJSForHtml5FormValidation() ) {
1440 $attribs['novalidate'] = true;
1441 }
1442 return $attribs;
1443 }
1444
1452 public function wrapForm( $html ) {
1453 # Include a <fieldset> wrapper for style, if requested.
1454 if ( $this->mWrapperLegend !== false ) {
1455 $legend = is_string( $this->mWrapperLegend ) ? $this->mWrapperLegend : false;
1456 $html = Xml::fieldset( $legend, $html, $this->mWrapperAttributes );
1457 }
1458
1459 return Html::rawElement(
1460 'form',
1461 $this->getFormAttributes(),
1462 $html
1463 );
1464 }
1465
1470 public function getHiddenFields() {
1471 $html = '';
1472
1473 // add the title as a hidden file if it hasn't been added yet and if it is necessary
1474 // added for backward compatibility with the previous version of this public method
1475 $html .= $this->getHiddenTitle();
1476
1477 if ( $this->mFormIdentifier !== null ) {
1478 $html .= Html::hidden(
1479 'wpFormIdentifier',
1480 $this->mFormIdentifier
1481 ) . "\n";
1482 }
1483 if ( $this->getMethod() === 'post' ) {
1484 $html .= Html::hidden(
1485 'wpEditToken',
1486 $this->getUser()->getEditToken( $this->mTokenSalt ),
1487 [ 'id' => 'wpEditToken' ]
1488 ) . "\n";
1489 }
1490
1491 foreach ( $this->mHiddenFields as [ $value, $attribs ] ) {
1492 $html .= Html::hidden( $attribs['name'], $value, $attribs ) . "\n";
1493 }
1494
1495 return $html;
1496 }
1497
1503 public function getButtons() {
1504 $buttons = '';
1505
1506 if ( $this->mShowSubmit ) {
1507 $attribs = [];
1508
1509 if ( isset( $this->mSubmitID ) ) {
1510 $attribs['id'] = $this->mSubmitID;
1511 }
1512
1513 if ( isset( $this->mSubmitName ) ) {
1514 $attribs['name'] = $this->mSubmitName;
1515 }
1516
1517 if ( isset( $this->mSubmitTooltip ) ) {
1518 $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
1519 }
1520
1521 $attribs['class'] = [ 'mw-htmlform-submit' ];
1522
1523 $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
1524 }
1525
1526 if ( $this->mShowCancel ) {
1527 $target = $this->getCancelTargetURL();
1528 $buttons .= Html::element(
1529 'a',
1530 [
1531 'href' => $target,
1532 ],
1533 $this->msg( 'cancel' )->text()
1534 ) . "\n";
1535 }
1536
1537 foreach ( $this->mButtons as $button ) {
1538 $attrs = [
1539 'type' => 'submit',
1540 'name' => $button['name'],
1541 'value' => $button['value']
1542 ];
1543
1544 if ( isset( $button['label-message'] ) ) {
1545 $label = $this->getMessage( $button['label-message'] )->parse();
1546 } elseif ( isset( $button['label'] ) ) {
1547 $label = htmlspecialchars( $button['label'] );
1548 } elseif ( isset( $button['label-raw'] ) ) {
1549 $label = $button['label-raw'];
1550 } else {
1551 $label = htmlspecialchars( $button['value'] );
1552 }
1553
1554 // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset Always set in self::addButton
1555 if ( $button['attribs'] ) {
1556 // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset Always set in self::addButton
1557 $attrs += $button['attribs'];
1558 }
1559
1560 if ( isset( $button['id'] ) ) {
1561 $attrs['id'] = $button['id'];
1562 }
1563
1564 $buttons .= Html::rawElement( 'button', $attrs, $label ) . "\n";
1565 }
1566
1567 if ( !$buttons ) {
1568 return '';
1569 }
1570
1571 return Html::rawElement( 'span',
1572 [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n";
1573 }
1574
1580 public function getBody() {
1581 return $this->displaySection( $this->mFieldTree, $this->mTableId );
1582 }
1583
1593 public function getErrorsOrWarnings( $elements, $elementsType ) {
1594 if ( !in_array( $elementsType, [ 'error', 'warning' ], true ) ) {
1595 throw new DomainException( $elementsType . ' is not a valid type.' );
1596 }
1597 $elementstr = false;
1598 if ( $elements instanceof Status ) {
1599 [ $errorStatus, $warningStatus ] = $elements->splitByErrorType();
1600 $status = $elementsType === 'error' ? $errorStatus : $warningStatus;
1601 if ( $status->isGood() ) {
1602 $elementstr = '';
1603 } else {
1604 $elementstr = $status
1605 ->getMessage()
1606 ->setContext( $this )
1607 ->setInterfaceMessageFlag( true )
1608 ->parse();
1609 }
1610 } elseif ( $elementsType === 'error' ) {
1611 if ( is_array( $elements ) ) {
1612 $elementstr = $this->formatErrors( $elements );
1613 } elseif ( $elements && $elements !== true ) {
1614 $elementstr = (string)$elements;
1615 }
1616 }
1617
1618 if ( !$elementstr ) {
1619 return '';
1620 } elseif ( $elementsType === 'error' ) {
1621 return Html::errorBox( $elementstr );
1622 } else { // $elementsType can only be 'warning'
1623 return Html::warningBox( $elementstr );
1624 }
1625 }
1626
1634 public function formatErrors( $errors ) {
1635 $errorstr = '';
1636
1637 foreach ( $errors as $error ) {
1638 $errorstr .= Html::rawElement(
1639 'li',
1640 [],
1641 $this->getMessage( $error )->parse()
1642 );
1643 }
1644
1645 return Html::rawElement( 'ul', [], $errorstr );
1646 }
1647
1655 public function setSubmitText( $t ) {
1656 $this->mSubmitText = $t;
1657
1658 return $this;
1659 }
1660
1667 public function setSubmitDestructive() {
1668 $this->mSubmitFlags = [ 'destructive', 'primary' ];
1669
1670 return $this;
1671 }
1672
1681 public function setSubmitTextMsg( $msg ) {
1682 if ( !$msg instanceof Message ) {
1683 $msg = $this->msg( $msg );
1684 }
1685 $this->setSubmitText( $msg->text() );
1686
1687 return $this;
1688 }
1689
1694 public function getSubmitText() {
1695 return $this->mSubmitText ?: $this->msg( 'htmlform-submit' )->text();
1696 }
1697
1703 public function setSubmitName( $name ) {
1704 $this->mSubmitName = $name;
1705
1706 return $this;
1707 }
1708
1714 public function setSubmitTooltip( $name ) {
1715 $this->mSubmitTooltip = $name;
1716
1717 return $this;
1718 }
1719
1728 public function setSubmitID( $t ) {
1729 $this->mSubmitID = $t;
1730
1731 return $this;
1732 }
1733
1752 public function setFormIdentifier( string $ident, bool $single = false ) {
1753 $this->mFormIdentifier = $ident;
1754 $this->mSingleForm = $single;
1755
1756 return $this;
1757 }
1758
1769 public function suppressDefaultSubmit( $suppressSubmit = true ) {
1770 $this->mShowSubmit = !$suppressSubmit;
1771
1772 return $this;
1773 }
1774
1781 public function showCancel( $show = true ) {
1782 $this->mShowCancel = $show;
1783 return $this;
1784 }
1785
1792 public function setCancelTarget( $target ) {
1793 if ( $target instanceof PageReference ) {
1794 $target = TitleValue::castPageToLinkTarget( $target );
1795 }
1796
1797 $this->mCancelTarget = $target;
1798 return $this;
1799 }
1800
1805 protected function getCancelTargetURL() {
1806 if ( is_string( $this->mCancelTarget ) ) {
1807 return $this->mCancelTarget;
1808 } else {
1809 // TODO: use a service to get the local URL for a LinkTarget, see T282283
1810 $target = Title::castFromLinkTarget( $this->mCancelTarget ) ?: Title::newMainPage();
1811 return $target->getLocalURL();
1812 }
1813 }
1814
1824 public function setTableId( $id ) {
1825 $this->mTableId = $id;
1826
1827 return $this;
1828 }
1829
1835 public function setId( $id ) {
1836 $this->mId = $id;
1837
1838 return $this;
1839 }
1840
1845 public function setName( $name ) {
1846 $this->mName = $name;
1847
1848 return $this;
1849 }
1850
1862 public function setWrapperLegend( $legend ) {
1863 $this->mWrapperLegend = $legend;
1864
1865 return $this;
1866 }
1867
1875 public function setWrapperAttributes( $attributes ) {
1876 $this->mWrapperAttributes = $attributes;
1877
1878 return $this;
1879 }
1880
1890 public function setWrapperLegendMsg( $msg ) {
1891 if ( !$msg instanceof Message ) {
1892 $msg = $this->msg( $msg );
1893 }
1894 $this->setWrapperLegend( $msg->text() );
1895
1896 return $this;
1897 }
1898
1908 public function setMessagePrefix( $p ) {
1909 $this->mMessagePrefix = $p;
1910
1911 return $this;
1912 }
1913
1921 public function setTitle( $t ) {
1922 // TODO: make mTitle a PageReference when we have a better way to get URLs, see T282283.
1923 $this->mTitle = Title::castFromPageReference( $t );
1924
1925 return $this;
1926 }
1927
1931 public function getTitle() {
1932 return $this->mTitle ?: $this->getContext()->getTitle();
1933 }
1934
1942 public function setMethod( $method = 'post' ) {
1943 $this->mMethod = strtolower( $method );
1944
1945 return $this;
1946 }
1947
1951 public function getMethod() {
1952 return $this->mMethod;
1953 }
1954
1965 protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
1966 return Xml::fieldset( $legend, $section, $attributes ) . "\n";
1967 }
1968
1986 public function displaySection( $fields,
1987 $sectionName = '',
1988 $fieldsetIDPrefix = '',
1989 &$hasUserVisibleFields = false
1990 ) {
1991 if ( $this->mFieldData === null ) {
1992 throw new LogicException( 'HTMLForm::displaySection() called on uninitialized field data. '
1993 . 'You probably called displayForm() without calling prepareForm() first.' );
1994 }
1995
1996 $html = [];
1997 $subsectionHtml = '';
1998 $hasLabel = false;
1999
2000 foreach ( $fields as $key => $value ) {
2001 if ( $value instanceof HTMLFormField ) {
2002 $v = array_key_exists( $key, $this->mFieldData )
2003 ? $this->mFieldData[$key]
2004 : $value->getDefault();
2005
2006 $retval = $this->formatField( $value, $v ?? '' );
2007
2008 // check, if the form field should be added to
2009 // the output.
2010 if ( $value->hasVisibleOutput() ) {
2011 $html[] = $retval;
2012
2013 $labelValue = trim( $value->getLabel() );
2014 if ( $labelValue !== "\u{00A0}" && $labelValue !== '&#160;' && $labelValue !== '' ) {
2015 $hasLabel = true;
2016 }
2017
2018 $hasUserVisibleFields = true;
2019 }
2020 } elseif ( is_array( $value ) ) {
2021 $subsectionHasVisibleFields = false;
2022 $section =
2023 $this->displaySection( $value,
2024 "mw-htmlform-$key",
2025 "$fieldsetIDPrefix$key-",
2026 $subsectionHasVisibleFields );
2027
2028 if ( $subsectionHasVisibleFields === true ) {
2029 // Display the section with various niceties.
2030 $hasUserVisibleFields = true;
2031
2032 $legend = $this->getLegend( $key );
2033
2034 $headerHtml = MWDebug::detectDeprecatedOverride( $this, __CLASS__, 'getHeaderText', '1.38' )
2035 ? $this->getHeaderText( $key )
2036 : $this->getHeaderHtml( $key );
2037 $footerHtml = MWDebug::detectDeprecatedOverride( $this, __CLASS__, 'getFooterText', '1.38' )
2038 ? $this->getFooterText( $key )
2039 : $this->getFooterHtml( $key );
2040 $section = $headerHtml .
2041 $section .
2042 $footerHtml;
2043
2044 $attributes = [];
2045 if ( $fieldsetIDPrefix ) {
2046 $attributes['id'] = Sanitizer::escapeIdForAttribute( "$fieldsetIDPrefix$key" );
2047 }
2048 $subsectionHtml .= $this->wrapFieldSetSection(
2049 $legend, $section, $attributes, $fields === $this->mFieldTree
2050 );
2051 } else {
2052 // Just return the inputs, nothing fancy.
2053 $subsectionHtml .= $section;
2054 }
2055 }
2056 }
2057
2058 $html = $this->formatSection( $html, $sectionName, $hasLabel );
2059
2060 if ( $subsectionHtml ) {
2061 if ( $this->mSubSectionBeforeFields ) {
2062 return $subsectionHtml . "\n" . $html;
2063 } else {
2064 return $html . "\n" . $subsectionHtml;
2065 }
2066 } else {
2067 return $html;
2068 }
2069 }
2070
2079 protected function formatField( HTMLFormField $field, $value ) {
2080 $displayFormat = $this->getDisplayFormat();
2081 switch ( $displayFormat ) {
2082 case 'table':
2083 return $field->getTableRow( $value );
2084 case 'div':
2085 return $field->getDiv( $value );
2086 case 'raw':
2087 return $field->getRaw( $value );
2088 case 'inline':
2089 return $field->getInline( $value );
2090 default:
2091 throw new LogicException( 'Not implemented' );
2092 }
2093 }
2094
2103 protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
2104 if ( !$fieldsHtml ) {
2105 // Do not generate any wrappers for empty sections. Sections may be empty if they only have
2106 // subsections, but no fields. A legend will still be added in wrapFieldSetSection().
2107 return '';
2108 }
2109
2110 $displayFormat = $this->getDisplayFormat();
2111 $html = implode( '', $fieldsHtml );
2112
2113 if ( $displayFormat === 'raw' ) {
2114 return $html;
2115 }
2116
2117 // Avoid strange spacing when no labels exist
2118 $attribs = $anyFieldHasLabel ? [] : [ 'class' => 'mw-htmlform-nolabel' ];
2119
2120 if ( $sectionName ) {
2121 $attribs['id'] = Sanitizer::escapeIdForAttribute( $sectionName );
2122 }
2123
2124 if ( $displayFormat === 'table' ) {
2125 return Html::rawElement( 'table',
2126 $attribs,
2127 Html::rawElement( 'tbody', [], "\n$html\n" ) ) . "\n";
2128 } elseif ( $displayFormat === 'inline' ) {
2129 return Html::rawElement( 'span', $attribs, "\n$html\n" );
2130 } else {
2131 return Html::rawElement( 'div', $attribs, "\n$html\n" );
2132 }
2133 }
2134
2138 public function loadData() {
2139 $this->prepareForm();
2140 }
2141
2145 protected function loadFieldData() {
2146 $fieldData = [];
2147 $request = $this->getRequest();
2148
2149 foreach ( $this->mFlatFields as $fieldname => $field ) {
2150 if ( $field->skipLoadData( $request ) ) {
2151 continue;
2152 }
2153 if ( $field->mParams['disabled'] ?? false ) {
2154 $fieldData[$fieldname] = $field->getDefault();
2155 } else {
2156 $fieldData[$fieldname] = $field->loadDataFromRequest( $request );
2157 }
2158 }
2159
2160 // Reset to default for fields that are supposed to be disabled.
2161 // FIXME: Handle dependency chains, fields that a field checks on may need a reset too.
2162 foreach ( $fieldData as $name => &$value ) {
2163 $field = $this->mFlatFields[$name];
2164 if ( $field->isDisabled( $fieldData ) ) {
2165 $value = $field->getDefault();
2166 }
2167 }
2168
2169 # Filter data.
2170 foreach ( $fieldData as $name => &$value ) {
2171 $field = $this->mFlatFields[$name];
2172 $value = $field->filter( $value, $fieldData );
2173 }
2174
2175 $this->mFieldData = $fieldData;
2176 }
2177
2188 public function filterDataForSubmit( $data ) {
2189 return $data;
2190 }
2191
2201 public function getLegend( $key ) {
2202 return $this->msg( $this->mMessagePrefix ? "{$this->mMessagePrefix}-$key" : $key )->text();
2203 }
2204
2215 public function setAction( $action ) {
2216 $this->mAction = $action;
2217
2218 return $this;
2219 }
2220
2228 public function getAction() {
2229 // If an action is already provided, return it
2230 if ( $this->mAction !== false ) {
2231 return $this->mAction;
2232 }
2233
2234 $articlePath = $this->getConfig()->get( MainConfigNames::ArticlePath );
2235 // Check whether we are in GET mode and the ArticlePath contains a "?"
2236 // meaning that getLocalURL() would return something like "index.php?title=...".
2237 // As browser remove the query string before submitting GET forms,
2238 // it means that the title would be lost. In such case use script path instead
2239 // and put title in a hidden field (see getHiddenFields()).
2240 if ( str_contains( $articlePath, '?' ) && $this->getMethod() === 'get' ) {
2241 return $this->getConfig()->get( MainConfigNames::Script );
2242 }
2243
2244 return $this->getTitle()->getLocalURL();
2245 }
2246
2257 public function setAutocomplete( $autocomplete ) {
2258 $this->mAutocomplete = $autocomplete;
2259
2260 return $this;
2261 }
2262
2269 protected function getMessage( $value ) {
2270 return Message::newFromSpecifier( $value )->setContext( $this );
2271 }
2272
2283 foreach ( $this->mFlatFields as $field ) {
2284 if ( $field->needsJSForHtml5FormValidation() ) {
2285 return true;
2286 }
2287 }
2288 return false;
2289 }
2290}
2291
2293class_alias( HTMLForm::class, 'HTMLForm' );
getUser()
getRequest()
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
getContext()
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:969
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:364
wrapFieldSetSection( $legend, $section, $attributes, $isRoot)
Wraps the given $section into a user-visible fieldset.
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.
Definition HTMLForm.php:987
bool $mCollapsed
Whether the form is collapsed by default.
Definition HTMLForm.php:322
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:727
array $availableSubclassDisplayFormats
Available formats in which to display the form.
Definition HTMLForm.php:398
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:872
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:859
loadFieldData()
Load data of form fields from the request.
tryAuthorizedSubmit()
Try submitting, with edit token check first.
Definition HTMLForm.php:649
wasSubmitted()
Test whether the form was considered to have been submitted or not, i.e.
Definition HTMLForm.php:816
getFormAttributes()
Get HTML attributes for the <form> tag.
static getClassFromDescriptor( $fieldname, &$descriptor)
Get the HTMLFormField subclass for this descriptor.
Definition HTMLForm.php:576
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
prepareForm()
Prepare form for submission.
Definition HTMLForm.php:630
bool $mCollapsible
Whether the form can be collapsed.
Definition HTMLForm.php:315
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:374
string $displayFormat
Format in which to display form.
Definition HTMLForm.php:381
addPreText( $msg)
Add HTML to introductory message.
Definition HTMLForm.php:923
setWrapperAttributes( $attributes)
For internal use only.
string null $mAutocomplete
Form attribute autocomplete.
Definition HTMLForm.php:329
getDisplayFormat()
Getter for displayFormat.
Definition HTMLForm.php:556
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:526
string array $mTokenSalt
Salt for the edit token.
Definition HTMLForm.php:350
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:606
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:706
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
addFields( $descriptor)
Add fields to the form.
Definition HTMLForm.php:468
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:830
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:688
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:845
HTMLFormField[] $mFlatFields
Definition HTMLForm.php:265
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:886
setSubmitID( $t)
Set the id for the submit button.
getPreText()
Get the introductory message HTML.
Definition HTMLForm.php:935
array $availableDisplayFormats
Available formats in which to display the form.
Definition HTMLForm.php:387
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:949
static factory( $displayFormat, $descriptor, IContextSource $context, $messagePrefix='')
Construct a HTMLForm object for given display type.
Definition HTMLForm.php:423
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:910
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:898
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:451
string false $mAction
Form action URL.
Definition HTMLForm.php:308
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:158
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition Message.php:460
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:79
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)