MediaWiki  master
HTMLForm.php
Go to the documentation of this file.
1 <?php
2 
24 use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
28 
150 class HTMLForm extends ContextSource {
151  use ProtectedHookAccessorTrait;
152 
154  public static $typeMappings = [
155  'api' => HTMLApiField::class,
156  'text' => HTMLTextField::class,
157  'textwithbutton' => HTMLTextFieldWithButton::class,
158  'textarea' => HTMLTextAreaField::class,
159  'select' => HTMLSelectField::class,
160  'combobox' => HTMLComboboxField::class,
161  'radio' => HTMLRadioField::class,
162  'multiselect' => HTMLMultiSelectField::class,
163  'limitselect' => HTMLSelectLimitField::class,
164  'check' => HTMLCheckField::class,
165  'toggle' => HTMLCheckField::class,
166  'int' => HTMLIntField::class,
167  'file' => HTMLFileField::class,
168  'float' => HTMLFloatField::class,
169  'info' => HTMLInfoField::class,
170  'selectorother' => HTMLSelectOrOtherField::class,
171  'selectandother' => HTMLSelectAndOtherField::class,
172  'namespaceselect' => HTMLSelectNamespace::class,
173  'namespaceselectwithbutton' => HTMLSelectNamespaceWithButton::class,
174  'tagfilter' => HTMLTagFilter::class,
175  'sizefilter' => HTMLSizeFilterField::class,
176  'submit' => HTMLSubmitField::class,
177  'hidden' => HTMLHiddenField::class,
178  'edittools' => HTMLEditTools::class,
179  'checkmatrix' => HTMLCheckMatrix::class,
180  'cloner' => HTMLFormFieldCloner::class,
181  'autocompleteselect' => HTMLAutoCompleteSelectField::class,
182  'language' => HTMLSelectLanguageField::class,
183  'date' => HTMLDateTimeField::class,
184  'time' => HTMLDateTimeField::class,
185  'datetime' => HTMLDateTimeField::class,
186  'expiry' => HTMLExpiryField::class,
187  'timezone' => HTMLTimezoneField::class,
188  // HTMLTextField will output the correct type="" attribute automagically.
189  // There are about four zillion other HTML5 input types, like range, but
190  // we don't use those at the moment, so no point in adding all of them.
191  'email' => HTMLTextField::class,
192  'password' => HTMLTextField::class,
193  'url' => HTMLTextField::class,
194  'title' => HTMLTitleTextField::class,
195  'user' => HTMLUserTextField::class,
196  'tagmultiselect' => HTMLTagMultiselectField::class,
197  'usersmultiselect' => HTMLUsersMultiselectField::class,
198  'titlesmultiselect' => HTMLTitlesMultiselectField::class,
199  'namespacesmultiselect' => HTMLNamespacesMultiselectField::class,
200  ];
201 
202  public $mFieldData;
203 
204  protected $mMessagePrefix;
205 
207  protected $mFlatFields = [];
208  protected $mFieldTree = [];
209  protected $mShowReset = false;
210  protected $mShowSubmit = true;
212  protected $mSubmitFlags = [ 'primary', 'progressive' ];
213  protected $mShowCancel = false;
214  protected $mCancelTarget;
215 
216  protected $mSubmitCallback;
218 
219  protected $mPre = '';
220  protected $mHeader = '';
221  protected $mFooter = '';
222  protected $mSectionHeaders = [];
223  protected $mSectionFooters = [];
224  protected $mPost = '';
225  protected $mId;
226  protected $mName;
227  protected $mTableId = '';
228 
229  protected $mSubmitID;
230  protected $mSubmitName;
231  protected $mSubmitText;
232  protected $mSubmitTooltip;
233 
234  protected $mFormIdentifier;
236  protected $mTitle;
237  protected $mMethod = 'post';
238  protected $mWasSubmitted = false;
239 
245  protected $mAction = false;
246 
252  protected $mCollapsible = false;
253 
259  protected $mCollapsed = false;
260 
266  protected $mAutocomplete = null;
267 
268  protected $mUseMultipart = false;
273  protected $mHiddenFields = [];
278  protected $mButtons = [];
279 
280  protected $mWrapperLegend = false;
281  protected $mWrapperAttributes = [];
282 
287  protected $mTokenSalt = '';
288 
297  protected $mSubSectionBeforeFields = true;
298 
304  protected $displayFormat = 'table';
305 
311  'table',
312  'div',
313  'raw',
314  'inline',
315  ];
316 
322  'vform',
323  'ooui',
324  ];
325 
330  private $hiddenTitleAddedToForm = false;
331 
345  public static function factory(
346  $displayFormat, $descriptor, IContextSource $context, $messagePrefix = ''
347  ) {
348  switch ( $displayFormat ) {
349  case 'vform':
350  return new VFormHTMLForm( $descriptor, $context, $messagePrefix );
351  case 'ooui':
352  return new OOUIHTMLForm( $descriptor, $context, $messagePrefix );
353  default:
354  $form = new self( $descriptor, $context, $messagePrefix );
355  $form->setDisplayFormat( $displayFormat );
356  return $form;
357  }
358  }
359 
371  public function __construct(
372  $descriptor, IContextSource $context, $messagePrefix = ''
373  ) {
374  $this->setContext( $context );
375  $this->mMessagePrefix = $messagePrefix;
376 
377  // Evil hack for mobile :(
378  if (
379  !$this->getConfig()->get( MainConfigNames::HTMLFormAllowTableFormat )
380  && $this->displayFormat === 'table'
381  ) {
382  $this->displayFormat = 'div';
383  }
384 
385  $this->addFields( $descriptor );
386  }
387 
397  public function addFields( $descriptor ) {
398  $loadedDescriptor = [];
399 
400  foreach ( $descriptor as $fieldname => $info ) {
401 
402  $section = $info['section'] ?? '';
403 
404  if ( isset( $info['type'] ) && $info['type'] === 'file' ) {
405  $this->mUseMultipart = true;
406  }
407 
408  $field = static::loadInputFromParameters( $fieldname, $info, $this );
409 
410  $setSection =& $loadedDescriptor;
411  if ( $section ) {
412  foreach ( explode( '/', $section ) as $newName ) {
413  if ( !isset( $setSection[$newName] ) ) {
414  $setSection[$newName] = [];
415  }
416 
417  $setSection =& $setSection[$newName];
418  }
419  }
420 
421  $setSection[$fieldname] = $field;
422  $this->mFlatFields[$fieldname] = $field;
423  }
424 
425  $this->mFieldTree = array_merge( $this->mFieldTree, $loadedDescriptor );
426 
427  return $this;
428  }
429 
434  public function hasField( $fieldname ) {
435  return isset( $this->mFlatFields[$fieldname] );
436  }
437 
443  public function getField( $fieldname ) {
444  if ( !$this->hasField( $fieldname ) ) {
445  throw new DomainException( __METHOD__ . ': no field named ' . $fieldname );
446  }
447  return $this->mFlatFields[$fieldname];
448  }
449 
460  public function setDisplayFormat( $format ) {
461  if (
462  in_array( $format, $this->availableSubclassDisplayFormats, true ) ||
463  in_array( $this->displayFormat, $this->availableSubclassDisplayFormats, true )
464  ) {
465  throw new MWException( 'Cannot change display format after creation, ' .
466  'use HTMLForm::factory() instead' );
467  }
468 
469  if ( !in_array( $format, $this->availableDisplayFormats, true ) ) {
470  throw new MWException( 'Display format must be one of ' .
471  print_r(
472  array_merge(
473  $this->availableDisplayFormats,
474  $this->availableSubclassDisplayFormats
475  ),
476  true
477  ) );
478  }
479 
480  // Evil hack for mobile :(
481  if ( !$this->getConfig()->get( MainConfigNames::HTMLFormAllowTableFormat ) &&
482  $format === 'table' ) {
483  $format = 'div';
484  }
485 
486  $this->displayFormat = $format;
487 
488  return $this;
489  }
490 
496  public function getDisplayFormat() {
497  return $this->displayFormat;
498  }
499 
517  public static function getClassFromDescriptor( $fieldname, &$descriptor ) {
518  if ( isset( $descriptor['class'] ) ) {
519  $class = $descriptor['class'];
520  } elseif ( isset( $descriptor['type'] ) ) {
521  $class = static::$typeMappings[$descriptor['type']];
522  $descriptor['class'] = $class;
523  } else {
524  $class = null;
525  }
526 
527  if ( !$class ) {
528  throw new MWException( "Descriptor with no class for $fieldname: "
529  . print_r( $descriptor, true ) );
530  }
531 
532  return $class;
533  }
534 
547  public static function loadInputFromParameters( $fieldname, $descriptor,
548  HTMLForm $parent = null
549  ) {
550  $class = static::getClassFromDescriptor( $fieldname, $descriptor );
551 
552  $descriptor['fieldname'] = $fieldname;
553  if ( $parent ) {
554  $descriptor['parent'] = $parent;
555  }
556 
557  # @todo This will throw a fatal error whenever someone try to use
558  # 'class' to feed a CSS class instead of 'cssclass'. Would be
559  # great to avoid the fatal error and show a nice error.
560  return new $class( $descriptor );
561  }
562 
572  public function prepareForm() {
573  # Load data from the request.
574  if (
575  $this->mFormIdentifier === null ||
576  $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier
577  ) {
578  $this->loadFieldData();
579  } else {
580  $this->mFieldData = [];
581  }
582 
583  return $this;
584  }
585 
590  public function tryAuthorizedSubmit() {
591  $result = false;
592 
593  if ( $this->mFormIdentifier === null ) {
594  $identOkay = true;
595  } else {
596  $identOkay = $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier;
597  }
598 
599  $tokenOkay = false;
600  if ( $this->getMethod() !== 'post' ) {
601  $tokenOkay = true; // no session check needed
602  } elseif ( $this->getRequest()->wasPosted() ) {
603  $editToken = $this->getRequest()->getVal( 'wpEditToken' );
604  if ( $this->getUser()->isRegistered() || $editToken !== null ) {
605  // Session tokens for logged-out users have no security value.
606  // However, if the user gave one, check it in order to give a nice
607  // "session expired" error instead of "permission denied" or such.
608  $tokenOkay = $this->getUser()->matchEditToken( $editToken, $this->mTokenSalt );
609  } else {
610  $tokenOkay = true;
611  }
612  }
613 
614  if ( $tokenOkay && $identOkay ) {
615  $this->mWasSubmitted = true;
616  $result = $this->trySubmit();
617  }
618 
619  return $result;
620  }
621 
629  public function show() {
630  $this->prepareForm();
631 
632  $result = $this->tryAuthorizedSubmit();
633  if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
634  return $result;
635  }
636 
637  $this->displayForm( $result );
638 
639  return false;
640  }
641 
647  public function showAlways() {
648  $this->prepareForm();
649 
650  $result = $this->tryAuthorizedSubmit();
651 
652  $this->displayForm( $result );
653 
654  return $result;
655  }
656 
669  public function trySubmit() {
670  $valid = true;
671  $hoistedErrors = Status::newGood();
672  if ( $this->mValidationErrorMessage ) {
673  foreach ( $this->mValidationErrorMessage as $error ) {
674  $hoistedErrors->fatal( ...$error );
675  }
676  } else {
677  $hoistedErrors->fatal( 'htmlform-invalid-input' );
678  }
679 
680  $this->mWasSubmitted = true;
681 
682  # Check for cancelled submission
683  foreach ( $this->mFlatFields as $fieldname => $field ) {
684  if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
685  continue;
686  }
687  if ( $field->cancelSubmit( $this->mFieldData[$fieldname], $this->mFieldData ) ) {
688  $this->mWasSubmitted = false;
689  return false;
690  }
691  }
692 
693  # Check for validation
694  foreach ( $this->mFlatFields as $fieldname => $field ) {
695  if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
696  continue;
697  }
698  if ( $field->isDisabled( $this->mFieldData ) ) {
699  continue;
700  }
701  $res = $field->validate( $this->mFieldData[$fieldname], $this->mFieldData );
702  if ( $res !== true ) {
703  $valid = false;
704  if ( $res !== false && !$field->canDisplayErrors() ) {
705  if ( is_string( $res ) ) {
706  $hoistedErrors->fatal( 'rawmessage', $res );
707  } else {
708  $hoistedErrors->fatal( $res );
709  }
710  }
711  }
712  }
713 
714  if ( !$valid ) {
715  return $hoistedErrors;
716  }
717 
718  $callback = $this->mSubmitCallback;
719  if ( !is_callable( $callback ) ) {
720  throw new MWException( 'HTMLForm: no submit callback provided. Use ' .
721  'setSubmitCallback() to set one.' );
722  }
723 
724  $data = $this->filterDataForSubmit( $this->mFieldData );
725 
726  $res = call_user_func( $callback, $data, $this );
727  if ( $res === false ) {
728  $this->mWasSubmitted = false;
729  } elseif ( $res instanceof StatusValue ) {
730  // DWIM - callbacks are not supposed to return a StatusValue but it's easy to mix up.
731  $res = Status::wrap( $res );
732  }
733 
734  return $res;
735  }
736 
748  public function wasSubmitted() {
749  return $this->mWasSubmitted;
750  }
751 
762  public function setSubmitCallback( $cb ) {
763  $this->mSubmitCallback = $cb;
764 
765  return $this;
766  }
767 
776  public function setValidationErrorMessage( $msg ) {
777  $this->mValidationErrorMessage = $msg;
778 
779  return $this;
780  }
781 
790  public function setIntro( $msg ) {
791  return $this->setPreHtml( $msg );
792  }
793 
802  public function setPreHtml( $html ) {
803  $this->mPre = $html;
804 
805  return $this;
806  }
807 
816  public function addPreHtml( $html ) {
817  $this->mPre .= $html;
818 
819  return $this;
820  }
821 
828  public function getPreHtml() {
829  return $this->mPre;
830  }
831 
840  public function setPreText( $msg ) {
841  return $this->setPreHtml( $msg );
842  }
843 
852  public function addPreText( $msg ) {
853  return $this->addPreHtml( $msg );
854  }
855 
863  public function getPreText() {
864  return $this->getPreHtml();
865  }
866 
876  public function addHeaderHtml( $html, $section = null ) {
877  if ( $section === null ) {
878  $this->mHeader .= $html;
879  } else {
880  if ( !isset( $this->mSectionHeaders[$section] ) ) {
881  $this->mSectionHeaders[$section] = '';
882  }
883  $this->mSectionHeaders[$section] .= $html;
884  }
885 
886  return $this;
887  }
888 
898  public function setHeaderHtml( $html, $section = null ) {
899  if ( $section === null ) {
900  $this->mHeader = $html;
901  } else {
902  $this->mSectionHeaders[$section] = $html;
903  }
904 
905  return $this;
906  }
907 
916  public function getHeaderHtml( $section = null ) {
917  if ( $section === null ) {
918  return $this->mHeader;
919  } else {
920  return $this->mSectionHeaders[$section] ?? '';
921  }
922  }
923 
933  public function addHeaderText( $msg, $section = null ) {
934  return $this->addHeaderHtml( $msg, $section );
935  }
936 
947  public function setHeaderText( $msg, $section = null ) {
948  return $this->setHeaderHtml( $msg, $section );
949  }
950 
960  public function getHeaderText( $section = null ) {
961  return $this->getHeaderHtml( $section );
962  }
963 
973  public function addFooterHtml( $html, $section = null ) {
974  if ( $section === null ) {
975  $this->mFooter .= $html;
976  } else {
977  if ( !isset( $this->mSectionFooters[$section] ) ) {
978  $this->mSectionFooters[$section] = '';
979  }
980  $this->mSectionFooters[$section] .= $html;
981  }
982 
983  return $this;
984  }
985 
995  public function setFooterHtml( $html, $section = null ) {
996  if ( $section === null ) {
997  $this->mFooter = $html;
998  } else {
999  $this->mSectionFooters[$section] = $html;
1000  }
1001 
1002  return $this;
1003  }
1004 
1012  public function getFooterHtml( $section = null ) {
1013  if ( $section === null ) {
1014  return $this->mFooter;
1015  } else {
1016  return $this->mSectionFooters[$section] ?? '';
1017  }
1018  }
1019 
1029  public function addFooterText( $msg, $section = null ) {
1030  return $this->addFooterHtml( $msg, $section );
1031  }
1032 
1043  public function setFooterText( $msg, $section = null ) {
1044  return $this->setFooterHtml( $msg, $section );
1045  }
1046 
1055  public function getFooterText( $section = null ) {
1056  return $this->getFooterHtml( $section );
1057  }
1058 
1067  public function addPostHtml( $html ) {
1068  $this->mPost .= $html;
1069 
1070  return $this;
1071  }
1072 
1081  public function setPostHtml( $html ) {
1082  $this->mPost = $html;
1083 
1084  return $this;
1085  }
1086 
1093  public function getPostHtml() {
1094  return $this->mPost;
1095  }
1096 
1105  public function addPostText( $msg ) {
1106  return $this->addPostHtml( $msg );
1107  }
1108 
1117  public function setPostText( $msg ) {
1118  return $this->setPostHtml( $msg );
1119  }
1120 
1130  public function addHiddenField( $name, $value, array $attribs = [] ) {
1131  $attribs += [ 'name' => $name ];
1132  $this->mHiddenFields[] = [ $value, $attribs ];
1133 
1134  return $this;
1135  }
1136 
1147  public function addHiddenFields( array $fields ) {
1148  foreach ( $fields as $name => $value ) {
1149  $this->mHiddenFields[] = [ $value, [ 'name' => $name ] ];
1150  }
1151 
1152  return $this;
1153  }
1154 
1178  public function addButton( $data ) {
1179  if ( !is_array( $data ) ) {
1180  $args = func_get_args();
1181  if ( count( $args ) < 2 || count( $args ) > 4 ) {
1182  throw new InvalidArgumentException(
1183  'Incorrect number of arguments for deprecated calling style'
1184  );
1185  }
1186  $data = [
1187  'name' => $args[0],
1188  'value' => $args[1],
1189  'id' => $args[2] ?? null,
1190  'attribs' => $args[3] ?? null,
1191  ];
1192  } else {
1193  if ( !isset( $data['name'] ) ) {
1194  throw new InvalidArgumentException( 'A name is required' );
1195  }
1196  if ( !isset( $data['value'] ) ) {
1197  throw new InvalidArgumentException( 'A value is required' );
1198  }
1199  }
1200  $this->mButtons[] = $data + [
1201  'id' => null,
1202  'attribs' => null,
1203  'flags' => null,
1204  'framed' => true,
1205  ];
1206 
1207  return $this;
1208  }
1209 
1219  public function setTokenSalt( $salt ) {
1220  $this->mTokenSalt = $salt;
1221 
1222  return $this;
1223  }
1224 
1239  public function displayForm( $submitResult ) {
1240  $this->getOutput()->addHTML( $this->getHTML( $submitResult ) );
1241  }
1242 
1247  private function getHiddenTitle(): string {
1248  if ( $this->hiddenTitleAddedToForm ) {
1249  return '';
1250  }
1251 
1252  $html = '';
1253  if ( $this->getMethod() === 'post' ||
1254  $this->getAction() === $this->getConfig()->get( MainConfigNames::Script )
1255  ) {
1256  $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1257  }
1258  $this->hiddenTitleAddedToForm = true;
1259  return $html;
1260  }
1261 
1272  public function getHTML( $submitResult ) {
1273  # For good measure (it is the default)
1274  $this->getOutput()->setPreventClickjacking( true );
1275  $this->getOutput()->addModules( 'mediawiki.htmlform' );
1276  $this->getOutput()->addModuleStyles( 'mediawiki.htmlform.styles' );
1277 
1278  if ( $this->mCollapsible ) {
1279  // Preload jquery.makeCollapsible for mediawiki.htmlform
1280  $this->getOutput()->addModules( 'jquery.makeCollapsible' );
1281  }
1282 
1283  $html = ''
1284  . $this->getErrorsOrWarnings( $submitResult, 'error' )
1285  . $this->getErrorsOrWarnings( $submitResult, 'warning' )
1286  . $this->getHeaderText()
1287  . $this->getHiddenTitle()
1288  . $this->getBody()
1289  . $this->getHiddenFields()
1290  . $this->getButtons()
1291  . $this->getFooterText();
1292 
1293  $html = $this->wrapForm( $html );
1294 
1295  return '' . $this->mPre . $html . $this->mPost;
1296  }
1297 
1305  public function setCollapsibleOptions( $collapsedByDefault = false ) {
1306  $this->mCollapsible = true;
1307  $this->mCollapsed = $collapsedByDefault;
1308  return $this;
1309  }
1310 
1316  protected function getFormAttributes() {
1317  # Use multipart/form-data
1318  $encType = $this->mUseMultipart
1319  ? 'multipart/form-data'
1320  : 'application/x-www-form-urlencoded';
1321  # Attributes
1322  $attribs = [
1323  'class' => 'mw-htmlform',
1324  'action' => $this->getAction(),
1325  'method' => $this->getMethod(),
1326  'enctype' => $encType,
1327  ];
1328  if ( $this->mId ) {
1329  $attribs['id'] = $this->mId;
1330  }
1331  if ( is_string( $this->mAutocomplete ) ) {
1332  $attribs['autocomplete'] = $this->mAutocomplete;
1333  }
1334  if ( $this->mName ) {
1335  $attribs['name'] = $this->mName;
1336  }
1337  if ( $this->needsJSForHtml5FormValidation() ) {
1338  $attribs['novalidate'] = true;
1339  }
1340  return $attribs;
1341  }
1342 
1351  public function wrapForm( $html ) {
1352  # Include a <fieldset> wrapper for style, if requested.
1353  if ( $this->mWrapperLegend !== false ) {
1354  $legend = is_string( $this->mWrapperLegend ) ? $this->mWrapperLegend : false;
1355  $html = Xml::fieldset( $legend, $html, $this->mWrapperAttributes );
1356  }
1357 
1358  return Html::rawElement(
1359  'form',
1360  $this->getFormAttributes(),
1361  $html
1362  );
1363  }
1364 
1369  public function getHiddenFields() {
1370  $html = '';
1371 
1372  // add the title as a hidden file if it hasn't been added yet and if it is necessary
1373  // added for backward compatibility with the previous version of this public method
1374  $html .= $this->getHiddenTitle();
1375 
1376  if ( $this->mFormIdentifier !== null ) {
1377  $html .= Html::hidden(
1378  'wpFormIdentifier',
1379  $this->mFormIdentifier
1380  ) . "\n";
1381  }
1382  if ( $this->getMethod() === 'post' ) {
1383  $html .= Html::hidden(
1384  'wpEditToken',
1385  $this->getUser()->getEditToken( $this->mTokenSalt ),
1386  [ 'id' => 'wpEditToken' ]
1387  ) . "\n";
1388  }
1389 
1390  foreach ( $this->mHiddenFields as [ $value, $attribs ] ) {
1391  $html .= Html::hidden( $attribs['name'], $value, $attribs ) . "\n";
1392  }
1393 
1394  return $html;
1395  }
1396 
1402  public function getButtons() {
1403  $buttons = '';
1404  $useMediaWikiUIEverywhere =
1405  $this->getConfig()->get( MainConfigNames::UseMediaWikiUIEverywhere );
1406 
1407  if ( $this->mShowSubmit ) {
1408  $attribs = [];
1409 
1410  if ( isset( $this->mSubmitID ) ) {
1411  $attribs['id'] = $this->mSubmitID;
1412  }
1413 
1414  if ( isset( $this->mSubmitName ) ) {
1415  $attribs['name'] = $this->mSubmitName;
1416  }
1417 
1418  if ( isset( $this->mSubmitTooltip ) ) {
1419  $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
1420  }
1421 
1422  $attribs['class'] = [ 'mw-htmlform-submit' ];
1423 
1424  if ( $useMediaWikiUIEverywhere ) {
1425  foreach ( $this->mSubmitFlags as $flag ) {
1426  $attribs['class'][] = 'mw-ui-' . $flag;
1427  }
1428  $attribs['class'][] = 'mw-ui-button';
1429  }
1430 
1431  $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
1432  }
1433 
1434  if ( $this->mShowReset ) {
1435  $buttons .= Html::element(
1436  'input',
1437  [
1438  'type' => 'reset',
1439  'value' => $this->msg( 'htmlform-reset' )->text(),
1440  'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null,
1441  ]
1442  ) . "\n";
1443  }
1444 
1445  if ( $this->mShowCancel ) {
1446  $target = $this->getCancelTargetURL();
1447  $buttons .= Html::element(
1448  'a',
1449  [
1450  'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null,
1451  'href' => $target,
1452  ],
1453  $this->msg( 'cancel' )->text()
1454  ) . "\n";
1455  }
1456 
1457  foreach ( $this->mButtons as $button ) {
1458  $attrs = [
1459  'type' => 'submit',
1460  'name' => $button['name'],
1461  'value' => $button['value']
1462  ];
1463 
1464  if ( isset( $button['label-message'] ) ) {
1465  $label = $this->getMessage( $button['label-message'] )->parse();
1466  } elseif ( isset( $button['label'] ) ) {
1467  $label = htmlspecialchars( $button['label'] );
1468  } elseif ( isset( $button['label-raw'] ) ) {
1469  $label = $button['label-raw'];
1470  } else {
1471  $label = htmlspecialchars( $button['value'] );
1472  }
1473 
1474  // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset Always set in self::addButton
1475  if ( $button['attribs'] ) {
1476  // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset Always set in self::addButton
1477  $attrs += $button['attribs'];
1478  }
1479 
1480  if ( isset( $button['id'] ) ) {
1481  $attrs['id'] = $button['id'];
1482  }
1483 
1484  if ( $useMediaWikiUIEverywhere ) {
1485  $attrs['class'] = isset( $attrs['class'] ) ? (array)$attrs['class'] : [];
1486  $attrs['class'][] = 'mw-ui-button';
1487  }
1488 
1489  $buttons .= Html::rawElement( 'button', $attrs, $label ) . "\n";
1490  }
1491 
1492  if ( !$buttons ) {
1493  return '';
1494  }
1495 
1496  return Html::rawElement( 'span',
1497  [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n";
1498  }
1499 
1505  public function getBody() {
1506  return $this->displaySection( $this->mFieldTree, $this->mTableId );
1507  }
1508 
1518  public function getErrorsOrWarnings( $elements, $elementsType ) {
1519  if ( !in_array( $elementsType, [ 'error', 'warning' ], true ) ) {
1520  throw new DomainException( $elementsType . ' is not a valid type.' );
1521  }
1522  $elementstr = false;
1523  if ( $elements instanceof Status ) {
1524  list( $errorStatus, $warningStatus ) = $elements->splitByErrorType();
1525  $status = $elementsType === 'error' ? $errorStatus : $warningStatus;
1526  if ( $status->isGood() ) {
1527  $elementstr = '';
1528  } else {
1529  $elementstr = $status
1530  ->getMessage()
1531  ->setContext( $this )
1532  ->setInterfaceMessageFlag( true )
1533  ->parse();
1534  }
1535  } elseif ( $elementsType === 'error' ) {
1536  if ( is_array( $elements ) ) {
1537  $elementstr = $this->formatErrors( $elements );
1538  } elseif ( $elements && $elements !== true ) {
1539  $elementstr = (string)$elements;
1540  }
1541  }
1542 
1543  if ( !$elementstr ) {
1544  return '';
1545  } elseif ( $elementsType === 'error' ) {
1546  return Html::errorBox( $elementstr );
1547  } else { // $elementsType can only be 'warning'
1548  return Html::warningBox( $elementstr );
1549  }
1550  }
1551 
1559  public function formatErrors( $errors ) {
1560  $errorstr = '';
1561 
1562  foreach ( $errors as $error ) {
1563  $errorstr .= Html::rawElement(
1564  'li',
1565  [],
1566  $this->getMessage( $error )->parse()
1567  );
1568  }
1569 
1570  $errorstr = Html::rawElement( 'ul', [], $errorstr );
1571 
1572  return $errorstr;
1573  }
1574 
1582  public function setSubmitText( $t ) {
1583  $this->mSubmitText = $t;
1584 
1585  return $this;
1586  }
1587 
1594  public function setSubmitDestructive() {
1595  $this->mSubmitFlags = [ 'destructive', 'primary' ];
1596 
1597  return $this;
1598  }
1599 
1608  public function setSubmitTextMsg( $msg ) {
1609  if ( !$msg instanceof Message ) {
1610  $msg = $this->msg( $msg );
1611  }
1612  $this->setSubmitText( $msg->text() );
1613 
1614  return $this;
1615  }
1616 
1621  public function getSubmitText() {
1622  return $this->mSubmitText ?: $this->msg( 'htmlform-submit' )->text();
1623  }
1624 
1630  public function setSubmitName( $name ) {
1631  $this->mSubmitName = $name;
1632 
1633  return $this;
1634  }
1635 
1641  public function setSubmitTooltip( $name ) {
1642  $this->mSubmitTooltip = $name;
1643 
1644  return $this;
1645  }
1646 
1655  public function setSubmitID( $t ) {
1656  $this->mSubmitID = $t;
1657 
1658  return $this;
1659  }
1660 
1676  public function setFormIdentifier( $ident ) {
1677  $this->mFormIdentifier = $ident;
1678 
1679  return $this;
1680  }
1681 
1692  public function suppressDefaultSubmit( $suppressSubmit = true ) {
1693  $this->mShowSubmit = !$suppressSubmit;
1694 
1695  return $this;
1696  }
1697 
1704  public function showCancel( $show = true ) {
1705  $this->mShowCancel = $show;
1706  return $this;
1707  }
1708 
1715  public function setCancelTarget( $target ) {
1716  if ( $target instanceof PageReference ) {
1717  $target = TitleValue::castPageToLinkTarget( $target );
1718  }
1719 
1720  $this->mCancelTarget = $target;
1721  return $this;
1722  }
1723 
1728  protected function getCancelTargetURL() {
1729  if ( is_string( $this->mCancelTarget ) ) {
1730  return $this->mCancelTarget;
1731  } else {
1732  // TODO: use a service to get the local URL for a LinkTarget, see T282283
1733  $target = Title::castFromLinkTarget( $this->mCancelTarget ) ?: Title::newMainPage();
1734  return $target->getLocalURL();
1735  }
1736  }
1737 
1747  public function setTableId( $id ) {
1748  $this->mTableId = $id;
1749 
1750  return $this;
1751  }
1752 
1758  public function setId( $id ) {
1759  $this->mId = $id;
1760 
1761  return $this;
1762  }
1763 
1768  public function setName( $name ) {
1769  $this->mName = $name;
1770 
1771  return $this;
1772  }
1773 
1785  public function setWrapperLegend( $legend ) {
1786  $this->mWrapperLegend = $legend;
1787 
1788  return $this;
1789  }
1790 
1798  public function setWrapperAttributes( $attributes ) {
1799  $this->mWrapperAttributes = $attributes;
1800 
1801  return $this;
1802  }
1803 
1813  public function setWrapperLegendMsg( $msg ) {
1814  if ( !$msg instanceof Message ) {
1815  $msg = $this->msg( $msg );
1816  }
1817  $this->setWrapperLegend( $msg->text() );
1818 
1819  return $this;
1820  }
1821 
1831  public function setMessagePrefix( $p ) {
1832  $this->mMessagePrefix = $p;
1833 
1834  return $this;
1835  }
1836 
1844  public function setTitle( $t ) {
1845  // TODO: make mTitle a PageReference when we have a better way to get URLs, see T282283.
1846  $this->mTitle = Title::castFromPageReference( $t );
1847 
1848  return $this;
1849  }
1850 
1854  public function getTitle() {
1855  return $this->mTitle ?: $this->getContext()->getTitle();
1856  }
1857 
1865  public function setMethod( $method = 'post' ) {
1866  $this->mMethod = strtolower( $method );
1867 
1868  return $this;
1869  }
1870 
1874  public function getMethod() {
1875  return $this->mMethod;
1876  }
1877 
1888  protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
1889  return Xml::fieldset( $legend, $section, $attributes ) . "\n";
1890  }
1891 
1909  public function displaySection( $fields,
1910  $sectionName = '',
1911  $fieldsetIDPrefix = '',
1912  &$hasUserVisibleFields = false
1913  ) {
1914  if ( $this->mFieldData === null ) {
1915  throw new LogicException( 'HTMLForm::displaySection() called on uninitialized field data. '
1916  . 'You probably called displayForm() without calling prepareForm() first.' );
1917  }
1918 
1919  $displayFormat = $this->getDisplayFormat();
1920 
1921  $html = [];
1922  $subsectionHtml = '';
1923  $hasLabel = false;
1924 
1925  // Conveniently, PHP method names are case-insensitive.
1926  // For grep: this can call getDiv, getRaw, getInline, getVForm, getOOUI
1927  $getFieldHtmlMethod = $displayFormat === 'table' ? 'getTableRow' : ( 'get' . $displayFormat );
1928 
1929  foreach ( $fields as $key => $value ) {
1930  if ( $value instanceof HTMLFormField ) {
1931  $v = array_key_exists( $key, $this->mFieldData )
1932  ? $this->mFieldData[$key]
1933  : $value->getDefault();
1934 
1935  $retval = $value->$getFieldHtmlMethod( $v );
1936 
1937  // check, if the form field should be added to
1938  // the output.
1939  if ( $value->hasVisibleOutput() ) {
1940  $html[] = $retval;
1941 
1942  $labelValue = trim( $value->getLabel() );
1943  if ( $labelValue !== "\u{00A0}" && $labelValue !== '&#160;' && $labelValue !== '' ) {
1944  $hasLabel = true;
1945  }
1946 
1947  $hasUserVisibleFields = true;
1948  }
1949  } elseif ( is_array( $value ) ) {
1950  $subsectionHasVisibleFields = false;
1951  $section =
1952  $this->displaySection( $value,
1953  "mw-htmlform-$key",
1954  "$fieldsetIDPrefix$key-",
1955  $subsectionHasVisibleFields );
1956 
1957  if ( $subsectionHasVisibleFields === true ) {
1958  // Display the section with various niceties.
1959  $hasUserVisibleFields = true;
1960 
1961  $legend = $this->getLegend( $key );
1962 
1963  $section = $this->getHeaderText( $key ) .
1964  $section .
1965  $this->getFooterText( $key );
1966 
1967  $attributes = [];
1968  if ( $fieldsetIDPrefix ) {
1969  $attributes['id'] = Sanitizer::escapeIdForAttribute( "$fieldsetIDPrefix$key" );
1970  }
1971  $subsectionHtml .= $this->wrapFieldSetSection(
1972  $legend, $section, $attributes, $fields === $this->mFieldTree
1973  );
1974  } else {
1975  // Just return the inputs, nothing fancy.
1976  $subsectionHtml .= $section;
1977  }
1978  }
1979  }
1980 
1981  $html = $this->formatSection( $html, $sectionName, $hasLabel );
1982 
1983  if ( $subsectionHtml ) {
1984  if ( $this->mSubSectionBeforeFields ) {
1985  return $subsectionHtml . "\n" . $html;
1986  } else {
1987  return $html . "\n" . $subsectionHtml;
1988  }
1989  } else {
1990  return $html;
1991  }
1992  }
1993 
2002  protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
2003  if ( !$fieldsHtml ) {
2004  // Do not generate any wrappers for empty sections. Sections may be empty if they only have
2005  // subsections, but no fields. A legend will still be added in wrapFieldSetSection().
2006  return '';
2007  }
2008 
2009  $displayFormat = $this->getDisplayFormat();
2010  $html = implode( '', $fieldsHtml );
2011 
2012  if ( $displayFormat === 'raw' ) {
2013  return $html;
2014  }
2015 
2016  $classes = [];
2017 
2018  if ( !$anyFieldHasLabel ) { // Avoid strange spacing when no labels exist
2019  $classes[] = 'mw-htmlform-nolabel';
2020  }
2021 
2022  $attribs = [ 'class' => $classes ];
2023 
2024  if ( $sectionName ) {
2025  $attribs['id'] = Sanitizer::escapeIdForAttribute( $sectionName );
2026  }
2027 
2028  if ( $displayFormat === 'table' ) {
2029  return Html::rawElement( 'table',
2030  $attribs,
2031  Html::rawElement( 'tbody', [], "\n$html\n" ) ) . "\n";
2032  } elseif ( $displayFormat === 'inline' ) {
2033  return Html::rawElement( 'span', $attribs, "\n$html\n" );
2034  } else {
2035  return Html::rawElement( 'div', $attribs, "\n$html\n" );
2036  }
2037  }
2038 
2042  public function loadData() {
2043  $this->prepareForm();
2044  }
2045 
2049  protected function loadFieldData() {
2050  $fieldData = [];
2051  $request = $this->getRequest();
2052 
2053  foreach ( $this->mFlatFields as $fieldname => $field ) {
2054  if ( $field->skipLoadData( $request ) ) {
2055  continue;
2056  }
2057  if ( $field->mParams['disabled'] ?? false ) {
2058  $fieldData[$fieldname] = $field->getDefault();
2059  } else {
2060  $fieldData[$fieldname] = $field->loadDataFromRequest( $request );
2061  }
2062  }
2063 
2064  // Reset to default for fields that are supposed to be disabled.
2065  // FIXME: Handle dependency chains, fields that a field checks on may need a reset too.
2066  foreach ( $fieldData as $name => &$value ) {
2067  $field = $this->mFlatFields[$name];
2068  if ( $field->isDisabled( $fieldData ) ) {
2069  $value = $field->getDefault();
2070  }
2071  }
2072 
2073  # Filter data.
2074  foreach ( $fieldData as $name => &$value ) {
2075  $field = $this->mFlatFields[$name];
2076  $value = $field->filter( $value, $fieldData );
2077  }
2078 
2079  $this->mFieldData = $fieldData;
2080  }
2081 
2089  public function suppressReset( $suppressReset = true ) {
2090  $this->mShowReset = !$suppressReset;
2091 
2092  return $this;
2093  }
2094 
2105  public function filterDataForSubmit( $data ) {
2106  return $data;
2107  }
2108 
2118  public function getLegend( $key ) {
2119  return $this->msg( $this->mMessagePrefix ? "{$this->mMessagePrefix}-$key" : $key )->text();
2120  }
2121 
2132  public function setAction( $action ) {
2133  $this->mAction = $action;
2134 
2135  return $this;
2136  }
2137 
2145  public function getAction() {
2146  // If an action is already provided, return it
2147  if ( $this->mAction !== false ) {
2148  return $this->mAction;
2149  }
2150 
2151  $articlePath = $this->getConfig()->get( MainConfigNames::ArticlePath );
2152  // Check whether we are in GET mode and the ArticlePath contains a "?"
2153  // meaning that getLocalURL() would return something like "index.php?title=...".
2154  // As browser remove the query string before submitting GET forms,
2155  // it means that the title would be lost. In such case use script path instead
2156  // and put title in an hidden field (see getHiddenFields()).
2157  if ( strpos( $articlePath, '?' ) !== false && $this->getMethod() === 'get' ) {
2158  return $this->getConfig()->get( MainConfigNames::Script );
2159  }
2160 
2161  return $this->getTitle()->getLocalURL();
2162  }
2163 
2174  public function setAutocomplete( $autocomplete ) {
2175  $this->mAutocomplete = $autocomplete;
2176 
2177  return $this;
2178  }
2179 
2186  protected function getMessage( $value ) {
2187  return Message::newFromSpecifier( $value )->setContext( $this );
2188  }
2189 
2199  public function needsJSForHtml5FormValidation() {
2200  foreach ( $this->mFlatFields as $field ) {
2201  if ( $field->needsJSForHtml5FormValidation() ) {
2202  return true;
2203  }
2204  }
2205  return false;
2206  }
2207 }
getUser()
getContext()
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
Definition: WebStart.php:82
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
setContext(IContextSource $context)
The parent class to generate form fields.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition: HTMLForm.php:150
needsJSForHtml5FormValidation()
Whether this form, with its current fields, requires the user agent to have JavaScript enabled for th...
Definition: HTMLForm.php:2199
setSubmitCallback( $cb)
Set a callback to a function to do something with the form once it's been successfully validated.
Definition: HTMLForm.php:762
setHeaderText( $msg, $section=null)
Set header text, inside the form.
Definition: HTMLForm.php:947
$mSubmitCallback
Definition: HTMLForm.php:216
displayForm( $submitResult)
Display the form (sending to the context's OutputPage object), with an appropriate error message or s...
Definition: HTMLForm.php:1239
$mWasSubmitted
Definition: HTMLForm.php:238
string null $mAutocomplete
Form attribute autocomplete.
Definition: HTMLForm.php:266
bool string $mAction
Form action URL.
Definition: HTMLForm.php:245
setAction( $action)
Set the value for the action attribute of the form.
Definition: HTMLForm.php:2132
string array $mTokenSalt
Salt for the edit token.
Definition: HTMLForm.php:287
setFooterHtml( $html, $section=null)
Set footer HTML, inside the form.
Definition: HTMLForm.php:995
string[] $mSubmitFlags
Definition: HTMLForm.php:212
addPreHtml( $html)
Add HTML to introductory message.
Definition: HTMLForm.php:816
getSubmitText()
Get the text for the submit button, either customised or a default.
Definition: HTMLForm.php:1621
setMethod( $method='post')
Set the method used to submit the form.
Definition: HTMLForm.php:1865
$mValidationErrorMessage
Definition: HTMLForm.php:217
setValidationErrorMessage( $msg)
Set a message to display on a validation error.
Definition: HTMLForm.php:776
getCancelTargetURL()
Definition: HTMLForm.php:1728
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
Definition: HTMLForm.php:2186
getHeaderHtml( $section=null)
Get header HTML.
Definition: HTMLForm.php:916
addHeaderHtml( $html, $section=null)
Add HTML to the header, inside the form.
Definition: HTMLForm.php:876
setAutocomplete( $autocomplete)
Set the value for the autocomplete attribute of the form.
Definition: HTMLForm.php:2174
static loadInputFromParameters( $fieldname, $descriptor, HTMLForm $parent=null)
Initialise a new Object for the field.
Definition: HTMLForm.php:547
setSubmitName( $name)
Definition: HTMLForm.php:1630
setTitle( $t)
Set the title for form submission.
Definition: HTMLForm.php:1844
static getClassFromDescriptor( $fieldname, &$descriptor)
Get the HTMLFormField subclass for this descriptor.
Definition: HTMLForm.php:517
array $availableSubclassDisplayFormats
Available formats in which to display the form.
Definition: HTMLForm.php:321
string $displayFormat
Format in which to display form.
Definition: HTMLForm.php:304
addPostHtml( $html)
Add HTML to the end of the display.
Definition: HTMLForm.php:1067
bool $mSubSectionBeforeFields
If true, sections that contain both fields and subsections will render their subsections before their...
Definition: HTMLForm.php:297
$mUseMultipart
Definition: HTMLForm.php:268
setTableId( $id)
Set the id of the <table> or outermost <div> element.
Definition: HTMLForm.php:1747
getHTML( $submitResult)
Returns the raw HTML generated by the form.
Definition: HTMLForm.php:1272
getLegend( $key)
Get a string to go in the "<legend>" of a section fieldset.
Definition: HTMLForm.php:2118
setSubmitTextMsg( $msg)
Set the text for the submit button to a message.
Definition: HTMLForm.php:1608
wrapFieldSetSection( $legend, $section, $attributes, $isRoot)
Wraps the given $section into an user-visible fieldset.
Definition: HTMLForm.php:1888
$mWrapperLegend
Definition: HTMLForm.php:280
filterDataForSubmit( $data)
Overload this if you want to apply special filtration routines to the form as a whole,...
Definition: HTMLForm.php:2105
setWrapperLegendMsg( $msg)
Prompt the whole form to be wrapped in a "<fieldset>", with this message as its "<legend>" element.
Definition: HTMLForm.php:1813
setId( $id)
Definition: HTMLForm.php:1758
setWrapperLegend( $legend)
Prompt the whole form to be wrapped in a "<fieldset>", with this text as its "<legend>" element.
Definition: HTMLForm.php:1785
formatErrors( $errors)
Format a stack of error messages into a single HTML string.
Definition: HTMLForm.php:1559
setDisplayFormat( $format)
Set format in which to display the form.
Definition: HTMLForm.php:460
addButton( $data)
Add a button to the form.
Definition: HTMLForm.php:1178
addFooterHtml( $html, $section=null)
Add footer HTML, inside the form.
Definition: HTMLForm.php:973
setPreHtml( $html)
Set the introductory message HTML, overwriting any existing message.
Definition: HTMLForm.php:802
getPreHtml()
Get the introductory message HTML.
Definition: HTMLForm.php:828
setPostHtml( $html)
Set HTML at the end of the display.
Definition: HTMLForm.php:1081
getPreText()
Get the introductory message HTML.
Definition: HTMLForm.php:863
static string[] $typeMappings
A mapping of 'type' inputs onto standard HTMLFormField subclasses.
Definition: HTMLForm.php:154
getHiddenFields()
Get the hidden fields that should go inside the form.
Definition: HTMLForm.php:1369
setSubmitDestructive()
Identify that the submit button in the form has a destructive action.
Definition: HTMLForm.php:1594
suppressDefaultSubmit( $suppressSubmit=true)
Stop a default submit button being shown for this form.
Definition: HTMLForm.php:1692
setSubmitID( $t)
Set the id for the submit button.
Definition: HTMLForm.php:1655
getDisplayFormat()
Getter for displayFormat.
Definition: HTMLForm.php:496
$mCancelTarget
Definition: HTMLForm.php:214
getAction()
Get the value for the action attribute of the form.
Definition: HTMLForm.php:2145
show()
The here's-one-I-made-earlier option: do the submission if posted, or display the form with or withou...
Definition: HTMLForm.php:629
hasField( $fieldname)
Definition: HTMLForm.php:434
$mWrapperAttributes
Definition: HTMLForm.php:281
addFooterText( $msg, $section=null)
Add footer text, inside the form.
Definition: HTMLForm.php:1029
addPostText( $msg)
Add text to the end of the display.
Definition: HTMLForm.php:1105
$mSectionHeaders
Definition: HTMLForm.php:222
getFooterText( $section=null)
Get footer text.
Definition: HTMLForm.php:1055
addHeaderText( $msg, $section=null)
Add HTML to the header, inside the form.
Definition: HTMLForm.php:933
setWrapperAttributes( $attributes)
For internal use only.
Definition: HTMLForm.php:1798
prepareForm()
Prepare form for submission.
Definition: HTMLForm.php:572
setCollapsibleOptions( $collapsedByDefault=false)
Enable collapsible mode, and set whether the form is collapsed by default.
Definition: HTMLForm.php:1305
wasSubmitted()
Test whether the form was considered to have been submitted or not, i.e.
Definition: HTMLForm.php:748
getHeaderText( $section=null)
Get header text.
Definition: HTMLForm.php:960
$mMessagePrefix
Definition: HTMLForm.php:204
array[] $mButtons
Definition: HTMLForm.php:278
$mFormIdentifier
Definition: HTMLForm.php:234
$mSubmitTooltip
Definition: HTMLForm.php:232
tryAuthorizedSubmit()
Try submitting, with edit token check first.
Definition: HTMLForm.php:590
setSubmitTooltip( $name)
Definition: HTMLForm.php:1641
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
Definition: HTMLForm.php:1909
array[] $mHiddenFields
Definition: HTMLForm.php:273
setPreText( $msg)
Set the introductory message HTML, overwriting any existing message.
Definition: HTMLForm.php:840
bool $mCollapsible
Whether the form can be collapsed.
Definition: HTMLForm.php:252
addHiddenField( $name, $value, array $attribs=[])
Add a hidden field to the output.
Definition: HTMLForm.php:1130
$mSectionFooters
Definition: HTMLForm.php:223
setFooterText( $msg, $section=null)
Set footer text, inside the form.
Definition: HTMLForm.php:1043
setMessagePrefix( $p)
Set the prefix for various default messages.
Definition: HTMLForm.php:1831
getField( $fieldname)
Definition: HTMLForm.php:443
bool $mCollapsed
Whether the form is collapsed by default.
Definition: HTMLForm.php:259
wrapForm( $html)
Wrap the form innards in an actual "<form>" element.
Definition: HTMLForm.php:1351
getFormAttributes()
Get HTML attributes for the <form> tag.
Definition: HTMLForm.php:1316
getBody()
Get the whole body of the form.
Definition: HTMLForm.php:1505
showAlways()
Same as self::show with the difference, that the form will be added to the output,...
Definition: HTMLForm.php:647
getFooterHtml( $section=null)
Get footer HTML.
Definition: HTMLForm.php:1012
loadFieldData()
Load data of form fields from the request.
Definition: HTMLForm.php:2049
setHeaderHtml( $html, $section=null)
Set header HTML, inside the form.
Definition: HTMLForm.php:898
setTokenSalt( $salt)
Set the salt for the edit token.
Definition: HTMLForm.php:1219
__construct( $descriptor, IContextSource $context, $messagePrefix='')
Build a new HTMLForm from an array of field attributes.
Definition: HTMLForm.php:371
addPreText( $msg)
Add HTML to introductory message.
Definition: HTMLForm.php:852
setFormIdentifier( $ident)
Set an internal identifier for this form.
Definition: HTMLForm.php:1676
setName( $name)
Definition: HTMLForm.php:1768
suppressReset( $suppressReset=true)
Stop a reset button being shown for this form.
Definition: HTMLForm.php:2089
setPostText( $msg)
Set text at the end of the display.
Definition: HTMLForm.php:1117
formatSection(array $fieldsHtml, $sectionName, $anyFieldHasLabel)
Put a form section together from the individual fields' HTML, merging it and wrapping.
Definition: HTMLForm.php:2002
setCancelTarget( $target)
Sets the target where the user is redirected to after clicking cancel.
Definition: HTMLForm.php:1715
array $availableDisplayFormats
Available formats in which to display the form.
Definition: HTMLForm.php:310
showCancel( $show=true)
Show a cancel button (or prevent it).
Definition: HTMLForm.php:1704
Title null $mTitle
Definition: HTMLForm.php:236
setSubmitText( $t)
Set the text for the submit button.
Definition: HTMLForm.php:1582
setIntro( $msg)
Set the introductory message, overwriting any existing message.
Definition: HTMLForm.php:790
getButtons()
Get the submit and (potentially) reset buttons.
Definition: HTMLForm.php:1402
static factory( $displayFormat, $descriptor, IContextSource $context, $messagePrefix='')
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:345
trySubmit()
Validate all the fields, and call the submission callback function if everything is kosher.
Definition: HTMLForm.php:669
HTMLFormField[] $mFlatFields
Definition: HTMLForm.php:207
getErrorsOrWarnings( $elements, $elementsType)
Returns a formatted list of errors or warnings from the given elements.
Definition: HTMLForm.php:1518
addHiddenFields(array $fields)
Add an array of hidden fields to the output.
Definition: HTMLForm.php:1147
getPostHtml()
Get HTML at the end of the display.
Definition: HTMLForm.php:1093
addFields( $descriptor)
Add fields to the form.
Definition: HTMLForm.php:397
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:236
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:214
static warningBox( $html, $className='')
Return a warning box.
Definition: Html.php:775
static errorBox( $html, $heading='', $className='')
Return an error box.
Definition: Html.php:788
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:851
static tooltipAndAccesskeyAttribs( $name, array $msgParams=[], $options=null, $localizer=null, $user=null, $config=null, $relevantTitle=null)
Returns the attributes for the tooltip and access key.
Definition: Linker.php:2255
MediaWiki exception.
Definition: MWException.php:29
A class containing constants representing the names of configuration variables.
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition: Message.php:141
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition: Message.php:423
Compact stacked vertical format for forms, implemented using OOUI widgets.
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:944
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: StatusValue.php:46
isGood()
Returns whether the operation completed and didn't have any error or warnings.
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:85
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: Status.php:44
static wrap( $sv)
Succinct helper method to wrap a StatusValue.
Definition: Status.php:62
static castPageToLinkTarget(?PageReference $page)
Casts a PageReference to a LinkTarget.
Definition: TitleValue.php:118
static castFromPageReference(?PageReference $pageReference)
Return a Title for a given Reference.
Definition: Title.php:332
static newMainPage(MessageLocalizer $localizer=null)
Create a new Title for the Main Page.
Definition: Title.php:700
static castFromLinkTarget( $linkTarget)
Same as newFromLinkTarget, but if passed null, returns null.
Definition: Title.php:306
Compact stacked vertical format for forms.
static submitButton( $value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
Definition: Xml.php:469
static fieldset( $legend=false, $content=false, $attribs=[])
Shortcut for creating fieldsets.
Definition: Xml.php:628
Interface for objects which can provide a MediaWiki context on request.
Interface for objects (potentially) representing a page that can be viewable and linked to on a wiki.
if( $line===false) $args
Definition: mcc.php:124