[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/ -> Html.php (summary)

Collection of methods to generate HTML content Copyright © 2009 Aryeh Gregor http://www.mediawiki.org/

File Size: 987 lines (31 kb)
Included or required:0 times
Referenced: 1 time
Includes or requires: 0 files

Defines 1 class

Html:: (22 methods):
  getTextInputAttributes()
  rawElement()
  element()
  openElement()
  closeElement()
  dropDefaults()
  expandAttributes()
  inlineScript()
  linkedScript()
  inlineStyle()
  linkedStyle()
  input()
  check()
  radio()
  label()
  hidden()
  textarea()
  namespaceSelector()
  htmlHeader()
  isXmlMimeType()
  infoBox()
  srcSet()


Class: Html  - X-Ref

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

getTextInputAttributes( $attrs )   X-Ref
Modifies a set of attributes meant for text input elements
and apply a set of default attributes.
Removes size attribute when $wgUseMediaWikiUIEverywhere enabled.

param: array $attrs An attribute array.
return: array $attrs A modified attribute array

rawElement( $element, $attribs = array()   X-Ref
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.

param: string $element The element's name, e.g., 'a'
param: array $attribs Associative array of attributes, e.g., array(
param: string $contents The raw HTML contents of the element: *not*
return: string Raw HTML

element( $element, $attribs = array()   X-Ref
Identical to rawElement(), but HTML-escapes $contents (like
Xml::element()).

param: string $element
param: array $attribs
param: string $contents
return: string

openElement( $element, $attribs = array()   X-Ref
Identical to rawElement(), but has no third parameter and omits the end
tag (and the self-closing '/' in XML mode for empty elements).

param: string $element
param: array $attribs
return: string

closeElement( $element )   X-Ref
Returns "</$element>"

param: string $element Name of the element, e.g., 'a'
return: string A closing tag

dropDefaults( $element, $attribs )   X-Ref
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).

param: string $element Name of the element, e.g., 'a'
param: array $attribs Associative array of attributes, e.g., array(
return: array An array of attributes functionally identical to $attribs

expandAttributes( $attribs )   X-Ref
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.

param: array $attribs Associative array of attributes, e.g., array(
return: string HTML fragment that goes between element name and '>'

inlineScript( $contents )   X-Ref
Output a "<script>" tag with the given contents.

param: string $contents JavaScript
return: string Raw HTML

linkedScript( $url )   X-Ref
Output a "<script>" tag linking to the given URL, e.g.,
"<script src=foo.js></script>".

param: string $url
return: string Raw HTML

inlineStyle( $contents, $media = 'all' )   X-Ref
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).

param: string $contents CSS
param: string $media A media type string, like 'screen'
return: string Raw HTML

linkedStyle( $url, $media = 'all' )   X-Ref
Output a "<link rel=stylesheet>" linking to the given URL for the given
media type (if any).

param: string $url
param: string $media A media type string, like 'screen'
return: string Raw HTML

input( $name, $value = '', $type = 'text', $attribs = array()   X-Ref
Convenience function to produce an "<input>" element.  This supports the
new HTML5 input types and attributes.

param: string $name Name attribute
param: array $value Value attribute
param: string $type Type attribute
param: array $attribs Associative array of miscellaneous extra
return: string Raw HTML

check( $name, $checked = false, array $attribs = array()   X-Ref
Convenience function to produce a checkbox (input element with type=checkbox)

param: string $name Name attribute
param: bool $checked Whether the checkbox is checked or not
param: array $attribs Array of additional attributes
return: string

radio( $name, $checked = false, array $attribs = array()   X-Ref
Convenience function to produce a checkbox (input element with type=checkbox)

param: string $name Name attribute
param: bool $checked Whether the checkbox is checked or not
param: array $attribs Array of additional attributes
return: string

label( $label, $id, array $attribs = array()   X-Ref
Convenience function for generating a label for inputs.

param: string $label Contents of the label
param: string $id ID of the element being labeled
param: array $attribs Additional attributes
return: string

hidden( $name, $value, $attribs = array()   X-Ref
Convenience function to produce an input element with type=hidden

param: string $name Name attribute
param: string $value Value attribute
param: array $attribs Associative array of miscellaneous extra
return: string Raw HTML

textarea( $name, $value = '', $attribs = array()   X-Ref
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.

param: string $name Name attribute
param: string $value Value attribute
param: array $attribs Associative array of miscellaneous extra
return: string Raw HTML

namespaceSelector( array $params = array()   X-Ref
Build a drop-down box for selecting a namespace

param: array $params Params to set.
param: array $selectAttribs HTML attributes for the generated select element.
return: string HTML code to select a namespace.

htmlHeader( $attribs = array()   X-Ref
Constructs the opening html-tag with necessary doctypes depending on
global variables.

param: array $attribs Associative array of miscellaneous extra
return: string Raw HTML

isXmlMimeType( $mimetype )   X-Ref
Determines if the given MIME type is xml.

param: string $mimetype MIME type
return: bool

infoBox( $text, $icon, $alt, $class = false )   X-Ref
Get HTML for an info box with an icon.

param: string $text Wikitext, get this with wfMessage()->plain()
param: string $icon Path to icon file (used as 'src' attribute)
param: string $alt Alternate text for the icon
param: string $class Additional class name to add to the wrapper div
return: string

srcSet( $urls )   X-Ref
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.

param: array $urls
return: string



Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1