MediaWiki  REL1_24
Xml Class Reference

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

List of all members.

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=array())
 Generate a form (without the opening form element).
static buildTable ($rows, $attribs=array(), $headers=null)
 Build a table of data.
static buildTableRow ($attribs, $cells)
 Build a row for a table.
static check ($name, $checked=false, $attribs=array())
 Convenience function to build an HTML checkbox.
static checkLabel ($label, $name, $id, $checked=false, $attribs=array())
 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=array(), $contents= '')
 Format an XML element as with self::element(), but run text through the $wgContLang->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 escapeJsString ($string)
 Returns an escaped string suitable for inclusion in a string literal for JavaScript source code.
static escapeTagsOnly ($in)
 Replace " > and < with their respective HTML entities ( ", >, <)
static expandAttributes ($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=array())
 Shortcut for creating fieldsets.
static input ($name, $size=false, $value=false, $attribs=array())
 Convenience function to build an HTML text input field.
static inputLabel ($label, $name, $id, $size=false, $value=false, $attribs=array())
 Convenience function to build an HTML text input field with a label.
static inputLabelSep ($label, $name, $id, $size=false, $value=false, $attribs=array())
 Same as Xml::inputLabel() but return input and label in an array.
static isWellFormed ($text)
 Check if a string is well-formed XML.
static isWellFormedXmlFragment ($text)
 Check if a string is a well-formed XML fragment.
static label ($label, $id, $attribs=array())
 Convenience function to build an HTML form label.
static languageSelector ($selected, $customisedOnly=true, $inLanguage=null, $overrideAttrs=array(), 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 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=array())
 Convenience function to build an HTML drop-down list item.
static password ($name, $size=false, $value=false, $attribs=array())
 Convenience function to build an HTML password input field.
static radio ($name, $value, $checked=false, $attribs=array())
 Convenience function to build an HTML radio button.
static radioLabel ($label, $name, $value, $id, $checked=false, $attribs=array())
 Convenience function to build an HTML radio button with a label.
static span ($text, $class, $attribs=array())
 Shortcut to make a span element.
static submitButton ($value, $attribs=array())
 Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will default to a constructive button.
static tags ($element, $attribs=null, $contents)
 Same as Xml::element(), but does not escape contents.
static textarea ($name, $content, $cols=40, $rows=5, $attribs=array())
 Shortcut for creating textareas.
static wrapClass ($text, $class, $tag= 'span', $attribs=array())
 Shortcut to make a specific element with a class attribute.

Detailed Description

Module of static functions for generating XML.

Definition at line 26 of file Xml.php.


Member Function Documentation

static Xml::attrib ( name,
present = true 
) [static]

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

Parameters:
string$name
bool$present
Returns:
array

Definition at line 322 of file Xml.php.

References $name, and array().

static Xml::buildForm ( fields,
submitLabel = null,
submitAttribs = array() 
) [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$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.

Definition at line 779 of file Xml.php.

static Xml::buildTable ( rows,
attribs = array(),
headers = null 
) [static]

Build a table of data.

Parameters:
array$rowsAn array of arrays of strings, each to be a row in a table
array$attribsAn array of attributes to apply to the table tag [optional]
array$headersAn array of strings to use as table headers [optional]
Returns:
string

Definition at line 818 of file Xml.php.

static Xml::buildTableRow ( attribs,
cells 
) [static]

Build a row for a table.

Parameters:
array$attribsAn array of attributes to apply to the tr tag
array$cellsAn array of strings to put in
Returns:
string

Definition at line 857 of file Xml.php.

static Xml::check ( name,
checked = false,
attribs = array() 
) [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

Definition at line 333 of file Xml.php.

References $attribs, $name, array(), and element().

Referenced by checkLabel(), and HTMLCheckField\getInputHTML().

static Xml::dateMenu ( year,
month 
) [static]
Parameters:
int$year
int$month
Returns:
string Formatted HTML

Definition at line 176 of file Xml.php.

References $timestamp, array(), MWTimestamp\getInstance(), input(), label(), monthSelector(), text, and wfMessage().

Referenced by XmlTest\testDateMenu().

static 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$attribsName=>value pairs. Values will be escaped.
string$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 39 of file Xml.php.

References $attribs, $out, and expandAttributes().

Referenced by ChangeTags\buildTagFilterSelector(), XmlDumpWriter\caseSetting(), check(), Preferences\datetimePreferences(), SpecialTags\doTagRow(), elementClean(), escapeJsString(), SpecialExport\execute(), SpecialListGroupRights\execute(), fieldset(), SpecialStatistics\formatRow(), ImageListPager\formatValue(), SpecialVersion\getExtensionCredits(), SpecialVersion\getMediaWikiCredits(), Skin\getNewtalks(), MIMEsearchPage\getPageHeader(), SpecialVersion\getSkinCredits(), UserrightsPage\groupCheckboxes(), input(), label(), SpecialPrefixindex\namespacePrefixForm(), option(), DjVuImage\parseFormDjvu(), SpecialSearch\powerSearchBox(), radio(), ApiFormatXml\recXmlPrint(), UserrightsPage\showEditUserGroupsForm(), SpecialPageLanguage\showLogFragment(), UserrightsPage\showLogFragment(), SpecialProtectedpages\showOptions(), SpecialProtectedtitles\showOptions(), ApiFormatWddx\slowWddxPrinter(), SpecialVersion\softwareInformation(), span(), submitButton(), XmlTest\testElementAttributes(), XmlTest\testElementEmpty(), XmlTest\testElementEscaping(), XmlTest\testElementOpen(), textarea(), Preferences\validateSignature(), and XmlDumpWriter\writeContributor().

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

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

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

Definition at line 91 of file Xml.php.

References $attribs, $wgContLang, array(), element(), global, wfProfileIn(), and wfProfileOut().

Referenced by JsonContent\objectRow(), and XmlDumpWriter\writeContributor().

static 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|bool String if successful; false upon failure

Definition at line 693 of file Xml.php.

Referenced by ResourceLoaderLanguageNamesModule\getScript(), ResourceLoaderLanguageDataModule\getScript(), ResourceLoaderUserTokensModule\getScript(), ResourceLoaderUserOptionsModule\getScript(), and ResourceLoaderStartUpModule\getScript().

static Xml::encodeJsVar ( value,
pretty = false 
) [static]

Encode a variable of arbitrary type to JavaScript.

If the value is an XmlJsCode 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|bool String if successful; false upon failure

Definition at line 675 of file Xml.php.

Referenced by WebInstallerComplete\execute(), XmlTest\testEncodeJsVarArray(), XmlTest\testEncodeJsVarBoolean(), XmlTest\testEncodeJsVarFloat(), XmlTest\testEncodeJsVarFloatString(), XmlTest\testEncodeJsVarInt(), XmlTest\testEncodeJsVarIntString(), XmlTest\testEncodeJsVarNull(), and XmlTest\testEncodeJsVarObject().

static Xml::escapeJsString ( string) [static]

Returns an escaped string suitable for inclusion in a string literal for JavaScript source code.

Illegal control characters are assumed not to be present.

Deprecated:
since 1.21; use Xml::encodeJsVar() or Xml::encodeJsCall() instead
Parameters:
string$stringString to escape
Returns:
string

Definition at line 637 of file Xml.php.

References any, array(), element(), https, of, section, and so.

Referenced by XmlTest\testEscapeJsStringSpecialChars().

static 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 761 of file Xml.php.

Referenced by CoreTagHooks\nowiki(), CoreTagHooks\pre(), and XmlTest\testEscapeTagsOnly().

static Xml::expandAttributes ( 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. Return null if no attributes given.

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

Definition at line 67 of file Xml.php.

References $attribs, $name, $out, as, and Sanitizer\encodeAttribute().

Referenced by element(), EditPage\getEditButtons(), openElement(), XmlTest\testExpandAttributes(), XmlTest\testExpandAttributesException(), and Linker\tooltip().

static Xml::fieldset ( legend = false,
content = false,
attribs = array() 
) [static]

Shortcut for creating fieldsets.

Parameters:
string | bool$legendLegend of the fieldset. If evaluates to false, legend is not added.
string$contentPre-escaped content for the fieldset. If false, only open fieldset is returned.
array$attribsAny attributes to fieldset-element.
Returns:
string

Definition at line 589 of file Xml.php.

References $attribs, $content, $s, closeElement(), element(), and openElement().

Referenced by SpecialRecentChanges\doHeader(), SpecialNewpages\form(), UsersPager\getPageHeader(), SpecialWatchlist\setTopText(), SpecialImport\showForm(), and UserrightsPage\switchForm().

static Xml::input ( name,
size = false,
value = false,
attribs = array() 
) [static]

Convenience function to build an HTML text input field.

Parameters:
string$nameValue of the name attribute
int$sizeValue of the size attribute
mixed$valueValue of the value attribute
array$attribsOther attributes
Returns:
string HTML

Definition at line 284 of file Xml.php.

References $attribs, $name, $size, $value, array(), element(), and Html\getTextInputAttributes().

Referenced by ChangeTags\buildTagFilterSelector(), dateMenu(), SpecialNewpages\form(), SpecialProtectedpages\getSizeLimit(), SpecialPrefixindex\namespacePrefixForm(), password(), UserrightsPage\showEditUserGroupsForm(), SpecialImport\showForm(), and XmlTest\testElementInputCanHaveAValueOfZero().

static Xml::inputLabel ( label,
name,
id,
size = false,
value = false,
attribs = array() 
) [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 | bool$sizeValue of the size attribute
string | bool$valueValue of the value attribute
array$attribsOther attributes
Returns:
string HTML

Definition at line 392 of file Xml.php.

References $attribs, $name, $size, $value, inputLabelSep(), and list.

Referenced by SpecialExport\execute(), LinkSearchPage\execute(), FileDuplicateSearchPage\execute(), WithoutInterwikiPage\getPageHeader(), MIMEsearchPage\getPageHeader(), SpecialBookSources\makeForm(), and UserrightsPage\switchForm().

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

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

Parameters:
string$label
string$name
string$id
int | bool$size
string | bool$value
array$attribs
Returns:
array

Definition at line 411 of file Xml.php.

References $attribs, $name, $size, $value, array(), and label().

Referenced by SpecialRecentChanges\categoryFilterForm(), and inputLabel().

static Xml::isWellFormed ( text) [static]

Check if a string is well-formed XML.

Must include the surrounding tag.

Parameters:
string$textString to test.
Returns:
bool
Todo:
Error position reporting return

Definition at line 716 of file Xml.php.

static 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 744 of file Xml.php.

static Xml::label ( label,
id,
attribs = array() 
) [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

Definition at line 368 of file Xml.php.

References $attribs, array(), and element().

Referenced by checkLabel(), dateMenu(), inputLabelSep(), languageSelector(), radioLabel(), SpecialImport\showForm(), XmlTest\testLabelAttributeCanOnlyBeClassOrTitle(), and XmlTest\testLabelCreation().

static Xml::languageSelector ( selected,
customisedOnly = true,
inLanguage = null,
overrideAttrs = array(),
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$inLanguageThe ISO code of the language to display the select list in (optional)
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

Definition at line 213 of file Xml.php.

References $name, $options, array(), as, Language\fetchLanguageNames(), global, label(), option(), tags(), and wfMessage().

Referenced by XmlTest\testLanguageSelector().

static Xml::listDropDown ( name = '',
list = '',
other = '',
selected = '',
class = '',
tabindex = null 
) [static]

Build a drop-down box from a textual list.

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$tabindexValue of the tabindex attribute
Returns:
string

Definition at line 519 of file Xml.php.

References $attribs, $name, $options, $tabindex, $value, array(), as, closeElement(), openElement(), and option().

static Xml::monthSelector ( selected = '',
allmonths = null,
id = 'month' 
) [static]

Create a date selector.

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

Definition at line 146 of file Xml.php.

References $options, $wgLang, array(), closeElement(), global, openElement(), option(), text, and wfMessage().

Referenced by dateMenu().

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

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

Parameters:
string$textText for this item. Will be HTML escaped
string$valueForm submission value; if empty, use text
bool$selectedIf true, will be the default selected item
array$attribsOptional additional HTML attributes
Returns:
string HTML

Definition at line 496 of file Xml.php.

References $attribs, $value, and element().

Referenced by ProtectionForm\buildSelector(), SpecialProtectedtitles\getLevelMenu(), SpecialProtectedpages\getLevelMenu(), UsersPager\getPageHeader(), SpecialProtectedpages\getTypeMenu(), languageSelector(), listDropDown(), monthSelector(), and SpecialImport\showForm().

static Xml::password ( name,
size = false,
value = false,
attribs = array() 
) [static]

Convenience function to build an HTML password input field.

Parameters:
string$nameValue of the name attribute
int$sizeValue of the size attribute
mixed$valueValue of the value attribute
array$attribsOther attributes
Returns:
string HTML

Definition at line 307 of file Xml.php.

References $attribs, $name, $size, $value, array(), and input().

static Xml::radio ( name,
value,
checked = false,
attribs = array() 
) [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

Definition at line 351 of file Xml.php.

References $attribs, $name, $value, array(), and element().

Referenced by HTMLRadioField\formatOptions(), and radioLabel().

static Xml::radioLabel ( label,
name,
value,
id,
checked = false,
attribs = array() 
) [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

Definition at line 456 of file Xml.php.

References $attribs, $name, $value, array(), label(), and radio().

Referenced by SpecialProtectedpages\getSizeLimit().

static Xml::span ( text,
class,
attribs = array() 
) [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

Definition at line 260 of file Xml.php.

References $attribs, array(), and element().

static Xml::textarea ( name,
content,
cols = 40,
rows = 5,
attribs = array() 
) [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

Definition at line 615 of file Xml.php.

References $attribs, $content, $name, array(), element(), and Html\getTextInputAttributes().

Referenced by XmlTest\testTextareaAttribs(), and XmlTest\testTextareaNoContent().

static Xml::wrapClass ( text,
class,
tag = 'span',
attribs = array() 
) [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

Definition at line 272 of file Xml.php.

References $attribs, array(), and tags().


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