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  // HTMLTextField will output the correct type="" attribute automagically.
188  // There are about four zillion other HTML5 input types, like range, but
189  // we don't use those at the moment, so no point in adding all of them.
190  'email' => HTMLTextField::class,
191  'password' => HTMLTextField::class,
192  'url' => HTMLTextField::class,
193  'title' => HTMLTitleTextField::class,
194  'user' => HTMLUserTextField::class,
195  'tagmultiselect' => HTMLTagMultiselectField::class,
196  'usersmultiselect' => HTMLUsersMultiselectField::class,
197  'titlesmultiselect' => HTMLTitlesMultiselectField::class,
198  'namespacesmultiselect' => HTMLNamespacesMultiselectField::class,
199  ];
200 
201  public $mFieldData;
202 
203  protected $mMessagePrefix;
204 
206  protected $mFlatFields = [];
207  protected $mFieldTree = [];
208  protected $mShowReset = false;
209  protected $mShowSubmit = true;
211  protected $mSubmitFlags = [ 'primary', 'progressive' ];
212  protected $mShowCancel = false;
213  protected $mCancelTarget;
214 
215  protected $mSubmitCallback;
217 
218  protected $mPre = '';
219  protected $mHeader = '';
220  protected $mFooter = '';
221  protected $mSectionHeaders = [];
222  protected $mSectionFooters = [];
223  protected $mPost = '';
224  protected $mId;
225  protected $mName;
226  protected $mTableId = '';
227 
228  protected $mSubmitID;
229  protected $mSubmitName;
230  protected $mSubmitText;
231  protected $mSubmitTooltip;
232 
233  protected $mFormIdentifier;
235  protected $mTitle;
236  protected $mMethod = 'post';
237  protected $mWasSubmitted = false;
238 
244  protected $mAction = false;
245 
251  protected $mCollapsible = false;
252 
258  protected $mCollapsed = false;
259 
265  protected $mAutocomplete = null;
266 
267  protected $mUseMultipart = false;
272  protected $mHiddenFields = [];
277  protected $mButtons = [];
278 
279  protected $mWrapperLegend = false;
280  protected $mWrapperAttributes = [];
281 
286  protected $mTokenSalt = '';
287 
296  protected $mSubSectionBeforeFields = true;
297 
303  protected $displayFormat = 'table';
304 
310  'table',
311  'div',
312  'raw',
313  'inline',
314  ];
315 
321  'vform',
322  'ooui',
323  ];
324 
329  private $hiddenTitleAddedToForm = false;
330 
344  public static function factory(
345  $displayFormat, $descriptor, IContextSource $context, $messagePrefix = ''
346  ) {
347  switch ( $displayFormat ) {
348  case 'vform':
349  return new VFormHTMLForm( $descriptor, $context, $messagePrefix );
350  case 'ooui':
351  return new OOUIHTMLForm( $descriptor, $context, $messagePrefix );
352  default:
353  $form = new self( $descriptor, $context, $messagePrefix );
354  $form->setDisplayFormat( $displayFormat );
355  return $form;
356  }
357  }
358 
370  public function __construct(
371  $descriptor, IContextSource $context, $messagePrefix = ''
372  ) {
373  $this->setContext( $context );
374  $this->mMessagePrefix = $messagePrefix;
375 
376  // Evil hack for mobile :(
377  if (
378  !$this->getConfig()->get( MainConfigNames::HTMLFormAllowTableFormat )
379  && $this->displayFormat === 'table'
380  ) {
381  $this->displayFormat = 'div';
382  }
383 
384  $this->addFields( $descriptor );
385  }
386 
396  public function addFields( $descriptor ) {
397  $loadedDescriptor = [];
398 
399  foreach ( $descriptor as $fieldname => $info ) {
400 
401  $section = $info['section'] ?? '';
402 
403  if ( isset( $info['type'] ) && $info['type'] === 'file' ) {
404  $this->mUseMultipart = true;
405  }
406 
407  $field = static::loadInputFromParameters( $fieldname, $info, $this );
408 
409  $setSection =& $loadedDescriptor;
410  if ( $section ) {
411  foreach ( explode( '/', $section ) as $newName ) {
412  if ( !isset( $setSection[$newName] ) ) {
413  $setSection[$newName] = [];
414  }
415 
416  $setSection =& $setSection[$newName];
417  }
418  }
419 
420  $setSection[$fieldname] = $field;
421  $this->mFlatFields[$fieldname] = $field;
422  }
423 
424  $this->mFieldTree = array_merge( $this->mFieldTree, $loadedDescriptor );
425 
426  return $this;
427  }
428 
433  public function hasField( $fieldname ) {
434  return isset( $this->mFlatFields[$fieldname] );
435  }
436 
442  public function getField( $fieldname ) {
443  if ( !$this->hasField( $fieldname ) ) {
444  throw new DomainException( __METHOD__ . ': no field named ' . $fieldname );
445  }
446  return $this->mFlatFields[$fieldname];
447  }
448 
459  public function setDisplayFormat( $format ) {
460  if (
461  in_array( $format, $this->availableSubclassDisplayFormats, true ) ||
462  in_array( $this->displayFormat, $this->availableSubclassDisplayFormats, true )
463  ) {
464  throw new MWException( 'Cannot change display format after creation, ' .
465  'use HTMLForm::factory() instead' );
466  }
467 
468  if ( !in_array( $format, $this->availableDisplayFormats, true ) ) {
469  throw new MWException( 'Display format must be one of ' .
470  print_r(
471  array_merge(
472  $this->availableDisplayFormats,
473  $this->availableSubclassDisplayFormats
474  ),
475  true
476  ) );
477  }
478 
479  // Evil hack for mobile :(
480  if ( !$this->getConfig()->get( MainConfigNames::HTMLFormAllowTableFormat ) &&
481  $format === 'table' ) {
482  $format = 'div';
483  }
484 
485  $this->displayFormat = $format;
486 
487  return $this;
488  }
489 
495  public function getDisplayFormat() {
496  return $this->displayFormat;
497  }
498 
516  public static function getClassFromDescriptor( $fieldname, &$descriptor ) {
517  if ( isset( $descriptor['class'] ) ) {
518  $class = $descriptor['class'];
519  } elseif ( isset( $descriptor['type'] ) ) {
520  $class = static::$typeMappings[$descriptor['type']];
521  $descriptor['class'] = $class;
522  } else {
523  $class = null;
524  }
525 
526  if ( !$class ) {
527  throw new MWException( "Descriptor with no class for $fieldname: "
528  . print_r( $descriptor, true ) );
529  }
530 
531  return $class;
532  }
533 
546  public static function loadInputFromParameters( $fieldname, $descriptor,
547  HTMLForm $parent = null
548  ) {
549  $class = static::getClassFromDescriptor( $fieldname, $descriptor );
550 
551  $descriptor['fieldname'] = $fieldname;
552  if ( $parent ) {
553  $descriptor['parent'] = $parent;
554  }
555 
556  # @todo This will throw a fatal error whenever someone try to use
557  # 'class' to feed a CSS class instead of 'cssclass'. Would be
558  # great to avoid the fatal error and show a nice error.
559  return new $class( $descriptor );
560  }
561 
571  public function prepareForm() {
572  # Load data from the request.
573  if (
574  $this->mFormIdentifier === null ||
575  $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier
576  ) {
577  $this->loadFieldData();
578  } else {
579  $this->mFieldData = [];
580  }
581 
582  return $this;
583  }
584 
589  public function tryAuthorizedSubmit() {
590  $result = false;
591 
592  if ( $this->mFormIdentifier === null ) {
593  $identOkay = true;
594  } else {
595  $identOkay = $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier;
596  }
597 
598  $tokenOkay = false;
599  if ( $this->getMethod() !== 'post' ) {
600  $tokenOkay = true; // no session check needed
601  } elseif ( $this->getRequest()->wasPosted() ) {
602  $editToken = $this->getRequest()->getVal( 'wpEditToken' );
603  if ( $this->getUser()->isRegistered() || $editToken !== null ) {
604  // Session tokens for logged-out users have no security value.
605  // However, if the user gave one, check it in order to give a nice
606  // "session expired" error instead of "permission denied" or such.
607  $tokenOkay = $this->getUser()->matchEditToken( $editToken, $this->mTokenSalt );
608  } else {
609  $tokenOkay = true;
610  }
611  }
612 
613  if ( $tokenOkay && $identOkay ) {
614  $this->mWasSubmitted = true;
615  $result = $this->trySubmit();
616  }
617 
618  return $result;
619  }
620 
628  public function show() {
629  $this->prepareForm();
630 
631  $result = $this->tryAuthorizedSubmit();
632  if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
633  return $result;
634  }
635 
636  $this->displayForm( $result );
637 
638  return false;
639  }
640 
646  public function showAlways() {
647  $this->prepareForm();
648 
649  $result = $this->tryAuthorizedSubmit();
650 
651  $this->displayForm( $result );
652 
653  return $result;
654  }
655 
668  public function trySubmit() {
669  $valid = true;
670  $hoistedErrors = Status::newGood();
671  if ( $this->mValidationErrorMessage ) {
672  foreach ( $this->mValidationErrorMessage as $error ) {
673  $hoistedErrors->fatal( ...$error );
674  }
675  } else {
676  $hoistedErrors->fatal( 'htmlform-invalid-input' );
677  }
678 
679  $this->mWasSubmitted = true;
680 
681  # Check for cancelled submission
682  foreach ( $this->mFlatFields as $fieldname => $field ) {
683  if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
684  continue;
685  }
686  if ( $field->cancelSubmit( $this->mFieldData[$fieldname], $this->mFieldData ) ) {
687  $this->mWasSubmitted = false;
688  return false;
689  }
690  }
691 
692  # Check for validation
693  foreach ( $this->mFlatFields as $fieldname => $field ) {
694  if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
695  continue;
696  }
697  if ( $field->isDisabled( $this->mFieldData ) ) {
698  continue;
699  }
700  $res = $field->validate( $this->mFieldData[$fieldname], $this->mFieldData );
701  if ( $res !== true ) {
702  $valid = false;
703  if ( $res !== false && !$field->canDisplayErrors() ) {
704  if ( is_string( $res ) ) {
705  $hoistedErrors->fatal( 'rawmessage', $res );
706  } else {
707  $hoistedErrors->fatal( $res );
708  }
709  }
710  }
711  }
712 
713  if ( !$valid ) {
714  return $hoistedErrors;
715  }
716 
717  $callback = $this->mSubmitCallback;
718  if ( !is_callable( $callback ) ) {
719  throw new MWException( 'HTMLForm: no submit callback provided. Use ' .
720  'setSubmitCallback() to set one.' );
721  }
722 
723  $data = $this->filterDataForSubmit( $this->mFieldData );
724 
725  $res = call_user_func( $callback, $data, $this );
726  if ( $res === false ) {
727  $this->mWasSubmitted = false;
728  }
729 
730  return $res;
731  }
732 
744  public function wasSubmitted() {
745  return $this->mWasSubmitted;
746  }
747 
758  public function setSubmitCallback( $cb ) {
759  $this->mSubmitCallback = $cb;
760 
761  return $this;
762  }
763 
772  public function setValidationErrorMessage( $msg ) {
773  $this->mValidationErrorMessage = $msg;
774 
775  return $this;
776  }
777 
786  public function setIntro( $msg ) {
787  return $this->setPreHtml( $msg );
788  }
789 
798  public function setPreHtml( $html ) {
799  $this->mPre = $html;
800 
801  return $this;
802  }
803 
812  public function addPreHtml( $html ) {
813  $this->mPre .= $html;
814 
815  return $this;
816  }
817 
824  public function getPreHtml() {
825  return $this->mPre;
826  }
827 
836  public function setPreText( $msg ) {
837  return $this->setPreHtml( $msg );
838  }
839 
848  public function addPreText( $msg ) {
849  return $this->addPreHtml( $msg );
850  }
851 
859  public function getPreText() {
860  return $this->getPreHtml();
861  }
862 
872  public function addHeaderHtml( $html, $section = null ) {
873  if ( $section === null ) {
874  $this->mHeader .= $html;
875  } else {
876  if ( !isset( $this->mSectionHeaders[$section] ) ) {
877  $this->mSectionHeaders[$section] = '';
878  }
879  $this->mSectionHeaders[$section] .= $html;
880  }
881 
882  return $this;
883  }
884 
894  public function setHeaderHtml( $html, $section = null ) {
895  if ( $section === null ) {
896  $this->mHeader = $html;
897  } else {
898  $this->mSectionHeaders[$section] = $html;
899  }
900 
901  return $this;
902  }
903 
912  public function getHeaderHtml( $section = null ) {
913  if ( $section === null ) {
914  return $this->mHeader;
915  } else {
916  return $this->mSectionHeaders[$section] ?? '';
917  }
918  }
919 
929  public function addHeaderText( $msg, $section = null ) {
930  return $this->addHeaderHtml( $msg, $section );
931  }
932 
943  public function setHeaderText( $msg, $section = null ) {
944  return $this->setHeaderHtml( $msg, $section );
945  }
946 
956  public function getHeaderText( $section = null ) {
957  return $this->getHeaderHtml( $section );
958  }
959 
969  public function addFooterHtml( $html, $section = null ) {
970  if ( $section === null ) {
971  $this->mFooter .= $html;
972  } else {
973  if ( !isset( $this->mSectionFooters[$section] ) ) {
974  $this->mSectionFooters[$section] = '';
975  }
976  $this->mSectionFooters[$section] .= $html;
977  }
978 
979  return $this;
980  }
981 
991  public function setFooterHtml( $html, $section = null ) {
992  if ( $section === null ) {
993  $this->mFooter = $html;
994  } else {
995  $this->mSectionFooters[$section] = $html;
996  }
997 
998  return $this;
999  }
1000 
1008  public function getFooterHtml( $section = null ) {
1009  if ( $section === null ) {
1010  return $this->mFooter;
1011  } else {
1012  return $this->mSectionFooters[$section] ?? '';
1013  }
1014  }
1015 
1025  public function addFooterText( $msg, $section = null ) {
1026  return $this->addFooterHtml( $msg, $section );
1027  }
1028 
1039  public function setFooterText( $msg, $section = null ) {
1040  return $this->setFooterHtml( $msg, $section );
1041  }
1042 
1051  public function getFooterText( $section = null ) {
1052  return $this->getFooterHtml( $section );
1053  }
1054 
1063  public function addPostHtml( $html ) {
1064  $this->mPost .= $html;
1065 
1066  return $this;
1067  }
1068 
1077  public function setPostHtml( $html ) {
1078  $this->mPost = $html;
1079 
1080  return $this;
1081  }
1082 
1089  public function getPostHtml() {
1090  return $this->mPost;
1091  }
1092 
1101  public function addPostText( $msg ) {
1102  return $this->addPostHtml( $msg );
1103  }
1104 
1113  public function setPostText( $msg ) {
1114  return $this->setPostHtml( $msg );
1115  }
1116 
1126  public function addHiddenField( $name, $value, array $attribs = [] ) {
1127  $attribs += [ 'name' => $name ];
1128  $this->mHiddenFields[] = [ $value, $attribs ];
1129 
1130  return $this;
1131  }
1132 
1143  public function addHiddenFields( array $fields ) {
1144  foreach ( $fields as $name => $value ) {
1145  $this->mHiddenFields[] = [ $value, [ 'name' => $name ] ];
1146  }
1147 
1148  return $this;
1149  }
1150 
1174  public function addButton( $data ) {
1175  if ( !is_array( $data ) ) {
1176  $args = func_get_args();
1177  if ( count( $args ) < 2 || count( $args ) > 4 ) {
1178  throw new InvalidArgumentException(
1179  'Incorrect number of arguments for deprecated calling style'
1180  );
1181  }
1182  $data = [
1183  'name' => $args[0],
1184  'value' => $args[1],
1185  'id' => $args[2] ?? null,
1186  'attribs' => $args[3] ?? null,
1187  ];
1188  } else {
1189  if ( !isset( $data['name'] ) ) {
1190  throw new InvalidArgumentException( 'A name is required' );
1191  }
1192  if ( !isset( $data['value'] ) ) {
1193  throw new InvalidArgumentException( 'A value is required' );
1194  }
1195  }
1196  $this->mButtons[] = $data + [
1197  'id' => null,
1198  'attribs' => null,
1199  'flags' => null,
1200  'framed' => true,
1201  ];
1202 
1203  return $this;
1204  }
1205 
1215  public function setTokenSalt( $salt ) {
1216  $this->mTokenSalt = $salt;
1217 
1218  return $this;
1219  }
1220 
1235  public function displayForm( $submitResult ) {
1236  $this->getOutput()->addHTML( $this->getHTML( $submitResult ) );
1237  }
1238 
1243  private function getHiddenTitle(): string {
1244  if ( $this->hiddenTitleAddedToForm ) {
1245  return '';
1246  }
1247 
1248  $html = '';
1249  if ( $this->getMethod() === 'post' ||
1250  $this->getAction() === $this->getConfig()->get( MainConfigNames::Script )
1251  ) {
1252  $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1253  }
1254  $this->hiddenTitleAddedToForm = true;
1255  return $html;
1256  }
1257 
1268  public function getHTML( $submitResult ) {
1269  # For good measure (it is the default)
1270  $this->getOutput()->setPreventClickjacking( true );
1271  $this->getOutput()->addModules( 'mediawiki.htmlform' );
1272  $this->getOutput()->addModuleStyles( 'mediawiki.htmlform.styles' );
1273 
1274  if ( $this->mCollapsible ) {
1275  // Preload jquery.makeCollapsible for mediawiki.htmlform
1276  $this->getOutput()->addModules( 'jquery.makeCollapsible' );
1277  }
1278 
1279  $html = ''
1280  . $this->getErrorsOrWarnings( $submitResult, 'error' )
1281  . $this->getErrorsOrWarnings( $submitResult, 'warning' )
1282  . $this->getHeaderText()
1283  . $this->getHiddenTitle()
1284  . $this->getBody()
1285  . $this->getHiddenFields()
1286  . $this->getButtons()
1287  . $this->getFooterText();
1288 
1289  $html = $this->wrapForm( $html );
1290 
1291  return '' . $this->mPre . $html . $this->mPost;
1292  }
1293 
1301  public function setCollapsibleOptions( $collapsedByDefault = false ) {
1302  $this->mCollapsible = true;
1303  $this->mCollapsed = $collapsedByDefault;
1304  return $this;
1305  }
1306 
1312  protected function getFormAttributes() {
1313  # Use multipart/form-data
1314  $encType = $this->mUseMultipart
1315  ? 'multipart/form-data'
1316  : 'application/x-www-form-urlencoded';
1317  # Attributes
1318  $attribs = [
1319  'class' => 'mw-htmlform',
1320  'action' => $this->getAction(),
1321  'method' => $this->getMethod(),
1322  'enctype' => $encType,
1323  ];
1324  if ( $this->mId ) {
1325  $attribs['id'] = $this->mId;
1326  }
1327  if ( is_string( $this->mAutocomplete ) ) {
1328  $attribs['autocomplete'] = $this->mAutocomplete;
1329  }
1330  if ( $this->mName ) {
1331  $attribs['name'] = $this->mName;
1332  }
1333  if ( $this->needsJSForHtml5FormValidation() ) {
1334  $attribs['novalidate'] = true;
1335  }
1336  return $attribs;
1337  }
1338 
1347  public function wrapForm( $html ) {
1348  # Include a <fieldset> wrapper for style, if requested.
1349  if ( $this->mWrapperLegend !== false ) {
1350  $legend = is_string( $this->mWrapperLegend ) ? $this->mWrapperLegend : false;
1351  $html = Xml::fieldset( $legend, $html, $this->mWrapperAttributes );
1352  }
1353 
1354  return Html::rawElement(
1355  'form',
1356  $this->getFormAttributes(),
1357  $html
1358  );
1359  }
1360 
1365  public function getHiddenFields() {
1366  $html = '';
1367 
1368  // add the title as a hidden file if it hasn't been added yet and if it is necessary
1369  // added for backward compatibility with the previous version of this public method
1370  $html .= $this->getHiddenTitle();
1371 
1372  if ( $this->mFormIdentifier !== null ) {
1373  $html .= Html::hidden(
1374  'wpFormIdentifier',
1375  $this->mFormIdentifier
1376  ) . "\n";
1377  }
1378  if ( $this->getMethod() === 'post' ) {
1379  $html .= Html::hidden(
1380  'wpEditToken',
1381  $this->getUser()->getEditToken( $this->mTokenSalt ),
1382  [ 'id' => 'wpEditToken' ]
1383  ) . "\n";
1384  }
1385 
1386  foreach ( $this->mHiddenFields as [ $value, $attribs ] ) {
1387  $html .= Html::hidden( $attribs['name'], $value, $attribs ) . "\n";
1388  }
1389 
1390  return $html;
1391  }
1392 
1398  public function getButtons() {
1399  $buttons = '';
1400  $useMediaWikiUIEverywhere =
1401  $this->getConfig()->get( MainConfigNames::UseMediaWikiUIEverywhere );
1402 
1403  if ( $this->mShowSubmit ) {
1404  $attribs = [];
1405 
1406  if ( isset( $this->mSubmitID ) ) {
1407  $attribs['id'] = $this->mSubmitID;
1408  }
1409 
1410  if ( isset( $this->mSubmitName ) ) {
1411  $attribs['name'] = $this->mSubmitName;
1412  }
1413 
1414  if ( isset( $this->mSubmitTooltip ) ) {
1415  $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
1416  }
1417 
1418  $attribs['class'] = [ 'mw-htmlform-submit' ];
1419 
1420  if ( $useMediaWikiUIEverywhere ) {
1421  foreach ( $this->mSubmitFlags as $flag ) {
1422  $attribs['class'][] = 'mw-ui-' . $flag;
1423  }
1424  $attribs['class'][] = 'mw-ui-button';
1425  }
1426 
1427  $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
1428  }
1429 
1430  if ( $this->mShowReset ) {
1431  $buttons .= Html::element(
1432  'input',
1433  [
1434  'type' => 'reset',
1435  'value' => $this->msg( 'htmlform-reset' )->text(),
1436  'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null,
1437  ]
1438  ) . "\n";
1439  }
1440 
1441  if ( $this->mShowCancel ) {
1442  $target = $this->getCancelTargetURL();
1443  $buttons .= Html::element(
1444  'a',
1445  [
1446  'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null,
1447  'href' => $target,
1448  ],
1449  $this->msg( 'cancel' )->text()
1450  ) . "\n";
1451  }
1452 
1453  foreach ( $this->mButtons as $button ) {
1454  $attrs = [
1455  'type' => 'submit',
1456  'name' => $button['name'],
1457  'value' => $button['value']
1458  ];
1459 
1460  if ( isset( $button['label-message'] ) ) {
1461  $label = $this->getMessage( $button['label-message'] )->parse();
1462  } elseif ( isset( $button['label'] ) ) {
1463  $label = htmlspecialchars( $button['label'] );
1464  } elseif ( isset( $button['label-raw'] ) ) {
1465  $label = $button['label-raw'];
1466  } else {
1467  $label = htmlspecialchars( $button['value'] );
1468  }
1469 
1470  // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset Always set in self::addButton
1471  if ( $button['attribs'] ) {
1472  // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset Always set in self::addButton
1473  $attrs += $button['attribs'];
1474  }
1475 
1476  if ( isset( $button['id'] ) ) {
1477  $attrs['id'] = $button['id'];
1478  }
1479 
1480  if ( $useMediaWikiUIEverywhere ) {
1481  $attrs['class'] = isset( $attrs['class'] ) ? (array)$attrs['class'] : [];
1482  $attrs['class'][] = 'mw-ui-button';
1483  }
1484 
1485  $buttons .= Html::rawElement( 'button', $attrs, $label ) . "\n";
1486  }
1487 
1488  if ( !$buttons ) {
1489  return '';
1490  }
1491 
1492  return Html::rawElement( 'span',
1493  [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n";
1494  }
1495 
1501  public function getBody() {
1502  return $this->displaySection( $this->mFieldTree, $this->mTableId );
1503  }
1504 
1514  public function getErrorsOrWarnings( $elements, $elementsType ) {
1515  if ( !in_array( $elementsType, [ 'error', 'warning' ], true ) ) {
1516  throw new DomainException( $elementsType . ' is not a valid type.' );
1517  }
1518  $elementstr = false;
1519  if ( $elements instanceof Status ) {
1520  list( $errorStatus, $warningStatus ) = $elements->splitByErrorType();
1521  $status = $elementsType === 'error' ? $errorStatus : $warningStatus;
1522  if ( $status->isGood() ) {
1523  $elementstr = '';
1524  } else {
1525  $elementstr = $status
1526  ->getMessage()
1527  ->setContext( $this )
1528  ->setInterfaceMessageFlag( true )
1529  ->parse();
1530  }
1531  } elseif ( $elementsType === 'error' ) {
1532  if ( is_array( $elements ) ) {
1533  $elementstr = $this->formatErrors( $elements );
1534  } elseif ( $elements && $elements !== true ) {
1535  $elementstr = (string)$elements;
1536  }
1537  }
1538 
1539  if ( !$elementstr ) {
1540  return '';
1541  } elseif ( $elementsType === 'error' ) {
1542  return Html::errorBox( $elementstr );
1543  } else { // $elementsType can only be 'warning'
1544  return Html::warningBox( $elementstr );
1545  }
1546  }
1547 
1555  public function formatErrors( $errors ) {
1556  $errorstr = '';
1557 
1558  foreach ( $errors as $error ) {
1559  $errorstr .= Html::rawElement(
1560  'li',
1561  [],
1562  $this->getMessage( $error )->parse()
1563  );
1564  }
1565 
1566  $errorstr = Html::rawElement( 'ul', [], $errorstr );
1567 
1568  return $errorstr;
1569  }
1570 
1578  public function setSubmitText( $t ) {
1579  $this->mSubmitText = $t;
1580 
1581  return $this;
1582  }
1583 
1590  public function setSubmitDestructive() {
1591  $this->mSubmitFlags = [ 'destructive', 'primary' ];
1592 
1593  return $this;
1594  }
1595 
1604  public function setSubmitTextMsg( $msg ) {
1605  if ( !$msg instanceof Message ) {
1606  $msg = $this->msg( $msg );
1607  }
1608  $this->setSubmitText( $msg->text() );
1609 
1610  return $this;
1611  }
1612 
1617  public function getSubmitText() {
1618  return $this->mSubmitText ?: $this->msg( 'htmlform-submit' )->text();
1619  }
1620 
1626  public function setSubmitName( $name ) {
1627  $this->mSubmitName = $name;
1628 
1629  return $this;
1630  }
1631 
1637  public function setSubmitTooltip( $name ) {
1638  $this->mSubmitTooltip = $name;
1639 
1640  return $this;
1641  }
1642 
1651  public function setSubmitID( $t ) {
1652  $this->mSubmitID = $t;
1653 
1654  return $this;
1655  }
1656 
1672  public function setFormIdentifier( $ident ) {
1673  $this->mFormIdentifier = $ident;
1674 
1675  return $this;
1676  }
1677 
1688  public function suppressDefaultSubmit( $suppressSubmit = true ) {
1689  $this->mShowSubmit = !$suppressSubmit;
1690 
1691  return $this;
1692  }
1693 
1700  public function showCancel( $show = true ) {
1701  $this->mShowCancel = $show;
1702  return $this;
1703  }
1704 
1711  public function setCancelTarget( $target ) {
1712  if ( $target instanceof PageReference ) {
1713  $target = TitleValue::castPageToLinkTarget( $target );
1714  }
1715 
1716  $this->mCancelTarget = $target;
1717  return $this;
1718  }
1719 
1724  protected function getCancelTargetURL() {
1725  if ( is_string( $this->mCancelTarget ) ) {
1726  return $this->mCancelTarget;
1727  } else {
1728  // TODO: use a service to get the local URL for a LinkTarget, see T282283
1729  $target = Title::castFromLinkTarget( $this->mCancelTarget ) ?: Title::newMainPage();
1730  return $target->getLocalURL();
1731  }
1732  }
1733 
1743  public function setTableId( $id ) {
1744  $this->mTableId = $id;
1745 
1746  return $this;
1747  }
1748 
1754  public function setId( $id ) {
1755  $this->mId = $id;
1756 
1757  return $this;
1758  }
1759 
1764  public function setName( $name ) {
1765  $this->mName = $name;
1766 
1767  return $this;
1768  }
1769 
1781  public function setWrapperLegend( $legend ) {
1782  $this->mWrapperLegend = $legend;
1783 
1784  return $this;
1785  }
1786 
1794  public function setWrapperAttributes( $attributes ) {
1795  $this->mWrapperAttributes = $attributes;
1796 
1797  return $this;
1798  }
1799 
1809  public function setWrapperLegendMsg( $msg ) {
1810  if ( !$msg instanceof Message ) {
1811  $msg = $this->msg( $msg );
1812  }
1813  $this->setWrapperLegend( $msg->text() );
1814 
1815  return $this;
1816  }
1817 
1827  public function setMessagePrefix( $p ) {
1828  $this->mMessagePrefix = $p;
1829 
1830  return $this;
1831  }
1832 
1840  public function setTitle( $t ) {
1841  // TODO: make mTitle a PageReference when we have a better way to get URLs, see T282283.
1842  $this->mTitle = Title::castFromPageReference( $t );
1843 
1844  return $this;
1845  }
1846 
1850  public function getTitle() {
1851  return $this->mTitle ?: $this->getContext()->getTitle();
1852  }
1853 
1861  public function setMethod( $method = 'post' ) {
1862  $this->mMethod = strtolower( $method );
1863 
1864  return $this;
1865  }
1866 
1870  public function getMethod() {
1871  return $this->mMethod;
1872  }
1873 
1884  protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
1885  return Xml::fieldset( $legend, $section, $attributes ) . "\n";
1886  }
1887 
1905  public function displaySection( $fields,
1906  $sectionName = '',
1907  $fieldsetIDPrefix = '',
1908  &$hasUserVisibleFields = false
1909  ) {
1910  if ( $this->mFieldData === null ) {
1911  throw new LogicException( 'HTMLForm::displaySection() called on uninitialized field data. '
1912  . 'You probably called displayForm() without calling prepareForm() first.' );
1913  }
1914 
1915  $displayFormat = $this->getDisplayFormat();
1916 
1917  $html = [];
1918  $subsectionHtml = '';
1919  $hasLabel = false;
1920 
1921  // Conveniently, PHP method names are case-insensitive.
1922  // For grep: this can call getDiv, getRaw, getInline, getVForm, getOOUI
1923  $getFieldHtmlMethod = $displayFormat === 'table' ? 'getTableRow' : ( 'get' . $displayFormat );
1924 
1925  foreach ( $fields as $key => $value ) {
1926  if ( $value instanceof HTMLFormField ) {
1927  $v = array_key_exists( $key, $this->mFieldData )
1928  ? $this->mFieldData[$key]
1929  : $value->getDefault();
1930 
1931  $retval = $value->$getFieldHtmlMethod( $v );
1932 
1933  // check, if the form field should be added to
1934  // the output.
1935  if ( $value->hasVisibleOutput() ) {
1936  $html[] = $retval;
1937 
1938  $labelValue = trim( $value->getLabel() );
1939  if ( $labelValue !== "\u{00A0}" && $labelValue !== '&#160;' && $labelValue !== '' ) {
1940  $hasLabel = true;
1941  }
1942 
1943  $hasUserVisibleFields = true;
1944  }
1945  } elseif ( is_array( $value ) ) {
1946  $subsectionHasVisibleFields = false;
1947  $section =
1948  $this->displaySection( $value,
1949  "mw-htmlform-$key",
1950  "$fieldsetIDPrefix$key-",
1951  $subsectionHasVisibleFields );
1952  $legend = null;
1953 
1954  if ( $subsectionHasVisibleFields === true ) {
1955  // Display the section with various niceties.
1956  $hasUserVisibleFields = true;
1957 
1958  $legend = $this->getLegend( $key );
1959 
1960  $section = $this->getHeaderText( $key ) .
1961  $section .
1962  $this->getFooterText( $key );
1963 
1964  $attributes = [];
1965  if ( $fieldsetIDPrefix ) {
1966  $attributes['id'] = Sanitizer::escapeIdForAttribute( "$fieldsetIDPrefix$key" );
1967  }
1968  $subsectionHtml .= $this->wrapFieldSetSection(
1969  $legend, $section, $attributes, $fields === $this->mFieldTree
1970  );
1971  } else {
1972  // Just return the inputs, nothing fancy.
1973  $subsectionHtml .= $section;
1974  }
1975  }
1976  }
1977 
1978  $html = $this->formatSection( $html, $sectionName, $hasLabel );
1979 
1980  if ( $subsectionHtml ) {
1981  if ( $this->mSubSectionBeforeFields ) {
1982  return $subsectionHtml . "\n" . $html;
1983  } else {
1984  return $html . "\n" . $subsectionHtml;
1985  }
1986  } else {
1987  return $html;
1988  }
1989  }
1990 
1999  protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
2000  if ( !$fieldsHtml ) {
2001  // Do not generate any wrappers for empty sections. Sections may be empty if they only have
2002  // subsections, but no fields. A legend will still be added in wrapFieldSetSection().
2003  return '';
2004  }
2005 
2006  $displayFormat = $this->getDisplayFormat();
2007  $html = implode( '', $fieldsHtml );
2008 
2009  if ( $displayFormat === 'raw' ) {
2010  return $html;
2011  }
2012 
2013  $classes = [];
2014 
2015  if ( !$anyFieldHasLabel ) { // Avoid strange spacing when no labels exist
2016  $classes[] = 'mw-htmlform-nolabel';
2017  }
2018 
2019  $attribs = [ 'class' => $classes ];
2020 
2021  if ( $sectionName ) {
2022  $attribs['id'] = Sanitizer::escapeIdForAttribute( $sectionName );
2023  }
2024 
2025  if ( $displayFormat === 'table' ) {
2026  return Html::rawElement( 'table',
2027  $attribs,
2028  Html::rawElement( 'tbody', [], "\n$html\n" ) ) . "\n";
2029  } elseif ( $displayFormat === 'inline' ) {
2030  return Html::rawElement( 'span', $attribs, "\n$html\n" );
2031  } else {
2032  return Html::rawElement( 'div', $attribs, "\n$html\n" );
2033  }
2034  }
2035 
2039  public function loadData() {
2040  $this->prepareForm();
2041  }
2042 
2046  protected function loadFieldData() {
2047  $fieldData = [];
2048  $request = $this->getRequest();
2049 
2050  foreach ( $this->mFlatFields as $fieldname => $field ) {
2051  if ( $field->skipLoadData( $request ) ) {
2052  continue;
2053  }
2054  if ( $field->mParams['disabled'] ?? false ) {
2055  $fieldData[$fieldname] = $field->getDefault();
2056  } else {
2057  $fieldData[$fieldname] = $field->loadDataFromRequest( $request );
2058  }
2059  }
2060 
2061  // Reset to default for fields that are supposed to be disabled.
2062  // FIXME: Handle dependency chains, fields that a field checks on may need a reset too.
2063  foreach ( $fieldData as $name => &$value ) {
2064  $field = $this->mFlatFields[$name];
2065  if ( $field->isDisabled( $fieldData ) ) {
2066  $value = $field->getDefault();
2067  }
2068  }
2069 
2070  # Filter data.
2071  foreach ( $fieldData as $name => &$value ) {
2072  $field = $this->mFlatFields[$name];
2073  $value = $field->filter( $value, $fieldData );
2074  }
2075 
2076  $this->mFieldData = $fieldData;
2077  }
2078 
2086  public function suppressReset( $suppressReset = true ) {
2087  $this->mShowReset = !$suppressReset;
2088 
2089  return $this;
2090  }
2091 
2102  public function filterDataForSubmit( $data ) {
2103  return $data;
2104  }
2105 
2115  public function getLegend( $key ) {
2116  return $this->msg( $this->mMessagePrefix ? "{$this->mMessagePrefix}-$key" : $key )->text();
2117  }
2118 
2129  public function setAction( $action ) {
2130  $this->mAction = $action;
2131 
2132  return $this;
2133  }
2134 
2142  public function getAction() {
2143  // If an action is already provided, return it
2144  if ( $this->mAction !== false ) {
2145  return $this->mAction;
2146  }
2147 
2148  $articlePath = $this->getConfig()->get( MainConfigNames::ArticlePath );
2149  // Check whether we are in GET mode and the ArticlePath contains a "?"
2150  // meaning that getLocalURL() would return something like "index.php?title=...".
2151  // As browser remove the query string before submitting GET forms,
2152  // it means that the title would be lost. In such case use script path instead
2153  // and put title in an hidden field (see getHiddenFields()).
2154  if ( strpos( $articlePath, '?' ) !== false && $this->getMethod() === 'get' ) {
2155  return $this->getConfig()->get( MainConfigNames::Script );
2156  }
2157 
2158  return $this->getTitle()->getLocalURL();
2159  }
2160 
2171  public function setAutocomplete( $autocomplete ) {
2172  $this->mAutocomplete = $autocomplete;
2173 
2174  return $this;
2175  }
2176 
2183  protected function getMessage( $value ) {
2184  return Message::newFromSpecifier( $value )->setContext( $this );
2185  }
2186 
2196  public function needsJSForHtml5FormValidation() {
2197  foreach ( $this->mFlatFields as $fieldname => $field ) {
2198  if ( $field->needsJSForHtml5FormValidation() ) {
2199  return true;
2200  }
2201  }
2202  return false;
2203  }
2204 }
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 ...
IContextSource $context
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:2196
setSubmitCallback( $cb)
Set a callback to a function to do something with the form once it's been successfully validated.
Definition: HTMLForm.php:758
setHeaderText( $msg, $section=null)
Set header text, inside the form.
Definition: HTMLForm.php:943
$mSubmitCallback
Definition: HTMLForm.php:215
getHiddenTitle()
Get a hidden field for the title of the page if necessary (empty string otherwise)
Definition: HTMLForm.php:1243
displayForm( $submitResult)
Display the form (sending to the context's OutputPage object), with an appropriate error message or s...
Definition: HTMLForm.php:1235
$mWasSubmitted
Definition: HTMLForm.php:237
bool $hiddenTitleAddedToForm
Whether a hidden title field has been added to the form.
Definition: HTMLForm.php:329
string null $mAutocomplete
Form attribute autocomplete.
Definition: HTMLForm.php:265
bool string $mAction
Form action URL.
Definition: HTMLForm.php:244
setAction( $action)
Set the value for the action attribute of the form.
Definition: HTMLForm.php:2129
string array $mTokenSalt
Salt for the edit token.
Definition: HTMLForm.php:286
setFooterHtml( $html, $section=null)
Set footer HTML, inside the form.
Definition: HTMLForm.php:991
string[] $mSubmitFlags
Definition: HTMLForm.php:211
addPreHtml( $html)
Add HTML to introductory message.
Definition: HTMLForm.php:812
getSubmitText()
Get the text for the submit button, either customised or a default.
Definition: HTMLForm.php:1617
setMethod( $method='post')
Set the method used to submit the form.
Definition: HTMLForm.php:1861
$mValidationErrorMessage
Definition: HTMLForm.php:216
setValidationErrorMessage( $msg)
Set a message to display on a validation error.
Definition: HTMLForm.php:772
getCancelTargetURL()
Definition: HTMLForm.php:1724
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
Definition: HTMLForm.php:2183
getHeaderHtml( $section=null)
Get header HTML.
Definition: HTMLForm.php:912
addHeaderHtml( $html, $section=null)
Add HTML to the header, inside the form.
Definition: HTMLForm.php:872
setAutocomplete( $autocomplete)
Set the value for the autocomplete attribute of the form.
Definition: HTMLForm.php:2171
static loadInputFromParameters( $fieldname, $descriptor, HTMLForm $parent=null)
Initialise a new Object for the field.
Definition: HTMLForm.php:546
setSubmitName( $name)
Definition: HTMLForm.php:1626
setTitle( $t)
Set the title for form submission.
Definition: HTMLForm.php:1840
static getClassFromDescriptor( $fieldname, &$descriptor)
Get the HTMLFormField subclass for this descriptor.
Definition: HTMLForm.php:516
array $availableSubclassDisplayFormats
Available formats in which to display the form.
Definition: HTMLForm.php:320
string $displayFormat
Format in which to display form.
Definition: HTMLForm.php:303
addPostHtml( $html)
Add HTML to the end of the display.
Definition: HTMLForm.php:1063
bool $mSubSectionBeforeFields
If true, sections that contain both fields and subsections will render their subsections before their...
Definition: HTMLForm.php:296
$mUseMultipart
Definition: HTMLForm.php:267
setTableId( $id)
Set the id of the <table> or outermost <div> element.
Definition: HTMLForm.php:1743
getHTML( $submitResult)
Returns the raw HTML generated by the form.
Definition: HTMLForm.php:1268
getLegend( $key)
Get a string to go in the "<legend>" of a section fieldset.
Definition: HTMLForm.php:2115
setSubmitTextMsg( $msg)
Set the text for the submit button to a message.
Definition: HTMLForm.php:1604
wrapFieldSetSection( $legend, $section, $attributes, $isRoot)
Wraps the given $section into an user-visible fieldset.
Definition: HTMLForm.php:1884
$mWrapperLegend
Definition: HTMLForm.php:279
filterDataForSubmit( $data)
Overload this if you want to apply special filtration routines to the form as a whole,...
Definition: HTMLForm.php:2102
setWrapperLegendMsg( $msg)
Prompt the whole form to be wrapped in a "<fieldset>", with this message as its "<legend>" element.
Definition: HTMLForm.php:1809
setId( $id)
Definition: HTMLForm.php:1754
setWrapperLegend( $legend)
Prompt the whole form to be wrapped in a "<fieldset>", with this text as its "<legend>" element.
Definition: HTMLForm.php:1781
formatErrors( $errors)
Format a stack of error messages into a single HTML string.
Definition: HTMLForm.php:1555
setDisplayFormat( $format)
Set format in which to display the form.
Definition: HTMLForm.php:459
addButton( $data)
Add a button to the form.
Definition: HTMLForm.php:1174
addFooterHtml( $html, $section=null)
Add footer HTML, inside the form.
Definition: HTMLForm.php:969
setPreHtml( $html)
Set the introductory message HTML, overwriting any existing message.
Definition: HTMLForm.php:798
getPreHtml()
Get the introductory message HTML.
Definition: HTMLForm.php:824
setPostHtml( $html)
Set HTML at the end of the display.
Definition: HTMLForm.php:1077
getPreText()
Get the introductory message HTML.
Definition: HTMLForm.php:859
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:1365
setSubmitDestructive()
Identify that the submit button in the form has a destructive action.
Definition: HTMLForm.php:1590
suppressDefaultSubmit( $suppressSubmit=true)
Stop a default submit button being shown for this form.
Definition: HTMLForm.php:1688
setSubmitID( $t)
Set the id for the submit button.
Definition: HTMLForm.php:1651
getDisplayFormat()
Getter for displayFormat.
Definition: HTMLForm.php:495
$mCancelTarget
Definition: HTMLForm.php:213
getAction()
Get the value for the action attribute of the form.
Definition: HTMLForm.php:2142
show()
The here's-one-I-made-earlier option: do the submission if posted, or display the form with or withou...
Definition: HTMLForm.php:628
hasField( $fieldname)
Definition: HTMLForm.php:433
$mWrapperAttributes
Definition: HTMLForm.php:280
addFooterText( $msg, $section=null)
Add footer text, inside the form.
Definition: HTMLForm.php:1025
addPostText( $msg)
Add text to the end of the display.
Definition: HTMLForm.php:1101
$mSectionHeaders
Definition: HTMLForm.php:221
getFooterText( $section=null)
Get footer text.
Definition: HTMLForm.php:1051
addHeaderText( $msg, $section=null)
Add HTML to the header, inside the form.
Definition: HTMLForm.php:929
setWrapperAttributes( $attributes)
For internal use only.
Definition: HTMLForm.php:1794
prepareForm()
Prepare form for submission.
Definition: HTMLForm.php:571
setCollapsibleOptions( $collapsedByDefault=false)
Enable collapsible mode, and set whether the form is collapsed by default.
Definition: HTMLForm.php:1301
wasSubmitted()
Test whether the form was considered to have been submitted or not, i.e.
Definition: HTMLForm.php:744
getHeaderText( $section=null)
Get header text.
Definition: HTMLForm.php:956
$mMessagePrefix
Definition: HTMLForm.php:203
array[] $mButtons
Definition: HTMLForm.php:277
$mFormIdentifier
Definition: HTMLForm.php:233
$mSubmitTooltip
Definition: HTMLForm.php:231
tryAuthorizedSubmit()
Try submitting, with edit token check first.
Definition: HTMLForm.php:589
setSubmitTooltip( $name)
Definition: HTMLForm.php:1637
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
Definition: HTMLForm.php:1905
array[] $mHiddenFields
Definition: HTMLForm.php:272
setPreText( $msg)
Set the introductory message HTML, overwriting any existing message.
Definition: HTMLForm.php:836
bool $mCollapsible
Whether the form can be collapsed.
Definition: HTMLForm.php:251
addHiddenField( $name, $value, array $attribs=[])
Add a hidden field to the output.
Definition: HTMLForm.php:1126
$mSectionFooters
Definition: HTMLForm.php:222
setFooterText( $msg, $section=null)
Set footer text, inside the form.
Definition: HTMLForm.php:1039
setMessagePrefix( $p)
Set the prefix for various default messages.
Definition: HTMLForm.php:1827
getField( $fieldname)
Definition: HTMLForm.php:442
bool $mCollapsed
Whether the form is collapsed by default.
Definition: HTMLForm.php:258
wrapForm( $html)
Wrap the form innards in an actual "<form>" element.
Definition: HTMLForm.php:1347
getFormAttributes()
Get HTML attributes for the <form> tag.
Definition: HTMLForm.php:1312
getBody()
Get the whole body of the form.
Definition: HTMLForm.php:1501
showAlways()
Same as self::show with the difference, that the form will be added to the output,...
Definition: HTMLForm.php:646
getFooterHtml( $section=null)
Get footer HTML.
Definition: HTMLForm.php:1008
loadFieldData()
Load data of form fields from the request.
Definition: HTMLForm.php:2046
setHeaderHtml( $html, $section=null)
Set header HTML, inside the form.
Definition: HTMLForm.php:894
setTokenSalt( $salt)
Set the salt for the edit token.
Definition: HTMLForm.php:1215
__construct( $descriptor, IContextSource $context, $messagePrefix='')
Build a new HTMLForm from an array of field attributes.
Definition: HTMLForm.php:370
addPreText( $msg)
Add HTML to introductory message.
Definition: HTMLForm.php:848
setFormIdentifier( $ident)
Set an internal identifier for this form.
Definition: HTMLForm.php:1672
setName( $name)
Definition: HTMLForm.php:1764
suppressReset( $suppressReset=true)
Stop a reset button being shown for this form.
Definition: HTMLForm.php:2086
setPostText( $msg)
Set text at the end of the display.
Definition: HTMLForm.php:1113
formatSection(array $fieldsHtml, $sectionName, $anyFieldHasLabel)
Put a form section together from the individual fields' HTML, merging it and wrapping.
Definition: HTMLForm.php:1999
setCancelTarget( $target)
Sets the target where the user is redirected to after clicking cancel.
Definition: HTMLForm.php:1711
array $availableDisplayFormats
Available formats in which to display the form.
Definition: HTMLForm.php:309
showCancel( $show=true)
Show a cancel button (or prevent it).
Definition: HTMLForm.php:1700
Title null $mTitle
Definition: HTMLForm.php:235
setSubmitText( $t)
Set the text for the submit button.
Definition: HTMLForm.php:1578
setIntro( $msg)
Set the introductory message, overwriting any existing message.
Definition: HTMLForm.php:786
getButtons()
Get the submit and (potentially) reset buttons.
Definition: HTMLForm.php:1398
static factory( $displayFormat, $descriptor, IContextSource $context, $messagePrefix='')
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:344
trySubmit()
Validate all the fields, and call the submission callback function if everything is kosher.
Definition: HTMLForm.php:668
HTMLFormField[] $mFlatFields
Definition: HTMLForm.php:206
getErrorsOrWarnings( $elements, $elementsType)
Returns a formatted list of errors or warnings from the given elements.
Definition: HTMLForm.php:1514
addHiddenFields(array $fields)
Add an array of hidden fields to the output.
Definition: HTMLForm.php:1143
getPostHtml()
Get HTML at the end of the display.
Definition: HTMLForm.php:1089
addFields( $descriptor)
Add fields to the form.
Definition: HTMLForm.php:396
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:2258
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:945
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:82
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: Status.php:44
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