44 public static function element( $element, $attribs =
null, $contents =
'',
47 $out =
'<' . $element;
48 if ( $attribs !==
null ) {
51 if ( $contents ===
null ) {
53 } elseif ( $allowShortTag && $contents ===
'' ) {
56 $out .=
'>' . htmlspecialchars( $contents, ENT_NOQUOTES ) .
"</$element>";
70 if ( $attribs ===
null ) {
74 foreach ( $attribs as $name => $val ) {
91 public static function elementClean( $element, $attribs = [], $contents =
'' ) {
93 $attribs = array_map( [ UtfNormal\Validator::class,
'cleanUp' ], $attribs );
97 MediaWikiServices::getInstance()->getContentLanguage()->normalize( $contents );
119 return "</$element>";
131 public static function tags( $element, $attribs, $contents ) {
144 public static function monthSelector( $selected =
'', $allmonths =
null, $id =
'month' ) {
148 $data =
new XmlSelect(
'month', $id, $selected ??
'' );
150 if ( $allmonths !==
null ) {
151 $options[
wfMessage(
'monthsall' )->text()] = $allmonths;
153 for ( $i = 1; $i < 13; $i++ ) {
154 $options[
$wgLang->getMonthName( $i )] = $i;
156 $data->addOptions( $options );
157 $data->setAttribute(
'class',
'mw-month-selector' );
158 return $data->getHTML();
168 # Offset overrides year/month selection
169 if ( $month && $month !== -1 ) {
170 $encMonth = intval( $month );
175 $encYear = intval( $year );
176 } elseif ( $encMonth ) {
178 $thisMonth = intval( $timestamp->format(
'n' ) );
179 $thisYear = intval( $timestamp->format(
'Y' ) );
180 if ( $encMonth > $thisMonth ) {
183 $encYear = $thisYear;
187 $inputAttribs = [
'id' =>
'year',
'maxlength' => 4,
'size' => 7 ];
189 Html::input(
'year', $encYear,
'number', $inputAttribs ) .
' ' .
205 $inLanguage =
null, $overrideAttrs = [],
Message $msg =
null
207 $languageCode = MediaWikiServices::getInstance()->getMainConfig()
208 ->get( MainConfigNames::LanguageCode );
210 $include = $customisedOnly ? LanguageNameUtils::SUPPORTED : LanguageNameUtils::DEFINED;
211 $languages = MediaWikiServices::getInstance()
212 ->getLanguageNameUtils()
213 ->getLanguageNames( $inLanguage, $include );
217 if ( !array_key_exists( $languageCode, $languages ) ) {
218 $languages[$languageCode] = $languageCode;
228 $selected = isset( $languages[$selected] ) ? $selected : $languageCode;
230 foreach ( $languages as $code => $name ) {
231 $options .=
self::option(
"$code - $name", $code, $code == $selected ) .
"\n";
234 $attrs = [
'id' =>
'wpUserLanguage',
'name' =>
'wpUserLanguage' ];
235 $attrs = array_merge( $attrs, $overrideAttrs );
237 if ( $msg ===
null ) {
253 public static function span( $text, $class, $attribs = [] ) {
254 return self::element(
'span', [
'class' => $class ] + $attribs, $text );
265 public static function wrapClass( $text, $class, $tag =
'span', $attribs = [] ) {
266 return self::tags( $tag, [
'class' => $class ] + $attribs, $text );
277 public static function input( $name, $size =
false, $value =
false, $attribs = [] ) {
278 $attributes = [
'name' => $name ];
281 $attributes[
'size'] = $size;
284 if ( $value !==
false ) {
285 $attributes[
'value'] = $value;
289 Html::getTextInputAttributes( $attributes + $attribs ) );
300 public static function password( $name, $size =
false, $value =
false,
304 array_merge( $attribs, [
'type' =>
'password' ] ) );
315 public static function attrib( $name, $present =
true ) {
316 return $present ? [ $name => $name ] : [];
326 public static function check( $name, $checked =
false, $attribs = [] ) {
330 'type' =>
'checkbox',
332 self::attrib(
'checked', $checked ),
344 public static function radio( $name, $value, $checked =
false, $attribs = [] ) {
348 'value' => $value ] + self::attrib(
'checked', $checked ) + $attribs );
361 public static function label( $label, $id, $attribs = [] ) {
362 $a = [
'for' => $id ];
364 foreach ( [
'class',
'title' ] as $attr ) {
365 if ( isset( $attribs[$attr] ) ) {
366 $a[$attr] = $attribs[$attr];
383 public static function inputLabel( $label, $name, $id, $size =
false,
384 $value =
false, $attribs = []
387 return $label .
"\u{00A0}" . $input;
403 $value =
false, $attribs = []
407 self::input( $name, $size, $value, [
'id' => $id ] + $attribs )
422 public static function checkLabel( $label, $name, $id, $checked =
false, $attribs = [] ) {
423 $useMediaWikiUIEverywhere = MediaWikiServices::getInstance()->getMainConfig()
424 ->get( MainConfigNames::UseMediaWikiUIEverywhere );
425 $chkLabel =
self::check( $name, $checked, [
'id' => $id ] + $attribs ) .
429 if ( $useMediaWikiUIEverywhere ) {
448 public static function radioLabel( $label, $name, $value, $id,
449 $checked =
false, $attribs = []
451 return self::radio( $name, $value, $checked, [
'id' => $id ] + $attribs ) .
464 $useMediaWikiUIEverywhere = MediaWikiServices::getInstance()->getMainConfig()
465 ->get( MainConfigNames::UseMediaWikiUIEverywhere );
473 if ( $useMediaWikiUIEverywhere ) {
474 $baseAttrs[
'class'] =
'mw-ui-button mw-ui-progressive';
477 $attribs += $baseAttrs;
478 return Html::element(
'input', $attribs );
489 public static function option( $text, $value =
null, $selected =
false,
491 if ( $value !==
null ) {
492 $attribs[
'value'] = $value;
495 $attribs[
'selected'] =
'selected';
497 return Html::element(
'option', $attribs, $text );
513 public static function listDropDown( $name =
'', $list =
'', $other =
'',
514 $selected =
'', $class =
'', $tabindex =
null
518 $xmlSelect =
new XmlSelect( $name, $name, $selected );
519 $xmlSelect->addOptions( $options );
522 $xmlSelect->setAttribute(
'class', $class );
525 $xmlSelect->setAttribute(
'tabindex', $tabindex );
528 return $xmlSelect->getHTML();
547 if ( isset( $params[
'other'] ) ) {
548 $options[ $params[
'other'] ] =
'other';
552 foreach ( explode(
"\n", $list ) as $option ) {
553 $value = trim( $option );
554 if ( $value ==
'' ) {
557 if ( substr( $value, 0, 1 ) ==
'*' && substr( $value, 1, 1 ) !=
'*' ) {
558 # A new group is starting...
559 $value = trim( substr( $value, 1 ) );
560 if ( $value !==
'' &&
562 ( !isset( $params[
'other'] ) || $value !== $params[
'other'] )
568 } elseif ( substr( $value, 0, 2 ) ==
'**' ) {
570 $opt = trim( substr( $value, 2 ) );
571 if ( $optgroup ===
false ) {
572 $options[$opt] = $opt;
574 $options[$optgroup][$opt] = $opt;
577 # groupless reason list
579 $options[$option] = $option;
597 foreach ( $options as $text => $value ) {
598 if ( is_array( $value ) ) {
599 $optionsOoui[] = [
'optgroup' => (string)$text ];
600 foreach ( $value as $text2 => $value2 ) {
601 $optionsOoui[] = [
'data' => (string)$value2,
'label' => (
string)$text2 ];
604 $optionsOoui[] = [
'data' => (string)$value,
'label' => (
string)$text ];
650 Html::getTextInputAttributes(
674 return $value->value;
691 foreach ( $args as &$arg ) {
693 if ( $arg ===
false ) {
698 return "$name(" . ( $pretty
699 ? (
' ' . implode(
', ', $args ) .
' ' )
700 : implode(
',', $args )
715 private static function isWellFormed( $text ) {
716 $parser = xml_parser_create(
"UTF-8" );
718 # case folding violates XML standard, turn it off
719 xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 );
721 if ( !xml_parse( $parser, $text,
true ) ) {
726 xml_parser_free( $parser );
730 xml_parser_free( $parser );
750 return self::isWellFormed( $html );
763 [
'"',
'>',
'<' ],
778 public static function buildForm( $fields, $submitLabel =
null, $submitAttribs = [] ) {
780 $form .=
"<table><tbody>";
782 foreach ( $fields as $labelmsg => $input ) {
783 $id =
"mw-$labelmsg";
796 if ( $submitLabel ) {
805 $form .=
"</tbody></table>";
816 public static function buildTable( $rows, $attribs = [], $headers =
null ) {
819 if ( is_array( $headers ) ) {
822 foreach ( $headers as $id =>
$header ) {
825 if ( is_string( $id ) ) {
826 $attribs[
'id'] = $id;
834 foreach ( $rows as $id => $row ) {
837 if ( is_string( $id ) ) {
838 $attribs[
'id'] = $id;
858 foreach ( $cells as $id => $cell ) {
861 if ( is_string( $id ) ) {
862 $attribs[
'id'] = $id;
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode) $wgLang
static getInstance( $ts=false)
Get a timestamp instance in GMT.
A class containing constants representing the names of configuration variables.
The Message class deals with fetching and processing of interface message into a variety of formats.
static encodeAttribute( $text)
Encode an attribute value for HTML output.
static hackDocType()
Hack up a private DOCTYPE with HTML's standard entity declarations.
A wrapper class which causes Xml::encodeJsVar() and Xml::encodeJsCall() to interpret a given string a...
Class for generating HTML <select> or <datalist> elements.
Module of static functions for generating XML.
static password( $name, $size=false, $value=false, $attribs=[])
Convenience function to build an HTML password input field.
static closeElement( $element)
Shortcut to close an XML element.
static textarea( $name, $content, $cols=40, $rows=5, $attribs=[])
Shortcut for creating textareas.
static inputLabelSep( $label, $name, $id, $size=false, $value=false, $attribs=[])
Same as Xml::inputLabel() but return input and label in an array.
static listDropDownOptions( $list, $params=[])
Build options for a drop-down box from a textual list.
static encodeJsVar( $value, $pretty=false)
Encode a variable of arbitrary type to JavaScript.
static listDropDownOptionsOoui( $options)
Convert options for a drop-down box into a format accepted by OOUI\DropdownInputWidget etc.
static isWellFormedXmlFragment( $text)
Check if a string is a well-formed XML fragment.
static check( $name, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox.
static dateMenu( $year, $month)
static buildForm( $fields, $submitLabel=null, $submitAttribs=[])
Generate a form (without the opening form element).
static attrib( $name, $present=true)
Internal function for use in checkboxes and radio buttons and such.
static label( $label, $id, $attribs=[])
Convenience function to build an HTML form label.
static openElement( $element, $attribs=null)
This opens an XML element.
static input( $name, $size=false, $value=false, $attribs=[])
Convenience function to build an HTML text input field.
static wrapClass( $text, $class, $tag='span', $attribs=[])
Shortcut to make a specific element with a class attribute.
static buildTable( $rows, $attribs=[], $headers=null)
static submitButton( $value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
static option( $text, $value=null, $selected=false, $attribs=[])
Convenience function to build an HTML drop-down list item.
static checkLabel( $label, $name, $id, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox with a label.
static inputLabel( $label, $name, $id, $size=false, $value=false, $attribs=[])
Convenience function to build an HTML text input field with a label.
static languageSelector( $selected, $customisedOnly=true, $inLanguage=null, $overrideAttrs=[], Message $msg=null)
Construct a language selector appropriate for use in a form or preferences.
static span( $text, $class, $attribs=[])
Shortcut to make a span element.
static escapeTagsOnly( $in)
Replace " > and < with their respective HTML entities ( ", >, <)
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
static radio( $name, $value, $checked=false, $attribs=[])
Convenience function to build an HTML radio button.
static buildTableRow( $attribs, $cells)
Build a row for a table.
static radioLabel( $label, $name, $value, $id, $checked=false, $attribs=[])
Convenience function to build an HTML radio button with a label.
static encodeJsCall( $name, $args, $pretty=false)
Create a call to a JavaScript function.
static listDropDown( $name='', $list='', $other='', $selected='', $class='', $tabindex=null)
Build a drop-down box from a textual list.
static expandAttributes(?array $attribs)
Given an array of ('attributename' => 'value'), it generates the code to set the XML attributes : att...
static monthSelector( $selected='', $allmonths=null, $id='month')
Create a date selector.
static fieldset( $legend=false, $content=false, $attribs=[])
Shortcut for creating fieldsets.
static elementClean( $element, $attribs=[], $contents='')
Format an XML element as with self::element(), but run text through the content language's normalize(...