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 
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 
278  protected $mSubSectionBeforeFields = true;
279 
285  protected $displayFormat = 'table';
286 
292  'table',
293  'div',
294  'raw',
295  'inline',
296  ];
297 
303  'vform',
304  'ooui',
305  ];
306 
316  public static function factory( $displayFormat, ...$arguments ) {
317  switch ( $displayFormat ) {
318  case 'vform':
319  return new VFormHTMLForm( ...$arguments );
320  case 'ooui':
321  return new OOUIHTMLForm( ...$arguments );
322  default:
323  $form = new self( ...$arguments );
324  $form->setDisplayFormat( $displayFormat );
325  return $form;
326  }
327  }
328 
340  public function __construct( $descriptor, /*IContextSource*/ $context = null,
341  $messagePrefix = ''
342  ) {
343  if ( $context instanceof IContextSource ) {
344  $this->setContext( $context );
345  $this->mTitle = false; // We don't need them to set a title
346  $this->mMessagePrefix = $messagePrefix;
347  } elseif ( $context === null && $messagePrefix !== '' ) {
348  $this->mMessagePrefix = $messagePrefix;
349  } elseif ( is_string( $context ) && $messagePrefix === '' ) {
350  // B/C since 1.18
351  // it's actually $messagePrefix
352  $this->mMessagePrefix = $context;
353  }
354 
355  // Evil hack for mobile :(
356  if (
357  !$this->getConfig()->get( 'HTMLFormAllowTableFormat' )
358  && $this->displayFormat === 'table'
359  ) {
360  $this->displayFormat = 'div';
361  }
362 
363  $this->addFields( $descriptor );
364  }
365 
375  public function addFields( $descriptor ) {
376  $loadedDescriptor = [];
377 
378  foreach ( $descriptor as $fieldname => $info ) {
379 
380  $section = $info['section'] ?? '';
381 
382  if ( isset( $info['type'] ) && $info['type'] === 'file' ) {
383  $this->mUseMultipart = true;
384  }
385 
386  $field = static::loadInputFromParameters( $fieldname, $info, $this );
387 
388  $setSection =& $loadedDescriptor;
389  if ( $section ) {
390  foreach ( explode( '/', $section ) as $newName ) {
391  if ( !isset( $setSection[$newName] ) ) {
392  $setSection[$newName] = [];
393  }
394 
395  $setSection =& $setSection[$newName];
396  }
397  }
398 
399  $setSection[$fieldname] = $field;
400  $this->mFlatFields[$fieldname] = $field;
401  }
402 
403  $this->mFieldTree = array_merge( $this->mFieldTree, $loadedDescriptor );
404 
405  return $this;
406  }
407 
412  public function hasField( $fieldname ) {
413  return isset( $this->mFlatFields[$fieldname] );
414  }
415 
421  public function getField( $fieldname ) {
422  if ( !$this->hasField( $fieldname ) ) {
423  throw new DomainException( __METHOD__ . ': no field named ' . $fieldname );
424  }
425  return $this->mFlatFields[$fieldname];
426  }
427 
438  public function setDisplayFormat( $format ) {
439  if (
440  in_array( $format, $this->availableSubclassDisplayFormats, true ) ||
441  in_array( $this->displayFormat, $this->availableSubclassDisplayFormats, true )
442  ) {
443  throw new MWException( 'Cannot change display format after creation, ' .
444  'use HTMLForm::factory() instead' );
445  }
446 
447  if ( !in_array( $format, $this->availableDisplayFormats, true ) ) {
448  throw new MWException( 'Display format must be one of ' .
449  print_r(
450  array_merge(
451  $this->availableDisplayFormats,
452  $this->availableSubclassDisplayFormats
453  ),
454  true
455  ) );
456  }
457 
458  // Evil hack for mobile :(
459  if ( !$this->getConfig()->get( 'HTMLFormAllowTableFormat' ) && $format === 'table' ) {
460  $format = 'div';
461  }
462 
463  $this->displayFormat = $format;
464 
465  return $this;
466  }
467 
473  public function getDisplayFormat() {
474  return $this->displayFormat;
475  }
476 
494  public static function getClassFromDescriptor( $fieldname, &$descriptor ) {
495  if ( isset( $descriptor['class'] ) ) {
496  $class = $descriptor['class'];
497  } elseif ( isset( $descriptor['type'] ) ) {
498  $class = static::$typeMappings[$descriptor['type']];
499  $descriptor['class'] = $class;
500  } else {
501  $class = null;
502  }
503 
504  if ( !$class ) {
505  throw new MWException( "Descriptor with no class for $fieldname: "
506  . print_r( $descriptor, true ) );
507  }
508 
509  return $class;
510  }
511 
524  public static function loadInputFromParameters( $fieldname, $descriptor,
525  HTMLForm $parent = null
526  ) {
527  $class = static::getClassFromDescriptor( $fieldname, $descriptor );
528 
529  $descriptor['fieldname'] = $fieldname;
530  if ( $parent ) {
531  $descriptor['parent'] = $parent;
532  }
533 
534  # @todo This will throw a fatal error whenever someone try to use
535  # 'class' to feed a CSS class instead of 'cssclass'. Would be
536  # great to avoid the fatal error and show a nice error.
537  return new $class( $descriptor );
538  }
539 
549  public function prepareForm() {
550  # Check if we have the info we need
551  if ( !$this->mTitle instanceof Title && $this->mTitle !== false ) {
552  throw new MWException( 'You must call setTitle() on an HTMLForm' );
553  }
554 
555  # Load data from the request.
556  if (
557  $this->mFormIdentifier === null ||
558  $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier
559  ) {
560  $this->loadData();
561  } else {
562  $this->mFieldData = [];
563  }
564 
565  return $this;
566  }
567 
572  public function tryAuthorizedSubmit() {
573  $result = false;
574 
575  if ( $this->mFormIdentifier === null ) {
576  $identOkay = true;
577  } else {
578  $identOkay = $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier;
579  }
580 
581  $tokenOkay = false;
582  if ( $this->getMethod() !== 'post' ) {
583  $tokenOkay = true; // no session check needed
584  } elseif ( $this->getRequest()->wasPosted() ) {
585  $editToken = $this->getRequest()->getVal( 'wpEditToken' );
586  if ( $this->getUser()->isLoggedIn() || $editToken !== null ) {
587  // Session tokens for logged-out users have no security value.
588  // However, if the user gave one, check it in order to give a nice
589  // "session expired" error instead of "permission denied" or such.
590  $tokenOkay = $this->getUser()->matchEditToken( $editToken, $this->mTokenSalt );
591  } else {
592  $tokenOkay = true;
593  }
594  }
595 
596  if ( $tokenOkay && $identOkay ) {
597  $this->mWasSubmitted = true;
598  $result = $this->trySubmit();
599  }
600 
601  return $result;
602  }
603 
611  public function show() {
612  $this->prepareForm();
613 
614  $result = $this->tryAuthorizedSubmit();
615  if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
616  return $result;
617  }
618 
619  $this->displayForm( $result );
620 
621  return false;
622  }
623 
629  public function showAlways() {
630  $this->prepareForm();
631 
632  $result = $this->tryAuthorizedSubmit();
633 
634  $this->displayForm( $result );
635 
636  return $result;
637  }
638 
651  public function trySubmit() {
652  $valid = true;
653  $hoistedErrors = Status::newGood();
654  if ( $this->mValidationErrorMessage ) {
655  foreach ( $this->mValidationErrorMessage as $error ) {
656  $hoistedErrors->fatal( ...$error );
657  }
658  } else {
659  $hoistedErrors->fatal( 'htmlform-invalid-input' );
660  }
661 
662  $this->mWasSubmitted = true;
663 
664  # Check for cancelled submission
665  foreach ( $this->mFlatFields as $fieldname => $field ) {
666  if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
667  continue;
668  }
669  if ( $field->cancelSubmit( $this->mFieldData[$fieldname], $this->mFieldData ) ) {
670  $this->mWasSubmitted = false;
671  return false;
672  }
673  }
674 
675  # Check for validation
676  foreach ( $this->mFlatFields as $fieldname => $field ) {
677  if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
678  continue;
679  }
680  if ( $field->isHidden( $this->mFieldData ) ) {
681  continue;
682  }
683  $res = $field->validate( $this->mFieldData[$fieldname], $this->mFieldData );
684  if ( $res !== true ) {
685  $valid = false;
686  if ( $res !== false && !$field->canDisplayErrors() ) {
687  if ( is_string( $res ) ) {
688  $hoistedErrors->fatal( 'rawmessage', $res );
689  } else {
690  $hoistedErrors->fatal( $res );
691  }
692  }
693  }
694  }
695 
696  if ( !$valid ) {
697  return $hoistedErrors;
698  }
699 
700  $callback = $this->mSubmitCallback;
701  if ( !is_callable( $callback ) ) {
702  throw new MWException( 'HTMLForm: no submit callback provided. Use ' .
703  'setSubmitCallback() to set one.' );
704  }
705 
706  $data = $this->filterDataForSubmit( $this->mFieldData );
707 
708  $res = call_user_func( $callback, $data, $this );
709  if ( $res === false ) {
710  $this->mWasSubmitted = false;
711  }
712 
713  return $res;
714  }
715 
727  public function wasSubmitted() {
728  return $this->mWasSubmitted;
729  }
730 
741  public function setSubmitCallback( $cb ) {
742  $this->mSubmitCallback = $cb;
743 
744  return $this;
745  }
746 
755  public function setValidationErrorMessage( $msg ) {
756  $this->mValidationErrorMessage = $msg;
757 
758  return $this;
759  }
760 
768  public function setIntro( $msg ) {
769  $this->setPreText( $msg );
770 
771  return $this;
772  }
773 
782  public function setPreText( $msg ) {
783  $this->mPre = $msg;
784 
785  return $this;
786  }
787 
795  public function addPreText( $msg ) {
796  $this->mPre .= $msg;
797 
798  return $this;
799  }
800 
808  public function getPreText() {
809  return $this->mPre;
810  }
811 
820  public function addHeaderText( $msg, $section = null ) {
821  if ( $section === null ) {
822  $this->mHeader .= $msg;
823  } else {
824  if ( !isset( $this->mSectionHeaders[$section] ) ) {
825  $this->mSectionHeaders[$section] = '';
826  }
827  $this->mSectionHeaders[$section] .= $msg;
828  }
829 
830  return $this;
831  }
832 
842  public function setHeaderText( $msg, $section = null ) {
843  if ( $section === null ) {
844  $this->mHeader = $msg;
845  } else {
846  $this->mSectionHeaders[$section] = $msg;
847  }
848 
849  return $this;
850  }
851 
860  public function getHeaderText( $section = null ) {
861  if ( $section === null ) {
862  return $this->mHeader;
863  } else {
864  return $this->mSectionHeaders[$section] ?? '';
865  }
866  }
867 
876  public function addFooterText( $msg, $section = null ) {
877  if ( $section === null ) {
878  $this->mFooter .= $msg;
879  } else {
880  if ( !isset( $this->mSectionFooters[$section] ) ) {
881  $this->mSectionFooters[$section] = '';
882  }
883  $this->mSectionFooters[$section] .= $msg;
884  }
885 
886  return $this;
887  }
888 
898  public function setFooterText( $msg, $section = null ) {
899  if ( $section === null ) {
900  $this->mFooter = $msg;
901  } else {
902  $this->mSectionFooters[$section] = $msg;
903  }
904 
905  return $this;
906  }
907 
915  public function getFooterText( $section = null ) {
916  if ( $section === null ) {
917  return $this->mFooter;
918  } else {
919  return $this->mSectionFooters[$section] ?? '';
920  }
921  }
922 
930  public function addPostText( $msg ) {
931  $this->mPost .= $msg;
932 
933  return $this;
934  }
935 
943  public function setPostText( $msg ) {
944  $this->mPost = $msg;
945 
946  return $this;
947  }
948 
958  public function addHiddenField( $name, $value, array $attribs = [] ) {
959  $attribs += [ 'name' => $name ];
960  $this->mHiddenFields[] = [ $value, $attribs ];
961 
962  return $this;
963  }
964 
975  public function addHiddenFields( array $fields ) {
976  foreach ( $fields as $name => $value ) {
977  $this->mHiddenFields[] = [ $value, [ 'name' => $name ] ];
978  }
979 
980  return $this;
981  }
982 
1007  public function addButton( $data ) {
1008  if ( !is_array( $data ) ) {
1009  $args = func_get_args();
1010  if ( count( $args ) < 2 || count( $args ) > 4 ) {
1011  throw new InvalidArgumentException(
1012  'Incorrect number of arguments for deprecated calling style'
1013  );
1014  }
1015  $data = [
1016  'name' => $args[0],
1017  'value' => $args[1],
1018  'id' => $args[2] ?? null,
1019  'attribs' => $args[3] ?? null,
1020  ];
1021  } else {
1022  if ( !isset( $data['name'] ) ) {
1023  throw new InvalidArgumentException( 'A name is required' );
1024  }
1025  if ( !isset( $data['value'] ) ) {
1026  throw new InvalidArgumentException( 'A value is required' );
1027  }
1028  }
1029  $this->mButtons[] = $data + [
1030  'id' => null,
1031  'attribs' => null,
1032  'flags' => null,
1033  'framed' => true,
1034  ];
1035 
1036  return $this;
1037  }
1038 
1048  public function setTokenSalt( $salt ) {
1049  $this->mTokenSalt = $salt;
1050 
1051  return $this;
1052  }
1053 
1068  public function displayForm( $submitResult ) {
1069  $this->getOutput()->addHTML( $this->getHTML( $submitResult ) );
1070  }
1071 
1082  public function getHTML( $submitResult ) {
1083  # For good measure (it is the default)
1084  $this->getOutput()->preventClickjacking();
1085  $this->getOutput()->addModules( 'mediawiki.htmlform' );
1086  $this->getOutput()->addModuleStyles( 'mediawiki.htmlform.styles' );
1087 
1088  if ( $this->mCollapsible ) {
1089  // Preload jquery.makeCollapsible for mediawiki.htmlform
1090  $this->getOutput()->addModules( 'jquery.makeCollapsible' );
1091  }
1092 
1093  $html = ''
1094  . $this->getErrorsOrWarnings( $submitResult, 'error' )
1095  . $this->getErrorsOrWarnings( $submitResult, 'warning' )
1096  . $this->getHeaderText()
1097  . $this->getBody()
1098  . $this->getHiddenFields()
1099  . $this->getButtons()
1100  . $this->getFooterText();
1101 
1102  $html = $this->wrapForm( $html );
1103 
1104  return '' . $this->mPre . $html . $this->mPost;
1105  }
1106 
1114  public function setCollapsibleOptions( $collapsedByDefault = false ) {
1115  $this->mCollapsible = true;
1116  $this->mCollapsed = $collapsedByDefault;
1117  return $this;
1118  }
1119 
1125  protected function getFormAttributes() {
1126  # Use multipart/form-data
1127  $encType = $this->mUseMultipart
1128  ? 'multipart/form-data'
1129  : 'application/x-www-form-urlencoded';
1130  # Attributes
1131  $attribs = [
1132  'class' => 'mw-htmlform',
1133  'action' => $this->getAction(),
1134  'method' => $this->getMethod(),
1135  'enctype' => $encType,
1136  ];
1137  if ( $this->mId ) {
1138  $attribs['id'] = $this->mId;
1139  }
1140  if ( is_string( $this->mAutocomplete ) ) {
1141  $attribs['autocomplete'] = $this->mAutocomplete;
1142  }
1143  if ( $this->mName ) {
1144  $attribs['name'] = $this->mName;
1145  }
1146  if ( $this->needsJSForHtml5FormValidation() ) {
1147  $attribs['novalidate'] = true;
1148  }
1149  return $attribs;
1150  }
1151 
1160  public function wrapForm( $html ) {
1161  # Include a <fieldset> wrapper for style, if requested.
1162  if ( $this->mWrapperLegend !== false ) {
1163  $legend = is_string( $this->mWrapperLegend ) ? $this->mWrapperLegend : false;
1164  $html = Xml::fieldset( $legend, $html, $this->mWrapperAttributes );
1165  }
1166 
1167  return Html::rawElement(
1168  'form',
1169  $this->getFormAttributes(),
1170  $html
1171  );
1172  }
1173 
1178  public function getHiddenFields() {
1179  $html = '';
1180  if ( $this->mFormIdentifier !== null ) {
1181  $html .= Html::hidden(
1182  'wpFormIdentifier',
1183  $this->mFormIdentifier
1184  ) . "\n";
1185  }
1186  if ( $this->getMethod() === 'post' ) {
1187  $html .= Html::hidden(
1188  'wpEditToken',
1189  $this->getUser()->getEditToken( $this->mTokenSalt ),
1190  [ 'id' => 'wpEditToken' ]
1191  ) . "\n";
1192  $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1193  }
1194 
1195  $articlePath = $this->getConfig()->get( 'ArticlePath' );
1196  if ( strpos( $articlePath, '?' ) !== false && $this->getMethod() === 'get' ) {
1197  $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1198  }
1199 
1200  foreach ( $this->mHiddenFields as [ $value, $attribs ] ) {
1201  $html .= Html::hidden( $attribs['name'], $value, $attribs ) . "\n";
1202  }
1203 
1204  return $html;
1205  }
1206 
1212  public function getButtons() {
1213  $buttons = '';
1214  $useMediaWikiUIEverywhere = $this->getConfig()->get( 'UseMediaWikiUIEverywhere' );
1215 
1216  if ( $this->mShowSubmit ) {
1217  $attribs = [];
1218 
1219  if ( isset( $this->mSubmitID ) ) {
1220  $attribs['id'] = $this->mSubmitID;
1221  }
1222 
1223  if ( isset( $this->mSubmitName ) ) {
1224  $attribs['name'] = $this->mSubmitName;
1225  }
1226 
1227  if ( isset( $this->mSubmitTooltip ) ) {
1228  $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
1229  }
1230 
1231  $attribs['class'] = [ 'mw-htmlform-submit' ];
1232 
1233  if ( $useMediaWikiUIEverywhere ) {
1234  foreach ( $this->mSubmitFlags as $flag ) {
1235  $attribs['class'][] = 'mw-ui-' . $flag;
1236  }
1237  $attribs['class'][] = 'mw-ui-button';
1238  }
1239 
1240  $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
1241  }
1242 
1243  if ( $this->mShowReset ) {
1244  $buttons .= Html::element(
1245  'input',
1246  [
1247  'type' => 'reset',
1248  'value' => $this->msg( 'htmlform-reset' )->text(),
1249  'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null,
1250  ]
1251  ) . "\n";
1252  }
1253 
1254  if ( $this->mShowCancel ) {
1255  $target = $this->mCancelTarget ?: Title::newMainPage();
1256  if ( $target instanceof Title ) {
1257  $target = $target->getLocalURL();
1258  }
1259  $buttons .= Html::element(
1260  'a',
1261  [
1262  'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null,
1263  'href' => $target,
1264  ],
1265  $this->msg( 'cancel' )->text()
1266  ) . "\n";
1267  }
1268 
1269  foreach ( $this->mButtons as $button ) {
1270  $attrs = [
1271  'type' => 'submit',
1272  'name' => $button['name'],
1273  'value' => $button['value']
1274  ];
1275 
1276  if ( isset( $button['label-message'] ) ) {
1277  $label = $this->getMessage( $button['label-message'] )->parse();
1278  } elseif ( isset( $button['label'] ) ) {
1279  $label = htmlspecialchars( $button['label'] );
1280  } elseif ( isset( $button['label-raw'] ) ) {
1281  $label = $button['label-raw'];
1282  } else {
1283  $label = htmlspecialchars( $button['value'] );
1284  }
1285 
1286  if ( $button['attribs'] ) {
1287  $attrs += $button['attribs'];
1288  }
1289 
1290  if ( isset( $button['id'] ) ) {
1291  $attrs['id'] = $button['id'];
1292  }
1293 
1294  if ( $useMediaWikiUIEverywhere ) {
1295  $attrs['class'] = isset( $attrs['class'] ) ? (array)$attrs['class'] : [];
1296  $attrs['class'][] = 'mw-ui-button';
1297  }
1298 
1299  $buttons .= Html::rawElement( 'button', $attrs, $label ) . "\n";
1300  }
1301 
1302  if ( !$buttons ) {
1303  return '';
1304  }
1305 
1306  return Html::rawElement( 'span',
1307  [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n";
1308  }
1309 
1315  public function getBody() {
1316  return $this->displaySection( $this->mFieldTree, $this->mTableId );
1317  }
1318 
1328  public function getErrorsOrWarnings( $elements, $elementsType ) {
1329  if ( !in_array( $elementsType, [ 'error', 'warning' ], true ) ) {
1330  throw new DomainException( $elementsType . ' is not a valid type.' );
1331  }
1332  $elementstr = false;
1333  if ( $elements instanceof Status ) {
1334  list( $errorStatus, $warningStatus ) = $elements->splitByErrorType();
1335  $status = $elementsType === 'error' ? $errorStatus : $warningStatus;
1336  if ( $status->isGood() ) {
1337  $elementstr = '';
1338  } else {
1339  $elementstr = $status
1340  ->getMessage()
1341  ->setContext( $this )
1342  ->setInterfaceMessageFlag( true )
1343  ->parse();
1344  }
1345  } elseif ( $elementsType === 'error' ) {
1346  if ( is_array( $elements ) ) {
1347  $elementstr = $this->formatErrors( $elements );
1348  } elseif ( $elements && $elements !== true ) {
1349  $elementstr = (string)$elements;
1350  }
1351  }
1352 
1353  return $elementstr
1354  ? Html::rawElement( 'div', [ 'class' => $elementsType . 'box' ], $elementstr )
1355  : '';
1356  }
1357 
1365  public function formatErrors( $errors ) {
1366  $errorstr = '';
1367 
1368  foreach ( $errors as $error ) {
1369  $errorstr .= Html::rawElement(
1370  'li',
1371  [],
1372  $this->getMessage( $error )->parse()
1373  );
1374  }
1375 
1376  $errorstr = Html::rawElement( 'ul', [], $errorstr );
1377 
1378  return $errorstr;
1379  }
1380 
1388  public function setSubmitText( $t ) {
1389  $this->mSubmitText = $t;
1390 
1391  return $this;
1392  }
1393 
1400  public function setSubmitDestructive() {
1401  $this->mSubmitFlags = [ 'destructive', 'primary' ];
1402 
1403  return $this;
1404  }
1405 
1414  public function setSubmitTextMsg( $msg ) {
1415  if ( !$msg instanceof Message ) {
1416  $msg = $this->msg( $msg );
1417  }
1418  $this->setSubmitText( $msg->text() );
1419 
1420  return $this;
1421  }
1422 
1427  public function getSubmitText() {
1428  return $this->mSubmitText ?: $this->msg( 'htmlform-submit' )->text();
1429  }
1430 
1436  public function setSubmitName( $name ) {
1437  $this->mSubmitName = $name;
1438 
1439  return $this;
1440  }
1441 
1447  public function setSubmitTooltip( $name ) {
1448  $this->mSubmitTooltip = $name;
1449 
1450  return $this;
1451  }
1452 
1461  public function setSubmitID( $t ) {
1462  $this->mSubmitID = $t;
1463 
1464  return $this;
1465  }
1466 
1482  public function setFormIdentifier( $ident ) {
1483  $this->mFormIdentifier = $ident;
1484 
1485  return $this;
1486  }
1487 
1498  public function suppressDefaultSubmit( $suppressSubmit = true ) {
1499  $this->mShowSubmit = !$suppressSubmit;
1500 
1501  return $this;
1502  }
1503 
1510  public function showCancel( $show = true ) {
1511  $this->mShowCancel = $show;
1512  return $this;
1513  }
1514 
1521  public function setCancelTarget( $target ) {
1522  $this->mCancelTarget = $target;
1523  return $this;
1524  }
1525 
1535  public function setTableId( $id ) {
1536  $this->mTableId = $id;
1537 
1538  return $this;
1539  }
1540 
1546  public function setId( $id ) {
1547  $this->mId = $id;
1548 
1549  return $this;
1550  }
1551 
1556  public function setName( $name ) {
1557  $this->mName = $name;
1558 
1559  return $this;
1560  }
1561 
1573  public function setWrapperLegend( $legend ) {
1574  $this->mWrapperLegend = $legend;
1575 
1576  return $this;
1577  }
1578 
1586  public function setWrapperAttributes( $attributes ) {
1587  $this->mWrapperAttributes = $attributes;
1588 
1589  return $this;
1590  }
1591 
1601  public function setWrapperLegendMsg( $msg ) {
1602  if ( !$msg instanceof Message ) {
1603  $msg = $this->msg( $msg );
1604  }
1605  $this->setWrapperLegend( $msg->text() );
1606 
1607  return $this;
1608  }
1609 
1619  public function setMessagePrefix( $p ) {
1620  $this->mMessagePrefix = $p;
1621 
1622  return $this;
1623  }
1624 
1632  public function setTitle( $t ) {
1633  $this->mTitle = $t;
1634 
1635  return $this;
1636  }
1637 
1641  public function getTitle() {
1642  return $this->mTitle === false
1643  ? $this->getContext()->getTitle()
1644  : $this->mTitle;
1645  }
1646 
1654  public function setMethod( $method = 'post' ) {
1655  $this->mMethod = strtolower( $method );
1656 
1657  return $this;
1658  }
1659 
1663  public function getMethod() {
1664  return $this->mMethod;
1665  }
1666 
1677  protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
1678  return Xml::fieldset( $legend, $section, $attributes ) . "\n";
1679  }
1680 
1698  public function displaySection( $fields,
1699  $sectionName = '',
1700  $fieldsetIDPrefix = '',
1701  &$hasUserVisibleFields = false
1702  ) {
1703  if ( $this->mFieldData === null ) {
1704  throw new LogicException( 'HTMLForm::displaySection() called on uninitialized field data. '
1705  . 'You probably called displayForm() without calling prepareForm() first.' );
1706  }
1707 
1708  $displayFormat = $this->getDisplayFormat();
1709 
1710  $html = [];
1711  $subsectionHtml = '';
1712  $hasLabel = false;
1713 
1714  // Conveniently, PHP method names are case-insensitive.
1715  // For grep: this can call getDiv, getRaw, getInline, getVForm, getOOUI
1716  $getFieldHtmlMethod = $displayFormat === 'table' ? 'getTableRow' : ( 'get' . $displayFormat );
1717 
1718  foreach ( $fields as $key => $value ) {
1719  if ( $value instanceof HTMLFormField ) {
1720  $v = array_key_exists( $key, $this->mFieldData )
1721  ? $this->mFieldData[$key]
1722  : $value->getDefault();
1723 
1724  $retval = $value->$getFieldHtmlMethod( $v );
1725 
1726  // check, if the form field should be added to
1727  // the output.
1728  if ( $value->hasVisibleOutput() ) {
1729  $html[] = $retval;
1730 
1731  $labelValue = trim( $value->getLabel() );
1732  if ( $labelValue !== "\u{00A0}" && $labelValue !== '&#160;' && $labelValue !== '' ) {
1733  $hasLabel = true;
1734  }
1735 
1736  $hasUserVisibleFields = true;
1737  }
1738  } elseif ( is_array( $value ) ) {
1739  $subsectionHasVisibleFields = false;
1740  $section =
1741  $this->displaySection( $value,
1742  "mw-htmlform-$key",
1743  "$fieldsetIDPrefix$key-",
1744  $subsectionHasVisibleFields );
1745  $legend = null;
1746 
1747  if ( $subsectionHasVisibleFields === true ) {
1748  // Display the section with various niceties.
1749  $hasUserVisibleFields = true;
1750 
1751  $legend = $this->getLegend( $key );
1752 
1753  $section = $this->getHeaderText( $key ) .
1754  $section .
1755  $this->getFooterText( $key );
1756 
1757  $attributes = [];
1758  if ( $fieldsetIDPrefix ) {
1759  $attributes['id'] = Sanitizer::escapeIdForAttribute( "$fieldsetIDPrefix$key" );
1760  }
1761  $subsectionHtml .= $this->wrapFieldSetSection(
1762  $legend, $section, $attributes, $fields === $this->mFieldTree
1763  );
1764  } else {
1765  // Just return the inputs, nothing fancy.
1766  $subsectionHtml .= $section;
1767  }
1768  }
1769  }
1770 
1771  $html = $this->formatSection( $html, $sectionName, $hasLabel );
1772 
1773  if ( $subsectionHtml ) {
1774  if ( $this->mSubSectionBeforeFields ) {
1775  return $subsectionHtml . "\n" . $html;
1776  } else {
1777  return $html . "\n" . $subsectionHtml;
1778  }
1779  } else {
1780  return $html;
1781  }
1782  }
1783 
1792  protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
1793  if ( !$fieldsHtml ) {
1794  // Do not generate any wrappers for empty sections. Sections may be empty if they only have
1795  // subsections, but no fields. A legend will still be added in wrapFieldSetSection().
1796  return '';
1797  }
1798 
1799  $displayFormat = $this->getDisplayFormat();
1800  $html = implode( '', $fieldsHtml );
1801 
1802  if ( $displayFormat === 'raw' ) {
1803  return $html;
1804  }
1805 
1806  $classes = [];
1807 
1808  if ( !$anyFieldHasLabel ) { // Avoid strange spacing when no labels exist
1809  $classes[] = 'mw-htmlform-nolabel';
1810  }
1811 
1812  $attribs = [ 'class' => $classes ];
1813 
1814  if ( $sectionName ) {
1815  $attribs['id'] = Sanitizer::escapeIdForAttribute( $sectionName );
1816  }
1817 
1818  if ( $displayFormat === 'table' ) {
1819  return Html::rawElement( 'table',
1820  $attribs,
1821  Html::rawElement( 'tbody', [], "\n$html\n" ) ) . "\n";
1822  } elseif ( $displayFormat === 'inline' ) {
1823  return Html::rawElement( 'span', $attribs, "\n$html\n" );
1824  } else {
1825  return Html::rawElement( 'div', $attribs, "\n$html\n" );
1826  }
1827  }
1828 
1832  public function loadData() {
1833  $fieldData = [];
1834 
1835  foreach ( $this->mFlatFields as $fieldname => $field ) {
1836  $request = $this->getRequest();
1837  if ( $field->skipLoadData( $request ) ) {
1838  continue;
1839  } elseif ( !empty( $field->mParams['disabled'] ) ) {
1840  $fieldData[$fieldname] = $field->getDefault();
1841  } else {
1842  $fieldData[$fieldname] = $field->loadDataFromRequest( $request );
1843  }
1844  }
1845 
1846  # Filter data.
1847  foreach ( $fieldData as $name => &$value ) {
1848  $field = $this->mFlatFields[$name];
1849  $value = $field->filter( $value, $this->mFlatFields );
1850  }
1851 
1852  $this->mFieldData = $fieldData;
1853  }
1854 
1862  public function suppressReset( $suppressReset = true ) {
1863  $this->mShowReset = !$suppressReset;
1864 
1865  return $this;
1866  }
1867 
1878  public function filterDataForSubmit( $data ) {
1879  return $data;
1880  }
1881 
1891  public function getLegend( $key ) {
1892  return $this->msg( $this->mMessagePrefix ? "{$this->mMessagePrefix}-$key" : $key )->text();
1893  }
1894 
1905  public function setAction( $action ) {
1906  $this->mAction = $action;
1907 
1908  return $this;
1909  }
1910 
1918  public function getAction() {
1919  // If an action is alredy provided, return it
1920  if ( $this->mAction !== false ) {
1921  return $this->mAction;
1922  }
1923 
1924  $articlePath = $this->getConfig()->get( 'ArticlePath' );
1925  // Check whether we are in GET mode and the ArticlePath contains a "?"
1926  // meaning that getLocalURL() would return something like "index.php?title=...".
1927  // As browser remove the query string before submitting GET forms,
1928  // it means that the title would be lost. In such case use wfScript() instead
1929  // and put title in an hidden field (see getHiddenFields()).
1930  if ( strpos( $articlePath, '?' ) !== false && $this->getMethod() === 'get' ) {
1931  return wfScript();
1932  }
1933 
1934  return $this->getTitle()->getLocalURL();
1935  }
1936 
1947  public function setAutocomplete( $autocomplete ) {
1948  $this->mAutocomplete = $autocomplete;
1949 
1950  return $this;
1951  }
1952 
1959  protected function getMessage( $value ) {
1960  return Message::newFromSpecifier( $value )->setContext( $this );
1961  }
1962 
1972  public function needsJSForHtml5FormValidation() {
1973  foreach ( $this->mFlatFields as $fieldname => $field ) {
1974  if ( $field->needsJSForHtml5FormValidation() ) {
1975  return true;
1976  }
1977  }
1978  return false;
1979  }
1980 }
HTMLForm\getLegend
getLegend( $key)
Get a string to go in the "<legend>" of a section fieldset.
Definition: HTMLForm.php:1891
HTMLForm\$mTokenSalt
string array $mTokenSalt
Salt for the edit token.
Definition: HTMLForm.php:268
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:37
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:70
HTMLForm\setPostText
setPostText( $msg)
Set text at the end of the display.
Definition: HTMLForm.php:943
HTMLForm\setAutocomplete
setAutocomplete( $autocomplete)
Set the value for the autocomplete attribute of the form.
Definition: HTMLForm.php:1947
Message\newFromSpecifier
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition: Message.php:423
HTMLForm\$mSubmitText
$mSubmitText
Definition: HTMLForm.php:213
HTMLForm\prepareForm
prepareForm()
Prepare form for submission.
Definition: HTMLForm.php:549
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:45
HTMLForm\hasField
hasField( $fieldname)
Definition: HTMLForm.php:412
HTMLForm\$mSubSectionBeforeFields
bool $mSubSectionBeforeFields
If true, sections that contain both fields and subsections will render their subsections before their...
Definition: HTMLForm.php:278
HTMLForm\setPreText
setPreText( $msg)
Set the introductory message HTML, overwriting any existing message.
Definition: HTMLForm.php:782
HTMLForm\suppressDefaultSubmit
suppressDefaultSubmit( $suppressSubmit=true)
Stop a default submit button being shown for this form.
Definition: HTMLForm.php:1498
HTMLForm\$mSectionHeaders
$mSectionHeaders
Definition: HTMLForm.php:204
HTMLForm\setSubmitName
setSubmitName( $name)
Definition: HTMLForm.php:1436
HTMLForm\setFooterText
setFooterText( $msg, $section=null)
Set footer text, inside the form.
Definition: HTMLForm.php:898
HTMLForm\$mFieldTree
$mFieldTree
Definition: HTMLForm.php:190
HTMLForm\setIntro
setIntro( $msg)
Set the introductory message, overwriting any existing message.
Definition: HTMLForm.php:768
HTMLForm\tryAuthorizedSubmit
tryAuthorizedSubmit()
Try submitting, with edit token check first.
Definition: HTMLForm.php:572
HTMLForm\setWrapperAttributes
setWrapperAttributes( $attributes)
For internal use only.
Definition: HTMLForm.php:1586
HTMLForm\setSubmitTooltip
setSubmitTooltip( $name)
Definition: HTMLForm.php:1447
HTMLForm\addHeaderText
addHeaderText( $msg, $section=null)
Add HTML to the header, inside the form.
Definition: HTMLForm.php:820
HTMLForm\$mTitle
$mTitle
Definition: HTMLForm.php:217
HTMLForm\setDisplayFormat
setDisplayFormat( $format)
Set format in which to display the form.
Definition: HTMLForm.php:438
HTMLForm\wrapForm
wrapForm( $html)
Wrap the form innards in an actual "<form>" element Stable to override.
Definition: HTMLForm.php:1160
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:1178
HTMLForm\$mCollapsed
bool $mCollapsed
Whether the form is collapsed by default.
Definition: HTMLForm.php:240
HTMLForm\getDisplayFormat
getDisplayFormat()
Getter for displayFormat.
Definition: HTMLForm.php:473
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:842
HTMLForm\formatErrors
formatErrors( $errors)
Format a stack of error messages into a single HTML string.
Definition: HTMLForm.php:1365
HTMLForm\getClassFromDescriptor
static getClassFromDescriptor( $fieldname, &$descriptor)
Get the HTMLFormField subclass for this descriptor.
Definition: HTMLForm.php:494
HTMLForm\showCancel
showCancel( $show=true)
Show a cancel button (or prevent it).
Definition: HTMLForm.php:1510
HTMLForm\addFields
addFields( $descriptor)
Add fields to the form.
Definition: HTMLForm.php:375
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:1048
HTMLForm\$mSubmitTooltip
$mSubmitTooltip
Definition: HTMLForm.php:214
HTMLForm\$displayFormat
string $displayFormat
Format in which to display form.
Definition: HTMLForm.php:285
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:611
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:1521
HTMLForm\getBody
getBody()
Get the whole body of the form.
Definition: HTMLForm.php:1315
VFormHTMLForm
Compact stacked vertical format for forms.
Definition: VFormHTMLForm.php:29
ContextSource\getRequest
getRequest()
Definition: ContextSource.php:79
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:134
HTMLForm\getAction
getAction()
Get the value for the action attribute of the form.
Definition: HTMLForm.php:1918
HTMLForm\setMethod
setMethod( $method='post')
Set the method used to submit the form.
Definition: HTMLForm.php:1654
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:340
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:1388
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:651
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:1114
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:1482
HTMLForm\getHeaderText
getHeaderText( $section=null)
Get header text.
Definition: HTMLForm.php:860
HTMLForm\addButton
addButton( $data)
Add a button to the form.
Definition: HTMLForm.php:1007
wfScript
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
Definition: GlobalFunctions.php:2515
HTMLForm\addHiddenField
addHiddenField( $name, $value, array $attribs=[])
Add a hidden field to the output.
Definition: HTMLForm.php:958
ContextSource\getOutput
getOutput()
Definition: ContextSource.php:124
HTMLForm\setSubmitID
setSubmitID( $t)
Set the id for the submit button.
Definition: HTMLForm.php:1461
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:31
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:727
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:1792
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:1619
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:741
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:524
ContextSource\setContext
setContext(IContextSource $context)
Definition: ContextSource.php:61
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:187
HTMLForm\getErrorsOrWarnings
getErrorsOrWarnings( $elements, $elementsType)
Returns a formatted list of errors or warnings from the given elements.
Definition: HTMLForm.php:1328
Html\hidden
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:805
HTMLForm\$mFooter
$mFooter
Definition: HTMLForm.php:203
HTMLForm\getFormAttributes
getFormAttributes()
Get HTML attributes for the <form> tag.
Definition: HTMLForm.php:1125
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:1546
HTMLForm\$availableSubclassDisplayFormats
array $availableSubclassDisplayFormats
Available formats in which to display the form.
Definition: HTMLForm.php:302
HTMLForm\$availableDisplayFormats
array $availableDisplayFormats
Available formats in which to display the form.
Definition: HTMLForm.php:291
HTMLForm\getPreText
getPreText()
Get the introductory message HTML.
Definition: HTMLForm.php:808
HTMLForm\$typeMappings
static string[] $typeMappings
A mapping of 'type' inputs onto standard HTMLFormField subclasses.
Definition: HTMLForm.php:139
HTMLForm\setWrapperLegend
setWrapperLegend( $legend)
Prompt the whole form to be wrapped in a "<fieldset>", with this text as its "<legend>" element.
Definition: HTMLForm.php:1573
HTMLForm\displaySection
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
Definition: HTMLForm.php:1698
HTMLForm\$mSubmitCallback
$mSubmitCallback
Definition: HTMLForm.php:198
HTMLForm\loadData
loadData()
Construct the form fields from the Descriptor array.
Definition: HTMLForm.php:1832
HTMLForm\showAlways
showAlways()
Same as self::show with the difference, that the form will be added to the output,...
Definition: HTMLForm.php:629
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:1400
HTMLForm\setValidationErrorMessage
setValidationErrorMessage( $msg)
Set a message to display on a validation error.
Definition: HTMLForm.php:755
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:1414
Title
Represents a title within MediaWiki.
Definition: Title.php:41
HTMLForm\setName
setName( $name)
Definition: HTMLForm.php:1556
HTMLForm\$mPre
$mPre
Definition: HTMLForm.php:201
HTMLForm\getHTML
getHTML( $submitResult)
Returns the raw HTML generated by the form.
Definition: HTMLForm.php:1082
HTMLForm\getSubmitText
getSubmitText()
Get the text for the submit button, either customised or a default.
Definition: HTMLForm.php:1427
HTMLForm\getMessage
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
Definition: HTMLForm.php:1959
HTMLForm\addHiddenFields
addHiddenFields(array $fields)
Add an array of hidden fields to the output.
Definition: HTMLForm.php:975
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:1601
HTMLForm\$mValidationErrorMessage
$mValidationErrorMessage
Definition: HTMLForm.php:199
HTMLForm\setAction
setAction( $action)
Set the value for the action attribute of the form.
Definition: HTMLForm.php:1905
HTMLForm\$mHeader
$mHeader
Definition: HTMLForm.php:202
HTMLForm\setTitle
setTitle( $t)
Set the title for form submission.
Definition: HTMLForm.php:1632
HTMLForm\setTableId
setTableId( $id)
Set the id of the <table> or outermost <div> element.
Definition: HTMLForm.php:1535
HTMLForm\$mMessagePrefix
$mMessagePrefix
Definition: HTMLForm.php:186
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:212
HTMLForm\displayForm
displayForm( $submitResult)
Display the form (sending to the context's OutputPage object), with an appropriate error message or s...
Definition: HTMLForm.php:1068
Message
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition: Message.php:161
HTMLForm\getTitle
getTitle()
Definition: HTMLForm.php:1641
HTMLForm\filterDataForSubmit
filterDataForSubmit( $data)
Overload this if you want to apply special filtration routines to the form as a whole,...
Definition: HTMLForm.php:1878
HTMLForm\getMethod
getMethod()
Definition: HTMLForm.php:1663
HTMLForm\addPreText
addPreText( $msg)
Add HTML to introductory message.
Definition: HTMLForm.php:795
$t
$t
Definition: testCompression.php:74
HTMLForm\getField
getField( $fieldname)
Definition: HTMLForm.php:421
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:234
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:930
HTMLForm\wrapFieldSetSection
wrapFieldSetSection( $legend, $section, $attributes, $isRoot)
Wraps the given $section into an user-visible fieldset.
Definition: HTMLForm.php:1677
HTMLForm\suppressReset
suppressReset( $suppressReset=true)
Stop a reset button being shown for this form.
Definition: HTMLForm.php:1862
HTMLForm\getFooterText
getFooterText( $section=null)
Get footer text.
Definition: HTMLForm.php:915
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:316
HTMLForm\getButtons
getButtons()
Get the submit and (potentially) reset buttons.
Definition: HTMLForm.php:1212
HTMLForm\addFooterText
addFooterText( $msg, $section=null)
Add footer text, inside the form.
Definition: HTMLForm.php:876
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:1972
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition: HTMLForm.php:135