MediaWiki master
|
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. | |
static | check ( $name, $checked=false, array $attribs=[]) |
Convenience function to produce a checkbox (input element with type=checkbox) | |
static | closeElement ( $element) |
Returns "</$element>". | |
static | element ( $element, $attribs=[], $contents='') |
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()). | |
static | encodeJsCall ( $name, $args, $pretty=false) |
Create a call to a JavaScript function. | |
static | encodeJsList ( $args, $pretty=false) |
Encode a JavaScript comma-separated list. | |
static | encodeJsVar ( $value, $pretty=false) |
Encode a variable of arbitrary type to JavaScript. | |
static | errorBox ( $html, $heading='', $className='') |
Return an error box. | |
static | expandAttributes (array $attribs) |
Given an associative array of element attributes, generate a string to stick after the element name in HTML output. | |
static | getTextInputAttributes (array $attrs) |
Modifies a set of attributes meant for text input elements. | |
static | hidden ( $name, $value, array $attribs=[]) |
Convenience function to produce an input element with type=hidden. | |
static | htmlHeader (array $attribs=[]) |
Constructs the opening html-tag with necessary doctypes depending on global variables. | |
static | inlineScript ( $contents, $nonce=null) |
Output an HTML script tag with the given contents. | |
static | inlineStyle ( $contents, $media='all', $attribs=[]) |
Output a "<style>" tag with the given contents for the given media type (if any). | |
static | input ( $name, $value='', $type='text', array $attribs=[]) |
Convenience function to produce an <input> element. | |
static | isXmlMimeType ( $mimetype) |
Determines if the given MIME type is xml. | |
static | label ( $label, $id, array $attribs=[]) |
Convenience function for generating a label for inputs. | |
static | linkButton ( $text, array $attrs, array $modifiers=[]) |
Returns an HTML link element in a string. | |
static | linkedScript ( $url, $nonce=null) |
Output a "<script>" tag linking to the given URL, e.g., "<script src=foo.js></script>". | |
static | linkedStyle ( $url, $media='all') |
Output a "<link rel=stylesheet>" linking to the given URL for the given media type (if any). | |
static | listDropdownOptions ( $list, $params=[]) |
Build options for a drop-down box from a textual list. | |
static | listDropdownOptionsCodex ( $options) |
Convert options for a drop-down box into a format accepted by OOUI\DropdownInputWidget etc. | |
static | listDropdownOptionsOoui ( $options) |
Convert options for a drop-down box into a format accepted by OOUI\DropdownInputWidget etc. | |
static | namespaceSelector (array $params=[], array $selectAttribs=[]) |
Build a drop-down box for selecting a namespace. | |
static | namespaceSelectorOptions (array $params=[]) |
Helper for Html::namespaceSelector(). | |
static | noticeBox ( $html, $className, $heading='', $iconClassName='') |
Return the HTML for a notice message box. | |
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). | |
static | radio ( $name, $checked=false, array $attribs=[]) |
Convenience function to produce a radio button (input element with type=radio) | |
static | rawElement ( $element, $attribs=[], $contents='') |
Returns an HTML element in a string. | |
static | srcSet (array $urls) |
Generate a srcset attribute value. | |
static | submitButton ( $contents, array $attrs=[], array $modifiers=[]) |
Returns an HTML input element in a string. | |
static | successBox ( $html, $className='') |
Return a success box. | |
static | textarea ( $name, $value='', array $attribs=[]) |
Convenience function to produce a <textarea> element. | |
static | warningBox ( $html, $className='') |
Return a warning box. | |
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.
|
static |
Modifies a set of attributes meant for button elements.
array | $attrs | HTML attributes in an associative array |
string[] | $modifiers | Unused |
Definition at line 118 of file Html.php.
References wfDeprecated().
|
static |
Convenience function to produce a checkbox (input element with type=checkbox)
string | $name | Name attribute |
bool | $checked | Whether the checkbox is checked or not |
array | $attribs | Array of additional attributes |
Definition at line 672 of file Html.php.
References MediaWiki\Html\Html\input().
Referenced by MediaWiki\Specials\SpecialUndelete\formatRevisionRow(), MediaWiki\Installer\WebInstaller\getCheckBox(), MediaWiki\Specials\SpecialRecentChangesLinked\getExtraOptions(), MediaWiki\HTMLForm\Field\HTMLCheckField\getInputCodex(), MediaWiki\HTMLForm\Field\HTMLCheckField\getInputHTML(), MediaWiki\HTMLForm\Field\HTMLMultiSelectField\getOneCheckbox(), and MediaWiki\HTMLForm\Field\HTMLCheckMatrix\getOneCheckboxHTML().
|
static |
Returns "</$element>".
string | $element | Name of the element, e.g., 'a' |
Definition at line 304 of file Html.php.
Referenced by MediaWiki\SpecialPage\QueryPage\execute(), MediaWiki\Specials\SpecialPasswordPolicies\execute(), MediaWiki\Specials\SpecialStatistics\execute(), MediaWiki\Site\SiteExporter\exportSites(), MediaWiki\Specials\SpecialWhatLinksHere\listEnd(), MediaWiki\Html\Html\namespaceSelector(), MediaWiki\Html\Html\rawElement(), MediaWiki\Search\SearchWidgets\SearchFormWidget\render(), and MediaWiki\Specials\SpecialUserRights\showEditUserGroupsForm().
|
static |
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
string | $element | Name of the element, e.g., 'a' |
array | $attribs | Associative array of attributes, e.g., [ 'href' => 'https://www.mediawiki.org/' ]. See expandAttributes() for further documentation. |
string | $contents |
Definition at line 216 of file Html.php.
References MediaWiki\Html\Html\rawElement().
Referenced by MediaWiki\Maintenance\TextPassDumper\clearOpenElement(), MediaWiki\Preferences\DefaultPreferencesFactory\datetimePreferences(), MediaWiki\Specials\SpecialPasswordPolicies\execute(), MediaWiki\Html\Html\input(), MediaWiki\Html\Html\label(), MediaWiki\Html\Html\linkButton(), MediaWiki\Html\Html\linkedScript(), MediaWiki\Html\Html\linkedStyle(), MediaWiki\Search\SearchWidgets\SearchFormWidget\makeSearchLink(), MediaWiki\Html\Html\namespaceSelector(), MediaWiki\Specials\SpecialChangeContentModel\postHtml(), MediaWiki\Specials\SpecialSearch\setupPage(), MediaWiki\Specials\SpecialUndelete\showHistory(), MediaWiki\Html\Html\submitButton(), and MediaWiki\Html\Html\textarea().
|
static |
Create a call to a JavaScript function.
The supplied arguments will be encoded using Html::encodeJsVar().
Xml
since 1.17) string | $name | The name of the function to call, or a JavaScript expression which evaluates to a function object which is called. |
array | $args | The arguments to pass to the function. |
bool | $pretty | If true, add non-significant whitespace to improve readability. |
Definition at line 1147 of file Html.php.
References MediaWiki\Html\Html\encodeJsList().
|
static |
Encode a JavaScript comma-separated list.
The supplied items will be encoded using Html::encodeJsVar().
array | $args | The elements of the list. |
bool | $pretty | If true, add non-significant whitespace to improve readability. |
Definition at line 1164 of file Html.php.
References MediaWiki\Html\Html\encodeJsVar().
Referenced by MediaWiki\Html\Html\encodeJsCall().
|
static |
Encode a variable of arbitrary type to JavaScript.
If the value is an HtmlJsCode object, pass through the object's value verbatim.
Xml
) mixed | $value | The value being encoded. Can be any type except a resource. |
bool | $pretty | If true, add non-significant whitespace to improve readability. |
Definition at line 1126 of file Html.php.
Referenced by MediaWiki\Html\Html\encodeJsList(), and MediaWiki\Html\HtmlJsCode\encodeObject().
|
static |
Return an error box.
This method produces HTML that requires CSS styles for the Codex MessageBox component that need to be supplied by mediawiki.codex.messagebox.styles or another suitable Codex style module.
string | $html | of contents of error box |
string | $heading | (optional) |
string | $className | (optional) corresponding to box |
|
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.
array | $attribs | Associative 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. |
Definition at line 456 of file Html.php.
Referenced by MediaWiki\Html\Html\openElement().
|
static |
Modifies a set of attributes meant for text input elements.
array | $attrs | An attribute array. |
Definition at line 130 of file Html.php.
References wfDeprecated().
|
static |
Convenience function to produce an input element with type=hidden.
string | $name | Name attribute |
mixed | $value | Value attribute |
array | $attribs | Associative array of miscellaneous extra attributes, passed to Html::element() |
Definition at line 851 of file Html.php.
References MediaWiki\Html\Html\input().
|
static |
Constructs the opening html-tag with necessary doctypes depending on global variables.
array | $attribs | Associative array of miscellaneous extra attributes, passed to Html::element() of html tag. |
Definition at line 1020 of file Html.php.
References MediaWiki\MediaWikiServices\getInstance(), MediaWiki\MainConfigNames\Html5Version, MediaWiki\Html\Html\isXmlMimeType(), MediaWiki\MainConfigNames\MimeType, MediaWiki\Html\Html\openElement(), and MediaWiki\MainConfigNames\XhtmlNamespaces.
|
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.
string | $contents | JavaScript |
string | null | $nonce | Unused |
Definition at line 569 of file Html.php.
References MediaWiki\Html\Html\rawElement(), and wfLogWarning().
|
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).
string | $contents | CSS |
string | $media | A 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. |
Definition at line 609 of file Html.php.
References MediaWiki\Html\Html\rawElement().
|
static |
Convenience function to produce an <input>
element.
This supports the new HTML5 input types and attributes.
string | $name | Name attribute |
string | $value | Value attribute |
string | $type | Type attribute |
array | $attribs | Associative array of miscellaneous extra attributes, passed to Html::element() |
Definition at line 657 of file Html.php.
References MediaWiki\Html\Html\element().
Referenced by MediaWiki\Html\Html\check(), MediaWiki\Specials\SpecialRecentChangesLinked\getExtraOptions(), MediaWiki\Installer\WebInstaller\getTextBox(), MediaWiki\Html\Html\hidden(), MediaWiki\Html\Html\radio(), and MediaWiki\Specials\SpecialUserRights\showEditUserGroupsForm().
|
static |
Determines if the given MIME type is xml.
string | $mimetype |
Definition at line 1060 of file Html.php.
Referenced by MediaWiki\Html\Html\htmlHeader().
|
static |
Convenience function for generating a label for inputs.
string | $label | Contents of the label |
string | $id | ID of the element being labeled |
array | $attribs | Additional attributes |
Definition at line 835 of file Html.php.
References MediaWiki\Html\Html\element().
Referenced by MediaWiki\Installer\WebInstallerDBConnect\execute(), and MediaWiki\Specials\SpecialRecentChangesLinked\getExtraOptions().
|
static |
Returns an HTML link element in a string.
string | $text | The text of the element. Will be escaped (not raw HTML) |
array | $attrs | Associative array of attributes, e.g., [ 'href' => 'https://www.mediawiki.org/' ]. See expandAttributes() for further documentation. |
string[] | $modifiers | Unused |
Definition at line 145 of file Html.php.
References MediaWiki\Html\Html\element().
|
static |
Output a "<script>" tag linking to the given URL, e.g., "<script src=foo.js></script>".
string | $url | |
string | null | $nonce | Nonce for CSP header, from OutputPage->getCSP()->getNonce() |
Definition at line 586 of file Html.php.
References $url, MediaWiki\Html\Html\element(), MediaWiki\MediaWikiServices\getInstance(), and wfWarn().
|
static |
Output a "<link rel=stylesheet>" linking to the given URL for the given media type (if any).
string | $url | |
string | $media | A media type string, like 'screen' |
Definition at line 638 of file Html.php.
References $url, and MediaWiki\Html\Html\element().
|
static |
Build options for a drop-down box from a textual list.
The result of this function can be passed to XmlSelect::addOptions() (to render a plain <select>
dropdown box) or to Html::listDropdownOptionsOoui() and then OOUI\DropdownInputWidget() (to render a pretty one).
string | $list | Correctly formatted text (newline delimited) to be used to generate the options. |
array | $params | Extra parameters:
|
Definition at line 1191 of file Html.php.
References $params.
Referenced by MediaWiki\Specials\SpecialUndelete\showHistory().
|
static |
|
static |
Convert options for a drop-down box into a format accepted by OOUI\DropdownInputWidget etc.
TODO Find a better home for this function.
array | $options | Options, as returned e.g. by Html::listDropdownOptions() |
Definition at line 1241 of file Html.php.
Referenced by MediaWiki\Specials\SpecialUndelete\showHistory().
|
static |
Build a drop-down box for selecting a namespace.
array | $params | Params to set.
|
array | $selectAttribs | HTML attributes for the generated select element.
|
Definition at line 951 of file Html.php.
References $params, MediaWiki\Html\Html\closeElement(), MediaWiki\Html\Html\element(), MediaWiki\Html\Html\namespaceSelectorOptions(), and MediaWiki\Html\Html\openElement().
|
static |
Helper for Html::namespaceSelector().
array | $params | See Html::namespaceSelector() |
Definition at line 887 of file Html.php.
References $params, $wgLang, MediaWiki\MediaWikiServices\getInstance(), NS_MAIN, and wfMessage().
Referenced by MediaWiki\Html\Html\namespaceSelector().
|
static |
Return the HTML for a notice message box.
This method produces HTML that requires CSS styles for the Codex MessageBox component that need to be supplied by mediawiki.codex.messagebox.styles or another suitable Codex style module.
string | $html | of contents of notice |
string | array | $className | corresponding to notice |
string | $heading | (optional) |
string | array | $iconClassName | (optional) corresponding to notice icon |
|
static |
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/' in XML mode for empty elements).
string | $element | Name of the element, e.g., 'a' |
array | $attribs | Associative array of attributes, e.g., [ 'href' => 'https://www.mediawiki.org/' ]. See expandAttributes() for further documentation. |
Definition at line 240 of file Html.php.
References MediaWiki\Html\Html\expandAttributes(), and wfWarn().
Referenced by MediaWiki\SpecialPage\QueryPage\execute(), MediaWiki\Specials\SpecialPasswordPolicies\execute(), MediaWiki\Specials\SpecialStatistics\execute(), MediaWiki\Site\SiteExporter\exportSites(), MediaWiki\Pager\AllMessagesTablePager\getStartBody(), MediaWiki\Html\Html\htmlHeader(), MediaWiki\Specials\SpecialWhatLinksHere\listStart(), MediaWiki\Html\Html\namespaceSelector(), MediaWiki\Html\Html\rawElement(), and MediaWiki\Search\SearchWidgets\SearchFormWidget\render().
|
static |
Convenience function to produce a radio button (input element with type=radio)
string | $name | Name attribute |
bool | $checked | Whether the radio button is checked or not |
array | $attribs | Array of additional attributes |
Definition at line 812 of file Html.php.
References MediaWiki\Html\Html\input().
Referenced by MediaWiki\Installer\WebInstallerDBConnect\execute(), MediaWiki\HTMLForm\Field\HTMLRadioField\formatOptions(), MediaWiki\Pager\MergeHistoryPager\formatRow(), and MediaWiki\Installer\WebInstaller\getRadioElements().
|
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.
string | $element | The element's name, e.g., 'a' |
array | $attribs | Associative array of attributes, e.g., [ 'href' => 'https://www.mediawiki.org/' ]. See expandAttributes() for further documentation. |
string | $contents | The raw HTML contents of the element: not escaped! |
Definition at line 191 of file Html.php.
References MediaWiki\Html\Html\closeElement(), and MediaWiki\Html\Html\openElement().
Referenced by MediaWiki\Html\Html\element(), MediaWiki\Html\ListToggle\getHTML(), MediaWiki\Html\Html\inlineScript(), and MediaWiki\Html\Html\inlineStyle().
|
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.
string[] | $urls |
Definition at line 1091 of file Html.php.
References $url.
|
static |
Returns an HTML input element in a string.
string | $contents | Plain text label for the button value |
array | $attrs | Associative array of attributes, e.g., [ 'href' => 'https://www.mediawiki.org/' ]. See expandAttributes() for further documentation. |
string[] | $modifiers | Unused |
Definition at line 163 of file Html.php.
References MediaWiki\Html\Html\element().
Referenced by MediaWiki\Installer\WebInstallerPage\endForm(), MediaWiki\HTMLForm\HTMLForm\getButtons(), and MediaWiki\Specials\SpecialRevisionDelete\tryShowFile().
|
static |
Return a success box.
This method produces HTML that requires CSS styles for the Codex MessageBox component that need to be supplied by mediawiki.codex.messagebox.styles or another suitable Codex style module.
string | $html | of contents of box |
string | $className | (optional) corresponding to box |
|
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.
string | $name | Name attribute |
string | $value | Value attribute |
array | $attribs | Associative array of miscellaneous extra attributes, passed to Html::element() |
Definition at line 867 of file Html.php.
References MediaWiki\Html\Html\element().
Referenced by MediaWiki\Installer\WebInstaller\getTextArea().
|
static |
Return a warning box.
This method produces HTML that requires CSS styles for the Codex MessageBox component that need to be supplied by mediawiki.codex.messagebox.styles or another suitable Codex style module.
string | $html | of contents of box |
string | $className | (optional) corresponding to box |