* @param string $contents Null to make an open tag only; '' for a contentless closed tag (default)
* @return string
*/
- public static function elementClean( $element, $attribs = array(), $contents = '' ) {
+ public static function elementClean( $element, $attribs = [], $contents = '' ) {
global $wgContLang;
if ( $attribs ) {
- $attribs = array_map( array( 'UtfNormal\Validator', 'cleanUp' ), $attribs );
+ $attribs = array_map( [ 'UtfNormal\Validator', 'cleanUp' ], $attribs );
}
if ( $contents ) {
$contents = $wgContLang->normalize( $contents );
*/
public static function monthSelector( $selected = '', $allmonths = null, $id = 'month' ) {
global $wgLang;
- $options = array();
+ $options = [];
$data = new XmlSelect( 'month', $id, $selected );
if ( is_null( $selected ) ) {
$selected = '';
} else {
$encYear = '';
}
- $inputAttribs = array( 'id' => 'year', 'maxlength' => 4, 'size' => 7 );
+ $inputAttribs = [ 'id' => 'year', 'maxlength' => 4, 'size' => 7 ];
return self::label( wfMessage( 'year' )->text(), 'year' ) . ' ' .
Html::input( 'year', $encYear, 'number', $inputAttribs ) . ' ' .
self::label( wfMessage( 'month' )->text(), 'month' ) . ' ' .
* @return array Array containing 2 items: label HTML and select list HTML
*/
public static function languageSelector( $selected, $customisedOnly = true,
- $inLanguage = null, $overrideAttrs = array(), Message $msg = null
+ $inLanguage = null, $overrideAttrs = [], Message $msg = null
) {
global $wgLanguageCode;
$options .= Xml::option( "$code - $name", $code, $code == $selected ) . "\n";
}
- $attrs = array( 'id' => 'wpUserLanguage', 'name' => 'wpUserLanguage' );
+ $attrs = [ 'id' => 'wpUserLanguage', 'name' => 'wpUserLanguage' ];
$attrs = array_merge( $attrs, $overrideAttrs );
if ( $msg === null ) {
$msg = wfMessage( 'yourlanguage' );
}
- return array(
+ return [
Xml::label( $msg->text(), $attrs['id'] ),
Xml::tags( 'select', $attrs, $options )
- );
-
+ ];
}
/**
* @param array $attribs Other attributes
* @return string
*/
- public static function span( $text, $class, $attribs = array() ) {
- return self::element( 'span', array( 'class' => $class ) + $attribs, $text );
+ public static function span( $text, $class, $attribs = [] ) {
+ return self::element( 'span', [ 'class' => $class ] + $attribs, $text );
}
/**
* @param array $attribs Other attributes
* @return string
*/
- public static function wrapClass( $text, $class, $tag = 'span', $attribs = array() ) {
- return self::tags( $tag, array( 'class' => $class ) + $attribs, $text );
+ public static function wrapClass( $text, $class, $tag = 'span', $attribs = [] ) {
+ return self::tags( $tag, [ 'class' => $class ] + $attribs, $text );
}
/**
* @param array $attribs Other attributes
* @return string HTML
*/
- public static function input( $name, $size = false, $value = false, $attribs = array() ) {
- $attributes = array( 'name' => $name );
+ public static function input( $name, $size = false, $value = false, $attribs = [] ) {
+ $attributes = [ 'name' => $name ];
if ( $size ) {
$attributes['size'] = $size;
* @return string HTML
*/
public static function password( $name, $size = false, $value = false,
- $attribs = array()
+ $attribs = []
) {
return self::input( $name, $size, $value,
- array_merge( $attribs, array( 'type' => 'password' ) ) );
+ array_merge( $attribs, [ 'type' => 'password' ] ) );
}
/**
* @return array
*/
public static function attrib( $name, $present = true ) {
- return $present ? array( $name => $name ) : array();
+ return $present ? [ $name => $name ] : [];
}
/**
* @param array $attribs Array other attributes
* @return string HTML
*/
- public static function check( $name, $checked = false, $attribs = array() ) {
+ public static function check( $name, $checked = false, $attribs = [] ) {
return self::element( 'input', array_merge(
- array(
+ [
'name' => $name,
'type' => 'checkbox',
- 'value' => 1 ),
+ 'value' => 1 ],
self::attrib( 'checked', $checked ),
$attribs ) );
}
* @param array $attribs Other attributes
* @return string HTML
*/
- public static function radio( $name, $value, $checked = false, $attribs = array() ) {
- return self::element( 'input', array(
+ public static function radio( $name, $value, $checked = false, $attribs = [] ) {
+ return self::element( 'input', [
'name' => $name,
'type' => 'radio',
- 'value' => $value ) + self::attrib( 'checked', $checked ) + $attribs );
+ 'value' => $value ] + self::attrib( 'checked', $checked ) + $attribs );
}
/**
* apply to the label as well; only class and title are applied.
* @return string HTML
*/
- public static function label( $label, $id, $attribs = array() ) {
- $a = array( 'for' => $id );
+ public static function label( $label, $id, $attribs = [] ) {
+ $a = [ 'for' => $id ];
- foreach ( array( 'class', 'title' ) as $attr ) {
+ foreach ( [ 'class', 'title' ] as $attr ) {
if ( isset( $attribs[$attr] ) ) {
$a[$attr] = $attribs[$attr];
}
* @return string HTML
*/
public static function inputLabel( $label, $name, $id, $size = false,
- $value = false, $attribs = array()
+ $value = false, $attribs = []
) {
list( $label, $input ) = self::inputLabelSep( $label, $name, $id, $size, $value, $attribs );
return $label . ' ' . $input;
* @return array
*/
public static function inputLabelSep( $label, $name, $id, $size = false,
- $value = false, $attribs = array()
+ $value = false, $attribs = []
) {
- return array(
+ return [
Xml::label( $label, $id, $attribs ),
- self::input( $name, $size, $value, array( 'id' => $id ) + $attribs )
- );
+ self::input( $name, $size, $value, [ 'id' => $id ] + $attribs )
+ ];
}
/**
*
* @return string HTML
*/
- public static function checkLabel( $label, $name, $id, $checked = false, $attribs = array() ) {
+ public static function checkLabel( $label, $name, $id, $checked = false, $attribs = [] ) {
global $wgUseMediaWikiUIEverywhere;
- $chkLabel = self::check( $name, $checked, array( 'id' => $id ) + $attribs ) .
+ $chkLabel = self::check( $name, $checked, [ 'id' => $id ] + $attribs ) .
' ' .
self::label( $label, $id, $attribs );
if ( $wgUseMediaWikiUIEverywhere ) {
- $chkLabel = self::openElement( 'div', array( 'class' => 'mw-ui-checkbox' ) ) .
+ $chkLabel = self::openElement( 'div', [ 'class' => 'mw-ui-checkbox' ] ) .
$chkLabel . self::closeElement( 'div' );
}
return $chkLabel;
* @return string HTML
*/
public static function radioLabel( $label, $name, $value, $id,
- $checked = false, $attribs = array()
+ $checked = false, $attribs = []
) {
- return self::radio( $name, $value, $checked, array( 'id' => $id ) + $attribs ) .
+ return self::radio( $name, $value, $checked, [ 'id' => $id ] + $attribs ) .
' ' .
self::label( $label, $id, $attribs );
}
/**
* Convenience function to build an HTML submit button
- * When $wgUseMediaWikiUIEverywhere is true it will default to a constructive button
+ * When $wgUseMediaWikiUIEverywhere is true it will default to a progressive button
* @param string $value Label text for the button
* @param array $attribs Optional custom attributes
* @return string HTML
*/
- public static function submitButton( $value, $attribs = array() ) {
+ public static function submitButton( $value, $attribs = [] ) {
global $wgUseMediaWikiUIEverywhere;
- $baseAttrs = array(
+ $baseAttrs = [
'type' => 'submit',
'value' => $value,
- );
+ ];
// Done conditionally for time being as it is possible
// some submit forms
// might need to be mw-ui-destructive (e.g. delete a page)
if ( $wgUseMediaWikiUIEverywhere ) {
- $baseAttrs['class'] = 'mw-ui-button mw-ui-constructive';
+ $baseAttrs['class'] = 'mw-ui-button mw-ui-progressive';
}
// Any custom attributes will take precendence of anything in baseAttrs e.g. override the class
$attribs = $attribs + $baseAttrs;
* @return string HTML
*/
public static function option( $text, $value = null, $selected = false,
- $attribs = array() ) {
+ $attribs = [] ) {
if ( !is_null( $value ) ) {
$attribs['value'] = $value;
}
if ( $optgroup ) {
$options .= self::closeElement( 'optgroup' );
}
- $options .= self::openElement( 'optgroup', array( 'label' => $value ) );
+ $options .= self::openElement( 'optgroup', [ 'label' => $value ] );
$optgroup = true;
} elseif ( substr( $value, 0, 2 ) == '**' ) {
// groupmember
$options .= self::closeElement( 'optgroup' );
}
- $attribs = array();
+ $attribs = [];
if ( $name ) {
$attribs['id'] = $name;
*
* @return string
*/
- public static function fieldset( $legend = false, $content = false, $attribs = array() ) {
+ public static function fieldset( $legend = false, $content = false, $attribs = [] ) {
$s = Xml::openElement( 'fieldset', $attribs ) . "\n";
if ( $legend ) {
*
* @return string
*/
- public static function textarea( $name, $content, $cols = 40, $rows = 5, $attribs = array() ) {
+ public static function textarea( $name, $content, $cols = 40, $rows = 5, $attribs = [] ) {
return self::element( 'textarea',
Html::getTextInputAttributes(
- array(
+ [
'name' => $name,
'id' => $name,
'cols' => $cols,
'rows' => $rows
- ) + $attribs
+ ] + $attribs
),
$content, false );
}
- /**
- * 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
- * @param string $string String to escape
- * @return string
- */
- public static function escapeJsString( $string ) {
- // See ECMA 262 section 7.8.4 for string literal format
- $pairs = array(
- "\\" => "\\\\",
- "\"" => "\\\"",
- '\'' => '\\\'',
- "\n" => "\\n",
- "\r" => "\\r",
-
- # To avoid closing the element or CDATA section
- "<" => "\\x3c",
- ">" => "\\x3e",
-
- # To avoid any complaints about bad entity refs
- "&" => "\\x26",
-
- # Work around https://bugzilla.mozilla.org/show_bug.cgi?id=274152
- # Encode certain Unicode formatting chars so affected
- # versions of Gecko don't misinterpret our strings;
- # this is a common problem with Farsi text.
- "\xe2\x80\x8c" => "\\u200c", // ZERO WIDTH NON-JOINER
- "\xe2\x80\x8d" => "\\u200d", // ZERO WIDTH JOINER
- );
-
- return strtr( $string, $pairs );
- }
-
/**
* Encode a variable of arbitrary type to JavaScript.
* If the value is an XmlJsCode object, pass through the object's value verbatim.
*/
public static function escapeTagsOnly( $in ) {
return str_replace(
- array( '"', '>', '<' ),
- array( '"', '>', '<' ),
+ [ '"', '>', '<' ],
+ [ '"', '>', '<' ],
$in );
}
* @param array $submitAttribs The attributes to add to the submit button
* @return string HTML form.
*/
- public static function buildForm( $fields, $submitLabel = null, $submitAttribs = array() ) {
+ public static function buildForm( $fields, $submitLabel = null, $submitAttribs = [] ) {
$form = '';
$form .= "<table><tbody>";
foreach ( $fields as $labelmsg => $input ) {
$id = "mw-$labelmsg";
- $form .= Xml::openElement( 'tr', array( 'id' => $id ) );
+ $form .= Xml::openElement( 'tr', [ 'id' => $id ] );
// TODO use a <label> here for accessibility purposes - will need
// to either not use a table to build the form, or find the ID of
// the input somehow.
- $form .= Xml::tags( 'td', array( 'class' => 'mw-label' ), wfMessage( $labelmsg )->parse() );
- $form .= Xml::openElement( 'td', array( 'class' => 'mw-input' ) )
+ $form .= Xml::tags( 'td', [ 'class' => 'mw-label' ], wfMessage( $labelmsg )->parse() );
+ $form .= Xml::openElement( 'td', [ 'class' => 'mw-input' ] )
. $input . Xml::closeElement( 'td' );
$form .= Xml::closeElement( 'tr' );
}
if ( $submitLabel ) {
$form .= Xml::openElement( 'tr' );
- $form .= Xml::tags( 'td', array(), '' );
- $form .= Xml::openElement( 'td', array( 'class' => 'mw-submit' ) )
+ $form .= Xml::tags( 'td', [], '' );
+ $form .= Xml::openElement( 'td', [ 'class' => 'mw-submit' ] )
. Xml::submitButton( wfMessage( $submitLabel )->text(), $submitAttribs )
. Xml::closeElement( 'td' );
$form .= Xml::closeElement( 'tr' );
* @param array $headers An array of strings to use as table headers [optional]
* @return string
*/
- public static function buildTable( $rows, $attribs = array(), $headers = null ) {
+ public static function buildTable( $rows, $attribs = [], $headers = null ) {
$s = Xml::openElement( 'table', $attribs );
if ( is_array( $headers ) ) {
$s .= Xml::openElement( 'thead', $attribs );
foreach ( $headers as $id => $header ) {
- $attribs = array();
+ $attribs = [];
if ( is_string( $id ) ) {
$attribs['id'] = $id;
}
foreach ( $rows as $id => $row ) {
- $attribs = array();
+ $attribs = [];
if ( is_string( $id ) ) {
$attribs['id'] = $id;
$s = Xml::openElement( 'tr', $attribs );
foreach ( $cells as $id => $cell ) {
- $attribs = array();
+ $attribs = [];
if ( is_string( $id ) ) {
$attribs['id'] = $id;