43 public static function element( $element, $attribs =
null, $contents =
'',
46 $out =
'<' . $element;
47 if ( $attribs !==
null ) {
50 if ( $contents ===
null ) {
52 } elseif ( $allowShortTag && $contents ===
'' ) {
55 $out .=
'>' . htmlspecialchars( $contents, ENT_NOQUOTES ) .
"</$element>";
71 if ( $attribs ===
null ) {
73 } elseif ( is_array( $attribs ) ) {
74 foreach ( $attribs as $name => $val ) {
79 throw new MWException(
'Expected attribute array, got something else in ' . __METHOD__ );
94 public static function elementClean( $element, $attribs = [], $contents =
'' ) {
96 $attribs = array_map( [ UtfNormal\Validator::class,
'cleanUp' ], $attribs );
100 MediaWikiServices::getInstance()->getContentLanguage()->normalize( $contents );
122 return "</$element>";
134 public static function tags( $element, $attribs, $contents ) {
147 public static function monthSelector( $selected =
'', $allmonths =
null, $id =
'month' ) {
151 if ( $selected ===
null ) {
154 $data =
new XmlSelect(
'month', $id, $selected );
156 if ( $allmonths !==
null ) {
157 $options[
wfMessage(
'monthsall' )->text()] = $allmonths;
159 for ( $i = 1; $i < 13; $i++ ) {
160 $options[
$wgLang->getMonthName( $i )] = $i;
162 $data->addOptions( $options );
163 $data->setAttribute(
'class',
'mw-month-selector' );
164 return $data->getHTML();
174 # Offset overrides year/month selection
175 if ( $month && $month !== -1 ) {
176 $encMonth = intval( $month );
181 $encYear = intval( $year );
182 } elseif ( $encMonth ) {
184 $thisMonth = intval( $timestamp->format(
'n' ) );
185 $thisYear = intval( $timestamp->format(
'Y' ) );
186 if ( intval( $encMonth ) > $thisMonth ) {
189 $encYear = $thisYear;
193 $inputAttribs = [
'id' =>
'year',
'maxlength' => 4,
'size' => 7 ];
195 Html::input(
'year', $encYear,
'number', $inputAttribs ) .
' ' .
211 $inLanguage =
null, $overrideAttrs = [],
Message $msg =
null
213 $languageCode = MediaWikiServices::getInstance()->getMainConfig()
214 ->get( MainConfigNames::LanguageCode );
216 $include = $customisedOnly ? LanguageNameUtils::SUPPORTED : LanguageNameUtils::DEFINED;
217 $languages = MediaWikiServices::getInstance()
218 ->getLanguageNameUtils()
219 ->getLanguageNames( $inLanguage, $include );
223 if ( !array_key_exists( $languageCode, $languages ) ) {
224 $languages[$languageCode] = $languageCode;
234 $selected = isset( $languages[$selected] ) ? $selected : $languageCode;
236 foreach ( $languages as $code => $name ) {
237 $options .=
self::option(
"$code - $name", $code, $code == $selected ) .
"\n";
240 $attrs = [
'id' =>
'wpUserLanguage',
'name' =>
'wpUserLanguage' ];
241 $attrs = array_merge( $attrs, $overrideAttrs );
243 if ( $msg ===
null ) {
259 public static function span( $text, $class, $attribs = [] ) {
260 return self::element(
'span', [
'class' => $class ] + $attribs, $text );
271 public static function wrapClass( $text, $class, $tag =
'span', $attribs = [] ) {
272 return self::tags( $tag, [
'class' => $class ] + $attribs, $text );
283 public static function input( $name, $size =
false, $value =
false, $attribs = [] ) {
284 $attributes = [
'name' => $name ];
287 $attributes[
'size'] = $size;
290 if ( $value !==
false ) {
291 $attributes[
'value'] = $value;
306 public static function password( $name, $size =
false, $value =
false,
310 array_merge( $attribs, [
'type' =>
'password' ] ) );
321 public static function attrib( $name, $present =
true ) {
322 return $present ? [ $name => $name ] : [];
332 public static function check( $name, $checked =
false, $attribs = [] ) {
336 'type' =>
'checkbox',
338 self::attrib(
'checked', $checked ),
350 public static function radio( $name, $value, $checked =
false, $attribs = [] ) {
354 'value' => $value ] + self::attrib(
'checked', $checked ) + $attribs );
367 public static function label( $label, $id, $attribs = [] ) {
368 $a = [
'for' => $id ];
370 foreach ( [
'class',
'title' ] as $attr ) {
371 if ( isset( $attribs[$attr] ) ) {
372 $a[$attr] = $attribs[$attr];
389 public static function inputLabel( $label, $name, $id, $size =
false,
390 $value =
false, $attribs = []
392 list( $label, $input ) =
self::inputLabelSep( $label, $name, $id, $size, $value, $attribs );
393 return $label .
"\u{00A0}" . $input;
409 $value =
false, $attribs = []
413 self::input( $name, $size, $value, [
'id' => $id ] + $attribs )
428 public static function checkLabel( $label, $name, $id, $checked =
false, $attribs = [] ) {
429 $useMediaWikiUIEverywhere = MediaWikiServices::getInstance()->getMainConfig()
430 ->get( MainConfigNames::UseMediaWikiUIEverywhere );
431 $chkLabel =
self::check( $name, $checked, [
'id' => $id ] + $attribs ) .
435 if ( $useMediaWikiUIEverywhere ) {
454 public static function radioLabel( $label, $name, $value, $id,
455 $checked =
false, $attribs = []
457 return self::radio( $name, $value, $checked, [
'id' => $id ] + $attribs ) .
470 $useMediaWikiUIEverywhere = MediaWikiServices::getInstance()->getMainConfig()
471 ->get( MainConfigNames::UseMediaWikiUIEverywhere );
479 if ( $useMediaWikiUIEverywhere ) {
480 $baseAttrs[
'class'] =
'mw-ui-button mw-ui-progressive';
483 $attribs += $baseAttrs;
495 public static function option( $text, $value =
null, $selected =
false,
497 if ( $value !==
null ) {
498 $attribs[
'value'] = $value;
501 $attribs[
'selected'] =
'selected';
519 public static function listDropDown( $name =
'', $list =
'', $other =
'',
520 $selected =
'', $class =
'', $tabindex =
null
524 $xmlSelect =
new XmlSelect( $name, $name, $selected );
525 $xmlSelect->addOptions( $options );
528 $xmlSelect->setAttribute(
'class', $class );
531 $xmlSelect->setAttribute(
'tabindex', $tabindex );
534 return $xmlSelect->getHTML();
553 if ( isset( $params[
'other'] ) ) {
554 $options[ $params[
'other'] ] =
'other';
558 foreach ( explode(
"\n", $list ) as $option ) {
559 $value = trim( $option );
560 if ( $value ==
'' ) {
563 if ( substr( $value, 0, 1 ) ==
'*' && substr( $value, 1, 1 ) !=
'*' ) {
564 # A new group is starting...
565 $value = trim( substr( $value, 1 ) );
566 if ( $value !==
'' &&
568 ( !isset( $params[
'other'] ) || $value !== $params[
'other'] )
574 } elseif ( substr( $value, 0, 2 ) ==
'**' ) {
576 $opt = trim( substr( $value, 2 ) );
577 if ( $optgroup ===
false ) {
578 $options[$opt] = $opt;
580 $options[$optgroup][$opt] = $opt;
583 # groupless reason list
585 $options[$option] = $option;
603 foreach ( $options as $text => $value ) {
604 if ( is_array( $value ) ) {
605 $optionsOoui[] = [
'optgroup' => (string)$text ];
606 foreach ( $value as $text2 => $value2 ) {
607 $optionsOoui[] = [
'data' => (string)$value2,
'label' => (
string)$text2 ];
610 $optionsOoui[] = [
'data' => (string)$value,
'label' => (
string)$text ];
680 return $value->value;
697 foreach (
$args as &$arg ) {
699 if ( $arg ===
false ) {
704 return "$name(" . ( $pretty
705 ? (
' ' . implode(
', ',
$args ) .
' ' )
706 : implode(
',',
$args )
722 $parser = xml_parser_create(
"UTF-8" );
724 # case folding violates XML standard, turn it off
725 xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 );
727 if ( !xml_parse( $parser, $text,
true ) ) {
732 xml_parser_free( $parser );
736 xml_parser_free( $parser );
769 [
'"',
'>',
'<' ],
784 public static function buildForm( $fields, $submitLabel =
null, $submitAttribs = [] ) {
786 $form .=
"<table><tbody>";
788 foreach ( $fields as $labelmsg => $input ) {
789 $id =
"mw-$labelmsg";
802 if ( $submitLabel ) {
811 $form .=
"</tbody></table>";
822 public static function buildTable( $rows, $attribs = [], $headers =
null ) {
825 if ( is_array( $headers ) ) {
828 foreach ( $headers as $id =>
$header ) {
831 if ( is_string( $id ) ) {
832 $attribs[
'id'] = $id;
840 foreach ( $rows as $id => $row ) {
843 if ( is_string( $id ) ) {
844 $attribs[
'id'] = $id;
864 foreach ( $cells as $id => $cell ) {
867 if ( is_string( $id ) ) {
868 $attribs[
'id'] = $id;
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode) $wgLang
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
static input( $name, $value='', $type='text', array $attribs=[])
Convenience function to produce an "<input>" element.
static getTextInputAttributes(array $attrs)
Modifies a set of attributes meant for text input elements and apply a set of default attributes.
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 isWellFormed( $text)
Check if a string is well-formed XML.
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 expandAttributes( $attribs)
Given an array of ('attributename' => 'value'), it generates the code to set the XML attributes : att...
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 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(...
foreach( $mmfl['setupFiles'] as $fileName) if( $queue) if(empty( $mmfl['quiet'])) $s