MediaWiki  master
HTMLForm.php
Go to the documentation of this file.
1 <?php
2 
24 use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
25 
140 class HTMLForm extends ContextSource {
141  use ProtectedHookAccessorTrait;
142 
144  public static $typeMappings = [
145  'api' => HTMLApiField::class,
146  'text' => HTMLTextField::class,
147  'textwithbutton' => HTMLTextFieldWithButton::class,
148  'textarea' => HTMLTextAreaField::class,
149  'select' => HTMLSelectField::class,
150  'combobox' => HTMLComboboxField::class,
151  'radio' => HTMLRadioField::class,
152  'multiselect' => HTMLMultiSelectField::class,
153  'limitselect' => HTMLSelectLimitField::class,
154  'check' => HTMLCheckField::class,
155  'toggle' => HTMLCheckField::class,
156  'int' => HTMLIntField::class,
157  'file' => HTMLFileField::class,
158  'float' => HTMLFloatField::class,
159  'info' => HTMLInfoField::class,
160  'selectorother' => HTMLSelectOrOtherField::class,
161  'selectandother' => HTMLSelectAndOtherField::class,
162  'namespaceselect' => HTMLSelectNamespace::class,
163  'namespaceselectwithbutton' => HTMLSelectNamespaceWithButton::class,
164  'tagfilter' => HTMLTagFilter::class,
165  'sizefilter' => HTMLSizeFilterField::class,
166  'submit' => HTMLSubmitField::class,
167  'hidden' => HTMLHiddenField::class,
168  'edittools' => HTMLEditTools::class,
169  'checkmatrix' => HTMLCheckMatrix::class,
170  'cloner' => HTMLFormFieldCloner::class,
171  'autocompleteselect' => HTMLAutoCompleteSelectField::class,
172  'language' => HTMLSelectLanguageField::class,
173  'date' => HTMLDateTimeField::class,
174  'time' => HTMLDateTimeField::class,
175  'datetime' => HTMLDateTimeField::class,
176  'expiry' => HTMLExpiryField::class,
177  // HTMLTextField will output the correct type="" attribute automagically.
178  // There are about four zillion other HTML5 input types, like range, but
179  // we don't use those at the moment, so no point in adding all of them.
180  'email' => HTMLTextField::class,
181  'password' => HTMLTextField::class,
182  'url' => HTMLTextField::class,
183  'title' => HTMLTitleTextField::class,
184  'user' => HTMLUserTextField::class,
185  'usersmultiselect' => HTMLUsersMultiselectField::class,
186  'titlesmultiselect' => HTMLTitlesMultiselectField::class,
187  'namespacesmultiselect' => HTMLNamespacesMultiselectField::class,
188  ];
189 
190  public $mFieldData;
191 
192  protected $mMessagePrefix;
193 
195  protected $mFlatFields = [];
196  protected $mFieldTree = [];
197  protected $mShowReset = false;
198  protected $mShowSubmit = true;
200  protected $mSubmitFlags = [ 'primary', 'progressive' ];
201  protected $mShowCancel = false;
202  protected $mCancelTarget;
203 
204  protected $mSubmitCallback;
206 
207  protected $mPre = '';
208  protected $mHeader = '';
209  protected $mFooter = '';
210  protected $mSectionHeaders = [];
211  protected $mSectionFooters = [];
212  protected $mPost = '';
213  protected $mId;
214  protected $mName;
215  protected $mTableId = '';
216 
217  protected $mSubmitID;
218  protected $mSubmitName;
219  protected $mSubmitText;
220  protected $mSubmitTooltip;
221 
222  protected $mFormIdentifier;
223  protected $mTitle;
224  protected $mMethod = 'post';
225  protected $mWasSubmitted = false;
226 
232  protected $mAction = false;
233 
239  protected $mCollapsible = false;
240 
246  protected $mCollapsed = false;
247 
253  protected $mAutocomplete = null;
254 
255  protected $mUseMultipart = false;
260  protected $mHiddenFields = [];
265  protected $mButtons = [];
266 
267  protected $mWrapperLegend = false;
268  protected $mWrapperAttributes = [];
269 
274  protected $mTokenSalt = '';
275 
284  protected $mSubSectionBeforeFields = true;
285 
291  protected $displayFormat = 'table';
292 
298  'table',
299  'div',
300  'raw',
301  'inline',
302  ];
303 
309  'vform',
310  'ooui',
311  ];
312 
322  public static function factory( $displayFormat, ...$arguments ) {
323  switch ( $displayFormat ) {
324  case 'vform':
325  return new VFormHTMLForm( ...$arguments );
326  case 'ooui':
327  return new OOUIHTMLForm( ...$arguments );
328  default:
329  $form = new self( ...$arguments );
330  $form->setDisplayFormat( $displayFormat );
331  return $form;
332  }
333  }
334 
346  public function __construct( $descriptor, /*IContextSource*/ $context = null,
347  $messagePrefix = ''
348  ) {
349  if ( $context instanceof IContextSource ) {
350  $this->setContext( $context );
351  $this->mTitle = false; // We don't need them to set a title
352  $this->mMessagePrefix = $messagePrefix;
353  } elseif ( $context === null && $messagePrefix !== '' ) {
354  $this->mMessagePrefix = $messagePrefix;
355  } elseif ( is_string( $context ) && $messagePrefix === '' ) {
356  // B/C since 1.18
357  // it's actually $messagePrefix
358  $this->mMessagePrefix = $context;
359  }
360 
361  // Evil hack for mobile :(
362  if (
363  !$this->getConfig()->get( 'HTMLFormAllowTableFormat' )
364  && $this->displayFormat === 'table'
365  ) {
366  $this->displayFormat = 'div';
367  }
368 
369  $this->addFields( $descriptor );
370  }
371 
381  public function addFields( $descriptor ) {
382  $loadedDescriptor = [];
383 
384  foreach ( $descriptor as $fieldname => $info ) {
385 
386  $section = $info['section'] ?? '';
387 
388  if ( isset( $info['type'] ) && $info['type'] === 'file' ) {
389  $this->mUseMultipart = true;
390  }
391 
392  $field = static::loadInputFromParameters( $fieldname, $info, $this );
393 
394  $setSection =& $loadedDescriptor;
395  if ( $section ) {
396  foreach ( explode( '/', $section ) as $newName ) {
397  if ( !isset( $setSection[$newName] ) ) {
398  $setSection[$newName] = [];
399  }
400 
401  $setSection =& $setSection[$newName];
402  }
403  }
404 
405  $setSection[$fieldname] = $field;
406  $this->mFlatFields[$fieldname] = $field;
407  }
408 
409  $this->mFieldTree = array_merge( $this->mFieldTree, $loadedDescriptor );
410 
411  return $this;
412  }
413 
418  public function hasField( $fieldname ) {
419  return isset( $this->mFlatFields[$fieldname] );
420  }
421 
427  public function getField( $fieldname ) {
428  if ( !$this->hasField( $fieldname ) ) {
429  throw new DomainException( __METHOD__ . ': no field named ' . $fieldname );
430  }
431  return $this->mFlatFields[$fieldname];
432  }
433 
444  public function setDisplayFormat( $format ) {
445  if (
446  in_array( $format, $this->availableSubclassDisplayFormats, true ) ||
447  in_array( $this->displayFormat, $this->availableSubclassDisplayFormats, true )
448  ) {
449  throw new MWException( 'Cannot change display format after creation, ' .
450  'use HTMLForm::factory() instead' );
451  }
452 
453  if ( !in_array( $format, $this->availableDisplayFormats, true ) ) {
454  throw new MWException( 'Display format must be one of ' .
455  print_r(
456  array_merge(
457  $this->availableDisplayFormats,
458  $this->availableSubclassDisplayFormats
459  ),
460  true
461  ) );
462  }
463 
464  // Evil hack for mobile :(
465  if ( !$this->getConfig()->get( 'HTMLFormAllowTableFormat' ) && $format === 'table' ) {
466  $format = 'div';
467  }
468 
469  $this->displayFormat = $format;
470 
471  return $this;
472  }
473 
479  public function getDisplayFormat() {
480  return $this->displayFormat;
481  }
482 
500  public static function getClassFromDescriptor( $fieldname, &$descriptor ) {
501  if ( isset( $descriptor['class'] ) ) {
502  $class = $descriptor['class'];
503  } elseif ( isset( $descriptor['type'] ) ) {
504  $class = static::$typeMappings[$descriptor['type']];
505  $descriptor['class'] = $class;
506  } else {
507  $class = null;
508  }
509 
510  if ( !$class ) {
511  throw new MWException( "Descriptor with no class for $fieldname: "
512  . print_r( $descriptor, true ) );
513  }
514 
515  return $class;
516  }
517 
530  public static function loadInputFromParameters( $fieldname, $descriptor,
531  HTMLForm $parent = null
532  ) {
533  $class = static::getClassFromDescriptor( $fieldname, $descriptor );
534 
535  $descriptor['fieldname'] = $fieldname;
536  if ( $parent ) {
537  $descriptor['parent'] = $parent;
538  }
539 
540  # @todo This will throw a fatal error whenever someone try to use
541  # 'class' to feed a CSS class instead of 'cssclass'. Would be
542  # great to avoid the fatal error and show a nice error.
543  return new $class( $descriptor );
544  }
545 
555  public function prepareForm() {
556  # Check if we have the info we need
557  if ( !$this->mTitle instanceof Title && $this->mTitle !== false ) {
558  throw new MWException( 'You must call setTitle() on an HTMLForm' );
559  }
560 
561  # Load data from the request.
562  if (
563  $this->mFormIdentifier === null ||
564  $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier
565  ) {
566  $this->loadData();
567  } else {
568  $this->mFieldData = [];
569  }
570 
571  return $this;
572  }
573 
578  public function tryAuthorizedSubmit() {
579  $result = false;
580 
581  if ( $this->mFormIdentifier === null ) {
582  $identOkay = true;
583  } else {
584  $identOkay = $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier;
585  }
586 
587  $tokenOkay = false;
588  if ( $this->getMethod() !== 'post' ) {
589  $tokenOkay = true; // no session check needed
590  } elseif ( $this->getRequest()->wasPosted() ) {
591  $editToken = $this->getRequest()->getVal( 'wpEditToken' );
592  if ( $this->getUser()->isRegistered() || $editToken !== null ) {
593  // Session tokens for logged-out users have no security value.
594  // However, if the user gave one, check it in order to give a nice
595  // "session expired" error instead of "permission denied" or such.
596  $tokenOkay = $this->getUser()->matchEditToken( $editToken, $this->mTokenSalt );
597  } else {
598  $tokenOkay = true;
599  }
600  }
601 
602  if ( $tokenOkay && $identOkay ) {
603  $this->mWasSubmitted = true;
604  $result = $this->trySubmit();
605  }
606 
607  return $result;
608  }
609 
617  public function show() {
618  $this->prepareForm();
619 
620  $result = $this->tryAuthorizedSubmit();
621  if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
622  return $result;
623  }
624 
625  $this->displayForm( $result );
626 
627  return false;
628  }
629 
635  public function showAlways() {
636  $this->prepareForm();
637 
638  $result = $this->tryAuthorizedSubmit();
639 
640  $this->displayForm( $result );
641 
642  return $result;
643  }
644 
657  public function trySubmit() {
658  $valid = true;
659  $hoistedErrors = Status::newGood();
660  if ( $this->mValidationErrorMessage ) {
661  foreach ( $this->mValidationErrorMessage as $error ) {
662  $hoistedErrors->fatal( ...$error );
663  }
664  } else {
665  $hoistedErrors->fatal( 'htmlform-invalid-input' );
666  }
667 
668  $this->mWasSubmitted = true;
669 
670  # Check for cancelled submission
671  foreach ( $this->mFlatFields as $fieldname => $field ) {
672  if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
673  continue;
674  }
675  if ( $field->cancelSubmit( $this->mFieldData[$fieldname], $this->mFieldData ) ) {
676  $this->mWasSubmitted = false;
677  return false;
678  }
679  }
680 
681  # Check for validation
682  foreach ( $this->mFlatFields as $fieldname => $field ) {
683  if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
684  continue;
685  }
686  if ( $field->isHidden( $this->mFieldData ) ) {
687  continue;
688  }
689  $res = $field->validate( $this->mFieldData[$fieldname], $this->mFieldData );
690  if ( $res !== true ) {
691  $valid = false;
692  if ( $res !== false && !$field->canDisplayErrors() ) {
693  if ( is_string( $res ) ) {
694  $hoistedErrors->fatal( 'rawmessage', $res );
695  } else {
696  $hoistedErrors->fatal( $res );
697  }
698  }
699  }
700  }
701 
702  if ( !$valid ) {
703  return $hoistedErrors;
704  }
705 
706  $callback = $this->mSubmitCallback;
707  if ( !is_callable( $callback ) ) {
708  throw new MWException( 'HTMLForm: no submit callback provided. Use ' .
709  'setSubmitCallback() to set one.' );
710  }
711 
712  $data = $this->filterDataForSubmit( $this->mFieldData );
713 
714  $res = call_user_func( $callback, $data, $this );
715  if ( $res === false ) {
716  $this->mWasSubmitted = false;
717  }
718 
719  return $res;
720  }
721 
733  public function wasSubmitted() {
734  return $this->mWasSubmitted;
735  }
736 
747  public function setSubmitCallback( $cb ) {
748  $this->mSubmitCallback = $cb;
749 
750  return $this;
751  }
752 
761  public function setValidationErrorMessage( $msg ) {
762  $this->mValidationErrorMessage = $msg;
763 
764  return $this;
765  }
766 
774  public function setIntro( $msg ) {
775  $this->setPreText( $msg );
776 
777  return $this;
778  }
779 
788  public function setPreText( $msg ) {
789  $this->mPre = $msg;
790 
791  return $this;
792  }
793 
801  public function addPreText( $msg ) {
802  $this->mPre .= $msg;
803 
804  return $this;
805  }
806 
814  public function getPreText() {
815  return $this->mPre;
816  }
817 
826  public function addHeaderText( $msg, $section = null ) {
827  if ( $section === null ) {
828  $this->mHeader .= $msg;
829  } else {
830  if ( !isset( $this->mSectionHeaders[$section] ) ) {
831  $this->mSectionHeaders[$section] = '';
832  }
833  $this->mSectionHeaders[$section] .= $msg;
834  }
835 
836  return $this;
837  }
838 
848  public function setHeaderText( $msg, $section = null ) {
849  if ( $section === null ) {
850  $this->mHeader = $msg;
851  } else {
852  $this->mSectionHeaders[$section] = $msg;
853  }
854 
855  return $this;
856  }
857 
866  public function getHeaderText( $section = null ) {
867  if ( $section === null ) {
868  return $this->mHeader;
869  } else {
870  return $this->mSectionHeaders[$section] ?? '';
871  }
872  }
873 
882  public function addFooterText( $msg, $section = null ) {
883  if ( $section === null ) {
884  $this->mFooter .= $msg;
885  } else {
886  if ( !isset( $this->mSectionFooters[$section] ) ) {
887  $this->mSectionFooters[$section] = '';
888  }
889  $this->mSectionFooters[$section] .= $msg;
890  }
891 
892  return $this;
893  }
894 
904  public function setFooterText( $msg, $section = null ) {
905  if ( $section === null ) {
906  $this->mFooter = $msg;
907  } else {
908  $this->mSectionFooters[$section] = $msg;
909  }
910 
911  return $this;
912  }
913 
921  public function getFooterText( $section = null ) {
922  if ( $section === null ) {
923  return $this->mFooter;
924  } else {
925  return $this->mSectionFooters[$section] ?? '';
926  }
927  }
928 
936  public function addPostText( $msg ) {
937  $this->mPost .= $msg;
938 
939  return $this;
940  }
941 
949  public function setPostText( $msg ) {
950  $this->mPost = $msg;
951 
952  return $this;
953  }
954 
964  public function addHiddenField( $name, $value, array $attribs = [] ) {
965  $attribs += [ 'name' => $name ];
966  $this->mHiddenFields[] = [ $value, $attribs ];
967 
968  return $this;
969  }
970 
981  public function addHiddenFields( array $fields ) {
982  foreach ( $fields as $name => $value ) {
983  $this->mHiddenFields[] = [ $value, [ 'name' => $name ] ];
984  }
985 
986  return $this;
987  }
988 
1013  public function addButton( $data ) {
1014  if ( !is_array( $data ) ) {
1015  $args = func_get_args();
1016  if ( count( $args ) < 2 || count( $args ) > 4 ) {
1017  throw new InvalidArgumentException(
1018  'Incorrect number of arguments for deprecated calling style'
1019  );
1020  }
1021  $data = [
1022  'name' => $args[0],
1023  'value' => $args[1],
1024  'id' => $args[2] ?? null,
1025  'attribs' => $args[3] ?? null,
1026  ];
1027  } else {
1028  if ( !isset( $data['name'] ) ) {
1029  throw new InvalidArgumentException( 'A name is required' );
1030  }
1031  if ( !isset( $data['value'] ) ) {
1032  throw new InvalidArgumentException( 'A value is required' );
1033  }
1034  }
1035  $this->mButtons[] = $data + [
1036  'id' => null,
1037  'attribs' => null,
1038  'flags' => null,
1039  'framed' => true,
1040  ];
1041 
1042  return $this;
1043  }
1044 
1054  public function setTokenSalt( $salt ) {
1055  $this->mTokenSalt = $salt;
1056 
1057  return $this;
1058  }
1059 
1074  public function displayForm( $submitResult ) {
1075  $this->getOutput()->addHTML( $this->getHTML( $submitResult ) );
1076  }
1077 
1088  public function getHTML( $submitResult ) {
1089  # For good measure (it is the default)
1090  $this->getOutput()->preventClickjacking();
1091  $this->getOutput()->addModules( 'mediawiki.htmlform' );
1092  $this->getOutput()->addModuleStyles( 'mediawiki.htmlform.styles' );
1093 
1094  if ( $this->mCollapsible ) {
1095  // Preload jquery.makeCollapsible for mediawiki.htmlform
1096  $this->getOutput()->addModules( 'jquery.makeCollapsible' );
1097  }
1098 
1099  $html = ''
1100  . $this->getErrorsOrWarnings( $submitResult, 'error' )
1101  . $this->getErrorsOrWarnings( $submitResult, 'warning' )
1102  . $this->getHeaderText()
1103  . $this->getBody()
1104  . $this->getHiddenFields()
1105  . $this->getButtons()
1106  . $this->getFooterText();
1107 
1108  $html = $this->wrapForm( $html );
1109 
1110  return '' . $this->mPre . $html . $this->mPost;
1111  }
1112 
1120  public function setCollapsibleOptions( $collapsedByDefault = false ) {
1121  $this->mCollapsible = true;
1122  $this->mCollapsed = $collapsedByDefault;
1123  return $this;
1124  }
1125 
1131  protected function getFormAttributes() {
1132  # Use multipart/form-data
1133  $encType = $this->mUseMultipart
1134  ? 'multipart/form-data'
1135  : 'application/x-www-form-urlencoded';
1136  # Attributes
1137  $attribs = [
1138  'class' => 'mw-htmlform',
1139  'action' => $this->getAction(),
1140  'method' => $this->getMethod(),
1141  'enctype' => $encType,
1142  ];
1143  if ( $this->mId ) {
1144  $attribs['id'] = $this->mId;
1145  }
1146  if ( is_string( $this->mAutocomplete ) ) {
1147  $attribs['autocomplete'] = $this->mAutocomplete;
1148  }
1149  if ( $this->mName ) {
1150  $attribs['name'] = $this->mName;
1151  }
1152  if ( $this->needsJSForHtml5FormValidation() ) {
1153  $attribs['novalidate'] = true;
1154  }
1155  return $attribs;
1156  }
1157 
1166  public function wrapForm( $html ) {
1167  # Include a <fieldset> wrapper for style, if requested.
1168  if ( $this->mWrapperLegend !== false ) {
1169  $legend = is_string( $this->mWrapperLegend ) ? $this->mWrapperLegend : false;
1170  $html = Xml::fieldset( $legend, $html, $this->mWrapperAttributes );
1171  }
1172 
1173  return Html::rawElement(
1174  'form',
1175  $this->getFormAttributes(),
1176  $html
1177  );
1178  }
1179 
1184  public function getHiddenFields() {
1185  $html = '';
1186  if ( $this->mFormIdentifier !== null ) {
1187  $html .= Html::hidden(
1188  'wpFormIdentifier',
1189  $this->mFormIdentifier
1190  ) . "\n";
1191  }
1192  if ( $this->getMethod() === 'post' ) {
1193  $html .= Html::hidden(
1194  'wpEditToken',
1195  $this->getUser()->getEditToken( $this->mTokenSalt ),
1196  [ 'id' => 'wpEditToken' ]
1197  ) . "\n";
1198  $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1199  }
1200 
1201  $articlePath = $this->getConfig()->get( 'ArticlePath' );
1202  if ( strpos( $articlePath, '?' ) !== false && $this->getMethod() === 'get' ) {
1203  $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1204  }
1205 
1206  foreach ( $this->mHiddenFields as [ $value, $attribs ] ) {
1207  $html .= Html::hidden( $attribs['name'], $value, $attribs ) . "\n";
1208  }
1209 
1210  return $html;
1211  }
1212 
1218  public function getButtons() {
1219  $buttons = '';
1220  $useMediaWikiUIEverywhere = $this->getConfig()->get( 'UseMediaWikiUIEverywhere' );
1221 
1222  if ( $this->mShowSubmit ) {
1223  $attribs = [];
1224 
1225  if ( isset( $this->mSubmitID ) ) {
1226  $attribs['id'] = $this->mSubmitID;
1227  }
1228 
1229  if ( isset( $this->mSubmitName ) ) {
1230  $attribs['name'] = $this->mSubmitName;
1231  }
1232 
1233  if ( isset( $this->mSubmitTooltip ) ) {
1234  $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
1235  }
1236 
1237  $attribs['class'] = [ 'mw-htmlform-submit' ];
1238 
1239  if ( $useMediaWikiUIEverywhere ) {
1240  foreach ( $this->mSubmitFlags as $flag ) {
1241  $attribs['class'][] = 'mw-ui-' . $flag;
1242  }
1243  $attribs['class'][] = 'mw-ui-button';
1244  }
1245 
1246  $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
1247  }
1248 
1249  if ( $this->mShowReset ) {
1250  $buttons .= Html::element(
1251  'input',
1252  [
1253  'type' => 'reset',
1254  'value' => $this->msg( 'htmlform-reset' )->text(),
1255  'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null,
1256  ]
1257  ) . "\n";
1258  }
1259 
1260  if ( $this->mShowCancel ) {
1261  $target = $this->mCancelTarget ?: Title::newMainPage();
1262  if ( $target instanceof Title ) {
1263  $target = $target->getLocalURL();
1264  }
1265  $buttons .= Html::element(
1266  'a',
1267  [
1268  'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null,
1269  'href' => $target,
1270  ],
1271  $this->msg( 'cancel' )->text()
1272  ) . "\n";
1273  }
1274 
1275  foreach ( $this->mButtons as $button ) {
1276  $attrs = [
1277  'type' => 'submit',
1278  'name' => $button['name'],
1279  'value' => $button['value']
1280  ];
1281 
1282  if ( isset( $button['label-message'] ) ) {
1283  $label = $this->getMessage( $button['label-message'] )->parse();
1284  } elseif ( isset( $button['label'] ) ) {
1285  $label = htmlspecialchars( $button['label'] );
1286  } elseif ( isset( $button['label-raw'] ) ) {
1287  $label = $button['label-raw'];
1288  } else {
1289  $label = htmlspecialchars( $button['value'] );
1290  }
1291 
1292  if ( $button['attribs'] ) {
1293  $attrs += $button['attribs'];
1294  }
1295 
1296  if ( isset( $button['id'] ) ) {
1297  $attrs['id'] = $button['id'];
1298  }
1299 
1300  if ( $useMediaWikiUIEverywhere ) {
1301  $attrs['class'] = isset( $attrs['class'] ) ? (array)$attrs['class'] : [];
1302  $attrs['class'][] = 'mw-ui-button';
1303  }
1304 
1305  $buttons .= Html::rawElement( 'button', $attrs, $label ) . "\n";
1306  }
1307 
1308  if ( !$buttons ) {
1309  return '';
1310  }
1311 
1312  return Html::rawElement( 'span',
1313  [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n";
1314  }
1315 
1321  public function getBody() {
1322  return $this->displaySection( $this->mFieldTree, $this->mTableId );
1323  }
1324 
1334  public function getErrorsOrWarnings( $elements, $elementsType ) {
1335  if ( !in_array( $elementsType, [ 'error', 'warning' ], true ) ) {
1336  throw new DomainException( $elementsType . ' is not a valid type.' );
1337  }
1338  $elementstr = false;
1339  if ( $elements instanceof Status ) {
1340  list( $errorStatus, $warningStatus ) = $elements->splitByErrorType();
1341  $status = $elementsType === 'error' ? $errorStatus : $warningStatus;
1342  if ( $status->isGood() ) {
1343  $elementstr = '';
1344  } else {
1345  $elementstr = $status
1346  ->getMessage()
1347  ->setContext( $this )
1348  ->setInterfaceMessageFlag( true )
1349  ->parse();
1350  }
1351  } elseif ( $elementsType === 'error' ) {
1352  if ( is_array( $elements ) ) {
1353  $elementstr = $this->formatErrors( $elements );
1354  } elseif ( $elements && $elements !== true ) {
1355  $elementstr = (string)$elements;
1356  }
1357  }
1358 
1359  return $elementstr
1360  ? Html::rawElement( 'div', [ 'class' => $elementsType . 'box' ], $elementstr )
1361  : '';
1362  }
1363 
1371  public function formatErrors( $errors ) {
1372  $errorstr = '';
1373 
1374  foreach ( $errors as $error ) {
1375  $errorstr .= Html::rawElement(
1376  'li',
1377  [],
1378  $this->getMessage( $error )->parse()
1379  );
1380  }
1381 
1382  $errorstr = Html::rawElement( 'ul', [], $errorstr );
1383 
1384  return $errorstr;
1385  }
1386 
1394  public function setSubmitText( $t ) {
1395  $this->mSubmitText = $t;
1396 
1397  return $this;
1398  }
1399 
1406  public function setSubmitDestructive() {
1407  $this->mSubmitFlags = [ 'destructive', 'primary' ];
1408 
1409  return $this;
1410  }
1411 
1420  public function setSubmitTextMsg( $msg ) {
1421  if ( !$msg instanceof Message ) {
1422  $msg = $this->msg( $msg );
1423  }
1424  $this->setSubmitText( $msg->text() );
1425 
1426  return $this;
1427  }
1428 
1433  public function getSubmitText() {
1434  return $this->mSubmitText ?: $this->msg( 'htmlform-submit' )->text();
1435  }
1436 
1442  public function setSubmitName( $name ) {
1443  $this->mSubmitName = $name;
1444 
1445  return $this;
1446  }
1447 
1453  public function setSubmitTooltip( $name ) {
1454  $this->mSubmitTooltip = $name;
1455 
1456  return $this;
1457  }
1458 
1467  public function setSubmitID( $t ) {
1468  $this->mSubmitID = $t;
1469 
1470  return $this;
1471  }
1472 
1488  public function setFormIdentifier( $ident ) {
1489  $this->mFormIdentifier = $ident;
1490 
1491  return $this;
1492  }
1493 
1504  public function suppressDefaultSubmit( $suppressSubmit = true ) {
1505  $this->mShowSubmit = !$suppressSubmit;
1506 
1507  return $this;
1508  }
1509 
1516  public function showCancel( $show = true ) {
1517  $this->mShowCancel = $show;
1518  return $this;
1519  }
1520 
1527  public function setCancelTarget( $target ) {
1528  $this->mCancelTarget = $target;
1529  return $this;
1530  }
1531 
1541  public function setTableId( $id ) {
1542  $this->mTableId = $id;
1543 
1544  return $this;
1545  }
1546 
1552  public function setId( $id ) {
1553  $this->mId = $id;
1554 
1555  return $this;
1556  }
1557 
1562  public function setName( $name ) {
1563  $this->mName = $name;
1564 
1565  return $this;
1566  }
1567 
1579  public function setWrapperLegend( $legend ) {
1580  $this->mWrapperLegend = $legend;
1581 
1582  return $this;
1583  }
1584 
1592  public function setWrapperAttributes( $attributes ) {
1593  $this->mWrapperAttributes = $attributes;
1594 
1595  return $this;
1596  }
1597 
1607  public function setWrapperLegendMsg( $msg ) {
1608  if ( !$msg instanceof Message ) {
1609  $msg = $this->msg( $msg );
1610  }
1611  $this->setWrapperLegend( $msg->text() );
1612 
1613  return $this;
1614  }
1615 
1625  public function setMessagePrefix( $p ) {
1626  $this->mMessagePrefix = $p;
1627 
1628  return $this;
1629  }
1630 
1638  public function setTitle( $t ) {
1639  $this->mTitle = $t;
1640 
1641  return $this;
1642  }
1643 
1647  public function getTitle() {
1648  return $this->mTitle === false
1649  ? $this->getContext()->getTitle()
1650  : $this->mTitle;
1651  }
1652 
1660  public function setMethod( $method = 'post' ) {
1661  $this->mMethod = strtolower( $method );
1662 
1663  return $this;
1664  }
1665 
1669  public function getMethod() {
1670  return $this->mMethod;
1671  }
1672 
1683  protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
1684  return Xml::fieldset( $legend, $section, $attributes ) . "\n";
1685  }
1686 
1704  public function displaySection( $fields,
1705  $sectionName = '',
1706  $fieldsetIDPrefix = '',
1707  &$hasUserVisibleFields = false
1708  ) {
1709  if ( $this->mFieldData === null ) {
1710  throw new LogicException( 'HTMLForm::displaySection() called on uninitialized field data. '
1711  . 'You probably called displayForm() without calling prepareForm() first.' );
1712  }
1713 
1714  $displayFormat = $this->getDisplayFormat();
1715 
1716  $html = [];
1717  $subsectionHtml = '';
1718  $hasLabel = false;
1719 
1720  // Conveniently, PHP method names are case-insensitive.
1721  // For grep: this can call getDiv, getRaw, getInline, getVForm, getOOUI
1722  $getFieldHtmlMethod = $displayFormat === 'table' ? 'getTableRow' : ( 'get' . $displayFormat );
1723 
1724  foreach ( $fields as $key => $value ) {
1725  if ( $value instanceof HTMLFormField ) {
1726  $v = array_key_exists( $key, $this->mFieldData )
1727  ? $this->mFieldData[$key]
1728  : $value->getDefault();
1729 
1730  $retval = $value->$getFieldHtmlMethod( $v );
1731 
1732  // check, if the form field should be added to
1733  // the output.
1734  if ( $value->hasVisibleOutput() ) {
1735  $html[] = $retval;
1736 
1737  $labelValue = trim( $value->getLabel() );
1738  if ( $labelValue !== "\u{00A0}" && $labelValue !== '&#160;' && $labelValue !== '' ) {
1739  $hasLabel = true;
1740  }
1741 
1742  $hasUserVisibleFields = true;
1743  }
1744  } elseif ( is_array( $value ) ) {
1745  $subsectionHasVisibleFields = false;
1746  $section =
1747  $this->displaySection( $value,
1748  "mw-htmlform-$key",
1749  "$fieldsetIDPrefix$key-",
1750  $subsectionHasVisibleFields );
1751  $legend = null;
1752 
1753  if ( $subsectionHasVisibleFields === true ) {
1754  // Display the section with various niceties.
1755  $hasUserVisibleFields = true;
1756 
1757  $legend = $this->getLegend( $key );
1758 
1759  $section = $this->getHeaderText( $key ) .
1760  $section .
1761  $this->getFooterText( $key );
1762 
1763  $attributes = [];
1764  if ( $fieldsetIDPrefix ) {
1765  $attributes['id'] = Sanitizer::escapeIdForAttribute( "$fieldsetIDPrefix$key" );
1766  }
1767  $subsectionHtml .= $this->wrapFieldSetSection(
1768  $legend, $section, $attributes, $fields === $this->mFieldTree
1769  );
1770  } else {
1771  // Just return the inputs, nothing fancy.
1772  $subsectionHtml .= $section;
1773  }
1774  }
1775  }
1776 
1777  $html = $this->formatSection( $html, $sectionName, $hasLabel );
1778 
1779  if ( $subsectionHtml ) {
1780  if ( $this->mSubSectionBeforeFields ) {
1781  return $subsectionHtml . "\n" . $html;
1782  } else {
1783  return $html . "\n" . $subsectionHtml;
1784  }
1785  } else {
1786  return $html;
1787  }
1788  }
1789 
1798  protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
1799  if ( !$fieldsHtml ) {
1800  // Do not generate any wrappers for empty sections. Sections may be empty if they only have
1801  // subsections, but no fields. A legend will still be added in wrapFieldSetSection().
1802  return '';
1803  }
1804 
1805  $displayFormat = $this->getDisplayFormat();
1806  $html = implode( '', $fieldsHtml );
1807 
1808  if ( $displayFormat === 'raw' ) {
1809  return $html;
1810  }
1811 
1812  $classes = [];
1813 
1814  if ( !$anyFieldHasLabel ) { // Avoid strange spacing when no labels exist
1815  $classes[] = 'mw-htmlform-nolabel';
1816  }
1817 
1818  $attribs = [ 'class' => $classes ];
1819 
1820  if ( $sectionName ) {
1821  $attribs['id'] = Sanitizer::escapeIdForAttribute( $sectionName );
1822  }
1823 
1824  if ( $displayFormat === 'table' ) {
1825  return Html::rawElement( 'table',
1826  $attribs,
1827  Html::rawElement( 'tbody', [], "\n$html\n" ) ) . "\n";
1828  } elseif ( $displayFormat === 'inline' ) {
1829  return Html::rawElement( 'span', $attribs, "\n$html\n" );
1830  } else {
1831  return Html::rawElement( 'div', $attribs, "\n$html\n" );
1832  }
1833  }
1834 
1838  public function loadData() {
1839  $fieldData = [];
1840 
1841  foreach ( $this->mFlatFields as $fieldname => $field ) {
1842  $request = $this->getRequest();
1843  if ( $field->skipLoadData( $request ) ) {
1844  continue;
1845  } elseif ( !empty( $field->mParams['disabled'] ) ) {
1846  $fieldData[$fieldname] = $field->getDefault();
1847  } else {
1848  $fieldData[$fieldname] = $field->loadDataFromRequest( $request );
1849  }
1850  }
1851 
1852  # Filter data.
1853  foreach ( $fieldData as $name => &$value ) {
1854  $field = $this->mFlatFields[$name];
1855  $value = $field->filter( $value, $this->mFlatFields );
1856  }
1857 
1858  $this->mFieldData = $fieldData;
1859  }
1860 
1868  public function suppressReset( $suppressReset = true ) {
1869  $this->mShowReset = !$suppressReset;
1870 
1871  return $this;
1872  }
1873 
1884  public function filterDataForSubmit( $data ) {
1885  return $data;
1886  }
1887 
1897  public function getLegend( $key ) {
1898  return $this->msg( $this->mMessagePrefix ? "{$this->mMessagePrefix}-$key" : $key )->text();
1899  }
1900 
1911  public function setAction( $action ) {
1912  $this->mAction = $action;
1913 
1914  return $this;
1915  }
1916 
1924  public function getAction() {
1925  // If an action is alredy provided, return it
1926  if ( $this->mAction !== false ) {
1927  return $this->mAction;
1928  }
1929 
1930  $articlePath = $this->getConfig()->get( 'ArticlePath' );
1931  // Check whether we are in GET mode and the ArticlePath contains a "?"
1932  // meaning that getLocalURL() would return something like "index.php?title=...".
1933  // As browser remove the query string before submitting GET forms,
1934  // it means that the title would be lost. In such case use wfScript() instead
1935  // and put title in an hidden field (see getHiddenFields()).
1936  if ( strpos( $articlePath, '?' ) !== false && $this->getMethod() === 'get' ) {
1937  return wfScript();
1938  }
1939 
1940  return $this->getTitle()->getLocalURL();
1941  }
1942 
1953  public function setAutocomplete( $autocomplete ) {
1954  $this->mAutocomplete = $autocomplete;
1955 
1956  return $this;
1957  }
1958 
1965  protected function getMessage( $value ) {
1966  return Message::newFromSpecifier( $value )->setContext( $this );
1967  }
1968 
1978  public function needsJSForHtml5FormValidation() {
1979  foreach ( $this->mFlatFields as $fieldname => $field ) {
1980  if ( $field->needsJSForHtml5FormValidation() ) {
1981  return true;
1982  }
1983  }
1984  return false;
1985  }
1986 }
HTMLForm\getLegend
getLegend( $key)
Get a string to go in the "<legend>" of a section fieldset.
Definition: HTMLForm.php:1897
HTMLForm\$mTokenSalt
string array $mTokenSalt
Salt for the edit token.
Definition: HTMLForm.php:274
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:38
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:71
HTMLForm\setPostText
setPostText( $msg)
Set text at the end of the display.
Definition: HTMLForm.php:949
HTMLForm\setAutocomplete
setAutocomplete( $autocomplete)
Set the value for the autocomplete attribute of the form.
Definition: HTMLForm.php:1953
Message\newFromSpecifier
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition: Message.php:424
HTMLForm\$mSubmitText
$mSubmitText
Definition: HTMLForm.php:219
HTMLForm\prepareForm
prepareForm()
Prepare form for submission.
Definition: HTMLForm.php:555
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:46
HTMLForm\hasField
hasField( $fieldname)
Definition: HTMLForm.php:418
HTMLForm\$mSubSectionBeforeFields
bool $mSubSectionBeforeFields
If true, sections that contain both fields and subsections will render their subsections before their...
Definition: HTMLForm.php:284
HTMLForm\setPreText
setPreText( $msg)
Set the introductory message HTML, overwriting any existing message.
Definition: HTMLForm.php:788
HTMLForm\suppressDefaultSubmit
suppressDefaultSubmit( $suppressSubmit=true)
Stop a default submit button being shown for this form.
Definition: HTMLForm.php:1504
HTMLForm\$mSectionHeaders
$mSectionHeaders
Definition: HTMLForm.php:210
HTMLForm\setSubmitName
setSubmitName( $name)
Definition: HTMLForm.php:1442
HTMLForm\setFooterText
setFooterText( $msg, $section=null)
Set footer text, inside the form.
Definition: HTMLForm.php:904
HTMLForm\$mFieldTree
$mFieldTree
Definition: HTMLForm.php:196
HTMLForm\setIntro
setIntro( $msg)
Set the introductory message, overwriting any existing message.
Definition: HTMLForm.php:774
HTMLForm\tryAuthorizedSubmit
tryAuthorizedSubmit()
Try submitting, with edit token check first.
Definition: HTMLForm.php:578
HTMLForm\setWrapperAttributes
setWrapperAttributes( $attributes)
For internal use only.
Definition: HTMLForm.php:1592
HTMLForm\setSubmitTooltip
setSubmitTooltip( $name)
Definition: HTMLForm.php:1453
HTMLForm\addHeaderText
addHeaderText( $msg, $section=null)
Add HTML to the header, inside the form.
Definition: HTMLForm.php:826
HTMLForm\$mTitle
$mTitle
Definition: HTMLForm.php:223
HTMLForm\setDisplayFormat
setDisplayFormat( $format)
Set format in which to display the form.
Definition: HTMLForm.php:444
HTMLForm\wrapForm
wrapForm( $html)
Wrap the form innards in an actual "<form>" element.
Definition: HTMLForm.php:1166
Sanitizer\escapeIdForAttribute
static escapeIdForAttribute( $id, $mode=self::ID_PRIMARY)
Given a section name or other user-generated or otherwise unsafe string, escapes it to be a valid HTM...
Definition: Sanitizer.php:811
HTMLForm\getHiddenFields
getHiddenFields()
Get the hidden fields that should go inside the form.
Definition: HTMLForm.php:1184
HTMLForm\$mCollapsed
bool $mCollapsed
Whether the form is collapsed by default.
Definition: HTMLForm.php:246
HTMLForm\getDisplayFormat
getDisplayFormat()
Getter for displayFormat.
Definition: HTMLForm.php:479
HTMLForm\$mWasSubmitted
$mWasSubmitted
Definition: HTMLForm.php:225
HTMLForm\$mFieldData
$mFieldData
Definition: HTMLForm.php:190
HTMLForm\setHeaderText
setHeaderText( $msg, $section=null)
Set header text, inside the form.
Definition: HTMLForm.php:848
HTMLForm\formatErrors
formatErrors( $errors)
Format a stack of error messages into a single HTML string.
Definition: HTMLForm.php:1371
HTMLForm\getClassFromDescriptor
static getClassFromDescriptor( $fieldname, &$descriptor)
Get the HTMLFormField subclass for this descriptor.
Definition: HTMLForm.php:500
HTMLForm\showCancel
showCancel( $show=true)
Show a cancel button (or prevent it).
Definition: HTMLForm.php:1516
HTMLForm\addFields
addFields( $descriptor)
Add fields to the form.
Definition: HTMLForm.php:381
HTMLForm\$mWrapperLegend
$mWrapperLegend
Definition: HTMLForm.php:267
HTMLForm\$mUseMultipart
$mUseMultipart
Definition: HTMLForm.php:255
HTMLForm\$mShowSubmit
$mShowSubmit
Definition: HTMLForm.php:198
HTMLForm\$mAutocomplete
string null $mAutocomplete
Form attribute autocomplete.
Definition: HTMLForm.php:253
HTMLForm\$mCancelTarget
$mCancelTarget
Definition: HTMLForm.php:202
HTMLForm\setTokenSalt
setTokenSalt( $salt)
Set the salt for the edit token.
Definition: HTMLForm.php:1054
HTMLForm\$mSubmitTooltip
$mSubmitTooltip
Definition: HTMLForm.php:220
HTMLForm\$displayFormat
string $displayFormat
Format in which to display form.
Definition: HTMLForm.php:291
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:617
HTMLForm\$mSubmitID
$mSubmitID
Definition: HTMLForm.php:217
HTMLForm\setCancelTarget
setCancelTarget( $target)
Sets the target where the user is redirected to after clicking cancel.
Definition: HTMLForm.php:1527
HTMLForm\getBody
getBody()
Get the whole body of the form.
Definition: HTMLForm.php:1321
VFormHTMLForm
Compact stacked vertical format for forms.
Definition: VFormHTMLForm.php:29
ContextSource\getRequest
getRequest()
Definition: ContextSource.php:80
Title\newMainPage
static newMainPage(MessageLocalizer $localizer=null)
Create a new Title for the Main Page.
Definition: Title.php:688
HTMLForm\$mShowReset
$mShowReset
Definition: HTMLForm.php:197
HTMLForm\$mTableId
$mTableId
Definition: HTMLForm.php:215
$res
$res
Definition: testCompression.php:57
HTMLForm\$mSubmitName
$mSubmitName
Definition: HTMLForm.php:218
ContextSource\getUser
getUser()
Definition: ContextSource.php:135
HTMLForm\getAction
getAction()
Get the value for the action attribute of the form.
Definition: HTMLForm.php:1924
HTMLForm\setMethod
setMethod( $method='post')
Set the method used to submit the form.
Definition: HTMLForm.php:1660
Linker\tooltipAndAccesskeyAttribs
static tooltipAndAccesskeyAttribs( $name, array $msgParams=[], $options=null)
Returns the attributes for the tooltip and access key.
Definition: Linker.php:2284
HTMLForm\__construct
__construct( $descriptor, $context=null, $messagePrefix='')
Build a new HTMLForm from an array of field attributes.
Definition: HTMLForm.php:346
Status
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: Status.php:44
Xml\fieldset
static fieldset( $legend=false, $content=false, $attribs=[])
Shortcut for creating fieldsets.
Definition: Xml.php:622
HTMLForm\setSubmitText
setSubmitText( $t)
Set the text for the submit button.
Definition: HTMLForm.php:1394
OOUIHTMLForm
Compact stacked vertical format for forms, implemented using OOUI widgets.
Definition: OOUIHTMLForm.php:29
HTMLForm\$mSubmitFlags
string[] $mSubmitFlags
Definition: HTMLForm.php:200
HTMLForm\trySubmit
trySubmit()
Validate all the fields, and call the submission callback function if everything is kosher.
Definition: HTMLForm.php:657
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:1120
MWException
MediaWiki exception.
Definition: MWException.php:29
HTMLForm\$mAction
bool string $mAction
Form action URL.
Definition: HTMLForm.php:232
HTMLForm\setFormIdentifier
setFormIdentifier( $ident)
Set an internal identifier for this form.
Definition: HTMLForm.php:1488
HTMLForm\getHeaderText
getHeaderText( $section=null)
Get header text.
Definition: HTMLForm.php:866
HTMLForm\addButton
addButton( $data)
Add a button to the form.
Definition: HTMLForm.php:1013
wfScript
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
Definition: GlobalFunctions.php:2534
HTMLForm\addHiddenField
addHiddenField( $name, $value, array $attribs=[])
Add a hidden field to the output.
Definition: HTMLForm.php:964
ContextSource\getOutput
getOutput()
Definition: ContextSource.php:125
HTMLForm\setSubmitID
setSubmitID( $t)
Set the id for the submit button.
Definition: HTMLForm.php:1467
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:32
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:733
HTMLForm\$mFormIdentifier
$mFormIdentifier
Definition: HTMLForm.php:222
HTMLForm\formatSection
formatSection(array $fieldsHtml, $sectionName, $anyFieldHasLabel)
Put a form section together from the individual fields' HTML, merging it and wrapping.
Definition: HTMLForm.php:1798
HTMLForm\$mButtons
array[] $mButtons
Definition: HTMLForm.php:265
HTMLForm\setMessagePrefix
setMessagePrefix( $p)
Set the prefix for various default messages.
Definition: HTMLForm.php:1625
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:747
HTMLForm\$mId
$mId
Definition: HTMLForm.php:213
HTMLForm\$mSectionFooters
$mSectionFooters
Definition: HTMLForm.php:211
HTMLForm\loadInputFromParameters
static loadInputFromParameters( $fieldname, $descriptor, HTMLForm $parent=null)
Initialise a new Object for the field.
Definition: HTMLForm.php:530
ContextSource\setContext
setContext(IContextSource $context)
Definition: ContextSource.php:62
HTMLForm\$mPost
$mPost
Definition: HTMLForm.php:212
ContextSource\msg
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:195
HTMLForm\getErrorsOrWarnings
getErrorsOrWarnings( $elements, $elementsType)
Returns a formatted list of errors or warnings from the given elements.
Definition: HTMLForm.php:1334
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:209
HTMLForm\getFormAttributes
getFormAttributes()
Get HTML attributes for the <form> tag.
Definition: HTMLForm.php:1131
HTMLForm\$mMethod
$mMethod
Definition: HTMLForm.php:224
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:82
HTMLForm\setId
setId( $id)
Definition: HTMLForm.php:1552
HTMLForm\$availableSubclassDisplayFormats
array $availableSubclassDisplayFormats
Available formats in which to display the form.
Definition: HTMLForm.php:308
HTMLForm\$availableDisplayFormats
array $availableDisplayFormats
Available formats in which to display the form.
Definition: HTMLForm.php:297
HTMLForm\getPreText
getPreText()
Get the introductory message HTML.
Definition: HTMLForm.php:814
HTMLForm\$typeMappings
static string[] $typeMappings
A mapping of 'type' inputs onto standard HTMLFormField subclasses.
Definition: HTMLForm.php:144
HTMLForm\setWrapperLegend
setWrapperLegend( $legend)
Prompt the whole form to be wrapped in a "<fieldset>", with this text as its "<legend>" element.
Definition: HTMLForm.php:1579
HTMLForm\displaySection
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
Definition: HTMLForm.php:1704
HTMLForm\$mSubmitCallback
$mSubmitCallback
Definition: HTMLForm.php:204
HTMLForm\loadData
loadData()
Construct the form fields from the Descriptor array.
Definition: HTMLForm.php:1838
HTMLForm\showAlways
showAlways()
Same as self::show with the difference, that the form will be added to the output,...
Definition: HTMLForm.php:635
HTMLForm\$mName
$mName
Definition: HTMLForm.php:214
HTMLForm\setSubmitDestructive
setSubmitDestructive()
Identify that the submit button in the form has a destructive action.
Definition: HTMLForm.php:1406
HTMLForm\setValidationErrorMessage
setValidationErrorMessage( $msg)
Set a message to display on a validation error.
Definition: HTMLForm.php:761
HTMLForm\$mCollapsible
bool $mCollapsible
Whether the form can be collapsed.
Definition: HTMLForm.php:239
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:57
HTMLForm\setSubmitTextMsg
setSubmitTextMsg( $msg)
Set the text for the submit button to a message.
Definition: HTMLForm.php:1420
Title
Represents a title within MediaWiki.
Definition: Title.php:46
HTMLForm\setName
setName( $name)
Definition: HTMLForm.php:1562
HTMLForm\$mPre
$mPre
Definition: HTMLForm.php:207
HTMLForm\getHTML
getHTML( $submitResult)
Returns the raw HTML generated by the form.
Definition: HTMLForm.php:1088
HTMLForm\getSubmitText
getSubmitText()
Get the text for the submit button, either customised or a default.
Definition: HTMLForm.php:1433
HTMLForm\getMessage
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
Definition: HTMLForm.php:1965
HTMLForm\addHiddenFields
addHiddenFields(array $fields)
Add an array of hidden fields to the output.
Definition: HTMLForm.php:981
HTMLForm\$mShowCancel
$mShowCancel
Definition: HTMLForm.php:201
HTMLForm\$mWrapperAttributes
$mWrapperAttributes
Definition: HTMLForm.php:268
HTMLForm\setWrapperLegendMsg
setWrapperLegendMsg( $msg)
Prompt the whole form to be wrapped in a "<fieldset>", with this message as its "<legend>" element.
Definition: HTMLForm.php:1607
HTMLForm\$mValidationErrorMessage
$mValidationErrorMessage
Definition: HTMLForm.php:205
HTMLForm\setAction
setAction( $action)
Set the value for the action attribute of the form.
Definition: HTMLForm.php:1911
HTMLForm\$mHeader
$mHeader
Definition: HTMLForm.php:208
HTMLForm\setTitle
setTitle( $t)
Set the title for form submission.
Definition: HTMLForm.php:1638
HTMLForm\setTableId
setTableId( $id)
Set the id of the <table> or outermost <div> element.
Definition: HTMLForm.php:1541
HTMLForm\$mMessagePrefix
$mMessagePrefix
Definition: HTMLForm.php:192
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:1074
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:1647
HTMLForm\filterDataForSubmit
filterDataForSubmit( $data)
Overload this if you want to apply special filtration routines to the form as a whole,...
Definition: HTMLForm.php:1884
HTMLForm\getMethod
getMethod()
Definition: HTMLForm.php:1669
HTMLForm\addPreText
addPreText( $msg)
Add HTML to introductory message.
Definition: HTMLForm.php:801
$t
$t
Definition: testCompression.php:74
HTMLForm\getField
getField( $fieldname)
Definition: HTMLForm.php:427
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
Definition: HTMLForm.php:260
HTMLForm\addPostText
addPostText( $msg)
Add text to the end of the display.
Definition: HTMLForm.php:936
HTMLForm\wrapFieldSetSection
wrapFieldSetSection( $legend, $section, $attributes, $isRoot)
Wraps the given $section into an user-visible fieldset.
Definition: HTMLForm.php:1683
HTMLForm\suppressReset
suppressReset( $suppressReset=true)
Stop a reset button being shown for this form.
Definition: HTMLForm.php:1868
HTMLForm\getFooterText
getFooterText( $section=null)
Get footer text.
Definition: HTMLForm.php:921
HTMLForm\$mFlatFields
HTMLFormField[] $mFlatFields
Definition: HTMLForm.php:195
HTMLForm\factory
static factory( $displayFormat,... $arguments)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:322
HTMLForm\getButtons
getButtons()
Get the submit and (potentially) reset buttons.
Definition: HTMLForm.php:1218
HTMLForm\addFooterText
addFooterText( $msg, $section=null)
Add footer text, inside the form.
Definition: HTMLForm.php:882
Xml\submitButton
static submitButton( $value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
Definition: Xml.php:465
HTMLForm\needsJSForHtml5FormValidation
needsJSForHtml5FormValidation()
Whether this form, with its current fields, requires the user agent to have JavaScript enabled for th...
Definition: HTMLForm.php:1978
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition: HTMLForm.php:140