14use UtfNormal\Validator;
36 public static function element( $element, $attribs =
null, $contents =
'',
39 $out =
'<' . $element;
40 if ( $attribs !==
null ) {
43 if ( $contents ===
null ) {
45 } elseif ( $allowShortTag && $contents ===
'' ) {
49 $out .=
'>' . htmlspecialchars( $contents, ENT_NOQUOTES ) .
"</$element>";
63 if ( $attribs ===
null ) {
67 foreach ( $attribs as $name => $val ) {
68 $out .=
" {$name}=\"" . Sanitizer::encodeAttribute( $val ) .
'"';
84 public static function elementClean( $element, $attribs = [], $contents =
'' ) {
86 $attribs = array_map( Validator::cleanUp( ... ), $attribs );
112 return "</$element>";
128 public static function tags( $element, $attribs, $contents ) {
142 public static function attrib( $name, $present =
true ) {
143 return $present ? [ $name => $name ] : [];
158 public static function label( $label, $id, $attribs = [] ) {
159 $a = [
'for' => $id ];
161 foreach ( [
'class',
'title' ] as $attr ) {
162 if ( isset( $attribs[$attr] ) ) {
163 $a[$attr] = $attribs[$attr];
180 public static function option( $text, $value =
null, $selected =
false,
182 if ( $value !==
null ) {
183 $attribs[
'value'] = $value;
186 $attribs[
'selected'] =
'selected';
206 public static function listDropdown( $name =
'', $list =
'', $other =
'',
207 $selected =
'', $class =
'', $tabindex =
null
211 $xmlSelect =
new XmlSelect( $name, $name, $selected );
212 $xmlSelect->addOptions( $options );
215 $xmlSelect->setAttribute(
'class', $class );
218 $xmlSelect->setAttribute(
'tabindex', $tabindex );
221 return $xmlSelect->getHTML();
242 if ( isset( $params[
'other'] ) ) {
243 $options[ $params[
'other'] ] =
'other';
247 foreach ( explode(
"\n", $list ) as $option ) {
248 $value = trim( $option );
249 if ( $value ==
'' ) {
252 if ( str_starts_with( $value,
'*' ) && substr( $value, 1, 1 ) !=
'*' ) {
253 # A new group is starting...
254 $value = trim( substr( $value, 1 ) );
255 if ( $value !==
'' &&
257 ( !isset( $params[
'other'] ) || $value !== $params[
'other'] )
263 } elseif ( str_starts_with( $value,
'**' ) ) {
265 $opt = trim( substr( $value, 2 ) );
266 if ( $optgroup ===
false ) {
267 $options[$opt] = $opt;
269 $options[$optgroup][$opt] = $opt;
272 # groupless reason list
274 $options[$option] = $option;
294 foreach ( $options as $text => $value ) {
295 if ( is_array( $value ) ) {
296 $optionsOoui[] = [
'optgroup' => (string)$text ];
297 foreach ( $value as $text2 => $value2 ) {
298 $optionsOoui[] = [
'data' => (string)$value2,
'label' => (
string)$text2 ];
301 $optionsOoui[] = [
'data' => (string)$value,
'label' => (
string)$text ];
320 public static function fieldset( $legend =
false, $content =
false, $attribs = [] ) {
327 if ( $content !==
false ) {
328 $s .= $content .
"\n";
346 private static function isWellFormed( $text ) {
347 $parser = xml_parser_create(
"UTF-8" );
349 # case folding violates XML standard, turn it off
350 xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 );
352 if ( !xml_parse( $parser, $text,
true ) ) {
368 Sanitizer::hackDocType() .
373 return self::isWellFormed( $html );
386 [
'"',
'>',
'<' ],
403 public static function buildForm( $fields, $submitLabel =
null, $submitAttribs = [] ) {
405 $form .=
"<table><tbody>";
407 foreach ( $fields as $labelmsg => $input ) {
408 $id =
"mw-$labelmsg";
421 if ( $submitLabel ) {
429 'value' =>
wfMessage( $submitLabel )->text(),
436 $form .=
"</tbody></table>";
442class_alias( Xml::class,
'Xml' );
wfMessage( $key,... $params)
This is the function for getting translated interface messages.