MediaWiki master
HTMLForm.php
Go to the documentation of this file.
1<?php
2
10namespace MediaWiki\HTMLForm;
11
12use DomainException;
13use InvalidArgumentException;
14use LogicException;
17use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
66use StatusValue;
67use Stringable;
70
195class HTMLForm extends ContextSource {
196 use ProtectedHookAccessorTrait;
197
199 public static $typeMappings = [
200 'api' => HTMLApiField::class,
201 'text' => HTMLTextField::class,
202 'textwithbutton' => HTMLTextFieldWithButton::class,
203 'textarea' => HTMLTextAreaField::class,
204 'select' => HTMLSelectField::class,
205 'combobox' => HTMLComboboxField::class,
206 'radio' => HTMLRadioField::class,
207 'multiselect' => HTMLMultiSelectField::class,
208 'limitselect' => HTMLSelectLimitField::class,
209 'check' => HTMLCheckField::class,
210 'toggle' => HTMLCheckField::class,
211 'int' => HTMLIntField::class,
212 'file' => HTMLFileField::class,
213 'float' => HTMLFloatField::class,
214 'info' => HTMLInfoField::class,
215 'selectorother' => HTMLSelectOrOtherField::class,
216 'selectandother' => HTMLSelectAndOtherField::class,
217 'namespaceselect' => HTMLSelectNamespace::class,
218 'namespaceselectwithbutton' => HTMLSelectNamespaceWithButton::class,
219 'tagfilter' => HTMLTagFilter::class,
220 'sizefilter' => HTMLSizeFilterField::class,
221 'submit' => HTMLSubmitField::class,
222 'hidden' => HTMLHiddenField::class,
223 'edittools' => HTMLEditTools::class,
224 'checkmatrix' => HTMLCheckMatrix::class,
225 'cloner' => HTMLFormFieldCloner::class,
226 'autocompleteselect' => HTMLAutoCompleteSelectField::class,
227 'language' => HTMLSelectLanguageField::class,
228 'date' => HTMLDateTimeField::class,
229 'time' => HTMLDateTimeField::class,
230 'datetime' => HTMLDateTimeField::class,
231 'expiry' => HTMLExpiryField::class,
232 'timezone' => HTMLTimezoneField::class,
233 // HTMLTextField will output the correct type="" attribute automagically.
234 // There are about four zillion other HTML5 input types, like range, but
235 // we don't use those at the moment, so no point in adding all of them.
236 'email' => HTMLTextField::class,
237 'password' => HTMLTextField::class,
238 'url' => HTMLTextField::class,
239 'title' => HTMLTitleTextField::class,
240 'user' => HTMLUserTextField::class,
241 'tagmultiselect' => HTMLTagMultiselectField::class,
242 'orderedmultiselect' => HTMLOrderedMultiselectField::class,
243 'usersmultiselect' => HTMLUsersMultiselectField::class,
244 'titlesmultiselect' => HTMLTitlesMultiselectField::class,
245 'namespacesmultiselect' => HTMLNamespacesMultiselectField::class,
246 ];
247
250
253
255 protected $mFlatFields = [];
257 protected $mFieldTree = [];
259 protected $mShowSubmit = true;
261 protected $mSubmitFlags = [ 'primary', 'progressive' ];
263 protected $mShowCancel = false;
265 protected $mCancelTarget;
266
274
276 protected $mPre = '';
278 protected $mHeader = '';
280 protected $mFooter = '';
282 protected $mSectionHeaders = [];
284 protected $mSectionFooters = [];
286 protected $mPost = '';
288 protected $mId;
290 protected $mName;
292 protected $mTableId = '';
293
295 protected $mSubmitID;
297 protected $mSubmitName;
299 protected $mSubmitText;
302
306 protected $mSingleForm = false;
307
309 protected $mTitle;
311 protected $mMethod = 'post';
313 protected $mWasSubmitted = false;
314
320 protected $mAction = false;
321
327 protected $mCollapsible = false;
328
334 protected $mCollapsed = false;
335
341 protected $mAutocomplete = null;
342
344 protected $mUseMultipart = false;
349 protected $mHiddenFields = [];
354 protected $mButtons = [];
355
357 protected $mWrapperLegend = false;
359 protected $mWrapperAttributes = [];
360
365 protected $mTokenSalt = '';
366
379 protected $mSections = [];
380
389 protected $mSubSectionBeforeFields = true;
390
396 protected $displayFormat = 'table';
397
403 'table',
404 'div',
405 'raw',
406 'inline',
407 ];
408
414 'vform', // deprecated since 1.45
415 'codex',
416 'ooui',
417 ];
418
423 private $hiddenTitleAddedToForm = false;
424
438 public static function factory(
439 $displayFormat, $descriptor, IContextSource $context, $messagePrefix = ''
440 ) {
441 switch ( $displayFormat ) {
442 case 'codex':
443 return new CodexHTMLForm( $descriptor, $context, $messagePrefix );
444 case 'vform':
445 wfDeprecatedMsg( "'vform' HTMLForm display format is deprecated", '1.45' );
446 return new VFormHTMLForm( $descriptor, $context, $messagePrefix );
447 case 'ooui':
448 return new OOUIHTMLForm( $descriptor, $context, $messagePrefix );
449 default:
450 $form = new self( $descriptor, $context, $messagePrefix );
451 $form->setDisplayFormat( $displayFormat );
452 return $form;
453 }
454 }
455
467 public function __construct(
468 $descriptor, IContextSource $context, $messagePrefix = ''
469 ) {
470 $this->setContext( $context );
471 $this->mMessagePrefix = $messagePrefix;
472 $this->addFields( $descriptor );
473 }
474
484 public function addFields( $descriptor ) {
485 $loadedDescriptor = [];
486
487 foreach ( $descriptor as $fieldname => $info ) {
488 $section = $info['section'] ?? '';
489
490 if ( isset( $info['type'] ) && $info['type'] === 'file' ) {
491 $this->mUseMultipart = true;
492 }
493
494 $field = static::loadInputFromParameters( $fieldname, $info, $this );
495
496 $setSection =& $loadedDescriptor;
497 if ( $section ) {
498 foreach ( explode( '/', $section ) as $newName ) {
499 $setSection[$newName] ??= [];
500 $setSection =& $setSection[$newName];
501 }
502 }
503
504 $setSection[$fieldname] = $field;
505 $this->mFlatFields[$fieldname] = $field;
506 }
507
508 $this->mFieldTree = array_merge_recursive( $this->mFieldTree, $loadedDescriptor );
509
510 return $this;
511 }
512
517 public function hasField( $fieldname ) {
518 return isset( $this->mFlatFields[$fieldname] );
519 }
520
526 public function getField( $fieldname ) {
527 if ( !$this->hasField( $fieldname ) ) {
528 throw new DomainException( __METHOD__ . ': no field named ' . $fieldname );
529 }
530 return $this->mFlatFields[$fieldname];
531 }
532
542 public function setDisplayFormat( $format ) {
543 if (
544 in_array( $format, $this->availableSubclassDisplayFormats, true ) ||
545 in_array( $this->displayFormat, $this->availableSubclassDisplayFormats, true )
546 ) {
547 throw new LogicException( 'Cannot change display format after creation, ' .
548 'use HTMLForm::factory() instead' );
549 }
550
551 if ( !in_array( $format, $this->availableDisplayFormats, true ) ) {
552 throw new InvalidArgumentException( 'Display format must be one of ' .
553 print_r(
554 array_merge(
555 $this->availableDisplayFormats,
556 $this->availableSubclassDisplayFormats
557 ),
558 true
559 ) );
560 }
561
562 $this->displayFormat = $format;
563
564 return $this;
565 }
566
572 public function getDisplayFormat() {
574 }
575
592 public static function getClassFromDescriptor( $fieldname, &$descriptor ) {
593 if ( isset( $descriptor['class'] ) ) {
594 $class = $descriptor['class'];
595 } elseif ( isset( $descriptor['type'] ) ) {
596 $class = static::$typeMappings[$descriptor['type']];
597 $descriptor['class'] = $class;
598 } else {
599 $class = null;
600 }
601
602 if ( !$class ) {
603 throw new InvalidArgumentException( "Descriptor with no class for $fieldname: "
604 . print_r( $descriptor, true ) );
605 }
606
607 return $class;
608 }
609
622 public static function loadInputFromParameters( $fieldname, $descriptor,
623 ?HTMLForm $parent = null
624 ) {
625 $class = static::getClassFromDescriptor( $fieldname, $descriptor );
626
627 $descriptor['fieldname'] = $fieldname;
628 if ( $parent ) {
629 $descriptor['parent'] = $parent;
630 }
631
632 # @todo This will throw a fatal error whenever someone try to use
633 # 'class' to feed a CSS class instead of 'cssclass'. Would be
634 # great to avoid the fatal error and show a nice error.
635 return new $class( $descriptor );
636 }
637
646 public function prepareForm() {
647 # Load data from the request.
648 if (
649 $this->mFormIdentifier === null ||
650 $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier ||
651 ( $this->mSingleForm && $this->getMethod() === 'get' )
652 ) {
653 $this->loadFieldData();
654 } else {
655 $this->mFieldData = [];
656 }
657
658 return $this;
659 }
660
665 public function tryAuthorizedSubmit() {
666 $result = false;
667
668 if ( $this->mFormIdentifier === null ) {
669 $identOkay = true;
670 } else {
671 $identOkay = $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier;
672 }
673
674 $tokenOkay = false;
675 if ( $this->getMethod() !== 'post' ) {
676 $tokenOkay = true; // no session check needed
677 } elseif ( $this->getRequest()->wasPosted() ) {
678 $editToken = $this->getRequest()->getVal( 'wpEditToken' );
679 if ( $this->getUser()->isRegistered() || $editToken !== null ) {
680 // Session tokens for logged-out users have no security value.
681 // However, if the user gave one, check it in order to give a nice
682 // "session expired" error instead of "permission denied" or such.
683 $tokenOkay = $this->getCsrfTokenSet()->matchTokenField(
684 CsrfTokenSet::DEFAULT_FIELD_NAME, $this->mTokenSalt
685 );
686 } else {
687 $tokenOkay = true;
688 }
689 }
690
691 if ( $tokenOkay && $identOkay ) {
692 $this->mWasSubmitted = true;
693 $result = $this->trySubmit();
694 }
695
696 return $result;
697 }
698
706 public function show() {
707 $this->prepareForm();
708
709 $result = $this->tryAuthorizedSubmit();
710 if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
711 return $result;
712 }
713
714 $this->displayForm( $result );
715
716 return false;
717 }
718
724 public function showAlways() {
725 $this->prepareForm();
726
727 $result = $this->tryAuthorizedSubmit();
728
729 $this->displayForm( $result );
730
731 return $result;
732 }
733
745 public function trySubmit() {
746 $valid = true;
747 $hoistedErrors = Status::newGood();
748 if ( $this->mValidationErrorMessage ) {
749 foreach ( $this->mValidationErrorMessage as $error ) {
750 $hoistedErrors->fatal( ...$error );
751 }
752 } else {
753 $hoistedErrors->fatal( 'htmlform-invalid-input' );
754 }
755
756 $this->mWasSubmitted = true;
757
758 # Check for cancelled submission
759 foreach ( $this->mFlatFields as $fieldname => $field ) {
760 if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
761 continue;
762 }
763 if ( $field->cancelSubmit( $this->mFieldData[$fieldname], $this->mFieldData ) ) {
764 $this->mWasSubmitted = false;
765 return false;
766 }
767 }
768
769 # Check for validation
770 $hasNonDefault = false;
771 foreach ( $this->mFlatFields as $fieldname => $field ) {
772 if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
773 continue;
774 }
775 $hasNonDefault = $hasNonDefault || $this->mFieldData[$fieldname] !== $field->getDefault();
776 if ( $field->isDisabled( $this->mFieldData ) ) {
777 continue;
778 }
779 $res = $field->validate( $this->mFieldData[$fieldname], $this->mFieldData );
780 if ( $res !== true ) {
781 $valid = false;
782 if ( $res !== false && !$field->canDisplayErrors() ) {
783 if ( is_string( $res ) ) {
784 $hoistedErrors->fatal( 'rawmessage', $res );
785 } else {
786 $hoistedErrors->fatal( $res );
787 }
788 }
789 }
790 }
791
792 if ( !$valid ) {
793 // Treat as not submitted if got nothing from the user on GET forms.
794 if ( !$hasNonDefault && $this->getMethod() === 'get' &&
795 ( $this->mFormIdentifier === null ||
796 $this->getRequest()->getCheck( 'wpFormIdentifier' ) )
797 ) {
798 $this->mWasSubmitted = false;
799 return false;
800 }
801 return $hoistedErrors;
802 }
803
804 $callback = $this->mSubmitCallback;
805 if ( !is_callable( $callback ) ) {
806 throw new LogicException( 'HTMLForm: no submit callback provided. Use ' .
807 'setSubmitCallback() to set one.' );
808 }
809
810 $data = $this->filterDataForSubmit( $this->mFieldData );
811
812 $res = $callback( $data, $this );
813 if ( $res === false ) {
814 $this->mWasSubmitted = false;
815 } elseif ( $res instanceof StatusValue ) {
816 // DWIM - callbacks are not supposed to return a StatusValue but it's easy to mix up.
817 $res = Status::wrap( $res );
818 }
819
820 return $res;
821 }
822
834 public function wasSubmitted() {
836 }
837
848 public function setSubmitCallback( $cb ) {
849 $this->mSubmitCallback = $cb;
850
851 return $this;
852 }
853
863 public function setValidationErrorMessage( $msg ) {
864 $this->mValidationErrorMessage = $msg;
865
866 return $this;
867 }
868
877 public function setPreHtml( $html ) {
878 $this->mPre = $html;
879
880 return $this;
881 }
882
891 public function addPreHtml( $html ) {
892 $this->mPre .= $html;
893
894 return $this;
895 }
896
903 public function getPreHtml() {
904 return $this->mPre;
905 }
906
916 public function addHeaderHtml( $html, $section = null ) {
917 if ( $section === null ) {
918 $this->mHeader .= $html;
919 } else {
920 $this->mSectionHeaders[$section] ??= '';
921 $this->mSectionHeaders[$section] .= $html;
922 }
923
924 return $this;
925 }
926
936 public function setHeaderHtml( $html, $section = null ) {
937 if ( $section === null ) {
938 $this->mHeader = $html;
939 } else {
940 $this->mSectionHeaders[$section] = $html;
941 }
942
943 return $this;
944 }
945
954 public function getHeaderHtml( $section = null ) {
955 return $section ? $this->mSectionHeaders[$section] ?? '' : $this->mHeader;
956 }
957
967 public function addFooterHtml( $html, $section = null ) {
968 if ( $section === null ) {
969 $this->mFooter .= $html;
970 } else {
971 $this->mSectionFooters[$section] ??= '';
972 $this->mSectionFooters[$section] .= $html;
973 }
974
975 return $this;
976 }
977
987 public function setFooterHtml( $html, $section = null ) {
988 if ( $section === null ) {
989 $this->mFooter = $html;
990 } else {
991 $this->mSectionFooters[$section] = $html;
992 }
993
994 return $this;
995 }
996
1004 public function getFooterHtml( $section = null ) {
1005 return $section ? $this->mSectionFooters[$section] ?? '' : $this->mFooter;
1006 }
1007
1016 public function addPostHtml( $html ) {
1017 $this->mPost .= $html;
1018
1019 return $this;
1020 }
1021
1030 public function setPostHtml( $html ) {
1031 $this->mPost = $html;
1032
1033 return $this;
1034 }
1035
1042 public function getPostHtml() {
1043 return $this->mPost;
1044 }
1045
1055 public function setSections( $sections ) {
1056 if ( $this->getDisplayFormat() !== 'codex' ) {
1057 throw new \InvalidArgumentException(
1058 "Non-Codex HTMLForms do not support additional section information."
1059 );
1060 }
1061
1062 $this->mSections = $sections;
1063
1064 return $this;
1065 }
1066
1077 public function addHiddenField( $name, $value, array $attribs = [] ) {
1078 if ( !is_array( $value ) ) {
1079 // Per WebRequest::getVal: Array values are discarded for security reasons.
1080 $attribs += [ 'name' => $name ];
1081 $this->mHiddenFields[] = [ $value, $attribs ];
1082 }
1083
1084 return $this;
1085 }
1086
1098 public function addHiddenFields( array $fields ) {
1099 foreach ( $fields as $name => $value ) {
1100 if ( is_array( $value ) ) {
1101 // Per WebRequest::getVal: Array values are discarded for security reasons.
1102 continue;
1103 }
1104 $this->mHiddenFields[] = [ $value, [ 'name' => $name ] ];
1105 }
1106
1107 return $this;
1108 }
1109
1133 public function addButton( $data ) {
1134 if ( !is_array( $data ) ) {
1135 $args = func_get_args();
1136 if ( count( $args ) < 2 || count( $args ) > 4 ) {
1137 throw new InvalidArgumentException(
1138 'Incorrect number of arguments for deprecated calling style'
1139 );
1140 }
1141 $data = [
1142 'name' => $args[0],
1143 'value' => $args[1],
1144 'id' => $args[2] ?? null,
1145 'attribs' => $args[3] ?? null,
1146 ];
1147 } else {
1148 if ( !isset( $data['name'] ) ) {
1149 throw new InvalidArgumentException( 'A name is required' );
1150 }
1151 if ( !isset( $data['value'] ) ) {
1152 throw new InvalidArgumentException( 'A value is required' );
1153 }
1154 }
1155 $this->mButtons[] = $data + [
1156 'id' => null,
1157 'attribs' => null,
1158 'flags' => null,
1159 'framed' => true,
1160 ];
1161
1162 return $this;
1163 }
1164
1174 public function setTokenSalt( $salt ) {
1175 $this->mTokenSalt = $salt;
1176
1177 return $this;
1178 }
1179
1194 public function displayForm( $submitResult ) {
1195 $this->getOutput()->addHTML( $this->getHTML( $submitResult ) );
1196 }
1197
1201 private function getHiddenTitle(): string {
1202 if ( $this->hiddenTitleAddedToForm ) {
1203 return '';
1204 }
1205
1206 $html = '';
1207 if ( $this->getMethod() === 'post' ||
1208 $this->getAction() === $this->getConfig()->get( MainConfigNames::Script )
1209 ) {
1210 $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1211 }
1212 $this->hiddenTitleAddedToForm = true;
1213 return $html;
1214 }
1215
1226 public function getHTML( $submitResult ) {
1227 # For good measure (it is the default)
1228 $this->getOutput()->getMetadata()->setPreventClickjacking( true );
1229 $this->getOutput()->addModules( 'mediawiki.htmlform' );
1230 $this->getOutput()->addModuleStyles( [
1231 'mediawiki.htmlform.styles',
1232 // Html::errorBox and Html::warningBox used by HtmlFormField and HtmlForm::getErrorsOrWarnings
1233 'mediawiki.codex.messagebox.styles'
1234 ] );
1235
1236 if ( $this->mCollapsible ) {
1237 // Preload jquery.makeCollapsible for mediawiki.htmlform
1238 $this->getOutput()->addModules( 'jquery.makeCollapsible' );
1239 }
1240
1241 $headerHtml = $this->getHeaderHtml();
1242 $footerHtml = $this->getFooterHtml();
1243 $html = $this->getErrorsOrWarnings( $submitResult, 'error' )
1244 . $this->getErrorsOrWarnings( $submitResult, 'warning' )
1245 . $headerHtml
1246 . $this->getHiddenTitle()
1247 . $this->getBody()
1248 . $this->getHiddenFields()
1249 . $this->getButtons()
1250 . $footerHtml;
1251
1252 return $this->mPre . $this->wrapForm( $html ) . $this->mPost;
1253 }
1254
1262 public function setCollapsibleOptions( $collapsedByDefault = false ) {
1263 $this->mCollapsible = true;
1264 $this->mCollapsed = $collapsedByDefault;
1265 return $this;
1266 }
1267
1273 protected function getFormAttributes() {
1274 # Use multipart/form-data
1275 $encType = $this->mUseMultipart
1276 ? 'multipart/form-data'
1277 : 'application/x-www-form-urlencoded';
1278 # Attributes
1279 $attribs = [
1280 'class' => 'mw-htmlform',
1281 'action' => $this->getAction(),
1282 'method' => $this->getMethod(),
1283 'enctype' => $encType,
1284 ];
1285 if ( $this->mId ) {
1286 $attribs['id'] = $this->mId;
1287 }
1288 if ( is_string( $this->mAutocomplete ) ) {
1289 $attribs['autocomplete'] = $this->mAutocomplete;
1290 }
1291 if ( $this->mName ) {
1292 $attribs['name'] = $this->mName;
1293 }
1294 if ( $this->needsJSForHtml5FormValidation() ) {
1295 $attribs['novalidate'] = true;
1296 }
1297 return $attribs;
1298 }
1299
1307 public function wrapForm( $html ) {
1308 # Include a <fieldset> wrapper for style, if requested.
1309 if ( $this->mWrapperLegend !== false ) {
1310 $legend = is_string( $this->mWrapperLegend ) ? $this->mWrapperLegend : false;
1311 $html = Html::rawElement(
1312 'fieldset',
1313 $this->mWrapperAttributes,
1314 ( $legend ? Html::element( 'legend', [], $legend ) : '' ) . $html
1315 );
1316 }
1317
1318 return Html::rawElement(
1319 'form',
1320 $this->getFormAttributes(),
1321 $html
1322 );
1323 }
1324
1329 public function getHiddenFields() {
1330 $html = '';
1331
1332 // add the title as a hidden file if it hasn't been added yet and if it is necessary
1333 // added for backward compatibility with the previous version of this public method
1334 $html .= $this->getHiddenTitle();
1335
1336 if ( $this->mFormIdentifier !== null ) {
1337 $html .= Html::hidden(
1338 'wpFormIdentifier',
1339 $this->mFormIdentifier
1340 ) . "\n";
1341 }
1342 if ( $this->getMethod() === 'post' ) {
1343 $html .= Html::hidden(
1344 'wpEditToken',
1345 $this->getUser()->getEditToken( $this->mTokenSalt ),
1346 [ 'id' => 'wpEditToken' ]
1347 ) . "\n";
1348 }
1349
1350 foreach ( $this->mHiddenFields as [ $value, $attribs ] ) {
1351 $html .= Html::hidden( $attribs['name'], $value, $attribs ) . "\n";
1352 }
1353
1354 return $html;
1355 }
1356
1362 public function getButtons() {
1363 $buttons = '';
1364
1365 if ( $this->mShowSubmit ) {
1366 $attribs = [];
1367
1368 if ( $this->mSubmitID !== null ) {
1369 $attribs['id'] = $this->mSubmitID;
1370 }
1371
1372 if ( $this->mSubmitName !== null ) {
1373 $attribs['name'] = $this->mSubmitName;
1374 }
1375
1376 if ( $this->mSubmitTooltip !== null ) {
1377 $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
1378 }
1379
1380 $attribs['class'] = [ 'mw-htmlform-submit' ];
1381
1382 $buttons .= Html::submitButton( $this->getSubmitText(), $attribs ) . "\n";
1383 }
1384
1385 if ( $this->mShowCancel ) {
1386 $target = $this->getCancelTargetURL();
1387 $buttons .= Html::element(
1388 'a',
1389 [
1390 'href' => $target,
1391 ],
1392 $this->msg( 'cancel' )->text()
1393 ) . "\n";
1394 }
1395
1396 foreach ( $this->mButtons as $button ) {
1397 $attrs = [
1398 'type' => 'submit',
1399 'name' => $button['name'],
1400 'value' => $button['value']
1401 ];
1402
1403 if ( isset( $button['label-message'] ) ) {
1404 $label = $this->getMessage( $button['label-message'] )->parse();
1405 } elseif ( isset( $button['label'] ) ) {
1406 $label = htmlspecialchars( $button['label'] );
1407 } elseif ( isset( $button['label-raw'] ) ) {
1408 $label = $button['label-raw'];
1409 } else {
1410 $label = htmlspecialchars( $button['value'] );
1411 }
1412
1413 // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset Always set in self::addButton
1414 if ( $button['attribs'] ) {
1415 // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset Always set in self::addButton
1416 $attrs += $button['attribs'];
1417 }
1418
1419 if ( isset( $button['id'] ) ) {
1420 $attrs['id'] = $button['id'];
1421 }
1422
1423 $buttons .= Html::rawElement( 'button', $attrs, $label ) . "\n";
1424 }
1425
1426 if ( !$buttons ) {
1427 return '';
1428 }
1429
1430 return Html::rawElement( 'span',
1431 [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n";
1432 }
1433
1439 public function getBody() {
1440 return $this->displaySection( $this->mFieldTree, $this->mTableId );
1441 }
1442
1452 public function getErrorsOrWarnings( $elements, $elementsType ) {
1453 if ( !in_array( $elementsType, [ 'error', 'warning' ], true ) ) {
1454 throw new DomainException( $elementsType . ' is not a valid type.' );
1455 }
1456 $elementstr = false;
1457 if ( $elements instanceof Status ) {
1458 [ $errorStatus, $warningStatus ] = $elements->splitByErrorType();
1459 $status = $elementsType === 'error' ? $errorStatus : $warningStatus;
1460 if ( $status->isGood() ) {
1461 $elementstr = '';
1462 } else {
1463 $elementstr = $status
1464 ->getMessage()
1465 ->setContext( $this )
1466 ->setInterfaceMessageFlag( true )
1467 ->parse();
1468 }
1469 } elseif ( $elementsType === 'error' ) {
1470 if ( is_array( $elements ) ) {
1471 $elementstr = $this->formatErrors( $elements );
1472 } elseif ( $elements && $elements !== true ) {
1473 $elementstr = (string)$elements;
1474 }
1475 }
1476
1477 if ( !$elementstr ) {
1478 return '';
1479 } elseif ( $elementsType === 'error' ) {
1480 return Html::errorBox( $elementstr );
1481 } else { // $elementsType can only be 'warning'
1482 return Html::warningBox( $elementstr );
1483 }
1484 }
1485
1493 public function formatErrors( $errors ) {
1494 $errorstr = '';
1495
1496 foreach ( $errors as $error ) {
1497 $errorstr .= Html::rawElement(
1498 'li',
1499 [],
1500 $this->getMessage( $error )->parse()
1501 );
1502 }
1503
1504 return Html::rawElement( 'ul', [], $errorstr );
1505 }
1506
1514 public function setSubmitText( $t ) {
1515 $this->mSubmitText = $t;
1516
1517 return $this;
1518 }
1519
1526 public function setSubmitDestructive() {
1527 $this->mSubmitFlags = [ 'destructive', 'primary' ];
1528
1529 return $this;
1530 }
1531
1540 public function setSubmitTextMsg( $msg ) {
1541 if ( !$msg instanceof Message ) {
1542 $msg = $this->msg( $msg );
1543 }
1544 $this->setSubmitText( $msg->text() );
1545
1546 return $this;
1547 }
1548
1553 public function getSubmitText() {
1554 return $this->mSubmitText ?: $this->msg( 'htmlform-submit' )->text();
1555 }
1556
1562 public function setSubmitName( $name ) {
1563 $this->mSubmitName = $name;
1564
1565 return $this;
1566 }
1567
1573 public function setSubmitTooltip( $name ) {
1574 $this->mSubmitTooltip = $name;
1575
1576 return $this;
1577 }
1578
1587 public function setSubmitID( $t ) {
1588 $this->mSubmitID = $t;
1589
1590 return $this;
1591 }
1592
1611 public function setFormIdentifier( string $ident, bool $single = false ) {
1612 $this->mFormIdentifier = $ident;
1613 $this->mSingleForm = $single;
1614
1615 return $this;
1616 }
1617
1628 public function suppressDefaultSubmit( $suppressSubmit = true ) {
1629 $this->mShowSubmit = !$suppressSubmit;
1630
1631 return $this;
1632 }
1633
1640 public function showCancel( $show = true ) {
1641 $this->mShowCancel = $show;
1642 return $this;
1643 }
1644
1651 public function setCancelTarget( $target ) {
1652 if ( $target instanceof PageReference ) {
1653 $target = TitleValue::castPageToLinkTarget( $target );
1654 }
1655
1656 $this->mCancelTarget = $target;
1657 return $this;
1658 }
1659
1664 protected function getCancelTargetURL() {
1665 if ( is_string( $this->mCancelTarget ) ) {
1666 return $this->mCancelTarget;
1667 } else {
1668 // TODO: use a service to get the local URL for a LinkTarget, see T282283
1669 $target = Title::castFromLinkTarget( $this->mCancelTarget ) ?: Title::newMainPage();
1670 return $target->getLocalURL();
1671 }
1672 }
1673
1683 public function setTableId( $id ) {
1684 $this->mTableId = $id;
1685
1686 return $this;
1687 }
1688
1694 public function setId( $id ) {
1695 $this->mId = $id;
1696
1697 return $this;
1698 }
1699
1704 public function setName( $name ) {
1705 $this->mName = $name;
1706
1707 return $this;
1708 }
1709
1721 public function setWrapperLegend( $legend ) {
1722 $this->mWrapperLegend = $legend;
1723
1724 return $this;
1725 }
1726
1734 public function setWrapperAttributes( $attributes ) {
1735 $this->mWrapperAttributes = $attributes;
1736
1737 return $this;
1738 }
1739
1749 public function setWrapperLegendMsg( $msg ) {
1750 if ( !$msg instanceof Message ) {
1751 $msg = $this->msg( $msg );
1752 }
1753 $this->setWrapperLegend( $msg->text() );
1754
1755 return $this;
1756 }
1757
1767 public function setMessagePrefix( $p ) {
1768 $this->mMessagePrefix = $p;
1769
1770 return $this;
1771 }
1772
1780 public function setTitle( $t ) {
1781 // TODO: make mTitle a PageReference when we have a better way to get URLs, see T282283.
1782 $this->mTitle = Title::castFromPageReference( $t );
1783
1784 return $this;
1785 }
1786
1790 public function getTitle() {
1791 return $this->mTitle ?: $this->getContext()->getTitle();
1792 }
1793
1801 public function setMethod( $method = 'post' ) {
1802 $this->mMethod = strtolower( $method );
1803
1804 return $this;
1805 }
1806
1810 public function getMethod() {
1811 return $this->mMethod;
1812 }
1813
1824 protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
1825 return Html::rawElement(
1826 'fieldset',
1827 $attributes,
1828 Html::element( 'legend', [], $legend ) . $section
1829 ) . "\n";
1830 }
1831
1850 public function displaySection( $fields,
1851 $sectionName = '',
1852 $fieldsetIDPrefix = '',
1853 &$hasUserVisibleFields = false
1854 ) {
1855 if ( $this->mFieldData === null ) {
1856 throw new LogicException( 'HTMLForm::displaySection() called on uninitialized field data. '
1857 . 'You probably called displayForm() without calling prepareForm() first.' );
1858 }
1859
1860 $html = [];
1861 $subsectionHtml = '';
1862 $hasLabel = false;
1863
1864 foreach ( $fields as $key => $value ) {
1865 if ( $value instanceof HTMLFormField ) {
1866 $v = array_key_exists( $key, $this->mFieldData )
1867 ? $this->mFieldData[$key]
1868 : $value->getDefault();
1869
1870 $retval = $this->formatField( $value, $v ?? '' );
1871
1872 // check, if the form field should be added to
1873 // the output.
1874 if ( $value->hasVisibleOutput() ) {
1875 $html[] = $retval;
1876
1877 $labelValue = trim( $value->getLabel() );
1878 if ( $labelValue !== "\u{00A0}" && $labelValue !== '&#160;' && $labelValue !== '' ) {
1879 $hasLabel = true;
1880 }
1881
1882 $hasUserVisibleFields = true;
1883 }
1884 } elseif ( is_array( $value ) ) {
1885 $subsectionHasVisibleFields = false;
1886 $section =
1887 $this->displaySection( $value,
1888 "mw-htmlform-$key",
1889 "$fieldsetIDPrefix$key-",
1890 $subsectionHasVisibleFields );
1891
1892 if ( $subsectionHasVisibleFields === true ) {
1893 // Display the section with various niceties.
1894 $hasUserVisibleFields = true;
1895
1896 $legend = $this->getLegend( $key );
1897
1898 $headerHtml = $this->getHeaderHtml( $key );
1899 $footerHtml = $this->getFooterHtml( $key );
1900 $section = $headerHtml .
1901 $section .
1902 $footerHtml;
1903
1904 $attributes = [];
1905 if ( $fieldsetIDPrefix ) {
1906 $attributes['id'] = Sanitizer::escapeIdForAttribute( "$fieldsetIDPrefix$key" );
1907 }
1908 $subsectionHtml .= $this->wrapFieldSetSection(
1909 $legend, $section, $attributes, $fields === $this->mFieldTree
1910 );
1911 } else {
1912 // Just return the inputs, nothing fancy.
1913 $subsectionHtml .= $section;
1914 }
1915 }
1916 }
1917
1918 $html = $this->formatSection( $html, $sectionName, $hasLabel );
1919
1920 if ( $subsectionHtml ) {
1921 if ( $this->mSubSectionBeforeFields ) {
1922 return $subsectionHtml . "\n" . $html;
1923 } else {
1924 return $html . "\n" . $subsectionHtml;
1925 }
1926 } else {
1927 return $html;
1928 }
1929 }
1930
1939 protected function formatField( HTMLFormField $field, $value ) {
1940 $displayFormat = $this->getDisplayFormat();
1941 switch ( $displayFormat ) {
1942 case 'table':
1943 return $field->getTableRow( $value );
1944 case 'div':
1945 return $field->getDiv( $value );
1946 case 'raw':
1947 return $field->getRaw( $value );
1948 case 'inline':
1949 return $field->getInline( $value );
1950 default:
1951 throw new LogicException( 'Not implemented' );
1952 }
1953 }
1954
1963 protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
1964 if ( !$fieldsHtml ) {
1965 // Do not generate any wrappers for empty sections. Sections may be empty if they only have
1966 // subsections, but no fields. A legend will still be added in wrapFieldSetSection().
1967 return '';
1968 }
1969
1970 $displayFormat = $this->getDisplayFormat();
1971 $html = implode( '', $fieldsHtml );
1972
1973 if ( $displayFormat === 'raw' ) {
1974 return $html;
1975 }
1976
1977 // Avoid strange spacing when no labels exist
1978 $attribs = $anyFieldHasLabel ? [] : [ 'class' => 'mw-htmlform-nolabel' ];
1979
1980 if ( $sectionName ) {
1981 $attribs['id'] = Sanitizer::escapeIdForAttribute( $sectionName );
1982 }
1983
1984 if ( $displayFormat === 'table' ) {
1985 return Html::rawElement( 'table',
1986 $attribs,
1987 Html::rawElement( 'tbody', [], "\n$html\n" ) ) . "\n";
1988 } elseif ( $displayFormat === 'inline' ) {
1989 return Html::rawElement( 'span', $attribs, "\n$html\n" );
1990 } else {
1991 return Html::rawElement( 'div', $attribs, "\n$html\n" );
1992 }
1993 }
1994
1998 public function loadData() {
1999 $this->prepareForm();
2000 }
2001
2005 protected function loadFieldData() {
2006 $fieldData = [];
2007 $request = $this->getRequest();
2008
2009 foreach ( $this->mFlatFields as $fieldname => $field ) {
2010 if ( $field->skipLoadData( $request ) ) {
2011 continue;
2012 }
2013 if ( $field->mParams['disabled'] ?? false ) {
2014 $fieldData[$fieldname] = $field->getDefault();
2015 } else {
2016 $fieldData[$fieldname] = $field->loadDataFromRequest( $request );
2017 }
2018 }
2019
2020 // Reset to default for fields that are supposed to be disabled.
2021 // FIXME: Handle dependency chains, fields that a field checks on may need a reset too.
2022 foreach ( $fieldData as $name => &$value ) {
2023 $field = $this->mFlatFields[$name];
2024 if ( $field->isDisabled( $fieldData ) ) {
2025 $value = $field->getDefault();
2026 }
2027 }
2028
2029 # Filter data.
2030 foreach ( $fieldData as $name => &$value ) {
2031 $field = $this->mFlatFields[$name];
2032 $value = $field->filter( $value, $fieldData );
2033 }
2034
2035 $this->mFieldData = $fieldData;
2036 }
2037
2048 public function filterDataForSubmit( $data ) {
2049 return $data;
2050 }
2051
2061 public function getLegend( $key ) {
2062 return $this->msg( $this->mMessagePrefix ? "{$this->mMessagePrefix}-$key" : $key )->text();
2063 }
2064
2075 public function setAction( $action ) {
2076 $this->mAction = $action;
2077
2078 return $this;
2079 }
2080
2088 public function getAction() {
2089 // If an action is already provided, return it
2090 if ( $this->mAction !== false ) {
2091 return $this->mAction;
2092 }
2093
2094 $articlePath = $this->getConfig()->get( MainConfigNames::ArticlePath );
2095 // Check whether we are in GET mode and the ArticlePath contains a "?"
2096 // meaning that getLocalURL() would return something like "index.php?title=...".
2097 // As browser remove the query string before submitting GET forms,
2098 // it means that the title would be lost. In such case use script path instead
2099 // and put title in a hidden field (see getHiddenFields()).
2100 if ( str_contains( $articlePath, '?' ) && $this->getMethod() === 'get' ) {
2101 return $this->getConfig()->get( MainConfigNames::Script );
2102 }
2103
2104 return $this->getTitle()->getLocalURL();
2105 }
2106
2117 public function setAutocomplete( $autocomplete ) {
2118 $this->mAutocomplete = $autocomplete;
2119
2120 return $this;
2121 }
2122
2129 protected function getMessage( $value ) {
2130 return Message::newFromSpecifier( $value )->setContext( $this );
2131 }
2132
2143 foreach ( $this->mFlatFields as $field ) {
2144 if ( $field->needsJSForHtml5FormValidation() ) {
2145 return true;
2146 }
2147 }
2148 return false;
2149 }
2150}
2151
2153class_alias( HTMLForm::class, 'HTMLForm' );
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:68
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
getCsrfTokenSet()
Get a repository to obtain and match CSRF tokens.
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.
Implements a tag multiselect input field with a searchable dropdown containing valid tags.
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:195
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:936
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.
array[] $mSections
Additional information about form sections.
Definition HTMLForm.php:379
wrapFieldSetSection( $legend, $section, $attributes, $isRoot)
Wraps the given $section into a user-visible fieldset.
callable null $mSubmitCallback
Definition HTMLForm.php:268
getHeaderHtml( $section=null)
Get header HTML.
Definition HTMLForm.php:954
bool $mCollapsed
Whether the form is collapsed by default.
Definition HTMLForm.php:334
setFormIdentifier(string $ident, bool $single=false)
Set an internal identifier for this form.
trySubmit()
Validate all the fields, and call the submission callback function if everything is kosher.
Definition HTMLForm.php:745
array $availableSubclassDisplayFormats
Available formats in which to display the form.
Definition HTMLForm.php:413
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:877
setTokenSalt( $salt)
Set the salt for the edit token.
setFooterHtml( $html, $section=null)
Set footer HTML, inside the form.
Definition HTMLForm.php:987
suppressDefaultSubmit( $suppressSubmit=true)
Stop a default submit button being shown for this form.
loadFieldData()
Load data of form fields from the request.
tryAuthorizedSubmit()
Try submitting, with edit token check first.
Definition HTMLForm.php:665
wasSubmitted()
Test whether the form was considered to have been submitted or not, i.e.
Definition HTMLForm.php:834
getFormAttributes()
Get HTML attributes for the <form> tag.
static getClassFromDescriptor( $fieldname, &$descriptor)
Get the HTMLFormField subclass for this descriptor.
Definition HTMLForm.php:592
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
prepareForm()
Prepare form for submission.
Definition HTMLForm.php:646
LinkTarget string null $mCancelTarget
Definition HTMLForm.php:265
bool $mCollapsible
Whether the form can be collapsed.
Definition HTMLForm.php:327
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:389
string $displayFormat
Format in which to display form.
Definition HTMLForm.php:396
setWrapperAttributes( $attributes)
For internal use only.
string null $mAutocomplete
Form attribute autocomplete.
Definition HTMLForm.php:341
getDisplayFormat()
Getter for displayFormat.
Definition HTMLForm.php:572
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:542
string array $mTokenSalt
Salt for the edit token.
Definition HTMLForm.php:365
getHTML( $submitResult)
Returns the raw HTML generated by the form.
addButton( $data)
Add a button to the form.
getHiddenFields()
Get the hidden fields that should go inside the form.
setTableId( $id)
Set the id of the <table> or outermost <div> element.
setWrapperLegend( $legend)
Prompt the whole form to be wrapped in a "<fieldset>", with this text as its "<legend>" element.
addFooterHtml( $html, $section=null)
Add footer HTML, inside the form.
Definition HTMLForm.php:967
showAlways()
Same as self::show with the difference, that the form will be added to the output,...
Definition HTMLForm.php:724
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
addFields( $descriptor)
Add fields to the form.
Definition HTMLForm.php:484
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.
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:848
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...
show()
The here's-one-I-made-earlier option: do the submission if posted, or display the form with or withou...
Definition HTMLForm.php:706
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:863
HTMLFormField[] $mFlatFields
Definition HTMLForm.php:255
setSubmitDestructive()
Identify that the submit button in the form has a destructive action.
static loadInputFromParameters( $fieldname, $descriptor, ?HTMLForm $parent=null)
Initialise a new Object for the field.
Definition HTMLForm.php:622
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:891
setSubmitID( $t)
Set the id for the submit button.
array $availableDisplayFormats
Available formats in which to display the form.
Definition HTMLForm.php:402
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:916
static factory( $displayFormat, $descriptor, IContextSource $context, $messagePrefix='')
Construct a HTMLForm object for given display type.
Definition HTMLForm.php:438
setCollapsibleOptions( $collapsedByDefault=false)
Enable collapsible mode, and set whether the form is collapsed by default.
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:903
getButtons()
Get the submit and (potentially) reset buttons.
static string[] $typeMappings
A mapping of 'type' inputs onto standard HTMLFormField subclasses.
Definition HTMLForm.php:199
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:467
string false $mAction
Form action URL.
Definition HTMLForm.php:320
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:43
Some internal bits split of from Skin.php.
Definition Linker.php:47
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:144
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition Message.php:492
HTML sanitizer for MediaWiki.
Definition Sanitizer.php:32
Stores and matches CSRF tokens belonging to a given session user.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:44
Represents the target of a wiki link.
Represents a title within MediaWiki.
Definition Title.php:70
Generic operation result class Has warning/error list, boolean status and arbitrary value.
isGood()
Returns whether the operation completed and didn't have any error or warnings.
Value object representing a message parameter that consists of a list of values.
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)