MediaWiki 1.43.1
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
1374 private function getHiddenTitle(): string {
1375 if ( $this->hiddenTitleAddedToForm ) {
1376 return '';
1377 }
1378
1379 $html = '';
1380 if ( $this->getMethod() === 'post' ||
1381 $this->getAction() === $this->getConfig()->get( MainConfigNames::Script )
1382 ) {
1383 $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1384 }
1385 $this->hiddenTitleAddedToForm = true;
1386 return $html;
1387 }
1388
1399 public function getHTML( $submitResult ) {
1400 # For good measure (it is the default)
1401 $this->getOutput()->getMetadata()->setPreventClickjacking( true );
1402 $this->getOutput()->addModules( 'mediawiki.htmlform' );
1403 $this->getOutput()->addModuleStyles( 'mediawiki.htmlform.styles' );
1404
1405 if ( $this->mCollapsible ) {
1406 // Preload jquery.makeCollapsible for mediawiki.htmlform
1407 $this->getOutput()->addModules( 'jquery.makeCollapsible' );
1408 }
1409
1410 $headerHtml = MWDebug::detectDeprecatedOverride( $this, __CLASS__, 'getHeaderText', '1.38' )
1411 ? $this->getHeaderText()
1412 : $this->getHeaderHtml();
1413 $footerHtml = MWDebug::detectDeprecatedOverride( $this, __CLASS__, 'getFooterText', '1.38' )
1414 ? $this->getFooterText()
1415 : $this->getFooterHtml();
1416 $html = $this->getErrorsOrWarnings( $submitResult, 'error' )
1417 . $this->getErrorsOrWarnings( $submitResult, 'warning' )
1418 . $headerHtml
1419 . $this->getHiddenTitle()
1420 . $this->getBody()
1421 . $this->getHiddenFields()
1422 . $this->getButtons()
1423 . $footerHtml;
1424
1425 return $this->mPre . $this->wrapForm( $html ) . $this->mPost;
1426 }
1427
1435 public function setCollapsibleOptions( $collapsedByDefault = false ) {
1436 $this->mCollapsible = true;
1437 $this->mCollapsed = $collapsedByDefault;
1438 return $this;
1439 }
1440
1446 protected function getFormAttributes() {
1447 # Use multipart/form-data
1448 $encType = $this->mUseMultipart
1449 ? 'multipart/form-data'
1450 : 'application/x-www-form-urlencoded';
1451 # Attributes
1452 $attribs = [
1453 'class' => 'mw-htmlform',
1454 'action' => $this->getAction(),
1455 'method' => $this->getMethod(),
1456 'enctype' => $encType,
1457 ];
1458 if ( $this->mId ) {
1459 $attribs['id'] = $this->mId;
1460 }
1461 if ( is_string( $this->mAutocomplete ) ) {
1462 $attribs['autocomplete'] = $this->mAutocomplete;
1463 }
1464 if ( $this->mName ) {
1465 $attribs['name'] = $this->mName;
1466 }
1467 if ( $this->needsJSForHtml5FormValidation() ) {
1468 $attribs['novalidate'] = true;
1469 }
1470 return $attribs;
1471 }
1472
1480 public function wrapForm( $html ) {
1481 # Include a <fieldset> wrapper for style, if requested.
1482 if ( $this->mWrapperLegend !== false ) {
1483 $legend = is_string( $this->mWrapperLegend ) ? $this->mWrapperLegend : false;
1484 $html = Xml::fieldset( $legend, $html, $this->mWrapperAttributes );
1485 }
1486
1487 return Html::rawElement(
1488 'form',
1489 $this->getFormAttributes(),
1490 $html
1491 );
1492 }
1493
1498 public function getHiddenFields() {
1499 $html = '';
1500
1501 // add the title as a hidden file if it hasn't been added yet and if it is necessary
1502 // added for backward compatibility with the previous version of this public method
1503 $html .= $this->getHiddenTitle();
1504
1505 if ( $this->mFormIdentifier !== null ) {
1506 $html .= Html::hidden(
1507 'wpFormIdentifier',
1508 $this->mFormIdentifier
1509 ) . "\n";
1510 }
1511 if ( $this->getMethod() === 'post' ) {
1512 $html .= Html::hidden(
1513 'wpEditToken',
1514 $this->getUser()->getEditToken( $this->mTokenSalt ),
1515 [ 'id' => 'wpEditToken' ]
1516 ) . "\n";
1517 }
1518
1519 foreach ( $this->mHiddenFields as [ $value, $attribs ] ) {
1520 $html .= Html::hidden( $attribs['name'], $value, $attribs ) . "\n";
1521 }
1522
1523 return $html;
1524 }
1525
1531 public function getButtons() {
1532 $buttons = '';
1533
1534 if ( $this->mShowSubmit ) {
1535 $attribs = [];
1536
1537 if ( isset( $this->mSubmitID ) ) {
1538 $attribs['id'] = $this->mSubmitID;
1539 }
1540
1541 if ( isset( $this->mSubmitName ) ) {
1542 $attribs['name'] = $this->mSubmitName;
1543 }
1544
1545 if ( isset( $this->mSubmitTooltip ) ) {
1546 $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
1547 }
1548
1549 $attribs['class'] = [ 'mw-htmlform-submit' ];
1550
1551 $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
1552 }
1553
1554 if ( $this->mShowCancel ) {
1555 $target = $this->getCancelTargetURL();
1556 $buttons .= Html::element(
1557 'a',
1558 [
1559 'href' => $target,
1560 ],
1561 $this->msg( 'cancel' )->text()
1562 ) . "\n";
1563 }
1564
1565 foreach ( $this->mButtons as $button ) {
1566 $attrs = [
1567 'type' => 'submit',
1568 'name' => $button['name'],
1569 'value' => $button['value']
1570 ];
1571
1572 if ( isset( $button['label-message'] ) ) {
1573 $label = $this->getMessage( $button['label-message'] )->parse();
1574 } elseif ( isset( $button['label'] ) ) {
1575 $label = htmlspecialchars( $button['label'] );
1576 } elseif ( isset( $button['label-raw'] ) ) {
1577 $label = $button['label-raw'];
1578 } else {
1579 $label = htmlspecialchars( $button['value'] );
1580 }
1581
1582 // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset Always set in self::addButton
1583 if ( $button['attribs'] ) {
1584 // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset Always set in self::addButton
1585 $attrs += $button['attribs'];
1586 }
1587
1588 if ( isset( $button['id'] ) ) {
1589 $attrs['id'] = $button['id'];
1590 }
1591
1592 $buttons .= Html::rawElement( 'button', $attrs, $label ) . "\n";
1593 }
1594
1595 if ( !$buttons ) {
1596 return '';
1597 }
1598
1599 return Html::rawElement( 'span',
1600 [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n";
1601 }
1602
1608 public function getBody() {
1609 return $this->displaySection( $this->mFieldTree, $this->mTableId );
1610 }
1611
1621 public function getErrorsOrWarnings( $elements, $elementsType ) {
1622 if ( !in_array( $elementsType, [ 'error', 'warning' ], true ) ) {
1623 throw new DomainException( $elementsType . ' is not a valid type.' );
1624 }
1625 $elementstr = false;
1626 if ( $elements instanceof Status ) {
1627 [ $errorStatus, $warningStatus ] = $elements->splitByErrorType();
1628 $status = $elementsType === 'error' ? $errorStatus : $warningStatus;
1629 if ( $status->isGood() ) {
1630 $elementstr = '';
1631 } else {
1632 $elementstr = $status
1633 ->getMessage()
1634 ->setContext( $this )
1635 ->setInterfaceMessageFlag( true )
1636 ->parse();
1637 }
1638 } elseif ( $elementsType === 'error' ) {
1639 if ( is_array( $elements ) ) {
1640 $elementstr = $this->formatErrors( $elements );
1641 } elseif ( $elements && $elements !== true ) {
1642 $elementstr = (string)$elements;
1643 }
1644 }
1645
1646 if ( !$elementstr ) {
1647 return '';
1648 } elseif ( $elementsType === 'error' ) {
1649 return Html::errorBox( $elementstr );
1650 } else { // $elementsType can only be 'warning'
1651 return Html::warningBox( $elementstr );
1652 }
1653 }
1654
1662 public function formatErrors( $errors ) {
1663 $errorstr = '';
1664
1665 foreach ( $errors as $error ) {
1666 $errorstr .= Html::rawElement(
1667 'li',
1668 [],
1669 $this->getMessage( $error )->parse()
1670 );
1671 }
1672
1673 return Html::rawElement( 'ul', [], $errorstr );
1674 }
1675
1683 public function setSubmitText( $t ) {
1684 $this->mSubmitText = $t;
1685
1686 return $this;
1687 }
1688
1695 public function setSubmitDestructive() {
1696 $this->mSubmitFlags = [ 'destructive', 'primary' ];
1697
1698 return $this;
1699 }
1700
1709 public function setSubmitTextMsg( $msg ) {
1710 if ( !$msg instanceof Message ) {
1711 $msg = $this->msg( $msg );
1712 }
1713 $this->setSubmitText( $msg->text() );
1714
1715 return $this;
1716 }
1717
1722 public function getSubmitText() {
1723 return $this->mSubmitText ?: $this->msg( 'htmlform-submit' )->text();
1724 }
1725
1731 public function setSubmitName( $name ) {
1732 $this->mSubmitName = $name;
1733
1734 return $this;
1735 }
1736
1742 public function setSubmitTooltip( $name ) {
1743 $this->mSubmitTooltip = $name;
1744
1745 return $this;
1746 }
1747
1756 public function setSubmitID( $t ) {
1757 $this->mSubmitID = $t;
1758
1759 return $this;
1760 }
1761
1780 public function setFormIdentifier( string $ident, bool $single = false ) {
1781 $this->mFormIdentifier = $ident;
1782 $this->mSingleForm = $single;
1783
1784 return $this;
1785 }
1786
1797 public function suppressDefaultSubmit( $suppressSubmit = true ) {
1798 $this->mShowSubmit = !$suppressSubmit;
1799
1800 return $this;
1801 }
1802
1809 public function showCancel( $show = true ) {
1810 $this->mShowCancel = $show;
1811 return $this;
1812 }
1813
1820 public function setCancelTarget( $target ) {
1821 if ( $target instanceof PageReference ) {
1822 $target = TitleValue::castPageToLinkTarget( $target );
1823 }
1824
1825 $this->mCancelTarget = $target;
1826 return $this;
1827 }
1828
1833 protected function getCancelTargetURL() {
1834 if ( is_string( $this->mCancelTarget ) ) {
1835 return $this->mCancelTarget;
1836 } else {
1837 // TODO: use a service to get the local URL for a LinkTarget, see T282283
1838 $target = Title::castFromLinkTarget( $this->mCancelTarget ) ?: Title::newMainPage();
1839 return $target->getLocalURL();
1840 }
1841 }
1842
1852 public function setTableId( $id ) {
1853 $this->mTableId = $id;
1854
1855 return $this;
1856 }
1857
1863 public function setId( $id ) {
1864 $this->mId = $id;
1865
1866 return $this;
1867 }
1868
1873 public function setName( $name ) {
1874 $this->mName = $name;
1875
1876 return $this;
1877 }
1878
1890 public function setWrapperLegend( $legend ) {
1891 $this->mWrapperLegend = $legend;
1892
1893 return $this;
1894 }
1895
1903 public function setWrapperAttributes( $attributes ) {
1904 $this->mWrapperAttributes = $attributes;
1905
1906 return $this;
1907 }
1908
1918 public function setWrapperLegendMsg( $msg ) {
1919 if ( !$msg instanceof Message ) {
1920 $msg = $this->msg( $msg );
1921 }
1922 $this->setWrapperLegend( $msg->text() );
1923
1924 return $this;
1925 }
1926
1936 public function setMessagePrefix( $p ) {
1937 $this->mMessagePrefix = $p;
1938
1939 return $this;
1940 }
1941
1949 public function setTitle( $t ) {
1950 // TODO: make mTitle a PageReference when we have a better way to get URLs, see T282283.
1951 $this->mTitle = Title::castFromPageReference( $t );
1952
1953 return $this;
1954 }
1955
1959 public function getTitle() {
1960 return $this->mTitle ?: $this->getContext()->getTitle();
1961 }
1962
1970 public function setMethod( $method = 'post' ) {
1971 $this->mMethod = strtolower( $method );
1972
1973 return $this;
1974 }
1975
1979 public function getMethod() {
1980 return $this->mMethod;
1981 }
1982
1993 protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
1994 return Xml::fieldset( $legend, $section, $attributes ) . "\n";
1995 }
1996
2015 public function displaySection( $fields,
2016 $sectionName = '',
2017 $fieldsetIDPrefix = '',
2018 &$hasUserVisibleFields = false
2019 ) {
2020 if ( $this->mFieldData === null ) {
2021 throw new LogicException( 'HTMLForm::displaySection() called on uninitialized field data. '
2022 . 'You probably called displayForm() without calling prepareForm() first.' );
2023 }
2024
2025 $html = [];
2026 $subsectionHtml = '';
2027 $hasLabel = false;
2028
2029 foreach ( $fields as $key => $value ) {
2030 if ( $value instanceof HTMLFormField ) {
2031 $v = array_key_exists( $key, $this->mFieldData )
2032 ? $this->mFieldData[$key]
2033 : $value->getDefault();
2034
2035 $retval = $this->formatField( $value, $v ?? '' );
2036
2037 // check, if the form field should be added to
2038 // the output.
2039 if ( $value->hasVisibleOutput() ) {
2040 $html[] = $retval;
2041
2042 $labelValue = trim( $value->getLabel() );
2043 if ( $labelValue !== "\u{00A0}" && $labelValue !== '&#160;' && $labelValue !== '' ) {
2044 $hasLabel = true;
2045 }
2046
2047 $hasUserVisibleFields = true;
2048 }
2049 } elseif ( is_array( $value ) ) {
2050 $subsectionHasVisibleFields = false;
2051 $section =
2052 $this->displaySection( $value,
2053 "mw-htmlform-$key",
2054 "$fieldsetIDPrefix$key-",
2055 $subsectionHasVisibleFields );
2056
2057 if ( $subsectionHasVisibleFields === true ) {
2058 // Display the section with various niceties.
2059 $hasUserVisibleFields = true;
2060
2061 $legend = $this->getLegend( $key );
2062
2063 $headerHtml = MWDebug::detectDeprecatedOverride( $this, __CLASS__, 'getHeaderText', '1.38' )
2064 ? $this->getHeaderText( $key )
2065 : $this->getHeaderHtml( $key );
2066 $footerHtml = MWDebug::detectDeprecatedOverride( $this, __CLASS__, 'getFooterText', '1.38' )
2067 ? $this->getFooterText( $key )
2068 : $this->getFooterHtml( $key );
2069 $section = $headerHtml .
2070 $section .
2071 $footerHtml;
2072
2073 $attributes = [];
2074 if ( $fieldsetIDPrefix ) {
2075 $attributes['id'] = Sanitizer::escapeIdForAttribute( "$fieldsetIDPrefix$key" );
2076 }
2077 $subsectionHtml .= $this->wrapFieldSetSection(
2078 $legend, $section, $attributes, $fields === $this->mFieldTree
2079 );
2080 } else {
2081 // Just return the inputs, nothing fancy.
2082 $subsectionHtml .= $section;
2083 }
2084 }
2085 }
2086
2087 $html = $this->formatSection( $html, $sectionName, $hasLabel );
2088
2089 if ( $subsectionHtml ) {
2090 if ( $this->mSubSectionBeforeFields ) {
2091 return $subsectionHtml . "\n" . $html;
2092 } else {
2093 return $html . "\n" . $subsectionHtml;
2094 }
2095 } else {
2096 return $html;
2097 }
2098 }
2099
2108 protected function formatField( HTMLFormField $field, $value ) {
2109 $displayFormat = $this->getDisplayFormat();
2110 switch ( $displayFormat ) {
2111 case 'table':
2112 return $field->getTableRow( $value );
2113 case 'div':
2114 return $field->getDiv( $value );
2115 case 'raw':
2116 return $field->getRaw( $value );
2117 case 'inline':
2118 return $field->getInline( $value );
2119 default:
2120 throw new LogicException( 'Not implemented' );
2121 }
2122 }
2123
2132 protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
2133 if ( !$fieldsHtml ) {
2134 // Do not generate any wrappers for empty sections. Sections may be empty if they only have
2135 // subsections, but no fields. A legend will still be added in wrapFieldSetSection().
2136 return '';
2137 }
2138
2139 $displayFormat = $this->getDisplayFormat();
2140 $html = implode( '', $fieldsHtml );
2141
2142 if ( $displayFormat === 'raw' ) {
2143 return $html;
2144 }
2145
2146 // Avoid strange spacing when no labels exist
2147 $attribs = $anyFieldHasLabel ? [] : [ 'class' => 'mw-htmlform-nolabel' ];
2148
2149 if ( $sectionName ) {
2150 $attribs['id'] = Sanitizer::escapeIdForAttribute( $sectionName );
2151 }
2152
2153 if ( $displayFormat === 'table' ) {
2154 return Html::rawElement( 'table',
2155 $attribs,
2156 Html::rawElement( 'tbody', [], "\n$html\n" ) ) . "\n";
2157 } elseif ( $displayFormat === 'inline' ) {
2158 return Html::rawElement( 'span', $attribs, "\n$html\n" );
2159 } else {
2160 return Html::rawElement( 'div', $attribs, "\n$html\n" );
2161 }
2162 }
2163
2167 public function loadData() {
2168 $this->prepareForm();
2169 }
2170
2174 protected function loadFieldData() {
2175 $fieldData = [];
2176 $request = $this->getRequest();
2177
2178 foreach ( $this->mFlatFields as $fieldname => $field ) {
2179 if ( $field->skipLoadData( $request ) ) {
2180 continue;
2181 }
2182 if ( $field->mParams['disabled'] ?? false ) {
2183 $fieldData[$fieldname] = $field->getDefault();
2184 } else {
2185 $fieldData[$fieldname] = $field->loadDataFromRequest( $request );
2186 }
2187 }
2188
2189 // Reset to default for fields that are supposed to be disabled.
2190 // FIXME: Handle dependency chains, fields that a field checks on may need a reset too.
2191 foreach ( $fieldData as $name => &$value ) {
2192 $field = $this->mFlatFields[$name];
2193 if ( $field->isDisabled( $fieldData ) ) {
2194 $value = $field->getDefault();
2195 }
2196 }
2197
2198 # Filter data.
2199 foreach ( $fieldData as $name => &$value ) {
2200 $field = $this->mFlatFields[$name];
2201 $value = $field->filter( $value, $fieldData );
2202 }
2203
2204 $this->mFieldData = $fieldData;
2205 }
2206
2217 public function filterDataForSubmit( $data ) {
2218 return $data;
2219 }
2220
2230 public function getLegend( $key ) {
2231 return $this->msg( $this->mMessagePrefix ? "{$this->mMessagePrefix}-$key" : $key )->text();
2232 }
2233
2244 public function setAction( $action ) {
2245 $this->mAction = $action;
2246
2247 return $this;
2248 }
2249
2257 public function getAction() {
2258 // If an action is already provided, return it
2259 if ( $this->mAction !== false ) {
2260 return $this->mAction;
2261 }
2262
2263 $articlePath = $this->getConfig()->get( MainConfigNames::ArticlePath );
2264 // Check whether we are in GET mode and the ArticlePath contains a "?"
2265 // meaning that getLocalURL() would return something like "index.php?title=...".
2266 // As browser remove the query string before submitting GET forms,
2267 // it means that the title would be lost. In such case use script path instead
2268 // and put title in a hidden field (see getHiddenFields()).
2269 if ( str_contains( $articlePath, '?' ) && $this->getMethod() === 'get' ) {
2270 return $this->getConfig()->get( MainConfigNames::Script );
2271 }
2272
2273 return $this->getTitle()->getLocalURL();
2274 }
2275
2286 public function setAutocomplete( $autocomplete ) {
2287 $this->mAutocomplete = $autocomplete;
2288
2289 return $this;
2290 }
2291
2298 protected function getMessage( $value ) {
2299 return Message::newFromSpecifier( $value )->setContext( $this );
2300 }
2301
2312 foreach ( $this->mFlatFields as $field ) {
2313 if ( $field->needsJSForHtml5FormValidation() ) {
2314 return true;
2315 }
2316 }
2317 return false;
2318 }
2319}
2320
2322class_alias( HTMLForm::class, 'HTMLForm' );
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:81
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
setContext(IContextSource $context)
Debug toolbar.
Definition MWDebug.php:48
Text field for selecting a value from a large list of possible values, with auto-completion and optio...
A checkbox matrix Operates similarly to HTMLMultiSelectField, but instead of using an array of option...
A field that will contain a date and/or time.
Expiry Field that allows the user to specify a precise date or a relative date string.
A field that will contain a numeric value.
A container for HTMLFormFields that allows for multiple copies of the set of fields to be displayed t...
An information field (text blob), not a proper input.
A field that must contain a number.
Implements a tag multiselect input field for namespaces.
Double field with a dropdown list constructed from a system message in the format.
A limit dropdown, which accepts any valid number.
Creates a Html::namespaceSelector input field with a button assigned to the input field.
Wrapper for Html::namespaceSelector to use in HTMLForm.
Select dropdown field, with an additional "other" textbox.
A size filter field for use on query-type special pages.
Add a submit button inline in the form (as opposed to HTMLForm::addButton(), which will add it at the...
Wrapper for ChangeTags::buildTagFilterSelector to use in HTMLForm.
Implements a tag multiselect input field for arbitrary values.
Creates a text input field with a button assigned to the input field.
Dropdown widget that allows the user to select a timezone, either by choosing a geographic zone,...
Implements a text input field for page titles.
Implements a tag multiselect input field for titles.
Implements a text input field for user names.
Implements a tag multiselect input field for user names.
The parent class to generate form fields.
getDiv( $value)
Get the complete div for the input, including help text, labels, and whatever.
getTableRow( $value)
Get the complete table row for the input, including help text, labels, and whatever.
getRaw( $value)
Get the complete raw fields for the input, including help text, labels, and whatever.
getInline( $value)
Get the complete field as an inline element.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php: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:57
static submitButton( $contents, array $attrs=[], array $modifiers=[])
Returns an HTML input element in a string.
Definition Html.php:164
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:156
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.
static newFromSpecifier(MessageSpecifier $spec)
Convert from any MessageSpecifier to a MessageValue.
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)