Methods

element()

element(string|null  $element = null, array  $attribs = null, string  $contents = '', boolean  $allowShortTag = true) : string

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|null $element

element name

array $attribs

Name=>value pairs. Values will be escaped.

string $contents

NULL to make an open tag only; '' for a contentless closed tag (default)

boolean $allowShortTag

whether '' in $contents will result in a contentless closed tag

Returns

string

encodeAttribute()

encodeAttribute(  $text) 

Parameters

$text

expandAttributes()

expandAttributes(array|null  $attribs = null) : null|string

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

The values are passed to self::encodeAttribute. Return null if no attributes given.

Parameters

array|null $attribs

of attributes for an XML element

Throws

\Exception

Returns

null|string

elementClean()

elementClean(  $element, array  $attribs = array(), string  $contents = '') : string

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

$element

String:

array $attribs

Name=>value pairs. Values will be escaped.

string $contents

NULL to make an open tag only; '' for a contentless closed tag (default)

Returns

string

openElement()

openElement(string  $element, array  $attribs = null) : string

This opens an XML element

Parameters

string $element

name of the element

array $attribs

of attributes, see self::expandAttributes()

Returns

string

closeElement()

closeElement(string  $element) : string

Shortcut to close an XML element

Parameters

string $element

element name

Returns

string

tags()

tags(string  $element, array  $attribs = null, string  $contents) : string

Same as self::element(), but does not escape contents. Handy when the content you have is already valid xml.

Parameters

string $element

element name

array $attribs

of attributes

string $contents

content of the element

Returns

string

span()

span(string  $text, string  $class, array  $attribs = array()) : string

Shortcut to make a span element

Parameters

string $text

content of the element, will be escaped

string $class

class name of the span element

array $attribs

other attributes

Returns

string

wrapClass()

wrapClass(string  $text, string  $class, string  $pgTag = 'span', array  $attribs = array()) : string

Shortcut to make a specific element with a class attribute

Parameters

string $text

content of the element, will be escaped

string $class

class name of the span element

string $pgTag

element name

array $attribs

other attributes

Returns

string

input()

input(string  $name, boolean|integer  $size = false, mixed  $value = false, array  $attribs = array()) : string

Convenience function to build an HTML text input field

Parameters

string $name

value of the name attribute

boolean|integer $size

value of the size attribute

mixed $value

mixed value of the value attribute

array $attribs

other attributes

Returns

string —

HTML

password()

password(string  $name, boolean|integer  $size = false,   $value = false, array  $attribs = array()) : string

Convenience function to build an HTML password input field

Parameters

string $name

value of the name attribute

boolean|integer $size

value of the size attribute

$value

mixed value of the value attribute

array $attribs

other attributes

Returns

string —

HTML

attrib()

attrib(  $name,   $present = true) : array

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

Parameters

$name

string

$present

bool

Returns

array

check()

check(string  $name, boolean  $checked = false, array  $attribs = array()) : string

Convenience function to build an HTML checkbox

Parameters

string $name

value of the name attribute

boolean $checked

Whether the checkbox is checked or not

array $attribs

other attributes

Returns

string —

HTML

radio()

radio(string  $name, string  $value, boolean  $checked = false, array  $attribs = array()) : string

Convenience function to build an HTML radio button

Parameters

string $name

value of the name attribute

string $value

value of the value attribute

boolean $checked

Whether the checkbox is checked or not

array $attribs

other attributes

Returns

string —

HTML

label()

label(string  $label,   $id, array  $attribs = array()) : string

Convenience function to build an HTML form label

Parameters

string $label

text of the label

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

Returns

string —

HTML

inputLabel()

inputLabel(string  $label, string  $name, string  $id, integer|Bool  $size = false, string|Bool  $value = false, array  $attribs = array()) : string

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

Parameters

string $label

text of the label

string $name

value of the name attribute

string $id

id of the input

integer|Bool $size

value of the size attribute

string|Bool $value

value of the value attribute

array $attribs

other attributes

Returns

string —

HTML

inputLabelSep()

inputLabelSep(  $label,   $name,   $id,   $size = false,   $value = false,   $attribs = array()) : array

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

Parameters

$label

String

$name

String

$id

String

$size

Int|Bool

$value

String|Bool

$attribs

array

Returns

array

checkLabel()

checkLabel(  $label,   $name,   $id,   $checked = false,   $attribs = array()) : string

Convenience function to build an HTML checkbox with a label

Parameters

$label
$name
$id
$checked

bool

$attribs

array

Returns

string —

HTML

radioLabel()

radioLabel(  $label,   $name,   $value,   $id,   $checked = false,   $attribs = array()) : string

Convenience function to build an HTML radio button with a label

Parameters

$label
$name
$value
$id
$checked

bool

$attribs

array

Returns

string —

HTML

submitButton()

submitButton(string  $value, array  $attribs = array()) : string

Convenience function to build an HTML submit button

Parameters

string $value

label text for the button

array $attribs

optional custom attributes

Returns

string —

HTML

option()

option(string  $text, string  $value = null,   $selected = false, array  $attribs = array()) : string

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

Parameters

string $text

text for this item. Will be HTML escaped

string $value

form submission value; if empty, use text

$selected

boolean: if true, will be the default selected item

array $attribs

optional additional HTML attributes

Returns

string —

HTML

listDropDown()

listDropDown(  $name = '',   $list = '',   $other = '',   $selected = '',   $class = '',   $tabindex = null) : string

Build a drop-down box from a textual list.

Parameters

$name

Mixed: Name and id for the drop-down

$list

Mixed: Correctly formatted text (newline delimited) to be used to generate the options

$other

Mixed: Text for the "Other reasons" option

$selected

Mixed: Option which should be pre-selected

$class

Mixed: CSS classes for the drop-down

$tabindex

Mixed: Value of the tabindex attribute

Returns

string

fieldset()

fieldset(string|boolean  $legend = false, string|boolean  $content = false, array  $attribs = array()) : string

Shortcut for creating fieldsets.

Parameters

string|boolean $legend

Legend of the fieldset. If evaluates to false, legend is not added.

string|boolean $content

Pre-escaped content for the fieldset. If false, only open fieldset is returned.

array $attribs

Any attributes to fieldset-element.

Returns

string

textarea()

textarea(string  $name, string  $content, integer  $cols = 40, integer  $rows = 5, array  $attribs = array()) : string

Shortcut for creating textareas.

Parameters

string $name

The 'name' for the textarea

string $content

Content for the textarea

integer $cols

The number of columns for the textarea

integer $rows

The number of rows for the textarea

array $attribs

Any other attributes for the textarea

Returns

string

escapeJsString()

escapeJsString(string  $string) : String

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

Illegal control characters are assumed not to be present.

Parameters

string $string

to escape

Returns

String

encodeJsVar()

encodeJsVar(  $value) : integer|string

Encode a variable of unknown type to JavaScript.

Arrays are converted to JS arrays, objects are converted to JS associative arrays (objects). So cast your PHP associative arrays to objects before passing them to here.

Parameters

$value

Returns

integer|string

encodeJsCall()

encodeJsCall(string  $name, array  $args, boolean  $pretty = false) : string|\bool:

Create a call to a JavaScript function. The supplied arguments will be encoded using self::encodeJsVar().

Parameters

string $name

The name of the function to call, or a JavaScript expression which evaluates to a function object which is called.

array $args

The arguments to pass to the function.

boolean $pretty

If true, add non-significant whitespace to improve readability.

Returns

string|\bool: —

String if successful; false upon failure

isWellFormed()

isWellFormed(string  $text) : boolean

Check if a string is well-formed XML.

Must include the surrounding tag.

Parameters

string $text

string to test.

Returns

boolean

isWellFormedXmlFragment()

isWellFormedXmlFragment(  $text) : boolean

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

$text

String:

Returns

boolean

hackDocType()

hackDocType() 

escapeTagsOnly()

escapeTagsOnly(string  $in) : string

Replace " > and < with their respective HTML entities ( &quot;, &gt;, &lt;)

Parameters

string $in

text that might contain HTML tags.

Returns

string —

Escaped string

buildTable()

buildTable(array  $rows, array  $attribs = array(), array  $headers = null) : string

Build a table of data

Parameters

array $rows

An array of arrays of strings, each to be a row in a table

array $attribs

An array of attributes to apply to the table tag [optional]

array $headers

An array of strings to use as table headers [optional]

Returns

string

buildTableRow()

buildTableRow(array  $attribs, array  $cells) : string

Build a row for a table

Parameters

array $attribs

An array of attributes to apply to the tr tag

array $cells

An array of strings to put in

Returns

string