MediaWiki REL1_33
Html.php
Go to the documentation of this file.
1<?php
26
49class Html {
50 // List of void elements from HTML5, section 8.1.2 as of 2016-09-19
51 private static $voidElements = [
52 'area',
53 'base',
54 'br',
55 'col',
56 'embed',
57 'hr',
58 'img',
59 'input',
60 'keygen',
61 'link',
62 'meta',
63 'param',
64 'source',
65 'track',
66 'wbr',
67 ];
68
69 // Boolean attributes, which may have the value omitted entirely. Manually
70 // collected from the HTML5 spec as of 2011-08-12.
71 private static $boolAttribs = [
72 'async',
73 'autofocus',
74 'autoplay',
75 'checked',
76 'controls',
77 'default',
78 'defer',
79 'disabled',
80 'formnovalidate',
81 'hidden',
82 'ismap',
83 'itemscope',
84 'loop',
85 'multiple',
86 'muted',
87 'novalidate',
88 'open',
89 'pubdate',
90 'readonly',
91 'required',
92 'reversed',
93 'scoped',
94 'seamless',
95 'selected',
96 'truespeed',
97 'typemustmatch',
98 // HTML5 Microdata
99 'itemscope',
100 ];
101
110 public static function buttonAttributes( array $attrs, array $modifiers = [] ) {
113 if ( isset( $attrs['class'] ) ) {
114 if ( is_array( $attrs['class'] ) ) {
115 $attrs['class'][] = 'mw-ui-button';
116 $attrs['class'] = array_merge( $attrs['class'], $modifiers );
117 // ensure compatibility with Xml
118 $attrs['class'] = implode( ' ', $attrs['class'] );
119 } else {
120 $attrs['class'] .= ' mw-ui-button ' . implode( ' ', $modifiers );
121 }
122 } else {
123 // ensure compatibility with Xml
124 $attrs['class'] = 'mw-ui-button ' . implode( ' ', $modifiers );
125 }
126 }
127 return $attrs;
128 }
129
137 public static function getTextInputAttributes( array $attrs ) {
140 if ( isset( $attrs['class'] ) ) {
141 if ( is_array( $attrs['class'] ) ) {
142 $attrs['class'][] = 'mw-ui-input';
143 } else {
144 $attrs['class'] .= ' mw-ui-input';
145 }
146 } else {
147 $attrs['class'] = 'mw-ui-input';
148 }
149 }
150 return $attrs;
151 }
152
166 public static function linkButton( $contents, array $attrs, array $modifiers = [] ) {
167 return self::element( 'a',
168 self::buttonAttributes( $attrs, $modifiers ),
169 $contents
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 ( in_array( $element, self::$voidElements ) ) {
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 = [] ) {
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',
268 'text',
269 'password',
270 'checkbox',
271 'radio',
272 'file',
273 'submit',
274 'image',
275 'reset',
276 'button',
277
278 // HTML input types
279 'datetime',
280 'datetime-local',
281 'date',
282 'month',
283 'time',
284 'week',
285 'number',
286 'range',
287 'email',
288 'url',
289 'search',
290 'tel',
291 'color',
292 ];
293 if ( isset( $attribs['type'] ) && !in_array( $attribs['type'], $validTypes ) ) {
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 $element = strtolower( $element );
373
374 foreach ( $attribs as $attrib => $value ) {
375 $lcattrib = strtolower( $attrib );
376 if ( is_array( $value ) ) {
377 $value = implode( ' ', $value );
378 } else {
379 $value = strval( $value );
380 }
381
382 // Simple checks using $attribDefaults
383 if ( isset( $attribDefaults[$element][$lcattrib] )
384 && $attribDefaults[$element][$lcattrib] == $value
385 ) {
386 unset( $attribs[$attrib] );
387 }
388
389 if ( $lcattrib == 'class' && $value == '' ) {
390 unset( $attribs[$attrib] );
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 || is_null( $value ) ) {
486 continue;
487 }
488
489 // For boolean attributes, support [ 'foo' ] instead of
490 // requiring [ 'foo' => 'meaningless' ].
491 if ( is_int( $key ) && in_array( strtolower( $value ), self::$boolAttribs ) ) {
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', // html4, html5
503 'accesskey', // 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',
508 ];
509
510 // Specific features for attributes that allow a list of space-separated values
511 if ( in_array( $key, $spaceSeparatedListAttributes ) ) {
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 $newValue = [];
519 foreach ( $value as $k => $v ) {
520 if ( is_string( $v ) ) {
521 // String values should be normal `array( '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 $newValue[] = $v;
528 }
529 } elseif ( $v ) {
530 // If the value is truthy but not a string this is likely
531 // an [ 'foo' => true ], falsy values don't add strings
532 $newValue[] = $k;
533 }
534 }
535 $value = implode( ' ', $newValue );
536 }
537 $value = explode( ' ', $value );
538
539 // Normalize spacing by fixing up cases where people used
540 // more than 1 space and/or a trailing/leading space
541 $value = array_diff( $value, [ '', ' ' ] );
542
543 // Remove duplicates and create the string
544 $value = implode( ' ', array_unique( $value ) );
545 } elseif ( is_array( $value ) ) {
546 throw new MWException( "HTML attribute $key can not contain a list of values" );
547 }
548
549 $quote = '"';
550
551 if ( in_array( $key, self::$boolAttribs ) ) {
552 $ret .= " $key=\"\"";
553 } else {
554 $ret .= " $key=$quote" . Sanitizer::encodeAttribute( $value ) . $quote;
555 }
556 }
557 return $ret;
558 }
559
573 public static function inlineScript( $contents, $nonce = null ) {
574 $attrs = [];
575 if ( $nonce !== null ) {
576 $attrs['nonce'] = $nonce;
577 } elseif ( ContentSecurityPolicy::isNonceRequired( RequestContext::getMain()->getConfig() ) ) {
578 wfWarn( "no nonce set on script. CSP will break it" );
579 }
580
581 if ( preg_match( '/<\/?script/i', $contents ) ) {
582 wfLogWarning( __METHOD__ . ': Illegal character sequence found in inline script.' );
583 $contents = '/* ERROR: Invalid script */';
584 }
585
586 return self::rawElement( 'script', $attrs, $contents );
587 }
588
597 public static function linkedScript( $url, $nonce = null ) {
598 $attrs = [ 'src' => $url ];
599 if ( $nonce !== null ) {
600 $attrs['nonce'] = $nonce;
601 } elseif ( ContentSecurityPolicy::isNonceRequired( RequestContext::getMain()->getConfig() ) ) {
602 wfWarn( "no nonce set on script. CSP will break it" );
603 }
604
605 return self::element( 'script', $attrs );
606 }
607
620 public static function inlineStyle( $contents, $media = 'all', $attribs = [] ) {
621 // Don't escape '>' since that is used
622 // as direct child selector.
623 // Remember, in css, there is no "x" for hexadecimal escapes, and
624 // the space immediately after an escape sequence is swallowed.
625 $contents = strtr( $contents, [
626 '<' => '\3C ',
627 // CDATA end tag for good measure, but the main security
628 // is from escaping the '<'.
629 ']]>' => '\5D\5D\3E '
630 ] );
631
632 if ( preg_match( '/[<&]/', $contents ) ) {
633 $contents = "/*<![CDATA[*/$contents/*]]>*/";
634 }
635
636 return self::rawElement( 'style', [
637 'media' => $media,
638 ] + $attribs, $contents );
639 }
640
649 public static function linkedStyle( $url, $media = 'all' ) {
650 return self::element( 'link', [
651 'rel' => 'stylesheet',
652 'href' => $url,
653 'media' => $media,
654 ] );
655 }
656
668 public static function input( $name, $value = '', $type = 'text', array $attribs = [] ) {
669 $attribs['type'] = $type;
670 $attribs['value'] = $value;
671 $attribs['name'] = $name;
672 if ( in_array( $type, [ 'text', 'search', 'email', 'password', 'number' ] ) ) {
673 $attribs = self::getTextInputAttributes( $attribs );
674 }
675 if ( in_array( $type, [ 'button', 'reset', 'submit' ] ) ) {
676 $attribs = self::buttonAttributes( $attribs );
677 }
678 return self::element( 'input', $attribs );
679 }
680
689 public static function check( $name, $checked = false, array $attribs = [] ) {
690 if ( isset( $attribs['value'] ) ) {
691 $value = $attribs['value'];
692 unset( $attribs['value'] );
693 } else {
694 $value = 1;
695 }
696
697 if ( $checked ) {
698 $attribs[] = 'checked';
699 }
700
701 return self::input( $name, $value, 'checkbox', $attribs );
702 }
703
712 private static function messageBox( $html, $className, $heading = '' ) {
713 if ( $heading !== '' ) {
714 $html = self::element( 'h2', [], $heading ) . $html;
715 }
716 return self::rawElement( 'div', [ 'class' => $className ], $html );
717 }
718
725 public static function warningBox( $html ) {
726 return self::messageBox( $html, 'warningbox' );
727 }
728
736 public static function errorBox( $html, $heading = '' ) {
737 return self::messageBox( $html, 'errorbox', $heading );
738 }
739
746 public static function successBox( $html ) {
747 return self::messageBox( $html, 'successbox' );
748 }
749
758 public static function radio( $name, $checked = false, array $attribs = [] ) {
759 if ( isset( $attribs['value'] ) ) {
760 $value = $attribs['value'];
761 unset( $attribs['value'] );
762 } else {
763 $value = 1;
764 }
765
766 if ( $checked ) {
767 $attribs[] = 'checked';
768 }
769
770 return self::input( $name, $value, 'radio', $attribs );
771 }
772
781 public static function label( $label, $id, array $attribs = [] ) {
782 $attribs += [
783 'for' => $id
784 ];
785 return self::element( 'label', $attribs, $label );
786 }
787
797 public static function hidden( $name, $value, array $attribs = [] ) {
798 return self::input( $name, $value, 'hidden', $attribs );
799 }
800
813 public static function textarea( $name, $value = '', array $attribs = [] ) {
814 $attribs['name'] = $name;
815
816 if ( substr( $value, 0, 1 ) == "\n" ) {
817 // Workaround for T14130: browsers eat the initial newline
818 // assuming that it's just for show, but they do keep the later
819 // newlines, which we may want to preserve during editing.
820 // Prepending a single newline
821 $spacedValue = "\n" . $value;
822 } else {
823 $spacedValue = $value;
824 }
825 return self::element( 'textarea', self::getTextInputAttributes( $attribs ), $spacedValue );
826 }
827
833 public static function namespaceSelectorOptions( array $params = [] ) {
834 $options = [];
835
836 if ( !isset( $params['exclude'] ) || !is_array( $params['exclude'] ) ) {
837 $params['exclude'] = [];
838 }
839
840 if ( isset( $params['all'] ) ) {
841 // add an option that would let the user select all namespaces.
842 // Value is provided by user, the name shown is localized for the user.
843 $options[$params['all']] = wfMessage( 'namespacesall' )->text();
844 }
845 if ( $params['in-user-lang'] ?? false ) {
846 global $wgLang;
847 $lang = $wgLang;
848 } else {
849 $lang = MediaWikiServices::getInstance()->getContentLanguage();
850 }
851 // Add all namespaces as options
852 $options += $lang->getFormattedNamespaces();
853
854 $optionsOut = [];
855 // Filter out namespaces below 0 and massage labels
856 foreach ( $options as $nsId => $nsName ) {
857 if ( $nsId < NS_MAIN || in_array( $nsId, $params['exclude'] ) ) {
858 continue;
859 }
860 if ( $nsId === NS_MAIN ) {
861 // For other namespaces use the namespace prefix as label, but for
862 // main we don't use "" but the user message describing it (e.g. "(Main)" or "(Article)")
863 $nsName = wfMessage( 'blanknamespace' )->text();
864 } elseif ( is_int( $nsId ) ) {
865 $nsName = $lang->convertNamespace( $nsId );
866 }
867 $optionsOut[$nsId] = $nsName;
868 }
869
870 return $optionsOut;
871 }
872
889 public static function namespaceSelector( array $params = [],
890 array $selectAttribs = []
891 ) {
892 ksort( $selectAttribs );
893
894 // Is a namespace selected?
895 if ( isset( $params['selected'] ) ) {
896 // If string only contains digits, convert to clean int. Selected could also
897 // be "all" or "" etc. which needs to be left untouched.
898 // PHP is_numeric() has issues with large strings, PHP ctype_digit has other issues
899 // and returns false for already clean ints. Use regex instead..
900 if ( preg_match( '/^\d+$/', $params['selected'] ) ) {
901 $params['selected'] = intval( $params['selected'] );
902 }
903 // else: leaves it untouched for later processing
904 } else {
905 $params['selected'] = '';
906 }
907
908 if ( !isset( $params['disable'] ) || !is_array( $params['disable'] ) ) {
909 $params['disable'] = [];
910 }
911
912 // Associative array between option-values and option-labels
913 $options = self::namespaceSelectorOptions( $params );
914
915 // Convert $options to HTML
916 $optionsHtml = [];
917 foreach ( $options as $nsId => $nsName ) {
918 $optionsHtml[] = self::element(
919 'option', [
920 'disabled' => in_array( $nsId, $params['disable'] ),
921 'value' => $nsId,
922 'selected' => $nsId === $params['selected'],
923 ], $nsName
924 );
925 }
926
927 if ( !array_key_exists( 'id', $selectAttribs ) ) {
928 $selectAttribs['id'] = 'namespace';
929 }
930
931 if ( !array_key_exists( 'name', $selectAttribs ) ) {
932 $selectAttribs['name'] = 'namespace';
933 }
934
935 $ret = '';
936 if ( isset( $params['label'] ) ) {
937 $ret .= self::element(
938 'label', [
939 'for' => $selectAttribs['id'] ?? null,
940 ], $params['label']
941 ) . "\u{00A0}";
942 }
943
944 // Wrap options in a <select>
945 $ret .= self::openElement( 'select', $selectAttribs )
946 . "\n"
947 . implode( "\n", $optionsHtml )
948 . "\n"
949 . self::closeElement( 'select' );
950
951 return $ret;
952 }
953
962 public static function htmlHeader( array $attribs = [] ) {
963 $ret = '';
964
966
967 $isXHTML = self::isXmlMimeType( $wgMimeType );
968
969 if ( $isXHTML ) { // XHTML5
970 // XML MIME-typed markup should have an xml header.
971 // However a DOCTYPE is not needed.
972 $ret .= "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
973
974 // Add the standard xmlns
975 $attribs['xmlns'] = 'http://www.w3.org/1999/xhtml';
976
977 // And support custom namespaces
978 foreach ( $wgXhtmlNamespaces as $tag => $ns ) {
979 $attribs["xmlns:$tag"] = $ns;
980 }
981 } else { // HTML5
982 $ret .= "<!DOCTYPE html>\n";
983 }
984
985 if ( $wgHtml5Version ) {
986 $attribs['version'] = $wgHtml5Version;
987 }
988
989 $ret .= self::openElement( 'html', $attribs );
990
991 return $ret;
992 }
993
1000 public static function isXmlMimeType( $mimetype ) {
1001 # https://html.spec.whatwg.org/multipage/infrastructure.html#xml-mime-type
1002 # * text/xml
1003 # * application/xml
1004 # * Any MIME type with a subtype ending in +xml (this implicitly includes application/xhtml+xml)
1005 return (bool)preg_match( '!^(text|application)/xml$|^.+/.+\+xml$!', $mimetype );
1006 }
1007
1018 static function infoBox( $text, $icon, $alt, $class = '' ) {
1019 $s = self::openElement( 'div', [ 'class' => "mw-infobox $class" ] );
1020
1021 $s .= self::openElement( 'div', [ 'class' => 'mw-infobox-left' ] ) .
1022 self::element( 'img',
1023 [
1024 'src' => $icon,
1025 'alt' => $alt,
1026 ]
1027 ) .
1028 self::closeElement( 'div' );
1029
1030 $s .= self::openElement( 'div', [ 'class' => 'mw-infobox-right' ] ) .
1031 $text .
1032 self::closeElement( 'div' );
1033 $s .= self::element( 'div', [ 'style' => 'clear: left;' ], ' ' );
1034
1035 $s .= self::closeElement( 'div' );
1036
1037 $s .= self::element( 'div', [ 'style' => 'clear: left;' ], ' ' );
1038
1039 return $s;
1040 }
1041
1065 static function srcSet( array $urls ) {
1066 $candidates = [];
1067 foreach ( $urls as $density => $url ) {
1068 // Cast density to float to strip 'x', then back to string to serve
1069 // as array index.
1070 $density = (string)(float)$density;
1071 $candidates[$density] = $url;
1072 }
1073
1074 // Remove duplicates that are the same as a smaller value
1075 ksort( $candidates, SORT_NUMERIC );
1076 $candidates = array_unique( $candidates );
1077
1078 // Append density info to the url
1079 foreach ( $candidates as $density => $url ) {
1080 $candidates[$density] = $url . ' ' . $density . 'x';
1081 }
1082
1083 return implode( ", ", $candidates );
1084 }
1085}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$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.
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.
$wgLang
Definition Setup.php:875
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:573
static label( $label, $id, array $attribs=[])
Convenience function for generating a label for inputs.
Definition Html.php:781
static textarea( $name, $value='', array $attribs=[])
Convenience function to produce a <textarea> element.
Definition Html.php:813
static infoBox( $text, $icon, $alt, $class='')
Get HTML for an info box with an icon.
Definition Html.php:1018
static namespaceSelectorOptions(array $params=[])
Helper for Html::namespaceSelector().
Definition Html.php:833
static linkedScript( $url, $nonce=null)
Output a "<script>" tag linking to the given URL, e.g., "<script src=foo.js></script>".
Definition Html.php:597
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:110
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:649
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:712
static isXmlMimeType( $mimetype)
Determines if the given MIME type is xml.
Definition Html.php:1000
static linkButton( $contents, 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 htmlHeader(array $attribs=[])
Constructs the opening html-tag with necessary doctypes depending on global variables.
Definition Html.php:962
static input( $name, $value='', $type='text', array $attribs=[])
Convenience function to produce an "<input>" element.
Definition Html.php:668
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 errorBox( $html, $heading='')
Return an error box.
Definition Html.php:736
static $boolAttribs
Definition Html.php:71
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:137
static radio( $name, $checked=false, array $attribs=[])
Convenience function to produce a radio button (input element with type=radio)
Definition Html.php:758
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:210
static warningBox( $html)
Return a warning box.
Definition Html.php:725
static namespaceSelector(array $params=[], array $selectAttribs=[])
Build a drop-down box for selecting a namespace.
Definition Html.php:889
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 successBox( $html)
Return a success box.
Definition Html.php:746
static check( $name, $checked=false, array $attribs=[])
Convenience function to produce a checkbox (input element with type=checkbox)
Definition Html.php:689
static srcSet(array $urls)
Generate a srcset attribute value.
Definition Html.php:1065
static closeElement( $element)
Returns "</$element>".
Definition Html.php:316
static $voidElements
Definition Html.php:51
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition Html.php:797
static inlineStyle( $contents, $media='all', $attribs=[])
Output a "<style>" tag with the given contents for the given media type (if any).
Definition Html.php:620
MediaWiki exception.
MediaWikiServices is the service locator for the application scope of MediaWiki.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
const NS_MAIN
Definition Defines.php:73
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
Definition hooks.txt:181
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition hooks.txt:1999
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition hooks.txt:2003
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt;div ...>$1&lt;/div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition hooks.txt:2011
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:271
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Definition hooks.txt:2012
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
$params
if(!isset( $args[0])) $lang