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
207class HTMLForm extends ContextSource {
208 use ProtectedHookAccessorTrait;
209
211 public static $typeMappings = [
212 'api' => HTMLApiField::class,
213 'text' => HTMLTextField::class,
214 'textwithbutton' => HTMLTextFieldWithButton::class,
215 'textarea' => HTMLTextAreaField::class,
216 'select' => HTMLSelectField::class,
217 'combobox' => HTMLComboboxField::class,
218 'radio' => HTMLRadioField::class,
219 'multiselect' => HTMLMultiSelectField::class,
220 'limitselect' => HTMLSelectLimitField::class,
221 'check' => HTMLCheckField::class,
222 'toggle' => HTMLCheckField::class,
223 'int' => HTMLIntField::class,
224 'file' => HTMLFileField::class,
225 'float' => HTMLFloatField::class,
226 'info' => HTMLInfoField::class,
227 'selectorother' => HTMLSelectOrOtherField::class,
228 'selectandother' => HTMLSelectAndOtherField::class,
229 'namespaceselect' => HTMLSelectNamespace::class,
230 'namespaceselectwithbutton' => HTMLSelectNamespaceWithButton::class,
231 'tagfilter' => HTMLTagFilter::class,
232 'sizefilter' => HTMLSizeFilterField::class,
233 'submit' => HTMLSubmitField::class,
234 'hidden' => HTMLHiddenField::class,
235 'edittools' => HTMLEditTools::class,
236 'checkmatrix' => HTMLCheckMatrix::class,
237 'cloner' => HTMLFormFieldCloner::class,
238 'autocompleteselect' => HTMLAutoCompleteSelectField::class,
239 'language' => HTMLSelectLanguageField::class,
240 'date' => HTMLDateTimeField::class,
241 'time' => HTMLDateTimeField::class,
242 'datetime' => HTMLDateTimeField::class,
243 'expiry' => HTMLExpiryField::class,
244 'timezone' => HTMLTimezoneField::class,
245 // HTMLTextField will output the correct type="" attribute automagically.
246 // There are about four zillion other HTML5 input types, like range, but
247 // we don't use those at the moment, so no point in adding all of them.
248 'email' => HTMLTextField::class,
249 'password' => HTMLTextField::class,
250 'url' => HTMLTextField::class,
251 'title' => HTMLTitleTextField::class,
252 'user' => HTMLUserTextField::class,
253 'tagmultiselect' => HTMLTagMultiselectField::class,
254 'orderedmultiselect' => HTMLOrderedMultiselectField::class,
255 'usersmultiselect' => HTMLUsersMultiselectField::class,
256 'titlesmultiselect' => HTMLTitlesMultiselectField::class,
257 'namespacesmultiselect' => HTMLNamespacesMultiselectField::class,
258 ];
259
262
265
267 protected $mFlatFields = [];
269 protected $mFieldTree = [];
271 protected $mShowSubmit = true;
273 protected $mSubmitFlags = [ 'primary', 'progressive' ];
275 protected $mShowCancel = false;
277 protected $mCancelTarget;
278
286
288 protected $mPre = '';
290 protected $mHeader = '';
292 protected $mFooter = '';
294 protected $mSectionHeaders = [];
296 protected $mSectionFooters = [];
298 protected $mPost = '';
300 protected $mId;
302 protected $mName;
304 protected $mTableId = '';
305
307 protected $mSubmitID;
309 protected $mSubmitName;
311 protected $mSubmitText;
314
318 protected $mSingleForm = false;
319
321 protected $mTitle;
323 protected $mMethod = 'post';
325 protected $mWasSubmitted = false;
326
332 protected $mAction = false;
333
339 protected $mCollapsible = false;
340
346 protected $mCollapsed = false;
347
353 protected $mAutocomplete = null;
354
356 protected $mUseMultipart = false;
361 protected $mHiddenFields = [];
366 protected $mButtons = [];
367
369 protected $mWrapperLegend = false;
371 protected $mWrapperAttributes = [];
372
377 protected $mTokenSalt = '';
378
391 protected $mSections = [];
392
401 protected $mSubSectionBeforeFields = true;
402
408 protected $displayFormat = 'table';
409
415 'table',
416 'div',
417 'raw',
418 'inline',
419 ];
420
426 'codex',
427 'ooui',
428 ];
429
434 private $hiddenTitleAddedToForm = false;
435
449 public static function factory(
450 $displayFormat, $descriptor, IContextSource $context, $messagePrefix = ''
451 ) {
452 switch ( $displayFormat ) {
453 case 'codex':
454 return new CodexHTMLForm( $descriptor, $context, $messagePrefix );
455 case 'ooui':
456 return new OOUIHTMLForm( $descriptor, $context, $messagePrefix );
457 default:
458 $form = new self( $descriptor, $context, $messagePrefix );
459 $form->setDisplayFormat( $displayFormat );
460 return $form;
461 }
462 }
463
475 public function __construct(
476 $descriptor, IContextSource $context, $messagePrefix = ''
477 ) {
478 $this->setContext( $context );
479 $this->mMessagePrefix = $messagePrefix;
480 $this->addFields( $descriptor );
481 }
482
492 public function addFields( $descriptor ) {
493 $loadedDescriptor = [];
494
495 foreach ( $descriptor as $fieldname => $info ) {
496 $section = $info['section'] ?? '';
497
498 if ( isset( $info['type'] ) && $info['type'] === 'file' ) {
499 $this->mUseMultipart = true;
500 }
501
502 $field = static::loadInputFromParameters( $fieldname, $info, $this );
503
504 $setSection =& $loadedDescriptor;
505 if ( $section ) {
506 foreach ( explode( '/', $section ) as $newName ) {
507 $setSection[$newName] ??= [];
508 $setSection =& $setSection[$newName];
509 }
510 }
511
512 $setSection[$fieldname] = $field;
513 $this->mFlatFields[$fieldname] = $field;
514 }
515
516 $this->mFieldTree = array_merge_recursive( $this->mFieldTree, $loadedDescriptor );
517
518 return $this;
519 }
520
525 public function hasField( $fieldname ) {
526 return isset( $this->mFlatFields[$fieldname] );
527 }
528
534 public function getField( $fieldname ) {
535 if ( !$this->hasField( $fieldname ) ) {
536 throw new DomainException( __METHOD__ . ': no field named ' . $fieldname );
537 }
538 return $this->mFlatFields[$fieldname];
539 }
540
550 public function setDisplayFormat( $format ) {
551 if (
552 in_array( $format, $this->availableSubclassDisplayFormats, true ) ||
553 in_array( $this->displayFormat, $this->availableSubclassDisplayFormats, true )
554 ) {
555 throw new LogicException( 'Cannot change display format after creation, ' .
556 'use HTMLForm::factory() instead' );
557 }
558
559 if ( !in_array( $format, $this->availableDisplayFormats, true ) ) {
560 throw new InvalidArgumentException( 'Display format must be one of ' .
561 print_r(
562 array_merge(
563 $this->availableDisplayFormats,
564 $this->availableSubclassDisplayFormats
565 ),
566 true
567 ) );
568 }
569
570 $this->displayFormat = $format;
571
572 return $this;
573 }
574
580 public function getDisplayFormat() {
582 }
583
600 public static function getClassFromDescriptor( $fieldname, &$descriptor ) {
601 if ( isset( $descriptor['class'] ) ) {
602 $class = $descriptor['class'];
603 } elseif ( isset( $descriptor['type'] ) ) {
604 $class = static::$typeMappings[$descriptor['type']];
605 $descriptor['class'] = $class;
606 } else {
607 $class = null;
608 }
609
610 if ( !$class ) {
611 throw new InvalidArgumentException( "Descriptor with no class for $fieldname: "
612 . print_r( $descriptor, true ) );
613 }
614
615 return $class;
616 }
617
630 public static function loadInputFromParameters( $fieldname, $descriptor,
631 ?self $parent = null
632 ) {
633 $class = static::getClassFromDescriptor( $fieldname, $descriptor );
634
635 $descriptor['fieldname'] = $fieldname;
636 if ( $parent ) {
637 $descriptor['parent'] = $parent;
638 } else {
640 'Calling HTMLForm::loadInputFromParameters without a parent was deprecated in 1.40',
641 '1.40'
642 );
643 }
644
645 # @todo This will throw a fatal error whenever someone try to use
646 # 'class' to feed a CSS class instead of 'cssclass'. Would be
647 # great to avoid the fatal error and show a nice error.
648 return new $class( $descriptor );
649 }
650
659 public function prepareForm() {
660 # Load data from the request.
661 if (
662 $this->mFormIdentifier === null ||
663 $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier ||
664 ( $this->mSingleForm && $this->getMethod() === 'get' )
665 ) {
666 $this->loadFieldData();
667 } else {
668 $this->mFieldData = [];
669 }
670
671 return $this;
672 }
673
678 public function tryAuthorizedSubmit() {
679 $result = false;
680 if ( $this->requestIsAuthorized() ) {
681 $this->mWasSubmitted = true;
682 $result = $this->trySubmit();
683 }
684
685 return $result;
686 }
687
694 public function requestIsAuthorized(): bool {
695 if ( $this->mFormIdentifier === null ) {
696 $identOkay = true;
697 } else {
698 $identOkay = $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier;
699 }
700
701 $tokenOkay = false;
702 if ( $this->getMethod() !== 'post' ) {
703 $tokenOkay = true; // no session check needed
704 } elseif ( $this->getRequest()->wasPosted() ) {
705 $editToken = $this->getRequest()->getVal( 'wpEditToken' );
706 if ( $this->getUser()->isRegistered() || $editToken !== null ) {
707 // Session tokens for logged-out users have no security value.
708 // However, if the user gave one, check it in order to give a nice
709 // "session expired" error instead of "permission denied" or such.
710 $tokenOkay = $this->getCsrfTokenSet()->matchTokenField(
711 CsrfTokenSet::DEFAULT_FIELD_NAME, $this->mTokenSalt
712 );
713 } else {
714 $tokenOkay = true;
715 }
716 }
717 return $identOkay && $tokenOkay;
718 }
719
727 public function show() {
728 $this->prepareForm();
729
730 $result = $this->tryAuthorizedSubmit();
731 if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
732 return $result;
733 }
734
735 $this->displayForm( $result );
736
737 return false;
738 }
739
745 public function showAlways() {
746 $this->prepareForm();
747
748 $result = $this->tryAuthorizedSubmit();
749
750 $this->displayForm( $result );
751
752 return $result;
753 }
754
766 public function trySubmit() {
767 $valid = true;
768 $hoistedErrors = Status::newGood();
769 if ( $this->mValidationErrorMessage ) {
770 foreach ( $this->mValidationErrorMessage as $error ) {
771 $hoistedErrors->fatal( ...$error );
772 }
773 } else {
774 $hoistedErrors->fatal( 'htmlform-invalid-input' );
775 }
776
777 $this->mWasSubmitted = true;
778
779 # Check for cancelled submission
780 foreach ( $this->mFlatFields as $fieldname => $field ) {
781 if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
782 continue;
783 }
784 if ( $field->cancelSubmit( $this->mFieldData[$fieldname], $this->mFieldData ) ) {
785 $this->mWasSubmitted = false;
786 return false;
787 }
788 }
789
790 # Check for validation
791 $hasNonDefault = false;
792 foreach ( $this->mFlatFields as $fieldname => $field ) {
793 if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
794 continue;
795 }
796 $hasNonDefault = $hasNonDefault || $this->mFieldData[$fieldname] !== $field->getDefault();
797 if ( $field->isDisabled( $this->mFieldData ) ) {
798 continue;
799 }
800 $res = $field->validate( $this->mFieldData[$fieldname], $this->mFieldData );
801 if ( $res !== true ) {
802 $valid = false;
803 if ( $res !== false && !$field->canDisplayErrors() ) {
804 if ( is_string( $res ) ) {
805 $hoistedErrors->fatal( 'rawmessage', $res );
806 } else {
807 $hoistedErrors->fatal( $res );
808 }
809 }
810 }
811 }
812
813 if ( !$valid ) {
814 // Treat as not submitted if got nothing from the user on GET forms.
815 if ( !$hasNonDefault && $this->getMethod() === 'get' &&
816 ( $this->mFormIdentifier === null ||
817 $this->getRequest()->getCheck( 'wpFormIdentifier' ) )
818 ) {
819 $this->mWasSubmitted = false;
820 return false;
821 }
822 return $hoistedErrors;
823 }
824
825 $callback = $this->mSubmitCallback;
826 if ( !is_callable( $callback ) ) {
827 throw new LogicException( 'HTMLForm: no submit callback provided. Use ' .
828 'setSubmitCallback() to set one.' );
829 }
830
831 $data = $this->filterDataForSubmit( $this->mFieldData );
832
833 $res = $callback( $data, $this );
834 if ( $res === false ) {
835 $this->mWasSubmitted = false;
836 } elseif ( $res instanceof StatusValue ) {
837 // DWIM - callbacks are not supposed to return a StatusValue but it's easy to mix up.
838 $res = Status::wrap( $res );
839 }
840
841 return $res;
842 }
843
855 public function wasSubmitted() {
856 return $this->mWasSubmitted;
857 }
858
869 public function setSubmitCallback( $cb ) {
870 $this->mSubmitCallback = $cb;
871
872 return $this;
873 }
874
884 public function setValidationErrorMessage( $msg ) {
885 $this->mValidationErrorMessage = $msg;
886
887 return $this;
888 }
889
898 public function setPreHtml( $html ) {
899 $this->mPre = $html;
900
901 return $this;
902 }
903
912 public function addPreHtml( $html ) {
913 $this->mPre .= $html;
914
915 return $this;
916 }
917
924 public function getPreHtml() {
925 return $this->mPre;
926 }
927
937 public function addHeaderHtml( $html, $section = null ) {
938 if ( $section === null ) {
939 $this->mHeader .= $html;
940 } else {
941 $this->mSectionHeaders[$section] ??= '';
942 $this->mSectionHeaders[$section] .= $html;
943 }
944
945 return $this;
946 }
947
957 public function setHeaderHtml( $html, $section = null ) {
958 if ( $section === null ) {
959 $this->mHeader = $html;
960 } else {
961 $this->mSectionHeaders[$section] = $html;
962 }
963
964 return $this;
965 }
966
975 public function getHeaderHtml( $section = null ) {
976 return $section ? $this->mSectionHeaders[$section] ?? '' : $this->mHeader;
977 }
978
988 public function addFooterHtml( $html, $section = null ) {
989 if ( $section === null ) {
990 $this->mFooter .= $html;
991 } else {
992 $this->mSectionFooters[$section] ??= '';
993 $this->mSectionFooters[$section] .= $html;
994 }
995
996 return $this;
997 }
998
1008 public function setFooterHtml( $html, $section = null ) {
1009 if ( $section === null ) {
1010 $this->mFooter = $html;
1011 } else {
1012 $this->mSectionFooters[$section] = $html;
1013 }
1014
1015 return $this;
1016 }
1017
1025 public function getFooterHtml( $section = null ) {
1026 return $section ? $this->mSectionFooters[$section] ?? '' : $this->mFooter;
1027 }
1028
1037 public function addPostHtml( $html ) {
1038 $this->mPost .= $html;
1039
1040 return $this;
1041 }
1042
1051 public function setPostHtml( $html ) {
1052 $this->mPost = $html;
1053
1054 return $this;
1055 }
1056
1063 public function getPostHtml() {
1064 return $this->mPost;
1065 }
1066
1076 public function setSections( $sections ) {
1077 if ( $this->getDisplayFormat() !== 'codex' ) {
1078 throw new \InvalidArgumentException(
1079 "Non-Codex HTMLForms do not support additional section information."
1080 );
1081 }
1082
1083 $this->mSections = $sections;
1084
1085 return $this;
1086 }
1087
1098 public function addHiddenField( $name, $value, array $attribs = [] ) {
1099 if ( !is_array( $value ) ) {
1100 // Per WebRequest::getVal: Array values are discarded for security reasons.
1101 $attribs += [ 'name' => $name ];
1102 $this->mHiddenFields[] = [ $value, $attribs ];
1103 }
1104
1105 return $this;
1106 }
1107
1119 public function addHiddenFields( array $fields ) {
1120 foreach ( $fields as $name => $value ) {
1121 if ( is_array( $value ) ) {
1122 // Per WebRequest::getVal: Array values are discarded for security reasons.
1123 continue;
1124 }
1125 $this->mHiddenFields[] = [ $value, [ 'name' => $name ] ];
1126 }
1127
1128 return $this;
1129 }
1130
1154 public function addButton( $data ) {
1155 if ( !is_array( $data ) ) {
1156 $args = func_get_args();
1157 if ( count( $args ) < 2 || count( $args ) > 4 ) {
1158 throw new InvalidArgumentException(
1159 'Incorrect number of arguments for deprecated calling style'
1160 );
1161 }
1162 $data = [
1163 'name' => $args[0],
1164 'value' => $args[1],
1165 'id' => $args[2] ?? null,
1166 'attribs' => $args[3] ?? null,
1167 ];
1168 } else {
1169 if ( !isset( $data['name'] ) ) {
1170 throw new InvalidArgumentException( 'A name is required' );
1171 }
1172 if ( !isset( $data['value'] ) ) {
1173 throw new InvalidArgumentException( 'A value is required' );
1174 }
1175 }
1176 $this->mButtons[] = $data + [
1177 'id' => null,
1178 'attribs' => null,
1179 'flags' => null,
1180 'framed' => true,
1181 ];
1182
1183 return $this;
1184 }
1185
1195 public function setTokenSalt( $salt ) {
1196 $this->mTokenSalt = $salt;
1197
1198 return $this;
1199 }
1200
1215 public function displayForm( $submitResult ) {
1216 $this->getOutput()->addHTML( $this->getHTML( $submitResult ) );
1217 }
1218
1222 private function getHiddenTitle(): string {
1223 if ( $this->hiddenTitleAddedToForm ) {
1224 return '';
1225 }
1226
1227 $html = '';
1228 if ( $this->getMethod() === 'post' ||
1229 $this->getAction() === $this->getConfig()->get( MainConfigNames::Script )
1230 ) {
1231 $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1232 }
1233 $this->hiddenTitleAddedToForm = true;
1234 return $html;
1235 }
1236
1247 public function getHTML( $submitResult ) {
1248 # For good measure (it is the default)
1249 $this->getOutput()->getMetadata()->setPreventClickjacking( true );
1250 $this->getOutput()->addModules( 'mediawiki.htmlform' );
1251 $this->getOutput()->addModuleStyles( [
1252 'mediawiki.htmlform.styles',
1253 // Html::errorBox and Html::warningBox used by HtmlFormField and HtmlForm::getErrorsOrWarnings
1254 'mediawiki.codex.messagebox.styles'
1255 ] );
1256
1257 if ( $this->mCollapsible ) {
1258 // Preload jquery.makeCollapsible for mediawiki.htmlform
1259 $this->getOutput()->addModules( 'jquery.makeCollapsible' );
1260 }
1261
1262 $headerHtml = $this->getHeaderHtml();
1263 $footerHtml = $this->getFooterHtml();
1264 $html = $this->getErrorsOrWarnings( $submitResult, 'error' )
1265 . $this->getErrorsOrWarnings( $submitResult, 'warning' )
1266 . $headerHtml
1267 . $this->getHiddenTitle()
1268 . $this->getBody()
1269 . $this->getHiddenFields()
1270 . $this->getButtons()
1271 . $footerHtml;
1272
1273 return $this->mPre . $this->wrapForm( $html ) . $this->mPost;
1274 }
1275
1283 public function setCollapsibleOptions( $collapsedByDefault = false ) {
1284 $this->mCollapsible = true;
1285 $this->mCollapsed = $collapsedByDefault;
1286 return $this;
1287 }
1288
1294 protected function getFormAttributes() {
1295 # Use multipart/form-data
1296 $encType = $this->mUseMultipart
1297 ? 'multipart/form-data'
1298 : 'application/x-www-form-urlencoded';
1299 # Attributes
1300 $attribs = [
1301 'class' => 'mw-htmlform',
1302 'action' => $this->getAction(),
1303 'method' => $this->getMethod(),
1304 'enctype' => $encType,
1305 ];
1306 if ( $this->mId ) {
1307 $attribs['id'] = $this->mId;
1308 }
1309 if ( is_string( $this->mAutocomplete ) ) {
1310 $attribs['autocomplete'] = $this->mAutocomplete;
1311 }
1312 if ( $this->mName ) {
1313 $attribs['name'] = $this->mName;
1314 }
1315 if ( $this->needsJSForHtml5FormValidation() ) {
1316 $attribs['novalidate'] = true;
1317 }
1318 return $attribs;
1319 }
1320
1328 public function wrapForm( $html ) {
1329 # Include a <fieldset> wrapper for style, if requested.
1330 if ( $this->mWrapperLegend !== false ) {
1331 $legend = is_string( $this->mWrapperLegend ) ? $this->mWrapperLegend : false;
1332 $html = Html::rawElement(
1333 'fieldset',
1334 $this->mWrapperAttributes,
1335 ( $legend ? Html::element( 'legend', [], $legend ) : '' ) . $html
1336 );
1337 }
1338
1339 return Html::rawElement(
1340 'form',
1341 $this->getFormAttributes(),
1342 $html
1343 );
1344 }
1345
1350 public function getHiddenFields() {
1351 $html = '';
1352
1353 // add the title as a hidden file if it hasn't been added yet and if it is necessary
1354 // added for backward compatibility with the previous version of this public method
1355 $html .= $this->getHiddenTitle();
1356
1357 if ( $this->mFormIdentifier !== null ) {
1358 $html .= Html::hidden(
1359 'wpFormIdentifier',
1360 $this->mFormIdentifier
1361 ) . "\n";
1362 }
1363 if ( $this->getMethod() === 'post' ) {
1364 $html .= Html::hidden(
1365 'wpEditToken',
1366 $this->getUser()->getEditToken( $this->mTokenSalt ),
1367 [ 'id' => 'wpEditToken' ]
1368 ) . "\n";
1369 }
1370
1371 foreach ( $this->mHiddenFields as [ $value, $attribs ] ) {
1372 $html .= Html::hidden( $attribs['name'], $value, $attribs ) . "\n";
1373 }
1374
1375 return $html;
1376 }
1377
1383 public function getButtons() {
1384 $buttons = '';
1385
1386 if ( $this->mShowSubmit ) {
1387 $attribs = [];
1388
1389 if ( $this->mSubmitID !== null ) {
1390 $attribs['id'] = $this->mSubmitID;
1391 }
1392
1393 if ( $this->mSubmitName !== null ) {
1394 $attribs['name'] = $this->mSubmitName;
1395 }
1396
1397 if ( $this->mSubmitTooltip !== null ) {
1398 $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
1399 }
1400
1401 $attribs['class'] = [ 'mw-htmlform-submit' ];
1402
1403 $buttons .= Html::submitButton( $this->getSubmitText(), $attribs ) . "\n";
1404 }
1405
1406 if ( $this->mShowCancel ) {
1407 $target = $this->getCancelTargetURL();
1408 $buttons .= Html::element(
1409 'a',
1410 [
1411 'href' => $target,
1412 ],
1413 $this->msg( 'cancel' )->text()
1414 ) . "\n";
1415 }
1416
1417 foreach ( $this->mButtons as $button ) {
1418 $attrs = [
1419 'type' => 'submit',
1420 'name' => $button['name'],
1421 'value' => $button['value']
1422 ];
1423
1424 if ( isset( $button['label-message'] ) ) {
1425 $label = $this->getMessage( $button['label-message'] )->parse();
1426 } elseif ( isset( $button['label'] ) ) {
1427 $label = htmlspecialchars( $button['label'] );
1428 } elseif ( isset( $button['label-raw'] ) ) {
1429 $label = $button['label-raw'];
1430 } else {
1431 $label = htmlspecialchars( $button['value'] );
1432 }
1433
1434 // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset Always set in self::addButton
1435 if ( $button['attribs'] ) {
1436 $attrs += $button['attribs'];
1437 }
1438
1439 if ( isset( $button['id'] ) ) {
1440 $attrs['id'] = $button['id'];
1441 }
1442
1443 $buttons .= Html::rawElement( 'button', $attrs, $label ) . "\n";
1444 }
1445
1446 if ( !$buttons ) {
1447 return '';
1448 }
1449
1450 return Html::rawElement( 'span',
1451 [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n";
1452 }
1453
1459 public function getBody() {
1460 return $this->displaySection( $this->mFieldTree, $this->mTableId );
1461 }
1462
1472 public function getErrorsOrWarnings( $elements, $elementsType ) {
1473 if ( !in_array( $elementsType, [ 'error', 'warning' ], true ) ) {
1474 throw new DomainException( $elementsType . ' is not a valid type.' );
1475 }
1476 $elementstr = false;
1477 if ( $elements instanceof Status ) {
1478 [ $errorStatus, $warningStatus ] = $elements->splitByErrorType();
1479 $status = $elementsType === 'error' ? $errorStatus : $warningStatus;
1480 if ( $status->isGood() ) {
1481 $elementstr = '';
1482 } else {
1483 $elementstr = $status
1484 ->getMessage()
1485 ->setContext( $this )
1486 ->setInterfaceMessageFlag( true )
1487 ->parse();
1488 }
1489 } elseif ( $elementsType === 'error' ) {
1490 if ( is_array( $elements ) ) {
1491 $elementstr = $this->formatErrors( $elements );
1492 } elseif ( $elements && $elements !== true ) {
1493 $elementstr = (string)$elements;
1494 }
1495 }
1496
1497 if ( !$elementstr ) {
1498 return '';
1499 } elseif ( $elementsType === 'error' ) {
1500 return Html::errorBox( $elementstr );
1501 } else { // $elementsType can only be 'warning'
1502 return Html::warningBox( $elementstr );
1503 }
1504 }
1505
1513 public function formatErrors( $errors ) {
1514 $errorstr = '';
1515
1516 foreach ( $errors as $error ) {
1517 $errorstr .= Html::rawElement(
1518 'li',
1519 [],
1520 $this->getMessage( $error )->parse()
1521 );
1522 }
1523
1524 return Html::rawElement( 'ul', [], $errorstr );
1525 }
1526
1535 public function setSubmitText( $t ) {
1536 $this->mSubmitText = $t;
1537
1538 return $this;
1539 }
1540
1547 public function setSubmitDestructive() {
1548 $this->mSubmitFlags = [ 'destructive', 'primary' ];
1549
1550 return $this;
1551 }
1552
1561 public function setSubmitTextMsg( $msg ) {
1562 if ( !$msg instanceof Message ) {
1563 $msg = $this->msg( $msg );
1564 }
1565 $this->setSubmitText( $msg->text() );
1566
1567 return $this;
1568 }
1569
1574 public function getSubmitText() {
1575 return $this->mSubmitText ?: $this->msg( 'htmlform-submit' )->text();
1576 }
1577
1583 public function setSubmitName( $name ) {
1584 $this->mSubmitName = $name;
1585
1586 return $this;
1587 }
1588
1594 public function setSubmitTooltip( $name ) {
1595 $this->mSubmitTooltip = $name;
1596
1597 return $this;
1598 }
1599
1608 public function setSubmitID( $t ) {
1609 $this->mSubmitID = $t;
1610
1611 return $this;
1612 }
1613
1632 public function setFormIdentifier( string $ident, bool $single = false ) {
1633 $this->mFormIdentifier = $ident;
1634 $this->mSingleForm = $single;
1635
1636 return $this;
1637 }
1638
1649 public function suppressDefaultSubmit( $suppressSubmit = true ) {
1650 $this->mShowSubmit = !$suppressSubmit;
1651
1652 return $this;
1653 }
1654
1661 public function showCancel( $show = true ) {
1662 $this->mShowCancel = $show;
1663 return $this;
1664 }
1665
1672 public function setCancelTarget( $target ) {
1673 if ( $target instanceof PageReference ) {
1674 $target = TitleValue::castPageToLinkTarget( $target );
1675 }
1676
1677 $this->mCancelTarget = $target;
1678 return $this;
1679 }
1680
1685 protected function getCancelTargetURL() {
1686 if ( is_string( $this->mCancelTarget ) ) {
1687 return $this->mCancelTarget;
1688 } else {
1689 // TODO: use a service to get the local URL for a LinkTarget, see T282283
1690 $target = Title::castFromLinkTarget( $this->mCancelTarget ) ?: Title::newMainPage();
1691 return $target->getLocalURL();
1692 }
1693 }
1694
1704 public function setTableId( $id ) {
1705 $this->mTableId = $id;
1706
1707 return $this;
1708 }
1709
1715 public function setId( $id ) {
1716 $this->mId = $id;
1717
1718 return $this;
1719 }
1720
1725 public function setName( $name ) {
1726 $this->mName = $name;
1727
1728 return $this;
1729 }
1730
1743 public function setWrapperLegend( $legend ) {
1744 $this->mWrapperLegend = $legend;
1745
1746 return $this;
1747 }
1748
1756 public function setWrapperAttributes( $attributes ) {
1757 $this->mWrapperAttributes = $attributes;
1758
1759 return $this;
1760 }
1761
1771 public function setWrapperLegendMsg( $msg ) {
1772 if ( !$msg instanceof Message ) {
1773 $msg = $this->msg( $msg );
1774 }
1775 $this->setWrapperLegend( $msg->text() );
1776
1777 return $this;
1778 }
1779
1789 public function setMessagePrefix( $p ) {
1790 $this->mMessagePrefix = $p;
1791
1792 return $this;
1793 }
1794
1802 public function setTitle( $t ) {
1803 // TODO: make mTitle a PageReference when we have a better way to get URLs, see T282283.
1804 $this->mTitle = Title::castFromPageReference( $t );
1805
1806 return $this;
1807 }
1808
1812 public function getTitle() {
1813 return $this->mTitle ?: $this->getContext()->getTitle();
1814 }
1815
1823 public function setMethod( $method = 'post' ) {
1824 $this->mMethod = strtolower( $method );
1825
1826 return $this;
1827 }
1828
1832 public function getMethod() {
1833 return $this->mMethod;
1834 }
1835
1846 protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
1847 return Html::rawElement(
1848 'fieldset',
1849 $attributes,
1850 Html::element( 'legend', [], $legend ) . $section
1851 ) . "\n";
1852 }
1853
1872 public function displaySection( $fields,
1873 $sectionName = '',
1874 $fieldsetIDPrefix = '',
1875 &$hasUserVisibleFields = false
1876 ) {
1877 if ( $this->mFieldData === null ) {
1878 throw new LogicException( 'HTMLForm::displaySection() called on uninitialized field data. '
1879 . 'You probably called displayForm() without calling prepareForm() first.' );
1880 }
1881
1882 $html = [];
1883 $subsectionHtml = '';
1884 $hasLabel = false;
1885
1886 foreach ( $fields as $key => $value ) {
1887 if ( $value instanceof HTMLFormField ) {
1888 $v = array_key_exists( $key, $this->mFieldData )
1889 ? $this->mFieldData[$key]
1890 : $value->getDefault();
1891
1892 $retval = $this->formatField( $value, $v ?? '' );
1893
1894 // check, if the form field should be added to
1895 // the output.
1896 if ( $value->hasVisibleOutput() ) {
1897 $html[] = $retval;
1898
1899 $labelValue = trim( $value->getLabel() );
1900 if ( $labelValue !== "\u{00A0}" && $labelValue !== '&#160;' && $labelValue !== '' ) {
1901 $hasLabel = true;
1902 }
1903
1904 $hasUserVisibleFields = true;
1905 }
1906 } elseif ( is_array( $value ) ) {
1907 $subsectionHasVisibleFields = false;
1908 $section =
1909 $this->displaySection( $value,
1910 "mw-htmlform-$key",
1911 "$fieldsetIDPrefix$key-",
1912 $subsectionHasVisibleFields );
1913
1914 if ( $subsectionHasVisibleFields === true ) {
1915 // Display the section with various niceties.
1916 $hasUserVisibleFields = true;
1917
1918 $legend = $this->getLegend( $key );
1919
1920 $headerHtml = $this->getHeaderHtml( $key );
1921 $footerHtml = $this->getFooterHtml( $key );
1922 $section = $headerHtml .
1923 $section .
1924 $footerHtml;
1925
1926 $attributes = [];
1927 if ( $fieldsetIDPrefix ) {
1928 $attributes['id'] = Sanitizer::escapeIdForAttribute( "$fieldsetIDPrefix$key" );
1929 }
1930 $subsectionHtml .= $this->wrapFieldSetSection(
1931 $legend, $section, $attributes, $fields === $this->mFieldTree
1932 );
1933 } else {
1934 // Just return the inputs, nothing fancy.
1935 $subsectionHtml .= $section;
1936 }
1937 }
1938 }
1939
1940 $html = $this->formatSection( $html, $sectionName, $hasLabel );
1941
1942 if ( $subsectionHtml ) {
1943 if ( $this->mSubSectionBeforeFields ) {
1944 return $subsectionHtml . "\n" . $html;
1945 } else {
1946 return $html . "\n" . $subsectionHtml;
1947 }
1948 } else {
1949 return $html;
1950 }
1951 }
1952
1961 protected function formatField( HTMLFormField $field, $value ) {
1962 $displayFormat = $this->getDisplayFormat();
1963 switch ( $displayFormat ) {
1964 case 'table':
1965 return $field->getTableRow( $value );
1966 case 'div':
1967 return $field->getDiv( $value );
1968 case 'raw':
1969 return $field->getRaw( $value );
1970 case 'inline':
1971 return $field->getInline( $value );
1972 default:
1973 throw new LogicException( 'Not implemented' );
1974 }
1975 }
1976
1985 protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
1986 if ( !$fieldsHtml ) {
1987 // Do not generate any wrappers for empty sections. Sections may be empty if they only have
1988 // subsections, but no fields. A legend will still be added in wrapFieldSetSection().
1989 return '';
1990 }
1991
1992 $displayFormat = $this->getDisplayFormat();
1993 $html = implode( '', $fieldsHtml );
1994
1995 if ( $displayFormat === 'raw' ) {
1996 return $html;
1997 }
1998
1999 // Avoid strange spacing when no labels exist
2000 $attribs = $anyFieldHasLabel ? [] : [ 'class' => 'mw-htmlform-nolabel' ];
2001
2002 if ( $sectionName ) {
2003 $attribs['id'] = Sanitizer::escapeIdForAttribute( $sectionName );
2004 }
2005
2006 if ( $displayFormat === 'table' ) {
2007 return Html::rawElement( 'table',
2008 $attribs,
2009 Html::rawElement( 'tbody', [], "\n$html\n" ) ) . "\n";
2010 } elseif ( $displayFormat === 'inline' ) {
2011 return Html::rawElement( 'span', $attribs, "\n$html\n" );
2012 } else {
2013 return Html::rawElement( 'div', $attribs, "\n$html\n" );
2014 }
2015 }
2016
2020 public function loadData() {
2021 $this->prepareForm();
2022 }
2023
2027 protected function loadFieldData() {
2028 $fieldData = [];
2029 $request = $this->getRequest();
2030
2031 foreach ( $this->mFlatFields as $fieldname => $field ) {
2032 if ( $field->skipLoadData( $request ) ) {
2033 continue;
2034 }
2035 if ( $field->mParams['disabled'] ?? false ) {
2036 $fieldData[$fieldname] = $field->getDefault();
2037 } else {
2038 $fieldData[$fieldname] = $field->loadDataFromRequest( $request );
2039 }
2040 }
2041
2042 // Reset to default for fields that are supposed to be disabled.
2043 // FIXME: Handle dependency chains, fields that a field checks on may need a reset too.
2044 foreach ( $fieldData as $name => &$value ) {
2045 $field = $this->mFlatFields[$name];
2046 if ( $field->isDisabled( $fieldData ) ) {
2047 $value = $field->getDefault();
2048 }
2049 }
2050
2051 # Filter data.
2052 foreach ( $fieldData as $name => &$value ) {
2053 $field = $this->mFlatFields[$name];
2054 $value = $field->filter( $value, $fieldData );
2055 }
2056
2057 $this->mFieldData = $fieldData;
2058 }
2059
2070 public function filterDataForSubmit( $data ) {
2071 return $data;
2072 }
2073
2083 public function getLegend( $key ) {
2084 return $this->msg( $this->mMessagePrefix ? "{$this->mMessagePrefix}-$key" : $key )->text();
2085 }
2086
2097 public function setAction( $action ) {
2098 $this->mAction = $action;
2099
2100 return $this;
2101 }
2102
2110 public function getAction() {
2111 // If an action is already provided, return it
2112 if ( $this->mAction !== false ) {
2113 return $this->mAction;
2114 }
2115
2116 $articlePath = $this->getConfig()->get( MainConfigNames::ArticlePath );
2117 // Check whether we are in GET mode and the ArticlePath contains a "?"
2118 // meaning that getLocalURL() would return something like "index.php?title=...".
2119 // As browser remove the query string before submitting GET forms,
2120 // it means that the title would be lost. In such case use script path instead
2121 // and put title in a hidden field (see getHiddenFields()).
2122 if ( str_contains( $articlePath, '?' ) && $this->getMethod() === 'get' ) {
2123 return $this->getConfig()->get( MainConfigNames::Script );
2124 }
2125
2126 return $this->getTitle()->getLocalURL();
2127 }
2128
2139 public function setAutocomplete( $autocomplete ) {
2140 $this->mAutocomplete = $autocomplete;
2141
2142 return $this;
2143 }
2144
2151 protected function getMessage( $value ) {
2152 return Message::newFromSpecifier( $value )->setContext( $this );
2153 }
2154
2165 foreach ( $this->mFlatFields as $field ) {
2166 if ( $field->needsJSForHtml5FormValidation() ) {
2167 return true;
2168 }
2169 }
2170 return false;
2171 }
2172}
2173
2175class_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:69
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:207
wrapForm( $html)
Wrap the form innards in an actual "<form>" element.
displayForm( $submitResult)
Display the form (sending to the context's OutputPage object), with an appropriate error message or s...
setHeaderHtml( $html, $section=null)
Set header HTML, inside the form.
Definition HTMLForm.php:957
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:391
wrapFieldSetSection( $legend, $section, $attributes, $isRoot)
Wraps the given $section into a user-visible fieldset.
static loadInputFromParameters( $fieldname, $descriptor, ?self $parent=null)
Initialise a new Object for the field.
Definition HTMLForm.php:630
callable null $mSubmitCallback
Definition HTMLForm.php:280
getHeaderHtml( $section=null)
Get header HTML.
Definition HTMLForm.php:975
bool $mCollapsed
Whether the form is collapsed by default.
Definition HTMLForm.php:346
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:766
array $availableSubclassDisplayFormats
Available formats in which to display the form.
Definition HTMLForm.php:425
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:898
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.
requestIsAuthorized()
Return true if the http request passes identity and csrf checks.
Definition HTMLForm.php:694
loadFieldData()
Load data of form fields from the request.
tryAuthorizedSubmit()
Try submitting, with edit token check first.
Definition HTMLForm.php:678
wasSubmitted()
Test whether the form was considered to have been submitted or not, i.e.
Definition HTMLForm.php:855
getFormAttributes()
Get HTML attributes for the <form> tag.
static getClassFromDescriptor( $fieldname, &$descriptor)
Get the HTMLFormField subclass for this descriptor.
Definition HTMLForm.php:600
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
prepareForm()
Prepare form for submission.
Definition HTMLForm.php:659
LinkTarget string null $mCancelTarget
Definition HTMLForm.php:277
bool $mCollapsible
Whether the form can be collapsed.
Definition HTMLForm.php:339
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:401
string $displayFormat
Format in which to display form.
Definition HTMLForm.php:408
setWrapperAttributes( $attributes)
For internal use only.
string null $mAutocomplete
Form attribute autocomplete.
Definition HTMLForm.php:353
getDisplayFormat()
Getter for displayFormat.
Definition HTMLForm.php:580
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:550
string array $mTokenSalt
Salt for the edit token.
Definition HTMLForm.php:377
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:988
showAlways()
Same as self::show with the difference, that the form will be added to the output,...
Definition HTMLForm.php:745
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
addFields( $descriptor)
Add fields to the form.
Definition HTMLForm.php:492
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:869
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:727
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:884
HTMLFormField[] $mFlatFields
Definition HTMLForm.php:267
setSubmitDestructive()
Identify that the submit button in the form has a destructive action.
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:912
setSubmitID( $t)
Set the id for the submit button.
array $availableDisplayFormats
Available formats in which to display the form.
Definition HTMLForm.php:414
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:937
static factory( $displayFormat, $descriptor, IContextSource $context, $messagePrefix='')
Construct a HTMLForm object for given display type.
Definition HTMLForm.php:449
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:924
getButtons()
Get the submit and (potentially) reset buttons.
static string[] $typeMappings
A mapping of 'type' inputs onto standard HTMLFormField subclasses.
Definition HTMLForm.php:211
filterDataForSubmit( $data)
Overload this if you want to apply special filtration routines to the form as a whole,...
__construct( $descriptor, IContextSource $context, $messagePrefix='')
Build a new HTMLForm from an array of field attributes.
Definition HTMLForm.php:475
string false $mAction
Form action URL.
Definition HTMLForm.php:332
addPostHtml( $html)
Add HTML to the end of the display.
Compact stacked vertical format for forms, implemented using OOUI widgets.
This class is a collection of static functions that serve two purposes:
Definition Html.php:44
Some internal bits split of from Skin.php.
Definition Linker.php:47
A class containing constants representing the names of configuration variables.
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
HTML sanitizer for MediaWiki.
Definition Sanitizer.php:34
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:69
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 with one of the types from {.
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.