MediaWiki REL1_40
Html.php
Go to the documentation of this file.
1<?php
26namespace MediaWiki\Html;
27
31use MWException;
32
55class Html {
57 private static $voidElements = [
58 'area' => true,
59 'base' => true,
60 'br' => true,
61 'col' => true,
62 'embed' => true,
63 'hr' => true,
64 'img' => true,
65 'input' => true,
66 'keygen' => true,
67 'link' => true,
68 'meta' => true,
69 'param' => true,
70 'source' => true,
71 'track' => true,
72 'wbr' => true,
73 ];
74
80 private static $boolAttribs = [
81 'async' => true,
82 'autofocus' => true,
83 'autoplay' => true,
84 'checked' => true,
85 'controls' => true,
86 'default' => true,
87 'defer' => true,
88 'disabled' => true,
89 'formnovalidate' => true,
90 'hidden' => true,
91 'ismap' => true,
92 'itemscope' => true,
93 'loop' => true,
94 'multiple' => true,
95 'muted' => true,
96 'novalidate' => true,
97 'open' => true,
98 'pubdate' => true,
99 'readonly' => true,
100 'required' => true,
101 'reversed' => true,
102 'scoped' => true,
103 'seamless' => true,
104 'selected' => true,
105 'truespeed' => true,
106 'typemustmatch' => true,
107 ];
108
117 public static function buttonAttributes( array $attrs, array $modifiers = [] ) {
118 $useMediaWikiUIEverywhere =
120 if ( $useMediaWikiUIEverywhere ) {
121 if ( isset( $attrs['class'] ) ) {
122 if ( is_array( $attrs['class'] ) ) {
123 $attrs['class'][] = 'mw-ui-button';
124 $attrs['class'] = array_merge( $attrs['class'], $modifiers );
125 // ensure compatibility with Xml
126 $attrs['class'] = implode( ' ', $attrs['class'] );
127 } else {
128 $attrs['class'] .= ' mw-ui-button ' . implode( ' ', $modifiers );
129 }
130 } else {
131 // ensure compatibility with Xml
132 $attrs['class'] = 'mw-ui-button ' . implode( ' ', $modifiers );
133 }
134 }
135 return $attrs;
136 }
137
145 public static function getTextInputAttributes( array $attrs ) {
146 $useMediaWikiUIEverywhere = MediaWikiServices::getInstance()
147 ->getMainConfig()->get( MainConfigNames::UseMediaWikiUIEverywhere );
148 if ( $useMediaWikiUIEverywhere ) {
149 if ( isset( $attrs['class'] ) ) {
150 if ( is_array( $attrs['class'] ) ) {
151 $attrs['class'][] = 'mw-ui-input';
152 } else {
153 $attrs['class'] .= ' mw-ui-input';
154 }
155 } else {
156 $attrs['class'] = 'mw-ui-input';
157 }
158 }
159 return $attrs;
160 }
161
174 public static function linkButton( $text, array $attrs, array $modifiers = [] ) {
175 return self::element(
176 'a',
177 self::buttonAttributes( $attrs, $modifiers ),
178 $text
179 );
180 }
181
195 public static function submitButton( $contents, array $attrs, array $modifiers = [] ) {
196 $attrs['type'] = 'submit';
197 $attrs['value'] = $contents;
198 return self::element( 'input', self::buttonAttributes( $attrs, $modifiers ) );
199 }
200
219 public static function rawElement( $element, $attribs = [], $contents = '' ) {
220 $start = self::openElement( $element, $attribs );
221 if ( isset( self::$voidElements[$element] ) ) {
222 // Silly XML.
223 return substr( $start, 0, -1 ) . '/>';
224 } else {
225 return $start . $contents . self::closeElement( $element );
226 }
227 }
228
241 public static function element( $element, $attribs = [], $contents = '' ) {
242 return self::rawElement(
243 $element,
244 $attribs,
245 strtr( $contents ?? '', [
246 // There's no point in escaping quotes, >, etc. in the contents of
247 // elements.
248 '&' => '&amp;',
249 '<' => '&lt;',
250 ] )
251 );
252 }
253
265 public static function openElement( $element, $attribs = [] ) {
266 $attribs = (array)$attribs;
267 // This is not required in HTML5, but let's do it anyway, for
268 // consistency and better compression.
269 $element = strtolower( $element );
270
271 // Some people were abusing this by passing things like
272 // 'h1 id="foo" to $element, which we don't want.
273 if ( strpos( $element, ' ' ) !== false ) {
274 wfWarn( __METHOD__ . " given element name with space '$element'" );
275 }
276
277 // Remove invalid input types
278 if ( $element == 'input' ) {
279 $validTypes = [
280 'hidden' => true,
281 'text' => true,
282 'password' => true,
283 'checkbox' => true,
284 'radio' => true,
285 'file' => true,
286 'submit' => true,
287 'image' => true,
288 'reset' => true,
289 'button' => true,
290
291 // HTML input types
292 'datetime' => true,
293 'datetime-local' => true,
294 'date' => true,
295 'month' => true,
296 'time' => true,
297 'week' => true,
298 'number' => true,
299 'range' => true,
300 'email' => true,
301 'url' => true,
302 'search' => true,
303 'tel' => true,
304 'color' => true,
305 ];
306 if ( isset( $attribs['type'] ) && !isset( $validTypes[$attribs['type']] ) ) {
307 unset( $attribs['type'] );
308 }
309 }
310
311 // According to standard the default type for <button> elements is "submit".
312 // Depending on compatibility mode IE might use "button", instead.
313 // We enforce the standard "submit".
314 if ( $element == 'button' && !isset( $attribs['type'] ) ) {
315 $attribs['type'] = 'submit';
316 }
317
318 return "<$element" . self::expandAttributes(
319 self::dropDefaults( $element, $attribs ) ) . '>';
320 }
321
329 public static function closeElement( $element ) {
330 $element = strtolower( $element );
331
332 return "</$element>";
333 }
334
352 private static function dropDefaults( $element, array $attribs ) {
353 // Whenever altering this array, please provide a covering test case
354 // in HtmlTest::provideElementsWithAttributesHavingDefaultValues
355 static $attribDefaults = [
356 'area' => [ 'shape' => 'rect' ],
357 'button' => [
358 'formaction' => 'GET',
359 'formenctype' => 'application/x-www-form-urlencoded',
360 ],
361 'canvas' => [
362 'height' => '150',
363 'width' => '300',
364 ],
365 'form' => [
366 'action' => 'GET',
367 'autocomplete' => 'on',
368 'enctype' => 'application/x-www-form-urlencoded',
369 ],
370 'input' => [
371 'formaction' => 'GET',
372 'type' => 'text',
373 ],
374 'keygen' => [ 'keytype' => 'rsa' ],
375 'link' => [ 'media' => 'all' ],
376 'menu' => [ 'type' => 'list' ],
377 'script' => [ 'type' => 'text/javascript' ],
378 'style' => [
379 'media' => 'all',
380 'type' => 'text/css',
381 ],
382 'textarea' => [ 'wrap' => 'soft' ],
383 ];
384
385 foreach ( $attribs as $attrib => $value ) {
386 if ( $attrib === 'class' ) {
387 if ( $value === '' || $value === [] || $value === [ '' ] ) {
388 unset( $attribs[$attrib] );
389 }
390 } elseif ( isset( $attribDefaults[$element][$attrib] ) ) {
391 if ( is_array( $value ) ) {
392 $value = implode( ' ', $value );
393 } else {
394 $value = strval( $value );
395 }
396 if ( $attribDefaults[$element][$attrib] == $value ) {
397 unset( $attribs[$attrib] );
398 }
399 }
400 }
401
402 // More subtle checks
403 if ( $element === 'link'
404 && isset( $attribs['type'] ) && strval( $attribs['type'] ) == 'text/css'
405 ) {
406 unset( $attribs['type'] );
407 }
408 if ( $element === 'input' ) {
409 $type = $attribs['type'] ?? null;
410 $value = $attribs['value'] ?? null;
411 if ( $type === 'checkbox' || $type === 'radio' ) {
412 // The default value for checkboxes and radio buttons is 'on'
413 // not ''. By stripping value="" we break radio boxes that
414 // actually wants empty values.
415 if ( $value === 'on' ) {
416 unset( $attribs['value'] );
417 }
418 } elseif ( $type === 'submit' ) {
419 // The default value for submit appears to be "Submit" but
420 // let's not bother stripping out localized text that matches
421 // that.
422 } else {
423 // The default value for nearly every other field type is ''
424 // The 'range' and 'color' types use different defaults but
425 // stripping a value="" does not hurt them.
426 if ( $value === '' ) {
427 unset( $attribs['value'] );
428 }
429 }
430 }
431 if ( $element === 'select' && isset( $attribs['size'] ) ) {
432 if ( in_array( 'multiple', $attribs )
433 || ( isset( $attribs['multiple'] ) && $attribs['multiple'] !== false )
434 ) {
435 // A multi-select
436 if ( strval( $attribs['size'] ) == '4' ) {
437 unset( $attribs['size'] );
438 }
439 } else {
440 // Single select
441 if ( strval( $attribs['size'] ) == '1' ) {
442 unset( $attribs['size'] );
443 }
444 }
445 }
446
447 return $attribs;
448 }
449
489 public static function expandAttributes( array $attribs ) {
490 $ret = '';
491 foreach ( $attribs as $key => $value ) {
492 // Support intuitive [ 'checked' => true/false ] form
493 if ( $value === false || $value === null ) {
494 continue;
495 }
496
497 // For boolean attributes, support [ 'foo' ] instead of
498 // requiring [ 'foo' => 'meaningless' ].
499 if ( is_int( $key ) && isset( self::$boolAttribs[strtolower( $value )] ) ) {
500 $key = $value;
501 }
502
503 // Not technically required in HTML5 but we'd like consistency
504 // and better compression anyway.
505 $key = strtolower( $key );
506
507 // https://www.w3.org/TR/html401/index/attributes.html ("space-separated")
508 // https://www.w3.org/TR/html5/index.html#attributes-1 ("space-separated")
509 $spaceSeparatedListAttributes = [
510 'class' => true, // html4, html5
511 'accesskey' => true, // as of html5, multiple space-separated values allowed
512 // html4-spec doesn't document rel= as space-separated
513 // but has been used like that and is now documented as such
514 // in the html5-spec.
515 'rel' => true,
516 ];
517
518 // Specific features for attributes that allow a list of space-separated values
519 if ( isset( $spaceSeparatedListAttributes[$key] ) ) {
520 // Apply some normalization and remove duplicates
521
522 // Convert into correct array. Array can contain space-separated
523 // values. Implode/explode to get those into the main array as well.
524 if ( is_array( $value ) ) {
525 // If input wasn't an array, we can skip this step
526 $arrayValue = [];
527 foreach ( $value as $k => $v ) {
528 if ( is_string( $v ) ) {
529 // String values should be normal `[ 'foo' ]`
530 // Just append them
531 if ( !isset( $value[$v] ) ) {
532 // As a special case don't set 'foo' if a
533 // separate 'foo' => true/false exists in the array
534 // keys should be authoritative
535 foreach ( explode( ' ', $v ) as $part ) {
536 // Normalize spacing by fixing up cases where people used
537 // more than 1 space and/or a trailing/leading space
538 if ( $part !== '' && $part !== ' ' ) {
539 $arrayValue[] = $part;
540 }
541 }
542 }
543 } elseif ( $v ) {
544 // If the value is truthy but not a string this is likely
545 // an [ 'foo' => true ], falsy values don't add strings
546 $arrayValue[] = $k;
547 }
548 }
549 } else {
550 $arrayValue = explode( ' ', $value );
551 // Normalize spacing by fixing up cases where people used
552 // more than 1 space and/or a trailing/leading space
553 $arrayValue = array_diff( $arrayValue, [ '', ' ' ] );
554 }
555
556 // Remove duplicates and create the string
557 $value = implode( ' ', array_unique( $arrayValue ) );
558
559 // Optimization: Skip below boolAttribs check and jump straight
560 // to its `else` block. The current $spaceSeparatedListAttributes
561 // block is mutually exclusive with $boolAttribs.
562 // phpcs:ignore Generic.PHP.DiscourageGoto
563 goto not_bool; // NOSONAR
564 } elseif ( is_array( $value ) ) {
565 throw new MWException( "HTML attribute $key can not contain a list of values" );
566 }
567
568 if ( isset( self::$boolAttribs[$key] ) ) {
569 $ret .= " $key=\"\"";
570 } else {
571 // phpcs:ignore Generic.PHP.DiscourageGoto
572 not_bool:
573 // Inlined from Sanitizer::encodeAttribute() for improved performance
574 $encValue = htmlspecialchars( $value, ENT_QUOTES );
575 // Whitespace is normalized during attribute decoding,
576 // so if we've been passed non-spaces we must encode them
577 // ahead of time or they won't be preserved.
578 $encValue = strtr( $encValue, [
579 "\n" => '&#10;',
580 "\r" => '&#13;',
581 "\t" => '&#9;',
582 ] );
583 $ret .= " $key=\"$encValue\"";
584 }
585 }
586 return $ret;
587 }
588
602 public static function inlineScript( $contents, $nonce = null ) {
603 $attrs = [];
604 if ( $nonce !== null ) {
605 $attrs['nonce'] = $nonce;
606 } elseif ( ContentSecurityPolicy::isNonceRequired( MediaWikiServices::getInstance()->getMainConfig() ) ) {
607 wfWarn( "no nonce set on script. CSP will break it" );
608 }
609
610 if ( preg_match( '/<\/?script/i', $contents ) ) {
611 wfLogWarning( __METHOD__ . ': Illegal character sequence found in inline script.' );
612 $contents = '/* ERROR: Invalid script */';
613 }
614
615 return self::rawElement( 'script', $attrs, $contents );
616 }
617
626 public static function linkedScript( $url, $nonce = null ) {
627 $attrs = [ 'src' => $url ];
628 if ( $nonce !== null ) {
629 $attrs['nonce'] = $nonce;
630 } elseif ( ContentSecurityPolicy::isNonceRequired( MediaWikiServices::getInstance()->getMainConfig() ) ) {
631 wfWarn( "no nonce set on script. CSP will break it" );
632 }
633
634 return self::element( 'script', $attrs );
635 }
636
649 public static function inlineStyle( $contents, $media = 'all', $attribs = [] ) {
650 // Don't escape '>' since that is used
651 // as direct child selector.
652 // Remember, in css, there is no "x" for hexadecimal escapes, and
653 // the space immediately after an escape sequence is swallowed.
654 $contents = strtr( $contents, [
655 '<' => '\3C ',
656 // CDATA end tag for good measure, but the main security
657 // is from escaping the '<'.
658 ']]>' => '\5D\5D\3E '
659 ] );
660
661 if ( preg_match( '/[<&]/', $contents ) ) {
662 $contents = "/*<![CDATA[*/$contents/*]]>*/";
663 }
664
665 return self::rawElement( 'style', [
666 'media' => $media,
667 ] + $attribs, $contents );
668 }
669
678 public static function linkedStyle( $url, $media = 'all' ) {
679 return self::element( 'link', [
680 'rel' => 'stylesheet',
681 'href' => $url,
682 'media' => $media,
683 ] );
684 }
685
697 public static function input( $name, $value = '', $type = 'text', array $attribs = [] ) {
698 $attribs['type'] = $type;
699 $attribs['value'] = $value;
700 $attribs['name'] = $name;
701 $textInputAttributes = [
702 'text' => true,
703 'search' => true,
704 'email' => true,
705 'password' => true,
706 'number' => true,
707 ];
708 if ( isset( $textInputAttributes[$type] ) ) {
709 $attribs = self::getTextInputAttributes( $attribs );
710 }
711 $buttonAttributes = [
712 'button' => true,
713 'reset' => true,
714 'submit' => true,
715 ];
716 if ( isset( $buttonAttributes[$type] ) ) {
717 $attribs = self::buttonAttributes( $attribs );
718 }
719 return self::element( 'input', $attribs );
720 }
721
730 public static function check( $name, $checked = false, array $attribs = [] ) {
731 if ( isset( $attribs['value'] ) ) {
732 $value = $attribs['value'];
733 unset( $attribs['value'] );
734 } else {
735 $value = 1;
736 }
737
738 if ( $checked ) {
739 $attribs[] = 'checked';
740 }
741
742 return self::input( $name, $value, 'checkbox', $attribs );
743 }
744
753 private static function messageBox( $html, $className, $heading = '' ) {
754 if ( $heading !== '' ) {
755 $html = self::element( 'h2', [], $heading ) . $html;
756 }
757 if ( is_array( $className ) ) {
758 $className[] = 'mw-message-box';
759 } else {
760 $className .= ' mw-message-box';
761 }
762 return self::rawElement( 'div', [ 'class' => $className ], $html );
763 }
764
772 public static function noticeBox( $html, $className ) {
773 return self::messageBox( $html, [ 'mw-message-box-notice', $className ] );
774 }
775
784 public static function warningBox( $html, $className = '' ) {
785 return self::messageBox( $html, [ 'mw-message-box-warning', $className ] );
786 }
787
797 public static function errorBox( $html, $heading = '', $className = '' ) {
798 return self::messageBox( $html, [ 'mw-message-box-error', $className ], $heading );
799 }
800
809 public static function successBox( $html, $className = '' ) {
810 return self::messageBox( $html, [ 'mw-message-box-success', $className ] );
811 }
812
821 public static function radio( $name, $checked = false, array $attribs = [] ) {
822 if ( isset( $attribs['value'] ) ) {
823 $value = $attribs['value'];
824 unset( $attribs['value'] );
825 } else {
826 $value = 1;
827 }
828
829 if ( $checked ) {
830 $attribs[] = 'checked';
831 }
832
833 return self::input( $name, $value, 'radio', $attribs );
834 }
835
844 public static function label( $label, $id, array $attribs = [] ) {
845 $attribs += [
846 'for' => $id,
847 ];
848 return self::element( 'label', $attribs, $label );
849 }
850
860 public static function hidden( $name, $value, array $attribs = [] ) {
861 return self::input( $name, $value, 'hidden', $attribs );
862 }
863
876 public static function textarea( $name, $value = '', array $attribs = [] ) {
877 $attribs['name'] = $name;
878
879 if ( substr( $value, 0, 1 ) == "\n" ) {
880 // Workaround for T14130: browsers eat the initial newline
881 // assuming that it's just for show, but they do keep the later
882 // newlines, which we may want to preserve during editing.
883 // Prepending a single newline
884 $spacedValue = "\n" . $value;
885 } else {
886 $spacedValue = $value;
887 }
888 return self::element( 'textarea', self::getTextInputAttributes( $attribs ), $spacedValue );
889 }
890
896 public static function namespaceSelectorOptions( array $params = [] ) {
897 if ( !isset( $params['exclude'] ) || !is_array( $params['exclude'] ) ) {
898 $params['exclude'] = [];
899 }
900
901 if ( $params['in-user-lang'] ?? false ) {
902 global $wgLang;
903 $lang = $wgLang;
904 } else {
905 $lang = MediaWikiServices::getInstance()->getContentLanguage();
906 }
907
908 $optionsOut = [];
909 if ( isset( $params['all'] ) ) {
910 // add an option that would let the user select all namespaces.
911 // Value is provided by user, the name shown is localized for the user.
912 $optionsOut[$params['all']] = wfMessage( 'namespacesall' )->text();
913 }
914 // Add all namespaces as options
915 $options = $lang->getFormattedNamespaces();
916 // Filter out namespaces below 0 and massage labels
917 foreach ( $options as $nsId => $nsName ) {
918 if ( $nsId < NS_MAIN || in_array( $nsId, $params['exclude'] ) ) {
919 continue;
920 }
921 if ( $nsId === NS_MAIN ) {
922 // For other namespaces use the namespace prefix as label, but for
923 // main we don't use "" but the user message describing it (e.g. "(Main)" or "(Article)")
924 $nsName = wfMessage( 'blanknamespace' )->text();
925 } elseif ( is_int( $nsId ) ) {
926 $converter = MediaWikiServices::getInstance()->getLanguageConverterFactory()
927 ->getLanguageConverter( $lang );
928 $nsName = $converter->convertNamespace( $nsId );
929 }
930 $optionsOut[$nsId] = $nsName;
931 }
932
933 return $optionsOut;
934 }
935
952 public static function namespaceSelector(
953 array $params = [],
954 array $selectAttribs = []
955 ) {
956 ksort( $selectAttribs );
957
958 // Is a namespace selected?
959 if ( isset( $params['selected'] ) ) {
960 // If string only contains digits, convert to clean int. Selected could also
961 // be "all" or "" etc. which needs to be left untouched.
962 if ( !is_int( $params['selected'] ) && ctype_digit( (string)$params['selected'] ) ) {
963 $params['selected'] = (int)$params['selected'];
964 }
965 // else: leaves it untouched for later processing
966 } else {
967 $params['selected'] = '';
968 }
969
970 if ( !isset( $params['disable'] ) || !is_array( $params['disable'] ) ) {
971 $params['disable'] = [];
972 }
973
974 // Associative array between option-values and option-labels
975 $options = self::namespaceSelectorOptions( $params );
976
977 // Convert $options to HTML
978 $optionsHtml = [];
979 foreach ( $options as $nsId => $nsName ) {
980 $optionsHtml[] = self::element(
981 'option',
982 [
983 'disabled' => in_array( $nsId, $params['disable'] ),
984 'value' => $nsId,
985 'selected' => $nsId === $params['selected'],
986 ],
987 $nsName
988 );
989 }
990
991 if ( !array_key_exists( 'id', $selectAttribs ) ) {
992 $selectAttribs['id'] = 'namespace';
993 }
994
995 if ( !array_key_exists( 'name', $selectAttribs ) ) {
996 $selectAttribs['name'] = 'namespace';
997 }
998
999 $ret = '';
1000 if ( isset( $params['label'] ) ) {
1001 $ret .= self::element(
1002 'label', [
1003 'for' => $selectAttribs['id'] ?? null,
1004 ], $params['label']
1005 ) . "\u{00A0}";
1006 }
1007
1008 // Wrap options in a <select>
1009 $ret .= self::openElement( 'select', $selectAttribs )
1010 . "\n"
1011 . implode( "\n", $optionsHtml )
1012 . "\n"
1013 . self::closeElement( 'select' );
1014
1015 return $ret;
1016 }
1017
1026 public static function htmlHeader( array $attribs = [] ) {
1027 $ret = '';
1028 $mainConfig = MediaWikiServices::getInstance()->getMainConfig();
1029 $html5Version = $mainConfig->get( MainConfigNames::Html5Version );
1030 $mimeType = $mainConfig->get( MainConfigNames::MimeType );
1031 $xhtmlNamespaces = $mainConfig->get( MainConfigNames::XhtmlNamespaces );
1032
1033 $isXHTML = self::isXmlMimeType( $mimeType );
1034
1035 if ( $isXHTML ) { // XHTML5
1036 // XML MIME-typed markup should have an xml header.
1037 // However a DOCTYPE is not needed.
1038 $ret .= "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
1039
1040 // Add the standard xmlns
1041 $attribs['xmlns'] = 'http://www.w3.org/1999/xhtml';
1042
1043 // And support custom namespaces
1044 foreach ( $xhtmlNamespaces as $tag => $ns ) {
1045 $attribs["xmlns:$tag"] = $ns;
1046 }
1047 } else { // HTML5
1048 $ret .= "<!DOCTYPE html>\n";
1049 }
1050
1051 if ( $html5Version ) {
1052 $attribs['version'] = $html5Version;
1053 }
1054
1055 $ret .= self::openElement( 'html', $attribs );
1056
1057 return $ret;
1058 }
1059
1066 public static function isXmlMimeType( $mimetype ) {
1067 # https://html.spec.whatwg.org/multipage/infrastructure.html#xml-mime-type
1068 # * text/xml
1069 # * application/xml
1070 # * Any MIME type with a subtype ending in +xml (this implicitly includes application/xhtml+xml)
1071 return (bool)preg_match( '!^(text|application)/xml$|^.+/.+\+xml$!', $mimetype );
1072 }
1073
1097 public static function srcSet( array $urls ) {
1098 $candidates = [];
1099 foreach ( $urls as $density => $url ) {
1100 // Cast density to float to strip 'x', then back to string to serve
1101 // as array index.
1102 $density = (string)(float)$density;
1103 $candidates[$density] = $url;
1104 }
1105
1106 // Remove duplicates that are the same as a smaller value
1107 ksort( $candidates, SORT_NUMERIC );
1108 $candidates = array_unique( $candidates );
1109
1110 // Append density info to the url
1111 foreach ( $candidates as $density => $url ) {
1112 $candidates[$density] = $url . ' ' . $density . 'x';
1113 }
1114
1115 return implode( ", ", $candidates );
1116 }
1117}
1118
1119class_alias( Html::class, 'Html' );
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.
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode $wgLang
Definition Setup.php:527
MediaWiki exception.
This class is a collection of static functions that serve two purposes:
Definition Html.php:55
static linkedScript( $url, $nonce=null)
Output a "<script>" tag linking to the given URL, e.g., "<script src=foo.js></script>".
Definition Html.php:626
static namespaceSelector(array $params=[], array $selectAttribs=[])
Build a drop-down box for selecting a namespace.
Definition Html.php:952
static warningBox( $html, $className='')
Return a warning box.
Definition Html.php:784
static check( $name, $checked=false, array $attribs=[])
Convenience function to produce a checkbox (input element with type=checkbox)
Definition Html.php:730
static label( $label, $id, array $attribs=[])
Convenience function for generating a label for inputs.
Definition Html.php:844
static noticeBox( $html, $className)
Return the HTML for a notice message box.
Definition Html.php:772
static expandAttributes(array $attribs)
Given an associative array of element attributes, generate a string to stick after the element name i...
Definition Html.php:489
static srcSet(array $urls)
Generate a srcset attribute value.
Definition Html.php:1097
static successBox( $html, $className='')
Return a success box.
Definition Html.php:809
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:117
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:195
static htmlHeader(array $attribs=[])
Constructs the opening html-tag with necessary doctypes depending on global variables.
Definition Html.php:1026
static errorBox( $html, $heading='', $className='')
Return an error box.
Definition Html.php:797
static inlineScript( $contents, $nonce=null)
Output an HTML script tag with the given contents.
Definition Html.php:602
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition Html.php:265
static radio( $name, $checked=false, array $attribs=[])
Convenience function to produce a radio button (input element with type=radio)
Definition Html.php:821
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition Html.php:219
static isXmlMimeType( $mimetype)
Determines if the given MIME type is xml.
Definition Html.php:1066
static getTextInputAttributes(array $attrs)
Modifies a set of attributes meant for text input elements and apply a set of default attributes.
Definition Html.php:145
static input( $name, $value='', $type='text', array $attribs=[])
Convenience function to produce an "<input>" element.
Definition Html.php:697
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition Html.php:860
static textarea( $name, $value='', array $attribs=[])
Convenience function to produce a <textarea> element.
Definition Html.php:876
static namespaceSelectorOptions(array $params=[])
Helper for Html::namespaceSelector().
Definition Html.php:896
static inlineStyle( $contents, $media='all', $attribs=[])
Output a "<style>" tag with the given contents for the given media type (if any).
Definition Html.php:649
static closeElement( $element)
Returns "</$element>".
Definition Html.php:329
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:174
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition Html.php:241
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:678
A class containing constants representing the names of configuration variables.
const MimeType
Name constant for the MimeType setting, for use with Config::get()
const UseMediaWikiUIEverywhere
Name constant for the UseMediaWikiUIEverywhere setting, for use with Config::get()
const XhtmlNamespaces
Name constant for the XhtmlNamespaces setting, for use with Config::get()
const Html5Version
Name constant for the Html5Version setting, for use with Config::get()
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
if(!isset( $args[0])) $lang