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