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 ) {
145 return $present ? [ $name => $name ] : [];
160 public static function label( $label, $id, $attribs = [] ) {
163 $a = [
'for' => $id ];
165 foreach ( [
'class',
'title' ] as $attr ) {
166 if ( isset( $attribs[$attr] ) ) {
167 $a[$attr] = $attribs[$attr];
184 public static function option( $text, $value =
null, $selected =
false,
188 if ( $value !==
null ) {
189 $attribs[
'value'] = $value;
192 $attribs[
'selected'] =
'selected';
212 public static function listDropdown( $name =
'', $list =
'', $other =
'',
213 $selected =
'', $class =
'', $tabindex =
null
219 $xmlSelect =
new XmlSelect( $name, $name, $selected );
220 $xmlSelect->addOptions( $options );
223 $xmlSelect->setAttribute(
'class', $class );
226 $xmlSelect->setAttribute(
'tabindex', $tabindex );
229 return $xmlSelect->getHTML();
252 if ( isset( $params[
'other'] ) ) {
253 $options[ $params[
'other'] ] =
'other';
257 foreach ( explode(
"\n", $list ) as $option ) {
258 $value = trim( $option );
259 if ( $value ==
'' ) {
262 if ( str_starts_with( $value,
'*' ) && substr( $value, 1, 1 ) !=
'*' ) {
263 # A new group is starting...
264 $value = trim( substr( $value, 1 ) );
265 if ( $value !==
'' &&
267 ( !isset( $params[
'other'] ) || $value !== $params[
'other'] )
273 } elseif ( str_starts_with( $value,
'**' ) ) {
275 $opt = trim( substr( $value, 2 ) );
276 if ( $optgroup ===
false ) {
277 $options[$opt] = $opt;
279 $options[$optgroup][$opt] = $opt;
282 # groupless reason list
284 $options[$option] = $option;
306 foreach ( $options as $text => $value ) {
307 if ( is_array( $value ) ) {
308 $optionsOoui[] = [
'optgroup' => (string)$text ];
309 foreach ( $value as $text2 => $value2 ) {
310 $optionsOoui[] = [
'data' => (string)$value2,
'label' => (
string)$text2 ];
313 $optionsOoui[] = [
'data' => (string)$value,
'label' => (
string)$text ];
332 public static function fieldset( $legend =
false, $content =
false, $attribs = [] ) {
341 if ( $content !==
false ) {
342 $s .= $content .
"\n";
360 private static function isWellFormed( $text ) {
361 $parser = xml_parser_create(
"UTF-8" );
363 # case folding violates XML standard, turn it off
364 xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 );
366 if ( !xml_parse( $parser, $text,
true ) ) {
382 Sanitizer::hackDocType() .
387 return self::isWellFormed( $html );
400 [
'"',
'>',
'<' ],
417 public static function buildForm( $fields, $submitLabel =
null, $submitAttribs = [] ) {
421 $form .=
"<table><tbody>";
423 foreach ( $fields as $labelmsg => $input ) {
424 $id =
"mw-$labelmsg";
432 $form .=
self::tags(
'td', [
'class' =>
'mw-input' ], $input );
436 if ( $submitLabel ) {
444 'value' =>
wfMessage( $submitLabel )->text(),
451 $form .=
"</tbody></table>";
457class_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.