32use UtfNormal\Validator;
54 public static function element( $element, $attribs =
null, $contents =
'',
57 $out =
'<' . $element;
58 if ( $attribs !==
null ) {
61 if ( $contents ===
null ) {
63 } elseif ( $allowShortTag && $contents ===
'' ) {
66 $out .=
'>' . htmlspecialchars( $contents, ENT_NOQUOTES ) .
"</$element>";
80 if ( $attribs ===
null ) {
84 foreach ( $attribs as $name => $val ) {
85 $out .=
" {$name}=\"" . Sanitizer::encodeAttribute( $val ) .
'"';
101 public static function elementClean( $element, $attribs = [], $contents =
'' ) {
103 $attribs = array_map( [ Validator::class,
'cleanUp' ], $attribs );
129 return "</$element>";
145 public static function tags( $element, $attribs, $contents ) {
160 public static function monthSelector( $selected =
'', $allmonths =
null, $id =
'month' ) {
166 $data =
new XmlSelect(
'month', $id, $selected ??
'' );
168 if ( $allmonths !==
null ) {
169 $options[
wfMessage(
'monthsall' )->text()] = $allmonths;
171 for ( $i = 1; $i < 13; $i++ ) {
172 $options[
$wgLang->getMonthName( $i )] = $i;
174 $data->addOptions( $options );
175 $data->setAttribute(
'class',
'mw-month-selector' );
176 return $data->getHTML();
189 # Offset overrides year/month selection
190 if ( $month && $month !== -1 ) {
191 $encMonth = intval( $month );
196 $encYear = intval( $year );
197 } elseif ( $encMonth ) {
198 $timestamp = MWTimestamp::getInstance();
199 $thisMonth = intval( $timestamp->format(
'n' ) );
200 $thisYear = intval( $timestamp->format(
'Y' ) );
201 if ( $encMonth > $thisMonth ) {
204 $encYear = $thisYear;
208 $inputAttribs = [
'id' =>
'year',
'maxlength' => 4,
'size' => 7 ];
210 Html::input(
'year', $encYear,
'number', $inputAttribs ) .
' ' .
228 $inLanguage =
null, $overrideAttrs = [], ?
Message $msg =
null
234 $include = $customisedOnly ? LanguageNameUtils::SUPPORTED : LanguageNameUtils::DEFINED;
236 ->getLanguageNameUtils()
237 ->getLanguageNames( $inLanguage, $include );
241 if ( !array_key_exists( $languageCode, $languages ) ) {
242 $languages[$languageCode] = $languageCode;
252 $selected = isset( $languages[$selected] ) ? $selected : $languageCode;
254 foreach ( $languages as $code => $name ) {
255 $options .=
self::option(
"$code - $name", $code, $code == $selected ) .
"\n";
258 $attrs = [
'id' =>
'wpUserLanguage',
'name' =>
'wpUserLanguage' ];
259 $attrs = array_merge( $attrs, $overrideAttrs );
277 public static function span( $text, $class, $attribs = [] ) {
280 return self::element(
'span', [
'class' => $class ] + $attribs, $text );
294 public static function wrapClass( $text, $class, $tag =
'span', $attribs = [] ) {
296 return self::tags( $tag, [
'class' => $class ] + $attribs, $text );
309 public static function input( $name, $size =
false, $value =
false, $attribs = [] ) {
310 $attributes = [
'name' => $name ];
313 $attributes[
'size'] = $size;
316 if ( $value !==
false ) {
317 $attributes[
'value'] = $value;
333 public static function password( $name, $size =
false, $value =
false,
339 array_merge( $attribs, [
'type' =>
'password' ] ) );
352 public static function attrib( $name, $present =
true ) {
353 return $present ? [ $name => $name ] : [];
365 public static function check( $name, $checked =
false, $attribs = [] ) {
369 'type' =>
'checkbox',
371 self::attrib(
'checked', $checked ),
385 public static function radio( $name, $value, $checked =
false, $attribs = [] ) {
389 'value' => $value ] + self::attrib(
'checked', $checked ) + $attribs );
404 public static function label( $label, $id, $attribs = [] ) {
405 $a = [
'for' => $id ];
407 foreach ( [
'class',
'title' ] as $attr ) {
408 if ( isset( $attribs[$attr] ) ) {
409 $a[$attr] = $attribs[$attr];
428 public static function inputLabel( $label, $name, $id, $size =
false,
429 $value =
false, $attribs = []
432 return $label .
"\u{00A0}" . $input;
449 $value =
false, $attribs = []
453 self::input( $name, $size, $value, [
'id' => $id ] + $attribs )
469 public static function checkLabel( $label, $name, $id, $checked =
false, $attribs = [] ) {
470 return self::check( $name, $checked, [
'id' => $id ] + $attribs ) .
488 public static function radioLabel( $label, $name, $value, $id,
489 $checked =
false, $attribs = []
491 return self::radio( $name, $value, $checked, [
'id' => $id ] + $attribs ) .
523 public static function option( $text, $value =
null, $selected =
false,
525 if ( $value !==
null ) {
526 $attribs[
'value'] = $value;
529 $attribs[
'selected'] =
'selected';
549 public static function listDropdown( $name =
'', $list =
'', $other =
'',
550 $selected =
'', $class =
'', $tabindex =
null
554 $xmlSelect =
new XmlSelect( $name, $name, $selected );
555 $xmlSelect->addOptions( $options );
558 $xmlSelect->setAttribute(
'class', $class );
561 $xmlSelect->setAttribute(
'tabindex', $tabindex );
564 return $xmlSelect->getHTML();
585 if ( isset( $params[
'other'] ) ) {
586 $options[ $params[
'other'] ] =
'other';
590 foreach ( explode(
"\n", $list ) as $option ) {
591 $value = trim( $option );
592 if ( $value ==
'' ) {
595 if ( substr( $value, 0, 1 ) ==
'*' && substr( $value, 1, 1 ) !=
'*' ) {
596 # A new group is starting...
597 $value = trim( substr( $value, 1 ) );
598 if ( $value !==
'' &&
600 ( !isset( $params[
'other'] ) || $value !== $params[
'other'] )
606 } elseif ( substr( $value, 0, 2 ) ==
'**' ) {
608 $opt = trim( substr( $value, 2 ) );
609 if ( $optgroup ===
false ) {
610 $options[$opt] = $opt;
612 $options[$optgroup][$opt] = $opt;
615 # groupless reason list
617 $options[$option] = $option;
637 foreach ( $options as $text => $value ) {
638 if ( is_array( $value ) ) {
639 $optionsOoui[] = [
'optgroup' => (string)$text ];
640 foreach ( $value as $text2 => $value2 ) {
641 $optionsOoui[] = [
'data' => (string)$value2,
'label' => (
string)$text2 ];
644 $optionsOoui[] = [
'data' => (string)$value,
'label' => (
string)$text ];
663 public static function fieldset( $legend =
false, $content =
false, $attribs = [] ) {
670 if ( $content !==
false ) {
671 $s .= $content .
"\n";
690 public static function textarea( $name, $content, $cols = 40, $rows = 5, $attribs = [] ) {
719 return Html::encodeJsVar( $value, $pretty );
741 return Html::encodeJsCall( $name, $args, $pretty );
755 private static function isWellFormed( $text ) {
756 $parser = xml_parser_create(
"UTF-8" );
758 # case folding violates XML standard, turn it off
759 xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 );
761 if ( !xml_parse( $parser, $text,
true ) ) {
766 xml_parser_free( $parser );
770 xml_parser_free( $parser );
785 Sanitizer::hackDocType() .
790 return self::isWellFormed( $html );
803 [
'"',
'>',
'<' ],
820 public static function buildForm( $fields, $submitLabel =
null, $submitAttribs = [] ) {
822 $form .=
"<table><tbody>";
824 foreach ( $fields as $labelmsg => $input ) {
825 $id =
"mw-$labelmsg";
838 if ( $submitLabel ) {
847 $form .=
"</tbody></table>";
860 public static function buildTable( $rows, $attribs = [], $headers =
null ) {
865 if ( is_array( $headers ) ) {
868 foreach ( $headers as $id =>
$header ) {
871 if ( is_string( $id ) ) {
872 $attribs[
'id'] = $id;
880 foreach ( $rows as $id => $row ) {
883 if ( is_string( $id ) ) {
884 $attribs[
'id'] = $id;
908 foreach ( $cells as $id => $cell ) {
911 if ( is_string( $id ) ) {
912 $attribs[
'id'] = $id;
924class_alias( Xml::class,
'Xml' );
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgLang
A class containing constants representing the names of configuration variables.
const LanguageCode
Name constant for the LanguageCode setting, for use with Config::get()