126 'api' =>
'HTMLApiField',
127 'text' =>
'HTMLTextField',
128 'textwithbutton' =>
'HTMLTextFieldWithButton',
129 'textarea' =>
'HTMLTextAreaField',
130 'select' =>
'HTMLSelectField',
131 'combobox' =>
'HTMLComboboxField',
132 'radio' =>
'HTMLRadioField',
133 'multiselect' =>
'HTMLMultiSelectField',
134 'limitselect' =>
'HTMLSelectLimitField',
135 'check' =>
'HTMLCheckField',
136 'toggle' =>
'HTMLCheckField',
137 'int' =>
'HTMLIntField',
138 'float' =>
'HTMLFloatField',
139 'info' =>
'HTMLInfoField',
140 'selectorother' =>
'HTMLSelectOrOtherField',
141 'selectandother' =>
'HTMLSelectAndOtherField',
142 'namespaceselect' =>
'HTMLSelectNamespace',
143 'namespaceselectwithbutton' =>
'HTMLSelectNamespaceWithButton',
144 'tagfilter' =>
'HTMLTagFilter',
145 'submit' =>
'HTMLSubmitField',
146 'hidden' =>
'HTMLHiddenField',
147 'edittools' =>
'HTMLEditTools',
148 'checkmatrix' =>
'HTMLCheckMatrix',
149 'cloner' =>
'HTMLFormFieldCloner',
150 'autocompleteselect' =>
'HTMLAutoCompleteSelectField',
154 'email' =>
'HTMLTextField',
155 'password' =>
'HTMLTextField',
156 'url' =>
'HTMLTextField',
157 'title' =>
'HTMLTitleTextField',
158 'user' =>
'HTMLUserTextField',
265 $arguments = func_get_args();
266 array_shift( $arguments );
270 $reflector =
new ReflectionClass(
'VFormHTMLForm' );
271 return $reflector->newInstanceArgs( $arguments );
273 $reflector =
new ReflectionClass(
'OOUIHTMLForm' );
274 return $reflector->newInstanceArgs( $arguments );
276 $reflector =
new ReflectionClass(
'HTMLForm' );
277 $form = $reflector->newInstanceArgs( $arguments );
296 $this->mTitle =
false;
297 $this->mMessagePrefix = $messagePrefix;
298 } elseif (
$context === null && $messagePrefix !==
'' ) {
299 $this->mMessagePrefix = $messagePrefix;
300 } elseif ( is_string(
$context ) && $messagePrefix ===
'' ) {
308 !$this->
getConfig()->
get(
'HTMLFormAllowTableFormat' )
309 && $this->displayFormat ===
'table'
311 $this->displayFormat =
'div';
315 $loadedDescriptor = [];
316 $this->mFlatFields = [];
318 foreach ( $descriptor
as $fieldname => $info ) {
319 $section = isset( $info[
'section'] )
323 if ( isset( $info[
'type'] ) && $info[
'type'] ===
'file' ) {
324 $this->mUseMultipart =
true;
327 $field = static::loadInputFromParameters( $fieldname, $info, $this );
329 $setSection =& $loadedDescriptor;
331 $sectionParts = explode(
'/',
$section );
333 while ( count( $sectionParts ) ) {
334 $newName = array_shift( $sectionParts );
336 if ( !isset( $setSection[$newName] ) ) {
337 $setSection[$newName] = [];
340 $setSection =& $setSection[$newName];
344 $setSection[$fieldname] = $field;
345 $this->mFlatFields[$fieldname] = $field;
348 $this->mFieldTree = $loadedDescriptor;
363 in_array( $format, $this->availableSubclassDisplayFormats,
true ) ||
364 in_array( $this->displayFormat, $this->availableSubclassDisplayFormats,
true )
366 throw new MWException(
'Cannot change display format after creation, ' .
367 'use HTMLForm::factory() instead' );
370 if ( !in_array( $format, $this->availableDisplayFormats,
true ) ) {
371 throw new MWException(
'Display format must be one of ' .
372 print_r( $this->availableDisplayFormats,
true ) );
376 if ( !$this->
getConfig()->
get(
'HTMLFormAllowTableFormat' ) && $format ===
'table' ) {
380 $this->displayFormat = $format;
422 if ( isset( $descriptor[
'class'] ) ) {
423 $class = $descriptor[
'class'];
424 } elseif ( isset( $descriptor[
'type'] ) ) {
425 $class = static::$typeMappings[$descriptor[
'type']];
426 $descriptor[
'class'] = $class;
432 throw new MWException(
"Descriptor with no class for $fieldname: "
433 . print_r( $descriptor,
true ) );
452 $class = static::getClassFromDescriptor( $fieldname, $descriptor );
454 $descriptor[
'fieldname'] = $fieldname;
456 $descriptor[
'parent'] = $parent;
459 # @todo This will throw a fatal error whenever someone try to use
460 # 'class' to feed a CSS class instead of 'cssclass'. Would be
461 # great to avoid the fatal error and show a nice error.
462 return new $class( $descriptor );
475 # Check if we have the info we need
476 if ( !$this->mTitle instanceof
Title && $this->mTitle !==
false ) {
477 throw new MWException(
'You must call setTitle() on an HTMLForm' );
480 # Load data from the request.
496 } elseif ( $this->
getRequest()->wasPosted() ) {
497 $editToken = $this->
getRequest()->getVal(
'wpEditToken' );
498 if ( $this->
getUser()->isLoggedIn() || $editToken !== null ) {
502 $submit = $this->
getUser()->matchEditToken( $editToken, $this->mTokenSalt );
509 $this->mWasSubmitted =
true;
564 $hoistedErrors[] = isset( $this->mValidationErrorMessage )
565 ? $this->mValidationErrorMessage
566 : [
'htmlform-invalid-input' ];
568 $this->mWasSubmitted =
true;
570 # Check for cancelled submission
571 foreach ( $this->mFlatFields
as $fieldname => $field ) {
572 if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
575 if ( $field->cancelSubmit( $this->mFieldData[$fieldname], $this->mFieldData ) ) {
576 $this->mWasSubmitted =
false;
581 # Check for validation
582 foreach ( $this->mFlatFields
as $fieldname => $field ) {
583 if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
586 if ( $field->isHidden( $this->mFieldData ) ) {
589 $res = $field->validate( $this->mFieldData[$fieldname], $this->mFieldData );
590 if (
$res !==
true ) {
592 if (
$res !==
false && !$field->canDisplayErrors() ) {
593 $hoistedErrors[] = [
'rawmessage',
$res ];
599 if ( count( $hoistedErrors ) === 1 ) {
600 $hoistedErrors = $hoistedErrors[0];
602 return $hoistedErrors;
606 if ( !is_callable( $callback ) ) {
607 throw new MWException(
'HTMLForm: no submit callback provided. Use ' .
608 'setSubmitCallback() to set one.' );
613 $res = call_user_func( $callback, $data, $this );
614 if (
$res ===
false ) {
615 $this->mWasSubmitted =
false;
647 $this->mSubmitCallback = $cb;
661 $this->mValidationErrorMessage = $msg;
716 $this->mHeader .= $msg;
718 if ( !isset( $this->mSectionHeaders[
$section] ) ) {
719 $this->mSectionHeaders[
$section] =
'';
721 $this->mSectionHeaders[
$section] .= $msg;
738 $this->mHeader = $msg;
740 $this->mSectionHeaders[
$section] = $msg;
757 return isset( $this->mSectionHeaders[
$section] ) ? $this->mSectionHeaders[
$section] :
'';
771 $this->mFooter .= $msg;
773 if ( !isset( $this->mSectionFooters[
$section] ) ) {
774 $this->mSectionFooters[
$section] =
'';
776 $this->mSectionFooters[
$section] .= $msg;
793 $this->mFooter = $msg;
795 $this->mSectionFooters[
$section] = $msg;
812 return isset( $this->mSectionFooters[
$section] ) ? $this->mSectionFooters[
$section] :
'';
824 $this->mPost .= $msg;
870 $this->mHiddenFields[] = [
$value, [
'name' =>
$name ] ];
900 if ( !is_array( $data ) ) {
901 $args = func_get_args();
902 if ( count(
$args ) < 2 || count(
$args ) > 4 ) {
904 'Incorrect number of arguments for deprecated calling style'
911 'attribs' => isset(
$args[3] ) ?
$args[3] : null,
914 if ( !isset( $data[
'name'] ) ) {
917 if ( !isset( $data[
'value'] ) ) {
921 $this->mButtons[] = $data + [
940 $this->mTokenSalt = $salt;
969 # For good measure (it is the default)
970 $this->
getOutput()->preventClickjacking();
971 $this->
getOutput()->addModules(
'mediawiki.htmlform' );
972 $this->
getOutput()->addModuleStyles(
'mediawiki.htmlform.styles' );
992 # Use multipart/form-data
993 $encType = $this->mUseMultipart
994 ?
'multipart/form-data'
995 :
'application/x-www-form-urlencoded';
1000 'enctype' => $encType,
1005 if ( $this->mAutocomplete ) {
1008 if ( $this->mName ) {
1022 # Include a <fieldset> wrapper for style, if requested.
1023 if ( $this->mWrapperLegend !==
false ) {
1024 $legend = is_string( $this->mWrapperLegend ) ? $this->mWrapperLegend :
false;
1044 $this->
getUser()->getEditToken( $this->mTokenSalt ),
1045 [
'id' =>
'wpEditToken' ]
1050 $articlePath = $this->
getConfig()->get(
'ArticlePath' );
1051 if ( strpos( $articlePath,
'?' ) !==
false && $this->
getMethod() ===
'get' ) {
1055 foreach ( $this->mHiddenFields
as $data ) {
1069 $useMediaWikiUIEverywhere = $this->
getConfig()->get(
'UseMediaWikiUIEverywhere' );
1071 if ( $this->mShowSubmit ) {
1074 if ( isset( $this->mSubmitID ) ) {
1078 if ( isset( $this->mSubmitName ) ) {
1082 if ( isset( $this->mSubmitTooltip ) ) {
1086 $attribs[
'class'] = [
'mw-htmlform-submit' ];
1088 if ( $useMediaWikiUIEverywhere ) {
1089 foreach ( $this->mSubmitFlags
as $flag ) {
1090 $attribs[
'class'][] =
'mw-ui-' . $flag;
1092 $attribs[
'class'][] =
'mw-ui-button';
1098 if ( $this->mShowReset ) {
1103 'value' => $this->
msg(
'htmlform-reset' )->
text(),
1104 'class' => $useMediaWikiUIEverywhere ?
'mw-ui-button' : null,
1110 $isBadIE = preg_match(
'/MSIE [1-7]\./i', $this->
getRequest()->getHeader(
'User-Agent' ) );
1112 foreach ( $this->mButtons
as $button ) {
1115 'name' => $button[
'name'],
1116 'value' => $button[
'value']
1119 if ( isset( $button[
'label-message'] ) ) {
1120 $label = $this->
getMessage( $button[
'label-message'] )->parse();
1121 } elseif ( isset( $button[
'label'] ) ) {
1122 $label = htmlspecialchars( $button[
'label'] );
1123 } elseif ( isset( $button[
'label-raw'] ) ) {
1124 $label = $button[
'label-raw'];
1126 $label = htmlspecialchars( $button[
'value'] );
1129 if ( $button[
'attribs'] ) {
1130 $attrs += $button[
'attribs'];
1133 if ( isset( $button[
'id'] ) ) {
1134 $attrs[
'id'] = $button[
'id'];
1137 if ( $useMediaWikiUIEverywhere ) {
1138 $attrs[
'class'] = isset( $attrs[
'class'] ) ? (
array)$attrs[
'class'] : [];
1139 $attrs[
'class'][] =
'mw-ui-button';
1154 [
'class' =>
'mw-htmlform-submit-buttons' ],
"\n$buttons" ) .
"\n";
1162 return $this->
displaySection( $this->mFieldTree, $this->mTableId );
1173 if ( $errors instanceof
Status ) {
1174 if ( $errors->isOK() ) {
1177 $errorstr = $this->
getOutput()->parse( $errors->getWikiText() );
1179 } elseif ( is_array( $errors ) ) {
1182 $errorstr = $errors;
1200 foreach ( $errors
as $error ) {
1221 $this->mSubmitText =
$t;
1231 $this->mSubmitFlags = [
'destructive',
'primary' ];
1239 $this->mSubmitFlags = [
'progressive',
'primary' ];
1251 if ( !$msg instanceof
Message ) {
1252 $msg = $this->
msg( $msg );
1264 return $this->mSubmitText ?: $this->
msg(
'htmlform-submit' )->text();
1273 $this->mSubmitName =
$name;
1284 $this->mSubmitTooltip =
$name;
1298 $this->mSubmitID =
$t;
1314 $this->mShowSubmit = !$suppressSubmit;
1329 $this->mTableId = $id;
1350 $this->mName =
$name;
1367 $this->mWrapperLegend = $legend;
1382 if ( !$msg instanceof
Message ) {
1383 $msg = $this->
msg( $msg );
1400 $this->mMessagePrefix = $p;
1423 return $this->mTitle ===
false
1436 $this->mMethod = strtolower( $method );
1478 $fieldsetIDPrefix =
'',
1479 &$hasUserVisibleFields =
false
1481 if ( $this->mFieldData === null ) {
1482 throw new LogicException(
'HTMLForm::displaySection() called on uninitialized field data. '
1483 .
'You probably called displayForm() without calling prepareForm() first.' );
1489 $subsectionHtml =
'';
1498 $v = array_key_exists(
$key, $this->mFieldData )
1499 ? $this->mFieldData[
$key]
1506 if (
$value->hasVisibleOutput() ) {
1509 $labelValue = trim(
$value->getLabel() );
1510 if ( $labelValue !==
' ' && $labelValue !==
'' ) {
1514 $hasUserVisibleFields =
true;
1516 } elseif ( is_array(
$value ) ) {
1517 $subsectionHasVisibleFields =
false;
1521 "$fieldsetIDPrefix$key-",
1522 $subsectionHasVisibleFields );
1525 if ( $subsectionHasVisibleFields ===
true ) {
1527 $hasUserVisibleFields =
true;
1536 if ( $fieldsetIDPrefix ) {
1549 if ( $subsectionHtml ) {
1550 if ( $this->mSubSectionBeforeFields ) {
1551 return $subsectionHtml .
"\n" .
$html;
1553 return $html .
"\n" . $subsectionHtml;
1569 $html = implode(
'', $fieldsHtml );
1577 if ( !$anyFieldHasLabel ) {
1578 $classes[] =
'mw-htmlform-nolabel';
1582 'class' => implode(
' ', $classes ),
1585 if ( $sectionName ) {
1606 foreach ( $this->mFlatFields
as $fieldname => $field ) {
1608 if ( $field->skipLoadData(
$request ) ) {
1610 } elseif ( !empty( $field->mParams[
'disabled'] ) ) {
1611 $fieldData[$fieldname] = $field->getDefault();
1613 $fieldData[$fieldname] = $field->loadDataFromRequest(
$request );
1619 $field = $this->mFlatFields[
$name];
1623 $this->mFieldData = $fieldData;
1634 $this->mShowReset = !$suppressReset;
1661 return $this->
msg(
"{$this->mMessagePrefix}-$key" )->text();
1675 $this->mAction = $action;
1689 if ( $this->mAction !==
false ) {
1693 $articlePath = $this->
getConfig()->get(
'ArticlePath' );
1699 if ( strpos( $articlePath,
'?' ) !==
false && $this->
getMethod() ===
'get' ) {
1703 return $this->
getTitle()->getLocalURL();
1717 $this->mAutocomplete = $autocomplete;
setContext(IContextSource $context)
Set the IContextSource object.
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
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
Interface for objects which can provide a MediaWiki context on request.
the array() calling protocol came about after MediaWiki 1.4rc1.
magic word the default is to use $key to get the and $key value or $key value text $key value html to format the value $key
wfScript($script= 'index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
static rawElement($element, $attribs=[], $contents= '')
Returns an HTML element in a string.
static hidden($name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Represents a title within MediaWiki.
static tooltipAndAccesskeyAttribs($name, array $msgParams=[])
Returns the attributes for the tooltip and access key.
static submitButton($value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
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':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
getRequest()
Get the WebRequest object.
static fieldset($legend=false, $content=false, $attribs=[])
Shortcut for creating fieldsets.
msg()
Get a Message object with context set Parameters are the same as wfMessage()
getConfig()
Get the Config object.
getContext()
Get the base IContextSource object.