MediaWiki  master
HTMLForm.php
Go to the documentation of this file.
1 <?php
2 
128 class HTMLForm extends ContextSource {
129  // A mapping of 'type' inputs onto standard HTMLFormField subclasses
130  public static $typeMappings = [
131  'api' => 'HTMLApiField',
132  'text' => 'HTMLTextField',
133  'textwithbutton' => 'HTMLTextFieldWithButton',
134  'textarea' => 'HTMLTextAreaField',
135  'select' => 'HTMLSelectField',
136  'combobox' => 'HTMLComboboxField',
137  'radio' => 'HTMLRadioField',
138  'multiselect' => 'HTMLMultiSelectField',
139  'limitselect' => 'HTMLSelectLimitField',
140  'check' => 'HTMLCheckField',
141  'toggle' => 'HTMLCheckField',
142  'int' => 'HTMLIntField',
143  'float' => 'HTMLFloatField',
144  'info' => 'HTMLInfoField',
145  'selectorother' => 'HTMLSelectOrOtherField',
146  'selectandother' => 'HTMLSelectAndOtherField',
147  'namespaceselect' => 'HTMLSelectNamespace',
148  'namespaceselectwithbutton' => 'HTMLSelectNamespaceWithButton',
149  'tagfilter' => 'HTMLTagFilter',
150  'submit' => 'HTMLSubmitField',
151  'hidden' => 'HTMLHiddenField',
152  'edittools' => 'HTMLEditTools',
153  'checkmatrix' => 'HTMLCheckMatrix',
154  'cloner' => 'HTMLFormFieldCloner',
155  'autocompleteselect' => 'HTMLAutoCompleteSelectField',
156  // HTMLTextField will output the correct type="" attribute automagically.
157  // There are about four zillion other HTML5 input types, like range, but
158  // we don't use those at the moment, so no point in adding all of them.
159  'email' => 'HTMLTextField',
160  'password' => 'HTMLTextField',
161  'url' => 'HTMLTextField',
162  'title' => 'HTMLTitleTextField',
163  'user' => 'HTMLUserTextField',
164  ];
165 
166  public $mFieldData;
167 
168  protected $mMessagePrefix;
169 
171  protected $mFlatFields;
172 
173  protected $mFieldTree;
174  protected $mShowReset = false;
175  protected $mShowSubmit = true;
176  protected $mSubmitFlags = [ 'constructive', 'primary' ];
177  protected $mShowCancel = false;
178  protected $mCancelTarget;
179 
180  protected $mSubmitCallback;
182 
183  protected $mPre = '';
184  protected $mHeader = '';
185  protected $mFooter = '';
186  protected $mSectionHeaders = [];
187  protected $mSectionFooters = [];
188  protected $mPost = '';
189  protected $mId;
190  protected $mName;
191  protected $mTableId = '';
192 
193  protected $mSubmitID;
194  protected $mSubmitName;
195  protected $mSubmitText;
196  protected $mSubmitTooltip;
197 
198  protected $mFormIdentifier;
199  protected $mTitle;
200  protected $mMethod = 'post';
201  protected $mWasSubmitted = false;
202 
208  protected $mAction = false;
209 
215  protected $mAutocomplete = false;
216 
217  protected $mUseMultipart = false;
218  protected $mHiddenFields = [];
219  protected $mButtons = [];
220 
221  protected $mWrapperLegend = false;
222 
227  protected $mTokenSalt = '';
228 
236  protected $mSubSectionBeforeFields = true;
237 
243  protected $displayFormat = 'table';
244 
250  'table',
251  'div',
252  'raw',
253  'inline',
254  ];
255 
261  'vform',
262  'ooui',
263  ];
264 
272  public static function factory( $displayFormat/*, $arguments...*/ ) {
273  $arguments = func_get_args();
274  array_shift( $arguments );
275 
276  switch ( $displayFormat ) {
277  case 'vform':
278  $reflector = new ReflectionClass( 'VFormHTMLForm' );
279  return $reflector->newInstanceArgs( $arguments );
280  case 'ooui':
281  $reflector = new ReflectionClass( 'OOUIHTMLForm' );
282  return $reflector->newInstanceArgs( $arguments );
283  default:
284  $reflector = new ReflectionClass( 'HTMLForm' );
285  $form = $reflector->newInstanceArgs( $arguments );
286  $form->setDisplayFormat( $displayFormat );
287  return $form;
288  }
289  }
290 
299  public function __construct( $descriptor, /*IContextSource*/ $context = null,
300  $messagePrefix = ''
301  ) {
302  if ( $context instanceof IContextSource ) {
303  $this->setContext( $context );
304  $this->mTitle = false; // We don't need them to set a title
305  $this->mMessagePrefix = $messagePrefix;
306  } elseif ( $context === null && $messagePrefix !== '' ) {
307  $this->mMessagePrefix = $messagePrefix;
308  } elseif ( is_string( $context ) && $messagePrefix === '' ) {
309  // B/C since 1.18
310  // it's actually $messagePrefix
311  $this->mMessagePrefix = $context;
312  }
313 
314  // Evil hack for mobile :(
315  if (
316  !$this->getConfig()->get( 'HTMLFormAllowTableFormat' )
317  && $this->displayFormat === 'table'
318  ) {
319  $this->displayFormat = 'div';
320  }
321 
322  // Expand out into a tree.
323  $loadedDescriptor = [];
324  $this->mFlatFields = [];
325 
326  foreach ( $descriptor as $fieldname => $info ) {
327  $section = isset( $info['section'] )
328  ? $info['section']
329  : '';
330 
331  if ( isset( $info['type'] ) && $info['type'] === 'file' ) {
332  $this->mUseMultipart = true;
333  }
334 
335  $field = static::loadInputFromParameters( $fieldname, $info, $this );
336 
337  $setSection =& $loadedDescriptor;
338  if ( $section ) {
339  $sectionParts = explode( '/', $section );
340 
341  while ( count( $sectionParts ) ) {
342  $newName = array_shift( $sectionParts );
343 
344  if ( !isset( $setSection[$newName] ) ) {
345  $setSection[$newName] = [];
346  }
347 
348  $setSection =& $setSection[$newName];
349  }
350  }
351 
352  $setSection[$fieldname] = $field;
353  $this->mFlatFields[$fieldname] = $field;
354  }
355 
356  $this->mFieldTree = $loadedDescriptor;
357  }
358 
369  public function setDisplayFormat( $format ) {
370  if (
371  in_array( $format, $this->availableSubclassDisplayFormats, true ) ||
372  in_array( $this->displayFormat, $this->availableSubclassDisplayFormats, true )
373  ) {
374  throw new MWException( 'Cannot change display format after creation, ' .
375  'use HTMLForm::factory() instead' );
376  }
377 
378  if ( !in_array( $format, $this->availableDisplayFormats, true ) ) {
379  throw new MWException( 'Display format must be one of ' .
380  print_r( $this->availableDisplayFormats, true ) );
381  }
382 
383  // Evil hack for mobile :(
384  if ( !$this->getConfig()->get( 'HTMLFormAllowTableFormat' ) && $format === 'table' ) {
385  $format = 'div';
386  }
387 
388  $this->displayFormat = $format;
389 
390  return $this;
391  }
392 
398  public function getDisplayFormat() {
399  return $this->displayFormat;
400  }
401 
408  public function isVForm() {
409  wfDeprecated( __METHOD__, '1.25' );
410  return false;
411  }
412 
429  public static function getClassFromDescriptor( $fieldname, &$descriptor ) {
430  if ( isset( $descriptor['class'] ) ) {
431  $class = $descriptor['class'];
432  } elseif ( isset( $descriptor['type'] ) ) {
433  $class = static::$typeMappings[$descriptor['type']];
434  $descriptor['class'] = $class;
435  } else {
436  $class = null;
437  }
438 
439  if ( !$class ) {
440  throw new MWException( "Descriptor with no class for $fieldname: "
441  . print_r( $descriptor, true ) );
442  }
443 
444  return $class;
445  }
446 
457  public static function loadInputFromParameters( $fieldname, $descriptor,
458  HTMLForm $parent = null
459  ) {
460  $class = static::getClassFromDescriptor( $fieldname, $descriptor );
461 
462  $descriptor['fieldname'] = $fieldname;
463  if ( $parent ) {
464  $descriptor['parent'] = $parent;
465  }
466 
467  # @todo This will throw a fatal error whenever someone try to use
468  # 'class' to feed a CSS class instead of 'cssclass'. Would be
469  # great to avoid the fatal error and show a nice error.
470  return new $class( $descriptor );
471  }
472 
482  public function prepareForm() {
483  # Check if we have the info we need
484  if ( !$this->mTitle instanceof Title && $this->mTitle !== false ) {
485  throw new MWException( 'You must call setTitle() on an HTMLForm' );
486  }
487 
488  # Load data from the request.
489  if (
490  $this->mFormIdentifier === null ||
491  $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier
492  ) {
493  $this->loadData();
494  } else {
495  $this->mFieldData = [];
496  }
497 
498  return $this;
499  }
500 
505  public function tryAuthorizedSubmit() {
506  $result = false;
507 
508  $identOkay = false;
509  if ( $this->mFormIdentifier === null ) {
510  $identOkay = true;
511  } else {
512  $identOkay = $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier;
513  }
514 
515  $tokenOkay = false;
516  if ( $this->getMethod() !== 'post' ) {
517  $tokenOkay = true; // no session check needed
518  } elseif ( $this->getRequest()->wasPosted() ) {
519  $editToken = $this->getRequest()->getVal( 'wpEditToken' );
520  if ( $this->getUser()->isLoggedIn() || $editToken !== null ) {
521  // Session tokens for logged-out users have no security value.
522  // However, if the user gave one, check it in order to give a nice
523  // "session expired" error instead of "permission denied" or such.
524  $tokenOkay = $this->getUser()->matchEditToken( $editToken, $this->mTokenSalt );
525  } else {
526  $tokenOkay = true;
527  }
528  }
529 
530  if ( $tokenOkay && $identOkay ) {
531  $this->mWasSubmitted = true;
532  $result = $this->trySubmit();
533  }
534 
535  return $result;
536  }
537 
544  public function show() {
545  $this->prepareForm();
546 
547  $result = $this->tryAuthorizedSubmit();
548  if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
549  return $result;
550  }
551 
552  $this->displayForm( $result );
553 
554  return false;
555  }
556 
562  public function showAlways() {
563  $this->prepareForm();
564 
565  $result = $this->tryAuthorizedSubmit();
566 
567  $this->displayForm( $result );
568 
569  return $result;
570  }
571 
583  public function trySubmit() {
584  $valid = true;
585  $hoistedErrors = [];
586  $hoistedErrors[] = isset( $this->mValidationErrorMessage )
587  ? $this->mValidationErrorMessage
588  : [ 'htmlform-invalid-input' ];
589 
590  $this->mWasSubmitted = true;
591 
592  # Check for cancelled submission
593  foreach ( $this->mFlatFields as $fieldname => $field ) {
594  if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
595  continue;
596  }
597  if ( $field->cancelSubmit( $this->mFieldData[$fieldname], $this->mFieldData ) ) {
598  $this->mWasSubmitted = false;
599  return false;
600  }
601  }
602 
603  # Check for validation
604  foreach ( $this->mFlatFields as $fieldname => $field ) {
605  if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
606  continue;
607  }
608  if ( $field->isHidden( $this->mFieldData ) ) {
609  continue;
610  }
611  $res = $field->validate( $this->mFieldData[$fieldname], $this->mFieldData );
612  if ( $res !== true ) {
613  $valid = false;
614  if ( $res !== false && !$field->canDisplayErrors() ) {
615  $hoistedErrors[] = [ 'rawmessage', $res ];
616  }
617  }
618  }
619 
620  if ( !$valid ) {
621  if ( count( $hoistedErrors ) === 1 ) {
622  $hoistedErrors = $hoistedErrors[0];
623  }
624  return $hoistedErrors;
625  }
626 
627  $callback = $this->mSubmitCallback;
628  if ( !is_callable( $callback ) ) {
629  throw new MWException( 'HTMLForm: no submit callback provided. Use ' .
630  'setSubmitCallback() to set one.' );
631  }
632 
633  $data = $this->filterDataForSubmit( $this->mFieldData );
634 
635  $res = call_user_func( $callback, $data, $this );
636  if ( $res === false ) {
637  $this->mWasSubmitted = false;
638  }
639 
640  return $res;
641  }
642 
654  public function wasSubmitted() {
655  return $this->mWasSubmitted;
656  }
657 
668  public function setSubmitCallback( $cb ) {
669  $this->mSubmitCallback = $cb;
670 
671  return $this;
672  }
673 
682  public function setValidationErrorMessage( $msg ) {
683  $this->mValidationErrorMessage = $msg;
684 
685  return $this;
686  }
687 
695  public function setIntro( $msg ) {
696  $this->setPreText( $msg );
697 
698  return $this;
699  }
700 
709  public function setPreText( $msg ) {
710  $this->mPre = $msg;
711 
712  return $this;
713  }
714 
722  public function addPreText( $msg ) {
723  $this->mPre .= $msg;
724 
725  return $this;
726  }
727 
736  public function addHeaderText( $msg, $section = null ) {
737  if ( $section === null ) {
738  $this->mHeader .= $msg;
739  } else {
740  if ( !isset( $this->mSectionHeaders[$section] ) ) {
741  $this->mSectionHeaders[$section] = '';
742  }
743  $this->mSectionHeaders[$section] .= $msg;
744  }
745 
746  return $this;
747  }
748 
758  public function setHeaderText( $msg, $section = null ) {
759  if ( $section === null ) {
760  $this->mHeader = $msg;
761  } else {
762  $this->mSectionHeaders[$section] = $msg;
763  }
764 
765  return $this;
766  }
767 
775  public function getHeaderText( $section = null ) {
776  if ( $section === null ) {
777  return $this->mHeader;
778  } else {
779  return isset( $this->mSectionHeaders[$section] ) ? $this->mSectionHeaders[$section] : '';
780  }
781  }
782 
791  public function addFooterText( $msg, $section = null ) {
792  if ( $section === null ) {
793  $this->mFooter .= $msg;
794  } else {
795  if ( !isset( $this->mSectionFooters[$section] ) ) {
796  $this->mSectionFooters[$section] = '';
797  }
798  $this->mSectionFooters[$section] .= $msg;
799  }
800 
801  return $this;
802  }
803 
813  public function setFooterText( $msg, $section = null ) {
814  if ( $section === null ) {
815  $this->mFooter = $msg;
816  } else {
817  $this->mSectionFooters[$section] = $msg;
818  }
819 
820  return $this;
821  }
822 
830  public function getFooterText( $section = null ) {
831  if ( $section === null ) {
832  return $this->mFooter;
833  } else {
834  return isset( $this->mSectionFooters[$section] ) ? $this->mSectionFooters[$section] : '';
835  }
836  }
837 
845  public function addPostText( $msg ) {
846  $this->mPost .= $msg;
847 
848  return $this;
849  }
850 
858  public function setPostText( $msg ) {
859  $this->mPost = $msg;
860 
861  return $this;
862  }
863 
873  public function addHiddenField( $name, $value, array $attribs = [] ) {
874  $attribs += [ 'name' => $name ];
875  $this->mHiddenFields[] = [ $value, $attribs ];
876 
877  return $this;
878  }
879 
890  public function addHiddenFields( array $fields ) {
891  foreach ( $fields as $name => $value ) {
892  $this->mHiddenFields[] = [ $value, [ 'name' => $name ] ];
893  }
894 
895  return $this;
896  }
897 
922  public function addButton( $data ) {
923  if ( !is_array( $data ) ) {
924  $args = func_get_args();
925  if ( count( $args ) < 2 || count( $args ) > 4 ) {
926  throw new InvalidArgumentException(
927  'Incorrect number of arguments for deprecated calling style'
928  );
929  }
930  $data = [
931  'name' => $args[0],
932  'value' => $args[1],
933  'id' => isset( $args[2] ) ? $args[2] : null,
934  'attribs' => isset( $args[3] ) ? $args[3] : null,
935  ];
936  } else {
937  if ( !isset( $data['name'] ) ) {
938  throw new InvalidArgumentException( 'A name is required' );
939  }
940  if ( !isset( $data['value'] ) ) {
941  throw new InvalidArgumentException( 'A value is required' );
942  }
943  }
944  $this->mButtons[] = $data + [
945  'id' => null,
946  'attribs' => null,
947  'flags' => null,
948  'framed' => true,
949  ];
950 
951  return $this;
952  }
953 
963  public function setTokenSalt( $salt ) {
964  $this->mTokenSalt = $salt;
965 
966  return $this;
967  }
968 
981  public function displayForm( $submitResult ) {
982  $this->getOutput()->addHTML( $this->getHTML( $submitResult ) );
983  }
984 
992  public function getHTML( $submitResult ) {
993  # For good measure (it is the default)
994  $this->getOutput()->preventClickjacking();
995  $this->getOutput()->addModules( 'mediawiki.htmlform' );
996  $this->getOutput()->addModuleStyles( 'mediawiki.htmlform.styles' );
997 
998  $html = ''
999  . $this->getErrors( $submitResult )
1000  . $this->getHeaderText()
1001  . $this->getBody()
1002  . $this->getHiddenFields()
1003  . $this->getButtons()
1004  . $this->getFooterText();
1005 
1006  $html = $this->wrapForm( $html );
1007 
1008  return '' . $this->mPre . $html . $this->mPost;
1009  }
1010 
1015  protected function getFormAttributes() {
1016  # Use multipart/form-data
1017  $encType = $this->mUseMultipart
1018  ? 'multipart/form-data'
1019  : 'application/x-www-form-urlencoded';
1020  # Attributes
1021  $attribs = [
1022  'action' => $this->getAction(),
1023  'method' => $this->getMethod(),
1024  'enctype' => $encType,
1025  ];
1026  if ( $this->mId ) {
1027  $attribs['id'] = $this->mId;
1028  }
1029  if ( $this->mAutocomplete ) {
1030  $attribs['autocomplete'] = $this->mAutocomplete;
1031  }
1032  if ( $this->mName ) {
1033  $attribs['name'] = $this->mName;
1034  }
1035  return $attribs;
1036  }
1037 
1045  public function wrapForm( $html ) {
1046  # Include a <fieldset> wrapper for style, if requested.
1047  if ( $this->mWrapperLegend !== false ) {
1048  $legend = is_string( $this->mWrapperLegend ) ? $this->mWrapperLegend : false;
1049  $html = Xml::fieldset( $legend, $html );
1050  }
1051 
1052  return Html::rawElement(
1053  'form',
1054  $this->getFormAttributes() + [ 'class' => 'visualClear' ],
1055  $html
1056  );
1057  }
1058 
1063  public function getHiddenFields() {
1064  $html = '';
1065  if ( $this->mFormIdentifier !== null ) {
1066  $html .= Html::hidden(
1067  'wpFormIdentifier',
1068  $this->mFormIdentifier
1069  ) . "\n";
1070  }
1071  if ( $this->getMethod() === 'post' ) {
1072  $html .= Html::hidden(
1073  'wpEditToken',
1074  $this->getUser()->getEditToken( $this->mTokenSalt ),
1075  [ 'id' => 'wpEditToken' ]
1076  ) . "\n";
1077  $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1078  }
1079 
1080  $articlePath = $this->getConfig()->get( 'ArticlePath' );
1081  if ( strpos( $articlePath, '?' ) !== false && $this->getMethod() === 'get' ) {
1082  $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1083  }
1084 
1085  foreach ( $this->mHiddenFields as $data ) {
1086  list( $value, $attribs ) = $data;
1087  $html .= Html::hidden( $attribs['name'], $value, $attribs ) . "\n";
1088  }
1089 
1090  return $html;
1091  }
1092 
1097  public function getButtons() {
1098  $buttons = '';
1099  $useMediaWikiUIEverywhere = $this->getConfig()->get( 'UseMediaWikiUIEverywhere' );
1100 
1101  if ( $this->mShowSubmit ) {
1102  $attribs = [];
1103 
1104  if ( isset( $this->mSubmitID ) ) {
1105  $attribs['id'] = $this->mSubmitID;
1106  }
1107 
1108  if ( isset( $this->mSubmitName ) ) {
1109  $attribs['name'] = $this->mSubmitName;
1110  }
1111 
1112  if ( isset( $this->mSubmitTooltip ) ) {
1113  $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
1114  }
1115 
1116  $attribs['class'] = [ 'mw-htmlform-submit' ];
1117 
1118  if ( $useMediaWikiUIEverywhere ) {
1119  foreach ( $this->mSubmitFlags as $flag ) {
1120  $attribs['class'][] = 'mw-ui-' . $flag;
1121  }
1122  $attribs['class'][] = 'mw-ui-button';
1123  }
1124 
1125  $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
1126  }
1127 
1128  if ( $this->mShowReset ) {
1129  $buttons .= Html::element(
1130  'input',
1131  [
1132  'type' => 'reset',
1133  'value' => $this->msg( 'htmlform-reset' )->text(),
1134  'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null,
1135  ]
1136  ) . "\n";
1137  }
1138 
1139  if ( $this->mShowCancel ) {
1140  $target = $this->mCancelTarget ?: Title::newMainPage();
1141  if ( $target instanceof Title ) {
1142  $target = $target->getLocalURL();
1143  }
1144  $buttons .= Html::element(
1145  'a',
1146  [
1147  'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null,
1148  'href' => $target,
1149  ],
1150  $this->msg( 'cancel' )->text()
1151  ) . "\n";
1152  }
1153 
1154  // IE<8 has bugs with <button>, so we'll need to avoid them.
1155  $isBadIE = preg_match( '/MSIE [1-7]\./i', $this->getRequest()->getHeader( 'User-Agent' ) );
1156 
1157  foreach ( $this->mButtons as $button ) {
1158  $attrs = [
1159  'type' => 'submit',
1160  'name' => $button['name'],
1161  'value' => $button['value']
1162  ];
1163 
1164  if ( isset( $button['label-message'] ) ) {
1165  $label = $this->getMessage( $button['label-message'] )->parse();
1166  } elseif ( isset( $button['label'] ) ) {
1167  $label = htmlspecialchars( $button['label'] );
1168  } elseif ( isset( $button['label-raw'] ) ) {
1169  $label = $button['label-raw'];
1170  } else {
1171  $label = htmlspecialchars( $button['value'] );
1172  }
1173 
1174  if ( $button['attribs'] ) {
1175  $attrs += $button['attribs'];
1176  }
1177 
1178  if ( isset( $button['id'] ) ) {
1179  $attrs['id'] = $button['id'];
1180  }
1181 
1182  if ( $useMediaWikiUIEverywhere ) {
1183  $attrs['class'] = isset( $attrs['class'] ) ? (array)$attrs['class'] : [];
1184  $attrs['class'][] = 'mw-ui-button';
1185  }
1186 
1187  if ( $isBadIE ) {
1188  $buttons .= Html::element( 'input', $attrs ) . "\n";
1189  } else {
1190  $buttons .= Html::rawElement( 'button', $attrs, $label ) . "\n";
1191  }
1192  }
1193 
1194  if ( !$buttons ) {
1195  return '';
1196  }
1197 
1198  return Html::rawElement( 'span',
1199  [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n";
1200  }
1201 
1206  public function getBody() {
1207  return $this->displaySection( $this->mFieldTree, $this->mTableId );
1208  }
1209 
1217  public function getErrors( $errors ) {
1218  if ( $errors instanceof Status ) {
1219  if ( $errors->isOK() ) {
1220  $errorstr = '';
1221  } else {
1222  $errorstr = $this->getOutput()->parse( $errors->getWikiText() );
1223  }
1224  } elseif ( is_array( $errors ) ) {
1225  $errorstr = $this->formatErrors( $errors );
1226  } else {
1227  $errorstr = $errors;
1228  }
1229 
1230  return $errorstr
1231  ? Html::rawElement( 'div', [ 'class' => 'error' ], $errorstr )
1232  : '';
1233  }
1234 
1242  public function formatErrors( $errors ) {
1243  $errorstr = '';
1244 
1245  foreach ( $errors as $error ) {
1246  $errorstr .= Html::rawElement(
1247  'li',
1248  [],
1249  $this->getMessage( $error )->parse()
1250  );
1251  }
1252 
1253  $errorstr = Html::rawElement( 'ul', [], $errorstr );
1254 
1255  return $errorstr;
1256  }
1257 
1265  public function setSubmitText( $t ) {
1266  $this->mSubmitText = $t;
1267 
1268  return $this;
1269  }
1270 
1277  public function setSubmitDestructive() {
1278  $this->mSubmitFlags = [ 'destructive', 'primary' ];
1279 
1280  return $this;
1281  }
1282 
1289  public function setSubmitProgressive() {
1290  $this->mSubmitFlags = [ 'progressive', 'primary' ];
1291 
1292  return $this;
1293  }
1294 
1303  public function setSubmitTextMsg( $msg ) {
1304  if ( !$msg instanceof Message ) {
1305  $msg = $this->msg( $msg );
1306  }
1307  $this->setSubmitText( $msg->text() );
1308 
1309  return $this;
1310  }
1311 
1316  public function getSubmitText() {
1317  return $this->mSubmitText ?: $this->msg( 'htmlform-submit' )->text();
1318  }
1319 
1325  public function setSubmitName( $name ) {
1326  $this->mSubmitName = $name;
1327 
1328  return $this;
1329  }
1330 
1336  public function setSubmitTooltip( $name ) {
1337  $this->mSubmitTooltip = $name;
1338 
1339  return $this;
1340  }
1341 
1350  public function setSubmitID( $t ) {
1351  $this->mSubmitID = $t;
1352 
1353  return $this;
1354  }
1355 
1371  public function setFormIdentifier( $ident ) {
1372  $this->mFormIdentifier = $ident;
1373 
1374  return $this;
1375  }
1376 
1387  public function suppressDefaultSubmit( $suppressSubmit = true ) {
1388  $this->mShowSubmit = !$suppressSubmit;
1389 
1390  return $this;
1391  }
1392 
1399  public function showCancel( $show = true ) {
1400  $this->mShowCancel = $show;
1401  return $this;
1402  }
1403 
1410  public function setCancelTarget( $target ) {
1411  $this->mCancelTarget = $target;
1412  return $this;
1413  }
1414 
1424  public function setTableId( $id ) {
1425  $this->mTableId = $id;
1426 
1427  return $this;
1428  }
1429 
1435  public function setId( $id ) {
1436  $this->mId = $id;
1437 
1438  return $this;
1439  }
1440 
1445  public function setName( $name ) {
1446  $this->mName = $name;
1447 
1448  return $this;
1449  }
1450 
1462  public function setWrapperLegend( $legend ) {
1463  $this->mWrapperLegend = $legend;
1464 
1465  return $this;
1466  }
1467 
1477  public function setWrapperLegendMsg( $msg ) {
1478  if ( !$msg instanceof Message ) {
1479  $msg = $this->msg( $msg );
1480  }
1481  $this->setWrapperLegend( $msg->text() );
1482 
1483  return $this;
1484  }
1485 
1495  public function setMessagePrefix( $p ) {
1496  $this->mMessagePrefix = $p;
1497 
1498  return $this;
1499  }
1500 
1508  public function setTitle( $t ) {
1509  $this->mTitle = $t;
1510 
1511  return $this;
1512  }
1513 
1518  public function getTitle() {
1519  return $this->mTitle === false
1520  ? $this->getContext()->getTitle()
1521  : $this->mTitle;
1522  }
1523 
1531  public function setMethod( $method = 'post' ) {
1532  $this->mMethod = strtolower( $method );
1533 
1534  return $this;
1535  }
1536 
1540  public function getMethod() {
1541  return $this->mMethod;
1542  }
1543 
1552  protected function wrapFieldSetSection( $legend, $section, $attributes ) {
1553  return Xml::fieldset( $legend, $section, $attributes ) . "\n";
1554  }
1555 
1572  public function displaySection( $fields,
1573  $sectionName = '',
1574  $fieldsetIDPrefix = '',
1575  &$hasUserVisibleFields = false
1576  ) {
1577  if ( $this->mFieldData === null ) {
1578  throw new LogicException( 'HTMLForm::displaySection() called on uninitialized field data. '
1579  . 'You probably called displayForm() without calling prepareForm() first.' );
1580  }
1581 
1582  $displayFormat = $this->getDisplayFormat();
1583 
1584  $html = [];
1585  $subsectionHtml = '';
1586  $hasLabel = false;
1587 
1588  // Conveniently, PHP method names are case-insensitive.
1589  // For grep: this can call getDiv, getRaw, getInline, getVForm, getOOUI
1590  $getFieldHtmlMethod = $displayFormat === 'table' ? 'getTableRow' : ( 'get' . $displayFormat );
1591 
1592  foreach ( $fields as $key => $value ) {
1593  if ( $value instanceof HTMLFormField ) {
1594  $v = array_key_exists( $key, $this->mFieldData )
1595  ? $this->mFieldData[$key]
1596  : $value->getDefault();
1597 
1598  $retval = $value->$getFieldHtmlMethod( $v );
1599 
1600  // check, if the form field should be added to
1601  // the output.
1602  if ( $value->hasVisibleOutput() ) {
1603  $html[] = $retval;
1604 
1605  $labelValue = trim( $value->getLabel() );
1606  if ( $labelValue !== '&#160;' && $labelValue !== '' ) {
1607  $hasLabel = true;
1608  }
1609 
1610  $hasUserVisibleFields = true;
1611  }
1612  } elseif ( is_array( $value ) ) {
1613  $subsectionHasVisibleFields = false;
1614  $section =
1615  $this->displaySection( $value,
1616  "mw-htmlform-$key",
1617  "$fieldsetIDPrefix$key-",
1618  $subsectionHasVisibleFields );
1619  $legend = null;
1620 
1621  if ( $subsectionHasVisibleFields === true ) {
1622  // Display the section with various niceties.
1623  $hasUserVisibleFields = true;
1624 
1625  $legend = $this->getLegend( $key );
1626 
1627  $section = $this->getHeaderText( $key ) .
1628  $section .
1629  $this->getFooterText( $key );
1630 
1631  $attributes = [];
1632  if ( $fieldsetIDPrefix ) {
1633  $attributes['id'] = Sanitizer::escapeId( "$fieldsetIDPrefix$key" );
1634  }
1635  $subsectionHtml .= $this->wrapFieldSetSection( $legend, $section, $attributes );
1636  } else {
1637  // Just return the inputs, nothing fancy.
1638  $subsectionHtml .= $section;
1639  }
1640  }
1641  }
1642 
1643  $html = $this->formatSection( $html, $sectionName, $hasLabel );
1644 
1645  if ( $subsectionHtml ) {
1646  if ( $this->mSubSectionBeforeFields ) {
1647  return $subsectionHtml . "\n" . $html;
1648  } else {
1649  return $html . "\n" . $subsectionHtml;
1650  }
1651  } else {
1652  return $html;
1653  }
1654  }
1655 
1663  protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
1664  $displayFormat = $this->getDisplayFormat();
1665  $html = implode( '', $fieldsHtml );
1666 
1667  if ( $displayFormat === 'raw' ) {
1668  return $html;
1669  }
1670 
1671  $classes = [];
1672 
1673  if ( !$anyFieldHasLabel ) { // Avoid strange spacing when no labels exist
1674  $classes[] = 'mw-htmlform-nolabel';
1675  }
1676 
1677  $attribs = [
1678  'class' => implode( ' ', $classes ),
1679  ];
1680 
1681  if ( $sectionName ) {
1682  $attribs['id'] = Sanitizer::escapeId( $sectionName );
1683  }
1684 
1685  if ( $displayFormat === 'table' ) {
1686  return Html::rawElement( 'table',
1687  $attribs,
1688  Html::rawElement( 'tbody', [], "\n$html\n" ) ) . "\n";
1689  } elseif ( $displayFormat === 'inline' ) {
1690  return Html::rawElement( 'span', $attribs, "\n$html\n" );
1691  } else {
1692  return Html::rawElement( 'div', $attribs, "\n$html\n" );
1693  }
1694  }
1695 
1699  public function loadData() {
1700  $fieldData = [];
1701 
1702  foreach ( $this->mFlatFields as $fieldname => $field ) {
1703  $request = $this->getRequest();
1704  if ( $field->skipLoadData( $request ) ) {
1705  continue;
1706  } elseif ( !empty( $field->mParams['disabled'] ) ) {
1707  $fieldData[$fieldname] = $field->getDefault();
1708  } else {
1709  $fieldData[$fieldname] = $field->loadDataFromRequest( $request );
1710  }
1711  }
1712 
1713  # Filter data.
1714  foreach ( $fieldData as $name => &$value ) {
1715  $field = $this->mFlatFields[$name];
1716  $value = $field->filter( $value, $this->mFlatFields );
1717  }
1718 
1719  $this->mFieldData = $fieldData;
1720  }
1721 
1729  public function suppressReset( $suppressReset = true ) {
1730  $this->mShowReset = !$suppressReset;
1731 
1732  return $this;
1733  }
1734 
1744  public function filterDataForSubmit( $data ) {
1745  return $data;
1746  }
1747 
1756  public function getLegend( $key ) {
1757  return $this->msg( "{$this->mMessagePrefix}-$key" )->text();
1758  }
1759 
1770  public function setAction( $action ) {
1771  $this->mAction = $action;
1772 
1773  return $this;
1774  }
1775 
1783  public function getAction() {
1784  // If an action is alredy provided, return it
1785  if ( $this->mAction !== false ) {
1786  return $this->mAction;
1787  }
1788 
1789  $articlePath = $this->getConfig()->get( 'ArticlePath' );
1790  // Check whether we are in GET mode and the ArticlePath contains a "?"
1791  // meaning that getLocalURL() would return something like "index.php?title=...".
1792  // As browser remove the query string before submitting GET forms,
1793  // it means that the title would be lost. In such case use wfScript() instead
1794  // and put title in an hidden field (see getHiddenFields()).
1795  if ( strpos( $articlePath, '?' ) !== false && $this->getMethod() === 'get' ) {
1796  return wfScript();
1797  }
1798 
1799  return $this->getTitle()->getLocalURL();
1800  }
1801 
1812  public function setAutocomplete( $autocomplete ) {
1813  $this->mAutocomplete = $autocomplete;
1814 
1815  return $this;
1816  }
1817 
1824  protected function getMessage( $value ) {
1825  return Message::newFromSpecifier( $value )->setContext( $this );
1826  }
1827 }
HTMLFormField[] $mFlatFields
Definition: HTMLForm.php:171
getFooterText($section=null)
Get footer text.
Definition: HTMLForm.php:830
setContext(IContextSource $context)
Set the IContextSource object.
showAlways()
Same as self::show with the difference, that the form will be added to the output, no matter, if the validation was good or not.
Definition: HTMLForm.php:562
setName($name)
Definition: HTMLForm.php:1445
setTokenSalt($salt)
Set the salt for the edit token.
Definition: HTMLForm.php:963
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition: hooks.txt:1816
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
Interface for objects which can provide a MediaWiki context on request.
bool string $mAutocomplete
Form attribute autocomplete.
Definition: HTMLForm.php:215
the array() calling protocol came about after MediaWiki 1.4rc1.
static $typeMappings
Definition: HTMLForm.php:130
getHTML($submitResult)
Returns the raw HTML generated by the form.
Definition: HTMLForm.php:992
getErrors($errors)
Format and display an error message stack.
Definition: HTMLForm.php:1217
wfScript($script= 'index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
prepareForm()
Prepare form for submission.
Definition: HTMLForm.php:482
addHiddenField($name, $value, array $attribs=[])
Add a hidden field to the output.
Definition: HTMLForm.php:873
$mWasSubmitted
Definition: HTMLForm.php:201
setPreText($msg)
Set the introductory message HTML, overwriting any existing message.
Definition: HTMLForm.php:709
static newMainPage()
Create a new Title for the Main Page.
Definition: Title.php:548
$mWrapperLegend
Definition: HTMLForm.php:221
getAction()
Get the value for the action attribute of the form.
Definition: HTMLForm.php:1783
getDisplayFormat()
Getter for displayFormat.
Definition: HTMLForm.php:398
setId($id)
Definition: HTMLForm.php:1435
setAutocomplete($autocomplete)
Set the value for the autocomplete attribute of the form.
Definition: HTMLForm.php:1812
setMethod($method= 'post')
Set the method used to submit the form.
Definition: HTMLForm.php:1531
$mUseMultipart
Definition: HTMLForm.php:217
The Message class provides methods which fulfil two basic services:
Definition: Message.php:159
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
setSubmitName($name)
Definition: HTMLForm.php:1325
static rawElement($element, $attribs=[], $contents= '')
Returns an HTML element in a string.
Definition: Html.php:210
trySubmit()
Validate all the fields, and call the submission callback function if everything is kosher...
Definition: HTMLForm.php:583
showCancel($show=true)
Show a cancel button (or prevent it).
Definition: HTMLForm.php:1399
setSubmitTooltip($name)
Definition: HTMLForm.php:1336
__construct($descriptor, $context=null, $messagePrefix= '')
Build a new HTMLForm from an array of field attributes.
Definition: HTMLForm.php:299
static hidden($name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:749
static factory($displayFormat)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:272
$mHiddenFields
Definition: HTMLForm.php:218
Generic operation result class Has warning/error list, boolean status and arbitrary value...
Definition: Status.php:40
getMessage($value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name, or a name + parameters array) into a Message.
Definition: HTMLForm.php:1824
addHeaderText($msg, $section=null)
Add HTML to the header, inside the form.
Definition: HTMLForm.php:736
setWrapperLegendMsg($msg)
Prompt the whole form to be wrapped in a "<fieldset>", with this message as its "<legend>" element...
Definition: HTMLForm.php:1477
$value
setSubmitCallback($cb)
Set a callback to a function to do something with the form once it's been successfully validated...
Definition: HTMLForm.php:668
setCancelTarget($target)
Sets the target where the user is redirected to after clicking cancel.
Definition: HTMLForm.php:1410
setIntro($msg)
Set the introductory message, overwriting any existing message.
Definition: HTMLForm.php:695
$mSubmitCallback
Definition: HTMLForm.php:180
Represents a title within MediaWiki.
Definition: Title.php:36
setSubmitID($t)
Set the id for the submit button.
Definition: HTMLForm.php:1350
$mSubmitTooltip
Definition: HTMLForm.php:196
IContextSource $context
static tooltipAndAccesskeyAttribs($name, array $msgParams=[])
Returns the attributes for the tooltip and access key.
Definition: Linker.php:2240
static submitButton($value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
Definition: Xml.php:460
setDisplayFormat($format)
Set format in which to display the form.
Definition: HTMLForm.php:369
array $availableDisplayFormats
Available formats in which to display the form.
Definition: HTMLForm.php:249
setTitle($t)
Set the title for form submission.
Definition: HTMLForm.php:1508
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message.Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item.Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page.Return false to stop further processing of the tag $reader:XMLReader object &$pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision.Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag.Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload.Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports.&$fullInterwikiPrefix:Interwiki prefix, may contain colons.&$pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable.Can be used to lazy-load the import sources list.&$importSources:The value of $wgImportSources.Modify as necessary.See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page.$context:IContextSource object &$pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect.&$title:Title object for the current page &$request:WebRequest &$ignoreRedirect:boolean to skip redirect check &$target:Title/string of redirect target &$article:Article object 'InternalParseBeforeLinks':during Parser's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InternalParseBeforeSanitize':during Parser's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings.Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not.Return true without providing an interwiki to continue interwiki search.$prefix:interwiki prefix we are looking for.&$iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user's email has been invalidated successfully.$user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification.Callee may modify $url and $query, URL will be constructed as $url.$query &$url:URL to index.php &$query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) &$article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() &$ip:IP being check &$result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from &$allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn't match your organization.$addr:The e-mail address entered by the user &$result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user &$result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we're looking for a messages file for &$file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED!Use $magicWords in a file listed in $wgExtensionMessagesFiles instead.Use this to define synonyms of magic words depending of the language &$magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces.Do not use this hook to add namespaces.Use CanonicalNamespaces for that.&$namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED!Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead.Use to define aliases of special pages names depending of the language &$specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names.&$names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page's language links.This is called in various places to allow extensions to define the effective language links for a page.$title:The page's Title.&$links:Associative array mapping language codes to prefixed links of the form"language:title".&$linkFlags:Associative array mapping prefixed links to arrays of flags.Currently unused, but planned to provide support for marking individual language links in the UI, e.g.for featured articles. 'LanguageSelector':Hook to change the language selector available on a page.$out:The output page.$cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED!Use HtmlPageLinkRendererBegin instead.Used when generating internal and interwiki links in Linker::link(), before processing starts.Return false to skip default processing and return $ret.See documentation for Linker::link() for details on the expected meanings of parameters.$skin:the Skin object $target:the Title that the link is pointing to &$html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1814
setValidationErrorMessage($msg)
Set a message to display on a validation error.
Definition: HTMLForm.php:682
getHiddenFields()
Get the hidden fields that should go inside the form.
Definition: HTMLForm.php:1063
string array $mTokenSalt
Salt for the edit token.
Definition: HTMLForm.php:227
addHiddenFields(array $fields)
Add an array of hidden fields to the output.
Definition: HTMLForm.php:890
if($line===false) $args
Definition: cdb.php:64
bool string $mAction
Form action URL.
Definition: HTMLForm.php:208
$mValidationErrorMessage
Definition: HTMLForm.php:181
getRequest()
Get the WebRequest object.
setSubmitProgressive()
Identify that the submit button in the form has a progressive action.
Definition: HTMLForm.php:1289
addPostText($msg)
Add text to the end of the display.
Definition: HTMLForm.php:845
static fieldset($legend=false, $content=false, $attribs=[])
Shortcut for creating fieldsets.
Definition: Xml.php:578
setSubmitText($t)
Set the text for the submit button.
Definition: HTMLForm.php:1265
string $displayFormat
Format in which to display form.
Definition: HTMLForm.php:243
msg()
Get a Message object with context set Parameters are the same as wfMessage()
show()
The here's-one-I-made-earlier option: do the submission if posted, or display the form with or withou...
Definition: HTMLForm.php:544
static $mFieldData
Definition: HTMLForm.php:132
setSubmitDestructive()
Identify that the submit button in the form has a destructive action.
Definition: HTMLForm.php:1277
isVForm()
Test if displayFormat is 'vform'.
Definition: HTMLForm.php:408
setPostText($msg)
Set text at the end of the display.
Definition: HTMLForm.php:858
$res
Definition: database.txt:21
getLegend($key)
Get a string to go in the "<legend>" of a section fieldset.
Definition: HTMLForm.php:1756
getTitle()
Get the title.
Definition: HTMLForm.php:1518
getConfig()
Get the Config object.
MediaWiki exception.
Definition: MWException.php:26
getHeaderText($section=null)
Get header text.
Definition: HTMLForm.php:775
getContext()
Get the base IContextSource object.
getFormAttributes()
Get HTML attributes for the <form> tag.
Definition: HTMLForm.php:1015
setTableId($id)
Set the id of the \<table\> or outermost \<div\> element.
Definition: HTMLForm.php:1424
setSubmitTextMsg($msg)
Set the text for the submit button to a message.
Definition: HTMLForm.php:1303
wfDeprecated($function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Object handling generic submission, CSRF protection, layout and other logic for UI forms...
Definition: HTMLForm.php:128
setWrapperLegend($legend)
Prompt the whole form to be wrapped in a "<fieldset>", with this text as its "<legend>" element...
Definition: HTMLForm.php:1462
formatSection(array $fieldsHtml, $sectionName, $anyFieldHasLabel)
Put a form section together from the individual fields' HTML, merging it and wrapping.
Definition: HTMLForm.php:1663
array $availableSubclassDisplayFormats
Available formats in which to display the form.
Definition: HTMLForm.php:260
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
formatErrors($errors)
Format a stack of error messages into a single HTML string.
Definition: HTMLForm.php:1242
getSubmitText()
Get the text for the submit button, either customised or a default.
Definition: HTMLForm.php:1316
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
filterDataForSubmit($data)
Overload this if you want to apply special filtration routines to the form as a whole, after it's submitted but before it's processed.
Definition: HTMLForm.php:1744
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template $section
Definition: hooks.txt:2755
static loadInputFromParameters($fieldname, $descriptor, HTMLForm $parent=null)
Initialise a new Object for the field.
Definition: HTMLForm.php:457
setHeaderText($msg, $section=null)
Set header text, inside the form.
Definition: HTMLForm.php:758
static getClassFromDescriptor($fieldname, &$descriptor)
Get the HTMLFormField subclass for this descriptor.
Definition: HTMLForm.php:429
$mCancelTarget
Definition: HTMLForm.php:178
setFooterText($msg, $section=null)
Set footer text, inside the form.
Definition: HTMLForm.php:813
static escapeId($id, $options=[])
Given a value, escape it so that it can be used in an id attribute and return it. ...
Definition: Sanitizer.php:1169
displaySection($fields, $sectionName= '', $fieldsetIDPrefix= '', &$hasUserVisibleFields=false)
Definition: HTMLForm.php:1572
wasSubmitted()
Test whether the form was considered to have been submitted or not, i.e.
Definition: HTMLForm.php:654
$mFormIdentifier
Definition: HTMLForm.php:198
suppressDefaultSubmit($suppressSubmit=true)
Stop a default submit button being shown for this form.
Definition: HTMLForm.php:1387
displayForm($submitResult)
Display the form (sending to the context's OutputPage object), with an appropriate error message or s...
Definition: HTMLForm.php:981
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2458
$mSectionFooters
Definition: HTMLForm.php:187
The parent class to generate form fields.
loadData()
Construct the form fields from the Descriptor array.
Definition: HTMLForm.php:1699
wrapForm($html)
Wrap the form innards in an actual "<form>" element.
Definition: HTMLForm.php:1045
addPreText($msg)
Add HTML to introductory message.
Definition: HTMLForm.php:722
tryAuthorizedSubmit()
Try submitting, with edit token check first.
Definition: HTMLForm.php:505
setFormIdentifier($ident)
Set an internal identifier for this form.
Definition: HTMLForm.php:1371
addButton($data)
Add a button to the form.
Definition: HTMLForm.php:922
$mSectionHeaders
Definition: HTMLForm.php:186
setMessagePrefix($p)
Set the prefix for various default messages.
Definition: HTMLForm.php:1495
addFooterText($msg, $section=null)
Add footer text, inside the form.
Definition: HTMLForm.php:791
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Definition: hooks.txt:1816
wrapFieldSetSection($legend, $section, $attributes)
Wraps the given $section into an user-visible fieldset.
Definition: HTMLForm.php:1552
$mMessagePrefix
Definition: HTMLForm.php:168
getBody()
Get the whole body of the form.
Definition: HTMLForm.php:1206
suppressReset($suppressReset=true)
Stop a reset button being shown for this form.
Definition: HTMLForm.php:1729
isGood()
Returns whether the operation completed and didn't have any error or warnings.
Definition: Status.php:133
getButtons()
Get the submit and (potentially) reset buttons.
Definition: HTMLForm.php:1097
static element($element, $attribs=[], $contents= '')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:230
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account incomplete not yet checked for validity & $retval
Definition: hooks.txt:242
getUser()
Get the User object.
$mSubSectionBeforeFields
If true, sections that contain both fields and subsections will render their subsections before their...
Definition: HTMLForm.php:236
setAction($action)
Set the value for the action attribute of the form.
Definition: HTMLForm.php:1770
getOutput()
Get the OutputPage object.
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:310
static newFromSpecifier($value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition: Message.php:398