MediaWiki master
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;
80use StatusValue;
81use Stringable;
82
207class HTMLForm extends ContextSource {
208 use ProtectedHookAccessorTrait;
209
211 public static $typeMappings = [
212 'api' => HTMLApiField::class,
213 'text' => HTMLTextField::class,
214 'textwithbutton' => HTMLTextFieldWithButton::class,
215 'textarea' => HTMLTextAreaField::class,
216 'select' => HTMLSelectField::class,
217 'combobox' => HTMLComboboxField::class,
218 'radio' => HTMLRadioField::class,
219 'multiselect' => HTMLMultiSelectField::class,
220 'limitselect' => HTMLSelectLimitField::class,
221 'check' => HTMLCheckField::class,
222 'toggle' => HTMLCheckField::class,
223 'int' => HTMLIntField::class,
224 'file' => HTMLFileField::class,
225 'float' => HTMLFloatField::class,
226 'info' => HTMLInfoField::class,
227 'selectorother' => HTMLSelectOrOtherField::class,
228 'selectandother' => HTMLSelectAndOtherField::class,
229 'namespaceselect' => HTMLSelectNamespace::class,
230 'namespaceselectwithbutton' => HTMLSelectNamespaceWithButton::class,
231 'tagfilter' => HTMLTagFilter::class,
232 'sizefilter' => HTMLSizeFilterField::class,
233 'submit' => HTMLSubmitField::class,
234 'hidden' => HTMLHiddenField::class,
235 'edittools' => HTMLEditTools::class,
236 'checkmatrix' => HTMLCheckMatrix::class,
237 'cloner' => HTMLFormFieldCloner::class,
238 'autocompleteselect' => HTMLAutoCompleteSelectField::class,
239 'language' => HTMLSelectLanguageField::class,
240 'date' => HTMLDateTimeField::class,
241 'time' => HTMLDateTimeField::class,
242 'datetime' => HTMLDateTimeField::class,
243 'expiry' => HTMLExpiryField::class,
244 'timezone' => HTMLTimezoneField::class,
245 // HTMLTextField will output the correct type="" attribute automagically.
246 // There are about four zillion other HTML5 input types, like range, but
247 // we don't use those at the moment, so no point in adding all of them.
248 'email' => HTMLTextField::class,
249 'password' => HTMLTextField::class,
250 'url' => HTMLTextField::class,
251 'title' => HTMLTitleTextField::class,
252 'user' => HTMLUserTextField::class,
253 'tagmultiselect' => HTMLTagMultiselectField::class,
254 'usersmultiselect' => HTMLUsersMultiselectField::class,
255 'titlesmultiselect' => HTMLTitlesMultiselectField::class,
256 'namespacesmultiselect' => HTMLNamespacesMultiselectField::class,
257 ];
258
260
262
264 protected $mFlatFields = [];
265 protected $mFieldTree = [];
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->mShowCancel ) {
1508 $target = $this->getCancelTargetURL();
1509 $buttons .= Html::element(
1510 'a',
1511 [
1512 'href' => $target,
1513 ],
1514 $this->msg( 'cancel' )->text()
1515 ) . "\n";
1516 }
1517
1518 foreach ( $this->mButtons as $button ) {
1519 $attrs = [
1520 'type' => 'submit',
1521 'name' => $button['name'],
1522 'value' => $button['value']
1523 ];
1524
1525 if ( isset( $button['label-message'] ) ) {
1526 $label = $this->getMessage( $button['label-message'] )->parse();
1527 } elseif ( isset( $button['label'] ) ) {
1528 $label = htmlspecialchars( $button['label'] );
1529 } elseif ( isset( $button['label-raw'] ) ) {
1530 $label = $button['label-raw'];
1531 } else {
1532 $label = htmlspecialchars( $button['value'] );
1533 }
1534
1535 // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset Always set in self::addButton
1536 if ( $button['attribs'] ) {
1537 // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset Always set in self::addButton
1538 $attrs += $button['attribs'];
1539 }
1540
1541 if ( isset( $button['id'] ) ) {
1542 $attrs['id'] = $button['id'];
1543 }
1544
1545 $buttons .= Html::rawElement( 'button', $attrs, $label ) . "\n";
1546 }
1547
1548 if ( !$buttons ) {
1549 return '';
1550 }
1551
1552 return Html::rawElement( 'span',
1553 [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n";
1554 }
1555
1561 public function getBody() {
1562 return $this->displaySection( $this->mFieldTree, $this->mTableId );
1563 }
1564
1574 public function getErrorsOrWarnings( $elements, $elementsType ) {
1575 if ( !in_array( $elementsType, [ 'error', 'warning' ], true ) ) {
1576 throw new DomainException( $elementsType . ' is not a valid type.' );
1577 }
1578 $elementstr = false;
1579 if ( $elements instanceof Status ) {
1580 [ $errorStatus, $warningStatus ] = $elements->splitByErrorType();
1581 $status = $elementsType === 'error' ? $errorStatus : $warningStatus;
1582 if ( $status->isGood() ) {
1583 $elementstr = '';
1584 } else {
1585 $elementstr = $status
1586 ->getMessage()
1587 ->setContext( $this )
1588 ->setInterfaceMessageFlag( true )
1589 ->parse();
1590 }
1591 } elseif ( $elementsType === 'error' ) {
1592 if ( is_array( $elements ) ) {
1593 $elementstr = $this->formatErrors( $elements );
1594 } elseif ( $elements && $elements !== true ) {
1595 $elementstr = (string)$elements;
1596 }
1597 }
1598
1599 if ( !$elementstr ) {
1600 return '';
1601 } elseif ( $elementsType === 'error' ) {
1602 return Html::errorBox( $elementstr );
1603 } else { // $elementsType can only be 'warning'
1604 return Html::warningBox( $elementstr );
1605 }
1606 }
1607
1615 public function formatErrors( $errors ) {
1616 $errorstr = '';
1617
1618 foreach ( $errors as $error ) {
1619 $errorstr .= Html::rawElement(
1620 'li',
1621 [],
1622 $this->getMessage( $error )->parse()
1623 );
1624 }
1625
1626 return Html::rawElement( 'ul', [], $errorstr );
1627 }
1628
1636 public function setSubmitText( $t ) {
1637 $this->mSubmitText = $t;
1638
1639 return $this;
1640 }
1641
1648 public function setSubmitDestructive() {
1649 $this->mSubmitFlags = [ 'destructive', 'primary' ];
1650
1651 return $this;
1652 }
1653
1662 public function setSubmitTextMsg( $msg ) {
1663 if ( !$msg instanceof Message ) {
1664 $msg = $this->msg( $msg );
1665 }
1666 $this->setSubmitText( $msg->text() );
1667
1668 return $this;
1669 }
1670
1675 public function getSubmitText() {
1676 return $this->mSubmitText ?: $this->msg( 'htmlform-submit' )->text();
1677 }
1678
1684 public function setSubmitName( $name ) {
1685 $this->mSubmitName = $name;
1686
1687 return $this;
1688 }
1689
1695 public function setSubmitTooltip( $name ) {
1696 $this->mSubmitTooltip = $name;
1697
1698 return $this;
1699 }
1700
1709 public function setSubmitID( $t ) {
1710 $this->mSubmitID = $t;
1711
1712 return $this;
1713 }
1714
1733 public function setFormIdentifier( string $ident, bool $single = false ) {
1734 $this->mFormIdentifier = $ident;
1735 $this->mSingleForm = $single;
1736
1737 return $this;
1738 }
1739
1750 public function suppressDefaultSubmit( $suppressSubmit = true ) {
1751 $this->mShowSubmit = !$suppressSubmit;
1752
1753 return $this;
1754 }
1755
1762 public function showCancel( $show = true ) {
1763 $this->mShowCancel = $show;
1764 return $this;
1765 }
1766
1773 public function setCancelTarget( $target ) {
1774 if ( $target instanceof PageReference ) {
1775 $target = TitleValue::castPageToLinkTarget( $target );
1776 }
1777
1778 $this->mCancelTarget = $target;
1779 return $this;
1780 }
1781
1786 protected function getCancelTargetURL() {
1787 if ( is_string( $this->mCancelTarget ) ) {
1788 return $this->mCancelTarget;
1789 } else {
1790 // TODO: use a service to get the local URL for a LinkTarget, see T282283
1791 $target = Title::castFromLinkTarget( $this->mCancelTarget ) ?: Title::newMainPage();
1792 return $target->getLocalURL();
1793 }
1794 }
1795
1805 public function setTableId( $id ) {
1806 $this->mTableId = $id;
1807
1808 return $this;
1809 }
1810
1816 public function setId( $id ) {
1817 $this->mId = $id;
1818
1819 return $this;
1820 }
1821
1826 public function setName( $name ) {
1827 $this->mName = $name;
1828
1829 return $this;
1830 }
1831
1843 public function setWrapperLegend( $legend ) {
1844 $this->mWrapperLegend = $legend;
1845
1846 return $this;
1847 }
1848
1856 public function setWrapperAttributes( $attributes ) {
1857 $this->mWrapperAttributes = $attributes;
1858
1859 return $this;
1860 }
1861
1871 public function setWrapperLegendMsg( $msg ) {
1872 if ( !$msg instanceof Message ) {
1873 $msg = $this->msg( $msg );
1874 }
1875 $this->setWrapperLegend( $msg->text() );
1876
1877 return $this;
1878 }
1879
1889 public function setMessagePrefix( $p ) {
1890 $this->mMessagePrefix = $p;
1891
1892 return $this;
1893 }
1894
1902 public function setTitle( $t ) {
1903 // TODO: make mTitle a PageReference when we have a better way to get URLs, see T282283.
1904 $this->mTitle = Title::castFromPageReference( $t );
1905
1906 return $this;
1907 }
1908
1912 public function getTitle() {
1913 return $this->mTitle ?: $this->getContext()->getTitle();
1914 }
1915
1923 public function setMethod( $method = 'post' ) {
1924 $this->mMethod = strtolower( $method );
1925
1926 return $this;
1927 }
1928
1932 public function getMethod() {
1933 return $this->mMethod;
1934 }
1935
1946 protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
1947 return Xml::fieldset( $legend, $section, $attributes ) . "\n";
1948 }
1949
1967 public function displaySection( $fields,
1968 $sectionName = '',
1969 $fieldsetIDPrefix = '',
1970 &$hasUserVisibleFields = false
1971 ) {
1972 if ( $this->mFieldData === null ) {
1973 throw new LogicException( 'HTMLForm::displaySection() called on uninitialized field data. '
1974 . 'You probably called displayForm() without calling prepareForm() first.' );
1975 }
1976
1977 $html = [];
1978 $subsectionHtml = '';
1979 $hasLabel = false;
1980
1981 foreach ( $fields as $key => $value ) {
1982 if ( $value instanceof HTMLFormField ) {
1983 $v = array_key_exists( $key, $this->mFieldData )
1984 ? $this->mFieldData[$key]
1985 : $value->getDefault();
1986
1987 $retval = $this->formatField( $value, $v ?? '' );
1988
1989 // check, if the form field should be added to
1990 // the output.
1991 if ( $value->hasVisibleOutput() ) {
1992 $html[] = $retval;
1993
1994 $labelValue = trim( $value->getLabel() );
1995 if ( $labelValue !== "\u{00A0}" && $labelValue !== '&#160;' && $labelValue !== '' ) {
1996 $hasLabel = true;
1997 }
1998
1999 $hasUserVisibleFields = true;
2000 }
2001 } elseif ( is_array( $value ) ) {
2002 $subsectionHasVisibleFields = false;
2003 $section =
2004 $this->displaySection( $value,
2005 "mw-htmlform-$key",
2006 "$fieldsetIDPrefix$key-",
2007 $subsectionHasVisibleFields );
2008
2009 if ( $subsectionHasVisibleFields === true ) {
2010 // Display the section with various niceties.
2011 $hasUserVisibleFields = true;
2012
2013 $legend = $this->getLegend( $key );
2014
2015 $section = $this->getHeaderText( $key ) .
2016 $section .
2017 $this->getFooterText( $key );
2018
2019 $attributes = [];
2020 if ( $fieldsetIDPrefix ) {
2021 $attributes['id'] = Sanitizer::escapeIdForAttribute( "$fieldsetIDPrefix$key" );
2022 }
2023 $subsectionHtml .= $this->wrapFieldSetSection(
2024 $legend, $section, $attributes, $fields === $this->mFieldTree
2025 );
2026 } else {
2027 // Just return the inputs, nothing fancy.
2028 $subsectionHtml .= $section;
2029 }
2030 }
2031 }
2032
2033 $html = $this->formatSection( $html, $sectionName, $hasLabel );
2034
2035 if ( $subsectionHtml ) {
2036 if ( $this->mSubSectionBeforeFields ) {
2037 return $subsectionHtml . "\n" . $html;
2038 } else {
2039 return $html . "\n" . $subsectionHtml;
2040 }
2041 } else {
2042 return $html;
2043 }
2044 }
2045
2054 protected function formatField( HTMLFormField $field, $value ) {
2055 $displayFormat = $this->getDisplayFormat();
2056 switch ( $displayFormat ) {
2057 case 'table':
2058 return $field->getTableRow( $value );
2059 case 'div':
2060 return $field->getDiv( $value );
2061 case 'raw':
2062 return $field->getRaw( $value );
2063 case 'inline':
2064 return $field->getInline( $value );
2065 default:
2066 throw new LogicException( 'Not implemented' );
2067 }
2068 }
2069
2078 protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
2079 if ( !$fieldsHtml ) {
2080 // Do not generate any wrappers for empty sections. Sections may be empty if they only have
2081 // subsections, but no fields. A legend will still be added in wrapFieldSetSection().
2082 return '';
2083 }
2084
2085 $displayFormat = $this->getDisplayFormat();
2086 $html = implode( '', $fieldsHtml );
2087
2088 if ( $displayFormat === 'raw' ) {
2089 return $html;
2090 }
2091
2092 // Avoid strange spacing when no labels exist
2093 $attribs = $anyFieldHasLabel ? [] : [ 'class' => 'mw-htmlform-nolabel' ];
2094
2095 if ( $sectionName ) {
2096 $attribs['id'] = Sanitizer::escapeIdForAttribute( $sectionName );
2097 }
2098
2099 if ( $displayFormat === 'table' ) {
2100 return Html::rawElement( 'table',
2101 $attribs,
2102 Html::rawElement( 'tbody', [], "\n$html\n" ) ) . "\n";
2103 } elseif ( $displayFormat === 'inline' ) {
2104 return Html::rawElement( 'span', $attribs, "\n$html\n" );
2105 } else {
2106 return Html::rawElement( 'div', $attribs, "\n$html\n" );
2107 }
2108 }
2109
2113 public function loadData() {
2114 $this->prepareForm();
2115 }
2116
2120 protected function loadFieldData() {
2121 $fieldData = [];
2122 $request = $this->getRequest();
2123
2124 foreach ( $this->mFlatFields as $fieldname => $field ) {
2125 if ( $field->skipLoadData( $request ) ) {
2126 continue;
2127 }
2128 if ( $field->mParams['disabled'] ?? false ) {
2129 $fieldData[$fieldname] = $field->getDefault();
2130 } else {
2131 $fieldData[$fieldname] = $field->loadDataFromRequest( $request );
2132 }
2133 }
2134
2135 // Reset to default for fields that are supposed to be disabled.
2136 // FIXME: Handle dependency chains, fields that a field checks on may need a reset too.
2137 foreach ( $fieldData as $name => &$value ) {
2138 $field = $this->mFlatFields[$name];
2139 if ( $field->isDisabled( $fieldData ) ) {
2140 $value = $field->getDefault();
2141 }
2142 }
2143
2144 # Filter data.
2145 foreach ( $fieldData as $name => &$value ) {
2146 $field = $this->mFlatFields[$name];
2147 $value = $field->filter( $value, $fieldData );
2148 }
2149
2150 $this->mFieldData = $fieldData;
2151 }
2152
2163 public function filterDataForSubmit( $data ) {
2164 return $data;
2165 }
2166
2176 public function getLegend( $key ) {
2177 return $this->msg( $this->mMessagePrefix ? "{$this->mMessagePrefix}-$key" : $key )->text();
2178 }
2179
2190 public function setAction( $action ) {
2191 $this->mAction = $action;
2192
2193 return $this;
2194 }
2195
2203 public function getAction() {
2204 // If an action is already provided, return it
2205 if ( $this->mAction !== false ) {
2206 return $this->mAction;
2207 }
2208
2209 $articlePath = $this->getConfig()->get( MainConfigNames::ArticlePath );
2210 // Check whether we are in GET mode and the ArticlePath contains a "?"
2211 // meaning that getLocalURL() would return something like "index.php?title=...".
2212 // As browser remove the query string before submitting GET forms,
2213 // it means that the title would be lost. In such case use script path instead
2214 // and put title in a hidden field (see getHiddenFields()).
2215 if ( str_contains( $articlePath, '?' ) && $this->getMethod() === 'get' ) {
2216 return $this->getConfig()->get( MainConfigNames::Script );
2217 }
2218
2219 return $this->getTitle()->getLocalURL();
2220 }
2221
2232 public function setAutocomplete( $autocomplete ) {
2233 $this->mAutocomplete = $autocomplete;
2234
2235 return $this;
2236 }
2237
2244 protected function getMessage( $value ) {
2245 return Message::newFromSpecifier( $value )->setContext( $this );
2246 }
2247
2258 foreach ( $this->mFlatFields as $field ) {
2259 if ( $field->needsJSForHtml5FormValidation() ) {
2260 return true;
2261 }
2262 }
2263 return false;
2264 }
2265}
2266
2268class_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:207
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:264
setSubmitDestructive()
Identify that the submit button in the form has a destructive action.
addPostText( $msg)
Add text to the end of the display.
getFooterText( $section=null)
Get footer text.
getErrorsOrWarnings( $elements, $elementsType)
Returns a formatted list of errors or warnings from the given elements.
addPreHtml( $html)
Add HTML to introductory message.
Definition HTMLForm.php: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:211
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
static submitButton( $contents, array $attrs=[], array $modifiers=[])
Returns an HTML input element in a string.
Definition Html.php:163
Some internal bits split of from Skin.php.
Definition Linker.php:63
A class containing constants representing the names of configuration variables.
const ArticlePath
Name constant for the ArticlePath setting, for use with Config::get()
const Script
Name constant for the Script setting, for use with Config::get()
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition Message.php:158
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition Message.php:460
HTML sanitizer for MediaWiki.
Definition Sanitizer.php:46
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:54
Represents the target of a wiki link.
Represents a title within MediaWiki.
Definition Title.php:79
Module of static functions for generating XML.
Definition Xml.php:37
Generic operation result class Has warning/error list, boolean status and arbitrary value.
isGood()
Returns whether the operation completed and didn't have any error or warnings.
Interface for objects which can provide a MediaWiki context on request.
Represents the target of a wiki link.
Interface for objects (potentially) representing a page that can be viewable and linked to on a wiki.
element(SerializerNode $parent, SerializerNode $node, $contents)