MediaWiki  master
HTMLForm.php
Go to the documentation of this file.
1 <?php
2 
24 use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
25 
133 class HTMLForm extends ContextSource {
134  use ProtectedHookAccessorTrait;
135 
136  // A mapping of 'type' inputs onto standard HTMLFormField subclasses
137  public static $typeMappings = [
138  'api' => HTMLApiField::class,
139  'text' => HTMLTextField::class,
140  'textwithbutton' => HTMLTextFieldWithButton::class,
141  'textarea' => HTMLTextAreaField::class,
142  'select' => HTMLSelectField::class,
143  'combobox' => HTMLComboboxField::class,
144  'radio' => HTMLRadioField::class,
145  'multiselect' => HTMLMultiSelectField::class,
146  'limitselect' => HTMLSelectLimitField::class,
147  'check' => HTMLCheckField::class,
148  'toggle' => HTMLCheckField::class,
149  'int' => HTMLIntField::class,
150  'float' => HTMLFloatField::class,
151  'info' => HTMLInfoField::class,
152  'selectorother' => HTMLSelectOrOtherField::class,
153  'selectandother' => HTMLSelectAndOtherField::class,
154  'namespaceselect' => HTMLSelectNamespace::class,
155  'namespaceselectwithbutton' => HTMLSelectNamespaceWithButton::class,
156  'tagfilter' => HTMLTagFilter::class,
157  'sizefilter' => HTMLSizeFilterField::class,
158  'submit' => HTMLSubmitField::class,
159  'hidden' => HTMLHiddenField::class,
160  'edittools' => HTMLEditTools::class,
161  'checkmatrix' => HTMLCheckMatrix::class,
162  'cloner' => HTMLFormFieldCloner::class,
163  'autocompleteselect' => HTMLAutoCompleteSelectField::class,
164  'language' => HTMLSelectLanguageField::class,
165  'date' => HTMLDateTimeField::class,
166  'time' => HTMLDateTimeField::class,
167  'datetime' => HTMLDateTimeField::class,
168  'expiry' => HTMLExpiryField::class,
169  // HTMLTextField will output the correct type="" attribute automagically.
170  // There are about four zillion other HTML5 input types, like range, but
171  // we don't use those at the moment, so no point in adding all of them.
172  'email' => HTMLTextField::class,
173  'password' => HTMLTextField::class,
174  'url' => HTMLTextField::class,
175  'title' => HTMLTitleTextField::class,
176  'user' => HTMLUserTextField::class,
177  'usersmultiselect' => HTMLUsersMultiselectField::class,
178  'titlesmultiselect' => HTMLTitlesMultiselectField::class,
179  'namespacesmultiselect' => HTMLNamespacesMultiselectField::class,
180  ];
181 
182  public $mFieldData;
183 
184  protected $mMessagePrefix;
185 
187  protected $mFlatFields = [];
188  protected $mFieldTree = [];
189  protected $mShowReset = false;
190  protected $mShowSubmit = true;
192  protected $mSubmitFlags = [ 'primary', 'progressive' ];
193  protected $mShowCancel = false;
194  protected $mCancelTarget;
195 
196  protected $mSubmitCallback;
198 
199  protected $mPre = '';
200  protected $mHeader = '';
201  protected $mFooter = '';
202  protected $mSectionHeaders = [];
203  protected $mSectionFooters = [];
204  protected $mPost = '';
205  protected $mId;
206  protected $mName;
207  protected $mTableId = '';
208 
209  protected $mSubmitID;
210  protected $mSubmitName;
211  protected $mSubmitText;
212  protected $mSubmitTooltip;
213 
214  protected $mFormIdentifier;
215  protected $mTitle;
216  protected $mMethod = 'post';
217  protected $mWasSubmitted = false;
218 
224  protected $mAction = false;
225 
231  protected $mCollapsible = false;
232 
238  protected $mCollapsed = false;
239 
245  protected $mAutocomplete = null;
246 
247  protected $mUseMultipart = false;
252  protected $mHiddenFields = [];
257  protected $mButtons = [];
258 
259  protected $mWrapperLegend = false;
260  protected $mWrapperAttributes = [];
261 
266  protected $mTokenSalt = '';
267 
275  protected $mSubSectionBeforeFields = true;
276 
282  protected $displayFormat = 'table';
283 
289  'table',
290  'div',
291  'raw',
292  'inline',
293  ];
294 
300  'vform',
301  'ooui',
302  ];
303 
311  public static function factory( $displayFormat, ...$arguments ) {
312  switch ( $displayFormat ) {
313  case 'vform':
314  return new VFormHTMLForm( ...$arguments );
315  case 'ooui':
316  return new OOUIHTMLForm( ...$arguments );
317  default:
318  $form = new self( ...$arguments );
319  $form->setDisplayFormat( $displayFormat );
320  return $form;
321  }
322  }
323 
333  public function __construct( $descriptor, /*IContextSource*/ $context = null,
334  $messagePrefix = ''
335  ) {
336  if ( $context instanceof IContextSource ) {
337  $this->setContext( $context );
338  $this->mTitle = false; // We don't need them to set a title
339  $this->mMessagePrefix = $messagePrefix;
340  } elseif ( $context === null && $messagePrefix !== '' ) {
341  $this->mMessagePrefix = $messagePrefix;
342  } elseif ( is_string( $context ) && $messagePrefix === '' ) {
343  // B/C since 1.18
344  // it's actually $messagePrefix
345  $this->mMessagePrefix = $context;
346  }
347 
348  // Evil hack for mobile :(
349  if (
350  !$this->getConfig()->get( 'HTMLFormAllowTableFormat' )
351  && $this->displayFormat === 'table'
352  ) {
353  $this->displayFormat = 'div';
354  }
355 
356  $this->addFields( $descriptor );
357  }
358 
368  public function addFields( $descriptor ) {
369  $loadedDescriptor = [];
370 
371  foreach ( $descriptor as $fieldname => $info ) {
372 
373  $section = $info['section'] ?? '';
374 
375  if ( isset( $info['type'] ) && $info['type'] === 'file' ) {
376  $this->mUseMultipart = true;
377  }
378 
379  $field = static::loadInputFromParameters( $fieldname, $info, $this );
380 
381  $setSection =& $loadedDescriptor;
382  if ( $section ) {
383  foreach ( explode( '/', $section ) as $newName ) {
384  if ( !isset( $setSection[$newName] ) ) {
385  $setSection[$newName] = [];
386  }
387 
388  $setSection =& $setSection[$newName];
389  }
390  }
391 
392  $setSection[$fieldname] = $field;
393  $this->mFlatFields[$fieldname] = $field;
394  }
395 
396  $this->mFieldTree = array_merge( $this->mFieldTree, $loadedDescriptor );
397 
398  return $this;
399  }
400 
405  public function hasField( $fieldname ) {
406  return isset( $this->mFlatFields[$fieldname] );
407  }
408 
414  public function getField( $fieldname ) {
415  if ( !$this->hasField( $fieldname ) ) {
416  throw new DomainException( __METHOD__ . ': no field named ' . $fieldname );
417  }
418  return $this->mFlatFields[$fieldname];
419  }
420 
431  public function setDisplayFormat( $format ) {
432  if (
433  in_array( $format, $this->availableSubclassDisplayFormats, true ) ||
434  in_array( $this->displayFormat, $this->availableSubclassDisplayFormats, true )
435  ) {
436  throw new MWException( 'Cannot change display format after creation, ' .
437  'use HTMLForm::factory() instead' );
438  }
439 
440  if ( !in_array( $format, $this->availableDisplayFormats, true ) ) {
441  throw new MWException( 'Display format must be one of ' .
442  print_r(
443  array_merge(
444  $this->availableDisplayFormats,
445  $this->availableSubclassDisplayFormats
446  ),
447  true
448  ) );
449  }
450 
451  // Evil hack for mobile :(
452  if ( !$this->getConfig()->get( 'HTMLFormAllowTableFormat' ) && $format === 'table' ) {
453  $format = 'div';
454  }
455 
456  $this->displayFormat = $format;
457 
458  return $this;
459  }
460 
466  public function getDisplayFormat() {
467  return $this->displayFormat;
468  }
469 
487  public static function getClassFromDescriptor( $fieldname, &$descriptor ) {
488  if ( isset( $descriptor['class'] ) ) {
489  $class = $descriptor['class'];
490  } elseif ( isset( $descriptor['type'] ) ) {
491  $class = static::$typeMappings[$descriptor['type']];
492  $descriptor['class'] = $class;
493  } else {
494  $class = null;
495  }
496 
497  if ( !$class ) {
498  throw new MWException( "Descriptor with no class for $fieldname: "
499  . print_r( $descriptor, true ) );
500  }
501 
502  return $class;
503  }
504 
516  public static function loadInputFromParameters( $fieldname, $descriptor,
517  HTMLForm $parent = null
518  ) {
519  $class = static::getClassFromDescriptor( $fieldname, $descriptor );
520 
521  $descriptor['fieldname'] = $fieldname;
522  if ( $parent ) {
523  $descriptor['parent'] = $parent;
524  }
525 
526  # @todo This will throw a fatal error whenever someone try to use
527  # 'class' to feed a CSS class instead of 'cssclass'. Would be
528  # great to avoid the fatal error and show a nice error.
529  return new $class( $descriptor );
530  }
531 
541  public function prepareForm() {
542  # Check if we have the info we need
543  if ( !$this->mTitle instanceof Title && $this->mTitle !== false ) {
544  throw new MWException( 'You must call setTitle() on an HTMLForm' );
545  }
546 
547  # Load data from the request.
548  if (
549  $this->mFormIdentifier === null ||
550  $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier
551  ) {
552  $this->loadData();
553  } else {
554  $this->mFieldData = [];
555  }
556 
557  return $this;
558  }
559 
564  public function tryAuthorizedSubmit() {
565  $result = false;
566 
567  if ( $this->mFormIdentifier === null ) {
568  $identOkay = true;
569  } else {
570  $identOkay = $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier;
571  }
572 
573  $tokenOkay = false;
574  if ( $this->getMethod() !== 'post' ) {
575  $tokenOkay = true; // no session check needed
576  } elseif ( $this->getRequest()->wasPosted() ) {
577  $editToken = $this->getRequest()->getVal( 'wpEditToken' );
578  if ( $this->getUser()->isLoggedIn() || $editToken !== null ) {
579  // Session tokens for logged-out users have no security value.
580  // However, if the user gave one, check it in order to give a nice
581  // "session expired" error instead of "permission denied" or such.
582  $tokenOkay = $this->getUser()->matchEditToken( $editToken, $this->mTokenSalt );
583  } else {
584  $tokenOkay = true;
585  }
586  }
587 
588  if ( $tokenOkay && $identOkay ) {
589  $this->mWasSubmitted = true;
590  $result = $this->trySubmit();
591  }
592 
593  return $result;
594  }
595 
602  public function show() {
603  $this->prepareForm();
604 
605  $result = $this->tryAuthorizedSubmit();
606  if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
607  return $result;
608  }
609 
610  $this->displayForm( $result );
611 
612  return false;
613  }
614 
620  public function showAlways() {
621  $this->prepareForm();
622 
623  $result = $this->tryAuthorizedSubmit();
624 
625  $this->displayForm( $result );
626 
627  return $result;
628  }
629 
641  public function trySubmit() {
642  $valid = true;
643  $hoistedErrors = Status::newGood();
644  if ( $this->mValidationErrorMessage ) {
645  foreach ( $this->mValidationErrorMessage as $error ) {
646  $hoistedErrors->fatal( ...$error );
647  }
648  } else {
649  $hoistedErrors->fatal( 'htmlform-invalid-input' );
650  }
651 
652  $this->mWasSubmitted = true;
653 
654  # Check for cancelled submission
655  foreach ( $this->mFlatFields as $fieldname => $field ) {
656  if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
657  continue;
658  }
659  if ( $field->cancelSubmit( $this->mFieldData[$fieldname], $this->mFieldData ) ) {
660  $this->mWasSubmitted = false;
661  return false;
662  }
663  }
664 
665  # Check for validation
666  foreach ( $this->mFlatFields as $fieldname => $field ) {
667  if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
668  continue;
669  }
670  if ( $field->isHidden( $this->mFieldData ) ) {
671  continue;
672  }
673  $res = $field->validate( $this->mFieldData[$fieldname], $this->mFieldData );
674  if ( $res !== true ) {
675  $valid = false;
676  if ( $res !== false && !$field->canDisplayErrors() ) {
677  if ( is_string( $res ) ) {
678  $hoistedErrors->fatal( 'rawmessage', $res );
679  } else {
680  $hoistedErrors->fatal( $res );
681  }
682  }
683  }
684  }
685 
686  if ( !$valid ) {
687  return $hoistedErrors;
688  }
689 
690  $callback = $this->mSubmitCallback;
691  if ( !is_callable( $callback ) ) {
692  throw new MWException( 'HTMLForm: no submit callback provided. Use ' .
693  'setSubmitCallback() to set one.' );
694  }
695 
696  $data = $this->filterDataForSubmit( $this->mFieldData );
697 
698  $res = call_user_func( $callback, $data, $this );
699  if ( $res === false ) {
700  $this->mWasSubmitted = false;
701  }
702 
703  return $res;
704  }
705 
717  public function wasSubmitted() {
718  return $this->mWasSubmitted;
719  }
720 
731  public function setSubmitCallback( $cb ) {
732  $this->mSubmitCallback = $cb;
733 
734  return $this;
735  }
736 
745  public function setValidationErrorMessage( $msg ) {
746  $this->mValidationErrorMessage = $msg;
747 
748  return $this;
749  }
750 
758  public function setIntro( $msg ) {
759  $this->setPreText( $msg );
760 
761  return $this;
762  }
763 
772  public function setPreText( $msg ) {
773  $this->mPre = $msg;
774 
775  return $this;
776  }
777 
785  public function addPreText( $msg ) {
786  $this->mPre .= $msg;
787 
788  return $this;
789  }
790 
798  public function getPreText() {
799  return $this->mPre;
800  }
801 
810  public function addHeaderText( $msg, $section = null ) {
811  if ( $section === null ) {
812  $this->mHeader .= $msg;
813  } else {
814  if ( !isset( $this->mSectionHeaders[$section] ) ) {
815  $this->mSectionHeaders[$section] = '';
816  }
817  $this->mSectionHeaders[$section] .= $msg;
818  }
819 
820  return $this;
821  }
822 
832  public function setHeaderText( $msg, $section = null ) {
833  if ( $section === null ) {
834  $this->mHeader = $msg;
835  } else {
836  $this->mSectionHeaders[$section] = $msg;
837  }
838 
839  return $this;
840  }
841 
849  public function getHeaderText( $section = null ) {
850  if ( $section === null ) {
851  return $this->mHeader;
852  } else {
853  return $this->mSectionHeaders[$section] ?? '';
854  }
855  }
856 
865  public function addFooterText( $msg, $section = null ) {
866  if ( $section === null ) {
867  $this->mFooter .= $msg;
868  } else {
869  if ( !isset( $this->mSectionFooters[$section] ) ) {
870  $this->mSectionFooters[$section] = '';
871  }
872  $this->mSectionFooters[$section] .= $msg;
873  }
874 
875  return $this;
876  }
877 
887  public function setFooterText( $msg, $section = null ) {
888  if ( $section === null ) {
889  $this->mFooter = $msg;
890  } else {
891  $this->mSectionFooters[$section] = $msg;
892  }
893 
894  return $this;
895  }
896 
904  public function getFooterText( $section = null ) {
905  if ( $section === null ) {
906  return $this->mFooter;
907  } else {
908  return $this->mSectionFooters[$section] ?? '';
909  }
910  }
911 
919  public function addPostText( $msg ) {
920  $this->mPost .= $msg;
921 
922  return $this;
923  }
924 
932  public function setPostText( $msg ) {
933  $this->mPost = $msg;
934 
935  return $this;
936  }
937 
947  public function addHiddenField( $name, $value, array $attribs = [] ) {
948  $attribs += [ 'name' => $name ];
949  $this->mHiddenFields[] = [ $value, $attribs ];
950 
951  return $this;
952  }
953 
964  public function addHiddenFields( array $fields ) {
965  foreach ( $fields as $name => $value ) {
966  $this->mHiddenFields[] = [ $value, [ 'name' => $name ] ];
967  }
968 
969  return $this;
970  }
971 
996  public function addButton( $data ) {
997  if ( !is_array( $data ) ) {
998  $args = func_get_args();
999  if ( count( $args ) < 2 || count( $args ) > 4 ) {
1000  throw new InvalidArgumentException(
1001  'Incorrect number of arguments for deprecated calling style'
1002  );
1003  }
1004  $data = [
1005  'name' => $args[0],
1006  'value' => $args[1],
1007  'id' => $args[2] ?? null,
1008  'attribs' => $args[3] ?? null,
1009  ];
1010  } else {
1011  if ( !isset( $data['name'] ) ) {
1012  throw new InvalidArgumentException( 'A name is required' );
1013  }
1014  if ( !isset( $data['value'] ) ) {
1015  throw new InvalidArgumentException( 'A value is required' );
1016  }
1017  }
1018  $this->mButtons[] = $data + [
1019  'id' => null,
1020  'attribs' => null,
1021  'flags' => null,
1022  'framed' => true,
1023  ];
1024 
1025  return $this;
1026  }
1027 
1037  public function setTokenSalt( $salt ) {
1038  $this->mTokenSalt = $salt;
1039 
1040  return $this;
1041  }
1042 
1055  public function displayForm( $submitResult ) {
1056  $this->getOutput()->addHTML( $this->getHTML( $submitResult ) );
1057  }
1058 
1067  public function getHTML( $submitResult ) {
1068  # For good measure (it is the default)
1069  $this->getOutput()->preventClickjacking();
1070  $this->getOutput()->addModules( 'mediawiki.htmlform' );
1071  $this->getOutput()->addModuleStyles( 'mediawiki.htmlform.styles' );
1072 
1073  $html = ''
1074  . $this->getErrorsOrWarnings( $submitResult, 'error' )
1075  . $this->getErrorsOrWarnings( $submitResult, 'warning' )
1076  . $this->getHeaderText()
1077  . $this->getBody()
1078  . $this->getHiddenFields()
1079  . $this->getButtons()
1080  . $this->getFooterText();
1081 
1082  $html = $this->wrapForm( $html );
1083 
1084  return '' . $this->mPre . $html . $this->mPost;
1085  }
1086 
1094  public function setCollapsibleOptions( $collapsedByDefault = false ) {
1095  $this->mCollapsible = true;
1096  $this->mCollapsed = $collapsedByDefault;
1097  return $this;
1098  }
1099 
1104  protected function getFormAttributes() {
1105  # Use multipart/form-data
1106  $encType = $this->mUseMultipart
1107  ? 'multipart/form-data'
1108  : 'application/x-www-form-urlencoded';
1109  # Attributes
1110  $attribs = [
1111  'class' => 'mw-htmlform',
1112  'action' => $this->getAction(),
1113  'method' => $this->getMethod(),
1114  'enctype' => $encType,
1115  ];
1116  if ( $this->mId ) {
1117  $attribs['id'] = $this->mId;
1118  }
1119  if ( is_string( $this->mAutocomplete ) ) {
1120  $attribs['autocomplete'] = $this->mAutocomplete;
1121  }
1122  if ( $this->mName ) {
1123  $attribs['name'] = $this->mName;
1124  }
1125  if ( $this->needsJSForHtml5FormValidation() ) {
1126  $attribs['novalidate'] = true;
1127  }
1128  return $attribs;
1129  }
1130 
1138  public function wrapForm( $html ) {
1139  # Include a <fieldset> wrapper for style, if requested.
1140  if ( $this->mWrapperLegend !== false ) {
1141  $legend = is_string( $this->mWrapperLegend ) ? $this->mWrapperLegend : false;
1142  $html = Xml::fieldset( $legend, $html, $this->mWrapperAttributes );
1143  }
1144 
1145  return Html::rawElement(
1146  'form',
1147  $this->getFormAttributes(),
1148  $html
1149  );
1150  }
1151 
1156  public function getHiddenFields() {
1157  $html = '';
1158  if ( $this->mFormIdentifier !== null ) {
1159  $html .= Html::hidden(
1160  'wpFormIdentifier',
1161  $this->mFormIdentifier
1162  ) . "\n";
1163  }
1164  if ( $this->getMethod() === 'post' ) {
1165  $html .= Html::hidden(
1166  'wpEditToken',
1167  $this->getUser()->getEditToken( $this->mTokenSalt ),
1168  [ 'id' => 'wpEditToken' ]
1169  ) . "\n";
1170  $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1171  }
1172 
1173  $articlePath = $this->getConfig()->get( 'ArticlePath' );
1174  if ( strpos( $articlePath, '?' ) !== false && $this->getMethod() === 'get' ) {
1175  $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1176  }
1177 
1178  foreach ( $this->mHiddenFields as $data ) {
1179  list( $value, $attribs ) = $data;
1180  $html .= Html::hidden( $attribs['name'], $value, $attribs ) . "\n";
1181  }
1182 
1183  return $html;
1184  }
1185 
1190  public function getButtons() {
1191  $buttons = '';
1192  $useMediaWikiUIEverywhere = $this->getConfig()->get( 'UseMediaWikiUIEverywhere' );
1193 
1194  if ( $this->mShowSubmit ) {
1195  $attribs = [];
1196 
1197  if ( isset( $this->mSubmitID ) ) {
1198  $attribs['id'] = $this->mSubmitID;
1199  }
1200 
1201  if ( isset( $this->mSubmitName ) ) {
1202  $attribs['name'] = $this->mSubmitName;
1203  }
1204 
1205  if ( isset( $this->mSubmitTooltip ) ) {
1206  $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
1207  }
1208 
1209  $attribs['class'] = [ 'mw-htmlform-submit' ];
1210 
1211  if ( $useMediaWikiUIEverywhere ) {
1212  foreach ( $this->mSubmitFlags as $flag ) {
1213  $attribs['class'][] = 'mw-ui-' . $flag;
1214  }
1215  $attribs['class'][] = 'mw-ui-button';
1216  }
1217 
1218  $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
1219  }
1220 
1221  if ( $this->mShowReset ) {
1222  $buttons .= Html::element(
1223  'input',
1224  [
1225  'type' => 'reset',
1226  'value' => $this->msg( 'htmlform-reset' )->text(),
1227  'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null,
1228  ]
1229  ) . "\n";
1230  }
1231 
1232  if ( $this->mShowCancel ) {
1233  $target = $this->mCancelTarget ?: Title::newMainPage();
1234  if ( $target instanceof Title ) {
1235  $target = $target->getLocalURL();
1236  }
1237  $buttons .= Html::element(
1238  'a',
1239  [
1240  'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null,
1241  'href' => $target,
1242  ],
1243  $this->msg( 'cancel' )->text()
1244  ) . "\n";
1245  }
1246 
1247  foreach ( $this->mButtons as $button ) {
1248  $attrs = [
1249  'type' => 'submit',
1250  'name' => $button['name'],
1251  'value' => $button['value']
1252  ];
1253 
1254  if ( isset( $button['label-message'] ) ) {
1255  $label = $this->getMessage( $button['label-message'] )->parse();
1256  } elseif ( isset( $button['label'] ) ) {
1257  $label = htmlspecialchars( $button['label'] );
1258  } elseif ( isset( $button['label-raw'] ) ) {
1259  $label = $button['label-raw'];
1260  } else {
1261  $label = htmlspecialchars( $button['value'] );
1262  }
1263 
1264  if ( $button['attribs'] ) {
1265  $attrs += $button['attribs'];
1266  }
1267 
1268  if ( isset( $button['id'] ) ) {
1269  $attrs['id'] = $button['id'];
1270  }
1271 
1272  if ( $useMediaWikiUIEverywhere ) {
1273  $attrs['class'] = isset( $attrs['class'] ) ? (array)$attrs['class'] : [];
1274  $attrs['class'][] = 'mw-ui-button';
1275  }
1276 
1277  $buttons .= Html::rawElement( 'button', $attrs, $label ) . "\n";
1278  }
1279 
1280  if ( !$buttons ) {
1281  return '';
1282  }
1283 
1284  return Html::rawElement( 'span',
1285  [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n";
1286  }
1287 
1292  public function getBody() {
1293  return $this->displaySection( $this->mFieldTree, $this->mTableId );
1294  }
1295 
1304  public function getErrorsOrWarnings( $elements, $elementsType ) {
1305  if ( !in_array( $elementsType, [ 'error', 'warning' ], true ) ) {
1306  throw new DomainException( $elementsType . ' is not a valid type.' );
1307  }
1308  $elementstr = false;
1309  if ( $elements instanceof Status ) {
1310  list( $errorStatus, $warningStatus ) = $elements->splitByErrorType();
1311  $status = $elementsType === 'error' ? $errorStatus : $warningStatus;
1312  if ( $status->isGood() ) {
1313  $elementstr = '';
1314  } else {
1315  $elementstr = $status
1316  ->getMessage()
1317  ->setContext( $this )
1318  ->setInterfaceMessageFlag( true )
1319  ->parse();
1320  }
1321  } elseif ( is_array( $elements ) && $elementsType === 'error' ) {
1322  $elementstr = $this->formatErrors( $elements );
1323  } elseif ( $elementsType === 'error' ) {
1324  $elementstr = $elements;
1325  }
1326 
1327  return $elementstr
1328  ? Html::rawElement( 'div', [ 'class' => $elementsType . 'box' ], $elementstr )
1329  : '';
1330  }
1331 
1339  public function formatErrors( $errors ) {
1340  $errorstr = '';
1341 
1342  foreach ( $errors as $error ) {
1343  $errorstr .= Html::rawElement(
1344  'li',
1345  [],
1346  $this->getMessage( $error )->parse()
1347  );
1348  }
1349 
1350  $errorstr = Html::rawElement( 'ul', [], $errorstr );
1351 
1352  return $errorstr;
1353  }
1354 
1362  public function setSubmitText( $t ) {
1363  $this->mSubmitText = $t;
1364 
1365  return $this;
1366  }
1367 
1374  public function setSubmitDestructive() {
1375  $this->mSubmitFlags = [ 'destructive', 'primary' ];
1376 
1377  return $this;
1378  }
1379 
1388  public function setSubmitTextMsg( $msg ) {
1389  if ( !$msg instanceof Message ) {
1390  $msg = $this->msg( $msg );
1391  }
1392  $this->setSubmitText( $msg->text() );
1393 
1394  return $this;
1395  }
1396 
1401  public function getSubmitText() {
1402  return $this->mSubmitText ?: $this->msg( 'htmlform-submit' )->text();
1403  }
1404 
1410  public function setSubmitName( $name ) {
1411  $this->mSubmitName = $name;
1412 
1413  return $this;
1414  }
1415 
1421  public function setSubmitTooltip( $name ) {
1422  $this->mSubmitTooltip = $name;
1423 
1424  return $this;
1425  }
1426 
1435  public function setSubmitID( $t ) {
1436  $this->mSubmitID = $t;
1437 
1438  return $this;
1439  }
1440 
1456  public function setFormIdentifier( $ident ) {
1457  $this->mFormIdentifier = $ident;
1458 
1459  return $this;
1460  }
1461 
1472  public function suppressDefaultSubmit( $suppressSubmit = true ) {
1473  $this->mShowSubmit = !$suppressSubmit;
1474 
1475  return $this;
1476  }
1477 
1484  public function showCancel( $show = true ) {
1485  $this->mShowCancel = $show;
1486  return $this;
1487  }
1488 
1495  public function setCancelTarget( $target ) {
1496  $this->mCancelTarget = $target;
1497  return $this;
1498  }
1499 
1509  public function setTableId( $id ) {
1510  $this->mTableId = $id;
1511 
1512  return $this;
1513  }
1514 
1520  public function setId( $id ) {
1521  $this->mId = $id;
1522 
1523  return $this;
1524  }
1525 
1530  public function setName( $name ) {
1531  $this->mName = $name;
1532 
1533  return $this;
1534  }
1535 
1547  public function setWrapperLegend( $legend ) {
1548  $this->mWrapperLegend = $legend;
1549 
1550  return $this;
1551  }
1552 
1560  public function setWrapperAttributes( $attributes ) {
1561  $this->mWrapperAttributes = $attributes;
1562 
1563  return $this;
1564  }
1565 
1575  public function setWrapperLegendMsg( $msg ) {
1576  if ( !$msg instanceof Message ) {
1577  $msg = $this->msg( $msg );
1578  }
1579  $this->setWrapperLegend( $msg->text() );
1580 
1581  return $this;
1582  }
1583 
1593  public function setMessagePrefix( $p ) {
1594  $this->mMessagePrefix = $p;
1595 
1596  return $this;
1597  }
1598 
1606  public function setTitle( $t ) {
1607  $this->mTitle = $t;
1608 
1609  return $this;
1610  }
1611 
1616  public function getTitle() {
1617  return $this->mTitle === false
1618  ? $this->getContext()->getTitle()
1619  : $this->mTitle;
1620  }
1621 
1629  public function setMethod( $method = 'post' ) {
1630  $this->mMethod = strtolower( $method );
1631 
1632  return $this;
1633  }
1634 
1638  public function getMethod() {
1639  return $this->mMethod;
1640  }
1641 
1651  protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
1652  return Xml::fieldset( $legend, $section, $attributes ) . "\n";
1653  }
1654 
1671  public function displaySection( $fields,
1672  $sectionName = '',
1673  $fieldsetIDPrefix = '',
1674  &$hasUserVisibleFields = false
1675  ) {
1676  if ( $this->mFieldData === null ) {
1677  throw new LogicException( 'HTMLForm::displaySection() called on uninitialized field data. '
1678  . 'You probably called displayForm() without calling prepareForm() first.' );
1679  }
1680 
1681  $displayFormat = $this->getDisplayFormat();
1682 
1683  $html = [];
1684  $subsectionHtml = '';
1685  $hasLabel = false;
1686 
1687  // Conveniently, PHP method names are case-insensitive.
1688  // For grep: this can call getDiv, getRaw, getInline, getVForm, getOOUI
1689  $getFieldHtmlMethod = $displayFormat === 'table' ? 'getTableRow' : ( 'get' . $displayFormat );
1690 
1691  foreach ( $fields as $key => $value ) {
1692  if ( $value instanceof HTMLFormField ) {
1693  $v = array_key_exists( $key, $this->mFieldData )
1694  ? $this->mFieldData[$key]
1695  : $value->getDefault();
1696 
1697  $retval = $value->$getFieldHtmlMethod( $v );
1698 
1699  // check, if the form field should be added to
1700  // the output.
1701  if ( $value->hasVisibleOutput() ) {
1702  $html[] = $retval;
1703 
1704  $labelValue = trim( $value->getLabel() );
1705  if ( $labelValue !== "\u{00A0}" && $labelValue !== '&#160;' && $labelValue !== '' ) {
1706  $hasLabel = true;
1707  }
1708 
1709  $hasUserVisibleFields = true;
1710  }
1711  } elseif ( is_array( $value ) ) {
1712  $subsectionHasVisibleFields = false;
1713  $section =
1714  $this->displaySection( $value,
1715  "mw-htmlform-$key",
1716  "$fieldsetIDPrefix$key-",
1717  $subsectionHasVisibleFields );
1718  $legend = null;
1719 
1720  if ( $subsectionHasVisibleFields === true ) {
1721  // Display the section with various niceties.
1722  $hasUserVisibleFields = true;
1723 
1724  $legend = $this->getLegend( $key );
1725 
1726  $section = $this->getHeaderText( $key ) .
1727  $section .
1728  $this->getFooterText( $key );
1729 
1730  $attributes = [];
1731  if ( $fieldsetIDPrefix ) {
1732  $attributes['id'] = Sanitizer::escapeIdForAttribute( "$fieldsetIDPrefix$key" );
1733  }
1734  $subsectionHtml .= $this->wrapFieldSetSection(
1735  $legend, $section, $attributes, $fields === $this->mFieldTree
1736  );
1737  } else {
1738  // Just return the inputs, nothing fancy.
1739  $subsectionHtml .= $section;
1740  }
1741  }
1742  }
1743 
1744  $html = $this->formatSection( $html, $sectionName, $hasLabel );
1745 
1746  if ( $subsectionHtml ) {
1747  if ( $this->mSubSectionBeforeFields ) {
1748  return $subsectionHtml . "\n" . $html;
1749  } else {
1750  return $html . "\n" . $subsectionHtml;
1751  }
1752  } else {
1753  return $html;
1754  }
1755  }
1756 
1764  protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
1765  if ( !$fieldsHtml ) {
1766  // Do not generate any wrappers for empty sections. Sections may be empty if they only have
1767  // subsections, but no fields. A legend will still be added in wrapFieldSetSection().
1768  return '';
1769  }
1770 
1771  $displayFormat = $this->getDisplayFormat();
1772  $html = implode( '', $fieldsHtml );
1773 
1774  if ( $displayFormat === 'raw' ) {
1775  return $html;
1776  }
1777 
1778  $classes = [];
1779 
1780  if ( !$anyFieldHasLabel ) { // Avoid strange spacing when no labels exist
1781  $classes[] = 'mw-htmlform-nolabel';
1782  }
1783 
1784  $attribs = [
1785  'class' => implode( ' ', $classes ),
1786  ];
1787 
1788  if ( $sectionName ) {
1789  $attribs['id'] = Sanitizer::escapeIdForAttribute( $sectionName );
1790  }
1791 
1792  if ( $displayFormat === 'table' ) {
1793  return Html::rawElement( 'table',
1794  $attribs,
1795  Html::rawElement( 'tbody', [], "\n$html\n" ) ) . "\n";
1796  } elseif ( $displayFormat === 'inline' ) {
1797  return Html::rawElement( 'span', $attribs, "\n$html\n" );
1798  } else {
1799  return Html::rawElement( 'div', $attribs, "\n$html\n" );
1800  }
1801  }
1802 
1806  public function loadData() {
1807  $fieldData = [];
1808 
1809  foreach ( $this->mFlatFields as $fieldname => $field ) {
1810  $request = $this->getRequest();
1811  if ( $field->skipLoadData( $request ) ) {
1812  continue;
1813  } elseif ( !empty( $field->mParams['disabled'] ) ) {
1814  $fieldData[$fieldname] = $field->getDefault();
1815  } else {
1816  $fieldData[$fieldname] = $field->loadDataFromRequest( $request );
1817  }
1818  }
1819 
1820  # Filter data.
1821  foreach ( $fieldData as $name => &$value ) {
1822  $field = $this->mFlatFields[$name];
1823  $value = $field->filter( $value, $this->mFlatFields );
1824  }
1825 
1826  $this->mFieldData = $fieldData;
1827  }
1828 
1836  public function suppressReset( $suppressReset = true ) {
1837  $this->mShowReset = !$suppressReset;
1838 
1839  return $this;
1840  }
1841 
1851  public function filterDataForSubmit( $data ) {
1852  return $data;
1853  }
1854 
1863  public function getLegend( $key ) {
1864  return $this->msg( $this->mMessagePrefix ? "{$this->mMessagePrefix}-$key" : $key )->text();
1865  }
1866 
1877  public function setAction( $action ) {
1878  $this->mAction = $action;
1879 
1880  return $this;
1881  }
1882 
1890  public function getAction() {
1891  // If an action is alredy provided, return it
1892  if ( $this->mAction !== false ) {
1893  return $this->mAction;
1894  }
1895 
1896  $articlePath = $this->getConfig()->get( 'ArticlePath' );
1897  // Check whether we are in GET mode and the ArticlePath contains a "?"
1898  // meaning that getLocalURL() would return something like "index.php?title=...".
1899  // As browser remove the query string before submitting GET forms,
1900  // it means that the title would be lost. In such case use wfScript() instead
1901  // and put title in an hidden field (see getHiddenFields()).
1902  if ( strpos( $articlePath, '?' ) !== false && $this->getMethod() === 'get' ) {
1903  return wfScript();
1904  }
1905 
1906  return $this->getTitle()->getLocalURL();
1907  }
1908 
1919  public function setAutocomplete( $autocomplete ) {
1920  $this->mAutocomplete = $autocomplete;
1921 
1922  return $this;
1923  }
1924 
1931  protected function getMessage( $value ) {
1932  return Message::newFromSpecifier( $value )->setContext( $this );
1933  }
1934 
1944  public function needsJSForHtml5FormValidation() {
1945  foreach ( $this->mFlatFields as $fieldname => $field ) {
1946  if ( $field->needsJSForHtml5FormValidation() ) {
1947  return true;
1948  }
1949  }
1950  return false;
1951  }
1952 }
HTMLForm\$mSubSectionBeforeFields
$mSubSectionBeforeFields
If true, sections that contain both fields and subsections will render their subsections before their...
Definition: HTMLForm.php:275
HTMLForm\getLegend
getLegend( $key)
Get a string to go in the "<legend>" of a section fieldset.
Definition: HTMLForm.php:1863
HTMLForm\$mTokenSalt
string array $mTokenSalt
Salt for the edit token.
Definition: HTMLForm.php:266
HTMLForm\$typeMappings
static $typeMappings
Definition: HTMLForm.php:137
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:34
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:67
HTMLForm\setPostText
setPostText( $msg)
Set text at the end of the display.
Definition: HTMLForm.php:932
HTMLForm\setAutocomplete
setAutocomplete( $autocomplete)
Set the value for the autocomplete attribute of the form.
Definition: HTMLForm.php:1919
Message\newFromSpecifier
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition: Message.php:436
HTMLForm\$mSubmitText
$mSubmitText
Definition: HTMLForm.php:211
HTMLForm\prepareForm
prepareForm()
Prepare form for submission.
Definition: HTMLForm.php:541
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:42
HTMLForm\hasField
hasField( $fieldname)
Definition: HTMLForm.php:405
HTMLForm\setPreText
setPreText( $msg)
Set the introductory message HTML, overwriting any existing message.
Definition: HTMLForm.php:772
HTMLForm\suppressDefaultSubmit
suppressDefaultSubmit( $suppressSubmit=true)
Stop a default submit button being shown for this form.
Definition: HTMLForm.php:1472
HTMLForm\$mSectionHeaders
$mSectionHeaders
Definition: HTMLForm.php:202
HTMLForm\setSubmitName
setSubmitName( $name)
Definition: HTMLForm.php:1410
HTMLForm\setFooterText
setFooterText( $msg, $section=null)
Set footer text, inside the form.
Definition: HTMLForm.php:887
HTMLForm\$mFieldTree
$mFieldTree
Definition: HTMLForm.php:188
HTMLForm\setIntro
setIntro( $msg)
Set the introductory message, overwriting any existing message.
Definition: HTMLForm.php:758
HTMLForm\tryAuthorizedSubmit
tryAuthorizedSubmit()
Try submitting, with edit token check first.
Definition: HTMLForm.php:564
HTMLForm\setWrapperAttributes
setWrapperAttributes( $attributes)
For internal use only.
Definition: HTMLForm.php:1560
HTMLForm\setSubmitTooltip
setSubmitTooltip( $name)
Definition: HTMLForm.php:1421
HTMLForm\addHeaderText
addHeaderText( $msg, $section=null)
Add HTML to the header, inside the form.
Definition: HTMLForm.php:810
HTMLForm\$mTitle
$mTitle
Definition: HTMLForm.php:215
HTMLForm\setDisplayFormat
setDisplayFormat( $format)
Set format in which to display the form.
Definition: HTMLForm.php:431
HTMLForm\wrapForm
wrapForm( $html)
Wrap the form innards in an actual "<form>" element.
Definition: HTMLForm.php:1138
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:1120
HTMLForm\getHiddenFields
getHiddenFields()
Get the hidden fields that should go inside the form.
Definition: HTMLForm.php:1156
HTMLForm\$mCollapsed
bool $mCollapsed
Whether the form is collapsed by default.
Definition: HTMLForm.php:238
HTMLForm\getDisplayFormat
getDisplayFormat()
Getter for displayFormat.
Definition: HTMLForm.php:466
HTMLForm\$mWasSubmitted
$mWasSubmitted
Definition: HTMLForm.php:217
HTMLForm\$mFieldData
$mFieldData
Definition: HTMLForm.php:182
HTMLForm\setHeaderText
setHeaderText( $msg, $section=null)
Set header text, inside the form.
Definition: HTMLForm.php:832
HTMLForm\formatErrors
formatErrors( $errors)
Format a stack of error messages into a single HTML string.
Definition: HTMLForm.php:1339
HTMLForm\getClassFromDescriptor
static getClassFromDescriptor( $fieldname, &$descriptor)
Get the HTMLFormField subclass for this descriptor.
Definition: HTMLForm.php:487
HTMLForm\showCancel
showCancel( $show=true)
Show a cancel button (or prevent it).
Definition: HTMLForm.php:1484
HTMLForm\addFields
addFields( $descriptor)
Add fields to the form.
Definition: HTMLForm.php:368
HTMLForm\$mWrapperLegend
$mWrapperLegend
Definition: HTMLForm.php:259
HTMLForm\$mUseMultipart
$mUseMultipart
Definition: HTMLForm.php:247
HTMLForm\$mShowSubmit
$mShowSubmit
Definition: HTMLForm.php:190
HTMLForm\$mAutocomplete
string null $mAutocomplete
Form attribute autocomplete.
Definition: HTMLForm.php:245
HTMLForm\$mCancelTarget
$mCancelTarget
Definition: HTMLForm.php:194
HTMLForm\setTokenSalt
setTokenSalt( $salt)
Set the salt for the edit token.
Definition: HTMLForm.php:1037
HTMLForm\$mSubmitTooltip
$mSubmitTooltip
Definition: HTMLForm.php:212
HTMLForm\$displayFormat
string $displayFormat
Format in which to display form.
Definition: HTMLForm.php:282
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:602
HTMLForm\$mSubmitID
$mSubmitID
Definition: HTMLForm.php:209
HTMLForm\setCancelTarget
setCancelTarget( $target)
Sets the target where the user is redirected to after clicking cancel.
Definition: HTMLForm.php:1495
HTMLForm\getBody
getBody()
Get the whole body of the form.
Definition: HTMLForm.php:1292
VFormHTMLForm
Compact stacked vertical format for forms.
Definition: VFormHTMLForm.php:27
ContextSource\getRequest
getRequest()
Definition: ContextSource.php:76
Title\newMainPage
static newMainPage(MessageLocalizer $localizer=null)
Create a new Title for the Main Page.
Definition: Title.php:654
HTMLForm\$mShowReset
$mShowReset
Definition: HTMLForm.php:189
HTMLForm\$mTableId
$mTableId
Definition: HTMLForm.php:207
$res
$res
Definition: testCompression.php:57
HTMLForm\$mSubmitName
$mSubmitName
Definition: HTMLForm.php:210
ContextSource\getUser
getUser()
Stable for overriding.
Definition: ContextSource.php:131
HTMLForm\getAction
getAction()
Get the value for the action attribute of the form.
Definition: HTMLForm.php:1890
HTMLForm\setMethod
setMethod( $method='post')
Set the method used to submit the form.
Definition: HTMLForm.php:1629
Linker\tooltipAndAccesskeyAttribs
static tooltipAndAccesskeyAttribs( $name, array $msgParams=[], $options=null)
Returns the attributes for the tooltip and access key.
Definition: Linker.php:2294
HTMLForm\__construct
__construct( $descriptor, $context=null, $messagePrefix='')
Build a new HTMLForm from an array of field attributes.
Definition: HTMLForm.php:333
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:613
HTMLForm\setSubmitText
setSubmitText( $t)
Set the text for the submit button.
Definition: HTMLForm.php:1362
OOUIHTMLForm
Compact stacked vertical format for forms, implemented using OOUI widgets.
Definition: OOUIHTMLForm.php:27
HTMLForm\$mSubmitFlags
string[] $mSubmitFlags
Definition: HTMLForm.php:192
HTMLForm\trySubmit
trySubmit()
Validate all the fields, and call the submission callback function if everything is kosher.
Definition: HTMLForm.php:641
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:1094
MWException
MediaWiki exception.
Definition: MWException.php:29
HTMLForm\$mAction
bool string $mAction
Form action URL.
Definition: HTMLForm.php:224
HTMLForm\setFormIdentifier
setFormIdentifier( $ident)
Set an internal identifier for this form.
Definition: HTMLForm.php:1456
HTMLForm\getHeaderText
getHeaderText( $section=null)
Get header text.
Definition: HTMLForm.php:849
HTMLForm\addButton
addButton( $data)
Add a button to the form.
Definition: HTMLForm.php:996
wfScript
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
Definition: GlobalFunctions.php:2528
HTMLForm\addHiddenField
addHiddenField( $name, $value, array $attribs=[])
Add a hidden field to the output.
Definition: HTMLForm.php:947
ContextSource\getOutput
getOutput()
Definition: ContextSource.php:121
HTMLForm\setSubmitID
setSubmitID( $t)
Set the id for the submit button.
Definition: HTMLForm.php:1435
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:30
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:717
HTMLForm\$mFormIdentifier
$mFormIdentifier
Definition: HTMLForm.php:214
HTMLForm\formatSection
formatSection(array $fieldsHtml, $sectionName, $anyFieldHasLabel)
Put a form section together from the individual fields' HTML, merging it and wrapping.
Definition: HTMLForm.php:1764
HTMLForm\$mButtons
array[] $mButtons
-var array<array{name:string,value:string,label-message?:string|string[]|MessageSpecifier,...
Definition: HTMLForm.php:257
HTMLForm\setMessagePrefix
setMessagePrefix( $p)
Set the prefix for various default messages.
Definition: HTMLForm.php:1593
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:731
HTMLForm\$mId
$mId
Definition: HTMLForm.php:205
HTMLForm\$mSectionFooters
$mSectionFooters
Definition: HTMLForm.php:203
HTMLForm\loadInputFromParameters
static loadInputFromParameters( $fieldname, $descriptor, HTMLForm $parent=null)
Initialise a new Object for the field.
Definition: HTMLForm.php:516
ContextSource\setContext
setContext(IContextSource $context)
Definition: ContextSource.php:58
HTMLForm\$mPost
$mPost
Definition: HTMLForm.php:204
ContextSource\msg
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:184
HTMLForm\getErrorsOrWarnings
getErrorsOrWarnings( $elements, $elementsType)
Returns a formatted list of errors or warnings from the given elements.
Definition: HTMLForm.php:1304
Html\hidden
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:802
HTMLForm\$mFooter
$mFooter
Definition: HTMLForm.php:201
HTMLForm\getFormAttributes
getFormAttributes()
Get HTML attributes for the <form> tag.
Definition: HTMLForm.php:1104
HTMLForm\$mMethod
$mMethod
Definition: HTMLForm.php:216
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:82
HTMLForm\setId
setId( $id)
Definition: HTMLForm.php:1520
HTMLForm\$availableSubclassDisplayFormats
array $availableSubclassDisplayFormats
Available formats in which to display the form.
Definition: HTMLForm.php:299
HTMLForm\$availableDisplayFormats
array $availableDisplayFormats
Available formats in which to display the form.
Definition: HTMLForm.php:288
HTMLForm\getPreText
getPreText()
Get the introductory message HTML.
Definition: HTMLForm.php:798
HTMLForm\setWrapperLegend
setWrapperLegend( $legend)
Prompt the whole form to be wrapped in a "<fieldset>", with this text as its "<legend>" element.
Definition: HTMLForm.php:1547
HTMLForm\displaySection
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
Definition: HTMLForm.php:1671
HTMLForm\$mSubmitCallback
$mSubmitCallback
Definition: HTMLForm.php:196
HTMLForm\loadData
loadData()
Construct the form fields from the Descriptor array.
Definition: HTMLForm.php:1806
HTMLForm\showAlways
showAlways()
Same as self::show with the difference, that the form will be added to the output,...
Definition: HTMLForm.php:620
HTMLForm\$mName
$mName
Definition: HTMLForm.php:206
HTMLForm\setSubmitDestructive
setSubmitDestructive()
Identify that the submit button in the form has a destructive action.
Definition: HTMLForm.php:1374
HTMLForm\setValidationErrorMessage
setValidationErrorMessage( $msg)
Set a message to display on a validation error.
Definition: HTMLForm.php:745
HTMLForm\$mCollapsible
bool $mCollapsible
Whether the form can be collapsed.
Definition: HTMLForm.php:231
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:55
HTMLForm\setSubmitTextMsg
setSubmitTextMsg( $msg)
Set the text for the submit button to a message.
Definition: HTMLForm.php:1388
Title
Represents a title within MediaWiki.
Definition: Title.php:42
HTMLForm\setName
setName( $name)
Definition: HTMLForm.php:1530
HTMLForm\$mPre
$mPre
Definition: HTMLForm.php:199
HTMLForm\getHTML
getHTML( $submitResult)
Returns the raw HTML generated by the form.
Definition: HTMLForm.php:1067
HTMLForm\getSubmitText
getSubmitText()
Get the text for the submit button, either customised or a default.
Definition: HTMLForm.php:1401
HTMLForm\getMessage
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
Definition: HTMLForm.php:1931
HTMLForm\addHiddenFields
addHiddenFields(array $fields)
Add an array of hidden fields to the output.
Definition: HTMLForm.php:964
HTMLForm\$mShowCancel
$mShowCancel
Definition: HTMLForm.php:193
HTMLForm\$mWrapperAttributes
$mWrapperAttributes
Definition: HTMLForm.php:260
HTMLForm\setWrapperLegendMsg
setWrapperLegendMsg( $msg)
Prompt the whole form to be wrapped in a "<fieldset>", with this message as its "<legend>" element.
Definition: HTMLForm.php:1575
HTMLForm\$mValidationErrorMessage
$mValidationErrorMessage
Definition: HTMLForm.php:197
HTMLForm\setAction
setAction( $action)
Set the value for the action attribute of the form.
Definition: HTMLForm.php:1877
HTMLForm\$mHeader
$mHeader
Definition: HTMLForm.php:200
HTMLForm\setTitle
setTitle( $t)
Set the title for form submission.
Definition: HTMLForm.php:1606
HTMLForm\setTableId
setTableId( $id)
Set the id of the <table> or outermost <div> element.
Definition: HTMLForm.php:1509
HTMLForm\$mMessagePrefix
$mMessagePrefix
Definition: HTMLForm.php:184
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
HTMLForm\displayForm
displayForm( $submitResult)
Display the form (sending to the context's OutputPage object), with an appropriate error message or s...
Definition: HTMLForm.php:1055
Message
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition: Message.php:161
HTMLForm\getTitle
getTitle()
Get the title.
Definition: HTMLForm.php:1616
HTMLForm\filterDataForSubmit
filterDataForSubmit( $data)
Overload this if you want to apply special filtration routines to the form as a whole,...
Definition: HTMLForm.php:1851
HTMLForm\getMethod
getMethod()
Definition: HTMLForm.php:1638
HTMLForm\addPreText
addPreText( $msg)
Add HTML to introductory message.
Definition: HTMLForm.php:785
$t
$t
Definition: testCompression.php:74
HTMLForm\getField
getField( $fieldname)
Definition: HTMLForm.php:414
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
HTMLForm\$mHiddenFields
array[] $mHiddenFields
-var array<int,array{0:string,1:array}>
Definition: HTMLForm.php:252
HTMLForm\addPostText
addPostText( $msg)
Add text to the end of the display.
Definition: HTMLForm.php:919
HTMLForm\wrapFieldSetSection
wrapFieldSetSection( $legend, $section, $attributes, $isRoot)
Wraps the given $section into an user-visible fieldset.
Definition: HTMLForm.php:1651
HTMLForm\suppressReset
suppressReset( $suppressReset=true)
Stop a reset button being shown for this form.
Definition: HTMLForm.php:1836
HTMLForm\getFooterText
getFooterText( $section=null)
Get footer text.
Definition: HTMLForm.php:904
HTMLForm\$mFlatFields
HTMLFormField[] $mFlatFields
Definition: HTMLForm.php:187
HTMLForm\factory
static factory( $displayFormat,... $arguments)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:311
HTMLForm\getButtons
getButtons()
Get the submit and (potentially) reset buttons.
Definition: HTMLForm.php:1190
HTMLForm\addFooterText
addFooterText( $msg, $section=null)
Add footer text, inside the form.
Definition: HTMLForm.php:865
Xml\submitButton
static submitButton( $value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
Definition: Xml.php:463
HTMLForm\needsJSForHtml5FormValidation
needsJSForHtml5FormValidation()
Whether this form, with its current fields, requires the user agent to have JavaScript enabled for th...
Definition: HTMLForm.php:1944
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition: HTMLForm.php:133