MediaWiki  master
HTMLForm.php
Go to the documentation of this file.
1 <?php
2 
24 use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
28 
144 class HTMLForm extends ContextSource {
145  use ProtectedHookAccessorTrait;
146 
148  public static $typeMappings = [
149  'api' => HTMLApiField::class,
150  'text' => HTMLTextField::class,
151  'textwithbutton' => HTMLTextFieldWithButton::class,
152  'textarea' => HTMLTextAreaField::class,
153  'select' => HTMLSelectField::class,
154  'combobox' => HTMLComboboxField::class,
155  'radio' => HTMLRadioField::class,
156  'multiselect' => HTMLMultiSelectField::class,
157  'limitselect' => HTMLSelectLimitField::class,
158  'check' => HTMLCheckField::class,
159  'toggle' => HTMLCheckField::class,
160  'int' => HTMLIntField::class,
161  'file' => HTMLFileField::class,
162  'float' => HTMLFloatField::class,
163  'info' => HTMLInfoField::class,
164  'selectorother' => HTMLSelectOrOtherField::class,
165  'selectandother' => HTMLSelectAndOtherField::class,
166  'namespaceselect' => HTMLSelectNamespace::class,
167  'namespaceselectwithbutton' => HTMLSelectNamespaceWithButton::class,
168  'tagfilter' => HTMLTagFilter::class,
169  'sizefilter' => HTMLSizeFilterField::class,
170  'submit' => HTMLSubmitField::class,
171  'hidden' => HTMLHiddenField::class,
172  'edittools' => HTMLEditTools::class,
173  'checkmatrix' => HTMLCheckMatrix::class,
174  'cloner' => HTMLFormFieldCloner::class,
175  'autocompleteselect' => HTMLAutoCompleteSelectField::class,
176  'language' => HTMLSelectLanguageField::class,
177  'date' => HTMLDateTimeField::class,
178  'time' => HTMLDateTimeField::class,
179  'datetime' => HTMLDateTimeField::class,
180  'expiry' => HTMLExpiryField::class,
181  // HTMLTextField will output the correct type="" attribute automagically.
182  // There are about four zillion other HTML5 input types, like range, but
183  // we don't use those at the moment, so no point in adding all of them.
184  'email' => HTMLTextField::class,
185  'password' => HTMLTextField::class,
186  'url' => HTMLTextField::class,
187  'title' => HTMLTitleTextField::class,
188  'user' => HTMLUserTextField::class,
189  'tagmultiselect' => HTMLTagMultiselectField::class,
190  'usersmultiselect' => HTMLUsersMultiselectField::class,
191  'titlesmultiselect' => HTMLTitlesMultiselectField::class,
192  'namespacesmultiselect' => HTMLNamespacesMultiselectField::class,
193  ];
194 
195  public $mFieldData;
196 
197  protected $mMessagePrefix;
198 
200  protected $mFlatFields = [];
201  protected $mFieldTree = [];
202  protected $mShowReset = false;
203  protected $mShowSubmit = true;
205  protected $mSubmitFlags = [ 'primary', 'progressive' ];
206  protected $mShowCancel = false;
207  protected $mCancelTarget;
208 
209  protected $mSubmitCallback;
211 
212  protected $mPre = '';
213  protected $mHeader = '';
214  protected $mFooter = '';
215  protected $mSectionHeaders = [];
216  protected $mSectionFooters = [];
217  protected $mPost = '';
218  protected $mId;
219  protected $mName;
220  protected $mTableId = '';
221 
222  protected $mSubmitID;
223  protected $mSubmitName;
224  protected $mSubmitText;
225  protected $mSubmitTooltip;
226 
227  protected $mFormIdentifier;
228  protected $mTitle;
229  protected $mMethod = 'post';
230  protected $mWasSubmitted = false;
231 
237  protected $mAction = false;
238 
244  protected $mCollapsible = false;
245 
251  protected $mCollapsed = false;
252 
258  protected $mAutocomplete = null;
259 
260  protected $mUseMultipart = false;
265  protected $mHiddenFields = [];
270  protected $mButtons = [];
271 
272  protected $mWrapperLegend = false;
273  protected $mWrapperAttributes = [];
274 
279  protected $mTokenSalt = '';
280 
289  protected $mSubSectionBeforeFields = true;
290 
296  protected $displayFormat = 'table';
297 
303  'table',
304  'div',
305  'raw',
306  'inline',
307  ];
308 
314  'vform',
315  'ooui',
316  ];
317 
327  public static function factory( $displayFormat, ...$arguments ) {
328  switch ( $displayFormat ) {
329  case 'vform':
330  return new VFormHTMLForm( ...$arguments );
331  case 'ooui':
332  return new OOUIHTMLForm( ...$arguments );
333  default:
334  $form = new self( ...$arguments );
335  $form->setDisplayFormat( $displayFormat );
336  return $form;
337  }
338  }
339 
351  public function __construct( $descriptor, /*IContextSource*/ $context = null,
352  $messagePrefix = ''
353  ) {
354  if ( $context instanceof IContextSource ) {
355  $this->setContext( $context );
356  $this->mTitle = false; // We don't need them to set a title
357  $this->mMessagePrefix = $messagePrefix;
358  } elseif ( $context === null && $messagePrefix !== '' ) {
359  $this->mMessagePrefix = $messagePrefix;
360  } elseif ( is_string( $context ) && $messagePrefix === '' ) {
361  // B/C since 1.18
362  // it's actually $messagePrefix
363  $this->mMessagePrefix = $context;
364  }
365 
366  // Evil hack for mobile :(
367  if (
368  !$this->getConfig()->get( 'HTMLFormAllowTableFormat' )
369  && $this->displayFormat === 'table'
370  ) {
371  $this->displayFormat = 'div';
372  }
373 
374  $this->addFields( $descriptor );
375  }
376 
386  public function addFields( $descriptor ) {
387  $loadedDescriptor = [];
388 
389  foreach ( $descriptor as $fieldname => $info ) {
390 
391  $section = $info['section'] ?? '';
392 
393  if ( isset( $info['type'] ) && $info['type'] === 'file' ) {
394  $this->mUseMultipart = true;
395  }
396 
397  $field = static::loadInputFromParameters( $fieldname, $info, $this );
398 
399  $setSection =& $loadedDescriptor;
400  if ( $section ) {
401  foreach ( explode( '/', $section ) as $newName ) {
402  if ( !isset( $setSection[$newName] ) ) {
403  $setSection[$newName] = [];
404  }
405 
406  $setSection =& $setSection[$newName];
407  }
408  }
409 
410  $setSection[$fieldname] = $field;
411  $this->mFlatFields[$fieldname] = $field;
412  }
413 
414  $this->mFieldTree = array_merge( $this->mFieldTree, $loadedDescriptor );
415 
416  return $this;
417  }
418 
423  public function hasField( $fieldname ) {
424  return isset( $this->mFlatFields[$fieldname] );
425  }
426 
432  public function getField( $fieldname ) {
433  if ( !$this->hasField( $fieldname ) ) {
434  throw new DomainException( __METHOD__ . ': no field named ' . $fieldname );
435  }
436  return $this->mFlatFields[$fieldname];
437  }
438 
449  public function setDisplayFormat( $format ) {
450  if (
451  in_array( $format, $this->availableSubclassDisplayFormats, true ) ||
452  in_array( $this->displayFormat, $this->availableSubclassDisplayFormats, true )
453  ) {
454  throw new MWException( 'Cannot change display format after creation, ' .
455  'use HTMLForm::factory() instead' );
456  }
457 
458  if ( !in_array( $format, $this->availableDisplayFormats, true ) ) {
459  throw new MWException( 'Display format must be one of ' .
460  print_r(
461  array_merge(
462  $this->availableDisplayFormats,
463  $this->availableSubclassDisplayFormats
464  ),
465  true
466  ) );
467  }
468 
469  // Evil hack for mobile :(
470  if ( !$this->getConfig()->get( 'HTMLFormAllowTableFormat' ) && $format === 'table' ) {
471  $format = 'div';
472  }
473 
474  $this->displayFormat = $format;
475 
476  return $this;
477  }
478 
484  public function getDisplayFormat() {
485  return $this->displayFormat;
486  }
487 
505  public static function getClassFromDescriptor( $fieldname, &$descriptor ) {
506  if ( isset( $descriptor['class'] ) ) {
507  $class = $descriptor['class'];
508  } elseif ( isset( $descriptor['type'] ) ) {
509  $class = static::$typeMappings[$descriptor['type']];
510  $descriptor['class'] = $class;
511  } else {
512  $class = null;
513  }
514 
515  if ( !$class ) {
516  throw new MWException( "Descriptor with no class for $fieldname: "
517  . print_r( $descriptor, true ) );
518  }
519 
520  return $class;
521  }
522 
535  public static function loadInputFromParameters( $fieldname, $descriptor,
536  HTMLForm $parent = null
537  ) {
538  $class = static::getClassFromDescriptor( $fieldname, $descriptor );
539 
540  $descriptor['fieldname'] = $fieldname;
541  if ( $parent ) {
542  $descriptor['parent'] = $parent;
543  }
544 
545  # @todo This will throw a fatal error whenever someone try to use
546  # 'class' to feed a CSS class instead of 'cssclass'. Would be
547  # great to avoid the fatal error and show a nice error.
548  return new $class( $descriptor );
549  }
550 
560  public function prepareForm() {
561  # Check if we have the info we need
562  if ( !$this->mTitle instanceof PageReference && $this->mTitle !== false ) {
563  throw new MWException( 'You must call setTitle() on an HTMLForm' );
564  }
565 
566  # Load data from the request.
567  if (
568  $this->mFormIdentifier === null ||
569  $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier
570  ) {
571  $this->loadData();
572  } else {
573  $this->mFieldData = [];
574  }
575 
576  return $this;
577  }
578 
583  public function tryAuthorizedSubmit() {
584  $result = false;
585 
586  if ( $this->mFormIdentifier === null ) {
587  $identOkay = true;
588  } else {
589  $identOkay = $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier;
590  }
591 
592  $tokenOkay = false;
593  if ( $this->getMethod() !== 'post' ) {
594  $tokenOkay = true; // no session check needed
595  } elseif ( $this->getRequest()->wasPosted() ) {
596  $editToken = $this->getRequest()->getVal( CsrfTokenSet::DEFAULT_FIELD_NAME );
597  if ( $this->getUser()->isRegistered() || $editToken !== null ) {
598  // Session tokens for logged-out users have no security value.
599  // However, if the user gave one, check it in order to give a nice
600  // "session expired" error instead of "permission denied" or such.
601  $tokenOkay = $this->getCsrfTokenSet()->matchToken( $editToken, $this->mTokenSalt );
602  } else {
603  $tokenOkay = true;
604  }
605  }
606 
607  if ( $tokenOkay && $identOkay ) {
608  $this->mWasSubmitted = true;
609  $result = $this->trySubmit();
610  }
611 
612  return $result;
613  }
614 
622  public function show() {
623  $this->prepareForm();
624 
625  $result = $this->tryAuthorizedSubmit();
626  if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
627  return $result;
628  }
629 
630  $this->displayForm( $result );
631 
632  return false;
633  }
634 
640  public function showAlways() {
641  $this->prepareForm();
642 
643  $result = $this->tryAuthorizedSubmit();
644 
645  $this->displayForm( $result );
646 
647  return $result;
648  }
649 
662  public function trySubmit() {
663  $valid = true;
664  $hoistedErrors = Status::newGood();
665  if ( $this->mValidationErrorMessage ) {
666  foreach ( $this->mValidationErrorMessage as $error ) {
667  $hoistedErrors->fatal( ...$error );
668  }
669  } else {
670  $hoistedErrors->fatal( 'htmlform-invalid-input' );
671  }
672 
673  $this->mWasSubmitted = true;
674 
675  # Check for cancelled submission
676  foreach ( $this->mFlatFields as $fieldname => $field ) {
677  if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
678  continue;
679  }
680  if ( $field->cancelSubmit( $this->mFieldData[$fieldname], $this->mFieldData ) ) {
681  $this->mWasSubmitted = false;
682  return false;
683  }
684  }
685 
686  # Check for validation
687  foreach ( $this->mFlatFields as $fieldname => $field ) {
688  if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
689  continue;
690  }
691  if ( $field->isHidden( $this->mFieldData ) ) {
692  continue;
693  }
694  $res = $field->validate( $this->mFieldData[$fieldname], $this->mFieldData );
695  if ( $res !== true ) {
696  $valid = false;
697  if ( $res !== false && !$field->canDisplayErrors() ) {
698  if ( is_string( $res ) ) {
699  $hoistedErrors->fatal( 'rawmessage', $res );
700  } else {
701  $hoistedErrors->fatal( $res );
702  }
703  }
704  }
705  }
706 
707  if ( !$valid ) {
708  return $hoistedErrors;
709  }
710 
711  $callback = $this->mSubmitCallback;
712  if ( !is_callable( $callback ) ) {
713  throw new MWException( 'HTMLForm: no submit callback provided. Use ' .
714  'setSubmitCallback() to set one.' );
715  }
716 
717  $data = $this->filterDataForSubmit( $this->mFieldData );
718 
719  $res = call_user_func( $callback, $data, $this );
720  if ( $res === false ) {
721  $this->mWasSubmitted = false;
722  }
723 
724  return $res;
725  }
726 
738  public function wasSubmitted() {
739  return $this->mWasSubmitted;
740  }
741 
752  public function setSubmitCallback( $cb ) {
753  $this->mSubmitCallback = $cb;
754 
755  return $this;
756  }
757 
766  public function setValidationErrorMessage( $msg ) {
767  $this->mValidationErrorMessage = $msg;
768 
769  return $this;
770  }
771 
779  public function setIntro( $msg ) {
780  $this->setPreText( $msg );
781 
782  return $this;
783  }
784 
793  public function setPreText( $msg ) {
794  $this->mPre = $msg;
795 
796  return $this;
797  }
798 
806  public function addPreText( $msg ) {
807  $this->mPre .= $msg;
808 
809  return $this;
810  }
811 
819  public function getPreText() {
820  return $this->mPre;
821  }
822 
831  public function addHeaderText( $msg, $section = null ) {
832  if ( $section === null ) {
833  $this->mHeader .= $msg;
834  } else {
835  if ( !isset( $this->mSectionHeaders[$section] ) ) {
836  $this->mSectionHeaders[$section] = '';
837  }
838  $this->mSectionHeaders[$section] .= $msg;
839  }
840 
841  return $this;
842  }
843 
853  public function setHeaderText( $msg, $section = null ) {
854  if ( $section === null ) {
855  $this->mHeader = $msg;
856  } else {
857  $this->mSectionHeaders[$section] = $msg;
858  }
859 
860  return $this;
861  }
862 
871  public function getHeaderText( $section = null ) {
872  if ( $section === null ) {
873  return $this->mHeader;
874  } else {
875  return $this->mSectionHeaders[$section] ?? '';
876  }
877  }
878 
887  public function addFooterText( $msg, $section = null ) {
888  if ( $section === null ) {
889  $this->mFooter .= $msg;
890  } else {
891  if ( !isset( $this->mSectionFooters[$section] ) ) {
892  $this->mSectionFooters[$section] = '';
893  }
894  $this->mSectionFooters[$section] .= $msg;
895  }
896 
897  return $this;
898  }
899 
909  public function setFooterText( $msg, $section = null ) {
910  if ( $section === null ) {
911  $this->mFooter = $msg;
912  } else {
913  $this->mSectionFooters[$section] = $msg;
914  }
915 
916  return $this;
917  }
918 
926  public function getFooterText( $section = null ) {
927  if ( $section === null ) {
928  return $this->mFooter;
929  } else {
930  return $this->mSectionFooters[$section] ?? '';
931  }
932  }
933 
941  public function addPostText( $msg ) {
942  $this->mPost .= $msg;
943 
944  return $this;
945  }
946 
954  public function setPostText( $msg ) {
955  $this->mPost = $msg;
956 
957  return $this;
958  }
959 
969  public function addHiddenField( $name, $value, array $attribs = [] ) {
970  $attribs += [ 'name' => $name ];
971  $this->mHiddenFields[] = [ $value, $attribs ];
972 
973  return $this;
974  }
975 
986  public function addHiddenFields( array $fields ) {
987  foreach ( $fields as $name => $value ) {
988  $this->mHiddenFields[] = [ $value, [ 'name' => $name ] ];
989  }
990 
991  return $this;
992  }
993 
1017  public function addButton( $data ) {
1018  if ( !is_array( $data ) ) {
1019  $args = func_get_args();
1020  if ( count( $args ) < 2 || count( $args ) > 4 ) {
1021  throw new InvalidArgumentException(
1022  'Incorrect number of arguments for deprecated calling style'
1023  );
1024  }
1025  $data = [
1026  'name' => $args[0],
1027  'value' => $args[1],
1028  'id' => $args[2] ?? null,
1029  'attribs' => $args[3] ?? null,
1030  ];
1031  } else {
1032  if ( !isset( $data['name'] ) ) {
1033  throw new InvalidArgumentException( 'A name is required' );
1034  }
1035  if ( !isset( $data['value'] ) ) {
1036  throw new InvalidArgumentException( 'A value is required' );
1037  }
1038  }
1039  $this->mButtons[] = $data + [
1040  'id' => null,
1041  'attribs' => null,
1042  'flags' => null,
1043  'framed' => true,
1044  ];
1045 
1046  return $this;
1047  }
1048 
1058  public function setTokenSalt( $salt ) {
1059  $this->mTokenSalt = $salt;
1060 
1061  return $this;
1062  }
1063 
1078  public function displayForm( $submitResult ) {
1079  $this->getOutput()->addHTML( $this->getHTML( $submitResult ) );
1080  }
1081 
1092  public function getHTML( $submitResult ) {
1093  # For good measure (it is the default)
1094  $this->getOutput()->preventClickjacking();
1095  $this->getOutput()->addModules( 'mediawiki.htmlform' );
1096  $this->getOutput()->addModuleStyles( 'mediawiki.htmlform.styles' );
1097 
1098  if ( $this->mCollapsible ) {
1099  // Preload jquery.makeCollapsible for mediawiki.htmlform
1100  $this->getOutput()->addModules( 'jquery.makeCollapsible' );
1101  }
1102 
1103  $html = ''
1104  . $this->getErrorsOrWarnings( $submitResult, 'error' )
1105  . $this->getErrorsOrWarnings( $submitResult, 'warning' )
1106  . $this->getHeaderText()
1107  . $this->getBody()
1108  . $this->getHiddenFields()
1109  . $this->getButtons()
1110  . $this->getFooterText();
1111 
1112  $html = $this->wrapForm( $html );
1113 
1114  return '' . $this->mPre . $html . $this->mPost;
1115  }
1116 
1124  public function setCollapsibleOptions( $collapsedByDefault = false ) {
1125  $this->mCollapsible = true;
1126  $this->mCollapsed = $collapsedByDefault;
1127  return $this;
1128  }
1129 
1135  protected function getFormAttributes() {
1136  # Use multipart/form-data
1137  $encType = $this->mUseMultipart
1138  ? 'multipart/form-data'
1139  : 'application/x-www-form-urlencoded';
1140  # Attributes
1141  $attribs = [
1142  'class' => 'mw-htmlform',
1143  'action' => $this->getAction(),
1144  'method' => $this->getMethod(),
1145  'enctype' => $encType,
1146  ];
1147  if ( $this->mId ) {
1148  $attribs['id'] = $this->mId;
1149  }
1150  if ( is_string( $this->mAutocomplete ) ) {
1151  $attribs['autocomplete'] = $this->mAutocomplete;
1152  }
1153  if ( $this->mName ) {
1154  $attribs['name'] = $this->mName;
1155  }
1156  if ( $this->needsJSForHtml5FormValidation() ) {
1157  $attribs['novalidate'] = true;
1158  }
1159  return $attribs;
1160  }
1161 
1170  public function wrapForm( $html ) {
1171  # Include a <fieldset> wrapper for style, if requested.
1172  if ( $this->mWrapperLegend !== false ) {
1173  $legend = is_string( $this->mWrapperLegend ) ? $this->mWrapperLegend : false;
1174  $html = Xml::fieldset( $legend, $html, $this->mWrapperAttributes );
1175  }
1176 
1177  return Html::rawElement(
1178  'form',
1179  $this->getFormAttributes(),
1180  $html
1181  );
1182  }
1183 
1188  public function getHiddenFields() {
1189  $html = '';
1190  if ( $this->mFormIdentifier !== null ) {
1191  $html .= Html::hidden(
1192  'wpFormIdentifier',
1193  $this->mFormIdentifier
1194  ) . "\n";
1195  }
1196  if ( $this->getMethod() === 'post' ) {
1197  $html .= Html::hidden(
1198  CsrfTokenSet::DEFAULT_FIELD_NAME,
1199  $this->getCsrfTokenSet()->getToken( $this->mTokenSalt )->toString(),
1200  [ 'id' => CsrfTokenSet::DEFAULT_FIELD_NAME ]
1201  ) . "\n";
1202  $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1203  }
1204 
1205  $articlePath = $this->getConfig()->get( 'ArticlePath' );
1206  if ( strpos( $articlePath, '?' ) !== false && $this->getMethod() === 'get' ) {
1207  $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1208  }
1209 
1210  foreach ( $this->mHiddenFields as [ $value, $attribs ] ) {
1211  $html .= Html::hidden( $attribs['name'], $value, $attribs ) . "\n";
1212  }
1213 
1214  return $html;
1215  }
1216 
1222  public function getButtons() {
1223  $buttons = '';
1224  $useMediaWikiUIEverywhere = $this->getConfig()->get( 'UseMediaWikiUIEverywhere' );
1225 
1226  if ( $this->mShowSubmit ) {
1227  $attribs = [];
1228 
1229  if ( isset( $this->mSubmitID ) ) {
1230  $attribs['id'] = $this->mSubmitID;
1231  }
1232 
1233  if ( isset( $this->mSubmitName ) ) {
1234  $attribs['name'] = $this->mSubmitName;
1235  }
1236 
1237  if ( isset( $this->mSubmitTooltip ) ) {
1238  $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
1239  }
1240 
1241  $attribs['class'] = [ 'mw-htmlform-submit' ];
1242 
1243  if ( $useMediaWikiUIEverywhere ) {
1244  foreach ( $this->mSubmitFlags as $flag ) {
1245  $attribs['class'][] = 'mw-ui-' . $flag;
1246  }
1247  $attribs['class'][] = 'mw-ui-button';
1248  }
1249 
1250  $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
1251  }
1252 
1253  if ( $this->mShowReset ) {
1254  $buttons .= Html::element(
1255  'input',
1256  [
1257  'type' => 'reset',
1258  'value' => $this->msg( 'htmlform-reset' )->text(),
1259  'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null,
1260  ]
1261  ) . "\n";
1262  }
1263 
1264  if ( $this->mShowCancel ) {
1265  $target = $this->getCancelTargetURL();
1266  $buttons .= Html::element(
1267  'a',
1268  [
1269  'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null,
1270  'href' => $target,
1271  ],
1272  $this->msg( 'cancel' )->text()
1273  ) . "\n";
1274  }
1275 
1276  foreach ( $this->mButtons as $button ) {
1277  $attrs = [
1278  'type' => 'submit',
1279  'name' => $button['name'],
1280  'value' => $button['value']
1281  ];
1282 
1283  if ( isset( $button['label-message'] ) ) {
1284  $label = $this->getMessage( $button['label-message'] )->parse();
1285  } elseif ( isset( $button['label'] ) ) {
1286  $label = htmlspecialchars( $button['label'] );
1287  } elseif ( isset( $button['label-raw'] ) ) {
1288  $label = $button['label-raw'];
1289  } else {
1290  $label = htmlspecialchars( $button['value'] );
1291  }
1292 
1293  if ( $button['attribs'] ) {
1294  $attrs += $button['attribs'];
1295  }
1296 
1297  if ( isset( $button['id'] ) ) {
1298  $attrs['id'] = $button['id'];
1299  }
1300 
1301  if ( $useMediaWikiUIEverywhere ) {
1302  $attrs['class'] = isset( $attrs['class'] ) ? (array)$attrs['class'] : [];
1303  $attrs['class'][] = 'mw-ui-button';
1304  }
1305 
1306  $buttons .= Html::rawElement( 'button', $attrs, $label ) . "\n";
1307  }
1308 
1309  if ( !$buttons ) {
1310  return '';
1311  }
1312 
1313  return Html::rawElement( 'span',
1314  [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n";
1315  }
1316 
1322  public function getBody() {
1323  return $this->displaySection( $this->mFieldTree, $this->mTableId );
1324  }
1325 
1335  public function getErrorsOrWarnings( $elements, $elementsType ) {
1336  if ( !in_array( $elementsType, [ 'error', 'warning' ], true ) ) {
1337  throw new DomainException( $elementsType . ' is not a valid type.' );
1338  }
1339  $elementstr = false;
1340  if ( $elements instanceof Status ) {
1341  list( $errorStatus, $warningStatus ) = $elements->splitByErrorType();
1342  $status = $elementsType === 'error' ? $errorStatus : $warningStatus;
1343  if ( $status->isGood() ) {
1344  $elementstr = '';
1345  } else {
1346  $elementstr = $status
1347  ->getMessage()
1348  ->setContext( $this )
1349  ->setInterfaceMessageFlag( true )
1350  ->parse();
1351  }
1352  } elseif ( $elementsType === 'error' ) {
1353  if ( is_array( $elements ) ) {
1354  $elementstr = $this->formatErrors( $elements );
1355  } elseif ( $elements && $elements !== true ) {
1356  $elementstr = (string)$elements;
1357  }
1358  }
1359 
1360  return $elementstr
1361  ? Html::rawElement( 'div', [ 'class' => $elementsType . 'box' ], $elementstr )
1362  : '';
1363  }
1364 
1372  public function formatErrors( $errors ) {
1373  $errorstr = '';
1374 
1375  foreach ( $errors as $error ) {
1376  $errorstr .= Html::rawElement(
1377  'li',
1378  [],
1379  $this->getMessage( $error )->parse()
1380  );
1381  }
1382 
1383  $errorstr = Html::rawElement( 'ul', [], $errorstr );
1384 
1385  return $errorstr;
1386  }
1387 
1395  public function setSubmitText( $t ) {
1396  $this->mSubmitText = $t;
1397 
1398  return $this;
1399  }
1400 
1407  public function setSubmitDestructive() {
1408  $this->mSubmitFlags = [ 'destructive', 'primary' ];
1409 
1410  return $this;
1411  }
1412 
1421  public function setSubmitTextMsg( $msg ) {
1422  if ( !$msg instanceof Message ) {
1423  $msg = $this->msg( $msg );
1424  }
1425  $this->setSubmitText( $msg->text() );
1426 
1427  return $this;
1428  }
1429 
1434  public function getSubmitText() {
1435  return $this->mSubmitText ?: $this->msg( 'htmlform-submit' )->text();
1436  }
1437 
1443  public function setSubmitName( $name ) {
1444  $this->mSubmitName = $name;
1445 
1446  return $this;
1447  }
1448 
1454  public function setSubmitTooltip( $name ) {
1455  $this->mSubmitTooltip = $name;
1456 
1457  return $this;
1458  }
1459 
1468  public function setSubmitID( $t ) {
1469  $this->mSubmitID = $t;
1470 
1471  return $this;
1472  }
1473 
1489  public function setFormIdentifier( $ident ) {
1490  $this->mFormIdentifier = $ident;
1491 
1492  return $this;
1493  }
1494 
1505  public function suppressDefaultSubmit( $suppressSubmit = true ) {
1506  $this->mShowSubmit = !$suppressSubmit;
1507 
1508  return $this;
1509  }
1510 
1517  public function showCancel( $show = true ) {
1518  $this->mShowCancel = $show;
1519  return $this;
1520  }
1521 
1528  public function setCancelTarget( $target ) {
1529  if ( $target instanceof PageReference ) {
1530  $target = TitleValue::castPageToLinkTarget( $target );
1531  }
1532 
1533  $this->mCancelTarget = $target;
1534  return $this;
1535  }
1536 
1541  protected function getCancelTargetURL() {
1542  if ( is_string( $this->mCancelTarget ) ) {
1543  return $this->mCancelTarget;
1544  } else {
1545  // TODO: use a service to get the local URL for a LinkTarget, see T282283
1546  $target = Title::castFromLinkTarget( $this->mCancelTarget ) ?: Title::newMainPage();
1547  return $target->getLocalURL();
1548  }
1549  }
1550 
1560  public function setTableId( $id ) {
1561  $this->mTableId = $id;
1562 
1563  return $this;
1564  }
1565 
1571  public function setId( $id ) {
1572  $this->mId = $id;
1573 
1574  return $this;
1575  }
1576 
1581  public function setName( $name ) {
1582  $this->mName = $name;
1583 
1584  return $this;
1585  }
1586 
1598  public function setWrapperLegend( $legend ) {
1599  $this->mWrapperLegend = $legend;
1600 
1601  return $this;
1602  }
1603 
1611  public function setWrapperAttributes( $attributes ) {
1612  $this->mWrapperAttributes = $attributes;
1613 
1614  return $this;
1615  }
1616 
1626  public function setWrapperLegendMsg( $msg ) {
1627  if ( !$msg instanceof Message ) {
1628  $msg = $this->msg( $msg );
1629  }
1630  $this->setWrapperLegend( $msg->text() );
1631 
1632  return $this;
1633  }
1634 
1644  public function setMessagePrefix( $p ) {
1645  $this->mMessagePrefix = $p;
1646 
1647  return $this;
1648  }
1649 
1657  public function setTitle( $t ) {
1658  // TODO: make mTitle a PageReference when we have a better way to get URLs, see T282283.
1659  $this->mTitle = Title::castFromPageReference( $t );
1660 
1661  return $this;
1662  }
1663 
1667  public function getTitle() {
1668  return $this->mTitle ?: $this->getContext()->getTitle();
1669  }
1670 
1678  public function setMethod( $method = 'post' ) {
1679  $this->mMethod = strtolower( $method );
1680 
1681  return $this;
1682  }
1683 
1687  public function getMethod() {
1688  return $this->mMethod;
1689  }
1690 
1701  protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
1702  return Xml::fieldset( $legend, $section, $attributes ) . "\n";
1703  }
1704 
1722  public function displaySection( $fields,
1723  $sectionName = '',
1724  $fieldsetIDPrefix = '',
1725  &$hasUserVisibleFields = false
1726  ) {
1727  if ( $this->mFieldData === null ) {
1728  throw new LogicException( 'HTMLForm::displaySection() called on uninitialized field data. '
1729  . 'You probably called displayForm() without calling prepareForm() first.' );
1730  }
1731 
1732  $displayFormat = $this->getDisplayFormat();
1733 
1734  $html = [];
1735  $subsectionHtml = '';
1736  $hasLabel = false;
1737 
1738  // Conveniently, PHP method names are case-insensitive.
1739  // For grep: this can call getDiv, getRaw, getInline, getVForm, getOOUI
1740  $getFieldHtmlMethod = $displayFormat === 'table' ? 'getTableRow' : ( 'get' . $displayFormat );
1741 
1742  foreach ( $fields as $key => $value ) {
1743  if ( $value instanceof HTMLFormField ) {
1744  $v = array_key_exists( $key, $this->mFieldData )
1745  ? $this->mFieldData[$key]
1746  : $value->getDefault();
1747 
1748  $retval = $value->$getFieldHtmlMethod( $v );
1749 
1750  // check, if the form field should be added to
1751  // the output.
1752  if ( $value->hasVisibleOutput() ) {
1753  $html[] = $retval;
1754 
1755  $labelValue = trim( $value->getLabel() );
1756  if ( $labelValue !== "\u{00A0}" && $labelValue !== '&#160;' && $labelValue !== '' ) {
1757  $hasLabel = true;
1758  }
1759 
1760  $hasUserVisibleFields = true;
1761  }
1762  } elseif ( is_array( $value ) ) {
1763  $subsectionHasVisibleFields = false;
1764  $section =
1765  $this->displaySection( $value,
1766  "mw-htmlform-$key",
1767  "$fieldsetIDPrefix$key-",
1768  $subsectionHasVisibleFields );
1769  $legend = null;
1770 
1771  if ( $subsectionHasVisibleFields === true ) {
1772  // Display the section with various niceties.
1773  $hasUserVisibleFields = true;
1774 
1775  $legend = $this->getLegend( $key );
1776 
1777  $section = $this->getHeaderText( $key ) .
1778  $section .
1779  $this->getFooterText( $key );
1780 
1781  $attributes = [];
1782  if ( $fieldsetIDPrefix ) {
1783  $attributes['id'] = Sanitizer::escapeIdForAttribute( "$fieldsetIDPrefix$key" );
1784  }
1785  $subsectionHtml .= $this->wrapFieldSetSection(
1786  $legend, $section, $attributes, $fields === $this->mFieldTree
1787  );
1788  } else {
1789  // Just return the inputs, nothing fancy.
1790  $subsectionHtml .= $section;
1791  }
1792  }
1793  }
1794 
1795  $html = $this->formatSection( $html, $sectionName, $hasLabel );
1796 
1797  if ( $subsectionHtml ) {
1798  if ( $this->mSubSectionBeforeFields ) {
1799  return $subsectionHtml . "\n" . $html;
1800  } else {
1801  return $html . "\n" . $subsectionHtml;
1802  }
1803  } else {
1804  return $html;
1805  }
1806  }
1807 
1816  protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
1817  if ( !$fieldsHtml ) {
1818  // Do not generate any wrappers for empty sections. Sections may be empty if they only have
1819  // subsections, but no fields. A legend will still be added in wrapFieldSetSection().
1820  return '';
1821  }
1822 
1823  $displayFormat = $this->getDisplayFormat();
1824  $html = implode( '', $fieldsHtml );
1825 
1826  if ( $displayFormat === 'raw' ) {
1827  return $html;
1828  }
1829 
1830  $classes = [];
1831 
1832  if ( !$anyFieldHasLabel ) { // Avoid strange spacing when no labels exist
1833  $classes[] = 'mw-htmlform-nolabel';
1834  }
1835 
1836  $attribs = [ 'class' => $classes ];
1837 
1838  if ( $sectionName ) {
1839  $attribs['id'] = Sanitizer::escapeIdForAttribute( $sectionName );
1840  }
1841 
1842  if ( $displayFormat === 'table' ) {
1843  return Html::rawElement( 'table',
1844  $attribs,
1845  Html::rawElement( 'tbody', [], "\n$html\n" ) ) . "\n";
1846  } elseif ( $displayFormat === 'inline' ) {
1847  return Html::rawElement( 'span', $attribs, "\n$html\n" );
1848  } else {
1849  return Html::rawElement( 'div', $attribs, "\n$html\n" );
1850  }
1851  }
1852 
1856  public function loadData() {
1857  $fieldData = [];
1858 
1859  foreach ( $this->mFlatFields as $fieldname => $field ) {
1860  $request = $this->getRequest();
1861  if ( $field->skipLoadData( $request ) ) {
1862  continue;
1863  } elseif ( !empty( $field->mParams['disabled'] ) ) {
1864  $fieldData[$fieldname] = $field->getDefault();
1865  } else {
1866  $fieldData[$fieldname] = $field->loadDataFromRequest( $request );
1867  }
1868  }
1869 
1870  # Filter data.
1871  foreach ( $fieldData as $name => &$value ) {
1872  $field = $this->mFlatFields[$name];
1873  $value = $field->filter( $value, $this->mFlatFields );
1874  }
1875 
1876  $this->mFieldData = $fieldData;
1877  }
1878 
1886  public function suppressReset( $suppressReset = true ) {
1887  $this->mShowReset = !$suppressReset;
1888 
1889  return $this;
1890  }
1891 
1902  public function filterDataForSubmit( $data ) {
1903  return $data;
1904  }
1905 
1915  public function getLegend( $key ) {
1916  return $this->msg( $this->mMessagePrefix ? "{$this->mMessagePrefix}-$key" : $key )->text();
1917  }
1918 
1929  public function setAction( $action ) {
1930  $this->mAction = $action;
1931 
1932  return $this;
1933  }
1934 
1942  public function getAction() {
1943  // If an action is alredy provided, return it
1944  if ( $this->mAction !== false ) {
1945  return $this->mAction;
1946  }
1947 
1948  $articlePath = $this->getConfig()->get( 'ArticlePath' );
1949  // Check whether we are in GET mode and the ArticlePath contains a "?"
1950  // meaning that getLocalURL() would return something like "index.php?title=...".
1951  // As browser remove the query string before submitting GET forms,
1952  // it means that the title would be lost. In such case use wfScript() instead
1953  // and put title in an hidden field (see getHiddenFields()).
1954  if ( strpos( $articlePath, '?' ) !== false && $this->getMethod() === 'get' ) {
1955  return wfScript();
1956  }
1957 
1958  return $this->getTitle()->getLocalURL();
1959  }
1960 
1971  public function setAutocomplete( $autocomplete ) {
1972  $this->mAutocomplete = $autocomplete;
1973 
1974  return $this;
1975  }
1976 
1983  protected function getMessage( $value ) {
1984  return Message::newFromSpecifier( $value )->setContext( $this );
1985  }
1986 
1996  public function needsJSForHtml5FormValidation() {
1997  foreach ( $this->mFlatFields as $fieldname => $field ) {
1998  if ( $field->needsJSForHtml5FormValidation() ) {
1999  return true;
2000  }
2001  }
2002  return false;
2003  }
2004 }
HTMLForm\getLegend
getLegend( $key)
Get a string to go in the "<legend>" of a section fieldset.
Definition: HTMLForm.php:1915
HTMLForm\$mTokenSalt
string array $mTokenSalt
Salt for the edit token.
Definition: HTMLForm.php:279
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:39
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:72
HTMLForm\setPostText
setPostText( $msg)
Set text at the end of the display.
Definition: HTMLForm.php:954
HTMLForm\setAutocomplete
setAutocomplete( $autocomplete)
Set the value for the autocomplete attribute of the form.
Definition: HTMLForm.php:1971
Message\newFromSpecifier
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition: Message.php:406
HTMLForm\$mSubmitText
$mSubmitText
Definition: HTMLForm.php:224
HTMLForm\prepareForm
prepareForm()
Prepare form for submission.
Definition: HTMLForm.php:560
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:47
HTMLForm\hasField
hasField( $fieldname)
Definition: HTMLForm.php:423
HTMLForm\$mSubSectionBeforeFields
bool $mSubSectionBeforeFields
If true, sections that contain both fields and subsections will render their subsections before their...
Definition: HTMLForm.php:289
HTMLForm\setPreText
setPreText( $msg)
Set the introductory message HTML, overwriting any existing message.
Definition: HTMLForm.php:793
HTMLForm\suppressDefaultSubmit
suppressDefaultSubmit( $suppressSubmit=true)
Stop a default submit button being shown for this form.
Definition: HTMLForm.php:1505
HTMLForm\$mSectionHeaders
$mSectionHeaders
Definition: HTMLForm.php:215
HTMLForm\setSubmitName
setSubmitName( $name)
Definition: HTMLForm.php:1443
HTMLForm\setFooterText
setFooterText( $msg, $section=null)
Set footer text, inside the form.
Definition: HTMLForm.php:909
HTMLForm\$mFieldTree
$mFieldTree
Definition: HTMLForm.php:201
HTMLForm\setIntro
setIntro( $msg)
Set the introductory message, overwriting any existing message.
Definition: HTMLForm.php:779
HTMLForm\tryAuthorizedSubmit
tryAuthorizedSubmit()
Try submitting, with edit token check first.
Definition: HTMLForm.php:583
HTMLForm\setWrapperAttributes
setWrapperAttributes( $attributes)
For internal use only.
Definition: HTMLForm.php:1611
HTMLForm\setSubmitTooltip
setSubmitTooltip( $name)
Definition: HTMLForm.php:1454
HTMLForm\addHeaderText
addHeaderText( $msg, $section=null)
Add HTML to the header, inside the form.
Definition: HTMLForm.php:831
HTMLForm\$mTitle
$mTitle
Definition: HTMLForm.php:228
HTMLForm\setDisplayFormat
setDisplayFormat( $format)
Set format in which to display the form.
Definition: HTMLForm.php:449
HTMLForm\wrapForm
wrapForm( $html)
Wrap the form innards in an actual "<form>" element.
Definition: HTMLForm.php:1170
Sanitizer\escapeIdForAttribute
static escapeIdForAttribute( $id, $mode=self::ID_PRIMARY)
Given a section name or other user-generated or otherwise unsafe string, escapes it to be a valid HTM...
Definition: Sanitizer.php:811
HTMLForm\getHiddenFields
getHiddenFields()
Get the hidden fields that should go inside the form.
Definition: HTMLForm.php:1188
HTMLForm\$mCollapsed
bool $mCollapsed
Whether the form is collapsed by default.
Definition: HTMLForm.php:251
HTMLForm\getDisplayFormat
getDisplayFormat()
Getter for displayFormat.
Definition: HTMLForm.php:484
HTMLForm\$mWasSubmitted
$mWasSubmitted
Definition: HTMLForm.php:230
HTMLForm\$mFieldData
$mFieldData
Definition: HTMLForm.php:195
HTMLForm\setHeaderText
setHeaderText( $msg, $section=null)
Set header text, inside the form.
Definition: HTMLForm.php:853
HTMLForm\formatErrors
formatErrors( $errors)
Format a stack of error messages into a single HTML string.
Definition: HTMLForm.php:1372
HTMLForm\getClassFromDescriptor
static getClassFromDescriptor( $fieldname, &$descriptor)
Get the HTMLFormField subclass for this descriptor.
Definition: HTMLForm.php:505
HTMLForm\showCancel
showCancel( $show=true)
Show a cancel button (or prevent it).
Definition: HTMLForm.php:1517
HTMLForm\addFields
addFields( $descriptor)
Add fields to the form.
Definition: HTMLForm.php:386
HTMLForm\$mWrapperLegend
$mWrapperLegend
Definition: HTMLForm.php:272
HTMLForm\$mUseMultipart
$mUseMultipart
Definition: HTMLForm.php:260
HTMLForm\$mShowSubmit
$mShowSubmit
Definition: HTMLForm.php:203
HTMLForm\$mAutocomplete
string null $mAutocomplete
Form attribute autocomplete.
Definition: HTMLForm.php:258
HTMLForm\$mCancelTarget
$mCancelTarget
Definition: HTMLForm.php:207
HTMLForm\setTokenSalt
setTokenSalt( $salt)
Set the salt for the edit token.
Definition: HTMLForm.php:1058
HTMLForm\$mSubmitTooltip
$mSubmitTooltip
Definition: HTMLForm.php:225
HTMLForm\$displayFormat
string $displayFormat
Format in which to display form.
Definition: HTMLForm.php:296
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:622
HTMLForm\$mSubmitID
$mSubmitID
Definition: HTMLForm.php:222
HTMLForm\setCancelTarget
setCancelTarget( $target)
Sets the target where the user is redirected to after clicking cancel.
Definition: HTMLForm.php:1528
HTMLForm\getBody
getBody()
Get the whole body of the form.
Definition: HTMLForm.php:1322
VFormHTMLForm
Compact stacked vertical format for forms.
Definition: VFormHTMLForm.php:29
ContextSource\getRequest
getRequest()
Definition: ContextSource.php:81
Title\newMainPage
static newMainPage(MessageLocalizer $localizer=null)
Create a new Title for the Main Page.
Definition: Title.php:742
HTMLForm\$mShowReset
$mShowReset
Definition: HTMLForm.php:202
HTMLForm\$mTableId
$mTableId
Definition: HTMLForm.php:220
$res
$res
Definition: testCompression.php:57
HTMLForm\$mSubmitName
$mSubmitName
Definition: HTMLForm.php:223
ContextSource\getUser
getUser()
Definition: ContextSource.php:136
HTMLForm\getAction
getAction()
Get the value for the action attribute of the form.
Definition: HTMLForm.php:1942
Page\PageReference
Interface for objects (potentially) representing a page that can be viewable and linked to on a wiki.
Definition: PageReference.php:49
HTMLForm\setMethod
setMethod( $method='post')
Set the method used to submit the form.
Definition: HTMLForm.php:1678
Linker\tooltipAndAccesskeyAttribs
static tooltipAndAccesskeyAttribs( $name, array $msgParams=[], $options=null)
Returns the attributes for the tooltip and access key.
Definition: Linker.php:2457
HTMLForm\__construct
__construct( $descriptor, $context=null, $messagePrefix='')
Build a new HTMLForm from an array of field attributes.
Definition: HTMLForm.php:351
Status
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: Status.php:44
Xml\fieldset
static fieldset( $legend=false, $content=false, $attribs=[])
Shortcut for creating fieldsets.
Definition: Xml.php:622
HTMLForm\setSubmitText
setSubmitText( $t)
Set the text for the submit button.
Definition: HTMLForm.php:1395
OOUIHTMLForm
Compact stacked vertical format for forms, implemented using OOUI widgets.
Definition: OOUIHTMLForm.php:29
HTMLForm\$mSubmitFlags
string[] $mSubmitFlags
Definition: HTMLForm.php:205
HTMLForm\trySubmit
trySubmit()
Validate all the fields, and call the submission callback function if everything is kosher.
Definition: HTMLForm.php:662
StatusValue\isGood
isGood()
Returns whether the operation completed and didn't have any error or warnings.
Definition: StatusValue.php:122
HTMLForm\setCollapsibleOptions
setCollapsibleOptions( $collapsedByDefault=false)
Enable collapsible mode, and set whether the form is collapsed by default.
Definition: HTMLForm.php:1124
TitleValue\castPageToLinkTarget
static castPageToLinkTarget(?PageReference $page)
Casts a PageReference to a LinkTarget.
Definition: TitleValue.php:136
MWException
MediaWiki exception.
Definition: MWException.php:29
HTMLForm\$mAction
bool string $mAction
Form action URL.
Definition: HTMLForm.php:237
HTMLForm\setFormIdentifier
setFormIdentifier( $ident)
Set an internal identifier for this form.
Definition: HTMLForm.php:1489
HTMLForm\getHeaderText
getHeaderText( $section=null)
Get header text.
Definition: HTMLForm.php:871
HTMLForm\addButton
addButton( $data)
Add a button to the form.
Definition: HTMLForm.php:1017
wfScript
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
Definition: GlobalFunctions.php:2306
HTMLForm\addHiddenField
addHiddenField( $name, $value, array $attribs=[])
Add a hidden field to the output.
Definition: HTMLForm.php:969
ContextSource\getOutput
getOutput()
Definition: ContextSource.php:126
HTMLForm\setSubmitID
setSubmitID( $t)
Set the id for the submit button.
Definition: HTMLForm.php:1468
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:33
HTMLFormField
The parent class to generate form fields.
Definition: HTMLFormField.php:11
$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:738
HTMLForm\$mFormIdentifier
$mFormIdentifier
Definition: HTMLForm.php:227
HTMLForm\formatSection
formatSection(array $fieldsHtml, $sectionName, $anyFieldHasLabel)
Put a form section together from the individual fields' HTML, merging it and wrapping.
Definition: HTMLForm.php:1816
HTMLForm\$mButtons
array[] $mButtons
Definition: HTMLForm.php:270
HTMLForm\setMessagePrefix
setMessagePrefix( $p)
Set the prefix for various default messages.
Definition: HTMLForm.php:1644
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:752
HTMLForm\$mId
$mId
Definition: HTMLForm.php:218
HTMLForm\$mSectionFooters
$mSectionFooters
Definition: HTMLForm.php:216
HTMLForm\loadInputFromParameters
static loadInputFromParameters( $fieldname, $descriptor, HTMLForm $parent=null)
Initialise a new Object for the field.
Definition: HTMLForm.php:535
ContextSource\setContext
setContext(IContextSource $context)
Definition: ContextSource.php:63
HTMLForm\$mPost
$mPost
Definition: HTMLForm.php:217
ContextSource\msg
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:197
HTMLForm\getErrorsOrWarnings
getErrorsOrWarnings( $elements, $elementsType)
Returns a formatted list of errors or warnings from the given elements.
Definition: HTMLForm.php:1335
Html\hidden
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:805
HTMLForm\$mFooter
$mFooter
Definition: HTMLForm.php:214
HTMLForm\getFormAttributes
getFormAttributes()
Get HTML attributes for the <form> tag.
Definition: HTMLForm.php:1135
HTMLForm\$mMethod
$mMethod
Definition: HTMLForm.php:229
MediaWiki\Session\CsrfTokenSet
Definition: CsrfTokenSet.php:31
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:82
HTMLForm\setId
setId( $id)
Definition: HTMLForm.php:1571
HTMLForm\$availableSubclassDisplayFormats
array $availableSubclassDisplayFormats
Available formats in which to display the form.
Definition: HTMLForm.php:313
HTMLForm\$availableDisplayFormats
array $availableDisplayFormats
Available formats in which to display the form.
Definition: HTMLForm.php:302
ContextSource\getCsrfTokenSet
getCsrfTokenSet()
Get a repository to obtain and match CSRF tokens.
Definition: ContextSource.php:219
HTMLForm\getPreText
getPreText()
Get the introductory message HTML.
Definition: HTMLForm.php:819
HTMLForm\$typeMappings
static string[] $typeMappings
A mapping of 'type' inputs onto standard HTMLFormField subclasses.
Definition: HTMLForm.php:148
HTMLForm\setWrapperLegend
setWrapperLegend( $legend)
Prompt the whole form to be wrapped in a "<fieldset>", with this text as its "<legend>" element.
Definition: HTMLForm.php:1598
HTMLForm\displaySection
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
Definition: HTMLForm.php:1722
HTMLForm\$mSubmitCallback
$mSubmitCallback
Definition: HTMLForm.php:209
HTMLForm\loadData
loadData()
Construct the form fields from the Descriptor array.
Definition: HTMLForm.php:1856
HTMLForm\showAlways
showAlways()
Same as self::show with the difference, that the form will be added to the output,...
Definition: HTMLForm.php:640
HTMLForm\$mName
$mName
Definition: HTMLForm.php:219
HTMLForm\setSubmitDestructive
setSubmitDestructive()
Identify that the submit button in the form has a destructive action.
Definition: HTMLForm.php:1407
HTMLForm\setValidationErrorMessage
setValidationErrorMessage( $msg)
Set a message to display on a validation error.
Definition: HTMLForm.php:766
HTMLForm\$mCollapsible
bool $mCollapsible
Whether the form can be collapsed.
Definition: HTMLForm.php:244
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:58
HTMLForm\getCancelTargetURL
getCancelTargetURL()
Definition: HTMLForm.php:1541
HTMLForm\setSubmitTextMsg
setSubmitTextMsg( $msg)
Set the text for the submit button to a message.
Definition: HTMLForm.php:1421
HTMLForm\setName
setName( $name)
Definition: HTMLForm.php:1581
HTMLForm\$mPre
$mPre
Definition: HTMLForm.php:212
HTMLForm\getHTML
getHTML( $submitResult)
Returns the raw HTML generated by the form.
Definition: HTMLForm.php:1092
HTMLForm\getSubmitText
getSubmitText()
Get the text for the submit button, either customised or a default.
Definition: HTMLForm.php:1434
HTMLForm\getMessage
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
Definition: HTMLForm.php:1983
HTMLForm\addHiddenFields
addHiddenFields(array $fields)
Add an array of hidden fields to the output.
Definition: HTMLForm.php:986
HTMLForm\$mShowCancel
$mShowCancel
Definition: HTMLForm.php:206
HTMLForm\$mWrapperAttributes
$mWrapperAttributes
Definition: HTMLForm.php:273
HTMLForm\setWrapperLegendMsg
setWrapperLegendMsg( $msg)
Prompt the whole form to be wrapped in a "<fieldset>", with this message as its "<legend>" element.
Definition: HTMLForm.php:1626
HTMLForm\$mValidationErrorMessage
$mValidationErrorMessage
Definition: HTMLForm.php:210
HTMLForm\setAction
setAction( $action)
Set the value for the action attribute of the form.
Definition: HTMLForm.php:1929
HTMLForm\$mHeader
$mHeader
Definition: HTMLForm.php:213
HTMLForm\setTitle
setTitle( $t)
Set the title for form submission.
Definition: HTMLForm.php:1657
HTMLForm\setTableId
setTableId( $id)
Set the id of the <table> or outermost <div> element.
Definition: HTMLForm.php:1560
HTMLForm\$mMessagePrefix
$mMessagePrefix
Definition: HTMLForm.php:197
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:212
HTMLForm\displayForm
displayForm( $submitResult)
Display the form (sending to the context's OutputPage object), with an appropriate error message or s...
Definition: HTMLForm.php:1078
Message
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition: Message.php:138
HTMLForm\getTitle
getTitle()
Definition: HTMLForm.php:1667
HTMLForm\filterDataForSubmit
filterDataForSubmit( $data)
Overload this if you want to apply special filtration routines to the form as a whole,...
Definition: HTMLForm.php:1902
HTMLForm\getMethod
getMethod()
Definition: HTMLForm.php:1687
Title\castFromPageReference
static castFromPageReference(?PageReference $pageReference)
Return a Title for a given Reference.
Definition: Title.php:377
HTMLForm\addPreText
addPreText( $msg)
Add HTML to introductory message.
Definition: HTMLForm.php:806
$t
$t
Definition: testCompression.php:74
Title\castFromLinkTarget
static castFromLinkTarget( $linkTarget)
Same as newFromLinkTarget, but if passed null, returns null.
Definition: Title.php:351
HTMLForm\getField
getField( $fieldname)
Definition: HTMLForm.php:432
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:234
MediaWiki\Linker\LinkTarget
Definition: LinkTarget.php:26
HTMLForm\$mHiddenFields
array[] $mHiddenFields
Definition: HTMLForm.php:265
HTMLForm\addPostText
addPostText( $msg)
Add text to the end of the display.
Definition: HTMLForm.php:941
HTMLForm\wrapFieldSetSection
wrapFieldSetSection( $legend, $section, $attributes, $isRoot)
Wraps the given $section into an user-visible fieldset.
Definition: HTMLForm.php:1701
HTMLForm\suppressReset
suppressReset( $suppressReset=true)
Stop a reset button being shown for this form.
Definition: HTMLForm.php:1886
HTMLForm\getFooterText
getFooterText( $section=null)
Get footer text.
Definition: HTMLForm.php:926
HTMLForm\$mFlatFields
HTMLFormField[] $mFlatFields
Definition: HTMLForm.php:200
HTMLForm\factory
static factory( $displayFormat,... $arguments)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:327
HTMLForm\getButtons
getButtons()
Get the submit and (potentially) reset buttons.
Definition: HTMLForm.php:1222
HTMLForm\addFooterText
addFooterText( $msg, $section=null)
Add footer text, inside the form.
Definition: HTMLForm.php:887
Xml\submitButton
static submitButton( $value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
Definition: Xml.php:465
HTMLForm\needsJSForHtml5FormValidation
needsJSForHtml5FormValidation()
Whether this form, with its current fields, requires the user agent to have JavaScript enabled for th...
Definition: HTMLForm.php:1996
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition: HTMLForm.php:144