MediaWiki
REL1_24
|
This class is a collection of static functions that serve two purposes: More...
Static Public Member Functions | |
static | check ($name, $checked=false, array $attribs=array()) |
Convenience function to produce a checkbox (input element with type=checkbox) | |
static | closeElement ($element) |
Returns "</$element>". | |
static | element ($element, $attribs=array(), $contents= '') |
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()). | |
static | expandAttributes ($attribs) |
Given an associative array of element attributes, generate a string to stick after the element name in HTML output. | |
static | getTextInputAttributes ($attrs) |
Modifies a set of attributes meant for text input elements and apply a set of default attributes. | |
static | hidden ($name, $value, $attribs=array()) |
Convenience function to produce an input element with type=hidden. | |
static | htmlHeader ($attribs=array()) |
Constructs the opening html-tag with necessary doctypes depending on global variables. | |
static | infoBox ($text, $icon, $alt, $class=false) |
Get HTML for an info box with an icon. | |
static | inlineScript ($contents) |
Output a "<script>" tag with the given contents. | |
static | inlineStyle ($contents, $media= 'all') |
Output a "<style>" tag with the given contents for the given media type (if any). | |
static | input ($name, $value= '', $type= 'text', $attribs=array()) |
Convenience function to produce an "<input>" element. | |
static | isXmlMimeType ($mimetype) |
Determines if the given MIME type is xml. | |
static | label ($label, $id, array $attribs=array()) |
Convenience function for generating a label for inputs. | |
static | linkedScript ($url) |
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(), array $selectAttribs=array()) |
Build a drop-down box for selecting a namespace. | |
static | openElement ($element, $attribs=array()) |
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=array()) |
Convenience function to produce a checkbox (input element with type=checkbox) | |
static | rawElement ($element, $attribs=array(), $contents= '') |
Returns an HTML element in a string. | |
static | srcSet ($urls) |
Generate a srcset attribute value from an array mapping pixel densities to URLs. | |
static | textarea ($name, $value= '', $attribs=array()) |
Convenience function to produce a <textarea> element. | |
Static Private Member Functions | |
static | dropDefaults ($element, $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. | |
Static Private Attributes | |
static | $boolAttribs |
static | $voidElements |
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. $wgWellFormedXml: If this is set to true, then all output should be well-formed XML (quotes on attributes, self-closing tags, etc.).
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 Html::check | ( | $ | name, |
$ | checked = false , |
||
array $ | attribs = array() |
||
) | [static] |
static Html::closeElement | ( | $ | element | ) | [static] |
Returns "</$element>".
string | $element | Name of the element, e.g., 'a' |
Definition at line 263 of file Html.php.
Referenced by SpecialTrackingCategories\execute(), SpecialCategories\execute(), LinkSearchPage\execute(), FileDuplicateSearchPage\execute(), TablePager\formatRow(), PostgresInstaller\getConnectForm(), OracleInstaller\getConnectForm(), MssqlInstaller\getConnectForm(), MysqlInstaller\getConnectForm(), SpecialVersion\getCreditsForExtension(), EditPage\getEditButtons(), SpecialVersion\getEntryPointInfo(), HTMLCheckMatrix\getInputHTML(), TablePager\getNavigationBar(), WithoutInterwikiPage\getPageHeader(), SpecialLog\getRevisionButton(), MssqlInstaller\getSettingsForm(), SpecialVersion\getWgHooks(), infoBox(), SpecialBookSources\makeForm(), namespaceSelector(), SpecialVersion\openExtType(), SpecialSpecialpages\outputPageList(), MediaStatisticsPage\outputTableEnd(), rawElement(), EmailConfirmation\showRequestForm(), UserrightsPage\switchForm(), and wfHtmlValidationHandler().
static Html::dropDefaults | ( | $ | element, |
$ | attribs | ||
) | [static, private] |
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).
string | $element | Name of the element, e.g., 'a' |
array | $attribs | Associative array of attributes, e.g., array( 'href' => 'http://www.mediawiki.org/' ). See expandAttributes() for further documentation. |
static Html::element | ( | $ | element, |
$ | attribs = array() , |
||
$ | contents = '' |
||
) | [static] |
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
string | $element | |
array | $attribs | |
string | $contents |
Definition at line 177 of file Html.php.
References $attribs, array(), and rawElement().
Referenced by MWDebug\deprecated(), UserloginTemplate\execute(), SpecialVersion\execute(), LinkSearchPage\execute(), FileDuplicateSearchPage\execute(), PageQueryPage\formatResult(), PopularPagesPage\formatResult(), FewestrevisionsPage\formatResult(), MostlinkedCategoriesPage\formatResult(), UnwatchedpagesPage\formatResult(), ShortPagesPage\formatResult(), MostcategoriesPage\formatResult(), MostinterwikisPage\formatResult(), MostlinkedTemplatesPage\formatResult(), MostlinkedPage\formatResult(), SpecialPagesWithProp\formatResult(), SpecialProtectedtitles\formatRow(), ProtectedPagesPager\formatValue(), HTMLForm\getButtons(), PostgresInstaller\getConnectForm(), OracleInstaller\getConnectForm(), MssqlInstaller\getConnectForm(), MysqlInstaller\getConnectForm(), SpecialVersion\getCreditsForExtension(), UploadForm\getDescriptionSection(), FeedUtils\getDiffLink(), TablePager\getEmptyBody(), SpecialVersion\getEntryPointInfo(), HTMLCheckMatrix\getInputHTML(), WithoutInterwikiPage\getPageHeader(), SpecialLog\getRevisionButton(), MssqlInstaller\getSettingsForm(), TablePager\getStartBody(), SpecialVersion\getVersionLinkedGit(), SpecialVersion\getWgHooks(), infoBox(), input(), label(), linkedScript(), linkedStyle(), Linker\makeExternalImage(), Skin\makeFooterIcon(), SpecialBookSources\makeForm(), InfoAction\makeHeader(), SpecialBookSources\makeListItem(), namespaceSelector(), InfoAction\onView(), SpecialVersion\openExtType(), MediaStatisticsPage\outputMediaType(), SpecialListGroupRights\outputNamespaceProtectionInfo(), SpecialSpecialpages\outputPageList(), MediaStatisticsPage\outputTableRow(), InfoAction\pageInfo(), ImportReporter\reportNotice(), SpecialImport\showForm(), SpecialBlockList\showList(), SpecialPrefixindex\showPrefixChunk(), SpecialUploadStash\showUploads(), HtmlTest\testElementBasics(), textarea(), and wfHtmlValidationHandler().
static Html::expandAttributes | ( | $ | attribs | ) | [static] |
Given an associative array of element attributes, generate a string to stick after the element name in HTML output.
Like array( 'href' => 'http://www.mediawiki.org/' ) becomes something like ' href="http://www.mediawiki.org"'. Again, this is like Xml::expandAttributes(), but it implements some HTML-specific logic. For instance, it will omit quotation marks if $wgWellFormedXml is false, and will treat boolean attributes specially.
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.
Html::element( 'em', array( 'class' => array( 'foo', 'bar' ) ) ); // gives '<em class="foo bar"></em>'
Html::element( 'em', array( 'class' => array( 'foo', 'bar', 'foo' => false, 'quux' => true ) ) ); // gives '<em class="bar quux"></em>'
array | $attribs | Associative array of attributes, e.g., array( 'href' => 'http://www.mediawiki.org/' ). Values will be HTML-escaped. A value of false means to omit the attribute. For boolean attributes, you can omit the key, e.g., array( 'checked' ) instead of array( 'checked' => 'checked' ) or such. |
MWException | If an attribute that doesn't allow lists is set to an array |
Definition at line 432 of file Html.php.
References $attribs, $key, $ret, $value, array(), as, and global.
Referenced by openElement().
static Html::getTextInputAttributes | ( | $ | 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.
array | $attrs | An attribute array. |
Definition at line 111 of file Html.php.
References array(), and global.
Referenced by Xml\input(), input(), Xml\textarea(), and textarea().
static Html::hidden | ( | $ | name, |
$ | value, | ||
$ | attribs = array() |
||
) | [static] |
Convenience function to produce an input element with type=hidden.
string | $name | Name attribute |
string | $value | Value attribute |
array | $attribs | Associative array of miscellaneous extra attributes, passed to Html::element() |
Definition at line 740 of file Html.php.
References $attribs, $name, $value, and input().
Referenced by ChangeTags\buildTagFilterSelector(), Preferences\datetimePreferences(), SpecialRecentChanges\doHeader(), SpecialWatchlist\doHeader(), LinkSearchPage\execute(), FileDuplicateSearchPage\execute(), SpecialNewpages\form(), TablePager\getHiddenFields(), HTMLForm\getHiddenFields(), WithoutInterwikiPage\getPageHeader(), MIMEsearchPage\getPageHeader(), UsersPager\getPageHeader(), SpecialLog\getRevisionButton(), SpecialBookSources\makeForm(), SpecialPrefixindex\namespacePrefixForm(), SpecialSearch\powerSearchBox(), SpecialWatchlist\setTopText(), UserrightsPage\showEditUserGroupsForm(), SpecialImport\showForm(), SpecialProtectedpages\showOptions(), SpecialProtectedtitles\showOptions(), EmailConfirmation\showRequestForm(), and UserrightsPage\switchForm().
static Html::htmlHeader | ( | $ | attribs = array() | ) | [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 883 of file Html.php.
References $attribs, $html, $ret, as, global, isXmlMimeType(), and openElement().
Referenced by wfHtmlValidationHandler().
static Html::infoBox | ( | $ | text, |
$ | icon, | ||
$ | alt, | ||
$ | class = false |
||
) | [static] |
Get HTML for an info box with an icon.
string | $text | Wikitext, get this with wfMessage()->plain() |
string | $icon | Path to icon file (used as 'src' attribute) |
string | $alt | Alternate text for the icon |
string | $class | Additional class name to add to the wrapper div |
Definition at line 946 of file Html.php.
References $s, array(), closeElement(), element(), and openElement().
static Html::inlineScript | ( | $ | contents | ) | [static] |
Output a "<script>" tag with the given contents.
string | $contents | JavaScript |
Definition at line 585 of file Html.php.
References array(), global, and rawElement().
Referenced by MWDebug\getDebugHTML(), and Skin\makeVariablesScript().
static Html::inlineStyle | ( | $ | contents, |
$ | media = 'all' |
||
) | [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' |
Definition at line 619 of file Html.php.
References array(), global, and rawElement().
Referenced by wfHtmlValidationHandler().
static Html::input | ( | $ | name, |
$ | value = '' , |
||
$ | type = 'text' , |
||
$ | attribs = array() |
||
) | [static] |
Convenience function to produce an "<input>" element.
This supports the new HTML5 input types and attributes.
string | $name | Name attribute |
array | $value | Value attribute |
string | $type | Type attribute |
array | $attribs | Associative array of miscellaneous extra attributes, passed to Html::element() |
Definition at line 660 of file Html.php.
References $attribs, $name, $type, $value, array(), element(), and getTextInputAttributes().
Referenced by check(), UserloginTemplate\execute(), UsercreateTemplate\execute(), HTMLTextField\getInputHTML(), HTMLButtonField\getInputHTML(), HTMLSelectOrOtherField\getInputHTML(), HTMLSelectAndOtherField\getInputHTML(), UsersPager\getPageHeader(), hidden(), radio(), and SpecialImport\showForm().
static Html::isXmlMimeType | ( | $ | mimetype | ) | [static] |
Determines if the given MIME type is xml.
string | $mimetype | MIME type |
Definition at line 928 of file Html.php.
Referenced by htmlHeader().
static Html::label | ( | $ | label, |
$ | id, | ||
array $ | attribs = array() |
||
) | [static] |
static Html::linkedScript | ( | $ | url | ) | [static] |
Output a "<script>" tag linking to the given URL, e.g., "<script src=foo.js></script>".
string | $url |
Definition at line 604 of file Html.php.
References array(), and element().
Referenced by ResourceLoaderStartUpModule\getScript().
static Html::linkedStyle | ( | $ | url, |
$ | media = 'all' |
||
) | [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 640 of file Html.php.
References array(), and element().
Referenced by WebInstallerOutput\getCssUrl().
static Html::namespaceSelector | ( | array $ | params = array() , |
array $ | selectAttribs = array() |
||
) | [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 787 of file Html.php.
References $options, $params, $ret, $wgContLang, array(), as, closeElement(), element(), global, openElement(), and wfMessage().
Referenced by SpecialWatchlist\doHeader(), SpecialExport\execute(), LinkSearchPage\execute(), SpecialNewpages\form(), SpecialProtectedpages\getNamespaceMenu(), SpecialProtectedtitles\getNamespaceMenu(), SpecialRecentChanges\namespaceFilterForm(), SpecialPrefixindex\namespacePrefixForm(), and SpecialImport\showForm().
static Html::openElement | ( | $ | element, |
$ | attribs = array() |
||
) | [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 | |
array | $attribs |
Definition at line 195 of file Html.php.
References $attribs, array(), expandAttributes(), and global.
Referenced by SpecialTrackingCategories\execute(), SpecialCategories\execute(), LinkSearchPage\execute(), FileDuplicateSearchPage\execute(), TablePager\formatRow(), PostgresInstaller\getConnectForm(), OracleInstaller\getConnectForm(), MssqlInstaller\getConnectForm(), MysqlInstaller\getConnectForm(), SpecialVersion\getCreditsForExtension(), EditPage\getEditButtons(), SpecialVersion\getEntryPointInfo(), HTMLCheckMatrix\getInputHTML(), TablePager\getNavigationBar(), WithoutInterwikiPage\getPageHeader(), SpecialLog\getRevisionButton(), MssqlInstaller\getSettingsForm(), TablePager\getStartBody(), SpecialVersion\getWgHooks(), htmlHeader(), infoBox(), SpecialBookSources\makeForm(), namespaceSelector(), SpecialVersion\openExtType(), SpecialSpecialpages\outputPageList(), MediaStatisticsPage\outputTableStart(), rawElement(), EmailConfirmation\showRequestForm(), WebInstallerPage\startForm(), UserrightsPage\switchForm(), and wfHtmlValidationHandler().
static Html::radio | ( | $ | name, |
$ | checked = false , |
||
array $ | attribs = array() |
||
) | [static] |
static Html::rawElement | ( | $ | element, |
$ | attribs = array() , |
||
$ | 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. If you're hardcoding all the attributes, or there are none, you should probably just type out the html element yourself.
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. If $wgWellFormedXml is false, then a few bytes will be shaved off the HTML output as well.
string | $element | The element's name, e.g., 'a' |
array | $attribs | Associative array of attributes, e.g., array( 'href' => 'http://www.mediawiki.org/' ). See expandAttributes() for further documentation. |
string | $contents | The raw HTML contents of the element: *not* escaped! |
Definition at line 153 of file Html.php.
References $attribs, closeElement(), global, and openElement().
Referenced by InfoAction\addRow(), InfoAction\addTable(), ChangeTags\buildTagFilterSelector(), SpecialEditWatchlist\buildTools(), MWDebug\deprecated(), element(), SpecialListGroupRights\execute(), SpecialListUsers\execute(), DateFormatter\formatDate(), HTMLMultiSelectField\formatOptions(), HTMLRadioField\formatOptions(), SpecialProtectedtitles\formatRow(), SpecialStatistics\formatRow(), UsersPager\formatRow(), TablePager\formatRow(), BlockListPager\formatValue(), ProtectedPagesPager\formatValue(), HTMLForm\getButtons(), Skin\getCachedNotice(), SpecialVersion\getCreditsForExtension(), TablePager\getEmptyBody(), SpecialVersion\getEntryPointInfo(), SpecialJavaScriptTest\getFrameworkListHtml(), HTMLCheckField\getInputHTML(), HTMLCheckMatrix\getInputHTML(), HTMLFormFieldCloner\getInputHTML(), TablePager\getLimitForm(), SpecialProtectedpages\getNamespaceMenu(), TablePager\getNavigationBar(), SpecialVersion\getParserFunctionHooks(), SpecialVersion\getParserTags(), TablePager\getStartBody(), MediaStatisticsPage\getTableHeaderRow(), HTMLCheckMatrix\getTableRow(), inlineScript(), inlineStyle(), Linker\link(), Linker\makeExternalLink(), Skin\makeFooterIcon(), InfoAction\makeHeader(), SpecialBookSources\makeListItem(), Linker\makeMediaLinkFile(), Linker\makeThumbLink2(), CreditsAction\onView(), SpecialVersion\openExtType(), SpecialListGroupRights\outputNamespaceProtectionInfo(), SpecialSpecialpages\outputPageList(), MediaStatisticsPage\outputTableRow(), InfoAction\pageInfo(), SpecialBlock\postText(), SpecialBlock\preText(), SpecialNewFiles\setTopText(), SpecialRecentChanges\setTopText(), SpecialBlockList\showList(), SpecialPrefixindex\showPrefixChunk(), SpecialUploadStash\showUploads(), and wfHtmlValidationHandler().
static Html::srcSet | ( | $ | urls | ) | [static] |
static Html::textarea | ( | $ | name, |
$ | value = '' , |
||
$ | attribs = array() |
||
) | [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 756 of file Html.php.
References $attribs, $name, $value, element(), and getTextInputAttributes().
Referenced by HTMLTextAreaField\getInputHTML().
Html::$boolAttribs [static, private] |
array( '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', )
Html::$voidElements [static, private] |