MediaWiki  master
Html.php
Go to the documentation of this file.
1 <?php
26 
49 class 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 = [] ) {
112  if ( $wgUseMediaWikiUIEverywhere ) {
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 ) {
139  if ( $wgUseMediaWikiUIEverywhere ) {
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  } else {
579  wfWarn( "no nonce set on script. CSP will break it" );
580  }
581  }
582 
583  if ( preg_match( '/<\/?script/i', $contents ) ) {
584  wfLogWarning( __METHOD__ . ': Illegal character sequence found in inline script.' );
585  $contents = '/* ERROR: Invalid script */';
586  }
587 
588  return self::rawElement( 'script', $attrs, $contents );
589  }
590 
599  public static function linkedScript( $url, $nonce = null ) {
600  $attrs = [ 'src' => $url ];
601  if ( $nonce !== null ) {
602  $attrs['nonce'] = $nonce;
603  } else {
605  wfWarn( "no nonce set on script. CSP will break it" );
606  }
607  }
608 
609  return self::element( 'script', $attrs );
610  }
611 
624  public static function inlineStyle( $contents, $media = 'all', $attribs = [] ) {
625  // Don't escape '>' since that is used
626  // as direct child selector.
627  // Remember, in css, there is no "x" for hexadecimal escapes, and
628  // the space immediately after an escape sequence is swallowed.
629  $contents = strtr( $contents, [
630  '<' => '\3C ',
631  // CDATA end tag for good measure, but the main security
632  // is from escaping the '<'.
633  ']]>' => '\5D\5D\3E '
634  ] );
635 
636  if ( preg_match( '/[<&]/', $contents ) ) {
637  $contents = "/*<![CDATA[*/$contents/*]]>*/";
638  }
639 
640  return self::rawElement( 'style', [
641  'media' => $media,
642  ] + $attribs, $contents );
643  }
644 
653  public static function linkedStyle( $url, $media = 'all' ) {
654  return self::element( 'link', [
655  'rel' => 'stylesheet',
656  'href' => $url,
657  'media' => $media,
658  ] );
659  }
660 
672  public static function input( $name, $value = '', $type = 'text', array $attribs = [] ) {
673  $attribs['type'] = $type;
674  $attribs['value'] = $value;
675  $attribs['name'] = $name;
676  if ( in_array( $type, [ 'text', 'search', 'email', 'password', 'number' ] ) ) {
677  $attribs = self::getTextInputAttributes( $attribs );
678  }
679  if ( in_array( $type, [ 'button', 'reset', 'submit' ] ) ) {
680  $attribs = self::buttonAttributes( $attribs );
681  }
682  return self::element( 'input', $attribs );
683  }
684 
693  public static function check( $name, $checked = false, array $attribs = [] ) {
694  if ( isset( $attribs['value'] ) ) {
695  $value = $attribs['value'];
696  unset( $attribs['value'] );
697  } else {
698  $value = 1;
699  }
700 
701  if ( $checked ) {
702  $attribs[] = 'checked';
703  }
704 
705  return self::input( $name, $value, 'checkbox', $attribs );
706  }
707 
716  private static function messageBox( $html, $className, $heading = '' ) {
717  if ( $heading !== '' ) {
718  $html = self::element( 'h2', [], $heading ) . $html;
719  }
720  return self::rawElement( 'div', [ 'class' => $className ], $html );
721  }
722 
729  public static function warningBox( $html ) {
730  return self::messageBox( $html, 'warningbox' );
731  }
732 
740  public static function errorBox( $html, $heading = '' ) {
741  return self::messageBox( $html, 'errorbox', $heading );
742  }
743 
750  public static function successBox( $html ) {
751  return self::messageBox( $html, 'successbox' );
752  }
753 
762  public static function radio( $name, $checked = false, array $attribs = [] ) {
763  if ( isset( $attribs['value'] ) ) {
764  $value = $attribs['value'];
765  unset( $attribs['value'] );
766  } else {
767  $value = 1;
768  }
769 
770  if ( $checked ) {
771  $attribs[] = 'checked';
772  }
773 
774  return self::input( $name, $value, 'radio', $attribs );
775  }
776 
785  public static function label( $label, $id, array $attribs = [] ) {
786  $attribs += [
787  'for' => $id
788  ];
789  return self::element( 'label', $attribs, $label );
790  }
791 
801  public static function hidden( $name, $value, array $attribs = [] ) {
802  return self::input( $name, $value, 'hidden', $attribs );
803  }
804 
817  public static function textarea( $name, $value = '', array $attribs = [] ) {
818  $attribs['name'] = $name;
819 
820  if ( substr( $value, 0, 1 ) == "\n" ) {
821  // Workaround for T14130: browsers eat the initial newline
822  // assuming that it's just for show, but they do keep the later
823  // newlines, which we may want to preserve during editing.
824  // Prepending a single newline
825  $spacedValue = "\n" . $value;
826  } else {
827  $spacedValue = $value;
828  }
829  return self::element( 'textarea', self::getTextInputAttributes( $attribs ), $spacedValue );
830  }
831 
837  public static function namespaceSelectorOptions( array $params = [] ) {
838  $options = [];
839 
840  if ( !isset( $params['exclude'] ) || !is_array( $params['exclude'] ) ) {
841  $params['exclude'] = [];
842  }
843 
844  if ( isset( $params['all'] ) ) {
845  // add an option that would let the user select all namespaces.
846  // Value is provided by user, the name shown is localized for the user.
847  $options[$params['all']] = wfMessage( 'namespacesall' )->text();
848  }
849  if ( $params['in-user-lang'] ?? false ) {
850  global $wgLang;
851  $lang = $wgLang;
852  } else {
853  $lang = MediaWikiServices::getInstance()->getContentLanguage();
854  }
855  // Add all namespaces as options
856  $options += $lang->getFormattedNamespaces();
857 
858  $optionsOut = [];
859  // Filter out namespaces below 0 and massage labels
860  foreach ( $options as $nsId => $nsName ) {
861  if ( $nsId < NS_MAIN || in_array( $nsId, $params['exclude'] ) ) {
862  continue;
863  }
864  if ( $nsId === NS_MAIN ) {
865  // For other namespaces use the namespace prefix as label, but for
866  // main we don't use "" but the user message describing it (e.g. "(Main)" or "(Article)")
867  $nsName = wfMessage( 'blanknamespace' )->text();
868  } elseif ( is_int( $nsId ) ) {
869  $nsName = $lang->convertNamespace( $nsId );
870  }
871  $optionsOut[$nsId] = $nsName;
872  }
873 
874  return $optionsOut;
875  }
876 
893  public static function namespaceSelector( array $params = [],
894  array $selectAttribs = []
895  ) {
896  ksort( $selectAttribs );
897 
898  // Is a namespace selected?
899  if ( isset( $params['selected'] ) ) {
900  // If string only contains digits, convert to clean int. Selected could also
901  // be "all" or "" etc. which needs to be left untouched.
902  // PHP is_numeric() has issues with large strings, PHP ctype_digit has other issues
903  // and returns false for already clean ints. Use regex instead..
904  if ( preg_match( '/^\d+$/', $params['selected'] ) ) {
905  $params['selected'] = intval( $params['selected'] );
906  }
907  // else: leaves it untouched for later processing
908  } else {
909  $params['selected'] = '';
910  }
911 
912  if ( !isset( $params['disable'] ) || !is_array( $params['disable'] ) ) {
913  $params['disable'] = [];
914  }
915 
916  // Associative array between option-values and option-labels
917  $options = self::namespaceSelectorOptions( $params );
918 
919  // Convert $options to HTML
920  $optionsHtml = [];
921  foreach ( $options as $nsId => $nsName ) {
922  $optionsHtml[] = self::element(
923  'option', [
924  'disabled' => in_array( $nsId, $params['disable'] ),
925  'value' => $nsId,
926  'selected' => $nsId === $params['selected'],
927  ], $nsName
928  );
929  }
930 
931  if ( !array_key_exists( 'id', $selectAttribs ) ) {
932  $selectAttribs['id'] = 'namespace';
933  }
934 
935  if ( !array_key_exists( 'name', $selectAttribs ) ) {
936  $selectAttribs['name'] = 'namespace';
937  }
938 
939  $ret = '';
940  if ( isset( $params['label'] ) ) {
941  $ret .= self::element(
942  'label', [
943  'for' => $selectAttribs['id'] ?? null,
944  ], $params['label']
945  ) . "\u{00A0}";
946  }
947 
948  // Wrap options in a <select>
949  $ret .= self::openElement( 'select', $selectAttribs )
950  . "\n"
951  . implode( "\n", $optionsHtml )
952  . "\n"
953  . self::closeElement( 'select' );
954 
955  return $ret;
956  }
957 
966  public static function htmlHeader( array $attribs = [] ) {
967  $ret = '';
968 
970 
971  $isXHTML = self::isXmlMimeType( $wgMimeType );
972 
973  if ( $isXHTML ) { // XHTML5
974  // XML MIME-typed markup should have an xml header.
975  // However a DOCTYPE is not needed.
976  $ret .= "<?xml version=\"1.0\" encoding=\"UTF-8\" ?" . ">\n";
977 
978  // Add the standard xmlns
979  $attribs['xmlns'] = 'http://www.w3.org/1999/xhtml';
980 
981  // And support custom namespaces
982  foreach ( $wgXhtmlNamespaces as $tag => $ns ) {
983  $attribs["xmlns:$tag"] = $ns;
984  }
985  } else { // HTML5
986  // DOCTYPE
987  $ret .= "<!DOCTYPE html>\n";
988  }
989 
990  if ( $wgHtml5Version ) {
991  $attribs['version'] = $wgHtml5Version;
992  }
993 
994  $ret .= self::openElement( 'html', $attribs );
995 
996  return $ret;
997  }
998 
1005  public static function isXmlMimeType( $mimetype ) {
1006  # https://html.spec.whatwg.org/multipage/infrastructure.html#xml-mime-type
1007  # * text/xml
1008  # * application/xml
1009  # * Any MIME type with a subtype ending in +xml (this implicitly includes application/xhtml+xml)
1010  return (bool)preg_match( '!^(text|application)/xml$|^.+/.+\+xml$!', $mimetype );
1011  }
1012 
1023  static function infoBox( $text, $icon, $alt, $class = '' ) {
1024  $s = self::openElement( 'div', [ 'class' => "mw-infobox $class" ] );
1025 
1026  $s .= self::openElement( 'div', [ 'class' => 'mw-infobox-left' ] ) .
1027  self::element( 'img',
1028  [
1029  'src' => $icon,
1030  'alt' => $alt,
1031  ]
1032  ) .
1033  self::closeElement( 'div' );
1034 
1035  $s .= self::openElement( 'div', [ 'class' => 'mw-infobox-right' ] ) .
1036  $text .
1037  self::closeElement( 'div' );
1038  $s .= self::element( 'div', [ 'style' => 'clear: left;' ], ' ' );
1039 
1040  $s .= self::closeElement( 'div' );
1041 
1042  $s .= self::element( 'div', [ 'style' => 'clear: left;' ], ' ' );
1043 
1044  return $s;
1045  }
1046 
1070  static function srcSet( array $urls ) {
1071  $candidates = [];
1072  foreach ( $urls as $density => $url ) {
1073  // Cast density to float to strip 'x', then back to string to serve
1074  // as array index.
1075  $density = (string)(float)$density;
1076  $candidates[$density] = $url;
1077  }
1078 
1079  // Remove duplicates that are the same as a smaller value
1080  ksort( $candidates, SORT_NUMERIC );
1081  $candidates = array_unique( $candidates );
1082 
1083  // Append density info to the url
1084  foreach ( $candidates as $density => $url ) {
1085  $candidates[$density] = $url . ' ' . $density . 'x';
1086  }
1087 
1088  return implode( ", ", $candidates );
1089  }
1090 }
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))
static linkedScript( $url, $nonce=null)
Output a "<script>" tag linking to the given URL, e.g., "<script src=foo.js></script>".
Definition: Html.php:599
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:1995
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
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:653
static radio( $name, $checked=false, array $attribs=[])
Convenience function to produce a radio button (input element with type=radio)
Definition: Html.php:762
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:232
static namespaceSelectorOptions(array $params=[])
Helper for Html::namespaceSelector().
Definition: Html.php:837
const NS_MAIN
Definition: Defines.php:64
static messageBox( $html, $className, $heading='')
Return the HTML for a message box.
Definition: Html.php:716
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:1995
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$wgMimeType
The default Content-Type header.
static $boolAttribs
Definition: Html.php:71
if(!isset( $args[0])) $lang
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing &#39;/&#39;...
Definition: Html.php:252
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:729
static isNonceRequired(Config $config)
Should we set nonce attribute.
$wgHtml5Version
Defines the value of the version attribute in the <html> tag, if any.
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:175
$value
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
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 MediaWikiServices
Definition: injection.txt:23
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
static inlineScript( $contents, $nonce=null)
Output an HTML script tag with the given contents.
Definition: Html.php:573
static textarea( $name, $value='', array $attribs=[])
Convenience function to produce a <textarea> element.
Definition: Html.php:817
static $voidElements
Definition: Html.php:51
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
$wgLang
Definition: Setup.php:909
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
static getMain()
Get the RequestContext object associated with the main request.
$params
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:1995
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:316
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:1995
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
$wgUseMediaWikiUIEverywhere
Temporary variable that applies MediaWiki UI wherever it can be supported.
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 input( $name, $value='', $type='text', array $attribs=[])
Convenience function to produce an "<input>" element.
Definition: Html.php:672
static htmlHeader(array $attribs=[])
Constructs the opening html-tag with necessary doctypes depending on global variables.
Definition: Html.php:966
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
Definition: distributors.txt:9
static check( $name, $checked=false, array $attribs=[])
Convenience function to produce a checkbox (input element with type=checkbox)
Definition: Html.php:693
static srcSet(array $urls)
Generate a srcset attribute value.
Definition: Html.php:1070
static errorBox( $html, $heading='')
Return an error box.
Definition: Html.php:740
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:35
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 encodeAttribute( $text)
Encode an attribute value for HTML output.
Definition: Sanitizer.php:1150
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:801
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 successBox( $html)
Return a success box.
Definition: Html.php:750
$wgXhtmlNamespaces
Permit other namespaces in addition to the w3.org default.
static isXmlMimeType( $mimetype)
Determines if the given MIME type is xml.
Definition: Html.php:1005
static infoBox( $text, $icon, $alt, $class='')
Get HTML for an info box with an icon.
Definition: Html.php:1023
static inlineStyle( $contents, $media='all', $attribs=[])
Output a "<style>" tag with the given contents for the given media type (if any). ...
Definition: Html.php:624
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
static label( $label, $id, array $attribs=[])
Convenience function for generating a label for inputs.
Definition: Html.php:785
static namespaceSelector(array $params=[], array $selectAttribs=[])
Build a drop-down box for selecting a namespace.
Definition: Html.php:893