MediaWiki REL1_39
|
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. | |
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 | 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 and apply a set of default attributes. | |
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 styled as a button (when $wgUseMediaWikiUIEverywhere is enabled). | |
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 | 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) |
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 link element in a string styled as a button (when $wgUseMediaWikiUIEverywhere is enabled). | |
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 and apply a set of default attributes when $wgUseMediaWikiUIEverywhere enabled.
array | $attrs | HTML attributes in an associative array |
string[] | $modifiers | classes to add to the button |
|
static |
|
static |
|
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 |
|
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. |
MWException | If an attribute that doesn't allow lists is set to an array |
|
static |
|
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 | Nonce for CSP header, from OutputPage->getCSP()->getNonce() |
Definition at line 593 of file Html.php.
References ContentSecurityPolicy\isNonceRequired(), wfLogWarning(), and wfWarn().
|
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 styled as a button (when $wgUseMediaWikiUIEverywhere is enabled).
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 | classes to add to the button |
|
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 617 of file Html.php.
References ContentSecurityPolicy\isNonceRequired(), and wfWarn().
|
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 |
|
static |
|
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 256 of file Html.php.
References wfWarn().
|
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! |
|
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 |
|
static |
Returns an HTML link element in a string styled as a button (when $wgUseMediaWikiUIEverywhere is enabled).
string | $contents | The raw HTML contents of the element: not escaped! |
array | $attrs | Associative array of attributes, e.g., [ 'href' => 'https://www.mediawiki.org/' ]. See expandAttributes() for further documentation. |
string[] | $modifiers | classes to add to the button |
|
static |
|
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 |