MediaWiki  1.29.1
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  'sizefilter' => 'HTMLSizeFilterField',
151  'submit' => 'HTMLSubmitField',
152  'hidden' => 'HTMLHiddenField',
153  'edittools' => 'HTMLEditTools',
154  'checkmatrix' => 'HTMLCheckMatrix',
155  'cloner' => 'HTMLFormFieldCloner',
156  'autocompleteselect' => 'HTMLAutoCompleteSelectField',
157  'date' => 'HTMLDateTimeField',
158  'time' => 'HTMLDateTimeField',
159  'datetime' => 'HTMLDateTimeField',
160  // HTMLTextField will output the correct type="" attribute automagically.
161  // There are about four zillion other HTML5 input types, like range, but
162  // we don't use those at the moment, so no point in adding all of them.
163  'email' => 'HTMLTextField',
164  'password' => 'HTMLTextField',
165  'url' => 'HTMLTextField',
166  'title' => 'HTMLTitleTextField',
167  'user' => 'HTMLUserTextField',
168  'usersmultiselect' => 'HTMLUsersMultiselectField',
169  ];
170 
171  public $mFieldData;
172 
173  protected $mMessagePrefix;
174 
176  protected $mFlatFields;
177 
178  protected $mFieldTree;
179  protected $mShowReset = false;
180  protected $mShowSubmit = true;
181  protected $mSubmitFlags = [ 'primary', 'progressive' ];
182  protected $mShowCancel = false;
183  protected $mCancelTarget;
184 
185  protected $mSubmitCallback;
187 
188  protected $mPre = '';
189  protected $mHeader = '';
190  protected $mFooter = '';
191  protected $mSectionHeaders = [];
192  protected $mSectionFooters = [];
193  protected $mPost = '';
194  protected $mId;
195  protected $mName;
196  protected $mTableId = '';
197 
198  protected $mSubmitID;
199  protected $mSubmitName;
200  protected $mSubmitText;
201  protected $mSubmitTooltip;
202 
203  protected $mFormIdentifier;
204  protected $mTitle;
205  protected $mMethod = 'post';
206  protected $mWasSubmitted = false;
207 
213  protected $mAction = false;
214 
220  protected $mAutocomplete = false;
221 
222  protected $mUseMultipart = false;
223  protected $mHiddenFields = [];
224  protected $mButtons = [];
225 
226  protected $mWrapperLegend = false;
227 
232  protected $mTokenSalt = '';
233 
241  protected $mSubSectionBeforeFields = true;
242 
248  protected $displayFormat = 'table';
249 
255  'table',
256  'div',
257  'raw',
258  'inline',
259  ];
260 
266  'vform',
267  'ooui',
268  ];
269 
277  public static function factory( $displayFormat/*, $arguments...*/ ) {
278  $arguments = func_get_args();
279  array_shift( $arguments );
280 
281  switch ( $displayFormat ) {
282  case 'vform':
284  case 'ooui':
286  default:
289  $form->setDisplayFormat( $displayFormat );
290  return $form;
291  }
292  }
293 
302  public function __construct( $descriptor, /*IContextSource*/ $context = null,
303  $messagePrefix = ''
304  ) {
305  if ( $context instanceof IContextSource ) {
306  $this->setContext( $context );
307  $this->mTitle = false; // We don't need them to set a title
308  $this->mMessagePrefix = $messagePrefix;
309  } elseif ( $context === null && $messagePrefix !== '' ) {
310  $this->mMessagePrefix = $messagePrefix;
311  } elseif ( is_string( $context ) && $messagePrefix === '' ) {
312  // B/C since 1.18
313  // it's actually $messagePrefix
314  $this->mMessagePrefix = $context;
315  }
316 
317  // Evil hack for mobile :(
318  if (
319  !$this->getConfig()->get( 'HTMLFormAllowTableFormat' )
320  && $this->displayFormat === 'table'
321  ) {
322  $this->displayFormat = 'div';
323  }
324 
325  // Expand out into a tree.
326  $loadedDescriptor = [];
327  $this->mFlatFields = [];
328 
329  foreach ( $descriptor as $fieldname => $info ) {
330  $section = isset( $info['section'] )
331  ? $info['section']
332  : '';
333 
334  if ( isset( $info['type'] ) && $info['type'] === 'file' ) {
335  $this->mUseMultipart = true;
336  }
337 
338  $field = static::loadInputFromParameters( $fieldname, $info, $this );
339 
340  $setSection =& $loadedDescriptor;
341  if ( $section ) {
342  $sectionParts = explode( '/', $section );
343 
344  while ( count( $sectionParts ) ) {
345  $newName = array_shift( $sectionParts );
346 
347  if ( !isset( $setSection[$newName] ) ) {
348  $setSection[$newName] = [];
349  }
350 
351  $setSection =& $setSection[$newName];
352  }
353  }
354 
355  $setSection[$fieldname] = $field;
356  $this->mFlatFields[$fieldname] = $field;
357  }
358 
359  $this->mFieldTree = $loadedDescriptor;
360  }
361 
366  public function hasField( $fieldname ) {
367  return isset( $this->mFlatFields[$fieldname] );
368  }
369 
375  public function getField( $fieldname ) {
376  if ( !$this->hasField( $fieldname ) ) {
377  throw new DomainException( __METHOD__ . ': no field named ' . $fieldname );
378  }
379  return $this->mFlatFields[$fieldname];
380  }
381 
392  public function setDisplayFormat( $format ) {
393  if (
394  in_array( $format, $this->availableSubclassDisplayFormats, true ) ||
395  in_array( $this->displayFormat, $this->availableSubclassDisplayFormats, true )
396  ) {
397  throw new MWException( 'Cannot change display format after creation, ' .
398  'use HTMLForm::factory() instead' );
399  }
400 
401  if ( !in_array( $format, $this->availableDisplayFormats, true ) ) {
402  throw new MWException( 'Display format must be one of ' .
403  print_r( $this->availableDisplayFormats, true ) );
404  }
405 
406  // Evil hack for mobile :(
407  if ( !$this->getConfig()->get( 'HTMLFormAllowTableFormat' ) && $format === 'table' ) {
408  $format = 'div';
409  }
410 
411  $this->displayFormat = $format;
412 
413  return $this;
414  }
415 
421  public function getDisplayFormat() {
422  return $this->displayFormat;
423  }
424 
431  public function isVForm() {
432  wfDeprecated( __METHOD__, '1.25' );
433  return false;
434  }
435 
452  public static function getClassFromDescriptor( $fieldname, &$descriptor ) {
453  if ( isset( $descriptor['class'] ) ) {
454  $class = $descriptor['class'];
455  } elseif ( isset( $descriptor['type'] ) ) {
456  $class = static::$typeMappings[$descriptor['type']];
457  $descriptor['class'] = $class;
458  } else {
459  $class = null;
460  }
461 
462  if ( !$class ) {
463  throw new MWException( "Descriptor with no class for $fieldname: "
464  . print_r( $descriptor, true ) );
465  }
466 
467  return $class;
468  }
469 
480  public static function loadInputFromParameters( $fieldname, $descriptor,
481  HTMLForm $parent = null
482  ) {
483  $class = static::getClassFromDescriptor( $fieldname, $descriptor );
484 
485  $descriptor['fieldname'] = $fieldname;
486  if ( $parent ) {
487  $descriptor['parent'] = $parent;
488  }
489 
490  # @todo This will throw a fatal error whenever someone try to use
491  # 'class' to feed a CSS class instead of 'cssclass'. Would be
492  # great to avoid the fatal error and show a nice error.
493  return new $class( $descriptor );
494  }
495 
505  public function prepareForm() {
506  # Check if we have the info we need
507  if ( !$this->mTitle instanceof Title && $this->mTitle !== false ) {
508  throw new MWException( 'You must call setTitle() on an HTMLForm' );
509  }
510 
511  # Load data from the request.
512  if (
513  $this->mFormIdentifier === null ||
514  $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier
515  ) {
516  $this->loadData();
517  } else {
518  $this->mFieldData = [];
519  }
520 
521  return $this;
522  }
523 
528  public function tryAuthorizedSubmit() {
529  $result = false;
530 
531  $identOkay = false;
532  if ( $this->mFormIdentifier === null ) {
533  $identOkay = true;
534  } else {
535  $identOkay = $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier;
536  }
537 
538  $tokenOkay = false;
539  if ( $this->getMethod() !== 'post' ) {
540  $tokenOkay = true; // no session check needed
541  } elseif ( $this->getRequest()->wasPosted() ) {
542  $editToken = $this->getRequest()->getVal( 'wpEditToken' );
543  if ( $this->getUser()->isLoggedIn() || $editToken !== null ) {
544  // Session tokens for logged-out users have no security value.
545  // However, if the user gave one, check it in order to give a nice
546  // "session expired" error instead of "permission denied" or such.
547  $tokenOkay = $this->getUser()->matchEditToken( $editToken, $this->mTokenSalt );
548  } else {
549  $tokenOkay = true;
550  }
551  }
552 
553  if ( $tokenOkay && $identOkay ) {
554  $this->mWasSubmitted = true;
555  $result = $this->trySubmit();
556  }
557 
558  return $result;
559  }
560 
567  public function show() {
568  $this->prepareForm();
569 
570  $result = $this->tryAuthorizedSubmit();
571  if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
572  return $result;
573  }
574 
575  $this->displayForm( $result );
576 
577  return false;
578  }
579 
585  public function showAlways() {
586  $this->prepareForm();
587 
588  $result = $this->tryAuthorizedSubmit();
589 
590  $this->displayForm( $result );
591 
592  return $result;
593  }
594 
606  public function trySubmit() {
607  $valid = true;
608  $hoistedErrors = Status::newGood();
609  if ( $this->mValidationErrorMessage ) {
610  foreach ( (array)$this->mValidationErrorMessage as $error ) {
611  call_user_func_array( [ $hoistedErrors, 'fatal' ], $error );
612  }
613  } else {
614  $hoistedErrors->fatal( 'htmlform-invalid-input' );
615  }
616 
617  $this->mWasSubmitted = true;
618 
619  # Check for cancelled submission
620  foreach ( $this->mFlatFields as $fieldname => $field ) {
621  if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
622  continue;
623  }
624  if ( $field->cancelSubmit( $this->mFieldData[$fieldname], $this->mFieldData ) ) {
625  $this->mWasSubmitted = false;
626  return false;
627  }
628  }
629 
630  # Check for validation
631  foreach ( $this->mFlatFields as $fieldname => $field ) {
632  if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
633  continue;
634  }
635  if ( $field->isHidden( $this->mFieldData ) ) {
636  continue;
637  }
638  $res = $field->validate( $this->mFieldData[$fieldname], $this->mFieldData );
639  if ( $res !== true ) {
640  $valid = false;
641  if ( $res !== false && !$field->canDisplayErrors() ) {
642  if ( is_string( $res ) ) {
643  $hoistedErrors->fatal( 'rawmessage', $res );
644  } else {
645  $hoistedErrors->fatal( $res );
646  }
647  }
648  }
649  }
650 
651  if ( !$valid ) {
652  return $hoistedErrors;
653  }
654 
655  $callback = $this->mSubmitCallback;
656  if ( !is_callable( $callback ) ) {
657  throw new MWException( 'HTMLForm: no submit callback provided. Use ' .
658  'setSubmitCallback() to set one.' );
659  }
660 
661  $data = $this->filterDataForSubmit( $this->mFieldData );
662 
663  $res = call_user_func( $callback, $data, $this );
664  if ( $res === false ) {
665  $this->mWasSubmitted = false;
666  }
667 
668  return $res;
669  }
670 
682  public function wasSubmitted() {
683  return $this->mWasSubmitted;
684  }
685 
696  public function setSubmitCallback( $cb ) {
697  $this->mSubmitCallback = $cb;
698 
699  return $this;
700  }
701 
710  public function setValidationErrorMessage( $msg ) {
711  $this->mValidationErrorMessage = $msg;
712 
713  return $this;
714  }
715 
723  public function setIntro( $msg ) {
724  $this->setPreText( $msg );
725 
726  return $this;
727  }
728 
737  public function setPreText( $msg ) {
738  $this->mPre = $msg;
739 
740  return $this;
741  }
742 
750  public function addPreText( $msg ) {
751  $this->mPre .= $msg;
752 
753  return $this;
754  }
755 
764  public function addHeaderText( $msg, $section = null ) {
765  if ( $section === null ) {
766  $this->mHeader .= $msg;
767  } else {
768  if ( !isset( $this->mSectionHeaders[$section] ) ) {
769  $this->mSectionHeaders[$section] = '';
770  }
771  $this->mSectionHeaders[$section] .= $msg;
772  }
773 
774  return $this;
775  }
776 
786  public function setHeaderText( $msg, $section = null ) {
787  if ( $section === null ) {
788  $this->mHeader = $msg;
789  } else {
790  $this->mSectionHeaders[$section] = $msg;
791  }
792 
793  return $this;
794  }
795 
803  public function getHeaderText( $section = null ) {
804  if ( $section === null ) {
805  return $this->mHeader;
806  } else {
807  return isset( $this->mSectionHeaders[$section] ) ? $this->mSectionHeaders[$section] : '';
808  }
809  }
810 
819  public function addFooterText( $msg, $section = null ) {
820  if ( $section === null ) {
821  $this->mFooter .= $msg;
822  } else {
823  if ( !isset( $this->mSectionFooters[$section] ) ) {
824  $this->mSectionFooters[$section] = '';
825  }
826  $this->mSectionFooters[$section] .= $msg;
827  }
828 
829  return $this;
830  }
831 
841  public function setFooterText( $msg, $section = null ) {
842  if ( $section === null ) {
843  $this->mFooter = $msg;
844  } else {
845  $this->mSectionFooters[$section] = $msg;
846  }
847 
848  return $this;
849  }
850 
858  public function getFooterText( $section = null ) {
859  if ( $section === null ) {
860  return $this->mFooter;
861  } else {
862  return isset( $this->mSectionFooters[$section] ) ? $this->mSectionFooters[$section] : '';
863  }
864  }
865 
873  public function addPostText( $msg ) {
874  $this->mPost .= $msg;
875 
876  return $this;
877  }
878 
886  public function setPostText( $msg ) {
887  $this->mPost = $msg;
888 
889  return $this;
890  }
891 
901  public function addHiddenField( $name, $value, array $attribs = [] ) {
902  $attribs += [ 'name' => $name ];
903  $this->mHiddenFields[] = [ $value, $attribs ];
904 
905  return $this;
906  }
907 
918  public function addHiddenFields( array $fields ) {
919  foreach ( $fields as $name => $value ) {
920  $this->mHiddenFields[] = [ $value, [ 'name' => $name ] ];
921  }
922 
923  return $this;
924  }
925 
950  public function addButton( $data ) {
951  if ( !is_array( $data ) ) {
952  $args = func_get_args();
953  if ( count( $args ) < 2 || count( $args ) > 4 ) {
954  throw new InvalidArgumentException(
955  'Incorrect number of arguments for deprecated calling style'
956  );
957  }
958  $data = [
959  'name' => $args[0],
960  'value' => $args[1],
961  'id' => isset( $args[2] ) ? $args[2] : null,
962  'attribs' => isset( $args[3] ) ? $args[3] : null,
963  ];
964  } else {
965  if ( !isset( $data['name'] ) ) {
966  throw new InvalidArgumentException( 'A name is required' );
967  }
968  if ( !isset( $data['value'] ) ) {
969  throw new InvalidArgumentException( 'A value is required' );
970  }
971  }
972  $this->mButtons[] = $data + [
973  'id' => null,
974  'attribs' => null,
975  'flags' => null,
976  'framed' => true,
977  ];
978 
979  return $this;
980  }
981 
991  public function setTokenSalt( $salt ) {
992  $this->mTokenSalt = $salt;
993 
994  return $this;
995  }
996 
1009  public function displayForm( $submitResult ) {
1010  $this->getOutput()->addHTML( $this->getHTML( $submitResult ) );
1011  }
1012 
1020  public function getHTML( $submitResult ) {
1021  # For good measure (it is the default)
1022  $this->getOutput()->preventClickjacking();
1023  $this->getOutput()->addModules( 'mediawiki.htmlform' );
1024  $this->getOutput()->addModuleStyles( 'mediawiki.htmlform.styles' );
1025 
1026  $html = ''
1027  . $this->getErrorsOrWarnings( $submitResult, 'error' )
1028  . $this->getErrorsOrWarnings( $submitResult, 'warning' )
1029  . $this->getHeaderText()
1030  . $this->getBody()
1031  . $this->getHiddenFields()
1032  . $this->getButtons()
1033  . $this->getFooterText();
1034 
1035  $html = $this->wrapForm( $html );
1036 
1037  return '' . $this->mPre . $html . $this->mPost;
1038  }
1039 
1044  protected function getFormAttributes() {
1045  # Use multipart/form-data
1046  $encType = $this->mUseMultipart
1047  ? 'multipart/form-data'
1048  : 'application/x-www-form-urlencoded';
1049  # Attributes
1050  $attribs = [
1051  'class' => 'mw-htmlform',
1052  'action' => $this->getAction(),
1053  'method' => $this->getMethod(),
1054  'enctype' => $encType,
1055  ];
1056  if ( $this->mId ) {
1057  $attribs['id'] = $this->mId;
1058  }
1059  if ( $this->mAutocomplete ) {
1060  $attribs['autocomplete'] = $this->mAutocomplete;
1061  }
1062  if ( $this->mName ) {
1063  $attribs['name'] = $this->mName;
1064  }
1065  if ( $this->needsJSForHtml5FormValidation() ) {
1066  $attribs['novalidate'] = true;
1067  }
1068  return $attribs;
1069  }
1070 
1078  public function wrapForm( $html ) {
1079  # Include a <fieldset> wrapper for style, if requested.
1080  if ( $this->mWrapperLegend !== false ) {
1081  $legend = is_string( $this->mWrapperLegend ) ? $this->mWrapperLegend : false;
1082  $html = Xml::fieldset( $legend, $html );
1083  }
1084 
1085  return Html::rawElement(
1086  'form',
1087  $this->getFormAttributes(),
1088  $html
1089  );
1090  }
1091 
1096  public function getHiddenFields() {
1097  $html = '';
1098  if ( $this->mFormIdentifier !== null ) {
1099  $html .= Html::hidden(
1100  'wpFormIdentifier',
1101  $this->mFormIdentifier
1102  ) . "\n";
1103  }
1104  if ( $this->getMethod() === 'post' ) {
1105  $html .= Html::hidden(
1106  'wpEditToken',
1107  $this->getUser()->getEditToken( $this->mTokenSalt ),
1108  [ 'id' => 'wpEditToken' ]
1109  ) . "\n";
1110  $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1111  }
1112 
1113  $articlePath = $this->getConfig()->get( 'ArticlePath' );
1114  if ( strpos( $articlePath, '?' ) !== false && $this->getMethod() === 'get' ) {
1115  $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1116  }
1117 
1118  foreach ( $this->mHiddenFields as $data ) {
1119  list( $value, $attribs ) = $data;
1120  $html .= Html::hidden( $attribs['name'], $value, $attribs ) . "\n";
1121  }
1122 
1123  return $html;
1124  }
1125 
1130  public function getButtons() {
1131  $buttons = '';
1132  $useMediaWikiUIEverywhere = $this->getConfig()->get( 'UseMediaWikiUIEverywhere' );
1133 
1134  if ( $this->mShowSubmit ) {
1135  $attribs = [];
1136 
1137  if ( isset( $this->mSubmitID ) ) {
1138  $attribs['id'] = $this->mSubmitID;
1139  }
1140 
1141  if ( isset( $this->mSubmitName ) ) {
1142  $attribs['name'] = $this->mSubmitName;
1143  }
1144 
1145  if ( isset( $this->mSubmitTooltip ) ) {
1146  $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
1147  }
1148 
1149  $attribs['class'] = [ 'mw-htmlform-submit' ];
1150 
1151  if ( $useMediaWikiUIEverywhere ) {
1152  foreach ( $this->mSubmitFlags as $flag ) {
1153  $attribs['class'][] = 'mw-ui-' . $flag;
1154  }
1155  $attribs['class'][] = 'mw-ui-button';
1156  }
1157 
1158  $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
1159  }
1160 
1161  if ( $this->mShowReset ) {
1162  $buttons .= Html::element(
1163  'input',
1164  [
1165  'type' => 'reset',
1166  'value' => $this->msg( 'htmlform-reset' )->text(),
1167  'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null,
1168  ]
1169  ) . "\n";
1170  }
1171 
1172  if ( $this->mShowCancel ) {
1173  $target = $this->mCancelTarget ?: Title::newMainPage();
1174  if ( $target instanceof Title ) {
1175  $target = $target->getLocalURL();
1176  }
1177  $buttons .= Html::element(
1178  'a',
1179  [
1180  'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null,
1181  'href' => $target,
1182  ],
1183  $this->msg( 'cancel' )->text()
1184  ) . "\n";
1185  }
1186 
1187  // IE<8 has bugs with <button>, so we'll need to avoid them.
1188  $isBadIE = preg_match( '/MSIE [1-7]\./i', $this->getRequest()->getHeader( 'User-Agent' ) );
1189 
1190  foreach ( $this->mButtons as $button ) {
1191  $attrs = [
1192  'type' => 'submit',
1193  'name' => $button['name'],
1194  'value' => $button['value']
1195  ];
1196 
1197  if ( isset( $button['label-message'] ) ) {
1198  $label = $this->getMessage( $button['label-message'] )->parse();
1199  } elseif ( isset( $button['label'] ) ) {
1200  $label = htmlspecialchars( $button['label'] );
1201  } elseif ( isset( $button['label-raw'] ) ) {
1202  $label = $button['label-raw'];
1203  } else {
1204  $label = htmlspecialchars( $button['value'] );
1205  }
1206 
1207  if ( $button['attribs'] ) {
1208  $attrs += $button['attribs'];
1209  }
1210 
1211  if ( isset( $button['id'] ) ) {
1212  $attrs['id'] = $button['id'];
1213  }
1214 
1215  if ( $useMediaWikiUIEverywhere ) {
1216  $attrs['class'] = isset( $attrs['class'] ) ? (array)$attrs['class'] : [];
1217  $attrs['class'][] = 'mw-ui-button';
1218  }
1219 
1220  if ( $isBadIE ) {
1221  $buttons .= Html::element( 'input', $attrs ) . "\n";
1222  } else {
1223  $buttons .= Html::rawElement( 'button', $attrs, $label ) . "\n";
1224  }
1225  }
1226 
1227  if ( !$buttons ) {
1228  return '';
1229  }
1230 
1231  return Html::rawElement( 'span',
1232  [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n";
1233  }
1234 
1239  public function getBody() {
1240  return $this->displaySection( $this->mFieldTree, $this->mTableId );
1241  }
1242 
1252  public function getErrors( $errors ) {
1253  wfDeprecated( __METHOD__ );
1254  return $this->getErrorsOrWarnings( $errors, 'error' );
1255  }
1256 
1265  public function getErrorsOrWarnings( $elements, $elementsType ) {
1266  if ( !in_array( $elementsType, [ 'error', 'warning' ], true ) ) {
1267  throw new DomainException( $elementsType . ' is not a valid type.' );
1268  }
1269  $elementstr = false;
1270  if ( $elements instanceof Status ) {
1271  list( $errorStatus, $warningStatus ) = $elements->splitByErrorType();
1272  $status = $elementsType === 'error' ? $errorStatus : $warningStatus;
1273  if ( $status->isGood() ) {
1274  $elementstr = '';
1275  } else {
1276  $elementstr = $this->getOutput()->parse(
1277  $status->getWikiText()
1278  );
1279  }
1280  } elseif ( is_array( $elements ) && $elementsType === 'error' ) {
1281  $elementstr = $this->formatErrors( $elements );
1282  } elseif ( $elementsType === 'error' ) {
1283  $elementstr = $elements;
1284  }
1285 
1286  return $elementstr
1287  ? Html::rawElement( 'div', [ 'class' => $elementsType ], $elementstr )
1288  : '';
1289  }
1290 
1298  public function formatErrors( $errors ) {
1299  $errorstr = '';
1300 
1301  foreach ( $errors as $error ) {
1302  $errorstr .= Html::rawElement(
1303  'li',
1304  [],
1305  $this->getMessage( $error )->parse()
1306  );
1307  }
1308 
1309  $errorstr = Html::rawElement( 'ul', [], $errorstr );
1310 
1311  return $errorstr;
1312  }
1313 
1321  public function setSubmitText( $t ) {
1322  $this->mSubmitText = $t;
1323 
1324  return $this;
1325  }
1326 
1333  public function setSubmitDestructive() {
1334  $this->mSubmitFlags = [ 'destructive', 'primary' ];
1335 
1336  return $this;
1337  }
1338 
1345  public function setSubmitProgressive() {
1346  $this->mSubmitFlags = [ 'progressive', 'primary' ];
1347 
1348  return $this;
1349  }
1350 
1359  public function setSubmitTextMsg( $msg ) {
1360  if ( !$msg instanceof Message ) {
1361  $msg = $this->msg( $msg );
1362  }
1363  $this->setSubmitText( $msg->text() );
1364 
1365  return $this;
1366  }
1367 
1372  public function getSubmitText() {
1373  return $this->mSubmitText ?: $this->msg( 'htmlform-submit' )->text();
1374  }
1375 
1381  public function setSubmitName( $name ) {
1382  $this->mSubmitName = $name;
1383 
1384  return $this;
1385  }
1386 
1392  public function setSubmitTooltip( $name ) {
1393  $this->mSubmitTooltip = $name;
1394 
1395  return $this;
1396  }
1397 
1406  public function setSubmitID( $t ) {
1407  $this->mSubmitID = $t;
1408 
1409  return $this;
1410  }
1411 
1427  public function setFormIdentifier( $ident ) {
1428  $this->mFormIdentifier = $ident;
1429 
1430  return $this;
1431  }
1432 
1443  public function suppressDefaultSubmit( $suppressSubmit = true ) {
1444  $this->mShowSubmit = !$suppressSubmit;
1445 
1446  return $this;
1447  }
1448 
1455  public function showCancel( $show = true ) {
1456  $this->mShowCancel = $show;
1457  return $this;
1458  }
1459 
1466  public function setCancelTarget( $target ) {
1467  $this->mCancelTarget = $target;
1468  return $this;
1469  }
1470 
1480  public function setTableId( $id ) {
1481  $this->mTableId = $id;
1482 
1483  return $this;
1484  }
1485 
1491  public function setId( $id ) {
1492  $this->mId = $id;
1493 
1494  return $this;
1495  }
1496 
1501  public function setName( $name ) {
1502  $this->mName = $name;
1503 
1504  return $this;
1505  }
1506 
1518  public function setWrapperLegend( $legend ) {
1519  $this->mWrapperLegend = $legend;
1520 
1521  return $this;
1522  }
1523 
1533  public function setWrapperLegendMsg( $msg ) {
1534  if ( !$msg instanceof Message ) {
1535  $msg = $this->msg( $msg );
1536  }
1537  $this->setWrapperLegend( $msg->text() );
1538 
1539  return $this;
1540  }
1541 
1551  public function setMessagePrefix( $p ) {
1552  $this->mMessagePrefix = $p;
1553 
1554  return $this;
1555  }
1556 
1564  public function setTitle( $t ) {
1565  $this->mTitle = $t;
1566 
1567  return $this;
1568  }
1569 
1574  public function getTitle() {
1575  return $this->mTitle === false
1576  ? $this->getContext()->getTitle()
1577  : $this->mTitle;
1578  }
1579 
1587  public function setMethod( $method = 'post' ) {
1588  $this->mMethod = strtolower( $method );
1589 
1590  return $this;
1591  }
1592 
1596  public function getMethod() {
1597  return $this->mMethod;
1598  }
1599 
1608  protected function wrapFieldSetSection( $legend, $section, $attributes ) {
1609  return Xml::fieldset( $legend, $section, $attributes ) . "\n";
1610  }
1611 
1628  public function displaySection( $fields,
1629  $sectionName = '',
1630  $fieldsetIDPrefix = '',
1631  &$hasUserVisibleFields = false
1632  ) {
1633  if ( $this->mFieldData === null ) {
1634  throw new LogicException( 'HTMLForm::displaySection() called on uninitialized field data. '
1635  . 'You probably called displayForm() without calling prepareForm() first.' );
1636  }
1637 
1638  $displayFormat = $this->getDisplayFormat();
1639 
1640  $html = [];
1641  $subsectionHtml = '';
1642  $hasLabel = false;
1643 
1644  // Conveniently, PHP method names are case-insensitive.
1645  // For grep: this can call getDiv, getRaw, getInline, getVForm, getOOUI
1646  $getFieldHtmlMethod = $displayFormat === 'table' ? 'getTableRow' : ( 'get' . $displayFormat );
1647 
1648  foreach ( $fields as $key => $value ) {
1649  if ( $value instanceof HTMLFormField ) {
1650  $v = array_key_exists( $key, $this->mFieldData )
1651  ? $this->mFieldData[$key]
1652  : $value->getDefault();
1653 
1654  $retval = $value->$getFieldHtmlMethod( $v );
1655 
1656  // check, if the form field should be added to
1657  // the output.
1658  if ( $value->hasVisibleOutput() ) {
1659  $html[] = $retval;
1660 
1661  $labelValue = trim( $value->getLabel() );
1662  if ( $labelValue !== '&#160;' && $labelValue !== '' ) {
1663  $hasLabel = true;
1664  }
1665 
1666  $hasUserVisibleFields = true;
1667  }
1668  } elseif ( is_array( $value ) ) {
1669  $subsectionHasVisibleFields = false;
1670  $section =
1671  $this->displaySection( $value,
1672  "mw-htmlform-$key",
1673  "$fieldsetIDPrefix$key-",
1674  $subsectionHasVisibleFields );
1675  $legend = null;
1676 
1677  if ( $subsectionHasVisibleFields === true ) {
1678  // Display the section with various niceties.
1679  $hasUserVisibleFields = true;
1680 
1681  $legend = $this->getLegend( $key );
1682 
1683  $section = $this->getHeaderText( $key ) .
1684  $section .
1685  $this->getFooterText( $key );
1686 
1687  $attributes = [];
1688  if ( $fieldsetIDPrefix ) {
1689  $attributes['id'] = Sanitizer::escapeId( "$fieldsetIDPrefix$key" );
1690  }
1691  $subsectionHtml .= $this->wrapFieldSetSection( $legend, $section, $attributes );
1692  } else {
1693  // Just return the inputs, nothing fancy.
1694  $subsectionHtml .= $section;
1695  }
1696  }
1697  }
1698 
1699  $html = $this->formatSection( $html, $sectionName, $hasLabel );
1700 
1701  if ( $subsectionHtml ) {
1702  if ( $this->mSubSectionBeforeFields ) {
1703  return $subsectionHtml . "\n" . $html;
1704  } else {
1705  return $html . "\n" . $subsectionHtml;
1706  }
1707  } else {
1708  return $html;
1709  }
1710  }
1711 
1719  protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
1720  $displayFormat = $this->getDisplayFormat();
1721  $html = implode( '', $fieldsHtml );
1722 
1723  if ( $displayFormat === 'raw' ) {
1724  return $html;
1725  }
1726 
1727  $classes = [];
1728 
1729  if ( !$anyFieldHasLabel ) { // Avoid strange spacing when no labels exist
1730  $classes[] = 'mw-htmlform-nolabel';
1731  }
1732 
1733  $attribs = [
1734  'class' => implode( ' ', $classes ),
1735  ];
1736 
1737  if ( $sectionName ) {
1738  $attribs['id'] = Sanitizer::escapeId( $sectionName );
1739  }
1740 
1741  if ( $displayFormat === 'table' ) {
1742  return Html::rawElement( 'table',
1743  $attribs,
1744  Html::rawElement( 'tbody', [], "\n$html\n" ) ) . "\n";
1745  } elseif ( $displayFormat === 'inline' ) {
1746  return Html::rawElement( 'span', $attribs, "\n$html\n" );
1747  } else {
1748  return Html::rawElement( 'div', $attribs, "\n$html\n" );
1749  }
1750  }
1751 
1755  public function loadData() {
1756  $fieldData = [];
1757 
1758  foreach ( $this->mFlatFields as $fieldname => $field ) {
1759  $request = $this->getRequest();
1760  if ( $field->skipLoadData( $request ) ) {
1761  continue;
1762  } elseif ( !empty( $field->mParams['disabled'] ) ) {
1763  $fieldData[$fieldname] = $field->getDefault();
1764  } else {
1765  $fieldData[$fieldname] = $field->loadDataFromRequest( $request );
1766  }
1767  }
1768 
1769  # Filter data.
1770  foreach ( $fieldData as $name => &$value ) {
1771  $field = $this->mFlatFields[$name];
1772  $value = $field->filter( $value, $this->mFlatFields );
1773  }
1774 
1775  $this->mFieldData = $fieldData;
1776  }
1777 
1785  public function suppressReset( $suppressReset = true ) {
1786  $this->mShowReset = !$suppressReset;
1787 
1788  return $this;
1789  }
1790 
1800  public function filterDataForSubmit( $data ) {
1801  return $data;
1802  }
1803 
1812  public function getLegend( $key ) {
1813  return $this->msg( "{$this->mMessagePrefix}-$key" )->text();
1814  }
1815 
1826  public function setAction( $action ) {
1827  $this->mAction = $action;
1828 
1829  return $this;
1830  }
1831 
1839  public function getAction() {
1840  // If an action is alredy provided, return it
1841  if ( $this->mAction !== false ) {
1842  return $this->mAction;
1843  }
1844 
1845  $articlePath = $this->getConfig()->get( 'ArticlePath' );
1846  // Check whether we are in GET mode and the ArticlePath contains a "?"
1847  // meaning that getLocalURL() would return something like "index.php?title=...".
1848  // As browser remove the query string before submitting GET forms,
1849  // it means that the title would be lost. In such case use wfScript() instead
1850  // and put title in an hidden field (see getHiddenFields()).
1851  if ( strpos( $articlePath, '?' ) !== false && $this->getMethod() === 'get' ) {
1852  return wfScript();
1853  }
1854 
1855  return $this->getTitle()->getLocalURL();
1856  }
1857 
1868  public function setAutocomplete( $autocomplete ) {
1869  $this->mAutocomplete = $autocomplete;
1870 
1871  return $this;
1872  }
1873 
1880  protected function getMessage( $value ) {
1881  return Message::newFromSpecifier( $value )->setContext( $this );
1882  }
1883 
1893  public function needsJSForHtml5FormValidation() {
1894  foreach ( $this->mFlatFields as $fieldname => $field ) {
1895  if ( $field->needsJSForHtml5FormValidation() ) {
1896  return true;
1897  }
1898  }
1899  return false;
1900  }
1901 }
HTMLForm\$mSubSectionBeforeFields
$mSubSectionBeforeFields
If true, sections that contain both fields and subsections will render their subsections before their...
Definition: HTMLForm.php:241
HTMLForm\getLegend
getLegend( $key)
Get a string to go in the "<legend>" of a section fieldset.
Definition: HTMLForm.php:1812
HTMLForm\$mTokenSalt
string array $mTokenSalt
Salt for the edit token.
Definition: HTMLForm.php:232
HTMLForm\$typeMappings
static $typeMappings
Definition: HTMLForm.php:130
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:34
ContextSource\getConfig
getConfig()
Get the Config object.
Definition: ContextSource.php:68
HTMLForm\setPostText
setPostText( $msg)
Set text at the end of the display.
Definition: HTMLForm.php:886
HTMLForm\setAutocomplete
setAutocomplete( $autocomplete)
Set the value for the autocomplete attribute of the form.
Definition: HTMLForm.php:1868
HTMLForm\$mSubmitText
$mSubmitText
Definition: HTMLForm.php:200
HTMLForm\prepareForm
prepareForm()
Prepare form for submission.
Definition: HTMLForm.php:505
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:41
HTMLForm\hasField
hasField( $fieldname)
Definition: HTMLForm.php:366
$request
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2612
HTMLForm\setPreText
setPreText( $msg)
Set the introductory message HTML, overwriting any existing message.
Definition: HTMLForm.php:737
HTMLForm\suppressDefaultSubmit
suppressDefaultSubmit( $suppressSubmit=true)
Stop a default submit button being shown for this form.
Definition: HTMLForm.php:1443
HTMLForm\$mSectionHeaders
$mSectionHeaders
Definition: HTMLForm.php:191
HTMLForm\setSubmitName
setSubmitName( $name)
Definition: HTMLForm.php:1381
HTMLForm\setFooterText
setFooterText( $msg, $section=null)
Set footer text, inside the form.
Definition: HTMLForm.php:841
HTMLForm\$mFieldTree
$mFieldTree
Definition: HTMLForm.php:178
HTMLForm\setIntro
setIntro( $msg)
Set the introductory message, overwriting any existing message.
Definition: HTMLForm.php:723
ContextSource\msg
msg()
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:187
HTMLForm\getErrors
getErrors( $errors)
Format and display an error message stack.
Definition: HTMLForm.php:1252
HTMLForm\tryAuthorizedSubmit
tryAuthorizedSubmit()
Try submitting, with edit token check first.
Definition: HTMLForm.php:528
HTMLForm\setSubmitTooltip
setSubmitTooltip( $name)
Definition: HTMLForm.php:1392
HTMLForm\addHeaderText
addHeaderText( $msg, $section=null)
Add HTML to the header, inside the form.
Definition: HTMLForm.php:764
HTMLForm\$mTitle
$mTitle
Definition: HTMLForm.php:204
captcha-old.count
count
Definition: captcha-old.py:225
HTMLForm\setDisplayFormat
setDisplayFormat( $format)
Set format in which to display the form.
Definition: HTMLForm.php:392
HTMLForm\wrapForm
wrapForm( $html)
Wrap the form innards in an actual "<form>" element.
Definition: HTMLForm.php:1078
text
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
Title\newMainPage
static newMainPage()
Create a new Title for the Main Page.
Definition: Title.php:559
HTMLForm\getHiddenFields
getHiddenFields()
Get the hidden fields that should go inside the form.
Definition: HTMLForm.php:1096
$result
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:Array with elements of the form "language:title" in the order that they will be output. & $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:1954
HTMLForm\getDisplayFormat
getDisplayFormat()
Getter for displayFormat.
Definition: HTMLForm.php:421
HTMLForm\$mWasSubmitted
$mWasSubmitted
Definition: HTMLForm.php:206
HTMLForm\$mFieldData
$mFieldData
Definition: HTMLForm.php:171
HTMLForm\setHeaderText
setHeaderText( $msg, $section=null)
Set header text, inside the form.
Definition: HTMLForm.php:786
HTMLForm\formatErrors
formatErrors( $errors)
Format a stack of error messages into a single HTML string.
Definition: HTMLForm.php:1298
$status
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition: hooks.txt:1049
HTMLForm\getClassFromDescriptor
static getClassFromDescriptor( $fieldname, &$descriptor)
Get the HTMLFormField subclass for this descriptor.
Definition: HTMLForm.php:452
HTMLForm\showCancel
showCancel( $show=true)
Show a cancel button (or prevent it).
Definition: HTMLForm.php:1455
HTMLForm\$mWrapperLegend
$mWrapperLegend
Definition: HTMLForm.php:226
HTMLForm\$mUseMultipart
$mUseMultipart
Definition: HTMLForm.php:222
HTMLForm\$mShowSubmit
$mShowSubmit
Definition: HTMLForm.php:180
HTMLForm\$mCancelTarget
$mCancelTarget
Definition: HTMLForm.php:183
HTMLForm\setTokenSalt
setTokenSalt( $salt)
Set the salt for the edit token.
Definition: HTMLForm.php:991
HTMLForm\$mSubmitTooltip
$mSubmitTooltip
Definition: HTMLForm.php:201
HTMLForm\$displayFormat
string $displayFormat
Format in which to display form.
Definition: HTMLForm.php:248
HTMLForm\show
show()
The here's-one-I-made-earlier option: do the submission if posted, or display the form with or withou...
Definition: HTMLForm.php:567
HTMLForm\$mSubmitID
$mSubmitID
Definition: HTMLForm.php:198
HTMLForm\setCancelTarget
setCancelTarget( $target)
Sets the target where the user is redirected to after clicking cancel.
Definition: HTMLForm.php:1466
HTMLForm\getBody
getBody()
Get the whole body of the form.
Definition: HTMLForm.php:1239
$res
$res
Definition: database.txt:21
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:304
ContextSource\getRequest
getRequest()
Get the WebRequest object.
Definition: ContextSource.php:78
HTMLForm\$mShowReset
$mShowReset
Definition: HTMLForm.php:179
HTMLForm\$mTableId
$mTableId
Definition: HTMLForm.php:196
HTMLForm\$mSubmitName
$mSubmitName
Definition: HTMLForm.php:199
ContextSource\getUser
getUser()
Get the User object.
Definition: ContextSource.php:133
HTMLForm\getAction
getAction()
Get the value for the action attribute of the form.
Definition: HTMLForm.php:1839
HTMLForm\setSubmitProgressive
setSubmitProgressive()
Identify that the submit button in the form has a progressive action.
Definition: HTMLForm.php:1345
HTMLForm\setMethod
setMethod( $method='post')
Set the method used to submit the form.
Definition: HTMLForm.php:1587
HTMLForm\$mButtons
$mButtons
Definition: HTMLForm.php:224
php
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
HTMLForm\__construct
__construct( $descriptor, $context=null, $messagePrefix='')
Build a new HTMLForm from an array of field attributes.
Definition: HTMLForm.php:302
Status
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: Status.php:40
Xml\fieldset
static fieldset( $legend=false, $content=false, $attribs=[])
Shortcut for creating fieldsets.
Definition: Xml.php:577
HTMLForm\setSubmitText
setSubmitText( $t)
Set the text for the submit button.
Definition: HTMLForm.php:1321
HTMLForm\trySubmit
trySubmit()
Validate all the fields, and call the submission callback function if everything is kosher.
Definition: HTMLForm.php:606
StatusValue\isGood
isGood()
Returns whether the operation completed and didn't have any error or warnings.
Definition: StatusValue.php:116
HTMLForm\$mSubmitFlags
$mSubmitFlags
Definition: HTMLForm.php:181
$html
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:1956
MWException
MediaWiki exception.
Definition: MWException.php:26
HTMLForm\$mAction
bool string $mAction
Form action URL.
Definition: HTMLForm.php:213
HTMLForm\setFormIdentifier
setFormIdentifier( $ident)
Set an internal identifier for this form.
Definition: HTMLForm.php:1427
HTMLForm\wrapFieldSetSection
wrapFieldSetSection( $legend, $section, $attributes)
Wraps the given $section into an user-visible fieldset.
Definition: HTMLForm.php:1608
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1128
HTMLForm\getHeaderText
getHeaderText( $section=null)
Get header text.
Definition: HTMLForm.php:803
HTMLForm\addButton
addButton( $data)
Add a button to the form.
Definition: HTMLForm.php:950
wfScript
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
Definition: GlobalFunctions.php:3138
HTMLForm\addHiddenField
addHiddenField( $name, $value, array $attribs=[])
Add a hidden field to the output.
Definition: HTMLForm.php:901
ContextSource\getOutput
getOutput()
Get the OutputPage object.
Definition: ContextSource.php:123
HTMLForm\setSubmitID
setSubmitID( $t)
Set the id for the submit button.
Definition: HTMLForm.php:1406
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:30
HTMLForm\factory
static factory( $displayFormat)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:277
HTMLFormField
The parent class to generate form fields.
Definition: HTMLFormField.php:7
$attribs
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:1956
HTMLForm\wasSubmitted
wasSubmitted()
Test whether the form was considered to have been submitted or not, i.e.
Definition: HTMLForm.php:682
HTMLForm\$mFormIdentifier
$mFormIdentifier
Definition: HTMLForm.php:203
HTMLForm\formatSection
formatSection(array $fieldsHtml, $sectionName, $anyFieldHasLabel)
Put a form section together from the individual fields' HTML, merging it and wrapping.
Definition: HTMLForm.php:1719
HTMLForm\setMessagePrefix
setMessagePrefix( $p)
Set the prefix for various default messages.
Definition: HTMLForm.php:1551
HTMLForm\setSubmitCallback
setSubmitCallback( $cb)
Set a callback to a function to do something with the form once it's been successfully validated.
Definition: HTMLForm.php:696
HTMLForm\isVForm
isVForm()
Test if displayFormat is 'vform'.
Definition: HTMLForm.php:431
HTMLForm\$mId
$mId
Definition: HTMLForm.php:194
HTMLForm\$mSectionFooters
$mSectionFooters
Definition: HTMLForm.php:192
HTMLForm\loadInputFromParameters
static loadInputFromParameters( $fieldname, $descriptor, HTMLForm $parent=null)
Initialise a new Object for the field.
Definition: HTMLForm.php:480
ContextSource\setContext
setContext(IContextSource $context)
Set the IContextSource object.
Definition: ContextSource.php:58
list
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
HTMLForm\$mPost
$mPost
Definition: HTMLForm.php:193
HTMLForm\getErrorsOrWarnings
getErrorsOrWarnings( $elements, $elementsType)
Returns a formatted list of errors or warnings from the given elements.
Definition: HTMLForm.php:1265
Html\hidden
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:746
HTMLForm\$mFooter
$mFooter
Definition: HTMLForm.php:190
HTMLForm\getFormAttributes
getFormAttributes()
Get HTML attributes for the <form> tag.
Definition: HTMLForm.php:1044
HTMLForm\$mMethod
$mMethod
Definition: HTMLForm.php:205
$value
$value
Definition: styleTest.css.php:45
Linker\tooltipAndAccesskeyAttribs
static tooltipAndAccesskeyAttribs( $name, array $msgParams=[])
Returns the attributes for the tooltip and access key.
Definition: Linker.php:2096
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:76
HTMLForm\setId
setId( $id)
Definition: HTMLForm.php:1491
HTMLForm\$availableSubclassDisplayFormats
array $availableSubclassDisplayFormats
Available formats in which to display the form.
Definition: HTMLForm.php:265
HTMLForm\$availableDisplayFormats
array $availableDisplayFormats
Available formats in which to display the form.
Definition: HTMLForm.php:254
$retval
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 account incomplete not yet checked for validity & $retval
Definition: hooks.txt:246
HTMLForm\setWrapperLegend
setWrapperLegend( $legend)
Prompt the whole form to be wrapped in a "<fieldset>", with this text as its "<legend>" element.
Definition: HTMLForm.php:1518
ObjectFactory\constructClassInstance
static constructClassInstance( $clazz, $args)
Construct an instance of the given class using the given arguments.
Definition: ObjectFactory.php:130
HTMLForm\displaySection
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
Definition: HTMLForm.php:1628
HTMLForm\$mSubmitCallback
$mSubmitCallback
Definition: HTMLForm.php:185
HTMLForm\loadData
loadData()
Construct the form fields from the Descriptor array.
Definition: HTMLForm.php:1755
HTMLForm\showAlways
showAlways()
Same as self::show with the difference, that the form will be added to the output,...
Definition: HTMLForm.php:585
HTMLForm\$mName
$mName
Definition: HTMLForm.php:195
HTMLForm\setSubmitDestructive
setSubmitDestructive()
Identify that the submit button in the form has a destructive action.
Definition: HTMLForm.php:1333
HTMLForm\setValidationErrorMessage
setValidationErrorMessage( $msg)
Set a message to display on a validation error.
Definition: HTMLForm.php:710
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:55
HTMLForm\setSubmitTextMsg
setSubmitTextMsg( $msg)
Set the text for the submit button to a message.
Definition: HTMLForm.php:1359
$args
if( $line===false) $args
Definition: cdb.php:63
Title
Represents a title within MediaWiki.
Definition: Title.php:39
HTMLForm\setName
setName( $name)
Definition: HTMLForm.php:1501
HTMLForm\$mPre
$mPre
Definition: HTMLForm.php:188
HTMLForm\getHTML
getHTML( $submitResult)
Returns the raw HTML generated by the form.
Definition: HTMLForm.php:1020
HTMLForm\getSubmitText
getSubmitText()
Get the text for the submit button, either customised or a default.
Definition: HTMLForm.php:1372
HTMLForm\getMessage
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
Definition: HTMLForm.php:1880
HTMLForm\addHiddenFields
addHiddenFields(array $fields)
Add an array of hidden fields to the output.
Definition: HTMLForm.php:918
HTMLForm\$mShowCancel
$mShowCancel
Definition: HTMLForm.php:182
HTMLForm\setWrapperLegendMsg
setWrapperLegendMsg( $msg)
Prompt the whole form to be wrapped in a "<fieldset>", with this message as its "<legend>" element.
Definition: HTMLForm.php:1533
HTMLForm\$mValidationErrorMessage
$mValidationErrorMessage
Definition: HTMLForm.php:186
HTMLForm\setAction
setAction( $action)
Set the value for the action attribute of the form.
Definition: HTMLForm.php:1826
$section
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:2929
HTMLForm\$mHeader
$mHeader
Definition: HTMLForm.php:189
HTMLForm\setTitle
setTitle( $t)
Set the title for form submission.
Definition: HTMLForm.php:1564
as
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
HTMLForm\setTableId
setTableId( $id)
Set the id of the <table> or outermost <div> element.
Definition: HTMLForm.php:1480
HTMLForm\$mMessagePrefix
$mMessagePrefix
Definition: HTMLForm.php:173
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
HTMLForm\displayForm
displayForm( $submitResult)
Display the form (sending to the context's OutputPage object), with an appropriate error message or s...
Definition: HTMLForm.php:1009
HTMLForm\$mHiddenFields
$mHiddenFields
Definition: HTMLForm.php:223
HTMLForm\$mAutocomplete
bool string $mAutocomplete
Form attribute autocomplete.
Definition: HTMLForm.php:220
HTMLForm\getTitle
getTitle()
Get the title.
Definition: HTMLForm.php:1574
HTMLForm\filterDataForSubmit
filterDataForSubmit( $data)
Overload this if you want to apply special filtration routines to the form as a whole,...
Definition: HTMLForm.php:1800
HTMLForm\getMethod
getMethod()
Definition: HTMLForm.php:1596
HTMLForm\addPreText
addPreText( $msg)
Add HTML to introductory message.
Definition: HTMLForm.php:750
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
$t
$t
Definition: testCompression.php:67
HTMLForm\getField
getField( $fieldname)
Definition: HTMLForm.php:375
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
HTMLForm\addPostText
addPostText( $msg)
Add text to the end of the display.
Definition: HTMLForm.php:873
HTMLForm\suppressReset
suppressReset( $suppressReset=true)
Stop a reset button being shown for this form.
Definition: HTMLForm.php:1785
HTMLForm\getFooterText
getFooterText( $section=null)
Get footer text.
Definition: HTMLForm.php:858
HTMLForm\$mFlatFields
HTMLFormField[] $mFlatFields
Definition: HTMLForm.php:176
HTMLForm\getButtons
getButtons()
Get the submit and (potentially) reset buttons.
Definition: HTMLForm.php:1130
HTMLForm\addFooterText
addFooterText( $msg, $section=null)
Add footer text, inside the form.
Definition: HTMLForm.php:819
array
the array() calling protocol came about after MediaWiki 1.4rc1.
Xml\submitButton
static submitButton( $value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
Definition: Xml.php:459
HTMLForm\needsJSForHtml5FormValidation
needsJSForHtml5FormValidation()
Whether this form, with its current fields, requires the user agent to have JavaScript enabled for th...
Definition: HTMLForm.php:1893
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms.
Definition: HTMLForm.php:128