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',
162 'email' =>
'HTMLTextField',
163 'password' =>
'HTMLTextField',
164 'url' =>
'HTMLTextField',
165 'title' =>
'HTMLTitleTextField',
166 'user' =>
'HTMLUserTextField',
276 $arguments = func_get_args();
277 array_shift( $arguments );
305 $this->mTitle =
false;
306 $this->mMessagePrefix = $messagePrefix;
307 } elseif (
$context === null && $messagePrefix !==
'' ) {
308 $this->mMessagePrefix = $messagePrefix;
309 } elseif ( is_string(
$context ) && $messagePrefix ===
'' ) {
317 !$this->
getConfig()->
get(
'HTMLFormAllowTableFormat' )
318 && $this->displayFormat ===
'table'
320 $this->displayFormat =
'div';
324 $loadedDescriptor = [];
325 $this->mFlatFields = [];
327 foreach ( $descriptor
as $fieldname => $info ) {
328 $section = isset( $info[
'section'] )
332 if ( isset( $info[
'type'] ) && $info[
'type'] ===
'file' ) {
333 $this->mUseMultipart =
true;
336 $field = static::loadInputFromParameters( $fieldname, $info, $this );
338 $setSection =& $loadedDescriptor;
340 $sectionParts = explode(
'/',
$section );
342 while ( count( $sectionParts ) ) {
343 $newName = array_shift( $sectionParts );
345 if ( !isset( $setSection[$newName] ) ) {
346 $setSection[$newName] = [];
349 $setSection =& $setSection[$newName];
353 $setSection[$fieldname] = $field;
354 $this->mFlatFields[$fieldname] = $field;
357 $this->mFieldTree = $loadedDescriptor;
365 return isset( $this->mFlatFields[$fieldname] );
374 if ( !$this->
hasField( $fieldname ) ) {
375 throw new DomainException( __METHOD__ .
': no field named ' . $fieldname );
377 return $this->mFlatFields[$fieldname];
392 in_array( $format, $this->availableSubclassDisplayFormats,
true ) ||
393 in_array( $this->displayFormat, $this->availableSubclassDisplayFormats,
true )
395 throw new MWException(
'Cannot change display format after creation, ' .
396 'use HTMLForm::factory() instead' );
399 if ( !in_array( $format, $this->availableDisplayFormats,
true ) ) {
400 throw new MWException(
'Display format must be one of ' .
401 print_r( $this->availableDisplayFormats,
true ) );
405 if ( !$this->
getConfig()->
get(
'HTMLFormAllowTableFormat' ) && $format ===
'table' ) {
409 $this->displayFormat = $format;
451 if ( isset( $descriptor[
'class'] ) ) {
452 $class = $descriptor[
'class'];
453 } elseif ( isset( $descriptor[
'type'] ) ) {
454 $class = static::$typeMappings[$descriptor[
'type']];
455 $descriptor[
'class'] = $class;
461 throw new MWException(
"Descriptor with no class for $fieldname: "
462 . print_r( $descriptor,
true ) );
481 $class = static::getClassFromDescriptor( $fieldname, $descriptor );
483 $descriptor[
'fieldname'] = $fieldname;
485 $descriptor[
'parent'] = $parent;
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 );
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' );
509 # Load data from the request.
511 $this->mFormIdentifier === null ||
512 $this->
getRequest()->getVal(
'wpFormIdentifier' ) === $this->mFormIdentifier
516 $this->mFieldData = [];
530 if ( $this->mFormIdentifier === null ) {
539 } elseif ( $this->
getRequest()->wasPosted() ) {
540 $editToken = $this->
getRequest()->getVal(
'wpEditToken' );
541 if ( $this->
getUser()->isLoggedIn() || $editToken !== null ) {
545 $tokenOkay = $this->
getUser()->matchEditToken( $editToken, $this->mTokenSalt );
551 if ( $tokenOkay && $identOkay ) {
552 $this->mWasSubmitted =
true;
607 $hoistedErrors[] = isset( $this->mValidationErrorMessage )
608 ? $this->mValidationErrorMessage
609 : [
'htmlform-invalid-input' ];
611 $this->mWasSubmitted =
true;
613 # Check for cancelled submission
614 foreach ( $this->mFlatFields
as $fieldname => $field ) {
615 if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
618 if ( $field->cancelSubmit( $this->mFieldData[$fieldname], $this->mFieldData ) ) {
619 $this->mWasSubmitted =
false;
624 # Check for validation
625 foreach ( $this->mFlatFields
as $fieldname => $field ) {
626 if ( !array_key_exists( $fieldname, $this->mFieldData ) ) {
629 if ( $field->isHidden( $this->mFieldData ) ) {
632 $res = $field->validate( $this->mFieldData[$fieldname], $this->mFieldData );
633 if (
$res !==
true ) {
635 if (
$res !==
false && !$field->canDisplayErrors() ) {
636 $hoistedErrors[] = [
'rawmessage',
$res ];
642 if ( count( $hoistedErrors ) === 1 ) {
643 $hoistedErrors = $hoistedErrors[0];
645 return $hoistedErrors;
649 if ( !is_callable( $callback ) ) {
650 throw new MWException(
'HTMLForm: no submit callback provided. Use ' .
651 'setSubmitCallback() to set one.' );
656 $res = call_user_func( $callback, $data, $this );
657 if (
$res ===
false ) {
658 $this->mWasSubmitted =
false;
690 $this->mSubmitCallback = $cb;
704 $this->mValidationErrorMessage = $msg;
759 $this->mHeader .= $msg;
761 if ( !isset( $this->mSectionHeaders[
$section] ) ) {
762 $this->mSectionHeaders[
$section] =
'';
764 $this->mSectionHeaders[
$section] .= $msg;
781 $this->mHeader = $msg;
783 $this->mSectionHeaders[
$section] = $msg;
800 return isset( $this->mSectionHeaders[
$section] ) ? $this->mSectionHeaders[
$section] :
'';
814 $this->mFooter .= $msg;
816 if ( !isset( $this->mSectionFooters[
$section] ) ) {
817 $this->mSectionFooters[
$section] =
'';
819 $this->mSectionFooters[
$section] .= $msg;
836 $this->mFooter = $msg;
838 $this->mSectionFooters[
$section] = $msg;
855 return isset( $this->mSectionFooters[
$section] ) ? $this->mSectionFooters[
$section] :
'';
867 $this->mPost .= $msg;
913 $this->mHiddenFields[] = [
$value, [
'name' =>
$name ] ];
944 if ( !is_array( $data ) ) {
945 $args = func_get_args();
946 if ( count(
$args ) < 2 || count(
$args ) > 4 ) {
948 'Incorrect number of arguments for deprecated calling style'
955 'attribs' => isset(
$args[3] ) ?
$args[3] : null,
958 if ( !isset( $data[
'name'] ) ) {
961 if ( !isset( $data[
'value'] ) ) {
965 $this->mButtons[] = $data + [
985 $this->mTokenSalt = $salt;
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' );
1038 # Use multipart/form-data
1039 $encType = $this->mUseMultipart
1040 ?
'multipart/form-data'
1041 :
'application/x-www-form-urlencoded';
1046 'enctype' => $encType,
1051 if ( $this->mAutocomplete ) {
1054 if ( $this->mName ) {
1068 # Include a <fieldset> wrapper for style, if requested.
1069 if ( $this->mWrapperLegend !==
false ) {
1070 $legend = is_string( $this->mWrapperLegend ) ? $this->mWrapperLegend :
false;
1087 if ( $this->mFormIdentifier !== null ) {
1090 $this->mFormIdentifier
1096 $this->
getUser()->getEditToken( $this->mTokenSalt ),
1097 [
'id' =>
'wpEditToken' ]
1102 $articlePath = $this->
getConfig()->get(
'ArticlePath' );
1103 if ( strpos( $articlePath,
'?' ) !==
false && $this->
getMethod() ===
'get' ) {
1107 foreach ( $this->mHiddenFields
as $data ) {
1121 $useMediaWikiUIEverywhere = $this->
getConfig()->get(
'UseMediaWikiUIEverywhere' );
1123 if ( $this->mShowSubmit ) {
1126 if ( isset( $this->mSubmitID ) ) {
1130 if ( isset( $this->mSubmitName ) ) {
1134 if ( isset( $this->mSubmitTooltip ) ) {
1138 $attribs[
'class'] = [
'mw-htmlform-submit' ];
1140 if ( $useMediaWikiUIEverywhere ) {
1141 foreach ( $this->mSubmitFlags
as $flag ) {
1142 $attribs[
'class'][] =
'mw-ui-' . $flag;
1144 $attribs[
'class'][] =
'mw-ui-button';
1150 if ( $this->mShowReset ) {
1155 'value' => $this->
msg(
'htmlform-reset' )->
text(),
1156 'class' => $useMediaWikiUIEverywhere ?
'mw-ui-button' : null,
1161 if ( $this->mShowCancel ) {
1163 if ( $target instanceof
Title ) {
1164 $target = $target->getLocalURL();
1169 'class' => $useMediaWikiUIEverywhere ?
'mw-ui-button' : null,
1172 $this->
msg(
'cancel' )->
text()
1177 $isBadIE = preg_match(
'/MSIE [1-7]\./i', $this->
getRequest()->getHeader(
'User-Agent' ) );
1179 foreach ( $this->mButtons
as $button ) {
1182 'name' => $button[
'name'],
1183 'value' => $button[
'value']
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'];
1193 $label = htmlspecialchars( $button[
'value'] );
1196 if ( $button[
'attribs'] ) {
1197 $attrs += $button[
'attribs'];
1200 if ( isset( $button[
'id'] ) ) {
1201 $attrs[
'id'] = $button[
'id'];
1204 if ( $useMediaWikiUIEverywhere ) {
1205 $attrs[
'class'] = isset( $attrs[
'class'] ) ? (
array)$attrs[
'class'] : [];
1206 $attrs[
'class'][] =
'mw-ui-button';
1221 [
'class' =>
'mw-htmlform-submit-buttons' ],
"\n$buttons" ) .
"\n";
1229 return $this->
displaySection( $this->mFieldTree, $this->mTableId );
1255 if ( !in_array( $elementsType, [
'error',
'warning' ],
true ) ) {
1256 throw new DomainException( $elementsType .
' is not a valid type.' );
1258 $elementstr =
false;
1259 if ( $elements instanceof
Status ) {
1260 list( $errorStatus, $warningStatus ) = $elements->splitByErrorType();
1261 $status = $elementsType ===
'error' ? $errorStatus : $warningStatus;
1265 $elementstr = $this->
getOutput()->parse(
1269 } elseif ( is_array( $elements ) && $elementsType ===
'error' ) {
1271 } elseif ( $elementsType ===
'error' ) {
1272 $elementstr = $elements;
1290 foreach ( $errors
as $error ) {
1311 $this->mSubmitText =
$t;
1323 $this->mSubmitFlags = [
'destructive',
'primary' ];
1335 $this->mSubmitFlags = [
'progressive',
'primary' ];
1349 if ( !$msg instanceof
Message ) {
1350 $msg = $this->
msg( $msg );
1362 return $this->mSubmitText ?: $this->
msg(
'htmlform-submit' )->text();
1371 $this->mSubmitName =
$name;
1382 $this->mSubmitTooltip =
$name;
1396 $this->mSubmitID =
$t;
1417 $this->mFormIdentifier = $ident;
1433 $this->mShowSubmit = !$suppressSubmit;
1445 $this->mShowCancel = $show;
1456 $this->mCancelTarget = $target;
1470 $this->mTableId = $id;
1491 $this->mName =
$name;
1508 $this->mWrapperLegend = $legend;
1523 if ( !$msg instanceof
Message ) {
1524 $msg = $this->
msg( $msg );
1541 $this->mMessagePrefix = $p;
1564 return $this->mTitle ===
false
1577 $this->mMethod = strtolower( $method );
1619 $fieldsetIDPrefix =
'',
1620 &$hasUserVisibleFields =
false
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.' );
1630 $subsectionHtml =
'';
1637 foreach ( $fields
as $key =>
$value ) {
1639 $v = array_key_exists( $key, $this->mFieldData )
1640 ? $this->mFieldData[$key]
1647 if (
$value->hasVisibleOutput() ) {
1650 $labelValue = trim(
$value->getLabel() );
1651 if ( $labelValue !==
' ' && $labelValue !==
'' ) {
1655 $hasUserVisibleFields =
true;
1657 } elseif ( is_array(
$value ) ) {
1658 $subsectionHasVisibleFields =
false;
1662 "$fieldsetIDPrefix$key-",
1663 $subsectionHasVisibleFields );
1666 if ( $subsectionHasVisibleFields ===
true ) {
1668 $hasUserVisibleFields =
true;
1677 if ( $fieldsetIDPrefix ) {
1690 if ( $subsectionHtml ) {
1691 if ( $this->mSubSectionBeforeFields ) {
1692 return $subsectionHtml .
"\n" .
$html;
1694 return $html .
"\n" . $subsectionHtml;
1710 $html = implode(
'', $fieldsHtml );
1718 if ( !$anyFieldHasLabel ) {
1719 $classes[] =
'mw-htmlform-nolabel';
1723 'class' => implode(
' ', $classes ),
1726 if ( $sectionName ) {
1747 foreach ( $this->mFlatFields
as $fieldname => $field ) {
1749 if ( $field->skipLoadData(
$request ) ) {
1751 } elseif ( !empty( $field->mParams[
'disabled'] ) ) {
1752 $fieldData[$fieldname] = $field->getDefault();
1754 $fieldData[$fieldname] = $field->loadDataFromRequest(
$request );
1760 $field = $this->mFlatFields[
$name];
1764 $this->mFieldData = $fieldData;
1775 $this->mShowReset = !$suppressReset;
1802 return $this->
msg(
"{$this->mMessagePrefix}-$key" )->text();
1816 $this->mAction = $action;
1830 if ( $this->mAction !==
false ) {
1834 $articlePath = $this->
getConfig()->get(
'ArticlePath' );
1840 if ( strpos( $articlePath,
'?' ) !==
false && $this->
getMethod() ===
'get' ) {
1844 return $this->
getTitle()->getLocalURL();
1858 $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.
wfScript($script= 'index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
static newMainPage()
Create a new Title for the Main Page.
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.
static constructClassInstance($clazz, $args)
Construct an instance of the given class using the given arguments.
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':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
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.