MediaWiki REL1_28
HTMLForm.php
Go to the documentation of this file.
1<?php
2
128class HTMLForm extends ContextSource {
129 // A mapping of 'type' inputs onto standard HTMLFormField subclasses
130 public static $typeMappings = [
131 'api' => 'HTMLApiField',
132 'text' => 'HTMLTextField',
133 'textwithbutton' => 'HTMLTextFieldWithButton',
134 'textarea' => 'HTMLTextAreaField',
135 'select' => 'HTMLSelectField',
136 'combobox' => 'HTMLComboboxField',
137 'radio' => 'HTMLRadioField',
138 'multiselect' => 'HTMLMultiSelectField',
139 'limitselect' => 'HTMLSelectLimitField',
140 'check' => 'HTMLCheckField',
141 'toggle' => 'HTMLCheckField',
142 'int' => 'HTMLIntField',
143 'float' => 'HTMLFloatField',
144 'info' => 'HTMLInfoField',
145 'selectorother' => 'HTMLSelectOrOtherField',
146 'selectandother' => 'HTMLSelectAndOtherField',
147 'namespaceselect' => 'HTMLSelectNamespace',
148 'namespaceselectwithbutton' => 'HTMLSelectNamespaceWithButton',
149 'tagfilter' => 'HTMLTagFilter',
150 'submit' => 'HTMLSubmitField',
151 'hidden' => 'HTMLHiddenField',
152 'edittools' => 'HTMLEditTools',
153 'checkmatrix' => 'HTMLCheckMatrix',
154 'cloner' => 'HTMLFormFieldCloner',
155 'autocompleteselect' => 'HTMLAutoCompleteSelectField',
156 'date' => 'HTMLDateTimeField',
157 'time' => 'HTMLDateTimeField',
158 'datetime' => 'HTMLDateTimeField',
159 // HTMLTextField will output the correct type="" attribute automagically.
160 // There are about four zillion other HTML5 input types, like range, but
161 // we don't use those at the moment, so no point in adding all of them.
162 'email' => 'HTMLTextField',
163 'password' => 'HTMLTextField',
164 'url' => 'HTMLTextField',
165 'title' => 'HTMLTitleTextField',
166 'user' => 'HTMLUserTextField',
167 ];
168
170
172
174 protected $mFlatFields;
175
176 protected $mFieldTree;
177 protected $mShowReset = false;
178 protected $mShowSubmit = true;
179 protected $mSubmitFlags = [ 'primary', 'progressive' ];
180 protected $mShowCancel = false;
181 protected $mCancelTarget;
182
185
186 protected $mPre = '';
187 protected $mHeader = '';
188 protected $mFooter = '';
189 protected $mSectionHeaders = [];
190 protected $mSectionFooters = [];
191 protected $mPost = '';
192 protected $mId;
193 protected $mName;
194 protected $mTableId = '';
195
196 protected $mSubmitID;
197 protected $mSubmitName;
198 protected $mSubmitText;
200
202 protected $mTitle;
203 protected $mMethod = 'post';
204 protected $mWasSubmitted = false;
205
211 protected $mAction = false;
212
218 protected $mAutocomplete = false;
219
220 protected $mUseMultipart = false;
221 protected $mHiddenFields = [];
222 protected $mButtons = [];
223
224 protected $mWrapperLegend = false;
225
230 protected $mTokenSalt = '';
231
239 protected $mSubSectionBeforeFields = true;
240
246 protected $displayFormat = 'table';
247
253 'table',
254 'div',
255 'raw',
256 'inline',
257 ];
258
264 'vform',
265 'ooui',
266 ];
267
275 public static function factory( $displayFormat/*, $arguments...*/ ) {
276 $arguments = func_get_args();
277 array_shift( $arguments );
278
279 switch ( $displayFormat ) {
280 case 'vform':
281 return ObjectFactory::constructClassInstance( VFormHTMLForm::class, $arguments );
282 case 'ooui':
283 return ObjectFactory::constructClassInstance( OOUIHTMLForm::class, $arguments );
284 default:
286 $form = ObjectFactory::constructClassInstance( HTMLForm::class, $arguments );
287 $form->setDisplayFormat( $displayFormat );
288 return $form;
289 }
290 }
291
300 public function __construct( $descriptor, /*IContextSource*/ $context = null,
301 $messagePrefix = ''
302 ) {
303 if ( $context instanceof IContextSource ) {
304 $this->setContext( $context );
305 $this->mTitle = false; // We don't need them to set a title
306 $this->mMessagePrefix = $messagePrefix;
307 } elseif ( $context === null && $messagePrefix !== '' ) {
308 $this->mMessagePrefix = $messagePrefix;
309 } elseif ( is_string( $context ) && $messagePrefix === '' ) {
310 // B/C since 1.18
311 // it's actually $messagePrefix
312 $this->mMessagePrefix = $context;
313 }
314
315 // Evil hack for mobile :(
316 if (
317 !$this->getConfig()->get( 'HTMLFormAllowTableFormat' )
318 && $this->displayFormat === 'table'
319 ) {
320 $this->displayFormat = 'div';
321 }
322
323 // Expand out into a tree.
324 $loadedDescriptor = [];
325 $this->mFlatFields = [];
326
327 foreach ( $descriptor as $fieldname => $info ) {
328 $section = isset( $info['section'] )
329 ? $info['section']
330 : '';
331
332 if ( isset( $info['type'] ) && $info['type'] === 'file' ) {
333 $this->mUseMultipart = true;
334 }
335
336 $field = static::loadInputFromParameters( $fieldname, $info, $this );
337
338 $setSection =& $loadedDescriptor;
339 if ( $section ) {
340 $sectionParts = explode( '/', $section );
341
342 while ( count( $sectionParts ) ) {
343 $newName = array_shift( $sectionParts );
344
345 if ( !isset( $setSection[$newName] ) ) {
346 $setSection[$newName] = [];
347 }
348
349 $setSection =& $setSection[$newName];
350 }
351 }
352
353 $setSection[$fieldname] = $field;
354 $this->mFlatFields[$fieldname] = $field;
355 }
356
357 $this->mFieldTree = $loadedDescriptor;
358 }
359
364 public function hasField( $fieldname ) {
365 return isset( $this->mFlatFields[$fieldname] );
366 }
367
373 public function getField( $fieldname ) {
374 if ( !$this->hasField( $fieldname ) ) {
375 throw new DomainException( __METHOD__ . ': no field named ' . $fieldname );
376 }
377 return $this->mFlatFields[$fieldname];
378 }
379
390 public function setDisplayFormat( $format ) {
391 if (
392 in_array( $format, $this->availableSubclassDisplayFormats, true ) ||
393 in_array( $this->displayFormat, $this->availableSubclassDisplayFormats, true )
394 ) {
395 throw new MWException( 'Cannot change display format after creation, ' .
396 'use HTMLForm::factory() instead' );
397 }
398
399 if ( !in_array( $format, $this->availableDisplayFormats, true ) ) {
400 throw new MWException( 'Display format must be one of ' .
401 print_r( $this->availableDisplayFormats, true ) );
402 }
403
404 // Evil hack for mobile :(
405 if ( !$this->getConfig()->get( 'HTMLFormAllowTableFormat' ) && $format === 'table' ) {
406 $format = 'div';
407 }
408
409 $this->displayFormat = $format;
410
411 return $this;
412 }
413
419 public function getDisplayFormat() {
421 }
422
429 public function isVForm() {
430 wfDeprecated( __METHOD__, '1.25' );
431 return false;
432 }
433
450 public static function getClassFromDescriptor( $fieldname, &$descriptor ) {
451 if ( isset( $descriptor['class'] ) ) {
452 $class = $descriptor['class'];
453 } elseif ( isset( $descriptor['type'] ) ) {
454 $class = static::$typeMappings[$descriptor['type']];
455 $descriptor['class'] = $class;
456 } else {
457 $class = null;
458 }
459
460 if ( !$class ) {
461 throw new MWException( "Descriptor with no class for $fieldname: "
462 . print_r( $descriptor, true ) );
463 }
464
465 return $class;
466 }
467
478 public static function loadInputFromParameters( $fieldname, $descriptor,
479 HTMLForm $parent = null
480 ) {
481 $class = static::getClassFromDescriptor( $fieldname, $descriptor );
482
483 $descriptor['fieldname'] = $fieldname;
484 if ( $parent ) {
485 $descriptor['parent'] = $parent;
486 }
487
488 # @todo This will throw a fatal error whenever someone try to use
489 # 'class' to feed a CSS class instead of 'cssclass'. Would be
490 # great to avoid the fatal error and show a nice error.
491 return new $class( $descriptor );
492 }
493
503 public function prepareForm() {
504 # Check if we have the info we need
505 if ( !$this->mTitle instanceof Title && $this->mTitle !== false ) {
506 throw new MWException( 'You must call setTitle() on an HTMLForm' );
507 }
508
509 # Load data from the request.
510 if (
511 $this->mFormIdentifier === null ||
512 $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier
513 ) {
514 $this->loadData();
515 } else {
516 $this->mFieldData = [];
517 }
518
519 return $this;
520 }
521
526 public function tryAuthorizedSubmit() {
527 $result = false;
528
529 $identOkay = false;
530 if ( $this->mFormIdentifier === null ) {
531 $identOkay = true;
532 } else {
533 $identOkay = $this->getRequest()->getVal( 'wpFormIdentifier' ) === $this->mFormIdentifier;
534 }
535
536 $tokenOkay = false;
537 if ( $this->getMethod() !== 'post' ) {
538 $tokenOkay = true; // no session check needed
539 } elseif ( $this->getRequest()->wasPosted() ) {
540 $editToken = $this->getRequest()->getVal( 'wpEditToken' );
541 if ( $this->getUser()->isLoggedIn() || $editToken !== null ) {
542 // Session tokens for logged-out users have no security value.
543 // However, if the user gave one, check it in order to give a nice
544 // "session expired" error instead of "permission denied" or such.
545 $tokenOkay = $this->getUser()->matchEditToken( $editToken, $this->mTokenSalt );
546 } else {
547 $tokenOkay = true;
548 }
549 }
550
551 if ( $tokenOkay && $identOkay ) {
552 $this->mWasSubmitted = true;
553 $result = $this->trySubmit();
554 }
555
556 return $result;
557 }
558
565 public function show() {
566 $this->prepareForm();
567
568 $result = $this->tryAuthorizedSubmit();
569 if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
570 return $result;
571 }
572
573 $this->displayForm( $result );
574
575 return false;
576 }
577
583 public function showAlways() {
584 $this->prepareForm();
585
586 $result = $this->tryAuthorizedSubmit();
587
588 $this->displayForm( $result );
589
590 return $result;
591 }
592
604 public function trySubmit() {
605 $valid = true;
606 $hoistedErrors = [];
607 $hoistedErrors[] = isset( $this->mValidationErrorMessage )
608 ? $this->mValidationErrorMessage
609 : [ 'htmlform-invalid-input' ];
610
611 $this->mWasSubmitted = true;
612
613 # Check for cancelled submission
614 foreach ( $this->mFlatFields as $fieldname => $field ) {
615 if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
616 continue;
617 }
618 if ( $field->cancelSubmit( $this->mFieldData[$fieldname], $this->mFieldData ) ) {
619 $this->mWasSubmitted = false;
620 return false;
621 }
622 }
623
624 # Check for validation
625 foreach ( $this->mFlatFields as $fieldname => $field ) {
626 if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
627 continue;
628 }
629 if ( $field->isHidden( $this->mFieldData ) ) {
630 continue;
631 }
632 $res = $field->validate( $this->mFieldData[$fieldname], $this->mFieldData );
633 if ( $res !== true ) {
634 $valid = false;
635 if ( $res !== false && !$field->canDisplayErrors() ) {
636 $hoistedErrors[] = [ 'rawmessage', $res ];
637 }
638 }
639 }
640
641 if ( !$valid ) {
642 if ( count( $hoistedErrors ) === 1 ) {
643 $hoistedErrors = $hoistedErrors[0];
644 }
645 return $hoistedErrors;
646 }
647
648 $callback = $this->mSubmitCallback;
649 if ( !is_callable( $callback ) ) {
650 throw new MWException( 'HTMLForm: no submit callback provided. Use ' .
651 'setSubmitCallback() to set one.' );
652 }
653
654 $data = $this->filterDataForSubmit( $this->mFieldData );
655
656 $res = call_user_func( $callback, $data, $this );
657 if ( $res === false ) {
658 $this->mWasSubmitted = false;
659 }
660
661 return $res;
662 }
663
675 public function wasSubmitted() {
677 }
678
689 public function setSubmitCallback( $cb ) {
690 $this->mSubmitCallback = $cb;
691
692 return $this;
693 }
694
703 public function setValidationErrorMessage( $msg ) {
704 $this->mValidationErrorMessage = $msg;
705
706 return $this;
707 }
708
716 public function setIntro( $msg ) {
717 $this->setPreText( $msg );
718
719 return $this;
720 }
721
730 public function setPreText( $msg ) {
731 $this->mPre = $msg;
732
733 return $this;
734 }
735
743 public function addPreText( $msg ) {
744 $this->mPre .= $msg;
745
746 return $this;
747 }
748
757 public function addHeaderText( $msg, $section = null ) {
758 if ( $section === null ) {
759 $this->mHeader .= $msg;
760 } else {
761 if ( !isset( $this->mSectionHeaders[$section] ) ) {
762 $this->mSectionHeaders[$section] = '';
763 }
764 $this->mSectionHeaders[$section] .= $msg;
765 }
766
767 return $this;
768 }
769
779 public function setHeaderText( $msg, $section = null ) {
780 if ( $section === null ) {
781 $this->mHeader = $msg;
782 } else {
783 $this->mSectionHeaders[$section] = $msg;
784 }
785
786 return $this;
787 }
788
796 public function getHeaderText( $section = null ) {
797 if ( $section === null ) {
798 return $this->mHeader;
799 } else {
800 return isset( $this->mSectionHeaders[$section] ) ? $this->mSectionHeaders[$section] : '';
801 }
802 }
803
812 public function addFooterText( $msg, $section = null ) {
813 if ( $section === null ) {
814 $this->mFooter .= $msg;
815 } else {
816 if ( !isset( $this->mSectionFooters[$section] ) ) {
817 $this->mSectionFooters[$section] = '';
818 }
819 $this->mSectionFooters[$section] .= $msg;
820 }
821
822 return $this;
823 }
824
834 public function setFooterText( $msg, $section = null ) {
835 if ( $section === null ) {
836 $this->mFooter = $msg;
837 } else {
838 $this->mSectionFooters[$section] = $msg;
839 }
840
841 return $this;
842 }
843
851 public function getFooterText( $section = null ) {
852 if ( $section === null ) {
853 return $this->mFooter;
854 } else {
855 return isset( $this->mSectionFooters[$section] ) ? $this->mSectionFooters[$section] : '';
856 }
857 }
858
866 public function addPostText( $msg ) {
867 $this->mPost .= $msg;
868
869 return $this;
870 }
871
879 public function setPostText( $msg ) {
880 $this->mPost = $msg;
881
882 return $this;
883 }
884
894 public function addHiddenField( $name, $value, array $attribs = [] ) {
895 $attribs += [ 'name' => $name ];
896 $this->mHiddenFields[] = [ $value, $attribs ];
897
898 return $this;
899 }
900
911 public function addHiddenFields( array $fields ) {
912 foreach ( $fields as $name => $value ) {
913 $this->mHiddenFields[] = [ $value, [ 'name' => $name ] ];
914 }
915
916 return $this;
917 }
918
943 public function addButton( $data ) {
944 if ( !is_array( $data ) ) {
945 $args = func_get_args();
946 if ( count( $args ) < 2 || count( $args ) > 4 ) {
947 throw new InvalidArgumentException(
948 'Incorrect number of arguments for deprecated calling style'
949 );
950 }
951 $data = [
952 'name' => $args[0],
953 'value' => $args[1],
954 'id' => isset( $args[2] ) ? $args[2] : null,
955 'attribs' => isset( $args[3] ) ? $args[3] : null,
956 ];
957 } else {
958 if ( !isset( $data['name'] ) ) {
959 throw new InvalidArgumentException( 'A name is required' );
960 }
961 if ( !isset( $data['value'] ) ) {
962 throw new InvalidArgumentException( 'A value is required' );
963 }
964 }
965 $this->mButtons[] = $data + [
966 'id' => null,
967 'attribs' => null,
968 'flags' => null,
969 'framed' => true,
970 ];
971
972 return $this;
973 }
974
984 public function setTokenSalt( $salt ) {
985 $this->mTokenSalt = $salt;
986
987 return $this;
988 }
989
1002 public function displayForm( $submitResult ) {
1003 $this->getOutput()->addHTML( $this->getHTML( $submitResult ) );
1004 }
1005
1013 public function getHTML( $submitResult ) {
1014 # For good measure (it is the default)
1015 $this->getOutput()->preventClickjacking();
1016 $this->getOutput()->addModules( 'mediawiki.htmlform' );
1017 $this->getOutput()->addModuleStyles( 'mediawiki.htmlform.styles' );
1018
1019 $html = ''
1020 . $this->getErrorsOrWarnings( $submitResult, 'error' )
1021 . $this->getErrorsOrWarnings( $submitResult, 'warning' )
1022 . $this->getHeaderText()
1023 . $this->getBody()
1024 . $this->getHiddenFields()
1025 . $this->getButtons()
1026 . $this->getFooterText();
1027
1028 $html = $this->wrapForm( $html );
1029
1030 return '' . $this->mPre . $html . $this->mPost;
1031 }
1032
1037 protected function getFormAttributes() {
1038 # Use multipart/form-data
1039 $encType = $this->mUseMultipart
1040 ? 'multipart/form-data'
1041 : 'application/x-www-form-urlencoded';
1042 # Attributes
1043 $attribs = [
1044 'action' => $this->getAction(),
1045 'method' => $this->getMethod(),
1046 'enctype' => $encType,
1047 ];
1048 if ( $this->mId ) {
1049 $attribs['id'] = $this->mId;
1050 }
1051 if ( $this->mAutocomplete ) {
1052 $attribs['autocomplete'] = $this->mAutocomplete;
1053 }
1054 if ( $this->mName ) {
1055 $attribs['name'] = $this->mName;
1056 }
1057 return $attribs;
1058 }
1059
1067 public function wrapForm( $html ) {
1068 # Include a <fieldset> wrapper for style, if requested.
1069 if ( $this->mWrapperLegend !== false ) {
1070 $legend = is_string( $this->mWrapperLegend ) ? $this->mWrapperLegend : false;
1071 $html = Xml::fieldset( $legend, $html );
1072 }
1073
1074 return Html::rawElement(
1075 'form',
1076 $this->getFormAttributes() + [ 'class' => 'visualClear' ],
1077 $html
1078 );
1079 }
1080
1085 public function getHiddenFields() {
1086 $html = '';
1087 if ( $this->mFormIdentifier !== null ) {
1088 $html .= Html::hidden(
1089 'wpFormIdentifier',
1090 $this->mFormIdentifier
1091 ) . "\n";
1092 }
1093 if ( $this->getMethod() === 'post' ) {
1094 $html .= Html::hidden(
1095 'wpEditToken',
1096 $this->getUser()->getEditToken( $this->mTokenSalt ),
1097 [ 'id' => 'wpEditToken' ]
1098 ) . "\n";
1099 $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1100 }
1101
1102 $articlePath = $this->getConfig()->get( 'ArticlePath' );
1103 if ( strpos( $articlePath, '?' ) !== false && $this->getMethod() === 'get' ) {
1104 $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
1105 }
1106
1107 foreach ( $this->mHiddenFields as $data ) {
1108 list( $value, $attribs ) = $data;
1109 $html .= Html::hidden( $attribs['name'], $value, $attribs ) . "\n";
1110 }
1111
1112 return $html;
1113 }
1114
1119 public function getButtons() {
1120 $buttons = '';
1121 $useMediaWikiUIEverywhere = $this->getConfig()->get( 'UseMediaWikiUIEverywhere' );
1122
1123 if ( $this->mShowSubmit ) {
1124 $attribs = [];
1125
1126 if ( isset( $this->mSubmitID ) ) {
1127 $attribs['id'] = $this->mSubmitID;
1128 }
1129
1130 if ( isset( $this->mSubmitName ) ) {
1131 $attribs['name'] = $this->mSubmitName;
1132 }
1133
1134 if ( isset( $this->mSubmitTooltip ) ) {
1135 $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
1136 }
1137
1138 $attribs['class'] = [ 'mw-htmlform-submit' ];
1139
1140 if ( $useMediaWikiUIEverywhere ) {
1141 foreach ( $this->mSubmitFlags as $flag ) {
1142 $attribs['class'][] = 'mw-ui-' . $flag;
1143 }
1144 $attribs['class'][] = 'mw-ui-button';
1145 }
1146
1147 $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
1148 }
1149
1150 if ( $this->mShowReset ) {
1151 $buttons .= Html::element(
1152 'input',
1153 [
1154 'type' => 'reset',
1155 'value' => $this->msg( 'htmlform-reset' )->text(),
1156 'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null,
1157 ]
1158 ) . "\n";
1159 }
1160
1161 if ( $this->mShowCancel ) {
1162 $target = $this->mCancelTarget ?: Title::newMainPage();
1163 if ( $target instanceof Title ) {
1164 $target = $target->getLocalURL();
1165 }
1166 $buttons .= Html::element(
1167 'a',
1168 [
1169 'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null,
1170 'href' => $target,
1171 ],
1172 $this->msg( 'cancel' )->text()
1173 ) . "\n";
1174 }
1175
1176 // IE<8 has bugs with <button>, so we'll need to avoid them.
1177 $isBadIE = preg_match( '/MSIE [1-7]\./i', $this->getRequest()->getHeader( 'User-Agent' ) );
1178
1179 foreach ( $this->mButtons as $button ) {
1180 $attrs = [
1181 'type' => 'submit',
1182 'name' => $button['name'],
1183 'value' => $button['value']
1184 ];
1185
1186 if ( isset( $button['label-message'] ) ) {
1187 $label = $this->getMessage( $button['label-message'] )->parse();
1188 } elseif ( isset( $button['label'] ) ) {
1189 $label = htmlspecialchars( $button['label'] );
1190 } elseif ( isset( $button['label-raw'] ) ) {
1191 $label = $button['label-raw'];
1192 } else {
1193 $label = htmlspecialchars( $button['value'] );
1194 }
1195
1196 if ( $button['attribs'] ) {
1197 $attrs += $button['attribs'];
1198 }
1199
1200 if ( isset( $button['id'] ) ) {
1201 $attrs['id'] = $button['id'];
1202 }
1203
1204 if ( $useMediaWikiUIEverywhere ) {
1205 $attrs['class'] = isset( $attrs['class'] ) ? (array)$attrs['class'] : [];
1206 $attrs['class'][] = 'mw-ui-button';
1207 }
1208
1209 if ( $isBadIE ) {
1210 $buttons .= Html::element( 'input', $attrs ) . "\n";
1211 } else {
1212 $buttons .= Html::rawElement( 'button', $attrs, $label ) . "\n";
1213 }
1214 }
1215
1216 if ( !$buttons ) {
1217 return '';
1218 }
1219
1220 return Html::rawElement( 'span',
1221 [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n";
1222 }
1223
1228 public function getBody() {
1229 return $this->displaySection( $this->mFieldTree, $this->mTableId );
1230 }
1231
1241 public function getErrors( $errors ) {
1242 wfDeprecated( __METHOD__ );
1243 return $this->getErrorsOrWarnings( $errors, 'error' );
1244 }
1245
1254 public function getErrorsOrWarnings( $elements, $elementsType ) {
1255 if ( !in_array( $elementsType, [ 'error', 'warning' ], true ) ) {
1256 throw new DomainException( $elementsType . ' is not a valid type.' );
1257 }
1258 $elementstr = false;
1259 if ( $elements instanceof Status ) {
1260 list( $errorStatus, $warningStatus ) = $elements->splitByErrorType();
1261 $status = $elementsType === 'error' ? $errorStatus : $warningStatus;
1262 if ( $status->isGood() ) {
1263 $elementstr = '';
1264 } else {
1265 $elementstr = $this->getOutput()->parse(
1266 $status->getWikiText()
1267 );
1268 }
1269 } elseif ( is_array( $elements ) && $elementsType === 'error' ) {
1270 $elementstr = $this->formatErrors( $elements );
1271 } elseif ( $elementsType === 'error' ) {
1272 $elementstr = $elements;
1273 }
1274
1275 return $elementstr
1276 ? Html::rawElement( 'div', [ 'class' => $elementsType ], $elementstr )
1277 : '';
1278 }
1279
1287 public function formatErrors( $errors ) {
1288 $errorstr = '';
1289
1290 foreach ( $errors as $error ) {
1291 $errorstr .= Html::rawElement(
1292 'li',
1293 [],
1294 $this->getMessage( $error )->parse()
1295 );
1296 }
1297
1298 $errorstr = Html::rawElement( 'ul', [], $errorstr );
1299
1300 return $errorstr;
1301 }
1302
1310 public function setSubmitText( $t ) {
1311 $this->mSubmitText = $t;
1312
1313 return $this;
1314 }
1315
1322 public function setSubmitDestructive() {
1323 $this->mSubmitFlags = [ 'destructive', 'primary' ];
1324
1325 return $this;
1326 }
1327
1334 public function setSubmitProgressive() {
1335 $this->mSubmitFlags = [ 'progressive', 'primary' ];
1336
1337 return $this;
1338 }
1339
1348 public function setSubmitTextMsg( $msg ) {
1349 if ( !$msg instanceof Message ) {
1350 $msg = $this->msg( $msg );
1351 }
1352 $this->setSubmitText( $msg->text() );
1353
1354 return $this;
1355 }
1356
1361 public function getSubmitText() {
1362 return $this->mSubmitText ?: $this->msg( 'htmlform-submit' )->text();
1363 }
1364
1370 public function setSubmitName( $name ) {
1371 $this->mSubmitName = $name;
1372
1373 return $this;
1374 }
1375
1381 public function setSubmitTooltip( $name ) {
1382 $this->mSubmitTooltip = $name;
1383
1384 return $this;
1385 }
1386
1395 public function setSubmitID( $t ) {
1396 $this->mSubmitID = $t;
1397
1398 return $this;
1399 }
1400
1416 public function setFormIdentifier( $ident ) {
1417 $this->mFormIdentifier = $ident;
1418
1419 return $this;
1420 }
1421
1432 public function suppressDefaultSubmit( $suppressSubmit = true ) {
1433 $this->mShowSubmit = !$suppressSubmit;
1434
1435 return $this;
1436 }
1437
1444 public function showCancel( $show = true ) {
1445 $this->mShowCancel = $show;
1446 return $this;
1447 }
1448
1455 public function setCancelTarget( $target ) {
1456 $this->mCancelTarget = $target;
1457 return $this;
1458 }
1459
1469 public function setTableId( $id ) {
1470 $this->mTableId = $id;
1471
1472 return $this;
1473 }
1474
1480 public function setId( $id ) {
1481 $this->mId = $id;
1482
1483 return $this;
1484 }
1485
1490 public function setName( $name ) {
1491 $this->mName = $name;
1492
1493 return $this;
1494 }
1495
1507 public function setWrapperLegend( $legend ) {
1508 $this->mWrapperLegend = $legend;
1509
1510 return $this;
1511 }
1512
1522 public function setWrapperLegendMsg( $msg ) {
1523 if ( !$msg instanceof Message ) {
1524 $msg = $this->msg( $msg );
1525 }
1526 $this->setWrapperLegend( $msg->text() );
1527
1528 return $this;
1529 }
1530
1540 public function setMessagePrefix( $p ) {
1541 $this->mMessagePrefix = $p;
1542
1543 return $this;
1544 }
1545
1553 public function setTitle( $t ) {
1554 $this->mTitle = $t;
1555
1556 return $this;
1557 }
1558
1563 public function getTitle() {
1564 return $this->mTitle === false
1565 ? $this->getContext()->getTitle()
1566 : $this->mTitle;
1567 }
1568
1576 public function setMethod( $method = 'post' ) {
1577 $this->mMethod = strtolower( $method );
1578
1579 return $this;
1580 }
1581
1585 public function getMethod() {
1586 return $this->mMethod;
1587 }
1588
1597 protected function wrapFieldSetSection( $legend, $section, $attributes ) {
1598 return Xml::fieldset( $legend, $section, $attributes ) . "\n";
1599 }
1600
1617 public function displaySection( $fields,
1618 $sectionName = '',
1619 $fieldsetIDPrefix = '',
1620 &$hasUserVisibleFields = false
1621 ) {
1622 if ( $this->mFieldData === null ) {
1623 throw new LogicException( 'HTMLForm::displaySection() called on uninitialized field data. '
1624 . 'You probably called displayForm() without calling prepareForm() first.' );
1625 }
1626
1628
1629 $html = [];
1630 $subsectionHtml = '';
1631 $hasLabel = false;
1632
1633 // Conveniently, PHP method names are case-insensitive.
1634 // For grep: this can call getDiv, getRaw, getInline, getVForm, getOOUI
1635 $getFieldHtmlMethod = $displayFormat === 'table' ? 'getTableRow' : ( 'get' . $displayFormat );
1636
1637 foreach ( $fields as $key => $value ) {
1638 if ( $value instanceof HTMLFormField ) {
1639 $v = array_key_exists( $key, $this->mFieldData )
1640 ? $this->mFieldData[$key]
1641 : $value->getDefault();
1642
1643 $retval = $value->$getFieldHtmlMethod( $v );
1644
1645 // check, if the form field should be added to
1646 // the output.
1647 if ( $value->hasVisibleOutput() ) {
1648 $html[] = $retval;
1649
1650 $labelValue = trim( $value->getLabel() );
1651 if ( $labelValue !== '&#160;' && $labelValue !== '' ) {
1652 $hasLabel = true;
1653 }
1654
1655 $hasUserVisibleFields = true;
1656 }
1657 } elseif ( is_array( $value ) ) {
1658 $subsectionHasVisibleFields = false;
1659 $section =
1660 $this->displaySection( $value,
1661 "mw-htmlform-$key",
1662 "$fieldsetIDPrefix$key-",
1663 $subsectionHasVisibleFields );
1664 $legend = null;
1665
1666 if ( $subsectionHasVisibleFields === true ) {
1667 // Display the section with various niceties.
1668 $hasUserVisibleFields = true;
1669
1670 $legend = $this->getLegend( $key );
1671
1672 $section = $this->getHeaderText( $key ) .
1673 $section .
1674 $this->getFooterText( $key );
1675
1676 $attributes = [];
1677 if ( $fieldsetIDPrefix ) {
1678 $attributes['id'] = Sanitizer::escapeId( "$fieldsetIDPrefix$key" );
1679 }
1680 $subsectionHtml .= $this->wrapFieldSetSection( $legend, $section, $attributes );
1681 } else {
1682 // Just return the inputs, nothing fancy.
1683 $subsectionHtml .= $section;
1684 }
1685 }
1686 }
1687
1688 $html = $this->formatSection( $html, $sectionName, $hasLabel );
1689
1690 if ( $subsectionHtml ) {
1691 if ( $this->mSubSectionBeforeFields ) {
1692 return $subsectionHtml . "\n" . $html;
1693 } else {
1694 return $html . "\n" . $subsectionHtml;
1695 }
1696 } else {
1697 return $html;
1698 }
1699 }
1700
1708 protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) {
1710 $html = implode( '', $fieldsHtml );
1711
1712 if ( $displayFormat === 'raw' ) {
1713 return $html;
1714 }
1715
1716 $classes = [];
1717
1718 if ( !$anyFieldHasLabel ) { // Avoid strange spacing when no labels exist
1719 $classes[] = 'mw-htmlform-nolabel';
1720 }
1721
1722 $attribs = [
1723 'class' => implode( ' ', $classes ),
1724 ];
1725
1726 if ( $sectionName ) {
1727 $attribs['id'] = Sanitizer::escapeId( $sectionName );
1728 }
1729
1730 if ( $displayFormat === 'table' ) {
1731 return Html::rawElement( 'table',
1732 $attribs,
1733 Html::rawElement( 'tbody', [], "\n$html\n" ) ) . "\n";
1734 } elseif ( $displayFormat === 'inline' ) {
1735 return Html::rawElement( 'span', $attribs, "\n$html\n" );
1736 } else {
1737 return Html::rawElement( 'div', $attribs, "\n$html\n" );
1738 }
1739 }
1740
1744 public function loadData() {
1745 $fieldData = [];
1746
1747 foreach ( $this->mFlatFields as $fieldname => $field ) {
1748 $request = $this->getRequest();
1749 if ( $field->skipLoadData( $request ) ) {
1750 continue;
1751 } elseif ( !empty( $field->mParams['disabled'] ) ) {
1752 $fieldData[$fieldname] = $field->getDefault();
1753 } else {
1754 $fieldData[$fieldname] = $field->loadDataFromRequest( $request );
1755 }
1756 }
1757
1758 # Filter data.
1759 foreach ( $fieldData as $name => &$value ) {
1760 $field = $this->mFlatFields[$name];
1761 $value = $field->filter( $value, $this->mFlatFields );
1762 }
1763
1764 $this->mFieldData = $fieldData;
1765 }
1766
1774 public function suppressReset( $suppressReset = true ) {
1775 $this->mShowReset = !$suppressReset;
1776
1777 return $this;
1778 }
1779
1789 public function filterDataForSubmit( $data ) {
1790 return $data;
1791 }
1792
1801 public function getLegend( $key ) {
1802 return $this->msg( "{$this->mMessagePrefix}-$key" )->text();
1803 }
1804
1815 public function setAction( $action ) {
1816 $this->mAction = $action;
1817
1818 return $this;
1819 }
1820
1828 public function getAction() {
1829 // If an action is alredy provided, return it
1830 if ( $this->mAction !== false ) {
1831 return $this->mAction;
1832 }
1833
1834 $articlePath = $this->getConfig()->get( 'ArticlePath' );
1835 // Check whether we are in GET mode and the ArticlePath contains a "?"
1836 // meaning that getLocalURL() would return something like "index.php?title=...".
1837 // As browser remove the query string before submitting GET forms,
1838 // it means that the title would be lost. In such case use wfScript() instead
1839 // and put title in an hidden field (see getHiddenFields()).
1840 if ( strpos( $articlePath, '?' ) !== false && $this->getMethod() === 'get' ) {
1841 return wfScript();
1842 }
1843
1844 return $this->getTitle()->getLocalURL();
1845 }
1846
1857 public function setAutocomplete( $autocomplete ) {
1858 $this->mAutocomplete = $autocomplete;
1859
1860 return $this;
1861 }
1862
1869 protected function getMessage( $value ) {
1870 return Message::newFromSpecifier( $value )->setContext( $this );
1871 }
1872}
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
if( $line===false) $args
Definition cdb.php:64
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
getUser()
Get the User object.
getRequest()
Get the WebRequest object.
getConfig()
Get the Config object.
msg()
Get a Message object with context set Parameters are the same as wfMessage()
getOutput()
Get the OutputPage object.
IContextSource $context
getContext()
Get the base IContextSource object.
setContext(IContextSource $context)
Set the IContextSource object.
The parent class to generate form fields.
Object handling generic submission, CSRF protection, layout and other logic for UI forms.
Definition HTMLForm.php:128
setSubmitCallback( $cb)
Set a callback to a function to do something with the form once it's been successfully validated.
Definition HTMLForm.php:689
setHeaderText( $msg, $section=null)
Set header text, inside the form.
Definition HTMLForm.php:779
displayForm( $submitResult)
Display the form (sending to the context's OutputPage object), with an appropriate error message or s...
bool string $mAction
Form action URL.
Definition HTMLForm.php:211
setAction( $action)
Set the value for the action attribute of the form.
string array $mTokenSalt
Salt for the edit token.
Definition HTMLForm.php:230
getSubmitText()
Get the text for the submit button, either customised or a default.
setMethod( $method='post')
Set the method used to submit the form.
$mValidationErrorMessage
Definition HTMLForm.php:184
setValidationErrorMessage( $msg)
Set a message to display on a validation error.
Definition HTMLForm.php:703
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
setAutocomplete( $autocomplete)
Set the value for the autocomplete attribute of the form.
static loadInputFromParameters( $fieldname, $descriptor, HTMLForm $parent=null)
Initialise a new Object for the field.
Definition HTMLForm.php:478
setSubmitName( $name)
setTitle( $t)
Set the title for form submission.
static getClassFromDescriptor( $fieldname, &$descriptor)
Get the HTMLFormField subclass for this descriptor.
Definition HTMLForm.php:450
array $availableSubclassDisplayFormats
Available formats in which to display the form.
Definition HTMLForm.php:263
string $displayFormat
Format in which to display form.
Definition HTMLForm.php:246
__construct( $descriptor, $context=null, $messagePrefix='')
Build a new HTMLForm from an array of field attributes.
Definition HTMLForm.php:300
setTableId( $id)
Set the id of the <table> or outermost <div> element.
getHTML( $submitResult)
Returns the raw HTML generated by the form.
getLegend( $key)
Get a string to go in the "<legend>" of a section fieldset.
setSubmitTextMsg( $msg)
Set the text for the submit button to a message.
setSubmitProgressive()
Identify that the submit button in the form has a progressive action.
filterDataForSubmit( $data)
Overload this if you want to apply special filtration routines to the form as a whole,...
setWrapperLegendMsg( $msg)
Prompt the whole form to be wrapped in a "<fieldset>", with this message as its "<legend>" element.
setId( $id)
setWrapperLegend( $legend)
Prompt the whole form to be wrapped in a "<fieldset>", with this text as its "<legend>" element.
formatErrors( $errors)
Format a stack of error messages into a single HTML string.
$mSubSectionBeforeFields
If true, sections that contain both fields and subsections will render their subsections before their...
Definition HTMLForm.php:239
setDisplayFormat( $format)
Set format in which to display the form.
Definition HTMLForm.php:390
addButton( $data)
Add a button to the form.
Definition HTMLForm.php:943
loadData()
Construct the form fields from the Descriptor array.
getHiddenFields()
Get the hidden fields that should go inside the form.
setSubmitDestructive()
Identify that the submit button in the form has a destructive action.
suppressDefaultSubmit( $suppressSubmit=true)
Stop a default submit button being shown for this form.
setSubmitID( $t)
Set the id for the submit button.
getDisplayFormat()
Getter for displayFormat.
Definition HTMLForm.php:419
getAction()
Get the value for the action attribute of the form.
show()
The here's-one-I-made-earlier option: do the submission if posted, or display the form with or withou...
Definition HTMLForm.php:565
hasField( $fieldname)
Definition HTMLForm.php:364
addFooterText( $msg, $section=null)
Add footer text, inside the form.
Definition HTMLForm.php:812
addPostText( $msg)
Add text to the end of the display.
Definition HTMLForm.php:866
getFooterText( $section=null)
Get footer text.
Definition HTMLForm.php:851
addHeaderText( $msg, $section=null)
Add HTML to the header, inside the form.
Definition HTMLForm.php:757
prepareForm()
Prepare form for submission.
Definition HTMLForm.php:503
getTitle()
Get the title.
wasSubmitted()
Test whether the form was considered to have been submitted or not, i.e.
Definition HTMLForm.php:675
getHeaderText( $section=null)
Get header text.
Definition HTMLForm.php:796
tryAuthorizedSubmit()
Try submitting, with edit token check first.
Definition HTMLForm.php:526
setSubmitTooltip( $name)
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
setPreText( $msg)
Set the introductory message HTML, overwriting any existing message.
Definition HTMLForm.php:730
addHiddenField( $name, $value, array $attribs=[])
Add a hidden field to the output.
Definition HTMLForm.php:894
bool string $mAutocomplete
Form attribute autocomplete.
Definition HTMLForm.php:218
setFooterText( $msg, $section=null)
Set footer text, inside the form.
Definition HTMLForm.php:834
setMessagePrefix( $p)
Set the prefix for various default messages.
getField( $fieldname)
Definition HTMLForm.php:373
wrapForm( $html)
Wrap the form innards in an actual "<form>" element.
getFormAttributes()
Get HTML attributes for the <form> tag.
wrapFieldSetSection( $legend, $section, $attributes)
Wraps the given $section into an user-visible fieldset.
getBody()
Get the whole body of the form.
showAlways()
Same as self::show with the difference, that the form will be added to the output,...
Definition HTMLForm.php:583
setTokenSalt( $salt)
Set the salt for the edit token.
Definition HTMLForm.php:984
addPreText( $msg)
Add HTML to introductory message.
Definition HTMLForm.php:743
getErrors( $errors)
Format and display an error message stack.
setFormIdentifier( $ident)
Set an internal identifier for this form.
setName( $name)
suppressReset( $suppressReset=true)
Stop a reset button being shown for this form.
setPostText( $msg)
Set text at the end of the display.
Definition HTMLForm.php:879
static $typeMappings
Definition HTMLForm.php:130
formatSection(array $fieldsHtml, $sectionName, $anyFieldHasLabel)
Put a form section together from the individual fields' HTML, merging it and wrapping.
isVForm()
Test if displayFormat is 'vform'.
Definition HTMLForm.php:429
setCancelTarget( $target)
Sets the target where the user is redirected to after clicking cancel.
static factory( $displayFormat)
Construct a HTMLForm object for given display type.
Definition HTMLForm.php:275
array $availableDisplayFormats
Available formats in which to display the form.
Definition HTMLForm.php:252
showCancel( $show=true)
Show a cancel button (or prevent it).
setSubmitText( $t)
Set the text for the submit button.
setIntro( $msg)
Set the introductory message, overwriting any existing message.
Definition HTMLForm.php:716
getButtons()
Get the submit and (potentially) reset buttons.
trySubmit()
Validate all the fields, and call the submission callback function if everything is kosher.
Definition HTMLForm.php:604
HTMLFormField[] $mFlatFields
Definition HTMLForm.php:174
getErrorsOrWarnings( $elements, $elementsType)
Returns a formatted list of errors or warnings from the given elements.
addHiddenFields(array $fields)
Add an array of hidden fields to the output.
Definition HTMLForm.php:911
static tooltipAndAccesskeyAttribs( $name, array $msgParams=[])
Returns the attributes for the tooltip and access key.
Definition Linker.php:2184
MediaWiki exception.
The Message class provides methods which fulfil two basic services:
Definition Message.php:159
isGood()
Returns whether the operation completed and didn't have any error or warnings.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:40
Represents a title within MediaWiki.
Definition Title.php:36
static submitButton( $value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
Definition Xml.php:460
static fieldset( $legend=false, $content=false, $attribs=[])
Shortcut for creating fieldsets.
Definition Xml.php:578
$res
Definition database.txt:21
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
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:18
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
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist 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
the array() calling protocol came about after MediaWiki 1.4rc1.
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Associative array mapping language codes to prefixed links of the form "language:title". & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition hooks.txt:1937
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account incomplete not yet checked for validity & $retval
Definition hooks.txt:268
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition hooks.txt:2685
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:1957
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:1958
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:304
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:2901
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:37
Interface for objects which can provide a MediaWiki context on request.