MediaWiki  1.23.8
HTMLForm.php
Go to the documentation of this file.
1 <?php
2 
100 class HTMLForm extends ContextSource {
101  // A mapping of 'type' inputs onto standard HTMLFormField subclasses
102  public static $typeMappings = array(
103  'api' => 'HTMLApiField',
104  'text' => 'HTMLTextField',
105  'textarea' => 'HTMLTextAreaField',
106  'select' => 'HTMLSelectField',
107  'radio' => 'HTMLRadioField',
108  'multiselect' => 'HTMLMultiSelectField',
109  'check' => 'HTMLCheckField',
110  'toggle' => 'HTMLCheckField',
111  'int' => 'HTMLIntField',
112  'float' => 'HTMLFloatField',
113  'info' => 'HTMLInfoField',
114  'selectorother' => 'HTMLSelectOrOtherField',
115  'selectandother' => 'HTMLSelectAndOtherField',
116  'submit' => 'HTMLSubmitField',
117  'hidden' => 'HTMLHiddenField',
118  'edittools' => 'HTMLEditTools',
119  'checkmatrix' => 'HTMLCheckMatrix',
120  // HTMLTextField will output the correct type="" attribute automagically.
121  // There are about four zillion other HTML5 input types, like range, but
122  // we don't use those at the moment, so no point in adding all of them.
123  'email' => 'HTMLTextField',
124  'password' => 'HTMLTextField',
125  'url' => 'HTMLTextField',
126  );
127 
128  public $mFieldData;
129 
130  protected $mMessagePrefix;
131 
133  protected $mFlatFields;
134 
135  protected $mFieldTree;
136  protected $mShowReset = false;
137  protected $mShowSubmit = true;
138 
139  protected $mSubmitCallback;
140  protected $mValidationErrorMessage;
141 
142  protected $mPre = '';
143  protected $mHeader = '';
144  protected $mFooter = '';
145  protected $mSectionHeaders = array();
146  protected $mSectionFooters = array();
147  protected $mPost = '';
148  protected $mId;
149  protected $mTableId = '';
150 
151  protected $mSubmitID;
152  protected $mSubmitName;
153  protected $mSubmitText;
154  protected $mSubmitTooltip;
155 
156  protected $mTitle;
157  protected $mMethod = 'post';
158 
164  protected $mAction = false;
165 
166  protected $mUseMultipart = false;
167  protected $mHiddenFields = array();
168  protected $mButtons = array();
169 
170  protected $mWrapperLegend = false;
171 
179  protected $mSubSectionBeforeFields = true;
180 
186  protected $displayFormat = 'table';
187 
192  protected $availableDisplayFormats = array(
193  'table',
194  'div',
195  'raw',
196  'vform',
197  );
198 
207  public function __construct( $descriptor, /*IContextSource*/ $context = null,
208  $messagePrefix = ''
209  ) {
210  if ( $context instanceof IContextSource ) {
211  $this->setContext( $context );
212  $this->mTitle = false; // We don't need them to set a title
213  $this->mMessagePrefix = $messagePrefix;
214  } elseif ( is_null( $context ) && $messagePrefix !== '' ) {
215  $this->mMessagePrefix = $messagePrefix;
216  } elseif ( is_string( $context ) && $messagePrefix === '' ) {
217  // B/C since 1.18
218  // it's actually $messagePrefix
219  $this->mMessagePrefix = $context;
220  }
221 
222  // Expand out into a tree.
223  $loadedDescriptor = array();
224  $this->mFlatFields = array();
225 
226  foreach ( $descriptor as $fieldname => $info ) {
227  $section = isset( $info['section'] )
228  ? $info['section']
229  : '';
230 
231  if ( isset( $info['type'] ) && $info['type'] == 'file' ) {
232  $this->mUseMultipart = true;
233  }
234 
235  $field = self::loadInputFromParameters( $fieldname, $info );
236  // FIXME During field's construct, the parent form isn't available!
237  // could add a 'parent' name-value to $info, could add a third parameter.
238  $field->mParent = $this;
239 
240  // vform gets too much space if empty labels generate HTML.
241  if ( $this->isVForm() ) {
242  $field->setShowEmptyLabel( false );
243  }
244 
245  $setSection =& $loadedDescriptor;
246  if ( $section ) {
247  $sectionParts = explode( '/', $section );
248 
249  while ( count( $sectionParts ) ) {
250  $newName = array_shift( $sectionParts );
251 
252  if ( !isset( $setSection[$newName] ) ) {
253  $setSection[$newName] = array();
254  }
255 
256  $setSection =& $setSection[$newName];
257  }
258  }
259 
260  $setSection[$fieldname] = $field;
261  $this->mFlatFields[$fieldname] = $field;
262  }
263 
264  $this->mFieldTree = $loadedDescriptor;
265  }
266 
277  public function setDisplayFormat( $format ) {
278  if ( !in_array( $format, $this->availableDisplayFormats ) ) {
279  throw new MWException( 'Display format must be one of ' .
280  print_r( $this->availableDisplayFormats, true ) );
281  }
282  $this->displayFormat = $format;
283 
284  return $this;
285  }
286 
292  public function getDisplayFormat() {
293  return $this->displayFormat;
294  }
295 
301  public function isVForm() {
302  return $this->displayFormat === 'vform';
303  }
304 
310  static function addJS() {
311  wfDeprecated( __METHOD__, '1.18' );
312  }
313 
330  public static function getClassFromDescriptor( $fieldname, &$descriptor ) {
331  if ( isset( $descriptor['class'] ) ) {
332  $class = $descriptor['class'];
333  } elseif ( isset( $descriptor['type'] ) ) {
334  $class = self::$typeMappings[$descriptor['type']];
335  $descriptor['class'] = $class;
336  } else {
337  $class = null;
338  }
339 
340  if ( !$class ) {
341  throw new MWException( "Descriptor with no class for $fieldname: " . print_r( $descriptor, true ) );
342  }
343  return $class;
344  }
345 
355  public static function loadInputFromParameters( $fieldname, $descriptor ) {
356  $class = self::getClassFromDescriptor( $fieldname, $descriptor );
357 
358  $descriptor['fieldname'] = $fieldname;
359 
360  # @todo This will throw a fatal error whenever someone try to use
361  # 'class' to feed a CSS class instead of 'cssclass'. Would be
362  # great to avoid the fatal error and show a nice error.
363  $obj = new $class( $descriptor );
364 
365  return $obj;
366  }
367 
377  function prepareForm() {
378  # Check if we have the info we need
379  if ( !$this->mTitle instanceof Title && $this->mTitle !== false ) {
380  throw new MWException( "You must call setTitle() on an HTMLForm" );
381  }
382 
383  # Load data from the request.
384  $this->loadData();
385 
386  return $this;
387  }
388 
393  function tryAuthorizedSubmit() {
394  $result = false;
395 
396  $submit = false;
397  if ( $this->getMethod() != 'post' ) {
398  $submit = true; // no session check needed
399  } elseif ( $this->getRequest()->wasPosted() ) {
400  $editToken = $this->getRequest()->getVal( 'wpEditToken' );
401  if ( $this->getUser()->isLoggedIn() || $editToken != null ) {
402  // Session tokens for logged-out users have no security value.
403  // However, if the user gave one, check it in order to give a nice
404  // "session expired" error instead of "permission denied" or such.
405  $submit = $this->getUser()->matchEditToken( $editToken );
406  } else {
407  $submit = true;
408  }
409  }
410 
411  if ( $submit ) {
412  $result = $this->trySubmit();
413  }
414 
415  return $result;
416  }
417 
424  function show() {
425  $this->prepareForm();
426 
427  $result = $this->tryAuthorizedSubmit();
428  if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
429  return $result;
430  }
431 
432  $this->displayForm( $result );
433 
434  return false;
435  }
436 
445  function trySubmit() {
446  # Check for validation
447  foreach ( $this->mFlatFields as $fieldname => $field ) {
448  if ( !empty( $field->mParams['nodata'] ) ) {
449  continue;
450  }
451  if ( $field->validate(
452  $this->mFieldData[$fieldname],
453  $this->mFieldData )
454  !== true
455  ) {
456  return isset( $this->mValidationErrorMessage )
457  ? $this->mValidationErrorMessage
458  : array( 'htmlform-invalid-input' );
459  }
460  }
461 
462  $callback = $this->mSubmitCallback;
463  if ( !is_callable( $callback ) ) {
464  throw new MWException( 'HTMLForm: no submit callback provided. Use ' .
465  'setSubmitCallback() to set one.' );
466  }
467 
468  $data = $this->filterDataForSubmit( $this->mFieldData );
469 
470  $res = call_user_func( $callback, $data, $this );
471 
472  return $res;
473  }
474 
486  function setSubmitCallback( $cb ) {
487  $this->mSubmitCallback = $cb;
488 
489  return $this;
490  }
491 
500  function setValidationErrorMessage( $msg ) {
501  $this->mValidationErrorMessage = $msg;
502 
503  return $this;
504  }
505 
513  function setIntro( $msg ) {
514  $this->setPreText( $msg );
515 
516  return $this;
517  }
518 
527  function setPreText( $msg ) {
528  $this->mPre = $msg;
529 
530  return $this;
531  }
532 
540  function addPreText( $msg ) {
541  $this->mPre .= $msg;
542 
543  return $this;
544  }
545 
554  function addHeaderText( $msg, $section = null ) {
555  if ( is_null( $section ) ) {
556  $this->mHeader .= $msg;
557  } else {
558  if ( !isset( $this->mSectionHeaders[$section] ) ) {
559  $this->mSectionHeaders[$section] = '';
560  }
561  $this->mSectionHeaders[$section] .= $msg;
562  }
563 
564  return $this;
565  }
566 
576  function setHeaderText( $msg, $section = null ) {
577  if ( is_null( $section ) ) {
578  $this->mHeader = $msg;
579  } else {
580  $this->mSectionHeaders[$section] = $msg;
581  }
582 
583  return $this;
584  }
585 
594  function addFooterText( $msg, $section = null ) {
595  if ( is_null( $section ) ) {
596  $this->mFooter .= $msg;
597  } else {
598  if ( !isset( $this->mSectionFooters[$section] ) ) {
599  $this->mSectionFooters[$section] = '';
600  }
601  $this->mSectionFooters[$section] .= $msg;
602  }
603 
604  return $this;
605  }
606 
616  function setFooterText( $msg, $section = null ) {
617  if ( is_null( $section ) ) {
618  $this->mFooter = $msg;
619  } else {
620  $this->mSectionFooters[$section] = $msg;
621  }
622 
623  return $this;
624  }
625 
633  function addPostText( $msg ) {
634  $this->mPost .= $msg;
635 
636  return $this;
637  }
638 
646  function setPostText( $msg ) {
647  $this->mPost = $msg;
648 
649  return $this;
650  }
651 
661  public function addHiddenField( $name, $value, $attribs = array() ) {
662  $attribs += array( 'name' => $name );
663  $this->mHiddenFields[] = array( $value, $attribs );
664 
665  return $this;
666  }
667 
678  public function addHiddenFields( array $fields ) {
679  foreach ( $fields as $name => $value ) {
680  $this->mHiddenFields[] = array( $value, array( 'name' => $name ) );
681  }
682 
683  return $this;
684  }
685 
696  public function addButton( $name, $value, $id = null, $attribs = null ) {
697  $this->mButtons[] = compact( 'name', 'value', 'id', 'attribs' );
698 
699  return $this;
700  }
701 
714  function displayForm( $submitResult ) {
715  $this->getOutput()->addHTML( $this->getHTML( $submitResult ) );
716  }
717 
725  function getHTML( $submitResult ) {
726  # For good measure (it is the default)
727  $this->getOutput()->preventClickjacking();
728  $this->getOutput()->addModules( 'mediawiki.htmlform' );
729  if ( $this->isVForm() ) {
730  $this->getOutput()->addModuleStyles( array(
731  'mediawiki.ui',
732  'mediawiki.ui.button',
733  ) );
734  // @todo Should vertical form set setWrapperLegend( false )
735  // to hide ugly fieldsets?
736  }
737 
738  $html = ''
739  . $this->getErrors( $submitResult )
740  . $this->mHeader
741  . $this->getBody()
742  . $this->getHiddenFields()
743  . $this->getButtons()
744  . $this->mFooter;
745 
746  $html = $this->wrapForm( $html );
747 
748  return '' . $this->mPre . $html . $this->mPost;
749  }
750 
758  function wrapForm( $html ) {
759 
760  # Include a <fieldset> wrapper for style, if requested.
761  if ( $this->mWrapperLegend !== false ) {
762  $html = Xml::fieldset( $this->mWrapperLegend, $html );
763  }
764  # Use multipart/form-data
765  $encType = $this->mUseMultipart
766  ? 'multipart/form-data'
767  : 'application/x-www-form-urlencoded';
768  # Attributes
769  $attribs = array(
770  'action' => $this->getAction(),
771  'method' => $this->getMethod(),
772  'class' => array( 'visualClear' ),
773  'enctype' => $encType,
774  );
775  if ( !empty( $this->mId ) ) {
776  $attribs['id'] = $this->mId;
777  }
778 
779  if ( $this->isVForm() ) {
780  array_push( $attribs['class'], 'mw-ui-vform', 'mw-ui-container' );
781  }
782 
783  return Html::rawElement( 'form', $attribs, $html );
784  }
785 
790  function getHiddenFields() {
792 
793  $html = '';
794  if ( $this->getMethod() == 'post' ) {
795  $html .= Html::hidden(
796  'wpEditToken',
797  $this->getUser()->getEditToken(),
798  array( 'id' => 'wpEditToken' )
799  ) . "\n";
800  $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
801  }
802 
803  if ( strpos( $wgArticlePath, '?' ) !== false && $this->getMethod() == 'get' ) {
804  $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
805  }
806 
807  foreach ( $this->mHiddenFields as $data ) {
808  list( $value, $attribs ) = $data;
809  $html .= Html::hidden( $attribs['name'], $value, $attribs ) . "\n";
810  }
811 
812  return $html;
813  }
814 
819  function getButtons() {
820  $buttons = '';
821 
822  if ( $this->mShowSubmit ) {
823  $attribs = array();
824 
825  if ( isset( $this->mSubmitID ) ) {
826  $attribs['id'] = $this->mSubmitID;
827  }
828 
829  if ( isset( $this->mSubmitName ) ) {
830  $attribs['name'] = $this->mSubmitName;
831  }
832 
833  if ( isset( $this->mSubmitTooltip ) ) {
834  $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
835  }
836 
837  $attribs['class'] = array( 'mw-htmlform-submit' );
838 
839  if ( $this->isVForm() ) {
840  // mw-ui-block is necessary because the buttons aren't necessarily in an
841  // immediate child div of the vform.
842  // @todo Let client specify if the primary submit button is progressive or destructive
843  array_push(
844  $attribs['class'],
845  'mw-ui-button',
846  'mw-ui-big',
847  'mw-ui-constructive',
848  'mw-ui-block'
849  );
850  }
851 
852  $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
853  }
854 
855  if ( $this->mShowReset ) {
856  $buttons .= Html::element(
857  'input',
858  array(
859  'type' => 'reset',
860  'value' => $this->msg( 'htmlform-reset' )->text()
861  )
862  ) . "\n";
863  }
864 
865  foreach ( $this->mButtons as $button ) {
866  $attrs = array(
867  'type' => 'submit',
868  'name' => $button['name'],
869  'value' => $button['value']
870  );
871 
872  if ( $button['attribs'] ) {
873  $attrs += $button['attribs'];
874  }
875 
876  if ( isset( $button['id'] ) ) {
877  $attrs['id'] = $button['id'];
878  }
879 
880  $buttons .= Html::element( 'input', $attrs ) . "\n";
881  }
882 
883  $html = Html::rawElement( 'span',
884  array( 'class' => 'mw-htmlform-submit-buttons' ), "\n$buttons" ) . "\n";
885 
886  // Buttons are top-level form elements in table and div layouts,
887  // but vform wants all elements inside divs to get spaced-out block
888  // styling.
889  if ( $this->mShowSubmit && $this->isVForm() ) {
890  $html = Html::rawElement( 'div', null, "\n$html" ) . "\n";
891  }
892 
893  return $html;
894  }
895 
900  function getBody() {
901  return $this->displaySection( $this->mFieldTree, $this->mTableId );
902  }
903 
911  function getErrors( $errors ) {
912  if ( $errors instanceof Status ) {
913  if ( $errors->isOK() ) {
914  $errorstr = '';
915  } else {
916  $errorstr = $this->getOutput()->parse( $errors->getWikiText() );
917  }
918  } elseif ( is_array( $errors ) ) {
919  $errorstr = $this->formatErrors( $errors );
920  } else {
921  $errorstr = $errors;
922  }
923 
924  return $errorstr
925  ? Html::rawElement( 'div', array( 'class' => 'error' ), $errorstr )
926  : '';
927  }
928 
936  public static function formatErrors( $errors ) {
937  $errorstr = '';
938 
939  foreach ( $errors as $error ) {
940  if ( is_array( $error ) ) {
941  $msg = array_shift( $error );
942  } else {
943  $msg = $error;
944  $error = array();
945  }
946 
947  $errorstr .= Html::rawElement(
948  'li',
949  array(),
950  wfMessage( $msg, $error )->parse()
951  );
952  }
953 
954  $errorstr = Html::rawElement( 'ul', array(), $errorstr );
955 
956  return $errorstr;
957  }
958 
966  function setSubmitText( $t ) {
967  $this->mSubmitText = $t;
968 
969  return $this;
970  }
971 
980  public function setSubmitTextMsg( $msg ) {
981  $this->setSubmitText( $this->msg( $msg )->text() );
982 
983  return $this;
984  }
985 
990  function getSubmitText() {
991  return $this->mSubmitText
992  ? $this->mSubmitText
993  : $this->msg( 'htmlform-submit' )->text();
994  }
995 
1001  public function setSubmitName( $name ) {
1002  $this->mSubmitName = $name;
1003 
1004  return $this;
1005  }
1006 
1012  public function setSubmitTooltip( $name ) {
1013  $this->mSubmitTooltip = $name;
1014 
1015  return $this;
1016  }
1017 
1026  function setSubmitID( $t ) {
1027  $this->mSubmitID = $t;
1028 
1029  return $this;
1030  }
1031 
1042  function suppressDefaultSubmit( $suppressSubmit = true ) {
1043  $this->mShowSubmit = !$suppressSubmit;
1044 
1045  return $this;
1046  }
1047 
1057  public function setTableId( $id ) {
1058  $this->mTableId = $id;
1059 
1060  return $this;
1061  }
1062 
1068  public function setId( $id ) {
1069  $this->mId = $id;
1070 
1071  return $this;
1072  }
1073 
1084  public function setWrapperLegend( $legend ) {
1085  $this->mWrapperLegend = $legend;
1086 
1087  return $this;
1088  }
1089 
1099  public function setWrapperLegendMsg( $msg ) {
1100  $this->setWrapperLegend( $this->msg( $msg )->text() );
1101 
1102  return $this;
1103  }
1104 
1114  function setMessagePrefix( $p ) {
1115  $this->mMessagePrefix = $p;
1116 
1117  return $this;
1118  }
1119 
1127  function setTitle( $t ) {
1128  $this->mTitle = $t;
1129 
1130  return $this;
1131  }
1132 
1137  function getTitle() {
1138  return $this->mTitle === false
1139  ? $this->getContext()->getTitle()
1140  : $this->mTitle;
1141  }
1142 
1150  public function setMethod( $method = 'post' ) {
1151  $this->mMethod = $method;
1153  return $this;
1154  }
1155 
1156  public function getMethod() {
1157  return $this->mMethod;
1158  }
1159 
1173  public function displaySection( $fields,
1174  $sectionName = '',
1175  $fieldsetIDPrefix = '',
1176  &$hasUserVisibleFields = false ) {
1177  $displayFormat = $this->getDisplayFormat();
1178 
1179  $html = '';
1180  $subsectionHtml = '';
1181  $hasLabel = false;
1182 
1183  switch ( $displayFormat ) {
1184  case 'table':
1185  $getFieldHtmlMethod = 'getTableRow';
1186  break;
1187  case 'vform':
1188  // Close enough to a div.
1189  $getFieldHtmlMethod = 'getDiv';
1190  break;
1191  default:
1192  $getFieldHtmlMethod = 'get' . ucfirst( $displayFormat );
1193  }
1194 
1195  foreach ( $fields as $key => $value ) {
1196  if ( $value instanceof HTMLFormField ) {
1197  $v = empty( $value->mParams['nodata'] )
1198  ? $this->mFieldData[$key]
1199  : $value->getDefault();
1200  $html .= $value->$getFieldHtmlMethod( $v );
1201 
1202  $labelValue = trim( $value->getLabel() );
1203  if ( $labelValue != '&#160;' && $labelValue !== '' ) {
1204  $hasLabel = true;
1205  }
1206 
1207  if ( get_class( $value ) !== 'HTMLHiddenField' &&
1208  get_class( $value ) !== 'HTMLApiField'
1209  ) {
1210  $hasUserVisibleFields = true;
1211  }
1212  } elseif ( is_array( $value ) ) {
1213  $subsectionHasVisibleFields = false;
1214  $section =
1215  $this->displaySection( $value,
1216  "mw-htmlform-$key",
1217  "$fieldsetIDPrefix$key-",
1218  $subsectionHasVisibleFields );
1219  $legend = null;
1220 
1221  if ( $subsectionHasVisibleFields === true ) {
1222  // Display the section with various niceties.
1223  $hasUserVisibleFields = true;
1224 
1225  $legend = $this->getLegend( $key );
1226 
1227  if ( isset( $this->mSectionHeaders[$key] ) ) {
1228  $section = $this->mSectionHeaders[$key] . $section;
1229  }
1230  if ( isset( $this->mSectionFooters[$key] ) ) {
1231  $section .= $this->mSectionFooters[$key];
1232  }
1233 
1234  $attributes = array();
1235  if ( $fieldsetIDPrefix ) {
1236  $attributes['id'] = Sanitizer::escapeId( "$fieldsetIDPrefix$key" );
1237  }
1238  $subsectionHtml .= Xml::fieldset( $legend, $section, $attributes ) . "\n";
1239  } else {
1240  // Just return the inputs, nothing fancy.
1241  $subsectionHtml .= $section;
1242  }
1243  }
1244  }
1245 
1246  if ( $displayFormat !== 'raw' ) {
1247  $classes = array();
1248 
1249  if ( !$hasLabel ) { // Avoid strange spacing when no labels exist
1250  $classes[] = 'mw-htmlform-nolabel';
1251  }
1252 
1253  $attribs = array(
1254  'class' => implode( ' ', $classes ),
1255  );
1256 
1257  if ( $sectionName ) {
1258  $attribs['id'] = Sanitizer::escapeId( $sectionName );
1259  }
1260 
1261  if ( $displayFormat === 'table' ) {
1262  $html = Html::rawElement( 'table',
1263  $attribs,
1264  Html::rawElement( 'tbody', array(), "\n$html\n" ) ) . "\n";
1265  } elseif ( $displayFormat === 'div' || $displayFormat === 'vform' ) {
1266  $html = Html::rawElement( 'div', $attribs, "\n$html\n" );
1267  }
1268  }
1269 
1270  if ( $this->mSubSectionBeforeFields ) {
1271  return $subsectionHtml . "\n" . $html;
1272  } else {
1273  return $html . "\n" . $subsectionHtml;
1274  }
1275  }
1280  function loadData() {
1281  $fieldData = array();
1282 
1283  foreach ( $this->mFlatFields as $fieldname => $field ) {
1284  if ( !empty( $field->mParams['nodata'] ) ) {
1285  continue;
1286  } elseif ( !empty( $field->mParams['disabled'] ) ) {
1287  $fieldData[$fieldname] = $field->getDefault();
1288  } else {
1289  $fieldData[$fieldname] = $field->loadDataFromRequest( $this->getRequest() );
1290  }
1291  }
1292 
1293  # Filter data.
1294  foreach ( $fieldData as $name => &$value ) {
1295  $field = $this->mFlatFields[$name];
1296  $value = $field->filter( $value, $this->mFlatFields );
1297  }
1298 
1299  $this->mFieldData = $fieldData;
1300  }
1301 
1310  function suppressReset( $suppressReset = true ) {
1311  $this->mShowReset = !$suppressReset;
1312 
1313  return $this;
1314  }
1315 
1325  function filterDataForSubmit( $data ) {
1326  return $data;
1327  }
1328 
1337  public function getLegend( $key ) {
1338  return $this->msg( "{$this->mMessagePrefix}-$key" )->text();
1339  }
1340 
1351  public function setAction( $action ) {
1352  $this->mAction = $action;
1353 
1354  return $this;
1355  }
1356 
1364  public function getAction() {
1365  global $wgScript, $wgArticlePath;
1366 
1367  // If an action is alredy provided, return it
1368  if ( $this->mAction !== false ) {
1369  return $this->mAction;
1370  }
1371 
1372  // Check whether we are in GET mode and $wgArticlePath contains a "?"
1373  // meaning that getLocalURL() would return something like "index.php?title=...".
1374  // As browser remove the query string before submitting GET forms,
1375  // it means that the title would be lost. In such case use $wgScript instead
1376  // and put title in an hidden field (see getHiddenFields()).
1377  if ( strpos( $wgArticlePath, '?' ) !== false && $this->getMethod() === 'get' ) {
1378  return $wgScript;
1379  }
1380 
1381  return $this->getTitle()->getLocalURL();
1382  }
1383 }
HTMLForm\$mSubSectionBeforeFields
$mSubSectionBeforeFields
If true, sections that contain both fields and subsections will render their subsections before their...
Definition: HTMLForm.php:177
HTMLForm\getLegend
getLegend( $key)
Get a string to go in the "<legend>" of a section fieldset.
Definition: HTMLForm.php:1333
HTMLForm\$typeMappings
static $typeMappings
Definition: HTMLForm.php:102
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:33
HTMLForm\setPostText
setPostText( $msg)
Set text at the end of the display.
Definition: HTMLForm.php:642
$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. $reader:XMLReader object $logInfo:Array of information Return false to stop further processing of the tag 'ImportHandlePageXMLTag':When parsing a XML tag in a page. $reader:XMLReader object $pageInfo:Array of information Return false to stop further processing of the tag 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information Return false to stop further processing of the tag 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. $reader:XMLReader object Return false to stop further processing of the tag 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. $reader:XMLReader object $revisionInfo:Array of information Return false to stop further processing of the tag '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 '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. '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 '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 '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 wfIsTrustedProxy() $ip:IP being check $result:Change this value to override the result of wfIsTrustedProxy() '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 User::isValidEmailAddr(), 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. '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 '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) '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. 'LinkBegin':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:1528
HTMLForm\$mSubmitText
$mSubmitText
Definition: HTMLForm.php:152
HTMLForm\prepareForm
prepareForm()
Prepare form for submission.
Definition: HTMLForm.php:373
ContextSource\getContext
getContext()
Get the RequestContext object.
Definition: ContextSource.php:40
HTMLForm\setPreText
setPreText( $msg)
Set the introductory message, overwriting any existing message.
Definition: HTMLForm.php:523
HTMLForm\suppressDefaultSubmit
suppressDefaultSubmit( $suppressSubmit=true)
Stop a default submit button being shown for this form.
Definition: HTMLForm.php:1038
HTMLForm\$mSectionHeaders
$mSectionHeaders
Definition: HTMLForm.php:144
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
HTMLForm\setSubmitName
setSubmitName( $name)
Definition: HTMLForm.php:997
HTMLForm\setFooterText
setFooterText( $msg, $section=null)
Set footer text, inside the form.
Definition: HTMLForm.php:612
HTMLForm\$mFieldTree
$mFieldTree
Definition: HTMLForm.php:134
HTMLForm\setIntro
setIntro( $msg)
Set the introductory message, overwriting any existing message.
Definition: HTMLForm.php:509
$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:1530
ContextSource\msg
msg()
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:175
HTMLForm\getErrors
getErrors( $errors)
Format and display an error message stack.
Definition: HTMLForm.php:907
HTMLForm\tryAuthorizedSubmit
tryAuthorizedSubmit()
Try submitting, with edit token check first.
Definition: HTMLForm.php:389
HTMLForm\setSubmitTooltip
setSubmitTooltip( $name)
Definition: HTMLForm.php:1008
HTMLForm\addHeaderText
addHeaderText( $msg, $section=null)
Add header text, inside the form.
Definition: HTMLForm.php:550
HTMLForm\$mTitle
$mTitle
Definition: HTMLForm.php:155
HTMLForm\setDisplayFormat
setDisplayFormat( $format)
Set format in which to display the form.
Definition: HTMLForm.php:273
HTMLForm\wrapForm
wrapForm( $html)
Wrap the form innards in an actual "<form>" element.
Definition: HTMLForm.php:754
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
HTMLForm\getHiddenFields
getHiddenFields()
Get the hidden fields that should go inside the form.
Definition: HTMLForm.php:786
HTMLForm\getDisplayFormat
getDisplayFormat()
Getter for displayFormat.
Definition: HTMLForm.php:288
HTMLForm\$mFieldData
$mFieldData
Definition: HTMLForm.php:128
HTMLForm\setHeaderText
setHeaderText( $msg, $section=null)
Set header text, inside the form.
Definition: HTMLForm.php:572
HTMLForm\getClassFromDescriptor
static getClassFromDescriptor( $fieldname, &$descriptor)
Get the HTMLFormField subclass for this descriptor.
Definition: HTMLForm.php:326
HTMLForm\$mWrapperLegend
$mWrapperLegend
Definition: HTMLForm.php:168
HTMLForm\$mUseMultipart
$mUseMultipart
Definition: HTMLForm.php:164
HTMLForm\$mShowSubmit
$mShowSubmit
Definition: HTMLForm.php:136
HTMLForm\$mSubmitTooltip
$mSubmitTooltip
Definition: HTMLForm.php:153
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:420
HTMLForm\$mSubmitID
$mSubmitID
Definition: HTMLForm.php:150
HTMLForm\getBody
getBody()
Get the whole body of the form.
Definition: HTMLForm.php:896
Html\hidden
static hidden( $name, $value, $attribs=array())
Convenience function to produce an input element with type=hidden.
Definition: Html.php:662
ContextSource\getRequest
getRequest()
Get the WebRequest object.
Definition: ContextSource.php:77
HTMLForm\addHiddenField
addHiddenField( $name, $value, $attribs=array())
Add a hidden field to the output.
Definition: HTMLForm.php:657
HTMLForm\$mShowReset
$mShowReset
Definition: HTMLForm.php:135
HTMLForm\addJS
static addJS()
Add the HTMLForm-specific JavaScript, if it hasn't been done already.
Definition: HTMLForm.php:306
HTMLForm\$mTableId
$mTableId
Definition: HTMLForm.php:148
HTMLForm\$mSubmitName
$mSubmitName
Definition: HTMLForm.php:151
ContextSource\getUser
getUser()
Get the User object.
Definition: ContextSource.php:132
HTMLForm\getAction
getAction()
Get the value for the action attribute of the form.
Definition: HTMLForm.php:1360
HTMLForm\setMethod
setMethod( $method='post')
Set the method used to submit the form.
Definition: HTMLForm.php:1146
HTMLForm\$mButtons
$mButtons
Definition: HTMLForm.php:166
true
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 true
Definition: hooks.txt:1530
Status\isGood
isGood()
Returns whether the operation completed and didn't have any error or warnings.
Definition: Status.php:100
HTMLForm\__construct
__construct( $descriptor, $context=null, $messagePrefix='')
Build a new HTMLForm from an array of field attributes.
Definition: HTMLForm.php:203
Status
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: Status.php:40
HTMLForm\setSubmitText
setSubmitText( $t)
Set the text for the submit button.
Definition: HTMLForm.php:962
Linker\tooltipAndAccesskeyAttribs
static tooltipAndAccesskeyAttribs( $name)
Returns the attributes for the tooltip and access key.
Definition: Linker.php:2298
HTMLForm\trySubmit
trySubmit()
Validate all the fields, and call the submission callback function if everything is kosher.
Definition: HTMLForm.php:441
MWException
MediaWiki exception.
Definition: MWException.php:26
HTMLForm\$mAction
bool string $mAction
Form action URL.
Definition: HTMLForm.php:162
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1127
Html\element
static element( $element, $attribs=array(), $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:148
HTMLForm\addButton
addButton( $name, $value, $id=null, $attribs=null)
Add a button to the form.
Definition: HTMLForm.php:692
ContextSource\getOutput
getOutput()
Get the OutputPage object.
Definition: ContextSource.php:122
HTMLForm\setSubmitID
setSubmitID( $t)
Set the id for the submit button.
Definition: HTMLForm.php:1022
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:30
HTMLFormField
The parent class to generate form fields.
Definition: HTMLFormField.php:7
wfMessage
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 after in associative array form externallinks including delete and has completed for all link tables default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
HTMLForm\setMessagePrefix
setMessagePrefix( $p)
Set the prefix for various default messages.
Definition: HTMLForm.php:1110
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:482
HTMLForm\isVForm
isVForm()
Test if displayFormat is 'vform'.
Definition: HTMLForm.php:297
HTMLForm\$mId
$mId
Definition: HTMLForm.php:147
HTMLForm\$mSectionFooters
$mSectionFooters
Definition: HTMLForm.php:145
ContextSource\setContext
setContext(IContextSource $context)
Set the IContextSource object.
Definition: ContextSource.php:57
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:146
Sanitizer\escapeId
static escapeId( $id, $options=array())
Given a value, escape it so that it can be used in an id attribute and return it.
Definition: Sanitizer.php:1099
$section
$section
Definition: Utf8Test.php:88
HTMLForm\$mFooter
$mFooter
Definition: HTMLForm.php:143
HTMLForm\$mMethod
$mMethod
Definition: HTMLForm.php:156
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
$value
$value
Definition: styleTest.css.php:45
HTMLForm\setId
setId( $id)
Definition: HTMLForm.php:1064
HTMLForm\setWrapperLegend
setWrapperLegend( $legend)
Prompt the whole form to be wrapped in a "<fieldset>", with this text as its "<legend>" element.
Definition: HTMLForm.php:1080
HTMLForm\displaySection
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
Definition: HTMLForm.php:1169
HTMLForm\$mSubmitCallback
$mSubmitCallback
Definition: HTMLForm.php:138
HTMLForm\loadData
loadData()
Construct the form fields from the Descriptor array.
Definition: HTMLForm.php:1276
HTMLForm\loadInputFromParameters
static loadInputFromParameters( $fieldname, $descriptor)
Initialise a new Object for the field.
Definition: HTMLForm.php:351
HTMLForm\setValidationErrorMessage
setValidationErrorMessage( $msg)
Set a message to display on a validation error.
Definition: HTMLForm.php:496
IContextSource
Interface for objects which can provide a context on request.
Definition: IContextSource.php:29
HTMLForm\setSubmitTextMsg
setSubmitTextMsg( $msg)
Set the text for the submit button to a message.
Definition: HTMLForm.php:976
$wgArticlePath
$wgArticlePath
Definition: img_auth.php:48
Title
Represents a title within MediaWiki.
Definition: Title.php:35
HTMLForm\$mPre
$mPre
Definition: HTMLForm.php:141
HTMLForm\getHTML
getHTML( $submitResult)
Returns the raw HTML generated by the form.
Definition: HTMLForm.php:721
HTMLForm\getSubmitText
getSubmitText()
Get the text for the submit button, either customised or a default.
Definition: HTMLForm.php:986
HTMLForm\addHiddenFields
addHiddenFields(array $fields)
Add an array of hidden fields to the output.
Definition: HTMLForm.php:674
HTMLForm\setWrapperLegendMsg
setWrapperLegendMsg( $msg)
Prompt the whole form to be wrapped in a "<fieldset>", with this message as its "<legend>" element.
Definition: HTMLForm.php:1095
HTMLForm\$mValidationErrorMessage
$mValidationErrorMessage
Definition: HTMLForm.php:139
HTMLForm\setAction
setAction( $action)
Set the value for the action attribute of the form.
Definition: HTMLForm.php:1347
HTMLForm\$mHeader
$mHeader
Definition: HTMLForm.php:142
HTMLForm\setTitle
setTitle( $t)
Set the title for form submission.
Definition: HTMLForm.php:1123
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:1053
HTMLForm\$mMessagePrefix
$mMessagePrefix
Definition: HTMLForm.php:130
HTMLForm\displayForm
displayForm( $submitResult)
Display the form (sending to the context's OutputPage object), with an appropriate error message or s...
Definition: HTMLForm.php:710
HTMLForm\$mHiddenFields
$mHiddenFields
Definition: HTMLForm.php:165
HTMLForm\getTitle
getTitle()
Get the title.
Definition: HTMLForm.php:1133
HTMLForm\$displayFormat
String $displayFormat
Format in which to display form.
Definition: HTMLForm.php:183
Xml\submitButton
static submitButton( $value, $attribs=array())
Convenience function to build an HTML submit button.
Definition: Xml.php:463
HTMLForm\filterDataForSubmit
filterDataForSubmit( $data)
Overload this if you want to apply special filtration routines to the form as a whole,...
Definition: HTMLForm.php:1321
HTMLForm\$availableDisplayFormats
Array $availableDisplayFormats
Available formats in which to display the form.
Definition: HTMLForm.php:188
HTMLForm\getMethod
getMethod()
Definition: HTMLForm.php:1152
HTMLForm\addPreText
addPreText( $msg)
Add introductory text.
Definition: HTMLForm.php:536
$t
$t
Definition: testCompression.php:65
HTMLForm\addPostText
addPostText( $msg)
Add text to the end of the display.
Definition: HTMLForm.php:629
$error
usually copyright or history_copyright This message must be in HTML not wikitext $subpages will be ignored and the rest of subPageSubtitle() will run. 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink' whether MediaWiki currently thinks this is a CSS JS page Hooks may change this value to override the return value of Title::isCssOrJsPage(). 'TitleIsAlwaysKnown' whether MediaWiki currently thinks this page is known isMovable() always returns false. $title whether MediaWiki currently thinks this page is movable Hooks may change this value to override the return value of Title::isMovable(). 'TitleIsWikitextPage' whether MediaWiki currently thinks this is a wikitext page Hooks may change this value to override the return value of Title::isWikitextPage() 'TitleMove' use UploadVerification and UploadVerifyFile instead where the first element is the message key and the remaining elements are used as parameters to the message based on mime etc Preferred in most cases over UploadVerification object with all info about the upload string as detected by MediaWiki Handlers will typically only apply for specific mime types object & $error
Definition: hooks.txt:2573
HTMLForm\formatErrors
static formatErrors( $errors)
Format a stack of error messages into a single HTML string.
Definition: HTMLForm.php:932
Html\rawElement
static rawElement( $element, $attribs=array(), $contents='')
Returns an HTML element in a string.
Definition: Html.php:124
$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:1530
HTMLForm\suppressReset
suppressReset( $suppressReset=true)
Stop a reset button being shown for this form.
Definition: HTMLForm.php:1306
$res
$res
Definition: database.txt:21
HTMLForm\$mFlatFields
HTMLFormField[] $mFlatFields
Definition: HTMLForm.php:132
HTMLForm\getButtons
getButtons()
Get the submit and (potentially) reset buttons.
Definition: HTMLForm.php:815
Xml\fieldset
static fieldset( $legend=false, $content=false, $attribs=array())
Shortcut for creating fieldsets.
Definition: Xml.php:563
HTMLForm\addFooterText
addFooterText( $msg, $section=null)
Add footer text, inside the form.
Definition: HTMLForm.php:590
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms.
Definition: HTMLForm.php:100