MediaWiki master
MediaWiki\Xml\Xml Class Reference

Module of static functions for generating XML. More...

Static Public Member Functions

static attrib ( $name, $present=true)
 Internal function for use in checkboxes and radio buttons and such.
 
static buildForm ( $fields, $submitLabel=null, $submitAttribs=[])
 Generate a form (without the opening form element).
 
static buildTable ( $rows, $attribs=[], $headers=null)
 
static buildTableRow ( $attribs, $cells)
 Build a row for a table.
 
static check ( $name, $checked=false, $attribs=[])
 Convenience function to build an HTML checkbox.
 
static checkLabel ( $label, $name, $id, $checked=false, $attribs=[])
 Convenience function to build an HTML checkbox with a label.
 
static closeElement ( $element)
 Shortcut to close an XML element.
 
static dateMenu ( $year, $month)
 
static element ( $element, $attribs=null, $contents='', $allowShortTag=true)
 Format an XML element with given attributes and, optionally, text content.
 
static elementClean ( $element, $attribs=[], $contents='')
 Format an XML element as with self::element(), but run text through the content language's normalize() validator first to ensure that no invalid UTF-8 is passed.
 
static encodeJsCall ( $name, $args, $pretty=false)
 Create a call to a JavaScript function.
 
static encodeJsVar ( $value, $pretty=false)
 Encode a variable of arbitrary type to JavaScript.
 
static escapeTagsOnly ( $in)
 Replace " > and < with their respective HTML entities ( ", >, <)
 
static expandAttributes (?array $attribs)
 Given an array of ('attributename' => 'value'), it generates the code to set the XML attributes : attributename="value".
 
static fieldset ( $legend=false, $content=false, $attribs=[])
 Shortcut for creating fieldsets.
 
static input ( $name, $size=false, $value=false, $attribs=[])
 Convenience function to build an HTML text input field.
 
static inputLabel ( $label, $name, $id, $size=false, $value=false, $attribs=[])
 Convenience function to build an HTML text input field with a label.
 
static inputLabelSep ( $label, $name, $id, $size=false, $value=false, $attribs=[])
 Same as Xml::inputLabel() but return input and label in an array.
 
static isWellFormedXmlFragment ( $text)
 Check if a string is a well-formed XML fragment.
 
static label ( $label, $id, $attribs=[])
 Convenience function to build an HTML form label.
 
static languageSelector ( $selected, $customisedOnly=true, $inLanguage=null, $overrideAttrs=[], Message $msg=null)
 Construct a language selector appropriate for use in a form or preferences.
 
static listDropdown ( $name='', $list='', $other='', $selected='', $class='', $tabindex=null)
 Build a drop-down box from a textual list.
 
static listDropdownOptions ( $list, $params=[])
 Build options for a drop-down box from a textual list.
 
static listDropdownOptionsOoui ( $options)
 Convert options for a drop-down box into a format accepted by OOUI\DropdownInputWidget etc.
 
static monthSelector ( $selected='', $allmonths=null, $id='month')
 Create a date selector.
 
static openElement ( $element, $attribs=null)
 This opens an XML element.
 
static option ( $text, $value=null, $selected=false, $attribs=[])
 Convenience function to build an HTML drop-down list item.
 
static password ( $name, $size=false, $value=false, $attribs=[])
 Convenience function to build an HTML password input field.
 
static radio ( $name, $value, $checked=false, $attribs=[])
 Convenience function to build an HTML radio button.
 
static radioLabel ( $label, $name, $value, $id, $checked=false, $attribs=[])
 Convenience function to build an HTML radio button with a label.
 
static span ( $text, $class, $attribs=[])
 Shortcut to make a span element.
 
static submitButton ( $value, $attribs=[])
 Convenience function to build an HTML submit button.
 
static tags ( $element, $attribs, $contents)
 Same as Xml::element(), but does not escape contents.
 
static textarea ( $name, $content, $cols=40, $rows=5, $attribs=[])
 Shortcut for creating textareas.
 
static wrapClass ( $text, $class, $tag='span', $attribs=[])
 Shortcut to make a specific element with a class attribute.
 

Detailed Description

Module of static functions for generating XML.

Definition at line 37 of file Xml.php.

Member Function Documentation

◆ attrib()

static MediaWiki\Xml\Xml::attrib ( $name,
$present = true )
static

Internal function for use in checkboxes and radio buttons and such.

Parameters
string$name
bool$present
Returns
array
Deprecated
since 1.42; only for use in methods being deprecated

Definition at line 348 of file Xml.php.

◆ buildForm()

static MediaWiki\Xml\Xml::buildForm ( $fields,
$submitLabel = null,
$submitAttribs = [] )
static

Generate a form (without the opening form element).

Output optionally includes a submit button.

Parameters
array$fieldsAssociative array, key is the name of a message that contains a description for the field, value is an HTML string containing the appropriate input.
string | null$submitLabelThe name of a message containing a label for the submit button.
array$submitAttribsThe attributes to add to the submit button
Returns
string HTML form.
Deprecated
since 1.42, use OOUI or Codex widgets instead

Definition at line 812 of file Xml.php.

References MediaWiki\Xml\Xml\closeElement(), MediaWiki\Xml\Xml\openElement(), MediaWiki\Xml\Xml\submitButton(), MediaWiki\Xml\Xml\tags(), and wfMessage().

◆ buildTable()

static MediaWiki\Xml\Xml::buildTable ( $rows,
$attribs = [],
$headers = null )
static
Parameters
string[][]$rows
array | null$attribsAn array of attributes to apply to the table tag
array | null$headersAn array of strings to use as table headers
Returns
string
Deprecated
since 1.42; use OOUI or Codex widgets instead

Definition at line 852 of file Xml.php.

References $header, MediaWiki\Xml\Xml\buildTableRow(), MediaWiki\Xml\Xml\closeElement(), MediaWiki\Xml\Xml\element(), and MediaWiki\Xml\Xml\openElement().

◆ buildTableRow()

static MediaWiki\Xml\Xml::buildTableRow ( $attribs,
$cells )
static

Build a row for a table.

Parameters
array | null$attribsAn array of attributes to apply to the tr tag
string[]$cellsAn array of strings to put in
Returns
string
Deprecated
since 1.42; use OOUI or Codex widgets instead

Definition at line 893 of file Xml.php.

References MediaWiki\Xml\Xml\closeElement(), MediaWiki\Xml\Xml\element(), and MediaWiki\Xml\Xml\openElement().

Referenced by MediaWiki\Xml\Xml\buildTable().

◆ check()

static MediaWiki\Xml\Xml::check ( $name,
$checked = false,
$attribs = [] )
static

Convenience function to build an HTML checkbox.

Parameters
string$nameValue of the name attribute
bool$checkedWhether the checkbox is checked or not
array$attribsArray other attributes
Returns
string HTML
Deprecated
since 1.42, use {
See also
Html::check} instead

Definition at line 361 of file Xml.php.

References MediaWiki\Xml\Xml\element().

Referenced by MediaWiki\Xml\Xml\checkLabel().

◆ checkLabel()

static MediaWiki\Xml\Xml::checkLabel ( $label,
$name,
$id,
$checked = false,
$attribs = [] )
static

Convenience function to build an HTML checkbox with a label.

Parameters
string$label
string$name
string$id
bool$checked
array$attribs
Returns
string HTML
Deprecated
since 1.42, use {
See also
Html::check} and {
Html::label} instead

Definition at line 465 of file Xml.php.

References MediaWiki\Xml\Xml\check(), and MediaWiki\Xml\Xml\label().

◆ closeElement()

static MediaWiki\Xml\Xml::closeElement ( $element)
static

Shortcut to close an XML element.

Parameters
string$elementElement name
Returns
string

Definition at line 128 of file Xml.php.

Referenced by MediaWiki\Xml\Xml\buildForm(), MediaWiki\Xml\Xml\buildTable(), MediaWiki\Xml\Xml\buildTableRow(), MediaWiki\Xml\Xml\fieldset(), and MediaWiki\Api\ApiFormatXml\recXmlPrint().

◆ dateMenu()

static MediaWiki\Xml\Xml::dateMenu ( $year,
$month )
static
Parameters
int | string$yearUse '' or 0 to start with no year preselected.
int | string$monthA month in the 1..12 range. Use '', 0 or -1 to start with no month preselected.
Returns
string Formatted HTML
Deprecated
since 1.42

Definition at line 187 of file Xml.php.

References MediaWiki\Xml\Xml\label(), MediaWiki\Xml\Xml\monthSelector(), wfDeprecated(), and wfMessage().

◆ element()

static MediaWiki\Xml\Xml::element ( $element,
$attribs = null,
$contents = '',
$allowShortTag = true )
static

Format an XML element with given attributes and, optionally, text content.

Element and attribute names are assumed to be ready for literal inclusion. Strings are assumed to not contain XML-illegal characters; special characters (<, >, &) are escaped but illegals are not touched.

Parameters
string$elementElement name
array | null$attribsName=>value pairs. Values will be escaped.
string | null$contentsNull to make an open tag only; '' for a contentless closed tag (default)
bool$allowShortTagWhether '' in $contents will result in a contentless closed tag
Returns
string

Definition at line 54 of file Xml.php.

References MediaWiki\Xml\Xml\expandAttributes().

Referenced by MediaWiki\Xml\Xml\buildTable(), MediaWiki\Xml\Xml\buildTableRow(), MediaWiki\Xml\Xml\check(), MediaWiki\Xml\Xml\elementClean(), MediaWiki\Xml\Xml\fieldset(), MediaWiki\Xml\Xml\input(), MediaWiki\Xml\Xml\label(), MediaWiki\Xml\Xml\radio(), MediaWiki\Api\ApiFormatXml\recXmlPrint(), MediaWiki\Xml\Xml\span(), and MediaWiki\Xml\Xml\textarea().

◆ elementClean()

static MediaWiki\Xml\Xml::elementClean ( $element,
$attribs = [],
$contents = '' )
static

Format an XML element as with self::element(), but run text through the content language's normalize() validator first to ensure that no invalid UTF-8 is passed.

Parameters
string$element
array | null$attribsName=>value pairs. Values will be escaped.
string | null$contentsNull to make an open tag only; '' for a contentless closed tag (default)
Returns
string

Definition at line 101 of file Xml.php.

References MediaWiki\Xml\Xml\element(), and MediaWiki\MediaWikiServices\getInstance().

◆ encodeJsCall()

static MediaWiki\Xml\Xml::encodeJsCall ( $name,
$args,
$pretty = false )
static

Create a call to a JavaScript function.

The supplied arguments will be encoded using Xml::encodeJsVar().

Since
1.17
Parameters
string$nameThe name of the function to call, or a JavaScript expression which evaluates to a function object which is called.
array$argsThe arguments to pass to the function.
bool$prettyIf true, add non-significant whitespace to improve readability.
Returns
string|false String if successful; false upon failure
Deprecated
since 1.41, use {
See also
Html::encodeJsCall} instead

Definition at line 732 of file Xml.php.

◆ encodeJsVar()

static MediaWiki\Xml\Xml::encodeJsVar ( $value,
$pretty = false )
static

Encode a variable of arbitrary type to JavaScript.

If the value is an HtmlJsCode object, pass through the object's value verbatim.

Note
Only use this function for generating JavaScript code. If generating output for a proper JSON parser, just call FormatJson::encode() directly.
Parameters
mixed$valueThe value being encoded. Can be any type except a resource.
bool$prettyIf true, add non-significant whitespace to improve readability.
Returns
string|false String if successful; false upon failure
Deprecated
since 1.41, use {
See also
Html::encodeJsVar} instead

Definition at line 712 of file Xml.php.

◆ escapeTagsOnly()

static MediaWiki\Xml\Xml::escapeTagsOnly ( $in)
static

Replace " > and < with their respective HTML entities ( ", >, <)

Parameters
string$inText that might contain HTML tags.
Returns
string Escaped string

Definition at line 792 of file Xml.php.

◆ expandAttributes()

static MediaWiki\Xml\Xml::expandAttributes ( ?array $attribs)
static

Given an array of ('attributename' => 'value'), it generates the code to set the XML attributes : attributename="value".

The values are passed to Sanitizer::encodeAttribute. Returns null or empty string if no attributes given.

Parameters
array | null$attribsArray of attributes for an XML element
Returns
null|string

Definition at line 79 of file Xml.php.

Referenced by MediaWiki\Xml\Xml\element(), and MediaWiki\Xml\Xml\openElement().

◆ fieldset()

static MediaWiki\Xml\Xml::fieldset ( $legend = false,
$content = false,
$attribs = [] )
static

Shortcut for creating fieldsets.

Parameters
string | false$legendLegend of the fieldset. If evaluates to false, legend is not added.
string | false$contentPre-escaped content for the fieldset. If false, only open fieldset is returned.
array$attribsAny attributes to fieldset-element.
Returns
string
Deprecated
since 1.42, use {
See also
Html::element} instead

Definition at line 659 of file Xml.php.

References MediaWiki\Xml\Xml\closeElement(), MediaWiki\Xml\Xml\element(), and MediaWiki\Xml\Xml\openElement().

◆ input()

static MediaWiki\Xml\Xml::input ( $name,
$size = false,
$value = false,
$attribs = [] )
static

Convenience function to build an HTML text input field.

Parameters
string$nameValue of the name attribute
int | false$sizeValue of the size attribute
string | false$valueValue of the value attribute
array$attribsOther attributes
Returns
string HTML
Deprecated
since 1.42, use {
See also
Html::input} instead

Definition at line 307 of file Xml.php.

References MediaWiki\Xml\Xml\element().

Referenced by MediaWiki\Xml\Xml\inputLabelSep(), and MediaWiki\Xml\Xml\password().

◆ inputLabel()

static MediaWiki\Xml\Xml::inputLabel ( $label,
$name,
$id,
$size = false,
$value = false,
$attribs = [] )
static

Convenience function to build an HTML text input field with a label.

Parameters
string$labelText of the label
string$nameValue of the name attribute
string$idId of the input
int | false$sizeValue of the size attribute
string | false$valueValue of the value attribute
array$attribsOther attributes
Returns
string HTML
Deprecated
since 1.42, use {
See also
Html::input} and {
Html::label} instead

Definition at line 424 of file Xml.php.

References MediaWiki\Xml\Xml\inputLabelSep().

◆ inputLabelSep()

static MediaWiki\Xml\Xml::inputLabelSep ( $label,
$name,
$id,
$size = false,
$value = false,
$attribs = [] )
static

Same as Xml::inputLabel() but return input and label in an array.

Parameters
string$label
string$name
string$id
int | false$size
string | false$value
array$attribs
Returns
array
Deprecated
since 1.42, use {
See also
Html::input} and {
Html::label} instead

Definition at line 444 of file Xml.php.

References MediaWiki\Xml\Xml\input(), and MediaWiki\Xml\Xml\label().

Referenced by MediaWiki\Xml\Xml\inputLabel().

◆ isWellFormedXmlFragment()

static MediaWiki\Xml\Xml::isWellFormedXmlFragment ( $text)
static

Check if a string is a well-formed XML fragment.

Wraps fragment in an \<html\> bit and doctype, so it can be a fragment and can use HTML named entities.

Parameters
string$text
Returns
bool

Definition at line 775 of file Xml.php.

◆ label()

static MediaWiki\Xml\Xml::label ( $label,
$id,
$attribs = [] )
static

Convenience function to build an HTML form label.

Parameters
string$labelText of the label
string$id
array$attribsAn attribute array. This will usually be the same array as is passed to the corresponding input element, so this function will cherry-pick appropriate attributes to apply to the label as well; only class and title are applied.
Returns
string HTML
Deprecated
since 1.42, use {
See also
Html::label} instead

Definition at line 400 of file Xml.php.

References MediaWiki\Xml\Xml\element().

Referenced by MediaWiki\Xml\Xml\checkLabel(), MediaWiki\Xml\Xml\dateMenu(), MediaWiki\Xml\Xml\inputLabelSep(), MediaWiki\Xml\Xml\languageSelector(), and MediaWiki\Xml\Xml\radioLabel().

◆ languageSelector()

static MediaWiki\Xml\Xml::languageSelector ( $selected,
$customisedOnly = true,
$inLanguage = null,
$overrideAttrs = [],
Message $msg = null )
static

Construct a language selector appropriate for use in a form or preferences.

Parameters
string$selectedThe language code of the selected language
bool$customisedOnlyIf true only languages which have some content are listed
string | null$inLanguageThe ISO code of the language to display the select list in
array$overrideAttrsOverride the attributes of the select tag (since 1.20)
Message | null$msgLabel message key (since 1.20)
Returns
array Array containing 2 items: label HTML and select list HTML
Deprecated
since 1.42

Definition at line 227 of file Xml.php.

References MediaWiki\MediaWikiServices\getInstance(), MediaWiki\Xml\Xml\label(), MediaWiki\MainConfigNames\LanguageCode, MediaWiki\Xml\Xml\option(), MediaWiki\Xml\Xml\tags(), wfDeprecated(), and wfMessage().

◆ listDropdown()

static MediaWiki\Xml\Xml::listDropdown ( $name = '',
$list = '',
$other = '',
$selected = '',
$class = '',
$tabindex = null )
static

Build a drop-down box from a textual list.

This is a wrapper for Xml::listDropdownOptions() plus the XmlSelect class.

Parameters
string$nameName and id for the drop-down
string$listCorrectly formatted text (newline delimited) to be used to generate the options.
string$otherText for the "Other reasons" option
string$selectedOption which should be pre-selected
string$classCSS classes for the drop-down
int | null$tabindexValue of the tabindex attribute
Returns
string
Deprecated
since 1.42; use the equivalent methods in Html without a wrapper

Definition at line 545 of file Xml.php.

References MediaWiki\Xml\Xml\listDropdownOptions().

◆ listDropdownOptions()

static MediaWiki\Xml\Xml::listDropdownOptions ( $list,
$params = [] )
static

Build options for a drop-down box from a textual list.

The result of this function can be passed to XmlSelect::addOptions() (to render a plain <select> dropdown box) or to Xml::listDropdownOptionsOoui() and then OOUI\DropdownInputWidget() (to render a pretty one).

Parameters
string$listCorrectly formatted text (newline delimited) to be used to generate the options.
array$paramsExtra parameters:
  • string $params['other'] If set, add an option with this as text and a value of 'other'
Returns
array Array keys are textual labels, values are internal values
Deprecated
since 1.42; use the equivalent method in Html

Definition at line 578 of file Xml.php.

References $params.

Referenced by MediaWiki\Xml\Xml\listDropdown().

◆ listDropdownOptionsOoui()

static MediaWiki\Xml\Xml::listDropdownOptionsOoui ( $options)
static

Convert options for a drop-down box into a format accepted by OOUI\DropdownInputWidget etc.

TODO Find a better home for this function.

Parameters
array$optionsOptions, as returned e.g. by Xml::listDropdownOptions()
Returns
array
Deprecated
since 1.42; use the equivalent method in Html

Definition at line 630 of file Xml.php.

◆ monthSelector()

static MediaWiki\Xml\Xml::monthSelector ( $selected = '',
$allmonths = null,
$id = 'month' )
static

Create a date selector.

Parameters
string | null$selectedThe month which should be selected, default ''.
string | null$allmonthsValue of a special item denoting all month. Null to not include (default).
string$idElement identifier
Returns
string Html string containing the month selector
Deprecated
since 1.42

Definition at line 160 of file Xml.php.

References $wgLang, wfDeprecated(), and wfMessage().

Referenced by MediaWiki\Xml\Xml\dateMenu().

◆ openElement()

static MediaWiki\Xml\Xml::openElement ( $element,
$attribs = null )
static

This opens an XML element.

Parameters
string$elementName of the element
array | null$attribsArray of attributes, see Xml::expandAttributes()
Returns
string

Definition at line 119 of file Xml.php.

References MediaWiki\Xml\Xml\expandAttributes().

Referenced by MediaWiki\Xml\Xml\buildForm(), MediaWiki\Xml\Xml\buildTable(), MediaWiki\Xml\Xml\buildTableRow(), MediaWiki\Xml\Xml\fieldset(), and MediaWiki\Xml\Xml\tags().

◆ option()

static MediaWiki\Xml\Xml::option ( $text,
$value = null,
$selected = false,
$attribs = [] )
static

Convenience function to build an HTML drop-down list item.

Parameters
string$textText for this item. Will be HTML escaped
string | null$valueForm submission value; if empty, use text
bool$selectedIf true, will be the default selected item
array$attribsOptional additional HTML attributes
Returns
string HTML
Deprecated
since 1.42, use {
See also
Html::element} instead

Definition at line 519 of file Xml.php.

References MediaWiki\Html\element().

Referenced by MediaWiki\Xml\XmlSelect\formatOptions(), and MediaWiki\Xml\Xml\languageSelector().

◆ password()

static MediaWiki\Xml\Xml::password ( $name,
$size = false,
$value = false,
$attribs = [] )
static

Convenience function to build an HTML password input field.

Parameters
string$nameValue of the name attribute
int | false$sizeValue of the size attribute
string | false$valueValue of the value attribute
array$attribsOther attributes
Returns
string HTML
Deprecated
since 1.42, use {
See also
Html::input} instead

Definition at line 331 of file Xml.php.

References MediaWiki\Xml\Xml\input().

◆ radio()

static MediaWiki\Xml\Xml::radio ( $name,
$value,
$checked = false,
$attribs = [] )
static

Convenience function to build an HTML radio button.

Parameters
string$nameValue of the name attribute
string$valueValue of the value attribute
bool$checkedWhether the checkbox is checked or not
array$attribsOther attributes
Returns
string HTML
Deprecated
since 1.42, use {
See also
Html::radio} instead

Definition at line 381 of file Xml.php.

References MediaWiki\Xml\Xml\element().

Referenced by MediaWiki\Xml\Xml\radioLabel().

◆ radioLabel()

static MediaWiki\Xml\Xml::radioLabel ( $label,
$name,
$value,
$id,
$checked = false,
$attribs = [] )
static

Convenience function to build an HTML radio button with a label.

Parameters
string$label
string$name
string$value
string$id
bool$checked
array$attribs
Returns
string HTML
Deprecated
since 1.42, use {
See also
Html::radio} and {
Html::label} instead

Definition at line 484 of file Xml.php.

References MediaWiki\Xml\Xml\label(), and MediaWiki\Xml\Xml\radio().

◆ span()

static MediaWiki\Xml\Xml::span ( $text,
$class,
$attribs = [] )
static

Shortcut to make a span element.

Parameters
string$textContent of the element, will be escaped
string$classClass name of the span element
array$attribsOther attributes
Returns
string
Deprecated
since 1.42, use {
See also
Html::element} instead

Definition at line 277 of file Xml.php.

References MediaWiki\Xml\Xml\element().

◆ submitButton()

static MediaWiki\Xml\Xml::submitButton ( $value,
$attribs = [] )
static

Convenience function to build an HTML submit button.

Parameters
string$valueLabel text for the button (unescaped)
array$attribsOptional custom attributes
Returns
string HTML
Deprecated
since 1.42, use {
See also
Html::submitButton} instead

Definition at line 501 of file Xml.php.

References MediaWiki\Html\element().

Referenced by MediaWiki\Xml\Xml\buildForm().

◆ tags()

static MediaWiki\Xml\Xml::tags ( $element,
$attribs,
$contents )
static

Same as Xml::element(), but does not escape contents.

Handy when the content you have is already valid xml.

Parameters
string$elementElement name
array | null$attribsArray of attributes
string$contentsContent of the element
Returns
string

Definition at line 145 of file Xml.php.

References MediaWiki\Xml\Xml\openElement().

Referenced by MediaWiki\Xml\Xml\buildForm(), MediaWiki\Xml\Xml\languageSelector(), and MediaWiki\Xml\Xml\wrapClass().

◆ textarea()

static MediaWiki\Xml\Xml::textarea ( $name,
$content,
$cols = 40,
$rows = 5,
$attribs = [] )
static

Shortcut for creating textareas.

Parameters
string$nameThe 'name' for the textarea
string$contentContent for the textarea
int$colsThe number of columns for the textarea
int$rowsThe number of rows for the textarea
array$attribsAny other attributes for the textarea
Returns
string
Deprecated
since 1.42, use {
See also
Html::textarea} instead

Definition at line 686 of file Xml.php.

References MediaWiki\Xml\Xml\element().

◆ wrapClass()

static MediaWiki\Xml\Xml::wrapClass ( $text,
$class,
$tag = 'span',
$attribs = [] )
static

Shortcut to make a specific element with a class attribute.

Parameters
string$textContent of the element, will be escaped
string$classClass name of the span element
string$tagElement name
array$attribsOther attributes
Returns
string
Deprecated
since 1.42, use {
See also
Xml::tags} instead

Definition at line 292 of file Xml.php.

References MediaWiki\Xml\Xml\tags(), and wfDeprecated().


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