X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FXml.php;h=43f72177a9b3372a9c34b59c76de5506a280a752;hb=734ca2b4d2a1246fb0ea1e54b861ab423ab5e257;hp=11f14dbb698da6c464e6a9a242b6479b5ef33aba;hpb=ea9fcc1e4d3b572199d82c426024e3e5efe23879;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Xml.php b/includes/Xml.php index 11f14dbb69..43f72177a9 100644 --- a/includes/Xml.php +++ b/includes/Xml.php @@ -88,10 +88,10 @@ class Xml { * @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', 'cleanUp' ), $attribs ); + $attribs = array_map( [ 'UtfNormal\Validator', 'cleanUp' ], $attribs ); } if ( $contents ) { $contents = $wgContLang->normalize( $contents ); @@ -143,7 +143,7 @@ class Xml { */ 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 = ''; @@ -184,7 +184,7 @@ class Xml { } 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' ) . ' ' . @@ -202,7 +202,7 @@ class Xml { * @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; @@ -228,16 +228,16 @@ class Xml { $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 ) - ); + ]; } @@ -248,8 +248,8 @@ class Xml { * @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 ); } /** @@ -260,8 +260,8 @@ class Xml { * @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 ); } /** @@ -272,8 +272,8 @@ class Xml { * @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; @@ -296,10 +296,10 @@ class Xml { * @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' ] ) ); } /** @@ -311,7 +311,7 @@ class Xml { * @return array */ public static function attrib( $name, $present = true ) { - return $present ? array( $name => $name ) : array(); + return $present ? [ $name => $name ] : []; } /** @@ -321,12 +321,12 @@ class Xml { * @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 ) ); } @@ -339,11 +339,11 @@ class Xml { * @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 ); } /** @@ -356,10 +356,10 @@ class Xml { * 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]; } @@ -379,7 +379,7 @@ class Xml { * @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; @@ -398,12 +398,12 @@ class Xml { * @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 ) + ]; } /** @@ -417,14 +417,14 @@ class Xml { * * @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; @@ -443,9 +443,9 @@ class Xml { * @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 ); } @@ -457,12 +457,12 @@ class Xml { * @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) @@ -483,7 +483,7 @@ class Xml { * @return string HTML */ public static function option( $text, $value = null, $selected = false, - $attribs = array() ) { + $attribs = [] ) { if ( !is_null( $value ) ) { $attribs['value'] = $value; } @@ -522,7 +522,7 @@ class Xml { 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 @@ -542,7 +542,7 @@ class Xml { $options .= self::closeElement( 'optgroup' ); } - $attribs = array(); + $attribs = []; if ( $name ) { $attribs['id'] = $name; @@ -575,7 +575,7 @@ class Xml { * * @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 ) { @@ -601,15 +601,15 @@ class Xml { * * @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 ); } @@ -625,7 +625,7 @@ class Xml { */ public static function escapeJsString( $string ) { // See ECMA 262 section 7.8.4 for string literal format - $pairs = array( + $pairs = [ "\\" => "\\\\", "\"" => "\\\"", '\'' => '\\\'', @@ -645,7 +645,7 @@ class Xml { # 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 ); } @@ -751,8 +751,8 @@ class Xml { */ public static function escapeTagsOnly( $in ) { return str_replace( - array( '"', '>', '<' ), - array( '"', '>', '<' ), + [ '"', '>', '<' ], + [ '"', '>', '<' ], $in ); } @@ -767,28 +767,28 @@ class Xml { * @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 .= ""; foreach ( $fields as $labelmsg => $input ) { $id = "mw-$labelmsg"; - $form .= Xml::openElement( 'tr', array( 'id' => $id ) ); + $form .= Xml::openElement( 'tr', [ 'id' => $id ] ); // TODO use a