MediaWiki  master
HTMLForm.php
Go to the documentation of this file.
1 <?php
2 
131 class HTMLForm extends ContextSource {
132  // A mapping of 'type' inputs onto standard HTMLFormField subclasses
133  public static $typeMappings = [
134  'api' => HTMLApiField::class,
135  'text' => HTMLTextField::class,
136  'textwithbutton' => HTMLTextFieldWithButton::class,
137  'textarea' => HTMLTextAreaField::class,
138  'select' => HTMLSelectField::class,
139  'combobox' => HTMLComboboxField::class,
140  'radio' => HTMLRadioField::class,
141  'multiselect' => HTMLMultiSelectField::class,
142  'limitselect' => HTMLSelectLimitField::class,
143  'check' => HTMLCheckField::class,
144  'toggle' => HTMLCheckField::class,
145  'int' => HTMLIntField::class,
146  'float' => HTMLFloatField::class,
147  'info' => HTMLInfoField::class,
148  'selectorother' => HTMLSelectOrOtherField::class,
149  'selectandother' => HTMLSelectAndOtherField::class,
150  'namespaceselect' => HTMLSelectNamespace::class,
151  'namespaceselectwithbutton' => HTMLSelectNamespaceWithButton::class,
152  'tagfilter' => HTMLTagFilter::class,
153  'sizefilter' => HTMLSizeFilterField::class,
154  'submit' => HTMLSubmitField::class,
155  'hidden' => HTMLHiddenField::class,
156  'edittools' => HTMLEditTools::class,
157  'checkmatrix' => HTMLCheckMatrix::class,
158  'cloner' => HTMLFormFieldCloner::class,
159  'autocompleteselect' => HTMLAutoCompleteSelectField::class,
160  'language' => HTMLSelectLanguageField::class,
161  'date' => HTMLDateTimeField::class,
162  'time' => HTMLDateTimeField::class,
163  'datetime' => HTMLDateTimeField::class,
164  'expiry' => HTMLExpiryField::class,
165  // HTMLTextField will output the correct type="" attribute automagically.
166  // There are about four zillion other HTML5 input types, like range, but
167  // we don't use those at the moment, so no point in adding all of them.
168  'email' => HTMLTextField::class,
169  'password' => HTMLTextField::class,
170  'url' => HTMLTextField::class,
171  'title' => HTMLTitleTextField::class,
172  'user' => HTMLUserTextField::class,
173  'usersmultiselect' => HTMLUsersMultiselectField::class,
174  'titlesmultiselect' => HTMLTitlesMultiselectField::class,
175  'namespacesmultiselect' => HTMLNamespacesMultiselectField::class,
176  ];
177 
178  public $mFieldData;
179 
180  protected $mMessagePrefix;
181 
183  protected $mFlatFields = [];
184  protected $mFieldTree = [];
185  protected $mShowReset = false;
186  protected $mShowSubmit = true;
188  protected $mSubmitFlags = [ 'primary', 'progressive' ];
189  protected $mShowCancel = false;
190  protected $mCancelTarget;
191 
192  protected $mSubmitCallback;
194 
195  protected $mPre = '';
196  protected $mHeader = '';
197  protected $mFooter = '';
198  protected $mSectionHeaders = [];
199  protected $mSectionFooters = [];
200  protected $mPost = '';
201  protected $mId;
202  protected $mName;
203  protected $mTableId = '';
204 
205  protected $mSubmitID;
206  protected $mSubmitName;
207  protected $mSubmitText;
208  protected $mSubmitTooltip;
209 
210  protected $mFormIdentifier;
211  protected $mTitle;
212  protected $mMethod = 'post';
213  protected $mWasSubmitted = false;
214 
220  protected $mAction = false;
221 
227  protected $mCollapsible = false;
228 
234  protected $mCollapsed = false;
235 
241  protected $mAutocomplete = null;
242 
243  protected $mUseMultipart = false;
248  protected $mHiddenFields = [];
253  protected $mButtons = [];
254 
255  protected $mWrapperLegend = false;
256  protected $mWrapperAttributes = [];
257 
262  protected $mTokenSalt = '';
263 
271  protected $mSubSectionBeforeFields = true;
272 
278  protected $displayFormat = 'table';
279 
285  'table',
286  'div',
287  'raw',
288  'inline',
289  ];
290 
296  'vform',
297  'ooui',
298  ];
299 
307  public static function factory( $displayFormat, ...$arguments ) {
308  switch ( $displayFormat ) {
309  case 'vform':
310  return new VFormHTMLForm( ...$arguments );
311  case 'ooui':
312  return new OOUIHTMLForm( ...$arguments );
313  default:
314  $form = new self( ...$arguments );
315  $form->setDisplayFormat( $displayFormat );
316  return $form;
317  }
318  }
319 
329  public function __construct( $descriptor, /*IContextSource*/ $context = null,
330  $messagePrefix = ''
331  ) {
332  if ( $context instanceof IContextSource ) {
333  $this->setContext( $context );
334  $this->mTitle = false; // We don't need them to set a title
335  $this->mMessagePrefix = $messagePrefix;
336  } elseif ( $context === null && $messagePrefix !== '' ) {
337  $this->mMessagePrefix = $messagePrefix;
338  } elseif ( is_string( $context ) && $messagePrefix === '' ) {
339  // B/C since 1.18
340  // it's actually $messagePrefix
341  $this->mMessagePrefix = $context;
342  }
343 
344  // Evil hack for mobile :(
345  if (
346  !$this->getConfig()->get( 'HTMLFormAllowTableFormat' )
347  && $this->displayFormat === 'table'
348  ) {
349  $this->displayFormat = 'div';
350  }
351 
352  $this->addFields( $descriptor );
353  }
354 
364  public function addFields( $descriptor ) {
365  $loadedDescriptor = [];
366 
367  foreach ( $descriptor as $fieldname => $info ) {
368 
369  $section = $info['section'] ?? '';
370 
371  if ( isset( $info['type'] ) && $info['type'] === 'file' ) {
372  $this->mUseMultipart = true;
373  }
374 
375  $field = static::loadInputFromParameters( $fieldname, $info, $this );
376 
377  $setSection =& $loadedDescriptor;
378  if ( $section ) {
379  foreach ( explode( '/', $section ) as $newName ) {
380  if ( !isset( $setSection[$newName] ) ) {
381  $setSection[$newName] = [];
382  }
383 
384  $setSection =& $setSection[$newName];
385  }
386  }
387 
388  $setSection[$fieldname] = $field;
389  $this->mFlatFields[$fieldname] = $field;
390  }
391 
392  $this->mFieldTree = array_merge( $this->mFieldTree, $loadedDescriptor );
393 
394  return $this;
395  }
396 
401  public function hasField( $fieldname ) {
402  return isset( $this->mFlatFields[$fieldname] );
403  }
404 
410  public function getField( $fieldname ) {
411  if ( !$this->hasField( $fieldname ) ) {
412  throw new DomainException( __METHOD__ . ': no field named ' . $fieldname );
413  }
414  return $this->mFlatFields[$fieldname];
415  }
416 
427  public function setDisplayFormat( $format ) {
428  if (
429  in_array( $format, $this->availableSubclassDisplayFormats, true ) ||
430  in_array( $this->displayFormat, $this->availableSubclassDisplayFormats, true )
431  ) {
432  throw new MWException( 'Cannot change display format after creation, ' .
433  'use HTMLForm::factory() instead' );
434  }
435 
436  if ( !in_array( $format, $this->availableDisplayFormats, true ) ) {
437  throw new MWException( 'Display format must be one of ' .
438  print_r(
439  array_merge(
440  $this->availableDisplayFormats,
441  $this->availableSubclassDisplayFormats
442  ),
443  true
444  ) );
445  }
446 
447  // Evil hack for mobile :(
448  if ( !$this->getConfig()->get( 'HTMLFormAllowTableFormat' ) && $format === 'table' ) {
449  $format = 'div';
450  }
451 
452  $this->displayFormat = $format;
453 
454  return $this;
455  }
456 
462  public function getDisplayFormat() {
463  return $this->displayFormat;
464  }
465 
483  public static function getClassFromDescriptor( $fieldname, &$descriptor ) {
484  if ( isset( $descriptor['class'] ) ) {
485  $class = $descriptor['class'];
486  } elseif ( isset( $descriptor['type'] ) ) {
487  $class = static::$typeMappings[$descriptor['type']];
488  $descriptor['class'] = $class;
489  } else {
490  $class = null;
491  }
492 
493  if ( !$class ) {
494  throw new MWException( "Descriptor with no class for $fieldname: "
495  . print_r( $descriptor, true ) );
496  }
497 
498  return $class;
499  }
500 
512  public static function loadInputFromParameters( $fieldname, $descriptor,
513  HTMLForm $parent = null
514  ) {
515  $class = static::getClassFromDescriptor( $fieldname, $descriptor );
516 
517  $descriptor['fieldname'] = $fieldname;
518  if ( $parent ) {
519  $descriptor['parent'] = $parent;
520  }
521 
522  # @todo This will throw a fatal error whenever someone try to use
523  # 'class' to feed a CSS class instead of 'cssclass'. Would be
524  # great to avoid the fatal error and show a nice error.
525  return new $class( $descriptor );
526  }
527 
537  public function prepareForm() {
538  # Check if we have the info we need
539  if ( !$this->mTitle instanceof Title && $this->mTitle !== false ) {
540  throw new MWException( 'You must call setTitle() on an HTMLForm' );
541  }
542 
543  # Load data from the request.
544  if (
545  $this->mFormIdentifier === null ||
546  $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier
547  ) {
548  $this->loadData();
549  } else {
550  $this->mFieldData = [];
551  }
552 
553  return $this;
554  }
555 
560  public function tryAuthorizedSubmit() {
561  $result = false;
562 
563  if ( $this->mFormIdentifier === null ) {
564  $identOkay = true;
565  } else {
566  $identOkay = $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier;
567  }
568 
569  $tokenOkay = false;
570  if ( $this->getMethod() !== 'post' ) {
571  $tokenOkay = true; // no session check needed
572  } elseif ( $this->getRequest()->wasPosted() ) {
573  $editToken = $this->getRequest()->getVal( 'wpEditToken' );
574  if ( $this->getUser()->isLoggedIn() || $editToken !== null ) {
575  // Session tokens for logged-out users have no security value.
576  // However, if the user gave one, check it in order to give a nice
577  // "session expired" error instead of "permission denied" or such.
578  $tokenOkay = $this->getUser()->matchEditToken( $editToken, $this->mTokenSalt );
579  } else {
580  $tokenOkay = true;
581  }
582  }
583 
584  if ( $tokenOkay && $identOkay ) {
585  $this->mWasSubmitted = true;
586  $result = $this->trySubmit();
587  }
588 
589  return $result;
590  }
591 
598  public function show() {
599  $this->prepareForm();
600 
601  $result = $this->tryAuthorizedSubmit();
602  if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
603  return $result;
604  }
605 
606  $this->displayForm( $result );
607 
608  return false;
609  }
610 
616  public function showAlways() {
617  $this->prepareForm();
618 
619  $result = $this->tryAuthorizedSubmit();
620 
621  $this->displayForm( $result );
622 
623  return $result;
624  }
625 
637  public function trySubmit() {
638  $valid = true;
639  $hoistedErrors = Status::newGood();
640  if ( $this->mValidationErrorMessage ) {
641  foreach ( $this->mValidationErrorMessage as $error ) {
642  $hoistedErrors->fatal( ...$error );
643  }
644  } else {
645  $hoistedErrors->fatal( 'htmlform-invalid-input' );
646  }
647 
648  $this->mWasSubmitted = true;
649 
650  # Check for cancelled submission
651  foreach ( $this->mFlatFields as $fieldname => $field ) {
652  if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
653  continue;
654  }
655  if ( $field->cancelSubmit( $this->mFieldData[$fieldname], $this->mFieldData ) ) {
656  $this->mWasSubmitted = false;
657  return false;
658  }
659  }
660 
661  # Check for validation
662  foreach ( $this->mFlatFields as $fieldname => $field ) {
663  if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
664  continue;
665  }
666  if ( $field->isHidden( $this->mFieldData ) ) {
667  continue;
668  }
669  $res = $field->validate( $this->mFieldData[$fieldname], $this->mFieldData );
670  if ( $res !== true ) {
671  $valid = false;
672  if ( $res !== false && !$field->canDisplayErrors() ) {
673  if ( is_string( $res ) ) {
674  $hoistedErrors->fatal( 'rawmessage', $res );
675  } else {
676  $hoistedErrors->fatal( $res );
677  }
678  }
679  }
680  }
681 
682  if ( !$valid ) {
683  return $hoistedErrors;
684  }
685 
686  $callback = $this->mSubmitCallback;
687  if ( !is_callable( $callback ) ) {
688  throw new MWException( 'HTMLForm: no submit callback provided. Use ' .
689  'setSubmitCallback() to set one.' );
690  }
691 
692  $data = $this->filterDataForSubmit( $this->mFieldData );
693 
694  $res = call_user_func( $callback, $data, $this );
695  if ( $res === false ) {
696  $this->mWasSubmitted = false;
697  }
698 
699  return $res;
700  }
701 
713  public function wasSubmitted() {
714  return $this->mWasSubmitted;
715  }
716 
727  public function setSubmitCallback( $cb ) {
728  $this->mSubmitCallback = $cb;
729 
730  return $this;
731  }
732 
741  public function setValidationErrorMessage( $msg ) {
742  $this->mValidationErrorMessage = $msg;
743 
744  return $this;
745  }
746 
754  public function setIntro( $msg ) {
755  $this->setPreText( $msg );
756 
757  return $this;
758  }
759 
768  public function setPreText( $msg ) {
769  $this->mPre = $msg;
770 
771  return $this;
772  }
773 
781  public function addPreText( $msg ) {
782  $this->mPre .= $msg;
783 
784  return $this;
785  }
786 
794  public function getPreText() {
795  return $this->mPre;
796  }
797 
806  public function addHeaderText( $msg, $section = null ) {
807  if ( $section === null ) {
808  $this->mHeader .= $msg;
809  } else {
810  if ( !isset( $this->mSectionHeaders[$section] ) ) {
811  $this->mSectionHeaders[$section] = '';
812  }
813  $this->mSectionHeaders[$section] .= $msg;
814  }
815 
816  return $this;
817  }
818 
828  public function setHeaderText( $msg, $section = null ) {
829  if ( $section === null ) {
830  $this->mHeader = $msg;
831  } else {
832  $this->mSectionHeaders[$section] = $msg;
833  }
834 
835  return $this;
836  }
837 
845  public function getHeaderText( $section = null ) {
846  if ( $section === null ) {
847  return $this->mHeader;
848  } else {
849  return $this->mSectionHeaders[$section] ?? '';
850  }
851  }
852 
861  public function addFooterText( $msg, $section = null ) {
862  if ( $section === null ) {
863  $this->mFooter .= $msg;
864  } else {
865  if ( !isset( $this->mSectionFooters[$section] ) ) {
866  $this->mSectionFooters[$section] = '';
867  }
868  $this->mSectionFooters[$section] .= $msg;
869  }
870 
871  return $this;
872  }
873 
883  public function setFooterText( $msg, $section = null ) {
884  if ( $section === null ) {
885  $this->mFooter = $msg;
886  } else {
887  $this->mSectionFooters[$section] = $msg;
888  }
889 
890  return $this;
891  }
892 
900  public function getFooterText( $section = null ) {
901  if ( $section === null ) {
902  return $this->mFooter;
903  } else {
904  return $this->mSectionFooters[$section] ?? '';
905  }
906  }
907 
915  public function addPostText( $msg ) {
916  $this->mPost .= $msg;
917 
918  return $this;
919  }
920 
928  public function setPostText( $msg ) {
929  $this->mPost = $msg;
930 
931  return $this;
932  }
933 
943  public function addHiddenField( $name, $value, array $attribs = [] ) {
944  $attribs += [ 'name' => $name ];
945  $this->mHiddenFields[] = [ $value, $attribs ];
946 
947  return $this;
948  }
949 
960  public function addHiddenFields( array $fields ) {
961  foreach ( $fields as $name => $value ) {
962  $this->mHiddenFields[] = [ $value, [ 'name' => $name ] ];
963  }
964 
965  return $this;
966  }
967 
995  public function addButton( $data ) {
996  if ( !is_array( $data ) ) {
997  $args = func_get_args();
998  if ( count( $args ) < 2 || count( $args ) > 4 ) {
999  throw new InvalidArgumentException(
1000  'Incorrect number of arguments for deprecated calling style'
1001  );
1002  }
1003  $data = [
1004  'name' => $args[0],
1005  'value' => $args[1],
1006  'id' => $args[2] ?? null,
1007  'attribs' => $args[3] ?? null,
1008  ];
1009  } else {
1010  if ( !isset( $data['name'] ) ) {
1011  throw new InvalidArgumentException( 'A name is required' );
1012  }
1013  if ( !isset( $data['value'] ) ) {
1014  throw new InvalidArgumentException( 'A value is required' );
1015  }
1016  }
1017  $this->mButtons[] = $data + [
1018  'id' => null,
1019  'attribs' => null,
1020  'flags' => null,
1021  'framed' => true,
1022  ];
1023 
1024  return $this;
1025  }
1026 
1036  public function setTokenSalt( $salt ) {
1037  $this->mTokenSalt = $salt;
1038 
1039  return $this;
1040  }
1041 
1054  public function displayForm( $submitResult ) {
1055  $this->getOutput()->addHTML( $this->getHTML( $submitResult ) );
1056  }
1057 
1066  public function getHTML( $submitResult ) {
1067  # For good measure (it is the default)
1068  $this->getOutput()->preventClickjacking();
1069  $this->getOutput()->addModules( 'mediawiki.htmlform' );
1070  $this->getOutput()->addModuleStyles( 'mediawiki.htmlform.styles' );
1071 
1072  $html = ''
1073  . $this->getErrorsOrWarnings( $submitResult, 'error' )
1074  . $this->getErrorsOrWarnings( $submitResult, 'warning' )
1075  . $this->getHeaderText()
1076  . $this->getBody()
1077  . $this->getHiddenFields()
1078  . $this->getButtons()
1079  . $this->getFooterText();
1080 
1081  $html = $this->wrapForm( $html );
1082 
1083  return '' . $this->mPre . $html . $this->mPost;
1084  }
1085 
1093  public function setCollapsibleOptions( $collapsedByDefault = false ) {
1094  $this->mCollapsible = true;
1095  $this->mCollapsed = $collapsedByDefault;
1096  return $this;
1097  }
1098 
1103  protected function getFormAttributes() {
1104  # Use multipart/form-data
1105  $encType = $this->mUseMultipart
1106  ? 'multipart/form-data'
1107  : 'application/x-www-form-urlencoded';
1108  # Attributes
1109  $attribs = [
1110  'class' => 'mw-htmlform',
1111  'action' => $this->getAction(),
1112  'method' => $this->getMethod(),
1113  'enctype' => $encType,
1114  ];
1115  if ( $this->mId ) {
1116  $attribs['id'] = $this->mId;
1117  }
1118  if ( is_string( $this->mAutocomplete ) ) {
1119  $attribs['autocomplete'] = $this->mAutocomplete;
1120  }
1121  if ( $this->mName ) {
1122  $attribs['name'] = $this->mName;
1123  }
1124  if ( $this->needsJSForHtml5FormValidation() ) {
1125  $attribs['novalidate'] = true;
1126  }
1127  return $attribs;
1128  }
1129 
1137  public function wrapForm( $html ) {
1138  # Include a <fieldset> wrapper for style, if requested.
1139  if ( $this->mWrapperLegend !== false ) {
1140  $legend = is_string( $this->mWrapperLegend ) ? $this->mWrapperLegend : false;
1141  $html = Xml::fieldset( $legend, $html, $this->mWrapperAttributes );
1142  }
1143 
1144  return Html::rawElement(
1145  'form',
1146  $this->getFormAttributes(),
1147  $html
1148  );
1149  }
1150 
1155  public function getHiddenFields() {
1156  $html = '';
1157  if ( $this->mFormIdentifier !== null ) {
1158  $html .= Html::hidden(
1159  'wpFormIdentifier',
1160  $this->mFormIdentifier
1161  ) . "\n";
1162  }
1163  if ( $this->getMethod() === 'post' ) {
1164  $html .= Html::hidden(
1165  'wpEditToken',
1166  $this->getUser()->getEditToken( $this->mTokenSalt ),
1167  [ 'id' => 'wpEditToken' ]
1168  ) . "\n";
1169  $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1170  }
1171 
1172  $articlePath = $this->getConfig()->get( 'ArticlePath' );
1173  if ( strpos( $articlePath, '?' ) !== false && $this->getMethod() === 'get' ) {
1174  $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1175  }
1176 
1177  foreach ( $this->mHiddenFields as $data ) {
1178  list( $value, $attribs ) = $data;
1179  $html .= Html::hidden( $attribs['name'], $value, $attribs ) . "\n";
1180  }
1181 
1182  return $html;
1183  }
1184 
1189  public function getButtons() {
1190  $buttons = '';
1191  $useMediaWikiUIEverywhere = $this->getConfig()->get( 'UseMediaWikiUIEverywhere' );
1192 
1193  if ( $this->mShowSubmit ) {
1194  $attribs = [];
1195 
1196  if ( isset( $this->mSubmitID ) ) {
1197  $attribs['id'] = $this->mSubmitID;
1198  }
1199 
1200  if ( isset( $this->mSubmitName ) ) {
1201  $attribs['name'] = $this->mSubmitName;
1202  }
1203 
1204  if ( isset( $this->mSubmitTooltip ) ) {
1205  $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
1206  }
1207 
1208  $attribs['class'] = [ 'mw-htmlform-submit' ];
1209 
1210  if ( $useMediaWikiUIEverywhere ) {
1211  foreach ( $this->mSubmitFlags as $flag ) {
1212  $attribs['class'][] = 'mw-ui-' . $flag;
1213  }
1214  $attribs['class'][] = 'mw-ui-button';
1215  }
1216 
1217  $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
1218  }
1219 
1220  if ( $this->mShowReset ) {
1221  $buttons .= Html::element(
1222  'input',
1223  [
1224  'type' => 'reset',
1225  'value' => $this->msg( 'htmlform-reset' )->text(),
1226  'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null,
1227  ]
1228  ) . "\n";
1229  }
1230 
1231  if ( $this->mShowCancel ) {
1232  $target = $this->mCancelTarget ?: Title::newMainPage();
1233  if ( $target instanceof Title ) {
1234  $target = $target->getLocalURL();
1235  }
1236  $buttons .= Html::element(
1237  'a',
1238  [
1239  'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null,
1240  'href' => $target,
1241  ],
1242  $this->msg( 'cancel' )->text()
1243  ) . "\n";
1244  }
1245 
1246  foreach ( $this->mButtons as $button ) {
1247  $attrs = [
1248  'type' => 'submit',
1249  'name' => $button['name'],
1250  'value' => $button['value']
1251  ];
1252 
1253  if ( isset( $button['label-message'] ) ) {
1254  $label = $this->getMessage( $button['label-message'] )->parse();
1255  } elseif ( isset( $button['label'] ) ) {
1256  $label = htmlspecialchars( $button['label'] );
1257  } elseif ( isset( $button['label-raw'] ) ) {
1258  $label = $button['label-raw'];
1259  } else {
1260  $label = htmlspecialchars( $button['value'] );
1261  }
1262 
1263  if ( $button['attribs'] ) {
1264  $attrs += $button['attribs'];
1265  }
1266 
1267  if ( isset( $button['id'] ) ) {
1268  $attrs['id'] = $button['id'];
1269  }
1270 
1271  if ( $useMediaWikiUIEverywhere ) {
1272  $attrs['class'] = isset( $attrs['class'] ) ? (array)$attrs['class'] : [];
1273  $attrs['class'][] = 'mw-ui-button';
1274  }
1275 
1276  $buttons .= Html::rawElement( 'button', $attrs, $label ) . "\n";
1277  }
1278 
1279  if ( !$buttons ) {
1280  return '';
1281  }
1282 
1283  return Html::rawElement( 'span',
1284  [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n";
1285  }
1286 
1291  public function getBody() {
1292  return $this->displaySection( $this->mFieldTree, $this->mTableId );
1293  }
1294 
1303  public function getErrorsOrWarnings( $elements, $elementsType ) {
1304  if ( !in_array( $elementsType, [ 'error', 'warning' ], true ) ) {
1305  throw new DomainException( $elementsType . ' is not a valid type.' );
1306  }
1307  $elementstr = false;
1308  if ( $elements instanceof Status ) {
1309  list( $errorStatus, $warningStatus ) = $elements->splitByErrorType();
1310  $status = $elementsType === 'error' ? $errorStatus : $warningStatus;
1311  if ( $status->isGood() ) {
1312  $elementstr = '';
1313  } else {
1314  $elementstr = $this->getOutput()->parseAsInterface(
1315  $status->getWikiText()
1316  );
1317  }
1318  } elseif ( is_array( $elements ) && $elementsType === 'error' ) {
1319  $elementstr = $this->formatErrors( $elements );
1320  } elseif ( $elementsType === 'error' ) {
1321  $elementstr = $elements;
1322  }
1323 
1324  return $elementstr
1325  ? Html::rawElement( 'div', [ 'class' => $elementsType . 'box' ], $elementstr )
1326  : '';
1327  }
1328 
1336  public function formatErrors( $errors ) {
1337  $errorstr = '';
1338 
1339  foreach ( $errors as $error ) {
1340  $errorstr .= Html::rawElement(
1341  'li',
1342  [],
1343  $this->getMessage( $error )->parse()
1344  );
1345  }
1346 
1347  $errorstr = Html::rawElement( 'ul', [], $errorstr );
1348 
1349  return $errorstr;
1350  }
1351 
1359  public function setSubmitText( $t ) {
1360  $this->mSubmitText = $t;
1361 
1362  return $this;
1363  }
1364 
1371  public function setSubmitDestructive() {
1372  $this->mSubmitFlags = [ 'destructive', 'primary' ];
1373 
1374  return $this;
1375  }
1376 
1385  public function setSubmitTextMsg( $msg ) {
1386  if ( !$msg instanceof Message ) {
1387  $msg = $this->msg( $msg );
1388  }
1389  $this->setSubmitText( $msg->text() );
1390 
1391  return $this;
1392  }
1393 
1398  public function getSubmitText() {
1399  return $this->mSubmitText ?: $this->msg( 'htmlform-submit' )->text();
1400  }
1401 
1407  public function setSubmitName( $name ) {
1408  $this->mSubmitName = $name;
1409 
1410  return $this;
1411  }
1412 
1418  public function setSubmitTooltip( $name ) {
1419  $this->mSubmitTooltip = $name;
1420 
1421  return $this;
1422  }
1423 
1432  public function setSubmitID( $t ) {
1433  $this->mSubmitID = $t;
1434 
1435  return $this;
1436  }
1437 
1453  public function setFormIdentifier( $ident ) {
1454  $this->mFormIdentifier = $ident;
1455 
1456  return $this;
1457  }
1458 
1469  public function suppressDefaultSubmit( $suppressSubmit = true ) {
1470  $this->mShowSubmit = !$suppressSubmit;
1471 
1472  return $this;
1473  }
1474 
1481  public function showCancel( $show = true ) {
1482  $this->mShowCancel = $show;
1483  return $this;
1484  }
1485 
1492  public function setCancelTarget( $target ) {
1493  $this->mCancelTarget = $target;
1494  return $this;
1495  }
1496 
1506  public function setTableId( $id ) {
1507  $this->mTableId = $id;
1508 
1509  return $this;
1510  }
1511 
1517  public function setId( $id ) {
1518  $this->mId = $id;
1519 
1520  return $this;
1521  }
1522 
1527  public function setName( $name ) {
1528  $this->mName = $name;
1529 
1530  return $this;
1531  }
1532 
1544  public function setWrapperLegend( $legend ) {
1545  $this->mWrapperLegend = $legend;
1546 
1547  return $this;
1548  }
1549 
1557  public function setWrapperAttributes( $attributes ) {
1558  $this->mWrapperAttributes = $attributes;
1559 
1560  return $this;
1561  }
1562 
1572  public function setWrapperLegendMsg( $msg ) {
1573  if ( !$msg instanceof Message ) {
1574  $msg = $this->msg( $msg );
1575  }
1576  $this->setWrapperLegend( $msg->text() );
1577 
1578  return $this;
1579  }
1580 
1590  public function setMessagePrefix( $p ) {
1591  $this->mMessagePrefix = $p;
1592 
1593  return $this;
1594  }
1595 
1603  public function setTitle( $t ) {
1604  $this->mTitle = $t;
1605 
1606  return $this;
1607  }
1608 
1613  public function getTitle() {
1614  return $this->mTitle === false
1615  ? $this->getContext()->getTitle()
1616  : $this->mTitle;
1617  }
1618 
1626  public function setMethod( $method = 'post' ) {
1627  $this->mMethod = strtolower( $method );
1628 
1629  return $this;
1630  }
1631 
1635  public function getMethod() {
1636  return $this->mMethod;
1637  }
1638 
1648  protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
1649  return Xml::fieldset( $legend, $section, $attributes ) . "\n";
1650  }
1651 
1668  public function displaySection( $fields,
1669  $sectionName = '',
1670  $fieldsetIDPrefix = '',
1671  &$hasUserVisibleFields = false
1672  ) {
1673  if ( $this->mFieldData === null ) {
1674  throw new LogicException( 'HTMLForm::displaySection() called on uninitialized field data. '
1675  . 'You probably called displayForm() without calling prepareForm() first.' );
1676  }
1677 
1678  $displayFormat = $this->getDisplayFormat();
1679 
1680  $html = [];
1681  $subsectionHtml = '';
1682  $hasLabel = false;
1683 
1684  // Conveniently, PHP method names are case-insensitive.
1685  // For grep: this can call getDiv, getRaw, getInline, getVForm, getOOUI
1686  $getFieldHtmlMethod = $displayFormat === 'table' ? 'getTableRow' : ( 'get' . $displayFormat );
1687 
1688  foreach ( $fields as $key => $value ) {
1689  if ( $value instanceof HTMLFormField ) {
1690  $v = array_key_exists( $key, $this->mFieldData )
1691  ? $this->mFieldData[$key]
1692  : $value->getDefault();
1693 
1694  $retval = $value->$getFieldHtmlMethod( $v );
1695 
1696  // check, if the form field should be added to
1697  // the output.
1698  if ( $value->hasVisibleOutput() ) {
1699  $html[] = $retval;
1700 
1701  $labelValue = trim( $value->getLabel() );
1702  if ( $labelValue !== "\u{00A0}" && $labelValue !== '&#160;' && $labelValue !== '' ) {
1703  $hasLabel = true;
1704  }
1705 
1706  $hasUserVisibleFields = true;
1707  }
1708  } elseif ( is_array( $value ) ) {
1709  $subsectionHasVisibleFields = false;
1710  $section =
1711  $this->displaySection( $value,
1712  "mw-htmlform-$key",
1713  "$fieldsetIDPrefix$key-",
1714  $subsectionHasVisibleFields );
1715  $legend = null;
1716 
1717  if ( $subsectionHasVisibleFields === true ) {
1718  // Display the section with various niceties.
1719  $hasUserVisibleFields = true;
1720 
1721  $legend = $this->getLegend( $key );
1722 
1723  $section = $this->getHeaderText( $key ) .
1724  $section .
1725  $this->getFooterText( $key );
1726 
1727  $attributes = [];
1728  if ( $fieldsetIDPrefix ) {
1729  $attributes['id'] = Sanitizer::escapeIdForAttribute( "$fieldsetIDPrefix$key" );
1730  }
1731  $subsectionHtml .= $this->wrapFieldSetSection(
1732  $legend, $section, $attributes, $fields === $this->mFieldTree
1733  );
1734  } else {
1735  // Just return the inputs, nothing fancy.
1736  $subsectionHtml .= $section;
1737  }
1738  }
1739  }
1740 
1741  $html = $this->formatSection( $html, $sectionName, $hasLabel );
1742 
1743  if ( $subsectionHtml ) {
1744  if ( $this->mSubSectionBeforeFields ) {
1745  return $subsectionHtml . "\n" . $html;
1746  } else {
1747  return $html . "\n" . $subsectionHtml;
1748  }
1749  } else {
1750  return $html;
1751  }
1752  }
1753 
1761  protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
1762  if ( !$fieldsHtml ) {
1763  // Do not generate any wrappers for empty sections. Sections may be empty if they only have
1764  // subsections, but no fields. A legend will still be added in wrapFieldSetSection().
1765  return '';
1766  }
1767 
1768  $displayFormat = $this->getDisplayFormat();
1769  $html = implode( '', $fieldsHtml );
1770 
1771  if ( $displayFormat === 'raw' ) {
1772  return $html;
1773  }
1774 
1775  $classes = [];
1776 
1777  if ( !$anyFieldHasLabel ) { // Avoid strange spacing when no labels exist
1778  $classes[] = 'mw-htmlform-nolabel';
1779  }
1780 
1781  $attribs = [
1782  'class' => implode( ' ', $classes ),
1783  ];
1784 
1785  if ( $sectionName ) {
1786  $attribs['id'] = Sanitizer::escapeIdForAttribute( $sectionName );
1787  }
1788 
1789  if ( $displayFormat === 'table' ) {
1790  return Html::rawElement( 'table',
1791  $attribs,
1792  Html::rawElement( 'tbody', [], "\n$html\n" ) ) . "\n";
1793  } elseif ( $displayFormat === 'inline' ) {
1794  return Html::rawElement( 'span', $attribs, "\n$html\n" );
1795  } else {
1796  return Html::rawElement( 'div', $attribs, "\n$html\n" );
1797  }
1798  }
1799 
1803  public function loadData() {
1804  $fieldData = [];
1805 
1806  foreach ( $this->mFlatFields as $fieldname => $field ) {
1807  $request = $this->getRequest();
1808  if ( $field->skipLoadData( $request ) ) {
1809  continue;
1810  } elseif ( !empty( $field->mParams['disabled'] ) ) {
1811  $fieldData[$fieldname] = $field->getDefault();
1812  } else {
1813  $fieldData[$fieldname] = $field->loadDataFromRequest( $request );
1814  }
1815  }
1816 
1817  # Filter data.
1818  foreach ( $fieldData as $name => &$value ) {
1819  $field = $this->mFlatFields[$name];
1820  $value = $field->filter( $value, $this->mFlatFields );
1821  }
1822 
1823  $this->mFieldData = $fieldData;
1824  }
1825 
1833  public function suppressReset( $suppressReset = true ) {
1834  $this->mShowReset = !$suppressReset;
1835 
1836  return $this;
1837  }
1838 
1848  public function filterDataForSubmit( $data ) {
1849  return $data;
1850  }
1851 
1860  public function getLegend( $key ) {
1861  return $this->msg( "{$this->mMessagePrefix}-$key" )->text();
1862  }
1863 
1874  public function setAction( $action ) {
1875  $this->mAction = $action;
1876 
1877  return $this;
1878  }
1879 
1887  public function getAction() {
1888  // If an action is alredy provided, return it
1889  if ( $this->mAction !== false ) {
1890  return $this->mAction;
1891  }
1892 
1893  $articlePath = $this->getConfig()->get( 'ArticlePath' );
1894  // Check whether we are in GET mode and the ArticlePath contains a "?"
1895  // meaning that getLocalURL() would return something like "index.php?title=...".
1896  // As browser remove the query string before submitting GET forms,
1897  // it means that the title would be lost. In such case use wfScript() instead
1898  // and put title in an hidden field (see getHiddenFields()).
1899  if ( strpos( $articlePath, '?' ) !== false && $this->getMethod() === 'get' ) {
1900  return wfScript();
1901  }
1902 
1903  return $this->getTitle()->getLocalURL();
1904  }
1905 
1916  public function setAutocomplete( $autocomplete ) {
1917  $this->mAutocomplete = $autocomplete;
1918 
1919  return $this;
1920  }
1921 
1928  protected function getMessage( $value ) {
1929  return Message::newFromSpecifier( $value )->setContext( $this );
1930  }
1931 
1941  public function needsJSForHtml5FormValidation() {
1942  foreach ( $this->mFlatFields as $fieldname => $field ) {
1943  if ( $field->needsJSForHtml5FormValidation() ) {
1944  return true;
1945  }
1946  }
1947  return false;
1948  }
1949 }
HTMLForm\$mSubSectionBeforeFields
$mSubSectionBeforeFields
If true, sections that contain both fields and subsections will render their subsections before their...
Definition: HTMLForm.php:271
HTMLForm\getLegend
getLegend( $key)
Get a string to go in the "<legend>" of a section fieldset.
Definition: HTMLForm.php:1860
HTMLForm\$mTokenSalt
string array $mTokenSalt
Salt for the edit token.
Definition: HTMLForm.php:262
HTMLForm\$typeMappings
static $typeMappings
Definition: HTMLForm.php:133
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:33
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:63
HTMLForm\setPostText
setPostText( $msg)
Set text at the end of the display.
Definition: HTMLForm.php:928
HTMLForm\setAutocomplete
setAutocomplete( $autocomplete)
Set the value for the autocomplete attribute of the form.
Definition: HTMLForm.php:1916
HTMLForm\$mSubmitText
$mSubmitText
Definition: HTMLForm.php:207
HTMLForm\prepareForm
prepareForm()
Prepare form for submission.
Definition: HTMLForm.php:537
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:40
HTMLForm\hasField
hasField( $fieldname)
Definition: HTMLForm.php:401
HTMLForm\setPreText
setPreText( $msg)
Set the introductory message HTML, overwriting any existing message.
Definition: HTMLForm.php:768
HTMLForm\suppressDefaultSubmit
suppressDefaultSubmit( $suppressSubmit=true)
Stop a default submit button being shown for this form.
Definition: HTMLForm.php:1469
HTMLForm\$mSectionHeaders
$mSectionHeaders
Definition: HTMLForm.php:198
HTMLForm\setSubmitName
setSubmitName( $name)
Definition: HTMLForm.php:1407
HTMLForm\setFooterText
setFooterText( $msg, $section=null)
Set footer text, inside the form.
Definition: HTMLForm.php:883
HTMLForm\$mFieldTree
$mFieldTree
Definition: HTMLForm.php:184
HTMLForm\setIntro
setIntro( $msg)
Set the introductory message, overwriting any existing message.
Definition: HTMLForm.php:754
HTMLForm\tryAuthorizedSubmit
tryAuthorizedSubmit()
Try submitting, with edit token check first.
Definition: HTMLForm.php:560
HTMLForm\setWrapperAttributes
setWrapperAttributes( $attributes)
For internal use only.
Definition: HTMLForm.php:1557
HTMLForm\setSubmitTooltip
setSubmitTooltip( $name)
Definition: HTMLForm.php:1418
HTMLForm\addHeaderText
addHeaderText( $msg, $section=null)
Add HTML to the header, inside the form.
Definition: HTMLForm.php:806
HTMLForm\$mTitle
$mTitle
Definition: HTMLForm.php:211
HTMLForm\setDisplayFormat
setDisplayFormat( $format)
Set format in which to display the form.
Definition: HTMLForm.php:427
HTMLForm\wrapForm
wrapForm( $html)
Wrap the form innards in an actual "<form>" element.
Definition: HTMLForm.php:1137
HTMLForm\getHiddenFields
getHiddenFields()
Get the hidden fields that should go inside the form.
Definition: HTMLForm.php:1155
HTMLForm\$mCollapsed
bool $mCollapsed
Whether the form is collapsed by default.
Definition: HTMLForm.php:234
HTMLForm\getDisplayFormat
getDisplayFormat()
Getter for displayFormat.
Definition: HTMLForm.php:462
HTMLForm\$mWasSubmitted
$mWasSubmitted
Definition: HTMLForm.php:213
HTMLForm\$mFieldData
$mFieldData
Definition: HTMLForm.php:178
HTMLForm\setHeaderText
setHeaderText( $msg, $section=null)
Set header text, inside the form.
Definition: HTMLForm.php:828
HTMLForm\formatErrors
formatErrors( $errors)
Format a stack of error messages into a single HTML string.
Definition: HTMLForm.php:1336
HTMLForm\getClassFromDescriptor
static getClassFromDescriptor( $fieldname, &$descriptor)
Get the HTMLFormField subclass for this descriptor.
Definition: HTMLForm.php:483
HTMLForm\showCancel
showCancel( $show=true)
Show a cancel button (or prevent it).
Definition: HTMLForm.php:1481
HTMLForm\addFields
addFields( $descriptor)
Add fields to the form.
Definition: HTMLForm.php:364
HTMLForm\$mWrapperLegend
$mWrapperLegend
Definition: HTMLForm.php:255
HTMLForm\$mUseMultipart
$mUseMultipart
Definition: HTMLForm.php:243
HTMLForm\$mShowSubmit
$mShowSubmit
Definition: HTMLForm.php:186
HTMLForm\$mAutocomplete
string null $mAutocomplete
Form attribute autocomplete.
Definition: HTMLForm.php:241
HTMLForm\$mCancelTarget
$mCancelTarget
Definition: HTMLForm.php:190
HTMLForm\setTokenSalt
setTokenSalt( $salt)
Set the salt for the edit token.
Definition: HTMLForm.php:1036
HTMLForm\$mSubmitTooltip
$mSubmitTooltip
Definition: HTMLForm.php:208
HTMLForm\$displayFormat
string $displayFormat
Format in which to display form.
Definition: HTMLForm.php:278
HTMLForm\show
show()
The here's-one-I-made-earlier option: do the submission if posted, or display the form with or withou...
Definition: HTMLForm.php:598
HTMLForm\$mSubmitID
$mSubmitID
Definition: HTMLForm.php:205
HTMLForm\setCancelTarget
setCancelTarget( $target)
Sets the target where the user is redirected to after clicking cancel.
Definition: HTMLForm.php:1492
HTMLForm\getBody
getBody()
Get the whole body of the form.
Definition: HTMLForm.php:1291
VFormHTMLForm
Compact stacked vertical format for forms.
Definition: VFormHTMLForm.php:27
ContextSource\getRequest
getRequest()
Definition: ContextSource.php:71
Title\newMainPage
static newMainPage(MessageLocalizer $localizer=null)
Create a new Title for the Main Page.
Definition: Title.php:646
HTMLForm\$mShowReset
$mShowReset
Definition: HTMLForm.php:185
HTMLForm\$mTableId
$mTableId
Definition: HTMLForm.php:203
Message
$res
$res
Definition: testCompression.php:54
HTMLForm\$mSubmitName
$mSubmitName
Definition: HTMLForm.php:206
ContextSource\getUser
getUser()
Definition: ContextSource.php:120
HTMLForm\getAction
getAction()
Get the value for the action attribute of the form.
Definition: HTMLForm.php:1887
HTMLForm\setMethod
setMethod( $method='post')
Set the method used to submit the form.
Definition: HTMLForm.php:1626
Linker\tooltipAndAccesskeyAttribs
static tooltipAndAccesskeyAttribs( $name, array $msgParams=[], $options=null)
Returns the attributes for the tooltip and access key.
Definition: Linker.php:2192
HTMLForm\__construct
__construct( $descriptor, $context=null, $messagePrefix='')
Build a new HTMLForm from an array of field attributes.
Definition: HTMLForm.php:329
Status
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: Status.php:40
Xml\fieldset
static fieldset( $legend=false, $content=false, $attribs=[])
Shortcut for creating fieldsets.
Definition: Xml.php:609
HTMLForm\setSubmitText
setSubmitText( $t)
Set the text for the submit button.
Definition: HTMLForm.php:1359
OOUIHTMLForm
Compact stacked vertical format for forms, implemented using OOUI widgets.
Definition: OOUIHTMLForm.php:27
HTMLForm\$mSubmitFlags
string[] $mSubmitFlags
Definition: HTMLForm.php:188
HTMLForm\trySubmit
trySubmit()
Validate all the fields, and call the submission callback function if everything is kosher.
Definition: HTMLForm.php:637
StatusValue\isGood
isGood()
Returns whether the operation completed and didn't have any error or warnings.
Definition: StatusValue.php:121
HTMLForm\setCollapsibleOptions
setCollapsibleOptions( $collapsedByDefault=false)
Enable collapsible mode, and set whether the form is collapsed by default.
Definition: HTMLForm.php:1093
MWException
MediaWiki exception.
Definition: MWException.php:26
HTMLForm\$mAction
bool string $mAction
Form action URL.
Definition: HTMLForm.php:220
HTMLForm\setFormIdentifier
setFormIdentifier( $ident)
Set an internal identifier for this form.
Definition: HTMLForm.php:1453
HTMLForm\getHeaderText
getHeaderText( $section=null)
Get header text.
Definition: HTMLForm.php:845
HTMLForm\addButton
addButton( $data)
Add a button to the form.
Definition: HTMLForm.php:995
wfScript
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
Definition: GlobalFunctions.php:2629
HTMLForm\addHiddenField
addHiddenField( $name, $value, array $attribs=[])
Add a hidden field to the output.
Definition: HTMLForm.php:943
ContextSource\getOutput
getOutput()
Definition: ContextSource.php:112
HTMLForm\setSubmitID
setSubmitID( $t)
Set the id for the submit button.
Definition: HTMLForm.php:1432
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:29
HTMLFormField
The parent class to generate form fields.
Definition: HTMLFormField.php:7
$args
if( $line===false) $args
Definition: mcc.php:124
HTMLForm\wasSubmitted
wasSubmitted()
Test whether the form was considered to have been submitted or not, i.e.
Definition: HTMLForm.php:713
HTMLForm\$mFormIdentifier
$mFormIdentifier
Definition: HTMLForm.php:210
HTMLForm\formatSection
formatSection(array $fieldsHtml, $sectionName, $anyFieldHasLabel)
Put a form section together from the individual fields' HTML, merging it and wrapping.
Definition: HTMLForm.php:1761
HTMLForm\$mButtons
array[] $mButtons
@phan-var array<array{name:string,value:string,label-message?:string|string[]|MessageSpecifier,...
Definition: HTMLForm.php:253
HTMLForm\setMessagePrefix
setMessagePrefix( $p)
Set the prefix for various default messages.
Definition: HTMLForm.php:1590
HTMLForm\setSubmitCallback
setSubmitCallback( $cb)
Set a callback to a function to do something with the form once it's been successfully validated.
Definition: HTMLForm.php:727
HTMLForm\$mId
$mId
Definition: HTMLForm.php:201
HTMLForm\$mSectionFooters
$mSectionFooters
Definition: HTMLForm.php:199
HTMLForm\loadInputFromParameters
static loadInputFromParameters( $fieldname, $descriptor, HTMLForm $parent=null)
Initialise a new Object for the field.
Definition: HTMLForm.php:512
ContextSource\setContext
setContext(IContextSource $context)
Definition: ContextSource.php:55
HTMLForm\$mPost
$mPost
Definition: HTMLForm.php:200
ContextSource\msg
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:168
HTMLForm\getErrorsOrWarnings
getErrorsOrWarnings( $elements, $elementsType)
Returns a formatted list of errors or warnings from the given elements.
Definition: HTMLForm.php:1303
HTMLForm\$mFooter
$mFooter
Definition: HTMLForm.php:197
HTMLForm\getFormAttributes
getFormAttributes()
Get HTML attributes for the <form> tag.
Definition: HTMLForm.php:1103
HTMLForm\$mMethod
$mMethod
Definition: HTMLForm.php:212
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:81
HTMLForm\setId
setId( $id)
Definition: HTMLForm.php:1517
HTMLForm\$availableSubclassDisplayFormats
array $availableSubclassDisplayFormats
Available formats in which to display the form.
Definition: HTMLForm.php:295
HTMLForm\$availableDisplayFormats
array $availableDisplayFormats
Available formats in which to display the form.
Definition: HTMLForm.php:284
HTMLForm\getPreText
getPreText()
Get the introductory message HTML.
Definition: HTMLForm.php:794
HTMLForm\setWrapperLegend
setWrapperLegend( $legend)
Prompt the whole form to be wrapped in a "<fieldset>", with this text as its "<legend>" element.
Definition: HTMLForm.php:1544
HTMLForm\displaySection
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
Definition: HTMLForm.php:1668
HTMLForm\$mSubmitCallback
$mSubmitCallback
Definition: HTMLForm.php:192
HTMLForm\loadData
loadData()
Construct the form fields from the Descriptor array.
Definition: HTMLForm.php:1803
HTMLForm\showAlways
showAlways()
Same as self::show with the difference, that the form will be added to the output,...
Definition: HTMLForm.php:616
HTMLForm\$mName
$mName
Definition: HTMLForm.php:202
HTMLForm\setSubmitDestructive
setSubmitDestructive()
Identify that the submit button in the form has a destructive action.
Definition: HTMLForm.php:1371
HTMLForm\setValidationErrorMessage
setValidationErrorMessage( $msg)
Set a message to display on a validation error.
Definition: HTMLForm.php:741
HTMLForm\$mCollapsible
bool $mCollapsible
Whether the form can be collapsed.
Definition: HTMLForm.php:227
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:53
HTMLForm\setSubmitTextMsg
setSubmitTextMsg( $msg)
Set the text for the submit button to a message.
Definition: HTMLForm.php:1385
Title
Represents a title within MediaWiki.
Definition: Title.php:42
HTMLForm\setName
setName( $name)
Definition: HTMLForm.php:1527
HTMLForm\$mPre
$mPre
Definition: HTMLForm.php:195
HTMLForm\getHTML
getHTML( $submitResult)
Returns the raw HTML generated by the form.
Definition: HTMLForm.php:1066
HTMLForm\getSubmitText
getSubmitText()
Get the text for the submit button, either customised or a default.
Definition: HTMLForm.php:1398
HTMLForm\getMessage
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
Definition: HTMLForm.php:1928
HTMLForm\addHiddenFields
addHiddenFields(array $fields)
Add an array of hidden fields to the output.
Definition: HTMLForm.php:960
HTMLForm\$mShowCancel
$mShowCancel
Definition: HTMLForm.php:189
HTMLForm\$mWrapperAttributes
$mWrapperAttributes
Definition: HTMLForm.php:256
HTMLForm\setWrapperLegendMsg
setWrapperLegendMsg( $msg)
Prompt the whole form to be wrapped in a "<fieldset>", with this message as its "<legend>" element.
Definition: HTMLForm.php:1572
HTMLForm\$mValidationErrorMessage
$mValidationErrorMessage
Definition: HTMLForm.php:193
HTMLForm\setAction
setAction( $action)
Set the value for the action attribute of the form.
Definition: HTMLForm.php:1874
HTMLForm\$mHeader
$mHeader
Definition: HTMLForm.php:196
HTMLForm\setTitle
setTitle( $t)
Set the title for form submission.
Definition: HTMLForm.php:1603
HTMLForm\setTableId
setTableId( $id)
Set the id of the <table> or outermost <div> element.
Definition: HTMLForm.php:1506
HTMLForm\$mMessagePrefix
$mMessagePrefix
Definition: HTMLForm.php:180
HTMLForm\displayForm
displayForm( $submitResult)
Display the form (sending to the context's OutputPage object), with an appropriate error message or s...
Definition: HTMLForm.php:1054
HTMLForm\getTitle
getTitle()
Get the title.
Definition: HTMLForm.php:1613
HTMLForm\filterDataForSubmit
filterDataForSubmit( $data)
Overload this if you want to apply special filtration routines to the form as a whole,...
Definition: HTMLForm.php:1848
HTMLForm\getMethod
getMethod()
Definition: HTMLForm.php:1635
HTMLForm\addPreText
addPreText( $msg)
Add HTML to introductory message.
Definition: HTMLForm.php:781
$t
$t
Definition: testCompression.php:71
HTMLForm\getField
getField( $fieldname)
Definition: HTMLForm.php:410
HTMLForm\$mHiddenFields
array[] $mHiddenFields
@phan-var array<int,array{0:string,1:array}>
Definition: HTMLForm.php:248
HTMLForm\addPostText
addPostText( $msg)
Add text to the end of the display.
Definition: HTMLForm.php:915
HTMLForm\wrapFieldSetSection
wrapFieldSetSection( $legend, $section, $attributes, $isRoot)
Wraps the given $section into an user-visible fieldset.
Definition: HTMLForm.php:1648
HTMLForm\suppressReset
suppressReset( $suppressReset=true)
Stop a reset button being shown for this form.
Definition: HTMLForm.php:1833
HTMLForm\getFooterText
getFooterText( $section=null)
Get footer text.
Definition: HTMLForm.php:900
HTMLForm\$mFlatFields
HTMLFormField[] $mFlatFields
Definition: HTMLForm.php:183
HTMLForm\factory
static factory( $displayFormat,... $arguments)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:307
HTMLForm\getButtons
getButtons()
Get the submit and (potentially) reset buttons.
Definition: HTMLForm.php:1189
HTMLForm\addFooterText
addFooterText( $msg, $section=null)
Add footer text, inside the form.
Definition: HTMLForm.php:861
Xml\submitButton
static submitButton( $value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
Definition: Xml.php:459
HTMLForm\needsJSForHtml5FormValidation
needsJSForHtml5FormValidation()
Whether this form, with its current fields, requires the user agent to have JavaScript enabled for th...
Definition: HTMLForm.php:1941
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition: HTMLForm.php:131