MediaWiki 1.42.1
HTMLForm.php
Go to the documentation of this file.
1<?php
2
24namespace MediaWiki\HTMLForm;
25
26use DomainException;
27use InvalidArgumentException;
28use LogicException;
31use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
79use StatusValue;
80use Stringable;
81use Xml;
82
206class HTMLForm extends ContextSource {
207 use ProtectedHookAccessorTrait;
208
210 public static $typeMappings = [
211 'api' => HTMLApiField::class,
212 'text' => HTMLTextField::class,
213 'textwithbutton' => HTMLTextFieldWithButton::class,
214 'textarea' => HTMLTextAreaField::class,
215 'select' => HTMLSelectField::class,
216 'combobox' => HTMLComboboxField::class,
217 'radio' => HTMLRadioField::class,
218 'multiselect' => HTMLMultiSelectField::class,
219 'limitselect' => HTMLSelectLimitField::class,
220 'check' => HTMLCheckField::class,
221 'toggle' => HTMLCheckField::class,
222 'int' => HTMLIntField::class,
223 'file' => HTMLFileField::class,
224 'float' => HTMLFloatField::class,
225 'info' => HTMLInfoField::class,
226 'selectorother' => HTMLSelectOrOtherField::class,
227 'selectandother' => HTMLSelectAndOtherField::class,
228 'namespaceselect' => HTMLSelectNamespace::class,
229 'namespaceselectwithbutton' => HTMLSelectNamespaceWithButton::class,
230 'tagfilter' => HTMLTagFilter::class,
231 'sizefilter' => HTMLSizeFilterField::class,
232 'submit' => HTMLSubmitField::class,
233 'hidden' => HTMLHiddenField::class,
234 'edittools' => HTMLEditTools::class,
235 'checkmatrix' => HTMLCheckMatrix::class,
236 'cloner' => HTMLFormFieldCloner::class,
237 'autocompleteselect' => HTMLAutoCompleteSelectField::class,
238 'language' => HTMLSelectLanguageField::class,
239 'date' => HTMLDateTimeField::class,
240 'time' => HTMLDateTimeField::class,
241 'datetime' => HTMLDateTimeField::class,
242 'expiry' => HTMLExpiryField::class,
243 'timezone' => HTMLTimezoneField::class,
244 // HTMLTextField will output the correct type="" attribute automagically.
245 // There are about four zillion other HTML5 input types, like range, but
246 // we don't use those at the moment, so no point in adding all of them.
247 'email' => HTMLTextField::class,
248 'password' => HTMLTextField::class,
249 'url' => HTMLTextField::class,
250 'title' => HTMLTitleTextField::class,
251 'user' => HTMLUserTextField::class,
252 'tagmultiselect' => HTMLTagMultiselectField::class,
253 'usersmultiselect' => HTMLUsersMultiselectField::class,
254 'titlesmultiselect' => HTMLTitlesMultiselectField::class,
255 'namespacesmultiselect' => HTMLNamespacesMultiselectField::class,
256 ];
257
259
261
263 protected $mFlatFields = [];
264 protected $mFieldTree = [];
265 protected $mShowReset = false;
266 protected $mShowSubmit = true;
268 protected $mSubmitFlags = [ 'primary', 'progressive' ];
269 protected $mShowCancel = false;
270 protected $mCancelTarget;
271
278
279 protected $mPre = '';
280 protected $mHeader = '';
281 protected $mFooter = '';
282 protected $mSectionHeaders = [];
283 protected $mSectionFooters = [];
284 protected $mPost = '';
285 protected $mId;
286 protected $mName;
287 protected $mTableId = '';
288
289 protected $mSubmitID;
290 protected $mSubmitName;
291 protected $mSubmitText;
293
295 protected $mSingleForm = false;
296
298 protected $mTitle;
299 protected $mMethod = 'post';
300 protected $mWasSubmitted = false;
301
307 protected $mAction = false;
308
314 protected $mCollapsible = false;
315
321 protected $mCollapsed = false;
322
328 protected $mAutocomplete = null;
329
330 protected $mUseMultipart = false;
335 protected $mHiddenFields = [];
340 protected $mButtons = [];
341
342 protected $mWrapperLegend = false;
343 protected $mWrapperAttributes = [];
344
349 protected $mTokenSalt = '';
350
363 protected $mSections = [];
364
373 protected $mSubSectionBeforeFields = true;
374
380 protected $displayFormat = 'table';
381
387 'table',
388 'div',
389 'raw',
390 'inline',
391 ];
392
398 'vform',
399 'codex',
400 'ooui',
401 ];
402
407 private $hiddenTitleAddedToForm = false;
408
422 public static function factory(
423 $displayFormat, $descriptor, IContextSource $context, $messagePrefix = ''
424 ) {
425 switch ( $displayFormat ) {
426 case 'codex':
427 return new CodexHTMLForm( $descriptor, $context, $messagePrefix );
428 case 'vform':
429 return new VFormHTMLForm( $descriptor, $context, $messagePrefix );
430 case 'ooui':
431 return new OOUIHTMLForm( $descriptor, $context, $messagePrefix );
432 default:
433 $form = new self( $descriptor, $context, $messagePrefix );
434 $form->setDisplayFormat( $displayFormat );
435 return $form;
436 }
437 }
438
450 public function __construct(
451 $descriptor, IContextSource $context, $messagePrefix = ''
452 ) {
453 $this->setContext( $context );
454 $this->mMessagePrefix = $messagePrefix;
455 $this->addFields( $descriptor );
456 }
457
467 public function addFields( $descriptor ) {
468 $loadedDescriptor = [];
469
470 foreach ( $descriptor as $fieldname => $info ) {
471 $section = $info['section'] ?? '';
472
473 if ( isset( $info['type'] ) && $info['type'] === 'file' ) {
474 $this->mUseMultipart = true;
475 }
476
477 $field = static::loadInputFromParameters( $fieldname, $info, $this );
478
479 $setSection =& $loadedDescriptor;
480 if ( $section ) {
481 foreach ( explode( '/', $section ) as $newName ) {
482 $setSection[$newName] ??= [];
483 $setSection =& $setSection[$newName];
484 }
485 }
486
487 $setSection[$fieldname] = $field;
488 $this->mFlatFields[$fieldname] = $field;
489 }
490
491 $this->mFieldTree = array_merge_recursive( $this->mFieldTree, $loadedDescriptor );
492
493 return $this;
494 }
495
500 public function hasField( $fieldname ) {
501 return isset( $this->mFlatFields[$fieldname] );
502 }
503
509 public function getField( $fieldname ) {
510 if ( !$this->hasField( $fieldname ) ) {
511 throw new DomainException( __METHOD__ . ': no field named ' . $fieldname );
512 }
513 return $this->mFlatFields[$fieldname];
514 }
515
525 public function setDisplayFormat( $format ) {
526 if (
527 in_array( $format, $this->availableSubclassDisplayFormats, true ) ||
528 in_array( $this->displayFormat, $this->availableSubclassDisplayFormats, true )
529 ) {
530 throw new LogicException( 'Cannot change display format after creation, ' .
531 'use HTMLForm::factory() instead' );
532 }
533
534 if ( !in_array( $format, $this->availableDisplayFormats, true ) ) {
535 throw new InvalidArgumentException( 'Display format must be one of ' .
536 print_r(
537 array_merge(
538 $this->availableDisplayFormats,
539 $this->availableSubclassDisplayFormats
540 ),
541 true
542 ) );
543 }
544
545 $this->displayFormat = $format;
546
547 return $this;
548 }
549
555 public function getDisplayFormat() {
557 }
558
575 public static function getClassFromDescriptor( $fieldname, &$descriptor ) {
576 if ( isset( $descriptor['class'] ) ) {
577 $class = $descriptor['class'];
578 } elseif ( isset( $descriptor['type'] ) ) {
579 $class = static::$typeMappings[$descriptor['type']];
580 $descriptor['class'] = $class;
581 } else {
582 $class = null;
583 }
584
585 if ( !$class ) {
586 throw new InvalidArgumentException( "Descriptor with no class for $fieldname: "
587 . print_r( $descriptor, true ) );
588 }
589
590 return $class;
591 }
592
605 public static function loadInputFromParameters( $fieldname, $descriptor,
606 HTMLForm $parent = null
607 ) {
608 $class = static::getClassFromDescriptor( $fieldname, $descriptor );
609
610 $descriptor['fieldname'] = $fieldname;
611 if ( $parent ) {
612 $descriptor['parent'] = $parent;
613 }
614
615 # @todo This will throw a fatal error whenever someone try to use
616 # 'class' to feed a CSS class instead of 'cssclass'. Would be
617 # great to avoid the fatal error and show a nice error.
618 return new $class( $descriptor );
619 }
620
629 public function prepareForm() {
630 # Load data from the request.
631 if (
632 $this->mFormIdentifier === null ||
633 $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier ||
634 ( $this->mSingleForm && $this->getMethod() === 'get' )
635 ) {
636 $this->loadFieldData();
637 } else {
638 $this->mFieldData = [];
639 }
640
641 return $this;
642 }
643
648 public function tryAuthorizedSubmit() {
649 $result = false;
650
651 if ( $this->mFormIdentifier === null ) {
652 $identOkay = true;
653 } else {
654 $identOkay = $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier;
655 }
656
657 $tokenOkay = false;
658 if ( $this->getMethod() !== 'post' ) {
659 $tokenOkay = true; // no session check needed
660 } elseif ( $this->getRequest()->wasPosted() ) {
661 $editToken = $this->getRequest()->getVal( 'wpEditToken' );
662 if ( $this->getUser()->isRegistered() || $editToken !== null ) {
663 // Session tokens for logged-out users have no security value.
664 // However, if the user gave one, check it in order to give a nice
665 // "session expired" error instead of "permission denied" or such.
666 $tokenOkay = $this->getUser()->matchEditToken( $editToken, $this->mTokenSalt );
667 } else {
668 $tokenOkay = true;
669 }
670 }
671
672 if ( $tokenOkay && $identOkay ) {
673 $this->mWasSubmitted = true;
674 $result = $this->trySubmit();
675 }
676
677 return $result;
678 }
679
687 public function show() {
688 $this->prepareForm();
689
690 $result = $this->tryAuthorizedSubmit();
691 if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
692 return $result;
693 }
694
695 $this->displayForm( $result );
696
697 return false;
698 }
699
705 public function showAlways() {
706 $this->prepareForm();
707
708 $result = $this->tryAuthorizedSubmit();
709
710 $this->displayForm( $result );
711
712 return $result;
713 }
714
726 public function trySubmit() {
727 $valid = true;
728 $hoistedErrors = Status::newGood();
729 if ( $this->mValidationErrorMessage ) {
730 foreach ( $this->mValidationErrorMessage as $error ) {
731 $hoistedErrors->fatal( ...$error );
732 }
733 } else {
734 $hoistedErrors->fatal( 'htmlform-invalid-input' );
735 }
736
737 $this->mWasSubmitted = true;
738
739 # Check for cancelled submission
740 foreach ( $this->mFlatFields as $fieldname => $field ) {
741 if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
742 continue;
743 }
744 if ( $field->cancelSubmit( $this->mFieldData[$fieldname], $this->mFieldData ) ) {
745 $this->mWasSubmitted = false;
746 return false;
747 }
748 }
749
750 # Check for validation
751 $hasNonDefault = false;
752 foreach ( $this->mFlatFields as $fieldname => $field ) {
753 if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
754 continue;
755 }
756 $hasNonDefault = $hasNonDefault || $this->mFieldData[$fieldname] !== $field->getDefault();
757 if ( $field->isDisabled( $this->mFieldData ) ) {
758 continue;
759 }
760 $res = $field->validate( $this->mFieldData[$fieldname], $this->mFieldData );
761 if ( $res !== true ) {
762 $valid = false;
763 if ( $res !== false && !$field->canDisplayErrors() ) {
764 if ( is_string( $res ) ) {
765 $hoistedErrors->fatal( 'rawmessage', $res );
766 } else {
767 $hoistedErrors->fatal( $res );
768 }
769 }
770 }
771 }
772
773 if ( !$valid ) {
774 // Treat as not submitted if got nothing from the user on GET forms.
775 if ( !$hasNonDefault && $this->getMethod() === 'get' &&
776 ( $this->mFormIdentifier === null ||
777 $this->getRequest()->getCheck( 'wpFormIdentifier' ) )
778 ) {
779 $this->mWasSubmitted = false;
780 return false;
781 }
782 return $hoistedErrors;
783 }
784
785 $callback = $this->mSubmitCallback;
786 if ( !is_callable( $callback ) ) {
787 throw new LogicException( 'HTMLForm: no submit callback provided. Use ' .
788 'setSubmitCallback() to set one.' );
789 }
790
791 $data = $this->filterDataForSubmit( $this->mFieldData );
792
793 $res = call_user_func( $callback, $data, $this );
794 if ( $res === false ) {
795 $this->mWasSubmitted = false;
796 } elseif ( $res instanceof StatusValue ) {
797 // DWIM - callbacks are not supposed to return a StatusValue but it's easy to mix up.
798 $res = Status::wrap( $res );
799 }
800
801 return $res;
802 }
803
815 public function wasSubmitted() {
817 }
818
829 public function setSubmitCallback( $cb ) {
830 $this->mSubmitCallback = $cb;
831
832 return $this;
833 }
834
844 public function setValidationErrorMessage( $msg ) {
845 $this->mValidationErrorMessage = $msg;
846
847 return $this;
848 }
849
858 public function setIntro( $msg ) {
859 return $this->setPreHtml( $msg );
860 }
861
870 public function setPreHtml( $html ) {
871 $this->mPre = $html;
872
873 return $this;
874 }
875
884 public function addPreHtml( $html ) {
885 $this->mPre .= $html;
886
887 return $this;
888 }
889
896 public function getPreHtml() {
897 return $this->mPre;
898 }
899
908 public function setPreText( $msg ) {
909 return $this->setPreHtml( $msg );
910 }
911
920 public function addPreText( $msg ) {
921 return $this->addPreHtml( $msg );
922 }
923
931 public function getPreText() {
932 return $this->getPreHtml();
933 }
934
944 public function addHeaderHtml( $html, $section = null ) {
945 if ( $section === null ) {
946 $this->mHeader .= $html;
947 } else {
948 $this->mSectionHeaders[$section] ??= '';
949 $this->mSectionHeaders[$section] .= $html;
950 }
951
952 return $this;
953 }
954
964 public function setHeaderHtml( $html, $section = null ) {
965 if ( $section === null ) {
966 $this->mHeader = $html;
967 } else {
968 $this->mSectionHeaders[$section] = $html;
969 }
970
971 return $this;
972 }
973
982 public function getHeaderHtml( $section = null ) {
983 return $section ? $this->mSectionHeaders[$section] ?? '' : $this->mHeader;
984 }
985
995 public function addHeaderText( $msg, $section = null ) {
996 return $this->addHeaderHtml( $msg, $section );
997 }
998
1009 public function setHeaderText( $msg, $section = null ) {
1010 return $this->setHeaderHtml( $msg, $section );
1011 }
1012
1022 public function getHeaderText( $section = null ) {
1023 return $this->getHeaderHtml( $section );
1024 }
1025
1035 public function addFooterHtml( $html, $section = null ) {
1036 if ( $section === null ) {
1037 $this->mFooter .= $html;
1038 } else {
1039 $this->mSectionFooters[$section] ??= '';
1040 $this->mSectionFooters[$section] .= $html;
1041 }
1042
1043 return $this;
1044 }
1045
1055 public function setFooterHtml( $html, $section = null ) {
1056 if ( $section === null ) {
1057 $this->mFooter = $html;
1058 } else {
1059 $this->mSectionFooters[$section] = $html;
1060 }
1061
1062 return $this;
1063 }
1064
1072 public function getFooterHtml( $section = null ) {
1073 return $section ? $this->mSectionFooters[$section] ?? '' : $this->mFooter;
1074 }
1075
1085 public function addFooterText( $msg, $section = null ) {
1086 return $this->addFooterHtml( $msg, $section );
1087 }
1088
1099 public function setFooterText( $msg, $section = null ) {
1100 return $this->setFooterHtml( $msg, $section );
1101 }
1102
1111 public function getFooterText( $section = null ) {
1112 return $this->getFooterHtml( $section );
1113 }
1114
1123 public function addPostHtml( $html ) {
1124 $this->mPost .= $html;
1125
1126 return $this;
1127 }
1128
1137 public function setPostHtml( $html ) {
1138 $this->mPost = $html;
1139
1140 return $this;
1141 }
1142
1149 public function getPostHtml() {
1150 return $this->mPost;
1151 }
1152
1161 public function addPostText( $msg ) {
1162 return $this->addPostHtml( $msg );
1163 }
1164
1173 public function setPostText( $msg ) {
1174 return $this->setPostHtml( $msg );
1175 }
1176
1186 public function setSections( $sections ) {
1187 if ( $this->getDisplayFormat() !== 'codex' ) {
1188 throw new \InvalidArgumentException(
1189 "Non-Codex HTMLForms do not support additional section information."
1190 );
1191 }
1192
1193 $this->mSections = $sections;
1194
1195 return $this;
1196 }
1197
1208 public function addHiddenField( $name, $value, array $attribs = [] ) {
1209 if ( !is_array( $value ) ) {
1210 // Per WebRequest::getVal: Array values are discarded for security reasons.
1211 $attribs += [ 'name' => $name ];
1212 $this->mHiddenFields[] = [ $value, $attribs ];
1213 }
1214
1215 return $this;
1216 }
1217
1229 public function addHiddenFields( array $fields ) {
1230 foreach ( $fields as $name => $value ) {
1231 if ( is_array( $value ) ) {
1232 // Per WebRequest::getVal: Array values are discarded for security reasons.
1233 continue;
1234 }
1235 $this->mHiddenFields[] = [ $value, [ 'name' => $name ] ];
1236 }
1237
1238 return $this;
1239 }
1240
1264 public function addButton( $data ) {
1265 if ( !is_array( $data ) ) {
1266 $args = func_get_args();
1267 if ( count( $args ) < 2 || count( $args ) > 4 ) {
1268 throw new InvalidArgumentException(
1269 'Incorrect number of arguments for deprecated calling style'
1270 );
1271 }
1272 $data = [
1273 'name' => $args[0],
1274 'value' => $args[1],
1275 'id' => $args[2] ?? null,
1276 'attribs' => $args[3] ?? null,
1277 ];
1278 } else {
1279 if ( !isset( $data['name'] ) ) {
1280 throw new InvalidArgumentException( 'A name is required' );
1281 }
1282 if ( !isset( $data['value'] ) ) {
1283 throw new InvalidArgumentException( 'A value is required' );
1284 }
1285 }
1286 $this->mButtons[] = $data + [
1287 'id' => null,
1288 'attribs' => null,
1289 'flags' => null,
1290 'framed' => true,
1291 ];
1292
1293 return $this;
1294 }
1295
1305 public function setTokenSalt( $salt ) {
1306 $this->mTokenSalt = $salt;
1307
1308 return $this;
1309 }
1310
1325 public function displayForm( $submitResult ) {
1326 $this->getOutput()->addHTML( $this->getHTML( $submitResult ) );
1327 }
1328
1333 private function getHiddenTitle(): string {
1334 if ( $this->hiddenTitleAddedToForm ) {
1335 return '';
1336 }
1337
1338 $html = '';
1339 if ( $this->getMethod() === 'post' ||
1340 $this->getAction() === $this->getConfig()->get( MainConfigNames::Script )
1341 ) {
1342 $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1343 }
1344 $this->hiddenTitleAddedToForm = true;
1345 return $html;
1346 }
1347
1358 public function getHTML( $submitResult ) {
1359 # For good measure (it is the default)
1360 $this->getOutput()->setPreventClickjacking( true );
1361 $this->getOutput()->addModules( 'mediawiki.htmlform' );
1362 $this->getOutput()->addModuleStyles( 'mediawiki.htmlform.styles' );
1363
1364 if ( $this->mCollapsible ) {
1365 // Preload jquery.makeCollapsible for mediawiki.htmlform
1366 $this->getOutput()->addModules( 'jquery.makeCollapsible' );
1367 }
1368
1369 $html = $this->getErrorsOrWarnings( $submitResult, 'error' )
1370 . $this->getErrorsOrWarnings( $submitResult, 'warning' )
1371 . $this->getHeaderText()
1372 . $this->getHiddenTitle()
1373 . $this->getBody()
1374 . $this->getHiddenFields()
1375 . $this->getButtons()
1376 . $this->getFooterText();
1377
1378 return $this->mPre . $this->wrapForm( $html ) . $this->mPost;
1379 }
1380
1388 public function setCollapsibleOptions( $collapsedByDefault = false ) {
1389 $this->mCollapsible = true;
1390 $this->mCollapsed = $collapsedByDefault;
1391 return $this;
1392 }
1393
1399 protected function getFormAttributes() {
1400 # Use multipart/form-data
1401 $encType = $this->mUseMultipart
1402 ? 'multipart/form-data'
1403 : 'application/x-www-form-urlencoded';
1404 # Attributes
1405 $attribs = [
1406 'class' => 'mw-htmlform',
1407 'action' => $this->getAction(),
1408 'method' => $this->getMethod(),
1409 'enctype' => $encType,
1410 ];
1411 if ( $this->mId ) {
1412 $attribs['id'] = $this->mId;
1413 }
1414 if ( is_string( $this->mAutocomplete ) ) {
1415 $attribs['autocomplete'] = $this->mAutocomplete;
1416 }
1417 if ( $this->mName ) {
1418 $attribs['name'] = $this->mName;
1419 }
1420 if ( $this->needsJSForHtml5FormValidation() ) {
1421 $attribs['novalidate'] = true;
1422 }
1423 return $attribs;
1424 }
1425
1433 public function wrapForm( $html ) {
1434 # Include a <fieldset> wrapper for style, if requested.
1435 if ( $this->mWrapperLegend !== false ) {
1436 $legend = is_string( $this->mWrapperLegend ) ? $this->mWrapperLegend : false;
1437 $html = Xml::fieldset( $legend, $html, $this->mWrapperAttributes );
1438 }
1439
1440 return Html::rawElement(
1441 'form',
1442 $this->getFormAttributes(),
1443 $html
1444 );
1445 }
1446
1451 public function getHiddenFields() {
1452 $html = '';
1453
1454 // add the title as a hidden file if it hasn't been added yet and if it is necessary
1455 // added for backward compatibility with the previous version of this public method
1456 $html .= $this->getHiddenTitle();
1457
1458 if ( $this->mFormIdentifier !== null ) {
1459 $html .= Html::hidden(
1460 'wpFormIdentifier',
1461 $this->mFormIdentifier
1462 ) . "\n";
1463 }
1464 if ( $this->getMethod() === 'post' ) {
1465 $html .= Html::hidden(
1466 'wpEditToken',
1467 $this->getUser()->getEditToken( $this->mTokenSalt ),
1468 [ 'id' => 'wpEditToken' ]
1469 ) . "\n";
1470 }
1471
1472 foreach ( $this->mHiddenFields as [ $value, $attribs ] ) {
1473 $html .= Html::hidden( $attribs['name'], $value, $attribs ) . "\n";
1474 }
1475
1476 return $html;
1477 }
1478
1484 public function getButtons() {
1485 $buttons = '';
1486
1487 if ( $this->mShowSubmit ) {
1488 $attribs = [];
1489
1490 if ( isset( $this->mSubmitID ) ) {
1491 $attribs['id'] = $this->mSubmitID;
1492 }
1493
1494 if ( isset( $this->mSubmitName ) ) {
1495 $attribs['name'] = $this->mSubmitName;
1496 }
1497
1498 if ( isset( $this->mSubmitTooltip ) ) {
1499 $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
1500 }
1501
1502 $attribs['class'] = [ 'mw-htmlform-submit' ];
1503
1504 $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
1505 }
1506
1507 if ( $this->mShowReset ) {
1508 $buttons .= Html::element(
1509 'input',
1510 [
1511 'type' => 'reset',
1512 'value' => $this->msg( 'htmlform-reset' )->text(),
1513 ]
1514 ) . "\n";
1515 }
1516
1517 if ( $this->mShowCancel ) {
1518 $target = $this->getCancelTargetURL();
1519 $buttons .= Html::element(
1520 'a',
1521 [
1522 'href' => $target,
1523 ],
1524 $this->msg( 'cancel' )->text()
1525 ) . "\n";
1526 }
1527
1528 foreach ( $this->mButtons as $button ) {
1529 $attrs = [
1530 'type' => 'submit',
1531 'name' => $button['name'],
1532 'value' => $button['value']
1533 ];
1534
1535 if ( isset( $button['label-message'] ) ) {
1536 $label = $this->getMessage( $button['label-message'] )->parse();
1537 } elseif ( isset( $button['label'] ) ) {
1538 $label = htmlspecialchars( $button['label'] );
1539 } elseif ( isset( $button['label-raw'] ) ) {
1540 $label = $button['label-raw'];
1541 } else {
1542 $label = htmlspecialchars( $button['value'] );
1543 }
1544
1545 // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset Always set in self::addButton
1546 if ( $button['attribs'] ) {
1547 // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset Always set in self::addButton
1548 $attrs += $button['attribs'];
1549 }
1550
1551 if ( isset( $button['id'] ) ) {
1552 $attrs['id'] = $button['id'];
1553 }
1554
1555 $buttons .= Html::rawElement( 'button', $attrs, $label ) . "\n";
1556 }
1557
1558 if ( !$buttons ) {
1559 return '';
1560 }
1561
1562 return Html::rawElement( 'span',
1563 [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n";
1564 }
1565
1571 public function getBody() {
1572 return $this->displaySection( $this->mFieldTree, $this->mTableId );
1573 }
1574
1584 public function getErrorsOrWarnings( $elements, $elementsType ) {
1585 if ( !in_array( $elementsType, [ 'error', 'warning' ], true ) ) {
1586 throw new DomainException( $elementsType . ' is not a valid type.' );
1587 }
1588 $elementstr = false;
1589 if ( $elements instanceof Status ) {
1590 [ $errorStatus, $warningStatus ] = $elements->splitByErrorType();
1591 $status = $elementsType === 'error' ? $errorStatus : $warningStatus;
1592 if ( $status->isGood() ) {
1593 $elementstr = '';
1594 } else {
1595 $elementstr = $status
1596 ->getMessage()
1597 ->setContext( $this )
1598 ->setInterfaceMessageFlag( true )
1599 ->parse();
1600 }
1601 } elseif ( $elementsType === 'error' ) {
1602 if ( is_array( $elements ) ) {
1603 $elementstr = $this->formatErrors( $elements );
1604 } elseif ( $elements && $elements !== true ) {
1605 $elementstr = (string)$elements;
1606 }
1607 }
1608
1609 if ( !$elementstr ) {
1610 return '';
1611 } elseif ( $elementsType === 'error' ) {
1612 return Html::errorBox( $elementstr );
1613 } else { // $elementsType can only be 'warning'
1614 return Html::warningBox( $elementstr );
1615 }
1616 }
1617
1625 public function formatErrors( $errors ) {
1626 $errorstr = '';
1627
1628 foreach ( $errors as $error ) {
1629 $errorstr .= Html::rawElement(
1630 'li',
1631 [],
1632 $this->getMessage( $error )->parse()
1633 );
1634 }
1635
1636 return Html::rawElement( 'ul', [], $errorstr );
1637 }
1638
1646 public function setSubmitText( $t ) {
1647 $this->mSubmitText = $t;
1648
1649 return $this;
1650 }
1651
1658 public function setSubmitDestructive() {
1659 $this->mSubmitFlags = [ 'destructive', 'primary' ];
1660
1661 return $this;
1662 }
1663
1672 public function setSubmitTextMsg( $msg ) {
1673 if ( !$msg instanceof Message ) {
1674 $msg = $this->msg( $msg );
1675 }
1676 $this->setSubmitText( $msg->text() );
1677
1678 return $this;
1679 }
1680
1685 public function getSubmitText() {
1686 return $this->mSubmitText ?: $this->msg( 'htmlform-submit' )->text();
1687 }
1688
1694 public function setSubmitName( $name ) {
1695 $this->mSubmitName = $name;
1696
1697 return $this;
1698 }
1699
1705 public function setSubmitTooltip( $name ) {
1706 $this->mSubmitTooltip = $name;
1707
1708 return $this;
1709 }
1710
1719 public function setSubmitID( $t ) {
1720 $this->mSubmitID = $t;
1721
1722 return $this;
1723 }
1724
1743 public function setFormIdentifier( string $ident, bool $single = false ) {
1744 $this->mFormIdentifier = $ident;
1745 $this->mSingleForm = $single;
1746
1747 return $this;
1748 }
1749
1760 public function suppressDefaultSubmit( $suppressSubmit = true ) {
1761 $this->mShowSubmit = !$suppressSubmit;
1762
1763 return $this;
1764 }
1765
1772 public function showCancel( $show = true ) {
1773 $this->mShowCancel = $show;
1774 return $this;
1775 }
1776
1783 public function setCancelTarget( $target ) {
1784 if ( $target instanceof PageReference ) {
1785 $target = TitleValue::castPageToLinkTarget( $target );
1786 }
1787
1788 $this->mCancelTarget = $target;
1789 return $this;
1790 }
1791
1796 protected function getCancelTargetURL() {
1797 if ( is_string( $this->mCancelTarget ) ) {
1798 return $this->mCancelTarget;
1799 } else {
1800 // TODO: use a service to get the local URL for a LinkTarget, see T282283
1801 $target = Title::castFromLinkTarget( $this->mCancelTarget ) ?: Title::newMainPage();
1802 return $target->getLocalURL();
1803 }
1804 }
1805
1815 public function setTableId( $id ) {
1816 $this->mTableId = $id;
1817
1818 return $this;
1819 }
1820
1826 public function setId( $id ) {
1827 $this->mId = $id;
1828
1829 return $this;
1830 }
1831
1836 public function setName( $name ) {
1837 $this->mName = $name;
1838
1839 return $this;
1840 }
1841
1853 public function setWrapperLegend( $legend ) {
1854 $this->mWrapperLegend = $legend;
1855
1856 return $this;
1857 }
1858
1866 public function setWrapperAttributes( $attributes ) {
1867 $this->mWrapperAttributes = $attributes;
1868
1869 return $this;
1870 }
1871
1881 public function setWrapperLegendMsg( $msg ) {
1882 if ( !$msg instanceof Message ) {
1883 $msg = $this->msg( $msg );
1884 }
1885 $this->setWrapperLegend( $msg->text() );
1886
1887 return $this;
1888 }
1889
1899 public function setMessagePrefix( $p ) {
1900 $this->mMessagePrefix = $p;
1901
1902 return $this;
1903 }
1904
1912 public function setTitle( $t ) {
1913 // TODO: make mTitle a PageReference when we have a better way to get URLs, see T282283.
1914 $this->mTitle = Title::castFromPageReference( $t );
1915
1916 return $this;
1917 }
1918
1922 public function getTitle() {
1923 return $this->mTitle ?: $this->getContext()->getTitle();
1924 }
1925
1933 public function setMethod( $method = 'post' ) {
1934 $this->mMethod = strtolower( $method );
1935
1936 return $this;
1937 }
1938
1942 public function getMethod() {
1943 return $this->mMethod;
1944 }
1945
1956 protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
1957 return Xml::fieldset( $legend, $section, $attributes ) . "\n";
1958 }
1959
1977 public function displaySection( $fields,
1978 $sectionName = '',
1979 $fieldsetIDPrefix = '',
1980 &$hasUserVisibleFields = false
1981 ) {
1982 if ( $this->mFieldData === null ) {
1983 throw new LogicException( 'HTMLForm::displaySection() called on uninitialized field data. '
1984 . 'You probably called displayForm() without calling prepareForm() first.' );
1985 }
1986
1987 $html = [];
1988 $subsectionHtml = '';
1989 $hasLabel = false;
1990
1991 foreach ( $fields as $key => $value ) {
1992 if ( $value instanceof HTMLFormField ) {
1993 $v = array_key_exists( $key, $this->mFieldData )
1994 ? $this->mFieldData[$key]
1995 : $value->getDefault();
1996
1997 $retval = $this->formatField( $value, $v ?? '' );
1998
1999 // check, if the form field should be added to
2000 // the output.
2001 if ( $value->hasVisibleOutput() ) {
2002 $html[] = $retval;
2003
2004 $labelValue = trim( $value->getLabel() );
2005 if ( $labelValue !== "\u{00A0}" && $labelValue !== '&#160;' && $labelValue !== '' ) {
2006 $hasLabel = true;
2007 }
2008
2009 $hasUserVisibleFields = true;
2010 }
2011 } elseif ( is_array( $value ) ) {
2012 $subsectionHasVisibleFields = false;
2013 $section =
2014 $this->displaySection( $value,
2015 "mw-htmlform-$key",
2016 "$fieldsetIDPrefix$key-",
2017 $subsectionHasVisibleFields );
2018
2019 if ( $subsectionHasVisibleFields === true ) {
2020 // Display the section with various niceties.
2021 $hasUserVisibleFields = true;
2022
2023 $legend = $this->getLegend( $key );
2024
2025 $section = $this->getHeaderText( $key ) .
2026 $section .
2027 $this->getFooterText( $key );
2028
2029 $attributes = [];
2030 if ( $fieldsetIDPrefix ) {
2031 $attributes['id'] = Sanitizer::escapeIdForAttribute( "$fieldsetIDPrefix$key" );
2032 }
2033 $subsectionHtml .= $this->wrapFieldSetSection(
2034 $legend, $section, $attributes, $fields === $this->mFieldTree
2035 );
2036 } else {
2037 // Just return the inputs, nothing fancy.
2038 $subsectionHtml .= $section;
2039 }
2040 }
2041 }
2042
2043 $html = $this->formatSection( $html, $sectionName, $hasLabel );
2044
2045 if ( $subsectionHtml ) {
2046 if ( $this->mSubSectionBeforeFields ) {
2047 return $subsectionHtml . "\n" . $html;
2048 } else {
2049 return $html . "\n" . $subsectionHtml;
2050 }
2051 } else {
2052 return $html;
2053 }
2054 }
2055
2064 protected function formatField( HTMLFormField $field, $value ) {
2065 $displayFormat = $this->getDisplayFormat();
2066 switch ( $displayFormat ) {
2067 case 'table':
2068 return $field->getTableRow( $value );
2069 case 'div':
2070 return $field->getDiv( $value );
2071 case 'raw':
2072 return $field->getRaw( $value );
2073 case 'inline':
2074 return $field->getInline( $value );
2075 default:
2076 throw new LogicException( 'Not implemented' );
2077 }
2078 }
2079
2088 protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
2089 if ( !$fieldsHtml ) {
2090 // Do not generate any wrappers for empty sections. Sections may be empty if they only have
2091 // subsections, but no fields. A legend will still be added in wrapFieldSetSection().
2092 return '';
2093 }
2094
2095 $displayFormat = $this->getDisplayFormat();
2096 $html = implode( '', $fieldsHtml );
2097
2098 if ( $displayFormat === 'raw' ) {
2099 return $html;
2100 }
2101
2102 // Avoid strange spacing when no labels exist
2103 $attribs = $anyFieldHasLabel ? [] : [ 'class' => 'mw-htmlform-nolabel' ];
2104
2105 if ( $sectionName ) {
2106 $attribs['id'] = Sanitizer::escapeIdForAttribute( $sectionName );
2107 }
2108
2109 if ( $displayFormat === 'table' ) {
2110 return Html::rawElement( 'table',
2111 $attribs,
2112 Html::rawElement( 'tbody', [], "\n$html\n" ) ) . "\n";
2113 } elseif ( $displayFormat === 'inline' ) {
2114 return Html::rawElement( 'span', $attribs, "\n$html\n" );
2115 } else {
2116 return Html::rawElement( 'div', $attribs, "\n$html\n" );
2117 }
2118 }
2119
2123 public function loadData() {
2124 $this->prepareForm();
2125 }
2126
2130 protected function loadFieldData() {
2131 $fieldData = [];
2132 $request = $this->getRequest();
2133
2134 foreach ( $this->mFlatFields as $fieldname => $field ) {
2135 if ( $field->skipLoadData( $request ) ) {
2136 continue;
2137 }
2138 if ( $field->mParams['disabled'] ?? false ) {
2139 $fieldData[$fieldname] = $field->getDefault();
2140 } else {
2141 $fieldData[$fieldname] = $field->loadDataFromRequest( $request );
2142 }
2143 }
2144
2145 // Reset to default for fields that are supposed to be disabled.
2146 // FIXME: Handle dependency chains, fields that a field checks on may need a reset too.
2147 foreach ( $fieldData as $name => &$value ) {
2148 $field = $this->mFlatFields[$name];
2149 if ( $field->isDisabled( $fieldData ) ) {
2150 $value = $field->getDefault();
2151 }
2152 }
2153
2154 # Filter data.
2155 foreach ( $fieldData as $name => &$value ) {
2156 $field = $this->mFlatFields[$name];
2157 $value = $field->filter( $value, $fieldData );
2158 }
2159
2160 $this->mFieldData = $fieldData;
2161 }
2162
2170 public function suppressReset( $suppressReset = true ) {
2171 $this->mShowReset = !$suppressReset;
2172
2173 return $this;
2174 }
2175
2186 public function filterDataForSubmit( $data ) {
2187 return $data;
2188 }
2189
2199 public function getLegend( $key ) {
2200 return $this->msg( $this->mMessagePrefix ? "{$this->mMessagePrefix}-$key" : $key )->text();
2201 }
2202
2213 public function setAction( $action ) {
2214 $this->mAction = $action;
2215
2216 return $this;
2217 }
2218
2226 public function getAction() {
2227 // If an action is already provided, return it
2228 if ( $this->mAction !== false ) {
2229 return $this->mAction;
2230 }
2231
2232 $articlePath = $this->getConfig()->get( MainConfigNames::ArticlePath );
2233 // Check whether we are in GET mode and the ArticlePath contains a "?"
2234 // meaning that getLocalURL() would return something like "index.php?title=...".
2235 // As browser remove the query string before submitting GET forms,
2236 // it means that the title would be lost. In such case use script path instead
2237 // and put title in a hidden field (see getHiddenFields()).
2238 if ( str_contains( $articlePath, '?' ) && $this->getMethod() === 'get' ) {
2239 return $this->getConfig()->get( MainConfigNames::Script );
2240 }
2241
2242 return $this->getTitle()->getLocalURL();
2243 }
2244
2255 public function setAutocomplete( $autocomplete ) {
2256 $this->mAutocomplete = $autocomplete;
2257
2258 return $this;
2259 }
2260
2267 protected function getMessage( $value ) {
2268 return Message::newFromSpecifier( $value )->setContext( $this );
2269 }
2270
2281 foreach ( $this->mFlatFields as $field ) {
2282 if ( $field->needsJSForHtml5FormValidation() ) {
2283 return true;
2284 }
2285 }
2286 return false;
2287 }
2288}
2289
2291class_alias( HTMLForm::class, 'HTMLForm' );
getUser()
getRequest()
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)
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:206
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:964
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:363
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.
Definition HTMLForm.php:995
getHeaderHtml( $section=null)
Get header HTML.
Definition HTMLForm.php:982
bool $mCollapsed
Whether the form is collapsed by default.
Definition HTMLForm.php:321
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:726
array $availableSubclassDisplayFormats
Available formats in which to display the form.
Definition HTMLForm.php:397
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:870
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:858
loadFieldData()
Load data of form fields from the request.
tryAuthorizedSubmit()
Try submitting, with edit token check first.
Definition HTMLForm.php:648
wasSubmitted()
Test whether the form was considered to have been submitted or not, i.e.
Definition HTMLForm.php:815
getFormAttributes()
Get HTML attributes for the <form> tag.
static getClassFromDescriptor( $fieldname, &$descriptor)
Get the HTMLFormField subclass for this descriptor.
Definition HTMLForm.php:575
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
prepareForm()
Prepare form for submission.
Definition HTMLForm.php:629
bool $mCollapsible
Whether the form can be collapsed.
Definition HTMLForm.php:314
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:373
string $displayFormat
Format in which to display form.
Definition HTMLForm.php:380
addPreText( $msg)
Add HTML to introductory message.
Definition HTMLForm.php:920
setWrapperAttributes( $attributes)
For internal use only.
string null $mAutocomplete
Form attribute autocomplete.
Definition HTMLForm.php:328
getDisplayFormat()
Getter for displayFormat.
Definition HTMLForm.php:555
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:525
string array $mTokenSalt
Salt for the edit token.
Definition HTMLForm.php:349
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:605
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:705
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
addFields( $descriptor)
Add fields to the form.
Definition HTMLForm.php:467
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:829
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:687
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:844
HTMLFormField[] $mFlatFields
Definition HTMLForm.php:263
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.
suppressReset( $suppressReset=true)
Stop a reset button being shown for this form.
addPreHtml( $html)
Add HTML to introductory message.
Definition HTMLForm.php:884
setSubmitID( $t)
Set the id for the submit button.
getPreText()
Get the introductory message HTML.
Definition HTMLForm.php:931
array $availableDisplayFormats
Available formats in which to display the form.
Definition HTMLForm.php:386
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:944
static factory( $displayFormat, $descriptor, IContextSource $context, $messagePrefix='')
Construct a HTMLForm object for given display type.
Definition HTMLForm.php:422
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:908
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:896
getButtons()
Get the submit and (potentially) reset buttons.
static string[] $typeMappings
A mapping of 'type' inputs onto standard HTMLFormField subclasses.
Definition HTMLForm.php:210
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:450
string false $mAction
Form action URL.
Definition HTMLForm.php:307
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
Some internal bits split of from Skin.php.
Definition Linker.php:65
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:157
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition Message.php:453
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
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.
Module of static functions for generating XML.
Definition Xml.php:33
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)