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 = [] ) {
278 return self::element(
'span', [
'class' => $class ] + $attribs, $text );
292 public static function wrapClass( $text, $class, $tag =
'span', $attribs = [] ) {
294 return self::tags( $tag, [
'class' => $class ] + $attribs, $text );
307 public static function input( $name, $size =
false, $value =
false, $attribs = [] ) {
308 $attributes = [
'name' => $name ];
311 $attributes[
'size'] = $size;
314 if ( $value !==
false ) {
315 $attributes[
'value'] = $value;
331 public static function password( $name, $size =
false, $value =
false,
335 array_merge( $attribs, [
'type' =>
'password' ] ) );
348 public static function attrib( $name, $present =
true ) {
349 return $present ? [ $name => $name ] : [];
361 public static function check( $name, $checked =
false, $attribs = [] ) {
365 'type' =>
'checkbox',
367 self::attrib(
'checked', $checked ),
381 public static function radio( $name, $value, $checked =
false, $attribs = [] ) {
385 'value' => $value ] + self::attrib(
'checked', $checked ) + $attribs );
400 public static function label( $label, $id, $attribs = [] ) {
401 $a = [
'for' => $id ];
403 foreach ( [
'class',
'title' ] as $attr ) {
404 if ( isset( $attribs[$attr] ) ) {
405 $a[$attr] = $attribs[$attr];
424 public static function inputLabel( $label, $name, $id, $size =
false,
425 $value =
false, $attribs = []
428 return $label .
"\u{00A0}" . $input;
445 $value =
false, $attribs = []
449 self::input( $name, $size, $value, [
'id' => $id ] + $attribs )
465 public static function checkLabel( $label, $name, $id, $checked =
false, $attribs = [] ) {
466 return self::check( $name, $checked, [
'id' => $id ] + $attribs ) .
484 public static function radioLabel( $label, $name, $value, $id,
485 $checked =
false, $attribs = []
487 return self::radio( $name, $value, $checked, [
'id' => $id ] + $attribs ) .
519 public static function option( $text, $value =
null, $selected =
false,
521 if ( $value !==
null ) {
522 $attribs[
'value'] = $value;
525 $attribs[
'selected'] =
'selected';
545 public static function listDropdown( $name =
'', $list =
'', $other =
'',
546 $selected =
'', $class =
'', $tabindex =
null
550 $xmlSelect =
new XmlSelect( $name, $name, $selected );
551 $xmlSelect->addOptions( $options );
554 $xmlSelect->setAttribute(
'class', $class );
557 $xmlSelect->setAttribute(
'tabindex', $tabindex );
560 return $xmlSelect->getHTML();
581 if ( isset(
$params[
'other'] ) ) {
582 $options[
$params[
'other'] ] =
'other';
586 foreach ( explode(
"\n", $list ) as $option ) {
587 $value = trim( $option );
588 if ( $value ==
'' ) {
591 if ( substr( $value, 0, 1 ) ==
'*' && substr( $value, 1, 1 ) !=
'*' ) {
592 # A new group is starting...
593 $value = trim( substr( $value, 1 ) );
594 if ( $value !==
'' &&
602 } elseif ( substr( $value, 0, 2 ) ==
'**' ) {
604 $opt = trim( substr( $value, 2 ) );
605 if ( $optgroup ===
false ) {
606 $options[$opt] = $opt;
608 $options[$optgroup][$opt] = $opt;
611 # groupless reason list
613 $options[$option] = $option;
633 foreach ( $options as $text => $value ) {
634 if ( is_array( $value ) ) {
635 $optionsOoui[] = [
'optgroup' => (string)$text ];
636 foreach ( $value as $text2 => $value2 ) {
637 $optionsOoui[] = [
'data' => (string)$value2,
'label' => (
string)$text2 ];
640 $optionsOoui[] = [
'data' => (string)$value,
'label' => (
string)$text ];
659 public static function fieldset( $legend =
false, $content =
false, $attribs = [] ) {
666 if ( $content !==
false ) {
667 $s .= $content .
"\n";
686 public static function textarea( $name, $content, $cols = 40, $rows = 5, $attribs = [] ) {
713 return Html::encodeJsVar( $value, $pretty );
733 return Html::encodeJsCall( $name, $args, $pretty );
747 private static function isWellFormed( $text ) {
748 $parser = xml_parser_create(
"UTF-8" );
750 # case folding violates XML standard, turn it off
751 xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 );
753 if ( !xml_parse( $parser, $text,
true ) ) {
758 xml_parser_free( $parser );
762 xml_parser_free( $parser );
777 Sanitizer::hackDocType() .
782 return self::isWellFormed( $html );
795 [
'"',
'>',
'<' ],
812 public static function buildForm( $fields, $submitLabel =
null, $submitAttribs = [] ) {
814 $form .=
"<table><tbody>";
816 foreach ( $fields as $labelmsg => $input ) {
817 $id =
"mw-$labelmsg";
830 if ( $submitLabel ) {
839 $form .=
"</tbody></table>";
852 public static function buildTable( $rows, $attribs = [], $headers =
null ) {
855 if ( is_array( $headers ) ) {
858 foreach ( $headers as $id =>
$header ) {
861 if ( is_string( $id ) ) {
862 $attribs[
'id'] = $id;
870 foreach ( $rows as $id => $row ) {
873 if ( is_string( $id ) ) {
874 $attribs[
'id'] = $id;
896 foreach ( $cells as $id => $cell ) {
899 if ( is_string( $id ) ) {
900 $attribs[
'id'] = $id;
912class_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
array $params
The job parameters.
A class containing constants representing the names of configuration variables.
const LanguageCode
Name constant for the LanguageCode setting, for use with Config::get()