MediaWiki REL1_37
Html.php
Go to the documentation of this file.
1<?php
26
49class Html {
51 private static $voidElements = [
52 'area' => true,
53 'base' => true,
54 'br' => true,
55 'col' => true,
56 'embed' => true,
57 'hr' => true,
58 'img' => true,
59 'input' => true,
60 'keygen' => true,
61 'link' => true,
62 'meta' => true,
63 'param' => true,
64 'source' => true,
65 'track' => true,
66 'wbr' => true,
67 ];
68
74 private static $boolAttribs = [
75 'async' => true,
76 'autofocus' => true,
77 'autoplay' => true,
78 'checked' => true,
79 'controls' => true,
80 'default' => true,
81 'defer' => true,
82 'disabled' => true,
83 'formnovalidate' => true,
84 'hidden' => true,
85 'ismap' => true,
86 'itemscope' => true,
87 'loop' => true,
88 'multiple' => true,
89 'muted' => true,
90 'novalidate' => true,
91 'open' => true,
92 'pubdate' => true,
93 'readonly' => true,
94 'required' => true,
95 'reversed' => true,
96 'scoped' => true,
97 'seamless' => true,
98 'selected' => true,
99 'truespeed' => true,
100 'typemustmatch' => true,
101 ];
102
111 public static function buttonAttributes( array $attrs, array $modifiers = [] ) {
114 if ( isset( $attrs['class'] ) ) {
115 if ( is_array( $attrs['class'] ) ) {
116 $attrs['class'][] = 'mw-ui-button';
117 $attrs['class'] = array_merge( $attrs['class'], $modifiers );
118 // ensure compatibility with Xml
119 $attrs['class'] = implode( ' ', $attrs['class'] );
120 } else {
121 $attrs['class'] .= ' mw-ui-button ' . implode( ' ', $modifiers );
122 }
123 } else {
124 // ensure compatibility with Xml
125 $attrs['class'] = 'mw-ui-button ' . implode( ' ', $modifiers );
126 }
127 }
128 return $attrs;
129 }
130
138 public static function getTextInputAttributes( array $attrs ) {
141 if ( isset( $attrs['class'] ) ) {
142 if ( is_array( $attrs['class'] ) ) {
143 $attrs['class'][] = 'mw-ui-input';
144 } else {
145 $attrs['class'] .= ' mw-ui-input';
146 }
147 } else {
148 $attrs['class'] = 'mw-ui-input';
149 }
150 }
151 return $attrs;
152 }
153
166 public static function linkButton( $text, array $attrs, array $modifiers = [] ) {
167 return self::element( 'a',
168 self::buttonAttributes( $attrs, $modifiers ),
169 $text
170 );
171 }
172
186 public static function submitButton( $contents, array $attrs, array $modifiers = [] ) {
187 $attrs['type'] = 'submit';
188 $attrs['value'] = $contents;
189 return self::element( 'input', self::buttonAttributes( $attrs, $modifiers ) );
190 }
191
210 public static function rawElement( $element, $attribs = [], $contents = '' ) {
211 $start = self::openElement( $element, $attribs );
212 if ( isset( self::$voidElements[$element] ) ) {
213 // Silly XML.
214 return substr( $start, 0, -1 ) . '/>';
215 } else {
216 return $start . $contents . self::closeElement( $element );
217 }
218 }
219
232 public static function element( $element, $attribs = [], $contents = '' ) {
233 return self::rawElement( $element, $attribs, strtr( $contents ?? '', [
234 // There's no point in escaping quotes, >, etc. in the contents of
235 // elements.
236 '&' => '&amp;',
237 '<' => '&lt;'
238 ] ) );
239 }
240
252 public static function openElement( $element, $attribs = [] ) {
253 $attribs = (array)$attribs;
254 // This is not required in HTML5, but let's do it anyway, for
255 // consistency and better compression.
256 $element = strtolower( $element );
257
258 // Some people were abusing this by passing things like
259 // 'h1 id="foo" to $element, which we don't want.
260 if ( strpos( $element, ' ' ) !== false ) {
261 wfWarn( __METHOD__ . " given element name with space '$element'" );
262 }
263
264 // Remove invalid input types
265 if ( $element == 'input' ) {
266 $validTypes = [
267 'hidden' => true,
268 'text' => true,
269 'password' => true,
270 'checkbox' => true,
271 'radio' => true,
272 'file' => true,
273 'submit' => true,
274 'image' => true,
275 'reset' => true,
276 'button' => true,
277
278 // HTML input types
279 'datetime' => true,
280 'datetime-local' => true,
281 'date' => true,
282 'month' => true,
283 'time' => true,
284 'week' => true,
285 'number' => true,
286 'range' => true,
287 'email' => true,
288 'url' => true,
289 'search' => true,
290 'tel' => true,
291 'color' => true,
292 ];
293 if ( isset( $attribs['type'] ) && !isset( $validTypes[$attribs['type']] ) ) {
294 unset( $attribs['type'] );
295 }
296 }
297
298 // According to standard the default type for <button> elements is "submit".
299 // Depending on compatibility mode IE might use "button", instead.
300 // We enforce the standard "submit".
301 if ( $element == 'button' && !isset( $attribs['type'] ) ) {
302 $attribs['type'] = 'submit';
303 }
304
305 return "<$element" . self::expandAttributes(
306 self::dropDefaults( $element, $attribs ) ) . '>';
307 }
308
316 public static function closeElement( $element ) {
317 $element = strtolower( $element );
318
319 return "</$element>";
320 }
321
339 private static function dropDefaults( $element, array $attribs ) {
340 // Whenever altering this array, please provide a covering test case
341 // in HtmlTest::provideElementsWithAttributesHavingDefaultValues
342 static $attribDefaults = [
343 'area' => [ 'shape' => 'rect' ],
344 'button' => [
345 'formaction' => 'GET',
346 'formenctype' => 'application/x-www-form-urlencoded',
347 ],
348 'canvas' => [
349 'height' => '150',
350 'width' => '300',
351 ],
352 'form' => [
353 'action' => 'GET',
354 'autocomplete' => 'on',
355 'enctype' => 'application/x-www-form-urlencoded',
356 ],
357 'input' => [
358 'formaction' => 'GET',
359 'type' => 'text',
360 ],
361 'keygen' => [ 'keytype' => 'rsa' ],
362 'link' => [ 'media' => 'all' ],
363 'menu' => [ 'type' => 'list' ],
364 'script' => [ 'type' => 'text/javascript' ],
365 'style' => [
366 'media' => 'all',
367 'type' => 'text/css',
368 ],
369 'textarea' => [ 'wrap' => 'soft' ],
370 ];
371
372 foreach ( $attribs as $attrib => $value ) {
373 if ( $attrib === 'class' ) {
374 if ( $value === '' || $value === [] || $value === [ '' ] ) {
375 unset( $attribs[$attrib] );
376 }
377 } elseif ( isset( $attribDefaults[$element][$attrib] ) ) {
378 if ( is_array( $value ) ) {
379 $value = implode( ' ', $value );
380 } else {
381 $value = strval( $value );
382 }
383 if ( $attribDefaults[$element][$attrib] == $value ) {
384 unset( $attribs[$attrib] );
385 }
386 }
387 }
388
389 // More subtle checks
390 if ( $element === 'link'
391 && isset( $attribs['type'] ) && strval( $attribs['type'] ) == 'text/css'
392 ) {
393 unset( $attribs['type'] );
394 }
395 if ( $element === 'input' ) {
396 $type = $attribs['type'] ?? null;
397 $value = $attribs['value'] ?? null;
398 if ( $type === 'checkbox' || $type === 'radio' ) {
399 // The default value for checkboxes and radio buttons is 'on'
400 // not ''. By stripping value="" we break radio boxes that
401 // actually wants empty values.
402 if ( $value === 'on' ) {
403 unset( $attribs['value'] );
404 }
405 } elseif ( $type === 'submit' ) {
406 // The default value for submit appears to be "Submit" but
407 // let's not bother stripping out localized text that matches
408 // that.
409 } else {
410 // The default value for nearly every other field type is ''
411 // The 'range' and 'color' types use different defaults but
412 // stripping a value="" does not hurt them.
413 if ( $value === '' ) {
414 unset( $attribs['value'] );
415 }
416 }
417 }
418 if ( $element === 'select' && isset( $attribs['size'] ) ) {
419 if ( in_array( 'multiple', $attribs )
420 || ( isset( $attribs['multiple'] ) && $attribs['multiple'] !== false )
421 ) {
422 // A multi-select
423 if ( strval( $attribs['size'] ) == '4' ) {
424 unset( $attribs['size'] );
425 }
426 } else {
427 // Single select
428 if ( strval( $attribs['size'] ) == '1' ) {
429 unset( $attribs['size'] );
430 }
431 }
432 }
433
434 return $attribs;
435 }
436
476 public static function expandAttributes( array $attribs ) {
477 $ret = '';
478 foreach ( $attribs as $key => $value ) {
479 // Support intuitive [ 'checked' => true/false ] form
480 if ( $value === false || $value === null ) {
481 continue;
482 }
483
484 // For boolean attributes, support [ 'foo' ] instead of
485 // requiring [ 'foo' => 'meaningless' ].
486 if ( is_int( $key ) && isset( self::$boolAttribs[strtolower( $value )] ) ) {
487 $key = $value;
488 }
489
490 // Not technically required in HTML5 but we'd like consistency
491 // and better compression anyway.
492 $key = strtolower( $key );
493
494 // https://www.w3.org/TR/html401/index/attributes.html ("space-separated")
495 // https://www.w3.org/TR/html5/index.html#attributes-1 ("space-separated")
496 $spaceSeparatedListAttributes = [
497 'class' => true, // html4, html5
498 'accesskey' => true, // as of html5, multiple space-separated values allowed
499 // html4-spec doesn't document rel= as space-separated
500 // but has been used like that and is now documented as such
501 // in the html5-spec.
502 'rel' => true,
503 ];
504
505 // Specific features for attributes that allow a list of space-separated values
506 if ( isset( $spaceSeparatedListAttributes[$key] ) ) {
507 // Apply some normalization and remove duplicates
508
509 // Convert into correct array. Array can contain space-separated
510 // values. Implode/explode to get those into the main array as well.
511 if ( is_array( $value ) ) {
512 // If input wasn't an array, we can skip this step
513 $arrayValue = [];
514 foreach ( $value as $k => $v ) {
515 if ( is_string( $v ) ) {
516 // String values should be normal `[ 'foo' ]`
517 // Just append them
518 if ( !isset( $value[$v] ) ) {
519 // As a special case don't set 'foo' if a
520 // separate 'foo' => true/false exists in the array
521 // keys should be authoritative
522 foreach ( explode( ' ', $v ) as $part ) {
523 // Normalize spacing by fixing up cases where people used
524 // more than 1 space and/or a trailing/leading space
525 if ( $part !== '' && $part !== ' ' ) {
526 $arrayValue[] = $part;
527 }
528 }
529 }
530 } elseif ( $v ) {
531 // If the value is truthy but not a string this is likely
532 // an [ 'foo' => true ], falsy values don't add strings
533 $arrayValue[] = $k;
534 }
535 }
536 } else {
537 $arrayValue = explode( ' ', $value );
538 // Normalize spacing by fixing up cases where people used
539 // more than 1 space and/or a trailing/leading space
540 $arrayValue = array_diff( $arrayValue, [ '', ' ' ] );
541 }
542
543 // Remove duplicates and create the string
544 $value = implode( ' ', array_unique( $arrayValue ) );
545
546 // Optimization: Skip below boolAttribs check and jump straight
547 // to its `else` block. The current $spaceSeparatedListAttributes
548 // block is mutually exclusive with $boolAttribs.
549 // phpcs:ignore Generic.PHP.DiscourageGoto
550 goto not_bool; // NOSONAR
551 } elseif ( is_array( $value ) ) {
552 throw new MWException( "HTML attribute $key can not contain a list of values" );
553 }
554
555 if ( isset( self::$boolAttribs[$key] ) ) {
556 $ret .= " $key=\"\"";
557 } else {
558 // phpcs:ignore Generic.PHP.DiscourageGoto
559 not_bool:
560 // Inlined from Sanitizer::encodeAttribute() for improved performance
561 $encValue = htmlspecialchars( $value, ENT_QUOTES );
562 // Whitespace is normalized during attribute decoding,
563 // so if we've been passed non-spaces we must encode them
564 // ahead of time or they won't be preserved.
565 $encValue = strtr( $encValue, [
566 "\n" => '&#10;',
567 "\r" => '&#13;',
568 "\t" => '&#9;',
569 ] );
570 $ret .= " $key=\"$encValue\"";
571 }
572 }
573 return $ret;
574 }
575
589 public static function inlineScript( $contents, $nonce = null ) {
590 $attrs = [];
591 if ( $nonce !== null ) {
592 $attrs['nonce'] = $nonce;
593 } elseif ( ContentSecurityPolicy::isNonceRequired( RequestContext::getMain()->getConfig() ) ) {
594 wfWarn( "no nonce set on script. CSP will break it" );
595 }
596
597 if ( preg_match( '/<\/?script/i', $contents ) ) {
598 wfLogWarning( __METHOD__ . ': Illegal character sequence found in inline script.' );
599 $contents = '/* ERROR: Invalid script */';
600 }
601
602 return self::rawElement( 'script', $attrs, $contents );
603 }
604
613 public static function linkedScript( $url, $nonce = null ) {
614 $attrs = [ 'src' => $url ];
615 if ( $nonce !== null ) {
616 $attrs['nonce'] = $nonce;
617 } elseif ( ContentSecurityPolicy::isNonceRequired( RequestContext::getMain()->getConfig() ) ) {
618 wfWarn( "no nonce set on script. CSP will break it" );
619 }
620
621 return self::element( 'script', $attrs );
622 }
623
636 public static function inlineStyle( $contents, $media = 'all', $attribs = [] ) {
637 // Don't escape '>' since that is used
638 // as direct child selector.
639 // Remember, in css, there is no "x" for hexadecimal escapes, and
640 // the space immediately after an escape sequence is swallowed.
641 $contents = strtr( $contents, [
642 '<' => '\3C ',
643 // CDATA end tag for good measure, but the main security
644 // is from escaping the '<'.
645 ']]>' => '\5D\5D\3E '
646 ] );
647
648 if ( preg_match( '/[<&]/', $contents ) ) {
649 $contents = "/*<![CDATA[*/$contents/*]]>*/";
650 }
651
652 return self::rawElement( 'style', [
653 'media' => $media,
654 ] + $attribs, $contents );
655 }
656
665 public static function linkedStyle( $url, $media = 'all' ) {
666 return self::element( 'link', [
667 'rel' => 'stylesheet',
668 'href' => $url,
669 'media' => $media,
670 ] );
671 }
672
684 public static function input( $name, $value = '', $type = 'text', array $attribs = [] ) {
685 $attribs['type'] = $type;
686 $attribs['value'] = $value;
687 $attribs['name'] = $name;
688 $textInputAttributes = [
689 'text' => true,
690 'search' => true,
691 'email' => true,
692 'password' => true,
693 'number' => true
694 ];
695 if ( isset( $textInputAttributes[$type] ) ) {
696 $attribs = self::getTextInputAttributes( $attribs );
697 }
698 $buttonAttributes = [
699 'button' => true,
700 'reset' => true,
701 'submit' => true
702 ];
703 if ( isset( $buttonAttributes[$type] ) ) {
704 $attribs = self::buttonAttributes( $attribs );
705 }
706 return self::element( 'input', $attribs );
707 }
708
717 public static function check( $name, $checked = false, array $attribs = [] ) {
718 if ( isset( $attribs['value'] ) ) {
719 $value = $attribs['value'];
720 unset( $attribs['value'] );
721 } else {
722 $value = 1;
723 }
724
725 if ( $checked ) {
726 $attribs[] = 'checked';
727 }
728
729 return self::input( $name, $value, 'checkbox', $attribs );
730 }
731
740 private static function messageBox( $html, $className, $heading = '' ) {
741 if ( $heading !== '' ) {
742 $html = self::element( 'h2', [], $heading ) . $html;
743 }
744 return self::rawElement( 'div', [ 'class' => $className ], $html );
745 }
746
755 public static function warningBox( $html, $className = '' ) {
756 return self::messageBox( $html, [ 'warningbox', $className ] );
757 }
758
768 public static function errorBox( $html, $heading = '', $className = '' ) {
769 return self::messageBox( $html, [ 'errorbox', $className ], $heading );
770 }
771
780 public static function successBox( $html, $className = '' ) {
781 return self::messageBox( $html, [ 'successbox', $className ] );
782 }
783
792 public static function radio( $name, $checked = false, array $attribs = [] ) {
793 if ( isset( $attribs['value'] ) ) {
794 $value = $attribs['value'];
795 unset( $attribs['value'] );
796 } else {
797 $value = 1;
798 }
799
800 if ( $checked ) {
801 $attribs[] = 'checked';
802 }
803
804 return self::input( $name, $value, 'radio', $attribs );
805 }
806
815 public static function label( $label, $id, array $attribs = [] ) {
816 $attribs += [
817 'for' => $id
818 ];
819 return self::element( 'label', $attribs, $label );
820 }
821
831 public static function hidden( $name, $value, array $attribs = [] ) {
832 return self::input( $name, $value, 'hidden', $attribs );
833 }
834
847 public static function textarea( $name, $value = '', array $attribs = [] ) {
848 $attribs['name'] = $name;
849
850 if ( substr( $value, 0, 1 ) == "\n" ) {
851 // Workaround for T14130: browsers eat the initial newline
852 // assuming that it's just for show, but they do keep the later
853 // newlines, which we may want to preserve during editing.
854 // Prepending a single newline
855 $spacedValue = "\n" . $value;
856 } else {
857 $spacedValue = $value;
858 }
859 return self::element( 'textarea', self::getTextInputAttributes( $attribs ), $spacedValue );
860 }
861
867 public static function namespaceSelectorOptions( array $params = [] ) {
868 if ( !isset( $params['exclude'] ) || !is_array( $params['exclude'] ) ) {
869 $params['exclude'] = [];
870 }
871
872 if ( $params['in-user-lang'] ?? false ) {
873 global $wgLang;
874 $lang = $wgLang;
875 } else {
876 $lang = MediaWikiServices::getInstance()->getContentLanguage();
877 }
878
879 $optionsOut = [];
880 if ( isset( $params['all'] ) ) {
881 // add an option that would let the user select all namespaces.
882 // Value is provided by user, the name shown is localized for the user.
883 $optionsOut[$params['all']] = wfMessage( 'namespacesall' )->text();
884 }
885 // Add all namespaces as options
886 $options = $lang->getFormattedNamespaces();
887 // Filter out namespaces below 0 and massage labels
888 foreach ( $options as $nsId => $nsName ) {
889 if ( $nsId < NS_MAIN || in_array( $nsId, $params['exclude'] ) ) {
890 continue;
891 }
892 if ( $nsId === NS_MAIN ) {
893 // For other namespaces use the namespace prefix as label, but for
894 // main we don't use "" but the user message describing it (e.g. "(Main)" or "(Article)")
895 $nsName = wfMessage( 'blanknamespace' )->text();
896 } elseif ( is_int( $nsId ) ) {
897 $converter = MediaWikiServices::getInstance()->getLanguageConverterFactory()
898 ->getLanguageConverter( $lang );
899 $nsName = $converter->convertNamespace( $nsId );
900 }
901 $optionsOut[$nsId] = $nsName;
902 }
903
904 return $optionsOut;
905 }
906
923 public static function namespaceSelector( array $params = [],
924 array $selectAttribs = []
925 ) {
926 ksort( $selectAttribs );
927
928 // Is a namespace selected?
929 if ( isset( $params['selected'] ) ) {
930 // If string only contains digits, convert to clean int. Selected could also
931 // be "all" or "" etc. which needs to be left untouched.
932 if ( !is_int( $params['selected'] ) && ctype_digit( (string)$params['selected'] ) ) {
933 $params['selected'] = (int)$params['selected'];
934 }
935 // else: leaves it untouched for later processing
936 } else {
937 $params['selected'] = '';
938 }
939
940 if ( !isset( $params['disable'] ) || !is_array( $params['disable'] ) ) {
941 $params['disable'] = [];
942 }
943
944 // Associative array between option-values and option-labels
945 $options = self::namespaceSelectorOptions( $params );
946
947 // Convert $options to HTML
948 $optionsHtml = [];
949 foreach ( $options as $nsId => $nsName ) {
950 $optionsHtml[] = self::element(
951 'option', [
952 'disabled' => in_array( $nsId, $params['disable'] ),
953 'value' => $nsId,
954 'selected' => $nsId === $params['selected'],
955 ], $nsName
956 );
957 }
958
959 if ( !array_key_exists( 'id', $selectAttribs ) ) {
960 $selectAttribs['id'] = 'namespace';
961 }
962
963 if ( !array_key_exists( 'name', $selectAttribs ) ) {
964 $selectAttribs['name'] = 'namespace';
965 }
966
967 $ret = '';
968 if ( isset( $params['label'] ) ) {
969 $ret .= self::element(
970 'label', [
971 'for' => $selectAttribs['id'] ?? null,
972 ], $params['label']
973 ) . "\u{00A0}";
974 }
975
976 // Wrap options in a <select>
977 $ret .= self::openElement( 'select', $selectAttribs )
978 . "\n"
979 . implode( "\n", $optionsHtml )
980 . "\n"
981 . self::closeElement( 'select' );
982
983 return $ret;
984 }
985
994 public static function htmlHeader( array $attribs = [] ) {
995 $ret = '';
996
998
999 $isXHTML = self::isXmlMimeType( $wgMimeType );
1000
1001 if ( $isXHTML ) { // XHTML5
1002 // XML MIME-typed markup should have an xml header.
1003 // However a DOCTYPE is not needed.
1004 $ret .= "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
1005
1006 // Add the standard xmlns
1007 $attribs['xmlns'] = 'http://www.w3.org/1999/xhtml';
1008
1009 // And support custom namespaces
1010 foreach ( $wgXhtmlNamespaces as $tag => $ns ) {
1011 $attribs["xmlns:$tag"] = $ns;
1012 }
1013 } else { // HTML5
1014 $ret .= "<!DOCTYPE html>\n";
1015 }
1016
1017 if ( $wgHtml5Version ) {
1018 $attribs['version'] = $wgHtml5Version;
1019 }
1020
1021 $ret .= self::openElement( 'html', $attribs );
1022
1023 return $ret;
1024 }
1025
1032 public static function isXmlMimeType( $mimetype ) {
1033 # https://html.spec.whatwg.org/multipage/infrastructure.html#xml-mime-type
1034 # * text/xml
1035 # * application/xml
1036 # * Any MIME type with a subtype ending in +xml (this implicitly includes application/xhtml+xml)
1037 return (bool)preg_match( '!^(text|application)/xml$|^.+/.+\+xml$!', $mimetype );
1038 }
1039
1063 public static function srcSet( array $urls ) {
1064 $candidates = [];
1065 foreach ( $urls as $density => $url ) {
1066 // Cast density to float to strip 'x', then back to string to serve
1067 // as array index.
1068 $density = (string)(float)$density;
1069 $candidates[$density] = $url;
1070 }
1071
1072 // Remove duplicates that are the same as a smaller value
1073 ksort( $candidates, SORT_NUMERIC );
1074 $candidates = array_unique( $candidates );
1075
1076 // Append density info to the url
1077 foreach ( $candidates as $density => $url ) {
1078 $candidates[$density] = $url . ' ' . $density . 'x';
1079 }
1080
1081 return implode( ", ", $candidates );
1082 }
1083}
$wgMimeType
The default Content-Type header.
$wgUseMediaWikiUIEverywhere
Temporary variable that applies MediaWiki UI wherever it can be supported.
$wgHtml5Version
Defines the value of the version attribute in the <html> tag, if any.
$wgXhtmlNamespaces
Permit other namespaces in addition to the w3.org default.
const NS_MAIN
Definition Defines.php:64
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
$wgLang
Definition Setup.php:831
static isNonceRequired(Config $config)
Should we set nonce attribute.
This class is a collection of static functions that serve two purposes:
Definition Html.php:49
static inlineScript( $contents, $nonce=null)
Output an HTML script tag with the given contents.
Definition Html.php:589
static label( $label, $id, array $attribs=[])
Convenience function for generating a label for inputs.
Definition Html.php:815
static textarea( $name, $value='', array $attribs=[])
Convenience function to produce a <textarea> element.
Definition Html.php:847
static namespaceSelectorOptions(array $params=[])
Helper for Html::namespaceSelector().
Definition Html.php:867
static linkedScript( $url, $nonce=null)
Output a "<script>" tag linking to the given URL, e.g., "<script src=foo.js></script>".
Definition Html.php:613
static buttonAttributes(array $attrs, array $modifiers=[])
Modifies a set of attributes meant for button elements and apply a set of default attributes when $wg...
Definition Html.php:111
static linkedStyle( $url, $media='all')
Output a "<link rel=stylesheet>" linking to the given URL for the given media type (if any).
Definition Html.php:665
static bool[] $boolAttribs
Boolean attributes, which may have the value omitted entirely.
Definition Html.php:74
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition Html.php:232
static messageBox( $html, $className, $heading='')
Return the HTML for a message box.
Definition Html.php:740
static isXmlMimeType( $mimetype)
Determines if the given MIME type is xml.
Definition Html.php:1032
static bool[] $voidElements
List of void elements from HTML5, section 8.1.2 as of 2016-09-19.
Definition Html.php:51
static htmlHeader(array $attribs=[])
Constructs the opening html-tag with necessary doctypes depending on global variables.
Definition Html.php:994
static input( $name, $value='', $type='text', array $attribs=[])
Convenience function to produce an "<input>" element.
Definition Html.php:684
static dropDefaults( $element, array $attribs)
Given an element name and an associative array of element attributes, return an array that is functio...
Definition Html.php:339
static submitButton( $contents, array $attrs, array $modifiers=[])
Returns an HTML link element in a string styled as a button (when $wgUseMediaWikiUIEverywhere is enab...
Definition Html.php:186
static getTextInputAttributes(array $attrs)
Modifies a set of attributes meant for text input elements and apply a set of default attributes.
Definition Html.php:138
static radio( $name, $checked=false, array $attribs=[])
Convenience function to produce a radio button (input element with type=radio)
Definition Html.php:792
static expandAttributes(array $attribs)
Given an associative array of element attributes, generate a string to stick after the element name i...
Definition Html.php:476
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition Html.php:210
static warningBox( $html, $className='')
Return a warning box.
Definition Html.php:755
static namespaceSelector(array $params=[], array $selectAttribs=[])
Build a drop-down box for selecting a namespace.
Definition Html.php:923
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition Html.php:252
static linkButton( $text, array $attrs, array $modifiers=[])
Returns an HTML link element in a string styled as a button (when $wgUseMediaWikiUIEverywhere is enab...
Definition Html.php:166
static check( $name, $checked=false, array $attribs=[])
Convenience function to produce a checkbox (input element with type=checkbox)
Definition Html.php:717
static srcSet(array $urls)
Generate a srcset attribute value.
Definition Html.php:1063
static successBox( $html, $className='')
Return a success box.
Definition Html.php:780
static errorBox( $html, $heading='', $className='')
Return an error box.
Definition Html.php:768
static closeElement( $element)
Returns "</$element>".
Definition Html.php:316
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition Html.php:831
static inlineStyle( $contents, $media='all', $attribs=[])
Output a "<style>" tag with the given contents for the given media type (if any).
Definition Html.php:636
MediaWiki exception.
MediaWikiServices is the service locator for the application scope of MediaWiki.
return true
Definition router.php:92
if(!isset( $args[0])) $lang