MediaWiki  master
Html Class Reference

This class is a collection of static functions that serve two purposes: More...

Static Public Member Functions

static buttonAttributes (array $attrs, array $modifiers=[])
 Modifies a set of attributes meant for button elements and apply a set of default attributes when $wgUseMediaWikiUIEverywhere enabled. More...
 
static check ( $name, $checked=false, array $attribs=[])
 Convenience function to produce a checkbox (input element with type=checkbox) More...
 
static closeElement ( $element)
 Returns "</$element>". More...
 
static element ( $element, $attribs=[], $contents='')
 Identical to rawElement(), but HTML-escapes $contents (like Xml::element()). More...
 
static errorBox ( $html, $heading='')
 Return an error box. More...
 
static expandAttributes (array $attribs)
 Given an associative array of element attributes, generate a string to stick after the element name in HTML output. More...
 
static getTextInputAttributes (array $attrs)
 Modifies a set of attributes meant for text input elements and apply a set of default attributes. More...
 
static hidden ( $name, $value, array $attribs=[])
 Convenience function to produce an input element with type=hidden. More...
 
static htmlHeader (array $attribs=[])
 Constructs the opening html-tag with necessary doctypes depending on global variables. More...
 
static infoBox ( $text, $icon, $alt, $class='')
 Get HTML for an info box with an icon. More...
 
static inlineScript ( $contents, $nonce=null)
 Output an HTML script tag with the given contents. More...
 
static inlineStyle ( $contents, $media='all', $attribs=[])
 Output a "<style>" tag with the given contents for the given media type (if any). More...
 
static input ( $name, $value='', $type='text', array $attribs=[])
 Convenience function to produce an "<input>" element. More...
 
static isXmlMimeType ( $mimetype)
 Determines if the given MIME type is xml. More...
 
static label ( $label, $id, array $attribs=[])
 Convenience function for generating a label for inputs. More...
 
static linkButton ( $contents, array $attrs, array $modifiers=[])
 Returns an HTML link element in a string styled as a button (when $wgUseMediaWikiUIEverywhere is enabled). More...
 
static linkedScript ( $url, $nonce=null)
 Output a "<script>" tag linking to the given URL, e.g., "<script src=foo.js></script>". More...
 
static linkedStyle ( $url, $media='all')
 Output a "<link rel=stylesheet>" linking to the given URL for the given media type (if any). More...
 
static namespaceSelector (array $params=[], array $selectAttribs=[])
 Build a drop-down box for selecting a namespace. More...
 
static namespaceSelectorOptions (array $params=[])
 Helper for Html::namespaceSelector(). More...
 
static openElement ( $element, $attribs=[])
 Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/' in XML mode for empty elements). More...
 
static radio ( $name, $checked=false, array $attribs=[])
 Convenience function to produce a radio button (input element with type=radio) More...
 
static rawElement ( $element, $attribs=[], $contents='')
 Returns an HTML element in a string. More...
 
static srcSet (array $urls)
 Generate a srcset attribute value. More...
 
static submitButton ( $contents, array $attrs, array $modifiers=[])
 Returns an HTML link element in a string styled as a button (when $wgUseMediaWikiUIEverywhere is enabled). More...
 
static successBox ( $html)
 Return a success box. More...
 
static textarea ( $name, $value='', array $attribs=[])
 Convenience function to produce a <textarea> element. More...
 
static warningBox ( $html)
 Return a warning box. More...
 

Static Private Member Functions

static dropDefaults ( $element, array $attribs)
 Given an element name and an associative array of element attributes, return an array that is functionally identical to the input array, but possibly smaller. More...
 
static messageBox ( $html, $className, $heading='')
 Return the HTML for a message box. More...
 

Static Private Attributes

static $boolAttribs
 
static $voidElements
 

Detailed Description

This class is a collection of static functions that serve two purposes:

1) Implement any algorithms specified by HTML5, or other HTML specifications, in a convenient and self-contained way.

2) Allow HTML elements to be conveniently and safely generated, like the current Xml class but a) less confused (Xml supports HTML-specific things, but only sometimes!) and b) not necessarily confined to XML-compatible output.

There are two important configuration options this class uses:

$wgMimeType: If this is set to an xml MIME type then output should be valid XHTML5.

This class is meant to be confined to utility functions that are called from trusted code paths. It does not do enforcement of policy like not allowing elements.

Since
1.16

Definition at line 49 of file Html.php.

Member Function Documentation

◆ buttonAttributes()

static Html::buttonAttributes ( array  $attrs,
array  $modifiers = [] 
)
static

Modifies a set of attributes meant for button elements and apply a set of default attributes when $wgUseMediaWikiUIEverywhere enabled.

Parameters
array$attrsHTML attributes in an associative array
string[]$modifiers classes to add to the button
See also
https://tools.wmflabs.org/styleguide/desktop/index.html for guidance on available modifiers
Returns
array $attrs A modified attribute array

Definition at line 110 of file Html.php.

References $wgUseMediaWikiUIEverywhere.

◆ check()

static Html::check (   $name,
  $checked = false,
array  $attribs = [] 
)
static

Convenience function to produce a checkbox (input element with type=checkbox)

Parameters
string$nameName attribute
bool$checkedWhether the checkbox is checked or not
array$attribsArray of additional attributes
Returns
string Raw HTML

Definition at line 687 of file Html.php.

References $attribs, $name, and $value.

Referenced by SpecialWatchlist\showHideCheck(), and HtmlTest\testWrapperCheck().

◆ closeElement()

◆ dropDefaults()

static Html::dropDefaults (   $element,
array  $attribs 
)
staticprivate

Given an element name and an associative array of element attributes, return an array that is functionally identical to the input array, but possibly smaller.

In particular, attributes might be stripped if they are given their default values.

This method is not guaranteed to remove all redundant attributes, only some common ones and some others selected arbitrarily at random. It only guarantees that the output array should be functionally identical to the input array (currently per the HTML 5 draft as of 2009-09-06).

Parameters
string$elementName of the element, e.g., 'a'
array$attribsAssociative array of attributes, e.g., [ 'href' => 'https://www.mediawiki.org/' ]. See expandAttributes() for further documentation.
Returns
array An array of attributes functionally identical to $attribs

Definition at line 333 of file Html.php.

References $attribs, $type, $value, and as.

◆ element()

static Html::element (   $element,
  $attribs = [],
  $contents = '' 
)
static

Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).

Parameters
string$elementName of the element, e.g., 'a'
array$attribsAssociative array of attributes, e.g., [ 'href' => 'https://www.mediawiki.org/' ]. See expandAttributes() for further documentation.
string$contents
Returns
string

Definition at line 232 of file Html.php.

References $attribs.

Referenced by OutputPage\addElement(), JsonContent\arrayTable(), OutputPage\buildExemptModules(), ListToggle\checkboxLink(), ApiFormatBase\closePrinter(), Revision\RevisionRenderer\combineSlotOutput(), MWDebug\deprecated(), WebInstaller\docLink(), SpecialRecentChanges\doHeader(), SpecialWatchlist\doHeader(), WebInstallerDBConnect\execute(), WebInstallerOptions\execute(), SpecialListGrants\execute(), SpecialPreferences\execute(), SpecialVersion\execute(), UserrightsPage\execute(), OutputPage\feedLink(), ChangesList\flag(), Parser\formatHeadings(), PageQueryPage\formatResult(), FewestrevisionsPage\formatResult(), MostlinkedCategoriesPage\formatResult(), MostcategoriesPage\formatResult(), MostinterwikisPage\formatResult(), MostlinkedTemplatesPage\formatResult(), MostlinkedPage\formatResult(), UnwatchedpagesPage\formatResult(), ShortPagesPage\formatResult(), SpecialPagesWithProp\formatResult(), SpecialProtectedtitles\formatRow(), SpecialNewpages\formatRow(), ProtectedPagesPager\formatValue(), SpecialLog\getActionButtons(), SpecialChangeCredentials\getAuthForm(), PreferencesFormOOUI\getBody(), VFormHTMLForm\getButtons(), HTMLForm\getButtons(), WebInstallerOptions\getCCChooser(), WebInstallerOptions\getCCDoneBox(), BaseTemplate\getClear(), OracleInstaller\getConnectForm(), PostgresInstaller\getConnectForm(), MysqlInstaller\getConnectForm(), MssqlInstaller\getConnectForm(), SpecialVersion\getCreditsForExtension(), UploadForm\getDescriptionSection(), FeedUtils\getDiffLink(), TablePager\getEmptyBody(), SpecialVersion\getEntryPointInfo(), SpecialVersion\getExternalLibraries(), LoginSignupSpecialPage\getFieldDefinitions(), OutputPage\getHeadLinksArray(), ApiHelp\getHelpInternal(), HTMLButtonField\getInputHTML(), HTMLCheckMatrix\getInputHTML(), DatabaseInstaller\getInstallUserBox(), UploadSourceField\getLabelHtml(), EnhancedChangesList\getLineData(), RevDelFileItem\getLink(), HTMLCheckMatrix\getOneCheckboxHTML(), WebInstaller\getPageListItem(), SpecialVersion\getParserTags(), HistoryPager\getRevisionButton(), MssqlInstaller\getSettingsForm(), DifferenceEngine\getSlotHeader(), TablePager\getStartBody(), ParserOutput\getText(), SpecialVersion\getVersionLinkedGit(), DatabaseInstaller\getWebUserBox(), SpecialVersion\getWgHooks(), OutputPage\headElement(), Linker\makeExternalImage(), Skin\makeFooterIcon(), InfoAction\makeHeader(), ChangesListSpecialPage\makeLegend(), SpecialBookSources\makeListItem(), ResourceLoaderClientHtml\makeLoad(), LogFormatter\makePageLink(), WebInstallerOptions\makeScreenshotsLink(), BaseTemplate\makeSearchButton(), BaseTemplate\makeSearchInput(), ApiMain\modifyHelp(), Language\numLink(), JsonContent\objectRow(), JsonContent\objectTable(), InfoAction\onView(), SpecialVersion\openExtType(), Xml\option(), MediaStatisticsPage\outputMediaType(), SpecialListGroupRights\outputNamespaceProtectionInfo(), InfoAction\pageInfo(), MWExceptionRenderer\reportHTML(), ImportReporter\reportNotice(), MWExceptionRenderer\reportOutageHTML(), JsonContent\rootValueTable(), ParserTestRunner\runTest(), ChangesList\showCharacterDifference(), SpecialAllPages\showChunk(), DifferenceEngine\showDiffPage(), SpecialImport\showForm(), SpecialUndelete\showHistory(), SpecialBlockList\showList(), SpecialUndelete\showList(), SpecialPrefixindex\showPrefixChunk(), McrUndoAction\showPreview(), SpecialChangeCredentials\showSubpageList(), SpecialUploadStash\showUploads(), WebInstaller\startPageWrapper(), Xml\submitButton(), OutputPageTest\testAddLink(), HtmlTest\testDropDefaults(), HtmlTest\testElementBasics(), HtmlTest\testHtmlElementAcceptsNewHtml5TypesInHtml5Mode(), OutputPageTest\testSetCanonicalUrl(), OutputPageTest\testSetCopyrightUrl(), Linker\tocLine(), Linker\tocList(), and JsonContent\valueCell().

◆ errorBox()

static Html::errorBox (   $html,
  $heading = '' 
)
static

Return an error box.

Since
1.31
Parameters
string$htmlof contents of error box
string$heading(optional)
Returns
string of HTML representing an error box.

Definition at line 734 of file Html.php.

References $html.

Referenced by SpecialRecentChangesLinked\doMainQuery(), MWException\getHTML(), MovePageForm\showForm(), SpecialSearch\showResults(), and HtmlTest\testErrorBox().

◆ expandAttributes()

static Html::expandAttributes ( array  $attribs)
static

Given an associative array of element attributes, generate a string to stick after the element name in HTML output.

Like [ 'href' => 'https://www.mediawiki.org/' ] becomes something like ' href="https://www.mediawiki.org"'. Again, this is like Xml::expandAttributes(), but it implements some HTML-specific logic.

Attributes that can contain space-separated lists ('class', 'accesskey' and 'rel') array values are allowed as well, which will automagically be normalized and converted to a space-separated string. In addition to a numerical array, the attribute value may also be an associative array. See the example below for how that works.

Numerical array
Html::element( 'em', [
'class' => [ 'foo', 'bar' ]
] );
// gives '<em class="foo bar"></em>'
Associative array
Html::element( 'em', [
'class' => [ 'foo', 'bar', 'foo' => false, 'quux' => true ]
] );
// gives '<em class="bar quux"></em>'
Parameters
array$attribsAssociative array of attributes, e.g., [ 'href' => 'https://www.mediawiki.org/' ]. Values will be HTML-escaped. A value of false or null means to omit the attribute. For boolean attributes, you can omit the key, e.g., [ 'checked' ] instead of [ 'checked' => 'checked' ] or such.
Exceptions
MWExceptionIf an attribute that doesn't allow lists is set to an array
Returns
string HTML fragment that goes between element name and '>' (starting with a space if at least one attribute is output)

Definition at line 475 of file Html.php.

References $ret, $value, as, and Sanitizer\encodeAttribute().

Referenced by LanguageConverter\autoConvert(), EnhancedChangesList\getLineData(), HtmlTest\testExpandAttributes_ArrayOnNonListValueAttribute_ThrowsException(), HtmlTest\testExpandAttributesForBooleans(), HtmlTest\testExpandAttributesForNumbers(), HtmlTest\testExpandAttributesForObjects(), HtmlTest\testExpandAttributesListValueAttributes(), HtmlTest\testExpandAttributesSkipsNullAndFalse(), HtmlTest\testExpandAttributesSpaceSeparatedAttributesWithBoolean(), HtmlTest\testExpandAttributesVariousExpansions(), and HtmlTest\testValueIsAuthoritativeInSpaceSeparatedAttributesArrays().

◆ getTextInputAttributes()

static Html::getTextInputAttributes ( array  $attrs)
static

Modifies a set of attributes meant for text input elements and apply a set of default attributes.

Removes size attribute when $wgUseMediaWikiUIEverywhere enabled.

Parameters
array$attrsAn attribute array.
Returns
array $attrs A modified attribute array

Definition at line 137 of file Html.php.

References $wgUseMediaWikiUIEverywhere.

Referenced by Xml\input(), and Xml\textarea().

◆ hidden()

static Html::hidden (   $name,
  $value,
array  $attribs = [] 
)
static

Convenience function to produce an input element with type=hidden.

Parameters
string$nameName attribute
string$valueValue attribute
array$attribsAssociative array of miscellaneous extra attributes, passed to Html::element()
Returns
string Raw HTML

Definition at line 795 of file Html.php.

References $attribs, $name, and $value.

Referenced by SpecialEditTags\buildCheckBoxes(), AllMessagesTablePager\buildForm(), ProtectionForm\buildForm(), Article\confirmDelete(), MediaWiki\Preferences\DefaultPreferencesFactory\datetimePreferences(), SpecialRecentChanges\doHeader(), SpecialWatchlist\doHeader(), ImagePage\doRenderLangOpt(), WebInstallerPage\endForm(), WebInstallerOptions\execute(), WebInstallerLanguage\execute(), SpecialLog\getActionButtons(), SpecialContributions\getForm(), TablePager\getHiddenFields(), HTMLForm\getHiddenFields(), HTMLFormFieldCloner\getInputHTMLForKey(), HTMLFormFieldCloner\getInputOOUIForKey(), HistoryPager\getStartBody(), UserrightsPage\groupCheckboxes(), HistoryAction\onView(), ImagePage\openShowImage(), MediaWiki\Widget\Search\SearchFormWidget\powerSearchBox(), SpecialWatchlist\setTopText(), MediaWiki\Widget\Search\SearchFormWidget\shortDialogHtml(), EditPage\showEditForm(), UserrightsPage\showEditUserGroupsForm(), MovePageForm\showForm(), SpecialEditTags\showForm(), FileDeleteForm\showForm(), SpecialImport\showForm(), SpecialRevisionDelete\showForm(), EditPage\showFormAfterText(), EditPage\showFormBeforeText(), SpecialMergeHistory\showHistory(), SpecialUndelete\showHistory(), SpecialMergeHistory\showMergeForm(), SpecialUndelete\showSearchForm(), UserrightsPage\switchForm(), and SpecialWhatLinksHere\whatlinkshereForm().

◆ htmlHeader()

static Html::htmlHeader ( array  $attribs = [])
static

Constructs the opening html-tag with necessary doctypes depending on global variables.

Parameters
array$attribsAssociative array of miscellaneous extra attributes, passed to Html::element() of html tag.
Returns
string Raw HTML

Definition at line 960 of file Html.php.

References $attribs, $ret, $wgHtml5Version, $wgMimeType, $wgXhtmlNamespaces, and as.

Referenced by OutputPage\headElement(), WebInstallerOutput\outputHeader(), and WebInstallerOutput\outputShortHeader().

◆ infoBox()

static Html::infoBox (   $text,
  $icon,
  $alt,
  $class = '' 
)
static

Get HTML for an info box with an icon.

Parameters
string$textWikitext, get this with wfMessage()->plain()
string$iconPath to icon file (used as 'src' attribute)
string$altAlternate text for the icon
string$classAdditional class name to add to the wrapper div
Returns
string

Definition at line 1017 of file Html.php.

References $s.

Referenced by WebInstaller\getInfoBox().

◆ inlineScript()

static Html::inlineScript (   $contents,
  $nonce = null 
)
static

Output an HTML script tag with the given contents.

It is unsupported for the contents to contain the sequence <script or </script (case-insensitive). This ensures the script can be terminated easily and consistently. It is the responsibility of the caller to avoid such character sequence by escaping or avoiding it. If found at run-time, the contents are replaced with a comment, and a warning is logged server-side.

Parameters
string$contentsJavaScript
string | null$nonceNonce for CSP header, from OutputPage::getCSPNonce()
Returns
string Raw HTML

Definition at line 567 of file Html.php.

References RequestContext\getMain(), ContentSecurityPolicy\isNonceRequired(), wfLogWarning(), and wfWarn().

Referenced by OutputPage\addInlineScript(), WebInstallerOptions\execute(), ResourceLoaderClientHtml\getHeadHtml(), ResourceLoader\isEmptyObject(), OutputPageTest\testAddInlineScript(), and HtmlTest\testInlineScript().

◆ inlineStyle()

static Html::inlineStyle (   $contents,
  $media = 'all',
  $attribs = [] 
)
static

Output a "<style>" tag with the given contents for the given media type (if any).

TODO: do some useful escaping as well, like if $contents contains literal "</style>" (admittedly unlikely).

Parameters
string$contentsCSS
string$mediaA media type string, like 'screen'
array$attribs(since 1.31) Associative array of attributes, e.g., [ 'href' => 'https://www.mediawiki.org/' ]. See expandAttributes() for further documentation.
Returns
string Raw HTML

Definition at line 618 of file Html.php.

References $attribs.

Referenced by OutputPage\addInlineStyle(), ResourceLoaderClientHtml\makeLoad(), and ParserTestRunner\runTest().

◆ input()

static Html::input (   $name,
  $value = '',
  $type = 'text',
array  $attribs = [] 
)
static

Convenience function to produce an "<input>" element.

This supports the new HTML5 input types and attributes.

Parameters
string$nameName attribute
string$valueValue attribute
string$typeType attribute
array$attribsAssociative array of miscellaneous extra attributes, passed to Html::element()
Returns
string Raw HTML

Definition at line 666 of file Html.php.

References $attribs, $name, $type, and $value.

Referenced by Xml\dateMenu(), SpecialContributions\getForm(), HTMLSelectOrOtherField\getInputHTML(), HTMLSelectAndOtherField\getInputHTML(), HTMLFormFieldWithButton\getInputHTML(), HTMLTextField\getInputHTML(), SpecialImport\showForm(), and HtmlTest\testWrapperInput().

◆ isXmlMimeType()

static Html::isXmlMimeType (   $mimetype)
static

Determines if the given MIME type is xml.

Parameters
string$mimetypeMIME type
Returns
bool

Definition at line 999 of file Html.php.

Referenced by OutputPage\headElement(), and HtmlTest\testXmlMimeType().

◆ label()

static Html::label (   $label,
  $id,
array  $attribs = [] 
)
static

Convenience function for generating a label for inputs.

Parameters
string$labelContents of the label
string$idID of the element being labeled
array$attribsAdditional attributes
Returns
string Raw HTML

Definition at line 779 of file Html.php.

References $attribs.

Referenced by HtmlTest\testWrapperLabel(), and Linker\tocList().

◆ linkButton()

static Html::linkButton (   $contents,
array  $attrs,
array  $modifiers = [] 
)
static

Returns an HTML link element in a string styled as a button (when $wgUseMediaWikiUIEverywhere is enabled).

Parameters
string$contentsThe raw HTML contents of the element: not escaped!
array$attrsAssociative array of attributes, e.g., [ 'href' => 'https://www.mediawiki.org/' ]. See expandAttributes() for further documentation.
string[]$modifiers classes to add to the button
See also
https://tools.wmflabs.org/styleguide/desktop/index.html for guidance on available modifiers
Returns
string Raw HTML

Definition at line 166 of file Html.php.

Referenced by EditPage\showStandardInputs().

◆ linkedScript()

static Html::linkedScript (   $url,
  $nonce = null 
)
static

Output a "<script>" tag linking to the given URL, e.g., "<script src=foo.js></script>".

Parameters
string$url
string | null$nonceNonce for CSP header, from OutputPage::getCSPNonce()
Returns
string Raw HTML

Definition at line 593 of file Html.php.

References RequestContext\getMain(), ContentSecurityPolicy\isNonceRequired(), and wfWarn().

Referenced by OutputPage\addScriptFile(), WebInstallerOutput\getJQuery(), WebInstallerOutput\outputHeader(), WebInstallerOutput\outputShortHeader(), SpecialJavaScriptTest\plainQUnit(), and OutputPageTest\testAddScriptFile().

◆ linkedStyle()

static Html::linkedStyle (   $url,
  $media = 'all' 
)
static

Output a "<link rel=stylesheet>" linking to the given URL for the given media type (if any).

Parameters
string$url
string$mediaA media type string, like 'screen'
Returns
string Raw HTML

Definition at line 647 of file Html.php.

Referenced by WebInstallerOutput\getCssUrl(), ResourceLoaderClientHtml\makeLoad(), and OutputPage\styleLink().

◆ messageBox()

static Html::messageBox (   $html,
  $className,
  $heading = '' 
)
staticprivate

Return the HTML for a message box.

Since
1.31
Parameters
string$htmlof contents of box
string$classNamecorresponding to box
string$heading(optional)
Returns
string of HTML representing a box.

Definition at line 710 of file Html.php.

References $html.

◆ namespaceSelector()

static Html::namespaceSelector ( array  $params = [],
array  $selectAttribs = [] 
)
static

Build a drop-down box for selecting a namespace.

Parameters
array$paramsParams to set.
  • selected: [optional] Id of namespace which should be pre-selected
  • all: [optional] Value of item for "all namespaces". If null or unset, no "<option>" is generated to select all namespaces.
  • label: text for label to add before the field.
  • exclude: [optional] Array of namespace ids to exclude.
  • disable: [optional] Array of namespace ids for which the option should be disabled in the selector.
array$selectAttribsHTML attributes for the generated select element.
  • id: [optional], default: 'namespace'.
  • name: [optional], default: 'namespace'.
Returns
string HTML code to select a namespace.

Definition at line 887 of file Html.php.

References $options, $params, $ret, and as.

Referenced by SpecialWatchlist\doHeader(), SpecialContributions\getForm(), HTMLSelectNamespace\getInputHTML(), SpecialImport\getMappingFormPart(), SpecialRecentChanges\namespaceFilterForm(), HtmlTest\testCanDisableANamespaces(), HtmlTest\testCanFilterOutNamespaces(), HtmlTest\testNamespaceSelector(), and SpecialWhatLinksHere\whatlinkshereForm().

◆ namespaceSelectorOptions()

static Html::namespaceSelectorOptions ( array  $params = [])
static

Helper for Html::namespaceSelector().

Parameters
array$paramsSee Html::namespaceSelector()
Returns
array

Definition at line 831 of file Html.php.

References $lang, $options, $params, $wgLang, as, NS_MAIN, and wfMessage().

Referenced by MediaWiki\Widget\NamespaceInputWidget\getNamespaceDropdownOptions().

◆ openElement()

static Html::openElement (   $element,
  $attribs = [] 
)
static

Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/' in XML mode for empty elements).

Parameters
string$elementName of the element, e.g., 'a'
array$attribsAssociative array of attributes, e.g., [ 'href' => 'https://www.mediawiki.org/' ]. See expandAttributes() for further documentation.
Returns
string

Definition at line 252 of file Html.php.

References $attribs, and array().

Referenced by DifferenceEngine\addHeader(), CategoryViewer\columnList(), WebInstallerDBConnect\execute(), SpecialCategories\execute(), SpecialListGrants\execute(), SpecialTrackingCategories\execute(), TablePager\formatRow(), SpecialLog\getActionButtons(), SpecialChangeCredentials\getAuthForm(), OracleInstaller\getConnectForm(), PostgresInstaller\getConnectForm(), MysqlInstaller\getConnectForm(), MssqlInstaller\getConnectForm(), SpecialVersion\getCreditsForExtension(), SpecialVersion\getEntryPointInfo(), SpecialVersion\getExternalLibraries(), BaseTemplate\getFooter(), SpecialContributions\getForm(), ApiHelp\getHelpInternal(), CategoryViewer\getHTML(), DatabaseInstaller\getInstallUserBox(), HTMLMultiSelectField\getOneCheckbox(), HTMLCheckMatrix\getOneCheckboxHTML(), EditPage\getPreviewLimitReport(), MssqlInstaller\getSettingsForm(), TablePager\getStartBody(), HistoryPager\getStartBody(), DatabaseInstaller\getWebUserBox(), SpecialVersion\getWgHooks(), OutputPage\headElement(), ImagePage\imageLinks(), ChangesListSpecialPage\makeLegend(), ApiMain\modifyHelp(), SpecialVersion\openExtType(), WebInstallerOutput\outputHeader(), SpecialSpecialpages\outputPageList(), MediaStatisticsPage\outputTableStart(), EnhancedChangesList\recentChangesBlockLine(), SpecialAllPages\showChunk(), EditPage\showEditForm(), SpecialExpandTemplates\showHtmlPreview(), SpecialPrefixindex\showPrefixChunk(), SpecialChangeCredentials\showSubpageList(), WebInstallerPage\startForm(), UserrightsPage\switchForm(), Linker\tocLine(), and Linker\tocList().

◆ radio()

static Html::radio (   $name,
  $checked = false,
array  $attribs = [] 
)
static

Convenience function to produce a radio button (input element with type=radio)

Parameters
string$nameName attribute
bool$checkedWhether the radio button is checked or not
array$attribsArray of additional attributes
Returns
string Raw HTML

Definition at line 756 of file Html.php.

References $attribs, $name, and $value.

Referenced by HtmlTest\testWrapperRadio().

◆ rawElement()

static Html::rawElement (   $element,
  $attribs = [],
  $contents = '' 
)
static

Returns an HTML element in a string.

The major advantage here over manually typing out the HTML is that it will escape all attribute values.

This is quite similar to Xml::tags(), but it implements some useful HTML-specific logic. For instance, there is no $allowShortTag parameter: the closing tag is magically omitted if $element has an empty content model.

Parameters
string$elementThe element's name, e.g., 'a'
array$attribsAssociative array of attributes, e.g., [ 'href' => 'https://www.mediawiki.org/' ]. See expandAttributes() for further documentation.
string$contentsThe raw HTML contents of the element: not escaped!
Returns
string Raw HTML

Definition at line 210 of file Html.php.

References $attribs.

Referenced by OutputPage\addHelpLink(), InfoAction\addRow(), InfoAction\addTable(), SpecialBlock\alterForm(), JsonContent\arrayRow(), JsonContent\arrayTable(), MediaWiki\Linker\LinkRenderer\buildAElement(), ChangeTags\buildTagFilterSelector(), SpecialEditWatchlist\buildTools(), ApiFormatBase\closePrinter(), Revision\RevisionRenderer\combineSlotOutput(), MWDebug\deprecated(), EditPage\displayPreviewArea(), SpecialRecentChanges\doHeader(), SpecialWatchlist\doHeader(), ImagePage\doRenderLangOpt(), WebInstaller\downloadLinkHook(), SpecialApiHelp\execute(), SpecialListGrants\execute(), SpecialPasswordPolicies\execute(), SpecialPreferences\execute(), SpecialActiveUsers\execute(), SpecialListGroupRights\execute(), SpecialListUsers\execute(), UserrightsPage\execute(), FormatMetadata\flattenArrayReal(), MediaWiki\Widget\Search\InterwikiSearchResultSetWidget\footerHtml(), SpecialNewpages\form(), TemplatesOnThisPageFormatter\format(), OldChangesList\formatChangeLine(), DateFormatter\formatDate(), HTMLFormField\formatErrors(), HTMLForm\formatErrors(), CategoryViewer\formatList(), HTMLMultiSelectField\formatOptions(), HTMLRadioField\formatOptions(), XmlSelect\formatOptions(), DeletedContribsPager\formatRevisionRow(), SpecialMergeHistory\formatRevisionRow(), SpecialProtectedtitles\formatRow(), CategoryPager\formatRow(), SpecialStatistics\formatRow(), ActiveUsersPager\formatRow(), UsersPager\formatRow(), TablePager\formatRow(), DeletedContribsPager\formatRow(), SpecialNewpages\formatRow(), ContribsPager\formatRow(), OOUIHTMLForm\formatSection(), HTMLForm\formatSection(), BlockListPager\formatValue(), ProtectedPagesPager\formatValue(), BaseTemplate\getAfterPortlet(), PreferencesFormOOUI\getBody(), OOUIHTMLForm\getButtons(), VFormHTMLForm\getButtons(), HTMLForm\getButtons(), Skin\getCachedNotice(), Skin\getCategories(), WebInstaller\getCheckBox(), EditPage\getContentObject(), SpecialVersion\getCreditsForExtension(), HTMLFormField\getDiv(), Title\getEditNotices(), TablePager\getEmptyBody(), SpecialVersion\getEntryPointInfo(), HTMLForm\getErrorsOrWarnings(), MediaWiki\EditPage\TextConflictHelper\getExplainHeader(), SpecialVersion\getExternalLibraries(), LoginSignupSpecialPage\getFieldDefinitions(), BaseTemplate\getFooter(), SpecialContributions\getForm(), ApiHelp\getHelpInternal(), HTMLFormField\getHelpTextHtmlDiv(), HTMLFormField\getHelpTextHtmlTable(), ChangesList\getHighlightsContainerDiv(), ListToggle\getHTML(), XmlSelect\getHTML(), BaseTemplate\getIndicators(), HTMLCheckField\getInputHTML(), HTMLButtonField\getInputHTML(), HTMLCheckMatrix\getInputHTML(), Licenses\getInputHTML(), HTMLFormFieldCloner\getInputHTML(), HTMLFormFieldCloner\getInputHTMLForKey(), HTMLFormFieldCloner\getInputOOUI(), HTMLFormFieldCloner\getInputOOUIForKey(), UploadSourceField\getLabelHtml(), HTMLFormField\getLabelHtml(), TablePager\getLimitForm(), LoginSignupSpecialPage\getPageHtml(), SpecialVersion\getParserFunctionHooks(), SpecialVersion\getParserTags(), EditPage\getPreviewLimitReport(), EditPage\getPreviewText(), Block\getRedactedName(), LogFormatter\getRestrictedElement(), BlockListPager\getRestrictionListHTML(), DifferenceEngine\getRevisionHeader(), DifferenceEngine\getSlotHeader(), TablePager\getStartBody(), MediaStatisticsPage\getTableHeaderRow(), HTMLCheckMatrix\getTableRow(), HTMLFormField\getTableRow(), ParserOutput\getText(), MediaWiki\Widget\Search\SimpleSearchResultSetWidget\headerHtml(), HistoryPager\historyLine(), CoreTagHooks\html(), ImagePage\imageLinks(), LogEventsList\logLine(), Linker\makeExternalLink(), Skin\makeFooterIcon(), InfoAction\makeHeader(), Linker\makeImageLink(), ChangesListSpecialPage\makeLegend(), BaseTemplate\makeLink(), SpecialBookSources\makeListItem(), BaseTemplate\makeListItem(), ResourceLoaderClientHtml\makeLoad(), Linker\makeMediaLinkFile(), ImagePage\makeMetadataTable(), BaseTemplate\makeSearchButton(), ImagePage\makeSizeLink(), EditPage\makeTemplatesOnThisPageList(), Linker\makeThumbLink2(), ApiMain\modifyHelp(), JsonContent\objectRow(), JsonContent\objectTable(), CreditsAction\onView(), SpecialVersion\openExtType(), ImagePage\openShowImage(), SpecialRecentChanges\optionsPanel(), SpecialListGroupRights\outputNamespaceProtectionInfo(), SpecialRecentChangesLinked\outputNoResults(), SpecialSpecialpages\outputPageList(), MediaStatisticsPage\outputTableRow(), InfoAction\pageInfo(), SpecialBlock\postText(), CoreTagHooks\pre(), SkinTemplate\prepareQuickTemplate(), SpecialBlock\preText(), EnhancedChangesList\recentChangesBlockLine(), OldChangesList\recentChangesLine(), MediaWiki\Widget\Search\InterwikiSearchResultWidget\render(), MediaWiki\Widget\Search\InterwikiSearchResultSetWidget\render(), JsonContent\rootValueTable(), SpecialNewFiles\setTopText(), SpecialRecentChanges\setTopText(), SpecialWatchlist\setTopText(), SpecialAllPages\showChunk(), DifferenceEngine\showDiffPage(), EditPage\showEditForm(), SpecialWatchlist\showHideCheck(), OutputPage\showLagWarning(), SpecialAutoblockList\showList(), SpecialBlockList\showList(), SpecialUndelete\showList(), LogEventsList\showLogExtract(), LogEventsList\showOptions(), SpecialPrefixindex\showPrefixChunk(), McrUndoAction\showPreview(), SpecialChangeCredentials\showSubpageList(), SpecialAutoblockList\showTotal(), SpecialUploadStash\showUploads(), SpecialUpload\showViewDeletedLinks(), LogFormatter\styleRestricedElement(), Linker\tocLine(), Linker\userLink(), JsonContent\valueCell(), ApiHelp\wrap(), VFormHTMLForm\wrapForm(), HTMLForm\wrapForm(), and SkinTemplate\wrapHTML().

◆ srcSet()

static Html::srcSet ( array  $urls)
static

Generate a srcset attribute value.

Generates a srcset attribute value from an array mapping pixel densities to URLs. A trailing 'x' in pixel density values is optional.

Note
srcset width and height values are not supported.
See also
https://html.spec.whatwg.org/#attr-img-srcset
Example:
'1x' => 'standard.jpeg',
'1.5x' => 'large.jpeg',
'3x' => 'extra-large.jpeg',
] );
// gives 'standard.jpeg 1x, large.jpeg 1.5x, extra-large.jpeg 2x'
Parameters
string[]$urls
Returns
string

Definition at line 1064 of file Html.php.

References as, and string.

Referenced by HtmlTest\testSrcSet(), and ThumbnailImage\toHtml().

◆ submitButton()

static Html::submitButton (   $contents,
array  $attrs,
array  $modifiers = [] 
)
static

Returns an HTML link element in a string styled as a button (when $wgUseMediaWikiUIEverywhere is enabled).

Parameters
string$contentsThe raw HTML contents of the element: not escaped!
array$attrsAssociative array of attributes, e.g., [ 'href' => 'https://www.mediawiki.org/' ]. See expandAttributes() for further documentation.
string[]$modifiers classes to add to the button
See also
https://tools.wmflabs.org/styleguide/desktop/index.html for guidance on available modifiers
Returns
string Raw HTML

Definition at line 186 of file Html.php.

Referenced by SpecialContributions\getForm(), HistoryAction\onView(), and HistoryPager\submitButton().

◆ successBox()

static Html::successBox (   $html)
static

Return a success box.

Since
1.31
Parameters
string$htmlof contents of box
Returns
string of HTML representing a success box.

Definition at line 744 of file Html.php.

References $html.

Referenced by SpecialResetTokens\onSuccess(), and HtmlTest\testSuccessBox().

◆ textarea()

static Html::textarea (   $name,
  $value = '',
array  $attribs = [] 
)
static

Convenience function to produce a <textarea> element.

This supports leaving out the cols= and rows= which Xml requires and are required by HTML4/XHTML but not required by HTML5.

Parameters
string$nameName attribute
string$valueValue attribute
array$attribsAssociative array of miscellaneous extra attributes, passed to Html::element()
Returns
string Raw HTML

Definition at line 811 of file Html.php.

References $attribs, $name, and $value.

Referenced by MediaWiki\EditPage\TextConflictHelper\getEditConflictMainTextBox(), HTMLTextAreaField\getInputHTML(), MediaWiki\EditPage\TextConflictHelper\showEditFormTextAfterFooters(), and EditPage\showTextbox().

◆ warningBox()

static Html::warningBox (   $html)
static

Return a warning box.

Since
1.31
Parameters
string$htmlof contents of box
Returns
string of HTML representing a warning box.

Definition at line 723 of file Html.php.

References $html.

Referenced by SkinFallbackTemplate\execute(), EditPage\showHeader(), SpecialSearch\showResults(), and HtmlTest\testWarningBox().

Member Data Documentation

◆ $boolAttribs

Html::$boolAttribs
staticprivate
Initial value:
= [
'async',
'autofocus',
'autoplay',
'checked',
'controls',
'default',
'defer',
'disabled',
'formnovalidate',
'hidden',
'ismap',
'itemscope',
'loop',
'multiple',
'muted',
'novalidate',
'open',
'pubdate',
'readonly',
'required',
'reversed',
'scoped',
'seamless',
'selected',
'truespeed',
'typemustmatch',
'itemscope',
]

Definition at line 71 of file Html.php.

◆ $voidElements

Html::$voidElements
staticprivate
Initial value:
= [
'area',
'base',
'br',
'col',
'embed',
'hr',
'img',
'input',
'keygen',
'link',
'meta',
'param',
'source',
'track',
'wbr',
]

Definition at line 51 of file Html.php.


The documentation for this class was generated from the following file: