MediaWiki  REL1_19
Html Class Reference

This class is a collection of static functions that serve two purposes: More...

List of all members.

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.
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 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, $useStylePath=true)
 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 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 rawElement ($element, $attribs=array(), $contents= '')
 Returns an HTML element in a string.
static textarea ($name, $value= '', $attribs=array())
 Convenience function to produce an <input> 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 $HTMLFiveOnlyAttribs
static $voidElements

Detailed Description

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:

$wgHtml5: If this is set to false, then all output should be valid XHTML 1.0 Transitional. $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.

Since:
1.16

Definition at line 50 of file Html.php.


Member Function Documentation

static Html::closeElement ( element) [static]

Returns "</$element>", except if $wgWellFormedXml is off, in which case it returns the empty string when that's guaranteed to be safe.

Since:
1.17
Parameters:
$elementstring Name of the element, e.g., 'a'
Returns:
string A closing tag, if required

Definition at line 241 of file Html.php.

References $wgWellFormedXml.

Referenced by SpecialCategories\execute(), MonoBookTemplate\execute(), PostgresInstaller\getConnectForm(), OracleInstaller\getConnectForm(), Ibm_db2Installer\getConnectForm(), MysqlInstaller\getConnectForm(), ImageListPager\getForm(), DatabaseInstaller\getInstallUserBox(), TablePager\getLimitSelect(), DatabaseInstaller\getWebUserBox(), OutputPage\headElement(), ImagePage\imageLinks(), infoBox(), namespaceSelector(), SpecialSpecialpages\outputPageList(), rawElement(), SpecialFilepath\showForm(), and UserrightsPage\switchForm().

Here is the caller graph for this function:

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).

Parameters:
$elementstring Name of the element, e.g., 'a'
$attribsarray Associative array of attributes, e.g., array( 'href' => 'http://www.mediawiki.org/' ). See expandAttributes() for further documentation.
Returns:
array An array of attributes functionally identical to $attribs

Definition at line 281 of file Html.php.

References $wgHtml5.

static Html::element ( element,
attribs = array(),
contents = '' 
) [static]

Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).

Parameters:
$elementstring
$attribsarray
$contentsstring
Returns:
string

Definition at line 161 of file Html.php.

References rawElement().

Referenced by OutputPage\addElement(), OutputPage\buildCssLinks(), MWDebug\deprecated(), WebInstaller\downloadLinkHook(), MonoBookTemplate\execute(), WebInstaller_DBConnect\execute(), OutputPage\feedLink(), SpecialNewpages\formatRow(), HTMLForm\getButtons(), WebInstaller_Options\getCCChooser(), WebInstaller_Options\getCCDoneBox(), OracleInstaller\getConnectForm(), PostgresInstaller\getConnectForm(), Ibm_db2Installer\getConnectForm(), MysqlInstaller\getConnectForm(), UploadForm\getDescriptionSection(), FeedUtils\getDiffLink(), OutputPage\getHeadLinks(), DBConnectionError\getHTML(), HTMLTextField\getInputHTML(), HTMLTextAreaField\getInputHTML(), DatabaseInstaller\getInstallUserBox(), UploadSourceField\getLabelHtml(), WebInstaller\getPageListItem(), HistoryPager\getRevisionButton(), DatabaseInstaller\getWebUserBox(), OutputPage\headElement(), infoBox(), input(), ApiParse\languagesHtml(), linkedScript(), linkedStyle(), LoginForm\mainLoginForm(), Linker\makeExternalImage(), Skin\makeFooterIcon(), BaseTemplate\makeSearchButton(), BaseTemplate\makeSearchInput(), Linker\makeThumbLink2(), Language\numLink(), InfoAction\onView(), SpecialVersion\openExtType(), LegacyTemplate\otherLanguages(), SpecialSpecialpages\outputPageList(), OutputPage\readOnlyPage(), ImportReporter\reportNotice(), ChangesList\showCharacterDifference(), SpecialAllpages\showChunk(), DifferenceEngine\showDiffPage(), SpecialFilepath\showForm(), MovePageForm\showForm(), SpecialBlockList\showList(), SpecialPrefixindex\showPrefixChunk(), SpecialUploadStash\showUploads(), WebInstaller\startPageWrapper(), textarea(), and Article\viewRedirect().

Here is the call graph for this function:

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 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.

Numerical array
     Html::element( 'em', array(
         'class' => array( 'foo', 'bar' )
     ) );
     // gives '<em class="foo bar"></em>'
Associative array
     Html::element( 'em', array(
         'class' => array( 'foo', 'bar', 'foo' => false, 'quux' => true )
     ) );
     // gives '<em class="bar quux"></em>'
Parameters:
$attribsarray 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.
Returns:
string HTML fragment that goes between element name and '>' (starting with a space if at least one attribute is output)

Definition at line 404 of file Html.php.

References $wgHtml5, and $wgWellFormedXml.

Referenced by LanguageConverter\autoConvert(), HtmlTest\testExpandAttributesForBooleans(), HtmlTest\testExpandAttributesListValueAttributes(), HtmlTest\testExpandAttributesSkipsNullAndFalse(), HtmlTest\testExpandAttributesSpaceSeparatedAttributesWithBoolean(), HtmlTest\testExpandAttributesVariousExpansions(), HtmlTest\testFormValidationBlacklist(), and HtmlTest\testValueIsAuthoritativeInSpaceSeparatedAttributesArrays().

Here is the caller graph for this function:

static Html::hidden ( name,
value,
attribs = array() 
) [static]

Convenience function to produce an input element with type=hidden.

Parameters:
$namestring name attribute
$valuestring value attribute
$attribsarray Associative array of miscellaneous extra attributes, passed to Html::element()
Returns:
string Raw HTML

Definition at line 667 of file Html.php.

References input().

Referenced by AllmessagesTablePager\buildForm(), ProtectionForm\buildForm(), ChangeTags\buildTagFilterSelector(), Article\confirmDelete(), Preferences\datetimePreferences(), SpecialRecentChanges\doHeader(), WebInstallerPage\endForm(), SpecialWatchlist\execute(), LinkSearchPage\execute(), MIMEsearchPage\execute(), FileDuplicateSearchPage\execute(), WebInstaller_Language\execute(), SpecialNewpages\form(), LogEventsList\getFilterLinks(), SpecialContributions\getForm(), DeletedContributionsPage\getForm(), HTMLForm\getHiddenFields(), WithoutInterwikiPage\getPageHeader(), ActiveUsersPager\getPageHeader(), UsersPager\getPageHeader(), HistoryPager\getStartBody(), CategoryPager\getStartForm(), SpecialBookSources\makeForm(), SpecialAllpages\namespaceForm(), SpecialPrefixindex\namespacePrefixForm(), HistoryAction\onView(), ImagePage\openShowImage(), SpecialSearch\powerSearchBox(), SpecialSearch\shortDialog(), EditPage\showEditForm(), UserrightsPage\showEditUserGroupsForm(), SpecialFilepath\showForm(), SpecialChangeEmail\showForm(), MovePageForm\showForm(), SpecialChangePassword\showForm(), SpecialImport\showForm(), FileDeleteForm\showForm(), SpecialRevisionDelete\showForm(), EditPage\showFormAfterText(), EditPage\showFormBeforeText(), SpecialMergeHistory\showHistory(), SpecialUndelete\showHistory(), SpecialMergeHistory\showMergeForm(), LogEventsList\showOptions(), SpecialProtectedtitles\showOptions(), SpecialProtectedpages\showOptions(), EmailConfirmation\showRequestForm(), SpecialUndelete\showSearchForm(), UserrightsPage\switchForm(), SpecialEmailUser\userForm(), and SpecialWhatLinksHere\whatlinkshereForm().

Here is the call graph for this function:

static Html::htmlHeader ( attribs = array()) [static]

Constructs the opening html-tag with necessary doctypes depending on global variables.

Parameters:
$attribsarray Associative array of miscellaneous extra attributes, passed to Html::element() of html tag.
Returns:
string Raw HTML

Definition at line 790 of file Html.php.

References $wgDocType, $wgDTD, $wgHtml5, $wgHtml5Version, $wgMimeType, $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces, and openElement().

Referenced by OutputPage\headElement(), WebInstallerOutput\outputHeader(), and WebInstallerOutput\outputShortHeader().

Here is the call graph for this function:

Here is the caller graph for this function:

static Html::infoBox ( text,
icon,
alt,
class = false,
useStylePath = true 
) [static]

Get HTML for an info box with an icon.

Parameters:
$textString: wikitext, get this with wfMsgNoTrans()
$iconString: icon name, file in skins/common/images
$altString: alternate text for the icon
$classString: additional class name to add to the wrapper div
$useStylePath
Returns:
string

Definition at line 856 of file Html.php.

References $wgStylePath, closeElement(), element(), and openElement().

Referenced by WebInstaller\getInfoBox().

Here is the call graph for this function:

Here is the caller graph for this function:

static Html::inlineScript ( contents) [static]

Output a <script> tag with the given contents.

TODO: do some useful escaping as well, like if $contents contains literal '</script>' or (for XML) literal "]]>".

Parameters:
$contentsstring JavaScript
Returns:
string Raw HTML

Definition at line 564 of file Html.php.

References $wgHtml5, $wgJsMimeType, $wgWellFormedXml, and rawElement().

Referenced by OutputPage\addInlineScript(), ProtectionForm\buildCleanupScript(), MWDebug\getDebugHTML(), EditPage\getEditToolbar(), OutputPage\getHeadScripts(), OutputPage\getScriptsForBottomQueue(), OutputPage\makeResourceLoaderLink(), Skin\makeVariablesScript(), and WebInstallerOutput\outputHeader().

Here is the call graph for this function:

Here is the caller graph for this function:

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).

Parameters:
$contentsstring CSS
$mediamixed A media type string, like 'screen'
Returns:
string Raw HTML

Definition at line 608 of file Html.php.

References $wgWellFormedXml, and rawElement().

Referenced by OutputPage\addInlineStyle(), OutputPage\buildCssLinks(), and OutputPage\makeResourceLoaderLink().

Here is the call graph for this function:

Here is the caller graph for this function:

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, and will silently strip them if $wgHtml5 is false.

Parameters:
$namestring name attribute
$valuemixed value attribute
$typestring type attribute
$attribsarray Associative array of miscellaneous extra attributes, passed to Html::element()
Returns:
string Raw HTML

Definition at line 650 of file Html.php.

References element().

Referenced by Article\confirmDelete(), UserloginTemplate\execute(), UsercreateTemplate\execute(), ImageListPager\getForm(), SpecialContributions\getForm(), DeletedContributionsPage\getForm(), HTMLSelectOrOtherField\getInputHTML(), HTMLSelectAndOtherField\getInputHTML(), EditPage\getSummaryInput(), hidden(), SpecialChangeEmail\pretty(), SpecialChangePassword\pretty(), and SpecialSearch\shortDialog().

Here is the call graph for this function:

Here is the caller graph for this function:

static Html::isXmlMimeType ( mimetype) [static]

Determines if the given mime type is xml.

Parameters:
$mimetypestring MimeType
Returns:
Boolean

Definition at line 834 of file Html.php.

static Html::linkedScript ( url) [static]

Output a <script> tag linking to the given URL, e.g., <script src="foo.js"></script>.

Parameters:
$urlstring
Returns:
string Raw HTML

Definition at line 587 of file Html.php.

References $url, $wgHtml5, $wgJsMimeType, and element().

Referenced by OutputPage\addScriptFile(), WebInstallerOutput\getJQuery(), ResourceLoaderStartUpModule\getScript(), OutputPage\makeResourceLoaderLink(), WebInstallerOutput\outputHeader(), and WebInstallerOutput\outputShortHeader().

Here is the call graph for this function:

Here is the caller graph for this function:

static Html::linkedStyle ( url,
media = 'all' 
) [static]

Output a <link rel="stylesheet"> linking to the given URL for the given media type (if any).

Parameters:
$urlstring
$mediamixed A media type string, like 'screen'
Returns:
string Raw HTML

Definition at line 629 of file Html.php.

References $url, and element().

Referenced by WebInstallerOutput\getCssUrl(), OutputPage\makeResourceLoaderLink(), WebInstallerOutput\outputHeader(), and OutputPage\styleLink().

Here is the call graph for this function:

Here is the caller graph for this function:

static Html::namespaceSelector ( Array $  params = array(),
Array $  selectAttribs = array() 
) [static]

Build a drop-down box for selecting a namespace.

Parameters:
$paramsarray:
  • selected: [optional] Id of namespace which should be pre-selected
  • all: [optional] Value of item for "all namespaces". If null or unset, no <option> is generated to select all namespaces
  • label: text for label to add before the field
$selectAttribsarray HTML attributes for the generated select element.
  • id: [optional], default: 'namespace'
  • name: [optional], default: 'namespace'
Returns:
string HTML code to select a namespace.

Definition at line 722 of file Html.php.

References $options, $wgContLang, closeElement(), Xml\label(), openElement(), Xml\option(), and wfMsg().

Referenced by SpecialRecentChanges\namespaceFilterForm(), SpecialAllpages\namespaceForm(), MovePageForm\showForm(), HtmlTest\testNamespaceSelector(), and HtmlTest\testNamespaceSelectorIdAndNameDefaultsAttributes().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters:
$elementstring The element's name, e.g., 'a'
$attribsarray Associative array of attributes, e.g., array( 'href' => 'http://www.mediawiki.org/' ). See expandAttributes() for further documentation.
$contentsstring The raw HTML contents of the element: *not* escaped!
Returns:
string Raw HTML

Definition at line 137 of file Html.php.

References $wgWellFormedXml, closeElement(), and openElement().

Referenced by SpecialBlock\alterForm(), ChangeTags\buildTagFilterSelector(), SpecialEditWatchlist\buildTools(), MWDebug\deprecated(), EditPage\displayPermissionsError(), HTMLForm\displaySection(), WebInstaller\downloadLinkHook(), element(), SpecialListGroupRights\execute(), SpecialActiveUsers\execute(), SpecialListUsers\execute(), DateFormatter\formatDate(), HTMLForm\formatErrors(), HTMLFormField\formatErrors(), CategoryViewer\formatList(), XmlSelect\formatOptions(), HTMLMultiSelectField\formatOptions(), HTMLRadioField\formatOptions(), SpecialProtectedpages\formatRow(), SpecialStatistics\formatRow(), ActiveUsersPager\formatRow(), DeletedContribsPager\formatRow(), SpecialNewpages\formatRow(), BlockListPager\formatValue(), Skin\getCachedNotice(), Skin\getCopyright(), HTMLForm\getErrors(), SpecialContributions\getForm(), SpecialJavaScriptTest\getFrameworkListHtml(), XmlSelect\getHTML(), Licenses\getInputHTML(), HTMLCheckField\getInputHTML(), UploadSourceField\getLabelHtml(), HTMLFormField\getLabelHtml(), EditPage\getPreviewText(), Block\getRedactedName(), LogFormatter\getRestrictedElement(), DifferenceEngine\getRevisionHeader(), HTMLFormField\getTableRow(), HistoryPager\historyLine(), ImagePage\imageLinks(), inlineScript(), inlineStyle(), ApiParse\languagesHtml(), Linker\link(), Linker\makeExternalLink(), Skin\makeFooterIcon(), BaseTemplate\makeLink(), BaseTemplate\makeListItem(), OutputPage\makeResourceLoaderLink(), BaseTemplate\makeSearchButton(), ImagePage\makeSizeLink(), Linker\makeThumbLink2(), SpecialPasswordReset\onSuccess(), CreditsAction\onView(), InfoAction\onView(), ImagePage\openShowImage(), SkinTemplate\outputPage(), SpecialSpecialpages\outputPageList(), SpecialBlock\postText(), SpecialBlock\preText(), SpecialRecentChanges\setTopText(), SpecialAllpages\showChunk(), EditPage\showEditForm(), OutputPage\showLagWarning(), SpecialBlockList\showList(), LogEventsList\showLogExtract(), SpecialPrefixindex\showPrefixChunk(), SpecialUploadStash\showUploads(), LegacyTemplate\specialPagesList(), LogFormatter\styleRestricedElement(), SpecialEmailUser\userForm(), and HTMLForm\wrapForm().

Here is the call graph for this function:

static Html::textarea ( name,
value = '',
attribs = array() 
) [static]

Convenience function to produce an <input> element.

This supports leaving out the cols= and rows= which Xml requires and are required by HTML4/XHTML but not required by HTML5 and will silently set cols="" and rows="" if $wgHtml5 is false and cols and rows are omitted (HTML4 validates present but empty cols="" and rows="" as valid).

Parameters:
$namestring name attribute
$valuestring value attribute
$attribsarray Associative array of miscellaneous extra attributes, passed to Html::element()
Returns:
string Raw HTML

Definition at line 684 of file Html.php.

References $wgHtml5, and element().

Referenced by EditPage\showTextbox().

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Html::$boolAttribs [static, private]
Initial value:
 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',
                # HTML5 Microdata
                'itemscope',
        )

Definition at line 73 of file Html.php.

Html::$HTMLFiveOnlyAttribs [static, private]
Initial value:
 array(
                'autocomplete',
                'autofocus',
                'max',
                'min',
                'multiple',
                'pattern',
                'placeholder',
                'required',
                'step',
                'spellcheck',
        )

Definition at line 104 of file Html.php.

Html::$voidElements [static, private]
Initial value:
 array(
                'area',
                'base',
                'br',
                'col',
                'command',
                'embed',
                'hr',
                'img',
                'input',
                'keygen',
                'link',
                'meta',
                'param',
                'source',
                'track',
                'wbr',
        )

Definition at line 52 of file Html.php.


The documentation for this class was generated from the following file: