|
MediaWiki master
|
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 | closeElement ( $element) |
| Shortcut to close an XML element. | |
| 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 | 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 | 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 | 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 | 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 | tags ( $element, $attribs, $contents) |
| Same as Xml::element(), but does not escape contents. | |
|
static |
Internal function for use in checkboxes and radio buttons and such.
| string | $name | |
| bool | $present |
|
static |
Generate a form (without the opening form element).
Output optionally includes a submit button.
| array | $fields | Associative 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 | $submitLabel | The name of a message containing a label for the submit button. |
| array | $submitAttribs | The attributes to add to the submit button |
Definition at line 411 of file Xml.php.
References MediaWiki\Xml\Xml\closeElement(), MediaWiki\Html\element(), MediaWiki\Xml\Xml\openElement(), MediaWiki\Xml\Xml\tags(), and wfMessage().
|
static |
Shortcut to close an XML element.
| string | $element | Element name |
Definition at line 111 of file Xml.php.
Referenced by MediaWiki\Xml\Xml\buildForm(), MediaWiki\Xml\Xml\fieldset(), and MediaWiki\Api\ApiFormatXml\recXmlPrint().
|
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.
| string | $element | Element name |
| array | null | $attribs | Name=>value pairs. Values will be escaped. |
| string | null | $contents | Null to make an open tag only; '' for a contentless closed tag (default) |
| bool | $allowShortTag | Whether '' in $contents will result in a contentless closed tag |
Definition at line 36 of file Xml.php.
References MediaWiki\Xml\Xml\expandAttributes().
Referenced by MediaWiki\Xml\Xml\elementClean(), MediaWiki\Xml\Xml\fieldset(), MediaWiki\Xml\Xml\label(), and MediaWiki\Api\ApiFormatXml\recXmlPrint().
|
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.
| string | $element | |
| array | null | $attribs | Name=>value pairs. Values will be escaped. |
| string | null | $contents | Null to make an open tag only; '' for a contentless closed tag (default) |
Definition at line 84 of file Xml.php.
References MediaWiki\Xml\Xml\element(), and MediaWiki\MediaWikiServices\getInstance().
|
static |
|
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.
| array | null | $attribs | Array of attributes for an XML element |
Definition at line 62 of file Xml.php.
Referenced by MediaWiki\Xml\Xml\element(), and MediaWiki\Xml\Xml\openElement().
|
static |
Shortcut for creating fieldsets.
| string | false | $legend | Legend of the fieldset. If evaluates to false, legend is not added. |
| string | false | $content | Pre-escaped content for the fieldset. If false, only open fieldset is returned. |
| array | $attribs | Any attributes to fieldset-element. |
Definition at line 320 of file Xml.php.
References MediaWiki\Xml\Xml\closeElement(), MediaWiki\Xml\Xml\element(), and MediaWiki\Xml\Xml\openElement().
|
static |
|
static |
Convenience function to build an HTML form label.
| string | $label | Text of the label |
| string | $id | |
| array | $attribs | An 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. |
Definition at line 158 of file Xml.php.
References MediaWiki\Xml\Xml\element().
|
static |
Build a drop-down box from a textual list.
This is a wrapper for Xml::listDropdownOptions() plus the XmlSelect class.
| string | $name | Name and id for the drop-down |
| string | $list | Correctly formatted text (newline delimited) to be used to generate the options. |
| string | $other | Text for the "Other reasons" option |
| string | $selected | Option which should be pre-selected |
| string | $class | CSS classes for the drop-down |
| int | null | $tabindex | Value of the tabindex attribute |
Definition at line 206 of file Xml.php.
References MediaWiki\Xml\Xml\listDropdownOptions().
|
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).
| string | $list | Correctly formatted text (newline delimited) to be used to generate the options. |
| array | $params | Extra parameters:
|
Definition at line 239 of file Xml.php.
Referenced by MediaWiki\Xml\Xml\listDropdown().
|
static |
Convert options for a drop-down box into a format accepted by OOUI\DropdownInputWidget etc.
TODO Find a better home for this function.
| array | $options | Options, as returned e.g. by Xml::listDropdownOptions() |
|
static |
This opens an XML element.
| string | $element | Name of the element |
| array | null | $attribs | Array of attributes, see Xml::expandAttributes() |
Definition at line 102 of file Xml.php.
References MediaWiki\Xml\Xml\expandAttributes().
Referenced by MediaWiki\Xml\Xml\buildForm(), MediaWiki\Xml\Xml\fieldset(), and MediaWiki\Xml\Xml\tags().
|
static |
Convenience function to build an HTML drop-down list item.
| string | $text | Text for this item. Will be HTML escaped |
| string | null | $value | Form submission value; if empty, use text |
| bool | $selected | If true, will be the default selected item |
| array | $attribs | Optional additional HTML attributes |
Definition at line 180 of file Xml.php.
References MediaWiki\Html\element().
|
static |
Same as Xml::element(), but does not escape contents.
Handy when the content you have is already valid xml.
| string | $element | Element name |
| array | null | $attribs | Array of attributes |
| string | $contents | Content of the element |
Definition at line 128 of file Xml.php.
References MediaWiki\Xml\Xml\openElement().
Referenced by MediaWiki\Xml\Xml\buildForm().