MediaWiki REL1_39
Html.php
Go to the documentation of this file.
1<?php
28
51class Html {
53 private static $voidElements = [
54 'area' => true,
55 'base' => true,
56 'br' => true,
57 'col' => true,
58 'embed' => true,
59 'hr' => true,
60 'img' => true,
61 'input' => true,
62 'keygen' => true,
63 'link' => true,
64 'meta' => true,
65 'param' => true,
66 'source' => true,
67 'track' => true,
68 'wbr' => true,
69 ];
70
76 private static $boolAttribs = [
77 'async' => true,
78 'autofocus' => true,
79 'autoplay' => true,
80 'checked' => true,
81 'controls' => true,
82 'default' => true,
83 'defer' => true,
84 'disabled' => true,
85 'formnovalidate' => true,
86 'hidden' => true,
87 'ismap' => true,
88 'itemscope' => true,
89 'loop' => true,
90 'multiple' => true,
91 'muted' => true,
92 'novalidate' => true,
93 'open' => true,
94 'pubdate' => true,
95 'readonly' => true,
96 'required' => true,
97 'reversed' => true,
98 'scoped' => true,
99 'seamless' => true,
100 'selected' => true,
101 'truespeed' => true,
102 'typemustmatch' => true,
103 ];
104
113 public static function buttonAttributes( array $attrs, array $modifiers = [] ) {
114 $useMediaWikiUIEverywhere = MediaWikiServices::getInstance()
115 ->getMainConfig()->get( MainConfigNames::UseMediaWikiUIEverywhere );
116 if ( $useMediaWikiUIEverywhere ) {
117 if ( isset( $attrs['class'] ) ) {
118 if ( is_array( $attrs['class'] ) ) {
119 $attrs['class'][] = 'mw-ui-button';
120 $attrs['class'] = array_merge( $attrs['class'], $modifiers );
121 // ensure compatibility with Xml
122 $attrs['class'] = implode( ' ', $attrs['class'] );
123 } else {
124 $attrs['class'] .= ' mw-ui-button ' . implode( ' ', $modifiers );
125 }
126 } else {
127 // ensure compatibility with Xml
128 $attrs['class'] = 'mw-ui-button ' . implode( ' ', $modifiers );
129 }
130 }
131 return $attrs;
132 }
133
141 public static function getTextInputAttributes( array $attrs ) {
142 $useMediaWikiUIEverywhere = MediaWikiServices::getInstance()
143 ->getMainConfig()->get( MainConfigNames::UseMediaWikiUIEverywhere );
144 if ( $useMediaWikiUIEverywhere ) {
145 if ( isset( $attrs['class'] ) ) {
146 if ( is_array( $attrs['class'] ) ) {
147 $attrs['class'][] = 'mw-ui-input';
148 } else {
149 $attrs['class'] .= ' mw-ui-input';
150 }
151 } else {
152 $attrs['class'] = 'mw-ui-input';
153 }
154 }
155 return $attrs;
156 }
157
170 public static function linkButton( $text, array $attrs, array $modifiers = [] ) {
171 return self::element( 'a',
172 self::buttonAttributes( $attrs, $modifiers ),
173 $text
174 );
175 }
176
190 public static function submitButton( $contents, array $attrs, array $modifiers = [] ) {
191 $attrs['type'] = 'submit';
192 $attrs['value'] = $contents;
193 return self::element( 'input', self::buttonAttributes( $attrs, $modifiers ) );
194 }
195
214 public static function rawElement( $element, $attribs = [], $contents = '' ) {
215 $start = self::openElement( $element, $attribs );
216 if ( isset( self::$voidElements[$element] ) ) {
217 // Silly XML.
218 return substr( $start, 0, -1 ) . '/>';
219 } else {
220 $contents = Sanitizer::escapeCombiningChar( $contents ?? '' );
221 return $start . $contents . self::closeElement( $element );
222 }
223 }
224
237 public static function element( $element, $attribs = [], $contents = '' ) {
238 return self::rawElement( $element, $attribs, strtr( $contents ?? '', [
239 // There's no point in escaping quotes, >, etc. in the contents of
240 // elements.
241 '&' => '&amp;',
242 '<' => '&lt;'
243 ] ) );
244 }
245
257 public static function openElement( $element, $attribs = [] ) {
258 $attribs = (array)$attribs;
259 // This is not required in HTML5, but let's do it anyway, for
260 // consistency and better compression.
261 $element = strtolower( $element );
262
263 // Some people were abusing this by passing things like
264 // 'h1 id="foo" to $element, which we don't want.
265 if ( strpos( $element, ' ' ) !== false ) {
266 wfWarn( __METHOD__ . " given element name with space '$element'" );
267 }
268
269 // Remove invalid input types
270 if ( $element == 'input' ) {
271 $validTypes = [
272 'hidden' => true,
273 'text' => true,
274 'password' => true,
275 'checkbox' => true,
276 'radio' => true,
277 'file' => true,
278 'submit' => true,
279 'image' => true,
280 'reset' => true,
281 'button' => true,
282
283 // HTML input types
284 'datetime' => true,
285 'datetime-local' => true,
286 'date' => true,
287 'month' => true,
288 'time' => true,
289 'week' => true,
290 'number' => true,
291 'range' => true,
292 'email' => true,
293 'url' => true,
294 'search' => true,
295 'tel' => true,
296 'color' => true,
297 ];
298 if ( isset( $attribs['type'] ) && !isset( $validTypes[$attribs['type']] ) ) {
299 unset( $attribs['type'] );
300 }
301 }
302
303 // According to standard the default type for <button> elements is "submit".
304 // Depending on compatibility mode IE might use "button", instead.
305 // We enforce the standard "submit".
306 if ( $element == 'button' && !isset( $attribs['type'] ) ) {
307 $attribs['type'] = 'submit';
308 }
309
310 return "<$element" . self::expandAttributes(
311 self::dropDefaults( $element, $attribs ) ) . '>';
312 }
313
321 public static function closeElement( $element ) {
322 $element = strtolower( $element );
323
324 return "</$element>";
325 }
326
344 private static function dropDefaults( $element, array $attribs ) {
345 // Whenever altering this array, please provide a covering test case
346 // in HtmlTest::provideElementsWithAttributesHavingDefaultValues
347 static $attribDefaults = [
348 'area' => [ 'shape' => 'rect' ],
349 'button' => [
350 'formaction' => 'GET',
351 'formenctype' => 'application/x-www-form-urlencoded',
352 ],
353 'canvas' => [
354 'height' => '150',
355 'width' => '300',
356 ],
357 'form' => [
358 'action' => 'GET',
359 'autocomplete' => 'on',
360 'enctype' => 'application/x-www-form-urlencoded',
361 ],
362 'input' => [
363 'formaction' => 'GET',
364 'type' => 'text',
365 ],
366 'keygen' => [ 'keytype' => 'rsa' ],
367 'link' => [ 'media' => 'all' ],
368 'menu' => [ 'type' => 'list' ],
369 'script' => [ 'type' => 'text/javascript' ],
370 'style' => [
371 'media' => 'all',
372 'type' => 'text/css',
373 ],
374 'textarea' => [ 'wrap' => 'soft' ],
375 ];
376
377 foreach ( $attribs as $attrib => $value ) {
378 if ( $attrib === 'class' ) {
379 if ( $value === '' || $value === [] || $value === [ '' ] ) {
380 unset( $attribs[$attrib] );
381 }
382 } elseif ( isset( $attribDefaults[$element][$attrib] ) ) {
383 if ( is_array( $value ) ) {
384 $value = implode( ' ', $value );
385 } else {
386 $value = strval( $value );
387 }
388 if ( $attribDefaults[$element][$attrib] == $value ) {
389 unset( $attribs[$attrib] );
390 }
391 }
392 }
393
394 // More subtle checks
395 if ( $element === 'link'
396 && isset( $attribs['type'] ) && strval( $attribs['type'] ) == 'text/css'
397 ) {
398 unset( $attribs['type'] );
399 }
400 if ( $element === 'input' ) {
401 $type = $attribs['type'] ?? null;
402 $value = $attribs['value'] ?? null;
403 if ( $type === 'checkbox' || $type === 'radio' ) {
404 // The default value for checkboxes and radio buttons is 'on'
405 // not ''. By stripping value="" we break radio boxes that
406 // actually wants empty values.
407 if ( $value === 'on' ) {
408 unset( $attribs['value'] );
409 }
410 } elseif ( $type === 'submit' ) {
411 // The default value for submit appears to be "Submit" but
412 // let's not bother stripping out localized text that matches
413 // that.
414 } else {
415 // The default value for nearly every other field type is ''
416 // The 'range' and 'color' types use different defaults but
417 // stripping a value="" does not hurt them.
418 if ( $value === '' ) {
419 unset( $attribs['value'] );
420 }
421 }
422 }
423 if ( $element === 'select' && isset( $attribs['size'] ) ) {
424 if ( in_array( 'multiple', $attribs )
425 || ( isset( $attribs['multiple'] ) && $attribs['multiple'] !== false )
426 ) {
427 // A multi-select
428 if ( strval( $attribs['size'] ) == '4' ) {
429 unset( $attribs['size'] );
430 }
431 } else {
432 // Single select
433 if ( strval( $attribs['size'] ) == '1' ) {
434 unset( $attribs['size'] );
435 }
436 }
437 }
438
439 return $attribs;
440 }
441
481 public static function expandAttributes( array $attribs ) {
482 $ret = '';
483 foreach ( $attribs as $key => $value ) {
484 // Support intuitive [ 'checked' => true/false ] form
485 if ( $value === false || $value === null ) {
486 continue;
487 }
488
489 // For boolean attributes, support [ 'foo' ] instead of
490 // requiring [ 'foo' => 'meaningless' ].
491 if ( is_int( $key ) && isset( self::$boolAttribs[strtolower( $value )] ) ) {
492 $key = $value;
493 }
494
495 // Not technically required in HTML5 but we'd like consistency
496 // and better compression anyway.
497 $key = strtolower( $key );
498
499 // https://www.w3.org/TR/html401/index/attributes.html ("space-separated")
500 // https://www.w3.org/TR/html5/index.html#attributes-1 ("space-separated")
501 $spaceSeparatedListAttributes = [
502 'class' => true, // html4, html5
503 'accesskey' => true, // as of html5, multiple space-separated values allowed
504 // html4-spec doesn't document rel= as space-separated
505 // but has been used like that and is now documented as such
506 // in the html5-spec.
507 'rel' => true,
508 ];
509
510 // Specific features for attributes that allow a list of space-separated values
511 if ( isset( $spaceSeparatedListAttributes[$key] ) ) {
512 // Apply some normalization and remove duplicates
513
514 // Convert into correct array. Array can contain space-separated
515 // values. Implode/explode to get those into the main array as well.
516 if ( is_array( $value ) ) {
517 // If input wasn't an array, we can skip this step
518 $arrayValue = [];
519 foreach ( $value as $k => $v ) {
520 if ( is_string( $v ) ) {
521 // String values should be normal `[ 'foo' ]`
522 // Just append them
523 if ( !isset( $value[$v] ) ) {
524 // As a special case don't set 'foo' if a
525 // separate 'foo' => true/false exists in the array
526 // keys should be authoritative
527 foreach ( explode( ' ', $v ) as $part ) {
528 // Normalize spacing by fixing up cases where people used
529 // more than 1 space and/or a trailing/leading space
530 if ( $part !== '' && $part !== ' ' ) {
531 $arrayValue[] = $part;
532 }
533 }
534 }
535 } elseif ( $v ) {
536 // If the value is truthy but not a string this is likely
537 // an [ 'foo' => true ], falsy values don't add strings
538 $arrayValue[] = $k;
539 }
540 }
541 } else {
542 $arrayValue = explode( ' ', $value );
543 // Normalize spacing by fixing up cases where people used
544 // more than 1 space and/or a trailing/leading space
545 $arrayValue = array_diff( $arrayValue, [ '', ' ' ] );
546 }
547
548 // Remove duplicates and create the string
549 $value = implode( ' ', array_unique( $arrayValue ) );
550
551 // Optimization: Skip below boolAttribs check and jump straight
552 // to its `else` block. The current $spaceSeparatedListAttributes
553 // block is mutually exclusive with $boolAttribs.
554 // phpcs:ignore Generic.PHP.DiscourageGoto
555 goto not_bool; // NOSONAR
556 } elseif ( is_array( $value ) ) {
557 throw new MWException( "HTML attribute $key can not contain a list of values" );
558 }
559
560 if ( isset( self::$boolAttribs[$key] ) ) {
561 $ret .= " $key=\"\"";
562 } else {
563 // phpcs:ignore Generic.PHP.DiscourageGoto
564 not_bool:
565 // Inlined from Sanitizer::encodeAttribute() for improved performance
566 $encValue = htmlspecialchars( $value, ENT_QUOTES );
567 // Whitespace is normalized during attribute decoding,
568 // so if we've been passed non-spaces we must encode them
569 // ahead of time or they won't be preserved.
570 $encValue = strtr( $encValue, [
571 "\n" => '&#10;',
572 "\r" => '&#13;',
573 "\t" => '&#9;',
574 ] );
575 $ret .= " $key=\"$encValue\"";
576 }
577 }
578 return $ret;
579 }
580
594 public static function inlineScript( $contents, $nonce = null ) {
595 $attrs = [];
596 if ( $nonce !== null ) {
597 $attrs['nonce'] = $nonce;
598 } elseif ( ContentSecurityPolicy::isNonceRequired( MediaWikiServices::getInstance()->getMainConfig() ) ) {
599 wfWarn( "no nonce set on script. CSP will break it" );
600 }
601
602 if ( preg_match( '/<\/?script/i', $contents ) ) {
603 wfLogWarning( __METHOD__ . ': Illegal character sequence found in inline script.' );
604 $contents = '/* ERROR: Invalid script */';
605 }
606
607 return self::rawElement( 'script', $attrs, $contents );
608 }
609
618 public static function linkedScript( $url, $nonce = null ) {
619 $attrs = [ 'src' => $url ];
620 if ( $nonce !== null ) {
621 $attrs['nonce'] = $nonce;
622 } elseif ( ContentSecurityPolicy::isNonceRequired( MediaWikiServices::getInstance()->getMainConfig() ) ) {
623 wfWarn( "no nonce set on script. CSP will break it" );
624 }
625
626 return self::element( 'script', $attrs );
627 }
628
641 public static function inlineStyle( $contents, $media = 'all', $attribs = [] ) {
642 // Don't escape '>' since that is used
643 // as direct child selector.
644 // Remember, in css, there is no "x" for hexadecimal escapes, and
645 // the space immediately after an escape sequence is swallowed.
646 $contents = strtr( $contents, [
647 '<' => '\3C ',
648 // CDATA end tag for good measure, but the main security
649 // is from escaping the '<'.
650 ']]>' => '\5D\5D\3E '
651 ] );
652
653 if ( preg_match( '/[<&]/', $contents ) ) {
654 $contents = "/*<![CDATA[*/$contents/*]]>*/";
655 }
656
657 return self::rawElement( 'style', [
658 'media' => $media,
659 ] + $attribs, $contents );
660 }
661
670 public static function linkedStyle( $url, $media = 'all' ) {
671 return self::element( 'link', [
672 'rel' => 'stylesheet',
673 'href' => $url,
674 'media' => $media,
675 ] );
676 }
677
689 public static function input( $name, $value = '', $type = 'text', array $attribs = [] ) {
690 $attribs['type'] = $type;
691 $attribs['value'] = $value;
692 $attribs['name'] = $name;
693 $textInputAttributes = [
694 'text' => true,
695 'search' => true,
696 'email' => true,
697 'password' => true,
698 'number' => true
699 ];
700 if ( isset( $textInputAttributes[$type] ) ) {
701 $attribs = self::getTextInputAttributes( $attribs );
702 }
703 $buttonAttributes = [
704 'button' => true,
705 'reset' => true,
706 'submit' => true
707 ];
708 if ( isset( $buttonAttributes[$type] ) ) {
709 $attribs = self::buttonAttributes( $attribs );
710 }
711 return self::element( 'input', $attribs );
712 }
713
722 public static function check( $name, $checked = false, array $attribs = [] ) {
723 if ( isset( $attribs['value'] ) ) {
724 $value = $attribs['value'];
725 unset( $attribs['value'] );
726 } else {
727 $value = 1;
728 }
729
730 if ( $checked ) {
731 $attribs[] = 'checked';
732 }
733
734 return self::input( $name, $value, 'checkbox', $attribs );
735 }
736
745 private static function messageBox( $html, $className, $heading = '' ) {
746 if ( $heading !== '' ) {
747 $html = self::element( 'h2', [], $heading ) . $html;
748 }
749 if ( is_array( $className ) ) {
750 $className[] = 'mw-message-box';
751 } else {
752 $className .= ' mw-message-box';
753 }
754 return self::rawElement( 'div', [ 'class' => $className ], $html );
755 }
756
764 public static function noticeBox( $html, $className ) {
765 return self::messageBox( $html, [ 'mw-message-box-notice', $className ] );
766 }
767
776 public static function warningBox( $html, $className = '' ) {
777 return self::messageBox( $html, [ 'mw-message-box-warning', $className ] );
778 }
779
789 public static function errorBox( $html, $heading = '', $className = '' ) {
790 return self::messageBox( $html, [ 'mw-message-box-error', $className ], $heading );
791 }
792
801 public static function successBox( $html, $className = '' ) {
802 return self::messageBox( $html, [ 'mw-message-box-success', $className ] );
803 }
804
813 public static function radio( $name, $checked = false, array $attribs = [] ) {
814 if ( isset( $attribs['value'] ) ) {
815 $value = $attribs['value'];
816 unset( $attribs['value'] );
817 } else {
818 $value = 1;
819 }
820
821 if ( $checked ) {
822 $attribs[] = 'checked';
823 }
824
825 return self::input( $name, $value, 'radio', $attribs );
826 }
827
836 public static function label( $label, $id, array $attribs = [] ) {
837 $attribs += [
838 'for' => $id
839 ];
840 return self::element( 'label', $attribs, $label );
841 }
842
852 public static function hidden( $name, $value, array $attribs = [] ) {
853 return self::input( $name, $value, 'hidden', $attribs );
854 }
855
868 public static function textarea( $name, $value = '', array $attribs = [] ) {
869 $attribs['name'] = $name;
870
871 if ( substr( $value, 0, 1 ) == "\n" ) {
872 // Workaround for T14130: browsers eat the initial newline
873 // assuming that it's just for show, but they do keep the later
874 // newlines, which we may want to preserve during editing.
875 // Prepending a single newline
876 $spacedValue = "\n" . $value;
877 } else {
878 $spacedValue = $value;
879 }
880 return self::element( 'textarea', self::getTextInputAttributes( $attribs ), $spacedValue );
881 }
882
888 public static function namespaceSelectorOptions( array $params = [] ) {
889 if ( !isset( $params['exclude'] ) || !is_array( $params['exclude'] ) ) {
890 $params['exclude'] = [];
891 }
892
893 if ( $params['in-user-lang'] ?? false ) {
894 global $wgLang;
895 $lang = $wgLang;
896 } else {
897 $lang = MediaWikiServices::getInstance()->getContentLanguage();
898 }
899
900 $optionsOut = [];
901 if ( isset( $params['all'] ) ) {
902 // add an option that would let the user select all namespaces.
903 // Value is provided by user, the name shown is localized for the user.
904 $optionsOut[$params['all']] = wfMessage( 'namespacesall' )->text();
905 }
906 // Add all namespaces as options
907 $options = $lang->getFormattedNamespaces();
908 // Filter out namespaces below 0 and massage labels
909 foreach ( $options as $nsId => $nsName ) {
910 if ( $nsId < NS_MAIN || in_array( $nsId, $params['exclude'] ) ) {
911 continue;
912 }
913 if ( $nsId === NS_MAIN ) {
914 // For other namespaces use the namespace prefix as label, but for
915 // main we don't use "" but the user message describing it (e.g. "(Main)" or "(Article)")
916 $nsName = wfMessage( 'blanknamespace' )->text();
917 } elseif ( is_int( $nsId ) ) {
918 $converter = MediaWikiServices::getInstance()->getLanguageConverterFactory()
919 ->getLanguageConverter( $lang );
920 $nsName = $converter->convertNamespace( $nsId );
921 }
922 $optionsOut[$nsId] = $nsName;
923 }
924
925 return $optionsOut;
926 }
927
944 public static function namespaceSelector( array $params = [],
945 array $selectAttribs = []
946 ) {
947 ksort( $selectAttribs );
948
949 // Is a namespace selected?
950 if ( isset( $params['selected'] ) ) {
951 // If string only contains digits, convert to clean int. Selected could also
952 // be "all" or "" etc. which needs to be left untouched.
953 if ( !is_int( $params['selected'] ) && ctype_digit( (string)$params['selected'] ) ) {
954 $params['selected'] = (int)$params['selected'];
955 }
956 // else: leaves it untouched for later processing
957 } else {
958 $params['selected'] = '';
959 }
960
961 if ( !isset( $params['disable'] ) || !is_array( $params['disable'] ) ) {
962 $params['disable'] = [];
963 }
964
965 // Associative array between option-values and option-labels
966 $options = self::namespaceSelectorOptions( $params );
967
968 // Convert $options to HTML
969 $optionsHtml = [];
970 foreach ( $options as $nsId => $nsName ) {
971 $optionsHtml[] = self::element(
972 'option', [
973 'disabled' => in_array( $nsId, $params['disable'] ),
974 'value' => $nsId,
975 'selected' => $nsId === $params['selected'],
976 ], $nsName
977 );
978 }
979
980 if ( !array_key_exists( 'id', $selectAttribs ) ) {
981 $selectAttribs['id'] = 'namespace';
982 }
983
984 if ( !array_key_exists( 'name', $selectAttribs ) ) {
985 $selectAttribs['name'] = 'namespace';
986 }
987
988 $ret = '';
989 if ( isset( $params['label'] ) ) {
990 $ret .= self::element(
991 'label', [
992 'for' => $selectAttribs['id'] ?? null,
993 ], $params['label']
994 ) . "\u{00A0}";
995 }
996
997 // Wrap options in a <select>
998 $ret .= self::openElement( 'select', $selectAttribs )
999 . "\n"
1000 . implode( "\n", $optionsHtml )
1001 . "\n"
1002 . self::closeElement( 'select' );
1003
1004 return $ret;
1005 }
1006
1015 public static function htmlHeader( array $attribs = [] ) {
1016 $ret = '';
1017 $mainConfig = MediaWikiServices::getInstance()->getMainConfig();
1018 $html5Version = $mainConfig->get( MainConfigNames::Html5Version );
1019 $mimeType = $mainConfig->get( MainConfigNames::MimeType );
1020 $xhtmlNamespaces = $mainConfig->get( MainConfigNames::XhtmlNamespaces );
1021
1022 $isXHTML = self::isXmlMimeType( $mimeType );
1023
1024 if ( $isXHTML ) { // XHTML5
1025 // XML MIME-typed markup should have an xml header.
1026 // However a DOCTYPE is not needed.
1027 $ret .= "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
1028
1029 // Add the standard xmlns
1030 $attribs['xmlns'] = 'http://www.w3.org/1999/xhtml';
1031
1032 // And support custom namespaces
1033 foreach ( $xhtmlNamespaces as $tag => $ns ) {
1034 $attribs["xmlns:$tag"] = $ns;
1035 }
1036 } else { // HTML5
1037 $ret .= "<!DOCTYPE html>\n";
1038 }
1039
1040 if ( $html5Version ) {
1041 $attribs['version'] = $html5Version;
1042 }
1043
1044 $ret .= self::openElement( 'html', $attribs );
1045
1046 return $ret;
1047 }
1048
1055 public static function isXmlMimeType( $mimetype ) {
1056 # https://html.spec.whatwg.org/multipage/infrastructure.html#xml-mime-type
1057 # * text/xml
1058 # * application/xml
1059 # * Any MIME type with a subtype ending in +xml (this implicitly includes application/xhtml+xml)
1060 return (bool)preg_match( '!^(text|application)/xml$|^.+/.+\+xml$!', $mimetype );
1061 }
1062
1086 public static function srcSet( array $urls ) {
1087 $candidates = [];
1088 foreach ( $urls as $density => $url ) {
1089 // Cast density to float to strip 'x', then back to string to serve
1090 // as array index.
1091 $density = (string)(float)$density;
1092 $candidates[$density] = $url;
1093 }
1094
1095 // Remove duplicates that are the same as a smaller value
1096 ksort( $candidates, SORT_NUMERIC );
1097 $candidates = array_unique( $candidates );
1098
1099 // Append density info to the url
1100 foreach ( $candidates as $density => $url ) {
1101 $candidates[$density] = $url . ' ' . $density . 'x';
1102 }
1103
1104 return implode( ", ", $candidates );
1105 }
1106}
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:497
static isNonceRequired(Config $config)
Should we set nonce attribute.
This class is a collection of static functions that serve two purposes:
Definition Html.php:51
static inlineScript( $contents, $nonce=null)
Output an HTML script tag with the given contents.
Definition Html.php:594
static label( $label, $id, array $attribs=[])
Convenience function for generating a label for inputs.
Definition Html.php:836
static textarea( $name, $value='', array $attribs=[])
Convenience function to produce a <textarea> element.
Definition Html.php:868
static namespaceSelectorOptions(array $params=[])
Helper for Html::namespaceSelector().
Definition Html.php:888
static linkedScript( $url, $nonce=null)
Output a "<script>" tag linking to the given URL, e.g., "<script src=foo.js></script>".
Definition Html.php:618
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:113
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:670
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition Html.php:237
static isXmlMimeType( $mimetype)
Determines if the given MIME type is xml.
Definition Html.php:1055
static htmlHeader(array $attribs=[])
Constructs the opening html-tag with necessary doctypes depending on global variables.
Definition Html.php:1015
static input( $name, $value='', $type='text', array $attribs=[])
Convenience function to produce an "<input>" element.
Definition Html.php:689
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:190
static getTextInputAttributes(array $attrs)
Modifies a set of attributes meant for text input elements and apply a set of default attributes.
Definition Html.php:141
static radio( $name, $checked=false, array $attribs=[])
Convenience function to produce a radio button (input element with type=radio)
Definition Html.php:813
static expandAttributes(array $attribs)
Given an associative array of element attributes, generate a string to stick after the element name i...
Definition Html.php:481
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition Html.php:214
static warningBox( $html, $className='')
Return a warning box.
Definition Html.php:776
static namespaceSelector(array $params=[], array $selectAttribs=[])
Build a drop-down box for selecting a namespace.
Definition Html.php:944
static noticeBox( $html, $className)
Return the HTML for a notice message box.
Definition Html.php:764
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition Html.php:257
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:170
static check( $name, $checked=false, array $attribs=[])
Convenience function to produce a checkbox (input element with type=checkbox)
Definition Html.php:722
static srcSet(array $urls)
Generate a srcset attribute value.
Definition Html.php:1086
static successBox( $html, $className='')
Return a success box.
Definition Html.php:801
static errorBox( $html, $heading='', $className='')
Return an error box.
Definition Html.php:789
static closeElement( $element)
Returns "</$element>".
Definition Html.php:321
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition Html.php:852
static inlineStyle( $contents, $media='all', $attribs=[])
Output a "<style>" tag with the given contents for the given media type (if any).
Definition Html.php:641
MediaWiki exception.
A class containing constants representing the names of configuration variables.
Service locator for MediaWiki core services.
return true
Definition router.php:92
if(!isset( $args[0])) $lang