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