MediaWiki master
|
This class is a collection of static functions that serve two purposes: More...
Static Public Member Functions | |
static | addClass (&$classes, string $class) |
Add a class to a 'class' attribute in a format accepted by Html::element(). | |
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 | expandClassList ( $classes) |
Convert a value for a 'class' attribute in a format accepted by Html::element() and similar methods to a single string. | |
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 |
Add a class to a 'class' attribute in a format accepted by Html::element().
This method may also be used for any other space-separated attribute, such as 'rel'.
array | string | null | &$classes | Class list to modify in-place |
string | $class | Class to add |
Definition at line 146 of file Html.php.
References wfWarn().
|
static |
Modifies a set of attributes meant for button elements.
array | $attrs | HTML attributes in an associative array |
string[] | $modifiers | Unused |
Definition at line 119 of file Html.php.
References wfDeprecated().
|
static |
|
static |
Returns "</$element>".
string | $element | Name of the element, e.g., 'a' |
Definition at line 333 of file Html.php.
Referenced by MediaWiki\Site\SiteExporter\exportSites().
|
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 |
|
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. |
|
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. |
|
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 1158 of file Html.php.
Referenced by 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. |
|
static |
Convert a value for a 'class' attribute in a format accepted by Html::element() and similar methods to a single string.
This method may also be used for any other space-separated attribute, such as 'rel'.
array | string | $classes |
|
static |
Modifies a set of attributes meant for text input elements.
array | $attrs | An attribute array. |
Definition at line 131 of file Html.php.
References wfDeprecated().
|
static |
|
static |
|
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 611 of file Html.php.
References 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. |
|
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() |
|
static |
|
static |
|
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 173 of file Html.php.
References MediaWiki\Html\element().
|
static |
|
static |
|
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:
|
|
static |
|
static |
|
static |
Build a drop-down box for selecting a namespace.
array | $params | Params to set.
|
array | $selectAttribs | HTML attributes for the generated select element.
|
|
static |
Helper for Html::namespaceSelector().
array | $params | See Html::namespaceSelector() |
Definition at line 919 of file Html.php.
References $wgLang, NS_MAIN, and wfMessage().
|
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 269 of file Html.php.
References wfWarn().
Referenced by MediaWiki\Site\SiteExporter\exportSites().
|
static |
|
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 219 of file Html.php.
Referenced by MediaWiki\Html\ListToggle\getHTML().
|
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 1123 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 191 of file Html.php.
References MediaWiki\Html\element().
|
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() |
|
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 |