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;
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 $mShowSubmit = true;
267 protected $mSubmitFlags = [ 'primary', 'progressive' ];
268 protected $mShowCancel = false;
269 protected $mCancelTarget;
270
277
278 protected $mPre = '';
279 protected $mHeader = '';
280 protected $mFooter = '';
281 protected $mSectionHeaders = [];
282 protected $mSectionFooters = [];
283 protected $mPost = '';
284 protected $mId;
285 protected $mName;
286 protected $mTableId = '';
287
288 protected $mSubmitID;
289 protected $mSubmitName;
290 protected $mSubmitText;
292
294 protected $mSingleForm = false;
295
297 protected $mTitle;
298 protected $mMethod = 'post';
299 protected $mWasSubmitted = false;
300
306 protected $mAction = false;
307
313 protected $mCollapsible = false;
314
320 protected $mCollapsed = false;
321
327 protected $mAutocomplete = null;
328
329 protected $mUseMultipart = false;
334 protected $mHiddenFields = [];
339 protected $mButtons = [];
340
341 protected $mWrapperLegend = false;
342 protected $mWrapperAttributes = [];
343
348 protected $mTokenSalt = '';
349
362 protected $mSections = [];
363
372 protected $mSubSectionBeforeFields = true;
373
379 protected $displayFormat = 'table';
380
386 'table',
387 'div',
388 'raw',
389 'inline',
390 ];
391
397 'vform',
398 'codex',
399 'ooui',
400 ];
401
406 private $hiddenTitleAddedToForm = false;
407
421 public static function factory(
422 $displayFormat, $descriptor, IContextSource $context, $messagePrefix = ''
423 ) {
424 switch ( $displayFormat ) {
425 case 'codex':
426 return new CodexHTMLForm( $descriptor, $context, $messagePrefix );
427 case 'vform':
428 return new VFormHTMLForm( $descriptor, $context, $messagePrefix );
429 case 'ooui':
430 return new OOUIHTMLForm( $descriptor, $context, $messagePrefix );
431 default:
432 $form = new self( $descriptor, $context, $messagePrefix );
433 $form->setDisplayFormat( $displayFormat );
434 return $form;
435 }
436 }
437
449 public function __construct(
450 $descriptor, IContextSource $context, $messagePrefix = ''
451 ) {
452 $this->setContext( $context );
453 $this->mMessagePrefix = $messagePrefix;
454 $this->addFields( $descriptor );
455 }
456
466 public function addFields( $descriptor ) {
467 $loadedDescriptor = [];
468
469 foreach ( $descriptor as $fieldname => $info ) {
470 $section = $info['section'] ?? '';
471
472 if ( isset( $info['type'] ) && $info['type'] === 'file' ) {
473 $this->mUseMultipart = true;
474 }
475
476 $field = static::loadInputFromParameters( $fieldname, $info, $this );
477
478 $setSection =& $loadedDescriptor;
479 if ( $section ) {
480 foreach ( explode( '/', $section ) as $newName ) {
481 $setSection[$newName] ??= [];
482 $setSection =& $setSection[$newName];
483 }
484 }
485
486 $setSection[$fieldname] = $field;
487 $this->mFlatFields[$fieldname] = $field;
488 }
489
490 $this->mFieldTree = array_merge_recursive( $this->mFieldTree, $loadedDescriptor );
491
492 return $this;
493 }
494
499 public function hasField( $fieldname ) {
500 return isset( $this->mFlatFields[$fieldname] );
501 }
502
508 public function getField( $fieldname ) {
509 if ( !$this->hasField( $fieldname ) ) {
510 throw new DomainException( __METHOD__ . ': no field named ' . $fieldname );
511 }
512 return $this->mFlatFields[$fieldname];
513 }
514
524 public function setDisplayFormat( $format ) {
525 if (
526 in_array( $format, $this->availableSubclassDisplayFormats, true ) ||
527 in_array( $this->displayFormat, $this->availableSubclassDisplayFormats, true )
528 ) {
529 throw new LogicException( 'Cannot change display format after creation, ' .
530 'use HTMLForm::factory() instead' );
531 }
532
533 if ( !in_array( $format, $this->availableDisplayFormats, true ) ) {
534 throw new InvalidArgumentException( 'Display format must be one of ' .
535 print_r(
536 array_merge(
537 $this->availableDisplayFormats,
538 $this->availableSubclassDisplayFormats
539 ),
540 true
541 ) );
542 }
543
544 $this->displayFormat = $format;
545
546 return $this;
547 }
548
554 public function getDisplayFormat() {
556 }
557
574 public static function getClassFromDescriptor( $fieldname, &$descriptor ) {
575 if ( isset( $descriptor['class'] ) ) {
576 $class = $descriptor['class'];
577 } elseif ( isset( $descriptor['type'] ) ) {
578 $class = static::$typeMappings[$descriptor['type']];
579 $descriptor['class'] = $class;
580 } else {
581 $class = null;
582 }
583
584 if ( !$class ) {
585 throw new InvalidArgumentException( "Descriptor with no class for $fieldname: "
586 . print_r( $descriptor, true ) );
587 }
588
589 return $class;
590 }
591
604 public static function loadInputFromParameters( $fieldname, $descriptor,
605 HTMLForm $parent = null
606 ) {
607 $class = static::getClassFromDescriptor( $fieldname, $descriptor );
608
609 $descriptor['fieldname'] = $fieldname;
610 if ( $parent ) {
611 $descriptor['parent'] = $parent;
612 }
613
614 # @todo This will throw a fatal error whenever someone try to use
615 # 'class' to feed a CSS class instead of 'cssclass'. Would be
616 # great to avoid the fatal error and show a nice error.
617 return new $class( $descriptor );
618 }
619
628 public function prepareForm() {
629 # Load data from the request.
630 if (
631 $this->mFormIdentifier === null ||
632 $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier ||
633 ( $this->mSingleForm && $this->getMethod() === 'get' )
634 ) {
635 $this->loadFieldData();
636 } else {
637 $this->mFieldData = [];
638 }
639
640 return $this;
641 }
642
647 public function tryAuthorizedSubmit() {
648 $result = false;
649
650 if ( $this->mFormIdentifier === null ) {
651 $identOkay = true;
652 } else {
653 $identOkay = $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier;
654 }
655
656 $tokenOkay = false;
657 if ( $this->getMethod() !== 'post' ) {
658 $tokenOkay = true; // no session check needed
659 } elseif ( $this->getRequest()->wasPosted() ) {
660 $editToken = $this->getRequest()->getVal( 'wpEditToken' );
661 if ( $this->getUser()->isRegistered() || $editToken !== null ) {
662 // Session tokens for logged-out users have no security value.
663 // However, if the user gave one, check it in order to give a nice
664 // "session expired" error instead of "permission denied" or such.
665 $tokenOkay = $this->getUser()->matchEditToken( $editToken, $this->mTokenSalt );
666 } else {
667 $tokenOkay = true;
668 }
669 }
670
671 if ( $tokenOkay && $identOkay ) {
672 $this->mWasSubmitted = true;
673 $result = $this->trySubmit();
674 }
675
676 return $result;
677 }
678
686 public function show() {
687 $this->prepareForm();
688
689 $result = $this->tryAuthorizedSubmit();
690 if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
691 return $result;
692 }
693
694 $this->displayForm( $result );
695
696 return false;
697 }
698
704 public function showAlways() {
705 $this->prepareForm();
706
707 $result = $this->tryAuthorizedSubmit();
708
709 $this->displayForm( $result );
710
711 return $result;
712 }
713
725 public function trySubmit() {
726 $valid = true;
727 $hoistedErrors = Status::newGood();
728 if ( $this->mValidationErrorMessage ) {
729 foreach ( $this->mValidationErrorMessage as $error ) {
730 $hoistedErrors->fatal( ...$error );
731 }
732 } else {
733 $hoistedErrors->fatal( 'htmlform-invalid-input' );
734 }
735
736 $this->mWasSubmitted = true;
737
738 # Check for cancelled submission
739 foreach ( $this->mFlatFields as $fieldname => $field ) {
740 if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
741 continue;
742 }
743 if ( $field->cancelSubmit( $this->mFieldData[$fieldname], $this->mFieldData ) ) {
744 $this->mWasSubmitted = false;
745 return false;
746 }
747 }
748
749 # Check for validation
750 $hasNonDefault = false;
751 foreach ( $this->mFlatFields as $fieldname => $field ) {
752 if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
753 continue;
754 }
755 $hasNonDefault = $hasNonDefault || $this->mFieldData[$fieldname] !== $field->getDefault();
756 if ( $field->isDisabled( $this->mFieldData ) ) {
757 continue;
758 }
759 $res = $field->validate( $this->mFieldData[$fieldname], $this->mFieldData );
760 if ( $res !== true ) {
761 $valid = false;
762 if ( $res !== false && !$field->canDisplayErrors() ) {
763 if ( is_string( $res ) ) {
764 $hoistedErrors->fatal( 'rawmessage', $res );
765 } else {
766 $hoistedErrors->fatal( $res );
767 }
768 }
769 }
770 }
771
772 if ( !$valid ) {
773 // Treat as not submitted if got nothing from the user on GET forms.
774 if ( !$hasNonDefault && $this->getMethod() === 'get' &&
775 ( $this->mFormIdentifier === null ||
776 $this->getRequest()->getCheck( 'wpFormIdentifier' ) )
777 ) {
778 $this->mWasSubmitted = false;
779 return false;
780 }
781 return $hoistedErrors;
782 }
783
784 $callback = $this->mSubmitCallback;
785 if ( !is_callable( $callback ) ) {
786 throw new LogicException( 'HTMLForm: no submit callback provided. Use ' .
787 'setSubmitCallback() to set one.' );
788 }
789
790 $data = $this->filterDataForSubmit( $this->mFieldData );
791
792 $res = call_user_func( $callback, $data, $this );
793 if ( $res === false ) {
794 $this->mWasSubmitted = false;
795 } elseif ( $res instanceof StatusValue ) {
796 // DWIM - callbacks are not supposed to return a StatusValue but it's easy to mix up.
797 $res = Status::wrap( $res );
798 }
799
800 return $res;
801 }
802
814 public function wasSubmitted() {
816 }
817
828 public function setSubmitCallback( $cb ) {
829 $this->mSubmitCallback = $cb;
830
831 return $this;
832 }
833
843 public function setValidationErrorMessage( $msg ) {
844 $this->mValidationErrorMessage = $msg;
845
846 return $this;
847 }
848
857 public function setIntro( $msg ) {
858 return $this->setPreHtml( $msg );
859 }
860
869 public function setPreHtml( $html ) {
870 $this->mPre = $html;
871
872 return $this;
873 }
874
883 public function addPreHtml( $html ) {
884 $this->mPre .= $html;
885
886 return $this;
887 }
888
895 public function getPreHtml() {
896 return $this->mPre;
897 }
898
907 public function setPreText( $msg ) {
908 return $this->setPreHtml( $msg );
909 }
910
919 public function addPreText( $msg ) {
920 return $this->addPreHtml( $msg );
921 }
922
930 public function getPreText() {
931 return $this->getPreHtml();
932 }
933
943 public function addHeaderHtml( $html, $section = null ) {
944 if ( $section === null ) {
945 $this->mHeader .= $html;
946 } else {
947 $this->mSectionHeaders[$section] ??= '';
948 $this->mSectionHeaders[$section] .= $html;
949 }
950
951 return $this;
952 }
953
963 public function setHeaderHtml( $html, $section = null ) {
964 if ( $section === null ) {
965 $this->mHeader = $html;
966 } else {
967 $this->mSectionHeaders[$section] = $html;
968 }
969
970 return $this;
971 }
972
981 public function getHeaderHtml( $section = null ) {
982 return $section ? $this->mSectionHeaders[$section] ?? '' : $this->mHeader;
983 }
984
994 public function addHeaderText( $msg, $section = null ) {
995 return $this->addHeaderHtml( $msg, $section );
996 }
997
1008 public function setHeaderText( $msg, $section = null ) {
1009 return $this->setHeaderHtml( $msg, $section );
1010 }
1011
1021 public function getHeaderText( $section = null ) {
1022 return $this->getHeaderHtml( $section );
1023 }
1024
1034 public function addFooterHtml( $html, $section = null ) {
1035 if ( $section === null ) {
1036 $this->mFooter .= $html;
1037 } else {
1038 $this->mSectionFooters[$section] ??= '';
1039 $this->mSectionFooters[$section] .= $html;
1040 }
1041
1042 return $this;
1043 }
1044
1054 public function setFooterHtml( $html, $section = null ) {
1055 if ( $section === null ) {
1056 $this->mFooter = $html;
1057 } else {
1058 $this->mSectionFooters[$section] = $html;
1059 }
1060
1061 return $this;
1062 }
1063
1071 public function getFooterHtml( $section = null ) {
1072 return $section ? $this->mSectionFooters[$section] ?? '' : $this->mFooter;
1073 }
1074
1084 public function addFooterText( $msg, $section = null ) {
1085 return $this->addFooterHtml( $msg, $section );
1086 }
1087
1098 public function setFooterText( $msg, $section = null ) {
1099 return $this->setFooterHtml( $msg, $section );
1100 }
1101
1110 public function getFooterText( $section = null ) {
1111 return $this->getFooterHtml( $section );
1112 }
1113
1122 public function addPostHtml( $html ) {
1123 $this->mPost .= $html;
1124
1125 return $this;
1126 }
1127
1136 public function setPostHtml( $html ) {
1137 $this->mPost = $html;
1138
1139 return $this;
1140 }
1141
1148 public function getPostHtml() {
1149 return $this->mPost;
1150 }
1151
1160 public function addPostText( $msg ) {
1161 return $this->addPostHtml( $msg );
1162 }
1163
1172 public function setPostText( $msg ) {
1173 return $this->setPostHtml( $msg );
1174 }
1175
1185 public function setSections( $sections ) {
1186 if ( $this->getDisplayFormat() !== 'codex' ) {
1187 throw new \InvalidArgumentException(
1188 "Non-Codex HTMLForms do not support additional section information."
1189 );
1190 }
1191
1192 $this->mSections = $sections;
1193
1194 return $this;
1195 }
1196
1207 public function addHiddenField( $name, $value, array $attribs = [] ) {
1208 if ( !is_array( $value ) ) {
1209 // Per WebRequest::getVal: Array values are discarded for security reasons.
1210 $attribs += [ 'name' => $name ];
1211 $this->mHiddenFields[] = [ $value, $attribs ];
1212 }
1213
1214 return $this;
1215 }
1216
1228 public function addHiddenFields( array $fields ) {
1229 foreach ( $fields as $name => $value ) {
1230 if ( is_array( $value ) ) {
1231 // Per WebRequest::getVal: Array values are discarded for security reasons.
1232 continue;
1233 }
1234 $this->mHiddenFields[] = [ $value, [ 'name' => $name ] ];
1235 }
1236
1237 return $this;
1238 }
1239
1263 public function addButton( $data ) {
1264 if ( !is_array( $data ) ) {
1265 $args = func_get_args();
1266 if ( count( $args ) < 2 || count( $args ) > 4 ) {
1267 throw new InvalidArgumentException(
1268 'Incorrect number of arguments for deprecated calling style'
1269 );
1270 }
1271 $data = [
1272 'name' => $args[0],
1273 'value' => $args[1],
1274 'id' => $args[2] ?? null,
1275 'attribs' => $args[3] ?? null,
1276 ];
1277 } else {
1278 if ( !isset( $data['name'] ) ) {
1279 throw new InvalidArgumentException( 'A name is required' );
1280 }
1281 if ( !isset( $data['value'] ) ) {
1282 throw new InvalidArgumentException( 'A value is required' );
1283 }
1284 }
1285 $this->mButtons[] = $data + [
1286 'id' => null,
1287 'attribs' => null,
1288 'flags' => null,
1289 'framed' => true,
1290 ];
1291
1292 return $this;
1293 }
1294
1304 public function setTokenSalt( $salt ) {
1305 $this->mTokenSalt = $salt;
1306
1307 return $this;
1308 }
1309
1324 public function displayForm( $submitResult ) {
1325 $this->getOutput()->addHTML( $this->getHTML( $submitResult ) );
1326 }
1327
1332 private function getHiddenTitle(): string {
1333 if ( $this->hiddenTitleAddedToForm ) {
1334 return '';
1335 }
1336
1337 $html = '';
1338 if ( $this->getMethod() === 'post' ||
1339 $this->getAction() === $this->getConfig()->get( MainConfigNames::Script )
1340 ) {
1341 $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1342 }
1343 $this->hiddenTitleAddedToForm = true;
1344 return $html;
1345 }
1346
1357 public function getHTML( $submitResult ) {
1358 # For good measure (it is the default)
1359 $this->getOutput()->setPreventClickjacking( true );
1360 $this->getOutput()->addModules( 'mediawiki.htmlform' );
1361 $this->getOutput()->addModuleStyles( 'mediawiki.htmlform.styles' );
1362
1363 if ( $this->mCollapsible ) {
1364 // Preload jquery.makeCollapsible for mediawiki.htmlform
1365 $this->getOutput()->addModules( 'jquery.makeCollapsible' );
1366 }
1367
1368 $html = $this->getErrorsOrWarnings( $submitResult, 'error' )
1369 . $this->getErrorsOrWarnings( $submitResult, 'warning' )
1370 . $this->getHeaderText()
1371 . $this->getHiddenTitle()
1372 . $this->getBody()
1373 . $this->getHiddenFields()
1374 . $this->getButtons()
1375 . $this->getFooterText();
1376
1377 return $this->mPre . $this->wrapForm( $html ) . $this->mPost;
1378 }
1379
1387 public function setCollapsibleOptions( $collapsedByDefault = false ) {
1388 $this->mCollapsible = true;
1389 $this->mCollapsed = $collapsedByDefault;
1390 return $this;
1391 }
1392
1398 protected function getFormAttributes() {
1399 # Use multipart/form-data
1400 $encType = $this->mUseMultipart
1401 ? 'multipart/form-data'
1402 : 'application/x-www-form-urlencoded';
1403 # Attributes
1404 $attribs = [
1405 'class' => 'mw-htmlform',
1406 'action' => $this->getAction(),
1407 'method' => $this->getMethod(),
1408 'enctype' => $encType,
1409 ];
1410 if ( $this->mId ) {
1411 $attribs['id'] = $this->mId;
1412 }
1413 if ( is_string( $this->mAutocomplete ) ) {
1414 $attribs['autocomplete'] = $this->mAutocomplete;
1415 }
1416 if ( $this->mName ) {
1417 $attribs['name'] = $this->mName;
1418 }
1419 if ( $this->needsJSForHtml5FormValidation() ) {
1420 $attribs['novalidate'] = true;
1421 }
1422 return $attribs;
1423 }
1424
1432 public function wrapForm( $html ) {
1433 # Include a <fieldset> wrapper for style, if requested.
1434 if ( $this->mWrapperLegend !== false ) {
1435 $legend = is_string( $this->mWrapperLegend ) ? $this->mWrapperLegend : false;
1436 $html = Xml::fieldset( $legend, $html, $this->mWrapperAttributes );
1437 }
1438
1439 return Html::rawElement(
1440 'form',
1441 $this->getFormAttributes(),
1442 $html
1443 );
1444 }
1445
1450 public function getHiddenFields() {
1451 $html = '';
1452
1453 // add the title as a hidden file if it hasn't been added yet and if it is necessary
1454 // added for backward compatibility with the previous version of this public method
1455 $html .= $this->getHiddenTitle();
1456
1457 if ( $this->mFormIdentifier !== null ) {
1458 $html .= Html::hidden(
1459 'wpFormIdentifier',
1460 $this->mFormIdentifier
1461 ) . "\n";
1462 }
1463 if ( $this->getMethod() === 'post' ) {
1464 $html .= Html::hidden(
1465 'wpEditToken',
1466 $this->getUser()->getEditToken( $this->mTokenSalt ),
1467 [ 'id' => 'wpEditToken' ]
1468 ) . "\n";
1469 }
1470
1471 foreach ( $this->mHiddenFields as [ $value, $attribs ] ) {
1472 $html .= Html::hidden( $attribs['name'], $value, $attribs ) . "\n";
1473 }
1474
1475 return $html;
1476 }
1477
1483 public function getButtons() {
1484 $buttons = '';
1485
1486 if ( $this->mShowSubmit ) {
1487 $attribs = [];
1488
1489 if ( isset( $this->mSubmitID ) ) {
1490 $attribs['id'] = $this->mSubmitID;
1491 }
1492
1493 if ( isset( $this->mSubmitName ) ) {
1494 $attribs['name'] = $this->mSubmitName;
1495 }
1496
1497 if ( isset( $this->mSubmitTooltip ) ) {
1498 $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
1499 }
1500
1501 $attribs['class'] = [ 'mw-htmlform-submit' ];
1502
1503 $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
1504 }
1505
1506 if ( $this->mShowCancel ) {
1507 $target = $this->getCancelTargetURL();
1508 $buttons .= Html::element(
1509 'a',
1510 [
1511 'href' => $target,
1512 ],
1513 $this->msg( 'cancel' )->text()
1514 ) . "\n";
1515 }
1516
1517 foreach ( $this->mButtons as $button ) {
1518 $attrs = [
1519 'type' => 'submit',
1520 'name' => $button['name'],
1521 'value' => $button['value']
1522 ];
1523
1524 if ( isset( $button['label-message'] ) ) {
1525 $label = $this->getMessage( $button['label-message'] )->parse();
1526 } elseif ( isset( $button['label'] ) ) {
1527 $label = htmlspecialchars( $button['label'] );
1528 } elseif ( isset( $button['label-raw'] ) ) {
1529 $label = $button['label-raw'];
1530 } else {
1531 $label = htmlspecialchars( $button['value'] );
1532 }
1533
1534 // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset Always set in self::addButton
1535 if ( $button['attribs'] ) {
1536 // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset Always set in self::addButton
1537 $attrs += $button['attribs'];
1538 }
1539
1540 if ( isset( $button['id'] ) ) {
1541 $attrs['id'] = $button['id'];
1542 }
1543
1544 $buttons .= Html::rawElement( 'button', $attrs, $label ) . "\n";
1545 }
1546
1547 if ( !$buttons ) {
1548 return '';
1549 }
1550
1551 return Html::rawElement( 'span',
1552 [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n";
1553 }
1554
1560 public function getBody() {
1561 return $this->displaySection( $this->mFieldTree, $this->mTableId );
1562 }
1563
1573 public function getErrorsOrWarnings( $elements, $elementsType ) {
1574 if ( !in_array( $elementsType, [ 'error', 'warning' ], true ) ) {
1575 throw new DomainException( $elementsType . ' is not a valid type.' );
1576 }
1577 $elementstr = false;
1578 if ( $elements instanceof Status ) {
1579 [ $errorStatus, $warningStatus ] = $elements->splitByErrorType();
1580 $status = $elementsType === 'error' ? $errorStatus : $warningStatus;
1581 if ( $status->isGood() ) {
1582 $elementstr = '';
1583 } else {
1584 $elementstr = $status
1585 ->getMessage()
1586 ->setContext( $this )
1587 ->setInterfaceMessageFlag( true )
1588 ->parse();
1589 }
1590 } elseif ( $elementsType === 'error' ) {
1591 if ( is_array( $elements ) ) {
1592 $elementstr = $this->formatErrors( $elements );
1593 } elseif ( $elements && $elements !== true ) {
1594 $elementstr = (string)$elements;
1595 }
1596 }
1597
1598 if ( !$elementstr ) {
1599 return '';
1600 } elseif ( $elementsType === 'error' ) {
1601 return Html::errorBox( $elementstr );
1602 } else { // $elementsType can only be 'warning'
1603 return Html::warningBox( $elementstr );
1604 }
1605 }
1606
1614 public function formatErrors( $errors ) {
1615 $errorstr = '';
1616
1617 foreach ( $errors as $error ) {
1618 $errorstr .= Html::rawElement(
1619 'li',
1620 [],
1621 $this->getMessage( $error )->parse()
1622 );
1623 }
1624
1625 return Html::rawElement( 'ul', [], $errorstr );
1626 }
1627
1635 public function setSubmitText( $t ) {
1636 $this->mSubmitText = $t;
1637
1638 return $this;
1639 }
1640
1647 public function setSubmitDestructive() {
1648 $this->mSubmitFlags = [ 'destructive', 'primary' ];
1649
1650 return $this;
1651 }
1652
1661 public function setSubmitTextMsg( $msg ) {
1662 if ( !$msg instanceof Message ) {
1663 $msg = $this->msg( $msg );
1664 }
1665 $this->setSubmitText( $msg->text() );
1666
1667 return $this;
1668 }
1669
1674 public function getSubmitText() {
1675 return $this->mSubmitText ?: $this->msg( 'htmlform-submit' )->text();
1676 }
1677
1683 public function setSubmitName( $name ) {
1684 $this->mSubmitName = $name;
1685
1686 return $this;
1687 }
1688
1694 public function setSubmitTooltip( $name ) {
1695 $this->mSubmitTooltip = $name;
1696
1697 return $this;
1698 }
1699
1708 public function setSubmitID( $t ) {
1709 $this->mSubmitID = $t;
1710
1711 return $this;
1712 }
1713
1732 public function setFormIdentifier( string $ident, bool $single = false ) {
1733 $this->mFormIdentifier = $ident;
1734 $this->mSingleForm = $single;
1735
1736 return $this;
1737 }
1738
1749 public function suppressDefaultSubmit( $suppressSubmit = true ) {
1750 $this->mShowSubmit = !$suppressSubmit;
1751
1752 return $this;
1753 }
1754
1761 public function showCancel( $show = true ) {
1762 $this->mShowCancel = $show;
1763 return $this;
1764 }
1765
1772 public function setCancelTarget( $target ) {
1773 if ( $target instanceof PageReference ) {
1774 $target = TitleValue::castPageToLinkTarget( $target );
1775 }
1776
1777 $this->mCancelTarget = $target;
1778 return $this;
1779 }
1780
1785 protected function getCancelTargetURL() {
1786 if ( is_string( $this->mCancelTarget ) ) {
1787 return $this->mCancelTarget;
1788 } else {
1789 // TODO: use a service to get the local URL for a LinkTarget, see T282283
1790 $target = Title::castFromLinkTarget( $this->mCancelTarget ) ?: Title::newMainPage();
1791 return $target->getLocalURL();
1792 }
1793 }
1794
1804 public function setTableId( $id ) {
1805 $this->mTableId = $id;
1806
1807 return $this;
1808 }
1809
1815 public function setId( $id ) {
1816 $this->mId = $id;
1817
1818 return $this;
1819 }
1820
1825 public function setName( $name ) {
1826 $this->mName = $name;
1827
1828 return $this;
1829 }
1830
1842 public function setWrapperLegend( $legend ) {
1843 $this->mWrapperLegend = $legend;
1844
1845 return $this;
1846 }
1847
1855 public function setWrapperAttributes( $attributes ) {
1856 $this->mWrapperAttributes = $attributes;
1857
1858 return $this;
1859 }
1860
1870 public function setWrapperLegendMsg( $msg ) {
1871 if ( !$msg instanceof Message ) {
1872 $msg = $this->msg( $msg );
1873 }
1874 $this->setWrapperLegend( $msg->text() );
1875
1876 return $this;
1877 }
1878
1888 public function setMessagePrefix( $p ) {
1889 $this->mMessagePrefix = $p;
1890
1891 return $this;
1892 }
1893
1901 public function setTitle( $t ) {
1902 // TODO: make mTitle a PageReference when we have a better way to get URLs, see T282283.
1903 $this->mTitle = Title::castFromPageReference( $t );
1904
1905 return $this;
1906 }
1907
1911 public function getTitle() {
1912 return $this->mTitle ?: $this->getContext()->getTitle();
1913 }
1914
1922 public function setMethod( $method = 'post' ) {
1923 $this->mMethod = strtolower( $method );
1924
1925 return $this;
1926 }
1927
1931 public function getMethod() {
1932 return $this->mMethod;
1933 }
1934
1945 protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
1946 return Xml::fieldset( $legend, $section, $attributes ) . "\n";
1947 }
1948
1966 public function displaySection( $fields,
1967 $sectionName = '',
1968 $fieldsetIDPrefix = '',
1969 &$hasUserVisibleFields = false
1970 ) {
1971 if ( $this->mFieldData === null ) {
1972 throw new LogicException( 'HTMLForm::displaySection() called on uninitialized field data. '
1973 . 'You probably called displayForm() without calling prepareForm() first.' );
1974 }
1975
1976 $html = [];
1977 $subsectionHtml = '';
1978 $hasLabel = false;
1979
1980 foreach ( $fields as $key => $value ) {
1981 if ( $value instanceof HTMLFormField ) {
1982 $v = array_key_exists( $key, $this->mFieldData )
1983 ? $this->mFieldData[$key]
1984 : $value->getDefault();
1985
1986 $retval = $this->formatField( $value, $v ?? '' );
1987
1988 // check, if the form field should be added to
1989 // the output.
1990 if ( $value->hasVisibleOutput() ) {
1991 $html[] = $retval;
1992
1993 $labelValue = trim( $value->getLabel() );
1994 if ( $labelValue !== "\u{00A0}" && $labelValue !== '&#160;' && $labelValue !== '' ) {
1995 $hasLabel = true;
1996 }
1997
1998 $hasUserVisibleFields = true;
1999 }
2000 } elseif ( is_array( $value ) ) {
2001 $subsectionHasVisibleFields = false;
2002 $section =
2003 $this->displaySection( $value,
2004 "mw-htmlform-$key",
2005 "$fieldsetIDPrefix$key-",
2006 $subsectionHasVisibleFields );
2007
2008 if ( $subsectionHasVisibleFields === true ) {
2009 // Display the section with various niceties.
2010 $hasUserVisibleFields = true;
2011
2012 $legend = $this->getLegend( $key );
2013
2014 $section = $this->getHeaderText( $key ) .
2015 $section .
2016 $this->getFooterText( $key );
2017
2018 $attributes = [];
2019 if ( $fieldsetIDPrefix ) {
2020 $attributes['id'] = Sanitizer::escapeIdForAttribute( "$fieldsetIDPrefix$key" );
2021 }
2022 $subsectionHtml .= $this->wrapFieldSetSection(
2023 $legend, $section, $attributes, $fields === $this->mFieldTree
2024 );
2025 } else {
2026 // Just return the inputs, nothing fancy.
2027 $subsectionHtml .= $section;
2028 }
2029 }
2030 }
2031
2032 $html = $this->formatSection( $html, $sectionName, $hasLabel );
2033
2034 if ( $subsectionHtml ) {
2035 if ( $this->mSubSectionBeforeFields ) {
2036 return $subsectionHtml . "\n" . $html;
2037 } else {
2038 return $html . "\n" . $subsectionHtml;
2039 }
2040 } else {
2041 return $html;
2042 }
2043 }
2044
2053 protected function formatField( HTMLFormField $field, $value ) {
2054 $displayFormat = $this->getDisplayFormat();
2055 switch ( $displayFormat ) {
2056 case 'table':
2057 return $field->getTableRow( $value );
2058 case 'div':
2059 return $field->getDiv( $value );
2060 case 'raw':
2061 return $field->getRaw( $value );
2062 case 'inline':
2063 return $field->getInline( $value );
2064 default:
2065 throw new LogicException( 'Not implemented' );
2066 }
2067 }
2068
2077 protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
2078 if ( !$fieldsHtml ) {
2079 // Do not generate any wrappers for empty sections. Sections may be empty if they only have
2080 // subsections, but no fields. A legend will still be added in wrapFieldSetSection().
2081 return '';
2082 }
2083
2084 $displayFormat = $this->getDisplayFormat();
2085 $html = implode( '', $fieldsHtml );
2086
2087 if ( $displayFormat === 'raw' ) {
2088 return $html;
2089 }
2090
2091 // Avoid strange spacing when no labels exist
2092 $attribs = $anyFieldHasLabel ? [] : [ 'class' => 'mw-htmlform-nolabel' ];
2093
2094 if ( $sectionName ) {
2095 $attribs['id'] = Sanitizer::escapeIdForAttribute( $sectionName );
2096 }
2097
2098 if ( $displayFormat === 'table' ) {
2099 return Html::rawElement( 'table',
2100 $attribs,
2101 Html::rawElement( 'tbody', [], "\n$html\n" ) ) . "\n";
2102 } elseif ( $displayFormat === 'inline' ) {
2103 return Html::rawElement( 'span', $attribs, "\n$html\n" );
2104 } else {
2105 return Html::rawElement( 'div', $attribs, "\n$html\n" );
2106 }
2107 }
2108
2112 public function loadData() {
2113 $this->prepareForm();
2114 }
2115
2119 protected function loadFieldData() {
2120 $fieldData = [];
2121 $request = $this->getRequest();
2122
2123 foreach ( $this->mFlatFields as $fieldname => $field ) {
2124 if ( $field->skipLoadData( $request ) ) {
2125 continue;
2126 }
2127 if ( $field->mParams['disabled'] ?? false ) {
2128 $fieldData[$fieldname] = $field->getDefault();
2129 } else {
2130 $fieldData[$fieldname] = $field->loadDataFromRequest( $request );
2131 }
2132 }
2133
2134 // Reset to default for fields that are supposed to be disabled.
2135 // FIXME: Handle dependency chains, fields that a field checks on may need a reset too.
2136 foreach ( $fieldData as $name => &$value ) {
2137 $field = $this->mFlatFields[$name];
2138 if ( $field->isDisabled( $fieldData ) ) {
2139 $value = $field->getDefault();
2140 }
2141 }
2142
2143 # Filter data.
2144 foreach ( $fieldData as $name => &$value ) {
2145 $field = $this->mFlatFields[$name];
2146 $value = $field->filter( $value, $fieldData );
2147 }
2148
2149 $this->mFieldData = $fieldData;
2150 }
2151
2162 public function filterDataForSubmit( $data ) {
2163 return $data;
2164 }
2165
2175 public function getLegend( $key ) {
2176 return $this->msg( $this->mMessagePrefix ? "{$this->mMessagePrefix}-$key" : $key )->text();
2177 }
2178
2189 public function setAction( $action ) {
2190 $this->mAction = $action;
2191
2192 return $this;
2193 }
2194
2202 public function getAction() {
2203 // If an action is already provided, return it
2204 if ( $this->mAction !== false ) {
2205 return $this->mAction;
2206 }
2207
2208 $articlePath = $this->getConfig()->get( MainConfigNames::ArticlePath );
2209 // Check whether we are in GET mode and the ArticlePath contains a "?"
2210 // meaning that getLocalURL() would return something like "index.php?title=...".
2211 // As browser remove the query string before submitting GET forms,
2212 // it means that the title would be lost. In such case use script path instead
2213 // and put title in a hidden field (see getHiddenFields()).
2214 if ( str_contains( $articlePath, '?' ) && $this->getMethod() === 'get' ) {
2215 return $this->getConfig()->get( MainConfigNames::Script );
2216 }
2217
2218 return $this->getTitle()->getLocalURL();
2219 }
2220
2231 public function setAutocomplete( $autocomplete ) {
2232 $this->mAutocomplete = $autocomplete;
2233
2234 return $this;
2235 }
2236
2243 protected function getMessage( $value ) {
2244 return Message::newFromSpecifier( $value )->setContext( $this );
2245 }
2246
2257 foreach ( $this->mFlatFields as $field ) {
2258 if ( $field->needsJSForHtml5FormValidation() ) {
2259 return true;
2260 }
2261 }
2262 return false;
2263 }
2264}
2265
2267class_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:963
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:362
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:994
getHeaderHtml( $section=null)
Get header HTML.
Definition HTMLForm.php:981
bool $mCollapsed
Whether the form is collapsed by default.
Definition HTMLForm.php:320
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:725
array $availableSubclassDisplayFormats
Available formats in which to display the form.
Definition HTMLForm.php:396
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:869
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:857
loadFieldData()
Load data of form fields from the request.
tryAuthorizedSubmit()
Try submitting, with edit token check first.
Definition HTMLForm.php:647
wasSubmitted()
Test whether the form was considered to have been submitted or not, i.e.
Definition HTMLForm.php:814
getFormAttributes()
Get HTML attributes for the <form> tag.
static getClassFromDescriptor( $fieldname, &$descriptor)
Get the HTMLFormField subclass for this descriptor.
Definition HTMLForm.php:574
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
prepareForm()
Prepare form for submission.
Definition HTMLForm.php:628
bool $mCollapsible
Whether the form can be collapsed.
Definition HTMLForm.php:313
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:372
string $displayFormat
Format in which to display form.
Definition HTMLForm.php:379
addPreText( $msg)
Add HTML to introductory message.
Definition HTMLForm.php:919
setWrapperAttributes( $attributes)
For internal use only.
string null $mAutocomplete
Form attribute autocomplete.
Definition HTMLForm.php:327
getDisplayFormat()
Getter for displayFormat.
Definition HTMLForm.php:554
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:524
string array $mTokenSalt
Salt for the edit token.
Definition HTMLForm.php:348
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:604
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:704
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
addFields( $descriptor)
Add fields to the form.
Definition HTMLForm.php:466
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:828
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:686
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:843
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.
addPreHtml( $html)
Add HTML to introductory message.
Definition HTMLForm.php:883
setSubmitID( $t)
Set the id for the submit button.
getPreText()
Get the introductory message HTML.
Definition HTMLForm.php:930
array $availableDisplayFormats
Available formats in which to display the form.
Definition HTMLForm.php:385
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:943
static factory( $displayFormat, $descriptor, IContextSource $context, $messagePrefix='')
Construct a HTMLForm object for given display type.
Definition HTMLForm.php:421
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:907
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:895
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:449
string false $mAction
Form action URL.
Definition HTMLForm.php:306
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:158
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition Message.php:454
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)