MediaWiki
1.23.6
|
This class is a collection of static functions that serve two purposes: More...
Static Public Member Functions | |
static | closeElement ( $element) |
Returns "</$element>", except if $wgWellFormedXml is off, in which case it returns the empty string when that's guaranteed to be safe. More... | |
static | element ( $element, $attribs=array(), $contents='') |
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()). More... | |
static | expandAttributes ( $attribs) |
Given an associative array of element attributes, generate a string to stick after the element name in HTML output. More... | |
static | hidden ( $name, $value, $attribs=array()) |
Convenience function to produce an input element with type=hidden. More... | |
static | htmlHeader ( $attribs=array()) |
Constructs the opening html-tag with necessary doctypes depending on global variables. More... | |
static | infoBox ( $text, $icon, $alt, $class=false, $useStylePath=true) |
Get HTML for an info box with an icon. More... | |
static | inlineScript ( $contents) |
Output a "<script>" tag with the given contents. More... | |
static | inlineStyle ( $contents, $media='all') |
Output a "<style>" tag with the given contents for the given media type (if any). More... | |
static | input ( $name, $value='', $type='text', $attribs=array()) |
Convenience function to produce an "<input>" element. More... | |
static | isXmlMimeType ( $mimetype) |
Determines if the given mime type is xml. More... | |
static | linkedScript ( $url) |
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(), array $selectAttribs=array()) |
Build a drop-down box for selecting a namespace. More... | |
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). More... | |
static | rawElement ( $element, $attribs=array(), $contents='') |
Returns an HTML element in a string. More... | |
static | srcSet ( $urls) |
Generate a srcset attribute value from an array mapping pixel densities to URLs. More... | |
static | textarea ( $name, $value='', $attribs=array()) |
Convenience function to produce a <textarea> element. More... | |
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. More... | |
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 mimetype 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 |
Returns "</$element>", except if $wgWellFormedXml is off, in which case it returns the empty string when that's guaranteed to be safe.
string | $element | Name of the element, e.g., 'a' |
Definition at line 235 of file Html.php.
References array(), and global.
Referenced by SpecialTrackingCategories\execute(), SpecialCategories\execute(), LinkSearchPage\execute(), FileDuplicateSearchPage\execute(), TablePager\formatRow(), PostgresInstaller\getConnectForm(), OracleInstaller\getConnectForm(), MssqlInstaller\getConnectForm(), MysqlInstaller\getConnectForm(), SpecialVersion\getCreditsForExtension(), SpecialVersion\getEntryPointInfo(), ImageListPager\getForm(), DatabaseInstaller\getInstallUserBox(), TablePager\getNavigationBar(), WithoutInterwikiPage\getPageHeader(), SpecialLog\getRevisionButton(), MssqlInstaller\getSettingsForm(), DatabaseInstaller\getWebUserBox(), SpecialVersion\getWgHooks(), OutputPage\headElement(), ImagePage\imageLinks(), infoBox(), SpecialBookSources\makeForm(), namespaceSelector(), SpecialVersion\openExtType(), WebInstallerOutput\outputFooter(), SpecialSpecialpages\outputPageList(), rawElement(), SpecialExpandTemplates\showHtmlPreview(), EmailConfirmation\showRequestForm(), UserrightsPage\switchForm(), and wfHtmlValidationHandler().
|
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).
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 |
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
$element | string |
$attribs | array |
$contents | string |
Definition at line 148 of file Html.php.
References $attribs, array(), and rawElement().
Referenced by OutputPage\addElement(), OutputPage\buildCssLinks(), MWDebug\deprecated(), WebInstaller\downloadLinkHook(), UserloginTemplate\execute(), SpecialVersion\execute(), LinkSearchPage\execute(), FileDuplicateSearchPage\execute(), OutputPage\feedLink(), PageQueryPage\formatResult(), PopularPagesPage\formatResult(), FewestrevisionsPage\formatResult(), UnwatchedpagesPage\formatResult(), MostlinkedCategoriesPage\formatResult(), ShortPagesPage\formatResult(), MostcategoriesPage\formatResult(), MostinterwikisPage\formatResult(), MostlinkedTemplatesPage\formatResult(), MostlinkedPage\formatResult(), SpecialPagesWithProp\formatResult(), SpecialProtectedtitles\formatRow(), SpecialNewpages\formatRow(), ProtectedPagesPager\formatValue(), HTMLForm\getButtons(), OracleInstaller\getConnectForm(), PostgresInstaller\getConnectForm(), MssqlInstaller\getConnectForm(), MysqlInstaller\getConnectForm(), SpecialVersion\getCreditsForExtension(), UploadForm\getDescriptionSection(), FeedUtils\getDiffLink(), TablePager\getEmptyBody(), SpecialVersion\getEntryPointInfo(), OutputPage\getHeadLinksArray(), DBConnectionError\getHTML(), HTMLTextField\getInputHTML(), HTMLTextAreaField\getInputHTML(), HTMLCheckMatrix\getInputHTML(), DatabaseInstaller\getInstallUserBox(), UploadSourceField\getLabelHtml(), TablePager\getNavigationBar(), WithoutInterwikiPage\getPageHeader(), WebInstaller\getPageListItem(), SpecialLog\getRevisionButton(), HistoryPager\getRevisionButton(), MssqlInstaller\getSettingsForm(), TablePager\getStartBody(), DBQueryError\getTextContent(), SpecialVersion\getVersionLinkedGit(), DatabaseInstaller\getWebUserBox(), SpecialVersion\getWgHooks(), OutputPage\headElement(), infoBox(), input(), ApiParse\languagesHtml(), linkedScript(), linkedStyle(), Linker\makeExternalImage(), Skin\makeFooterIcon(), SpecialBookSources\makeForm(), InfoAction\makeHeader(), SpecialBookSources\makeListItem(), BaseTemplate\makeSearchButton(), BaseTemplate\makeSearchInput(), Linker\makeThumbLink2(), namespaceSelector(), Language\numLink(), InfoAction\onView(), SpecialVersion\openExtType(), Xml\option(), SpecialListGroupRights\outputNamespaceProtectionInfo(), SpecialSpecialpages\outputPageList(), InfoAction\pageInfo(), SpecialSearch\powerSearchBox(), OutputPage\readOnlyPage(), ImportReporter\reportNotice(), ChangesList\showCharacterDifference(), SpecialAllpages\showChunk(), DifferenceEngine\showDiffPage(), SpecialAllpages\showline(), SpecialBlockList\showList(), SpecialUndelete\showList(), SpecialPrefixindex\showPrefixChunk(), SpecialUploadStash\showUploads(), WebInstaller\startPageWrapper(), Xml\submitButton(), textarea(), Article\viewRedirect(), and wfHtmlValidationHandler().
|
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 should contain space-separated lists (such as 'class') 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., 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. |
Definition at line 419 of file Html.php.
References $attribs, $ret, $value, array(), as, and global.
Referenced by openElement().
|
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 662 of file Html.php.
References $attribs, $name, $value, and input().
Referenced by AllmessagesTablePager\buildForm(), ProtectionForm\buildForm(), ChangeTags\buildTagFilterSelector(), Article\confirmDelete(), Preferences\datetimePreferences(), SpecialRecentChanges\doHeader(), SpecialWatchlist\doHeader(), ImagePage\doRenderLangOpt(), SpecialRandomInCategory\execute(), LinkSearchPage\execute(), FileDuplicateSearchPage\execute(), MIMEsearchPage\execute(), SpecialNewpages\form(), LogEventsList\getFilterLinks(), ImageListPager\getForm(), HTMLForm\getHiddenFields(), TablePager\getHiddenFields(), WithoutInterwikiPage\getPageHeader(), ActiveUsersPager\getPageHeader(), UsersPager\getPageHeader(), SpecialLog\getRevisionButton(), HistoryPager\getStartBody(), CategoryPager\getStartForm(), SpecialBookSources\makeForm(), SpecialAllpages\namespaceForm(), SpecialPrefixindex\namespacePrefixForm(), HistoryAction\onView(), ImagePage\openShowImage(), SpecialSearch\powerSearchBox(), SpecialWatchlist\setTopText(), SpecialSearch\shortDialog(), UserrightsPage\showEditUserGroupsForm(), MovePageForm\showForm(), SpecialChangeEmail\showForm(), SpecialImport\showForm(), FileDeleteForm\showForm(), SpecialRevisionDelete\showForm(), SpecialMergeHistory\showHistory(), SpecialUndelete\showHistory(), SpecialMergeHistory\showMergeForm(), LogEventsList\showOptions(), SpecialProtectedpages\showOptions(), SpecialProtectedtitles\showOptions(), EmailConfirmation\showRequestForm(), SpecialUndelete\showSearchForm(), UserrightsPage\switchForm(), SpecialEmailUser\userForm(), and SpecialWhatLinksHere\whatlinkshereForm().
|
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 801 of file Html.php.
References $attribs, $html, $ret, as, global, isXmlMimeType(), and openElement().
Referenced by OutputPage\headElement(), WebInstallerOutput\outputHeader(), WebInstallerOutput\outputShortHeader(), and wfHtmlValidationHandler().
Get HTML for an info box with an icon.
string | $text | wikitext, get this with wfMessage()->plain() |
string | $icon | icon name, file in skins/common/images |
string | $alt | alternate text for the icon |
string | $class | additional class name to add to the wrapper div |
$useStylePath |
Definition at line 865 of file Html.php.
References $s, array(), closeElement(), element(), global, and openElement().
Referenced by WebInstaller\getInfoBox().
|
static |
Output a "<script>" tag with the given contents.
string | $contents | JavaScript |
Definition at line 570 of file Html.php.
References array(), global, and rawElement().
Referenced by OutputPage\addInlineScript(), ProtectionForm\buildCleanupScript(), OutputPage\getBottomScripts(), MWDebug\getDebugHTML(), OutputPage\getHeadScripts(), OutputPage\getHtmlFromLoaderLinks(), OutputPage\getScriptsForBottomQueue(), OutputPage\makeResourceLoaderLink(), and Skin\makeVariablesScript().
|
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 |
$media | mixed A media type string, like 'screen' |
Definition at line 604 of file Html.php.
References array(), global, and rawElement().
Referenced by OutputPage\addInlineStyle(), OutputPage\buildCssLinks(), OutputPage\makeResourceLoaderLink(), and wfHtmlValidationHandler().
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 645 of file Html.php.
References $attribs, $name, $type, $value, and element().
Referenced by Article\confirmDelete(), Xml\dateMenu(), UsercreateTemplate\execute(), SpecialRandomInCategory\execute(), ImageListPager\getForm(), HTMLButtonField\getInputHTML(), HTMLSelectOrOtherField\getInputHTML(), HTMLSelectAndOtherField\getInputHTML(), UsersPager\getPageHeader(), hidden(), SpecialChangeEmail\pretty(), SpecialSearch\shortDialog(), and SpecialImport\showForm().
|
static |
Determines if the given mime type is xml.
string | $mimetype | MimeType |
Definition at line 846 of file Html.php.
Referenced by OutputPage\headElement(), and htmlHeader().
|
static |
Output a "<script>" tag linking to the given URL, e.g., "<script src=foo.js></script>".
$url | string |
Definition at line 589 of file Html.php.
References array(), and element().
Referenced by OutputPage\addScriptFile(), WebInstallerOutput\getJQuery(), ResourceLoaderStartUpModule\getScript(), OutputPage\makeResourceLoaderLink(), WebInstallerOutput\outputHeader(), and WebInstallerOutput\outputShortHeader().
|
static |
Output a "<link rel=stylesheet>" linking to the given URL for the given media type (if any).
$url | string |
$media | mixed A media type string, like 'screen' |
Definition at line 625 of file Html.php.
References array(), and element().
Referenced by WebInstallerOutput\getCssUrl(), OutputPage\makeResourceLoaderLink(), and OutputPage\styleLink().
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 707 of file Html.php.
References $options, $params, $ret, $wgContLang, array(), as, closeElement(), element(), global, NS_MAIN, openElement(), and wfMessage().
Referenced by SpecialWatchlist\doHeader(), SpecialExport\execute(), LinkSearchPage\execute(), SpecialNewpages\form(), SpecialProtectedpages\getNamespaceMenu(), SpecialProtectedtitles\getNamespaceMenu(), SpecialRecentChanges\namespaceFilterForm(), SpecialAllpages\namespaceForm(), SpecialPrefixindex\namespacePrefixForm(), Xml\namespaceSelector(), MovePageForm\showForm(), SpecialImport\showForm(), and SpecialWhatLinksHere\whatlinkshereForm().
|
static |
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/' in XML mode for empty elements).
$element | string |
$attribs | array |
Definition at line 166 of file Html.php.
References $attribs, array(), expandAttributes(), and global.
Referenced by MonoBookTemplate\customBox(), SpecialTrackingCategories\execute(), SpecialCategories\execute(), LinkSearchPage\execute(), FileDuplicateSearchPage\execute(), TablePager\formatRow(), OracleInstaller\getConnectForm(), PostgresInstaller\getConnectForm(), MssqlInstaller\getConnectForm(), MysqlInstaller\getConnectForm(), SpecialVersion\getCreditsForExtension(), SpecialVersion\getEntryPointInfo(), ImageListPager\getForm(), CategoryViewer\getHTML(), DatabaseInstaller\getInstallUserBox(), TablePager\getNavigationBar(), WithoutInterwikiPage\getPageHeader(), SpecialLog\getRevisionButton(), MssqlInstaller\getSettingsForm(), HistoryPager\getStartBody(), TablePager\getStartBody(), DatabaseInstaller\getWebUserBox(), SpecialVersion\getWgHooks(), OutputPage\headElement(), htmlHeader(), ImagePage\imageLinks(), infoBox(), SpecialBookSources\makeForm(), namespaceSelector(), SpecialVersion\openExtType(), WebInstallerOutput\outputHeader(), SpecialSpecialpages\outputPageList(), rawElement(), EnhancedChangesList\recentChangesBlockGroup(), EnhancedChangesList\recentChangesBlockLine(), SpecialExpandTemplates\showHtmlPreview(), EmailConfirmation\showRequestForm(), UserrightsPage\switchForm(), and wfHtmlValidationHandler().
|
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 124 of file Html.php.
References $attribs, closeElement(), global, and openElement().
Referenced by InfoAction\addRow(), InfoAction\addTable(), SpecialBlock\alterForm(), ChangeTags\buildTagFilterSelector(), SpecialEditWatchlist\buildTools(), MWDebug\deprecated(), HTMLForm\displaySection(), ImagePage\doRenderLangOpt(), WebInstaller\downloadLinkHook(), element(), SpecialListGroupRights\execute(), SpecialRandomInCategory\execute(), SpecialActiveUsers\execute(), SpecialListUsers\execute(), FormatMetadata\flattenArrayReal(), DateFormatter\formatDate(), HTMLFormField\formatErrors(), HTMLForm\formatErrors(), CategoryViewer\formatList(), HTMLMultiSelectField\formatOptions(), HTMLRadioField\formatOptions(), SpecialMergeHistory\formatRevisionRow(), SpecialProtectedtitles\formatRow(), SpecialStatistics\formatRow(), ActiveUsersPager\formatRow(), DeletedContribsPager\formatRow(), UsersPager\formatRow(), CategoryPager\formatRow(), SpecialNewpages\formatRow(), ContribsPager\formatRow(), TablePager\formatRow(), BlockListPager\formatValue(), ProtectedPagesPager\formatValue(), HTMLForm\getButtons(), Skin\getCachedNotice(), Skin\getCopyright(), SpecialVersion\getCreditsForExtension(), HTMLFormField\getDiv(), TablePager\getEmptyBody(), SpecialVersion\getEntryPointInfo(), HTMLForm\getErrors(), SpecialJavaScriptTest\getFrameworkListHtml(), HTMLFormField\getHelpTextHtmlDiv(), HTMLFormField\getHelpTextHtmlTable(), HTMLCheckField\getInputHTML(), HTMLCheckMatrix\getInputHTML(), Licenses\getInputHTML(), HTMLFormField\getLabelHtml(), UploadSourceField\getLabelHtml(), TablePager\getLimitForm(), RevDel_FileItem\getLink(), SpecialProtectedpages\getNamespaceMenu(), TablePager\getNavigationBar(), SpecialVersion\getParserFunctionHooks(), SpecialVersion\getParserTags(), Block\getRedactedName(), LogFormatter\getRestrictedElement(), DifferenceEngine\getRevisionHeader(), TablePager\getStartBody(), HTMLCheckMatrix\getTableRow(), HTMLFormField\getTableRow(), HistoryPager\historyLine(), ImagePage\imageLinks(), inlineScript(), inlineStyle(), ApiParse\languagesHtml(), Linker\link(), LogEventsList\logLine(), Linker\makeExternalLink(), Skin\makeFooterIcon(), InfoAction\makeHeader(), BaseTemplate\makeLink(), SpecialBookSources\makeListItem(), BaseTemplate\makeListItem(), OutputPage\makeResourceLoaderLink(), BaseTemplate\makeSearchButton(), ImagePage\makeSizeLink(), Linker\makeThumbLink2(), SpecialPasswordReset\onSuccess(), CreditsAction\onView(), SpecialVersion\openExtType(), ImagePage\openShowImage(), SpecialListGroupRights\outputNamespaceProtectionInfo(), SpecialSpecialpages\outputPageList(), InfoAction\pageInfo(), SpecialBlock\postText(), SkinTemplate\prepareQuickTemplate(), SpecialBlock\preText(), SpecialRecentChanges\setTopText(), SpecialAllpages\showChunk(), OutputPage\showLagWarning(), SpecialBlockList\showList(), LogEventsList\showLogExtract(), SpecialPrefixindex\showPrefixChunk(), SpecialUndelete\showSearchForm(), SpecialUploadStash\showUploads(), LogFormatter\styleRestricedElement(), SpecialEmailUser\userForm(), wfHtmlValidationHandler(), and HTMLForm\wrapForm().
|
static |
Generate a srcset attribute value from an array mapping pixel densities to URLs.
Note that srcset supports width and height values as well, which are not used here.
array | $urls |
Definition at line 903 of file Html.php.
Referenced by ThumbnailImage\toHtml().
|
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() |
|
staticprivate |
|
staticprivate |