MediaWiki  master
HTMLForm.php
Go to the documentation of this file.
1 <?php
2 
24 use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
25 
135 class HTMLForm extends ContextSource {
136  use ProtectedHookAccessorTrait;
137 
138  // A mapping of 'type' inputs onto standard HTMLFormField subclasses
139  public static $typeMappings = [
140  'api' => HTMLApiField::class,
141  'text' => HTMLTextField::class,
142  'textwithbutton' => HTMLTextFieldWithButton::class,
143  'textarea' => HTMLTextAreaField::class,
144  'select' => HTMLSelectField::class,
145  'combobox' => HTMLComboboxField::class,
146  'radio' => HTMLRadioField::class,
147  'multiselect' => HTMLMultiSelectField::class,
148  'limitselect' => HTMLSelectLimitField::class,
149  'check' => HTMLCheckField::class,
150  'toggle' => HTMLCheckField::class,
151  'int' => HTMLIntField::class,
152  'float' => HTMLFloatField::class,
153  'info' => HTMLInfoField::class,
154  'selectorother' => HTMLSelectOrOtherField::class,
155  'selectandother' => HTMLSelectAndOtherField::class,
156  'namespaceselect' => HTMLSelectNamespace::class,
157  'namespaceselectwithbutton' => HTMLSelectNamespaceWithButton::class,
158  'tagfilter' => HTMLTagFilter::class,
159  'sizefilter' => HTMLSizeFilterField::class,
160  'submit' => HTMLSubmitField::class,
161  'hidden' => HTMLHiddenField::class,
162  'edittools' => HTMLEditTools::class,
163  'checkmatrix' => HTMLCheckMatrix::class,
164  'cloner' => HTMLFormFieldCloner::class,
165  'autocompleteselect' => HTMLAutoCompleteSelectField::class,
166  'language' => HTMLSelectLanguageField::class,
167  'date' => HTMLDateTimeField::class,
168  'time' => HTMLDateTimeField::class,
169  'datetime' => HTMLDateTimeField::class,
170  'expiry' => HTMLExpiryField::class,
171  // HTMLTextField will output the correct type="" attribute automagically.
172  // There are about four zillion other HTML5 input types, like range, but
173  // we don't use those at the moment, so no point in adding all of them.
174  'email' => HTMLTextField::class,
175  'password' => HTMLTextField::class,
176  'url' => HTMLTextField::class,
177  'title' => HTMLTitleTextField::class,
178  'user' => HTMLUserTextField::class,
179  'usersmultiselect' => HTMLUsersMultiselectField::class,
180  'titlesmultiselect' => HTMLTitlesMultiselectField::class,
181  'namespacesmultiselect' => HTMLNamespacesMultiselectField::class,
182  ];
183 
184  public $mFieldData;
185 
186  protected $mMessagePrefix;
187 
189  protected $mFlatFields = [];
190  protected $mFieldTree = [];
191  protected $mShowReset = false;
192  protected $mShowSubmit = true;
194  protected $mSubmitFlags = [ 'primary', 'progressive' ];
195  protected $mShowCancel = false;
196  protected $mCancelTarget;
197 
198  protected $mSubmitCallback;
200 
201  protected $mPre = '';
202  protected $mHeader = '';
203  protected $mFooter = '';
204  protected $mSectionHeaders = [];
205  protected $mSectionFooters = [];
206  protected $mPost = '';
207  protected $mId;
208  protected $mName;
209  protected $mTableId = '';
210 
211  protected $mSubmitID;
212  protected $mSubmitName;
213  protected $mSubmitText;
214  protected $mSubmitTooltip;
215 
216  protected $mFormIdentifier;
217  protected $mTitle;
218  protected $mMethod = 'post';
219  protected $mWasSubmitted = false;
220 
226  protected $mAction = false;
227 
233  protected $mCollapsible = false;
234 
240  protected $mCollapsed = false;
241 
247  protected $mAutocomplete = null;
248 
249  protected $mUseMultipart = false;
254  protected $mHiddenFields = [];
259  protected $mButtons = [];
260 
261  protected $mWrapperLegend = false;
262  protected $mWrapperAttributes = [];
263 
268  protected $mTokenSalt = '';
269 
277  protected $mSubSectionBeforeFields = true;
278 
284  protected $displayFormat = 'table';
285 
291  'table',
292  'div',
293  'raw',
294  'inline',
295  ];
296 
302  'vform',
303  'ooui',
304  ];
305 
315  public static function factory( $displayFormat, ...$arguments ) {
316  switch ( $displayFormat ) {
317  case 'vform':
318  return new VFormHTMLForm( ...$arguments );
319  case 'ooui':
320  return new OOUIHTMLForm( ...$arguments );
321  default:
322  $form = new self( ...$arguments );
323  $form->setDisplayFormat( $displayFormat );
324  return $form;
325  }
326  }
327 
339  public function __construct( $descriptor, /*IContextSource*/ $context = null,
340  $messagePrefix = ''
341  ) {
342  if ( $context instanceof IContextSource ) {
343  $this->setContext( $context );
344  $this->mTitle = false; // We don't need them to set a title
345  $this->mMessagePrefix = $messagePrefix;
346  } elseif ( $context === null && $messagePrefix !== '' ) {
347  $this->mMessagePrefix = $messagePrefix;
348  } elseif ( is_string( $context ) && $messagePrefix === '' ) {
349  // B/C since 1.18
350  // it's actually $messagePrefix
351  $this->mMessagePrefix = $context;
352  }
353 
354  // Evil hack for mobile :(
355  if (
356  !$this->getConfig()->get( 'HTMLFormAllowTableFormat' )
357  && $this->displayFormat === 'table'
358  ) {
359  $this->displayFormat = 'div';
360  }
361 
362  $this->addFields( $descriptor );
363  }
364 
374  public function addFields( $descriptor ) {
375  $loadedDescriptor = [];
376 
377  foreach ( $descriptor as $fieldname => $info ) {
378 
379  $section = $info['section'] ?? '';
380 
381  if ( isset( $info['type'] ) && $info['type'] === 'file' ) {
382  $this->mUseMultipart = true;
383  }
384 
385  $field = static::loadInputFromParameters( $fieldname, $info, $this );
386 
387  $setSection =& $loadedDescriptor;
388  if ( $section ) {
389  foreach ( explode( '/', $section ) as $newName ) {
390  if ( !isset( $setSection[$newName] ) ) {
391  $setSection[$newName] = [];
392  }
393 
394  $setSection =& $setSection[$newName];
395  }
396  }
397 
398  $setSection[$fieldname] = $field;
399  $this->mFlatFields[$fieldname] = $field;
400  }
401 
402  $this->mFieldTree = array_merge( $this->mFieldTree, $loadedDescriptor );
403 
404  return $this;
405  }
406 
411  public function hasField( $fieldname ) {
412  return isset( $this->mFlatFields[$fieldname] );
413  }
414 
420  public function getField( $fieldname ) {
421  if ( !$this->hasField( $fieldname ) ) {
422  throw new DomainException( __METHOD__ . ': no field named ' . $fieldname );
423  }
424  return $this->mFlatFields[$fieldname];
425  }
426 
437  public function setDisplayFormat( $format ) {
438  if (
439  in_array( $format, $this->availableSubclassDisplayFormats, true ) ||
440  in_array( $this->displayFormat, $this->availableSubclassDisplayFormats, true )
441  ) {
442  throw new MWException( 'Cannot change display format after creation, ' .
443  'use HTMLForm::factory() instead' );
444  }
445 
446  if ( !in_array( $format, $this->availableDisplayFormats, true ) ) {
447  throw new MWException( 'Display format must be one of ' .
448  print_r(
449  array_merge(
450  $this->availableDisplayFormats,
451  $this->availableSubclassDisplayFormats
452  ),
453  true
454  ) );
455  }
456 
457  // Evil hack for mobile :(
458  if ( !$this->getConfig()->get( 'HTMLFormAllowTableFormat' ) && $format === 'table' ) {
459  $format = 'div';
460  }
461 
462  $this->displayFormat = $format;
463 
464  return $this;
465  }
466 
472  public function getDisplayFormat() {
473  return $this->displayFormat;
474  }
475 
493  public static function getClassFromDescriptor( $fieldname, &$descriptor ) {
494  if ( isset( $descriptor['class'] ) ) {
495  $class = $descriptor['class'];
496  } elseif ( isset( $descriptor['type'] ) ) {
497  $class = static::$typeMappings[$descriptor['type']];
498  $descriptor['class'] = $class;
499  } else {
500  $class = null;
501  }
502 
503  if ( !$class ) {
504  throw new MWException( "Descriptor with no class for $fieldname: "
505  . print_r( $descriptor, true ) );
506  }
507 
508  return $class;
509  }
510 
523  public static function loadInputFromParameters( $fieldname, $descriptor,
524  HTMLForm $parent = null
525  ) {
526  $class = static::getClassFromDescriptor( $fieldname, $descriptor );
527 
528  $descriptor['fieldname'] = $fieldname;
529  if ( $parent ) {
530  $descriptor['parent'] = $parent;
531  }
532 
533  # @todo This will throw a fatal error whenever someone try to use
534  # 'class' to feed a CSS class instead of 'cssclass'. Would be
535  # great to avoid the fatal error and show a nice error.
536  return new $class( $descriptor );
537  }
538 
548  public function prepareForm() {
549  # Check if we have the info we need
550  if ( !$this->mTitle instanceof Title && $this->mTitle !== false ) {
551  throw new MWException( 'You must call setTitle() on an HTMLForm' );
552  }
553 
554  # Load data from the request.
555  if (
556  $this->mFormIdentifier === null ||
557  $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier
558  ) {
559  $this->loadData();
560  } else {
561  $this->mFieldData = [];
562  }
563 
564  return $this;
565  }
566 
571  public function tryAuthorizedSubmit() {
572  $result = false;
573 
574  if ( $this->mFormIdentifier === null ) {
575  $identOkay = true;
576  } else {
577  $identOkay = $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier;
578  }
579 
580  $tokenOkay = false;
581  if ( $this->getMethod() !== 'post' ) {
582  $tokenOkay = true; // no session check needed
583  } elseif ( $this->getRequest()->wasPosted() ) {
584  $editToken = $this->getRequest()->getVal( 'wpEditToken' );
585  if ( $this->getUser()->isLoggedIn() || $editToken !== null ) {
586  // Session tokens for logged-out users have no security value.
587  // However, if the user gave one, check it in order to give a nice
588  // "session expired" error instead of "permission denied" or such.
589  $tokenOkay = $this->getUser()->matchEditToken( $editToken, $this->mTokenSalt );
590  } else {
591  $tokenOkay = true;
592  }
593  }
594 
595  if ( $tokenOkay && $identOkay ) {
596  $this->mWasSubmitted = true;
597  $result = $this->trySubmit();
598  }
599 
600  return $result;
601  }
602 
610  public function show() {
611  $this->prepareForm();
612 
613  $result = $this->tryAuthorizedSubmit();
614  if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
615  return $result;
616  }
617 
618  $this->displayForm( $result );
619 
620  return false;
621  }
622 
628  public function showAlways() {
629  $this->prepareForm();
630 
631  $result = $this->tryAuthorizedSubmit();
632 
633  $this->displayForm( $result );
634 
635  return $result;
636  }
637 
650  public function trySubmit() {
651  $valid = true;
652  $hoistedErrors = Status::newGood();
653  if ( $this->mValidationErrorMessage ) {
654  foreach ( $this->mValidationErrorMessage as $error ) {
655  $hoistedErrors->fatal( ...$error );
656  }
657  } else {
658  $hoistedErrors->fatal( 'htmlform-invalid-input' );
659  }
660 
661  $this->mWasSubmitted = true;
662 
663  # Check for cancelled submission
664  foreach ( $this->mFlatFields as $fieldname => $field ) {
665  if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
666  continue;
667  }
668  if ( $field->cancelSubmit( $this->mFieldData[$fieldname], $this->mFieldData ) ) {
669  $this->mWasSubmitted = false;
670  return false;
671  }
672  }
673 
674  # Check for validation
675  foreach ( $this->mFlatFields as $fieldname => $field ) {
676  if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
677  continue;
678  }
679  if ( $field->isHidden( $this->mFieldData ) ) {
680  continue;
681  }
682  $res = $field->validate( $this->mFieldData[$fieldname], $this->mFieldData );
683  if ( $res !== true ) {
684  $valid = false;
685  if ( $res !== false && !$field->canDisplayErrors() ) {
686  if ( is_string( $res ) ) {
687  $hoistedErrors->fatal( 'rawmessage', $res );
688  } else {
689  $hoistedErrors->fatal( $res );
690  }
691  }
692  }
693  }
694 
695  if ( !$valid ) {
696  return $hoistedErrors;
697  }
698 
699  $callback = $this->mSubmitCallback;
700  if ( !is_callable( $callback ) ) {
701  throw new MWException( 'HTMLForm: no submit callback provided. Use ' .
702  'setSubmitCallback() to set one.' );
703  }
704 
705  $data = $this->filterDataForSubmit( $this->mFieldData );
706 
707  $res = call_user_func( $callback, $data, $this );
708  if ( $res === false ) {
709  $this->mWasSubmitted = false;
710  }
711 
712  return $res;
713  }
714 
726  public function wasSubmitted() {
727  return $this->mWasSubmitted;
728  }
729 
740  public function setSubmitCallback( $cb ) {
741  $this->mSubmitCallback = $cb;
742 
743  return $this;
744  }
745 
754  public function setValidationErrorMessage( $msg ) {
755  $this->mValidationErrorMessage = $msg;
756 
757  return $this;
758  }
759 
767  public function setIntro( $msg ) {
768  $this->setPreText( $msg );
769 
770  return $this;
771  }
772 
781  public function setPreText( $msg ) {
782  $this->mPre = $msg;
783 
784  return $this;
785  }
786 
794  public function addPreText( $msg ) {
795  $this->mPre .= $msg;
796 
797  return $this;
798  }
799 
807  public function getPreText() {
808  return $this->mPre;
809  }
810 
819  public function addHeaderText( $msg, $section = null ) {
820  if ( $section === null ) {
821  $this->mHeader .= $msg;
822  } else {
823  if ( !isset( $this->mSectionHeaders[$section] ) ) {
824  $this->mSectionHeaders[$section] = '';
825  }
826  $this->mSectionHeaders[$section] .= $msg;
827  }
828 
829  return $this;
830  }
831 
841  public function setHeaderText( $msg, $section = null ) {
842  if ( $section === null ) {
843  $this->mHeader = $msg;
844  } else {
845  $this->mSectionHeaders[$section] = $msg;
846  }
847 
848  return $this;
849  }
850 
859  public function getHeaderText( $section = null ) {
860  if ( $section === null ) {
861  return $this->mHeader;
862  } else {
863  return $this->mSectionHeaders[$section] ?? '';
864  }
865  }
866 
875  public function addFooterText( $msg, $section = null ) {
876  if ( $section === null ) {
877  $this->mFooter .= $msg;
878  } else {
879  if ( !isset( $this->mSectionFooters[$section] ) ) {
880  $this->mSectionFooters[$section] = '';
881  }
882  $this->mSectionFooters[$section] .= $msg;
883  }
884 
885  return $this;
886  }
887 
897  public function setFooterText( $msg, $section = null ) {
898  if ( $section === null ) {
899  $this->mFooter = $msg;
900  } else {
901  $this->mSectionFooters[$section] = $msg;
902  }
903 
904  return $this;
905  }
906 
914  public function getFooterText( $section = null ) {
915  if ( $section === null ) {
916  return $this->mFooter;
917  } else {
918  return $this->mSectionFooters[$section] ?? '';
919  }
920  }
921 
929  public function addPostText( $msg ) {
930  $this->mPost .= $msg;
931 
932  return $this;
933  }
934 
942  public function setPostText( $msg ) {
943  $this->mPost = $msg;
944 
945  return $this;
946  }
947 
957  public function addHiddenField( $name, $value, array $attribs = [] ) {
958  $attribs += [ 'name' => $name ];
959  $this->mHiddenFields[] = [ $value, $attribs ];
960 
961  return $this;
962  }
963 
974  public function addHiddenFields( array $fields ) {
975  foreach ( $fields as $name => $value ) {
976  $this->mHiddenFields[] = [ $value, [ 'name' => $name ] ];
977  }
978 
979  return $this;
980  }
981 
1006  public function addButton( $data ) {
1007  if ( !is_array( $data ) ) {
1008  $args = func_get_args();
1009  if ( count( $args ) < 2 || count( $args ) > 4 ) {
1010  throw new InvalidArgumentException(
1011  'Incorrect number of arguments for deprecated calling style'
1012  );
1013  }
1014  $data = [
1015  'name' => $args[0],
1016  'value' => $args[1],
1017  'id' => $args[2] ?? null,
1018  'attribs' => $args[3] ?? null,
1019  ];
1020  } else {
1021  if ( !isset( $data['name'] ) ) {
1022  throw new InvalidArgumentException( 'A name is required' );
1023  }
1024  if ( !isset( $data['value'] ) ) {
1025  throw new InvalidArgumentException( 'A value is required' );
1026  }
1027  }
1028  $this->mButtons[] = $data + [
1029  'id' => null,
1030  'attribs' => null,
1031  'flags' => null,
1032  'framed' => true,
1033  ];
1034 
1035  return $this;
1036  }
1037 
1047  public function setTokenSalt( $salt ) {
1048  $this->mTokenSalt = $salt;
1049 
1050  return $this;
1051  }
1052 
1067  public function displayForm( $submitResult ) {
1068  $this->getOutput()->addHTML( $this->getHTML( $submitResult ) );
1069  }
1070 
1081  public function getHTML( $submitResult ) {
1082  # For good measure (it is the default)
1083  $this->getOutput()->preventClickjacking();
1084  $this->getOutput()->addModules( 'mediawiki.htmlform' );
1085  $this->getOutput()->addModuleStyles( 'mediawiki.htmlform.styles' );
1086 
1087  if ( $this->mCollapsible ) {
1088  $this->getOutput()->addModules( 'jquery.makeCollapsible' );
1089  }
1090 
1091  $html = ''
1092  . $this->getErrorsOrWarnings( $submitResult, 'error' )
1093  . $this->getErrorsOrWarnings( $submitResult, 'warning' )
1094  . $this->getHeaderText()
1095  . $this->getBody()
1096  . $this->getHiddenFields()
1097  . $this->getButtons()
1098  . $this->getFooterText();
1099 
1100  $html = $this->wrapForm( $html );
1101 
1102  return '' . $this->mPre . $html . $this->mPost;
1103  }
1104 
1112  public function setCollapsibleOptions( $collapsedByDefault = false ) {
1113  $this->mCollapsible = true;
1114  $this->mCollapsed = $collapsedByDefault;
1115  return $this;
1116  }
1117 
1123  protected function getFormAttributes() {
1124  # Use multipart/form-data
1125  $encType = $this->mUseMultipart
1126  ? 'multipart/form-data'
1127  : 'application/x-www-form-urlencoded';
1128  # Attributes
1129  $attribs = [
1130  'class' => 'mw-htmlform',
1131  'action' => $this->getAction(),
1132  'method' => $this->getMethod(),
1133  'enctype' => $encType,
1134  ];
1135  if ( $this->mId ) {
1136  $attribs['id'] = $this->mId;
1137  }
1138  if ( is_string( $this->mAutocomplete ) ) {
1139  $attribs['autocomplete'] = $this->mAutocomplete;
1140  }
1141  if ( $this->mName ) {
1142  $attribs['name'] = $this->mName;
1143  }
1144  if ( $this->needsJSForHtml5FormValidation() ) {
1145  $attribs['novalidate'] = true;
1146  }
1147  return $attribs;
1148  }
1149 
1158  public function wrapForm( $html ) {
1159  # Include a <fieldset> wrapper for style, if requested.
1160  if ( $this->mWrapperLegend !== false ) {
1161  $legend = is_string( $this->mWrapperLegend ) ? $this->mWrapperLegend : false;
1162  $html = Xml::fieldset( $legend, $html, $this->mWrapperAttributes );
1163  }
1164 
1165  return Html::rawElement(
1166  'form',
1167  $this->getFormAttributes(),
1168  $html
1169  );
1170  }
1171 
1176  public function getHiddenFields() {
1177  $html = '';
1178  if ( $this->mFormIdentifier !== null ) {
1179  $html .= Html::hidden(
1180  'wpFormIdentifier',
1181  $this->mFormIdentifier
1182  ) . "\n";
1183  }
1184  if ( $this->getMethod() === 'post' ) {
1185  $html .= Html::hidden(
1186  'wpEditToken',
1187  $this->getUser()->getEditToken( $this->mTokenSalt ),
1188  [ 'id' => 'wpEditToken' ]
1189  ) . "\n";
1190  $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1191  }
1192 
1193  $articlePath = $this->getConfig()->get( 'ArticlePath' );
1194  if ( strpos( $articlePath, '?' ) !== false && $this->getMethod() === 'get' ) {
1195  $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1196  }
1197 
1198  foreach ( $this->mHiddenFields as $data ) {
1199  list( $value, $attribs ) = $data;
1200  $html .= Html::hidden( $attribs['name'], $value, $attribs ) . "\n";
1201  }
1202 
1203  return $html;
1204  }
1205 
1211  public function getButtons() {
1212  $buttons = '';
1213  $useMediaWikiUIEverywhere = $this->getConfig()->get( 'UseMediaWikiUIEverywhere' );
1214 
1215  if ( $this->mShowSubmit ) {
1216  $attribs = [];
1217 
1218  if ( isset( $this->mSubmitID ) ) {
1219  $attribs['id'] = $this->mSubmitID;
1220  }
1221 
1222  if ( isset( $this->mSubmitName ) ) {
1223  $attribs['name'] = $this->mSubmitName;
1224  }
1225 
1226  if ( isset( $this->mSubmitTooltip ) ) {
1227  $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
1228  }
1229 
1230  $attribs['class'] = [ 'mw-htmlform-submit' ];
1231 
1232  if ( $useMediaWikiUIEverywhere ) {
1233  foreach ( $this->mSubmitFlags as $flag ) {
1234  $attribs['class'][] = 'mw-ui-' . $flag;
1235  }
1236  $attribs['class'][] = 'mw-ui-button';
1237  }
1238 
1239  $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
1240  }
1241 
1242  if ( $this->mShowReset ) {
1243  $buttons .= Html::element(
1244  'input',
1245  [
1246  'type' => 'reset',
1247  'value' => $this->msg( 'htmlform-reset' )->text(),
1248  'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null,
1249  ]
1250  ) . "\n";
1251  }
1252 
1253  if ( $this->mShowCancel ) {
1254  $target = $this->mCancelTarget ?: Title::newMainPage();
1255  if ( $target instanceof Title ) {
1256  $target = $target->getLocalURL();
1257  }
1258  $buttons .= Html::element(
1259  'a',
1260  [
1261  'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null,
1262  'href' => $target,
1263  ],
1264  $this->msg( 'cancel' )->text()
1265  ) . "\n";
1266  }
1267 
1268  foreach ( $this->mButtons as $button ) {
1269  $attrs = [
1270  'type' => 'submit',
1271  'name' => $button['name'],
1272  'value' => $button['value']
1273  ];
1274 
1275  if ( isset( $button['label-message'] ) ) {
1276  $label = $this->getMessage( $button['label-message'] )->parse();
1277  } elseif ( isset( $button['label'] ) ) {
1278  $label = htmlspecialchars( $button['label'] );
1279  } elseif ( isset( $button['label-raw'] ) ) {
1280  $label = $button['label-raw'];
1281  } else {
1282  $label = htmlspecialchars( $button['value'] );
1283  }
1284 
1285  if ( $button['attribs'] ) {
1286  $attrs += $button['attribs'];
1287  }
1288 
1289  if ( isset( $button['id'] ) ) {
1290  $attrs['id'] = $button['id'];
1291  }
1292 
1293  if ( $useMediaWikiUIEverywhere ) {
1294  $attrs['class'] = isset( $attrs['class'] ) ? (array)$attrs['class'] : [];
1295  $attrs['class'][] = 'mw-ui-button';
1296  }
1297 
1298  $buttons .= Html::rawElement( 'button', $attrs, $label ) . "\n";
1299  }
1300 
1301  if ( !$buttons ) {
1302  return '';
1303  }
1304 
1305  return Html::rawElement( 'span',
1306  [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n";
1307  }
1308 
1314  public function getBody() {
1315  return $this->displaySection( $this->mFieldTree, $this->mTableId );
1316  }
1317 
1327  public function getErrorsOrWarnings( $elements, $elementsType ) {
1328  if ( !in_array( $elementsType, [ 'error', 'warning' ], true ) ) {
1329  throw new DomainException( $elementsType . ' is not a valid type.' );
1330  }
1331  $elementstr = false;
1332  if ( $elements instanceof Status ) {
1333  list( $errorStatus, $warningStatus ) = $elements->splitByErrorType();
1334  $status = $elementsType === 'error' ? $errorStatus : $warningStatus;
1335  if ( $status->isGood() ) {
1336  $elementstr = '';
1337  } else {
1338  $elementstr = $status
1339  ->getMessage()
1340  ->setContext( $this )
1341  ->setInterfaceMessageFlag( true )
1342  ->parse();
1343  }
1344  } elseif ( is_array( $elements ) && $elementsType === 'error' ) {
1345  $elementstr = $this->formatErrors( $elements );
1346  } elseif ( $elementsType === 'error' ) {
1347  $elementstr = $elements;
1348  }
1349 
1350  return $elementstr
1351  ? Html::rawElement( 'div', [ 'class' => $elementsType . 'box' ], $elementstr )
1352  : '';
1353  }
1354 
1362  public function formatErrors( $errors ) {
1363  $errorstr = '';
1364 
1365  foreach ( $errors as $error ) {
1366  $errorstr .= Html::rawElement(
1367  'li',
1368  [],
1369  $this->getMessage( $error )->parse()
1370  );
1371  }
1372 
1373  $errorstr = Html::rawElement( 'ul', [], $errorstr );
1374 
1375  return $errorstr;
1376  }
1377 
1385  public function setSubmitText( $t ) {
1386  $this->mSubmitText = $t;
1387 
1388  return $this;
1389  }
1390 
1397  public function setSubmitDestructive() {
1398  $this->mSubmitFlags = [ 'destructive', 'primary' ];
1399 
1400  return $this;
1401  }
1402 
1411  public function setSubmitTextMsg( $msg ) {
1412  if ( !$msg instanceof Message ) {
1413  $msg = $this->msg( $msg );
1414  }
1415  $this->setSubmitText( $msg->text() );
1416 
1417  return $this;
1418  }
1419 
1424  public function getSubmitText() {
1425  return $this->mSubmitText ?: $this->msg( 'htmlform-submit' )->text();
1426  }
1427 
1433  public function setSubmitName( $name ) {
1434  $this->mSubmitName = $name;
1435 
1436  return $this;
1437  }
1438 
1444  public function setSubmitTooltip( $name ) {
1445  $this->mSubmitTooltip = $name;
1446 
1447  return $this;
1448  }
1449 
1458  public function setSubmitID( $t ) {
1459  $this->mSubmitID = $t;
1460 
1461  return $this;
1462  }
1463 
1479  public function setFormIdentifier( $ident ) {
1480  $this->mFormIdentifier = $ident;
1481 
1482  return $this;
1483  }
1484 
1495  public function suppressDefaultSubmit( $suppressSubmit = true ) {
1496  $this->mShowSubmit = !$suppressSubmit;
1497 
1498  return $this;
1499  }
1500 
1507  public function showCancel( $show = true ) {
1508  $this->mShowCancel = $show;
1509  return $this;
1510  }
1511 
1518  public function setCancelTarget( $target ) {
1519  $this->mCancelTarget = $target;
1520  return $this;
1521  }
1522 
1532  public function setTableId( $id ) {
1533  $this->mTableId = $id;
1534 
1535  return $this;
1536  }
1537 
1543  public function setId( $id ) {
1544  $this->mId = $id;
1545 
1546  return $this;
1547  }
1548 
1553  public function setName( $name ) {
1554  $this->mName = $name;
1555 
1556  return $this;
1557  }
1558 
1570  public function setWrapperLegend( $legend ) {
1571  $this->mWrapperLegend = $legend;
1572 
1573  return $this;
1574  }
1575 
1583  public function setWrapperAttributes( $attributes ) {
1584  $this->mWrapperAttributes = $attributes;
1585 
1586  return $this;
1587  }
1588 
1598  public function setWrapperLegendMsg( $msg ) {
1599  if ( !$msg instanceof Message ) {
1600  $msg = $this->msg( $msg );
1601  }
1602  $this->setWrapperLegend( $msg->text() );
1603 
1604  return $this;
1605  }
1606 
1616  public function setMessagePrefix( $p ) {
1617  $this->mMessagePrefix = $p;
1618 
1619  return $this;
1620  }
1621 
1629  public function setTitle( $t ) {
1630  $this->mTitle = $t;
1631 
1632  return $this;
1633  }
1634 
1639  public function getTitle() {
1640  return $this->mTitle === false
1641  ? $this->getContext()->getTitle()
1642  : $this->mTitle;
1643  }
1644 
1652  public function setMethod( $method = 'post' ) {
1653  $this->mMethod = strtolower( $method );
1654 
1655  return $this;
1656  }
1657 
1661  public function getMethod() {
1662  return $this->mMethod;
1663  }
1664 
1675  protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
1676  return Xml::fieldset( $legend, $section, $attributes ) . "\n";
1677  }
1678 
1696  public function displaySection( $fields,
1697  $sectionName = '',
1698  $fieldsetIDPrefix = '',
1699  &$hasUserVisibleFields = false
1700  ) {
1701  if ( $this->mFieldData === null ) {
1702  throw new LogicException( 'HTMLForm::displaySection() called on uninitialized field data. '
1703  . 'You probably called displayForm() without calling prepareForm() first.' );
1704  }
1705 
1706  $displayFormat = $this->getDisplayFormat();
1707 
1708  $html = [];
1709  $subsectionHtml = '';
1710  $hasLabel = false;
1711 
1712  // Conveniently, PHP method names are case-insensitive.
1713  // For grep: this can call getDiv, getRaw, getInline, getVForm, getOOUI
1714  $getFieldHtmlMethod = $displayFormat === 'table' ? 'getTableRow' : ( 'get' . $displayFormat );
1715 
1716  foreach ( $fields as $key => $value ) {
1717  if ( $value instanceof HTMLFormField ) {
1718  $v = array_key_exists( $key, $this->mFieldData )
1719  ? $this->mFieldData[$key]
1720  : $value->getDefault();
1721 
1722  $retval = $value->$getFieldHtmlMethod( $v );
1723 
1724  // check, if the form field should be added to
1725  // the output.
1726  if ( $value->hasVisibleOutput() ) {
1727  $html[] = $retval;
1728 
1729  $labelValue = trim( $value->getLabel() );
1730  if ( $labelValue !== "\u{00A0}" && $labelValue !== '&#160;' && $labelValue !== '' ) {
1731  $hasLabel = true;
1732  }
1733 
1734  $hasUserVisibleFields = true;
1735  }
1736  } elseif ( is_array( $value ) ) {
1737  $subsectionHasVisibleFields = false;
1738  $section =
1739  $this->displaySection( $value,
1740  "mw-htmlform-$key",
1741  "$fieldsetIDPrefix$key-",
1742  $subsectionHasVisibleFields );
1743  $legend = null;
1744 
1745  if ( $subsectionHasVisibleFields === true ) {
1746  // Display the section with various niceties.
1747  $hasUserVisibleFields = true;
1748 
1749  $legend = $this->getLegend( $key );
1750 
1751  $section = $this->getHeaderText( $key ) .
1752  $section .
1753  $this->getFooterText( $key );
1754 
1755  $attributes = [];
1756  if ( $fieldsetIDPrefix ) {
1757  $attributes['id'] = Sanitizer::escapeIdForAttribute( "$fieldsetIDPrefix$key" );
1758  }
1759  $subsectionHtml .= $this->wrapFieldSetSection(
1760  $legend, $section, $attributes, $fields === $this->mFieldTree
1761  );
1762  } else {
1763  // Just return the inputs, nothing fancy.
1764  $subsectionHtml .= $section;
1765  }
1766  }
1767  }
1768 
1769  $html = $this->formatSection( $html, $sectionName, $hasLabel );
1770 
1771  if ( $subsectionHtml ) {
1772  if ( $this->mSubSectionBeforeFields ) {
1773  return $subsectionHtml . "\n" . $html;
1774  } else {
1775  return $html . "\n" . $subsectionHtml;
1776  }
1777  } else {
1778  return $html;
1779  }
1780  }
1781 
1790  protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
1791  if ( !$fieldsHtml ) {
1792  // Do not generate any wrappers for empty sections. Sections may be empty if they only have
1793  // subsections, but no fields. A legend will still be added in wrapFieldSetSection().
1794  return '';
1795  }
1796 
1797  $displayFormat = $this->getDisplayFormat();
1798  $html = implode( '', $fieldsHtml );
1799 
1800  if ( $displayFormat === 'raw' ) {
1801  return $html;
1802  }
1803 
1804  $classes = [];
1805 
1806  if ( !$anyFieldHasLabel ) { // Avoid strange spacing when no labels exist
1807  $classes[] = 'mw-htmlform-nolabel';
1808  }
1809 
1810  $attribs = [ 'class' => $classes ];
1811 
1812  if ( $sectionName ) {
1813  $attribs['id'] = Sanitizer::escapeIdForAttribute( $sectionName );
1814  }
1815 
1816  if ( $displayFormat === 'table' ) {
1817  return Html::rawElement( 'table',
1818  $attribs,
1819  Html::rawElement( 'tbody', [], "\n$html\n" ) ) . "\n";
1820  } elseif ( $displayFormat === 'inline' ) {
1821  return Html::rawElement( 'span', $attribs, "\n$html\n" );
1822  } else {
1823  return Html::rawElement( 'div', $attribs, "\n$html\n" );
1824  }
1825  }
1826 
1830  public function loadData() {
1831  $fieldData = [];
1832 
1833  foreach ( $this->mFlatFields as $fieldname => $field ) {
1834  $request = $this->getRequest();
1835  if ( $field->skipLoadData( $request ) ) {
1836  continue;
1837  } elseif ( !empty( $field->mParams['disabled'] ) ) {
1838  $fieldData[$fieldname] = $field->getDefault();
1839  } else {
1840  $fieldData[$fieldname] = $field->loadDataFromRequest( $request );
1841  }
1842  }
1843 
1844  # Filter data.
1845  foreach ( $fieldData as $name => &$value ) {
1846  $field = $this->mFlatFields[$name];
1847  $value = $field->filter( $value, $this->mFlatFields );
1848  }
1849 
1850  $this->mFieldData = $fieldData;
1851  }
1852 
1860  public function suppressReset( $suppressReset = true ) {
1861  $this->mShowReset = !$suppressReset;
1862 
1863  return $this;
1864  }
1865 
1876  public function filterDataForSubmit( $data ) {
1877  return $data;
1878  }
1879 
1889  public function getLegend( $key ) {
1890  return $this->msg( $this->mMessagePrefix ? "{$this->mMessagePrefix}-$key" : $key )->text();
1891  }
1892 
1903  public function setAction( $action ) {
1904  $this->mAction = $action;
1905 
1906  return $this;
1907  }
1908 
1916  public function getAction() {
1917  // If an action is alredy provided, return it
1918  if ( $this->mAction !== false ) {
1919  return $this->mAction;
1920  }
1921 
1922  $articlePath = $this->getConfig()->get( 'ArticlePath' );
1923  // Check whether we are in GET mode and the ArticlePath contains a "?"
1924  // meaning that getLocalURL() would return something like "index.php?title=...".
1925  // As browser remove the query string before submitting GET forms,
1926  // it means that the title would be lost. In such case use wfScript() instead
1927  // and put title in an hidden field (see getHiddenFields()).
1928  if ( strpos( $articlePath, '?' ) !== false && $this->getMethod() === 'get' ) {
1929  return wfScript();
1930  }
1931 
1932  return $this->getTitle()->getLocalURL();
1933  }
1934 
1945  public function setAutocomplete( $autocomplete ) {
1946  $this->mAutocomplete = $autocomplete;
1947 
1948  return $this;
1949  }
1950 
1957  protected function getMessage( $value ) {
1958  return Message::newFromSpecifier( $value )->setContext( $this );
1959  }
1960 
1970  public function needsJSForHtml5FormValidation() {
1971  foreach ( $this->mFlatFields as $fieldname => $field ) {
1972  if ( $field->needsJSForHtml5FormValidation() ) {
1973  return true;
1974  }
1975  }
1976  return false;
1977  }
1978 }
HTMLForm\$mSubSectionBeforeFields
$mSubSectionBeforeFields
If true, sections that contain both fields and subsections will render their subsections before their...
Definition: HTMLForm.php:277
HTMLForm\getLegend
getLegend( $key)
Get a string to go in the "<legend>" of a section fieldset.
Definition: HTMLForm.php:1889
HTMLForm\$mTokenSalt
string array $mTokenSalt
Salt for the edit token.
Definition: HTMLForm.php:268
HTMLForm\$typeMappings
static $typeMappings
Definition: HTMLForm.php:139
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:942
HTMLForm\setAutocomplete
setAutocomplete( $autocomplete)
Set the value for the autocomplete attribute of the form.
Definition: HTMLForm.php:1945
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:213
HTMLForm\prepareForm
prepareForm()
Prepare form for submission.
Definition: HTMLForm.php:548
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:42
HTMLForm\hasField
hasField( $fieldname)
Definition: HTMLForm.php:411
HTMLForm\setPreText
setPreText( $msg)
Set the introductory message HTML, overwriting any existing message.
Definition: HTMLForm.php:781
HTMLForm\suppressDefaultSubmit
suppressDefaultSubmit( $suppressSubmit=true)
Stop a default submit button being shown for this form.
Definition: HTMLForm.php:1495
HTMLForm\$mSectionHeaders
$mSectionHeaders
Definition: HTMLForm.php:204
HTMLForm\setSubmitName
setSubmitName( $name)
Definition: HTMLForm.php:1433
HTMLForm\setFooterText
setFooterText( $msg, $section=null)
Set footer text, inside the form.
Definition: HTMLForm.php:897
HTMLForm\$mFieldTree
$mFieldTree
Definition: HTMLForm.php:190
HTMLForm\setIntro
setIntro( $msg)
Set the introductory message, overwriting any existing message.
Definition: HTMLForm.php:767
HTMLForm\tryAuthorizedSubmit
tryAuthorizedSubmit()
Try submitting, with edit token check first.
Definition: HTMLForm.php:571
HTMLForm\setWrapperAttributes
setWrapperAttributes( $attributes)
For internal use only.
Definition: HTMLForm.php:1583
HTMLForm\setSubmitTooltip
setSubmitTooltip( $name)
Definition: HTMLForm.php:1444
HTMLForm\addHeaderText
addHeaderText( $msg, $section=null)
Add HTML to the header, inside the form.
Definition: HTMLForm.php:819
HTMLForm\$mTitle
$mTitle
Definition: HTMLForm.php:217
HTMLForm\setDisplayFormat
setDisplayFormat( $format)
Set format in which to display the form.
Definition: HTMLForm.php:437
HTMLForm\wrapForm
wrapForm( $html)
Wrap the form innards in an actual "<form>" element Stable to override.
Definition: HTMLForm.php:1158
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:815
HTMLForm\getHiddenFields
getHiddenFields()
Get the hidden fields that should go inside the form.
Definition: HTMLForm.php:1176
HTMLForm\$mCollapsed
bool $mCollapsed
Whether the form is collapsed by default.
Definition: HTMLForm.php:240
HTMLForm\getDisplayFormat
getDisplayFormat()
Getter for displayFormat.
Definition: HTMLForm.php:472
HTMLForm\$mWasSubmitted
$mWasSubmitted
Definition: HTMLForm.php:219
HTMLForm\$mFieldData
$mFieldData
Definition: HTMLForm.php:184
HTMLForm\setHeaderText
setHeaderText( $msg, $section=null)
Set header text, inside the form.
Definition: HTMLForm.php:841
HTMLForm\formatErrors
formatErrors( $errors)
Format a stack of error messages into a single HTML string.
Definition: HTMLForm.php:1362
HTMLForm\getClassFromDescriptor
static getClassFromDescriptor( $fieldname, &$descriptor)
Get the HTMLFormField subclass for this descriptor.
Definition: HTMLForm.php:493
HTMLForm\showCancel
showCancel( $show=true)
Show a cancel button (or prevent it).
Definition: HTMLForm.php:1507
HTMLForm\addFields
addFields( $descriptor)
Add fields to the form.
Definition: HTMLForm.php:374
HTMLForm\$mWrapperLegend
$mWrapperLegend
Definition: HTMLForm.php:261
HTMLForm\$mUseMultipart
$mUseMultipart
Definition: HTMLForm.php:249
HTMLForm\$mShowSubmit
$mShowSubmit
Definition: HTMLForm.php:192
HTMLForm\$mAutocomplete
string null $mAutocomplete
Form attribute autocomplete.
Definition: HTMLForm.php:247
HTMLForm\$mCancelTarget
$mCancelTarget
Definition: HTMLForm.php:196
HTMLForm\setTokenSalt
setTokenSalt( $salt)
Set the salt for the edit token.
Definition: HTMLForm.php:1047
HTMLForm\$mSubmitTooltip
$mSubmitTooltip
Definition: HTMLForm.php:214
HTMLForm\$displayFormat
string $displayFormat
Format in which to display form.
Definition: HTMLForm.php:284
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:610
HTMLForm\$mSubmitID
$mSubmitID
Definition: HTMLForm.php:211
HTMLForm\setCancelTarget
setCancelTarget( $target)
Sets the target where the user is redirected to after clicking cancel.
Definition: HTMLForm.php:1518
HTMLForm\getBody
getBody()
Get the whole body of the form.
Definition: HTMLForm.php:1314
VFormHTMLForm
Compact stacked vertical format for forms.
Definition: VFormHTMLForm.php:29
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:653
HTMLForm\$mShowReset
$mShowReset
Definition: HTMLForm.php:191
HTMLForm\$mTableId
$mTableId
Definition: HTMLForm.php:209
$res
$res
Definition: testCompression.php:57
HTMLForm\$mSubmitName
$mSubmitName
Definition: HTMLForm.php:212
ContextSource\getUser
getUser()
Stable to override.
Definition: ContextSource.php:131
HTMLForm\getAction
getAction()
Get the value for the action attribute of the form.
Definition: HTMLForm.php:1916
HTMLForm\setMethod
setMethod( $method='post')
Set the method used to submit the form.
Definition: HTMLForm.php:1652
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:339
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:616
HTMLForm\setSubmitText
setSubmitText( $t)
Set the text for the submit button.
Definition: HTMLForm.php:1385
OOUIHTMLForm
Compact stacked vertical format for forms, implemented using OOUI widgets.
Definition: OOUIHTMLForm.php:29
HTMLForm\$mSubmitFlags
string[] $mSubmitFlags
Definition: HTMLForm.php:194
HTMLForm\trySubmit
trySubmit()
Validate all the fields, and call the submission callback function if everything is kosher.
Definition: HTMLForm.php:650
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:1112
MWException
MediaWiki exception.
Definition: MWException.php:29
HTMLForm\$mAction
bool string $mAction
Form action URL.
Definition: HTMLForm.php:226
HTMLForm\setFormIdentifier
setFormIdentifier( $ident)
Set an internal identifier for this form.
Definition: HTMLForm.php:1479
HTMLForm\getHeaderText
getHeaderText( $section=null)
Get header text.
Definition: HTMLForm.php:859
HTMLForm\addButton
addButton( $data)
Add a button to the form.
Definition: HTMLForm.php:1006
wfScript
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
Definition: GlobalFunctions.php:2536
HTMLForm\addHiddenField
addHiddenField( $name, $value, array $attribs=[])
Add a hidden field to the output.
Definition: HTMLForm.php:957
ContextSource\getOutput
getOutput()
Definition: ContextSource.php:121
HTMLForm\setSubmitID
setSubmitID( $t)
Set the id for the submit button.
Definition: HTMLForm.php:1458
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:9
$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:726
HTMLForm\$mFormIdentifier
$mFormIdentifier
Definition: HTMLForm.php:216
HTMLForm\formatSection
formatSection(array $fieldsHtml, $sectionName, $anyFieldHasLabel)
Put a form section together from the individual fields' HTML, merging it and wrapping.
Definition: HTMLForm.php:1790
HTMLForm\$mButtons
array[] $mButtons
-var array<array{name:string,value:string,label-message?:string|string[]|MessageSpecifier,...
Definition: HTMLForm.php:259
HTMLForm\setMessagePrefix
setMessagePrefix( $p)
Set the prefix for various default messages.
Definition: HTMLForm.php:1616
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:740
HTMLForm\$mId
$mId
Definition: HTMLForm.php:207
HTMLForm\$mSectionFooters
$mSectionFooters
Definition: HTMLForm.php:205
HTMLForm\loadInputFromParameters
static loadInputFromParameters( $fieldname, $descriptor, HTMLForm $parent=null)
Initialise a new Object for the field Stable to override.
Definition: HTMLForm.php:523
ContextSource\setContext
setContext(IContextSource $context)
Definition: ContextSource.php:58
HTMLForm\$mPost
$mPost
Definition: HTMLForm.php:206
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:1327
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:203
HTMLForm\getFormAttributes
getFormAttributes()
Get HTML attributes for the <form> tag.
Definition: HTMLForm.php:1123
HTMLForm\$mMethod
$mMethod
Definition: HTMLForm.php:218
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:82
HTMLForm\setId
setId( $id)
Definition: HTMLForm.php:1543
HTMLForm\$availableSubclassDisplayFormats
array $availableSubclassDisplayFormats
Available formats in which to display the form.
Definition: HTMLForm.php:301
HTMLForm\$availableDisplayFormats
array $availableDisplayFormats
Available formats in which to display the form.
Definition: HTMLForm.php:290
HTMLForm\getPreText
getPreText()
Get the introductory message HTML.
Definition: HTMLForm.php:807
HTMLForm\setWrapperLegend
setWrapperLegend( $legend)
Prompt the whole form to be wrapped in a "<fieldset>", with this text as its "<legend>" element.
Definition: HTMLForm.php:1570
HTMLForm\displaySection
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
Definition: HTMLForm.php:1696
HTMLForm\$mSubmitCallback
$mSubmitCallback
Definition: HTMLForm.php:198
HTMLForm\loadData
loadData()
Construct the form fields from the Descriptor array.
Definition: HTMLForm.php:1830
HTMLForm\showAlways
showAlways()
Same as self::show with the difference, that the form will be added to the output,...
Definition: HTMLForm.php:628
HTMLForm\$mName
$mName
Definition: HTMLForm.php:208
HTMLForm\setSubmitDestructive
setSubmitDestructive()
Identify that the submit button in the form has a destructive action.
Definition: HTMLForm.php:1397
HTMLForm\setValidationErrorMessage
setValidationErrorMessage( $msg)
Set a message to display on a validation error.
Definition: HTMLForm.php:754
HTMLForm\$mCollapsible
bool $mCollapsible
Whether the form can be collapsed.
Definition: HTMLForm.php:233
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:1411
Title
Represents a title within MediaWiki.
Definition: Title.php:41
HTMLForm\setName
setName( $name)
Definition: HTMLForm.php:1553
HTMLForm\$mPre
$mPre
Definition: HTMLForm.php:201
HTMLForm\getHTML
getHTML( $submitResult)
Returns the raw HTML generated by the form.
Definition: HTMLForm.php:1081
HTMLForm\getSubmitText
getSubmitText()
Get the text for the submit button, either customised or a default.
Definition: HTMLForm.php:1424
HTMLForm\getMessage
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
Definition: HTMLForm.php:1957
HTMLForm\addHiddenFields
addHiddenFields(array $fields)
Add an array of hidden fields to the output.
Definition: HTMLForm.php:974
HTMLForm\$mShowCancel
$mShowCancel
Definition: HTMLForm.php:195
HTMLForm\$mWrapperAttributes
$mWrapperAttributes
Definition: HTMLForm.php:262
HTMLForm\setWrapperLegendMsg
setWrapperLegendMsg( $msg)
Prompt the whole form to be wrapped in a "<fieldset>", with this message as its "<legend>" element.
Definition: HTMLForm.php:1598
HTMLForm\$mValidationErrorMessage
$mValidationErrorMessage
Definition: HTMLForm.php:199
HTMLForm\setAction
setAction( $action)
Set the value for the action attribute of the form.
Definition: HTMLForm.php:1903
HTMLForm\$mHeader
$mHeader
Definition: HTMLForm.php:202
HTMLForm\setTitle
setTitle( $t)
Set the title for form submission.
Definition: HTMLForm.php:1629
HTMLForm\setTableId
setTableId( $id)
Set the id of the <table> or outermost <div> element.
Definition: HTMLForm.php:1532
HTMLForm\$mMessagePrefix
$mMessagePrefix
Definition: HTMLForm.php:186
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:1067
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:1639
HTMLForm\filterDataForSubmit
filterDataForSubmit( $data)
Overload this if you want to apply special filtration routines to the form as a whole,...
Definition: HTMLForm.php:1876
HTMLForm\getMethod
getMethod()
Definition: HTMLForm.php:1661
HTMLForm\addPreText
addPreText( $msg)
Add HTML to introductory message.
Definition: HTMLForm.php:794
$t
$t
Definition: testCompression.php:74
HTMLForm\getField
getField( $fieldname)
Definition: HTMLForm.php:420
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:254
HTMLForm\addPostText
addPostText( $msg)
Add text to the end of the display.
Definition: HTMLForm.php:929
HTMLForm\wrapFieldSetSection
wrapFieldSetSection( $legend, $section, $attributes, $isRoot)
Wraps the given $section into an user-visible fieldset.
Definition: HTMLForm.php:1675
HTMLForm\suppressReset
suppressReset( $suppressReset=true)
Stop a reset button being shown for this form.
Definition: HTMLForm.php:1860
HTMLForm\getFooterText
getFooterText( $section=null)
Get footer text.
Definition: HTMLForm.php:914
HTMLForm\$mFlatFields
HTMLFormField[] $mFlatFields
Definition: HTMLForm.php:189
HTMLForm\factory
static factory( $displayFormat,... $arguments)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:315
HTMLForm\getButtons
getButtons()
Get the submit and (potentially) reset buttons.
Definition: HTMLForm.php:1211
HTMLForm\addFooterText
addFooterText( $msg, $section=null)
Add footer text, inside the form.
Definition: HTMLForm.php:875
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:1970
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition: HTMLForm.php:135