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 
165  public static function linkButton( $text, array $attrs, array $modifiers = [] ) {
166  return self::element( 'a',
167  self::buttonAttributes( $attrs, $modifiers ),
168  $text
169  );
170  }
171 
185  public static function submitButton( $contents, array $attrs, array $modifiers = [] ) {
186  $attrs['type'] = 'submit';
187  $attrs['value'] = $contents;
188  return self::element( 'input', self::buttonAttributes( $attrs, $modifiers ) );
189  }
190 
209  public static function rawElement( $element, $attribs = [], $contents = '' ) {
210  $start = self::openElement( $element, $attribs );
211  if ( in_array( $element, self::$voidElements ) ) {
212  // Silly XML.
213  return substr( $start, 0, -1 ) . '/>';
214  } else {
215  return $start . $contents . self::closeElement( $element );
216  }
217  }
218 
231  public static function element( $element, $attribs = [], $contents = '' ) {
232  return self::rawElement( $element, $attribs, strtr( $contents, [
233  // There's no point in escaping quotes, >, etc. in the contents of
234  // elements.
235  '&' => '&amp;',
236  '<' => '&lt;'
237  ] ) );
238  }
239 
251  public static function openElement( $element, $attribs = [] ) {
252  $attribs = (array)$attribs;
253  // This is not required in HTML5, but let's do it anyway, for
254  // consistency and better compression.
255  $element = strtolower( $element );
256 
257  // Some people were abusing this by passing things like
258  // 'h1 id="foo" to $element, which we don't want.
259  if ( strpos( $element, ' ' ) !== false ) {
260  wfWarn( __METHOD__ . " given element name with space '$element'" );
261  }
262 
263  // Remove invalid input types
264  if ( $element == 'input' ) {
265  $validTypes = [
266  'hidden',
267  'text',
268  'password',
269  'checkbox',
270  'radio',
271  'file',
272  'submit',
273  'image',
274  'reset',
275  'button',
276 
277  // HTML input types
278  'datetime',
279  'datetime-local',
280  'date',
281  'month',
282  'time',
283  'week',
284  'number',
285  'range',
286  'email',
287  'url',
288  'search',
289  'tel',
290  'color',
291  ];
292  if ( isset( $attribs['type'] ) && !in_array( $attribs['type'], $validTypes ) ) {
293  unset( $attribs['type'] );
294  }
295  }
296 
297  // According to standard the default type for <button> elements is "submit".
298  // Depending on compatibility mode IE might use "button", instead.
299  // We enforce the standard "submit".
300  if ( $element == 'button' && !isset( $attribs['type'] ) ) {
301  $attribs['type'] = 'submit';
302  }
303 
304  return "<$element" . self::expandAttributes(
305  self::dropDefaults( $element, $attribs ) ) . '>';
306  }
307 
315  public static function closeElement( $element ) {
316  $element = strtolower( $element );
317 
318  return "</$element>";
319  }
320 
338  private static function dropDefaults( $element, array $attribs ) {
339  // Whenever altering this array, please provide a covering test case
340  // in HtmlTest::provideElementsWithAttributesHavingDefaultValues
341  static $attribDefaults = [
342  'area' => [ 'shape' => 'rect' ],
343  'button' => [
344  'formaction' => 'GET',
345  'formenctype' => 'application/x-www-form-urlencoded',
346  ],
347  'canvas' => [
348  'height' => '150',
349  'width' => '300',
350  ],
351  'form' => [
352  'action' => 'GET',
353  'autocomplete' => 'on',
354  'enctype' => 'application/x-www-form-urlencoded',
355  ],
356  'input' => [
357  'formaction' => 'GET',
358  'type' => 'text',
359  ],
360  'keygen' => [ 'keytype' => 'rsa' ],
361  'link' => [ 'media' => 'all' ],
362  'menu' => [ 'type' => 'list' ],
363  'script' => [ 'type' => 'text/javascript' ],
364  'style' => [
365  'media' => 'all',
366  'type' => 'text/css',
367  ],
368  'textarea' => [ 'wrap' => 'soft' ],
369  ];
370 
371  $element = strtolower( $element );
372 
373  foreach ( $attribs as $attrib => $value ) {
374  $lcattrib = strtolower( $attrib );
375  if ( is_array( $value ) ) {
376  $value = implode( ' ', $value );
377  } else {
378  $value = strval( $value );
379  }
380 
381  // Simple checks using $attribDefaults
382  if ( isset( $attribDefaults[$element][$lcattrib] )
383  && $attribDefaults[$element][$lcattrib] == $value
384  ) {
385  unset( $attribs[$attrib] );
386  }
387 
388  if ( $lcattrib == 'class' && $value == '' ) {
389  unset( $attribs[$attrib] );
390  }
391  }
392 
393  // More subtle checks
394  if ( $element === 'link'
395  && isset( $attribs['type'] ) && strval( $attribs['type'] ) == 'text/css'
396  ) {
397  unset( $attribs['type'] );
398  }
399  if ( $element === 'input' ) {
400  $type = $attribs['type'] ?? null;
401  $value = $attribs['value'] ?? null;
402  if ( $type === 'checkbox' || $type === 'radio' ) {
403  // The default value for checkboxes and radio buttons is 'on'
404  // not ''. By stripping value="" we break radio boxes that
405  // actually wants empty values.
406  if ( $value === 'on' ) {
407  unset( $attribs['value'] );
408  }
409  } elseif ( $type === 'submit' ) {
410  // The default value for submit appears to be "Submit" but
411  // let's not bother stripping out localized text that matches
412  // that.
413  } else {
414  // The default value for nearly every other field type is ''
415  // The 'range' and 'color' types use different defaults but
416  // stripping a value="" does not hurt them.
417  if ( $value === '' ) {
418  unset( $attribs['value'] );
419  }
420  }
421  }
422  if ( $element === 'select' && isset( $attribs['size'] ) ) {
423  if ( in_array( 'multiple', $attribs )
424  || ( isset( $attribs['multiple'] ) && $attribs['multiple'] !== false )
425  ) {
426  // A multi-select
427  if ( strval( $attribs['size'] ) == '4' ) {
428  unset( $attribs['size'] );
429  }
430  } else {
431  // Single select
432  if ( strval( $attribs['size'] ) == '1' ) {
433  unset( $attribs['size'] );
434  }
435  }
436  }
437 
438  return $attribs;
439  }
440 
480  public static function expandAttributes( array $attribs ) {
481  $ret = '';
482  foreach ( $attribs as $key => $value ) {
483  // Support intuitive [ 'checked' => true/false ] form
484  if ( $value === false || is_null( $value ) ) {
485  continue;
486  }
487 
488  // For boolean attributes, support [ 'foo' ] instead of
489  // requiring [ 'foo' => 'meaningless' ].
490  if ( is_int( $key ) && in_array( strtolower( $value ), self::$boolAttribs ) ) {
491  $key = $value;
492  }
493 
494  // Not technically required in HTML5 but we'd like consistency
495  // and better compression anyway.
496  $key = strtolower( $key );
497 
498  // https://www.w3.org/TR/html401/index/attributes.html ("space-separated")
499  // https://www.w3.org/TR/html5/index.html#attributes-1 ("space-separated")
500  $spaceSeparatedListAttributes = [
501  'class', // html4, html5
502  'accesskey', // as of html5, multiple space-separated values allowed
503  // html4-spec doesn't document rel= as space-separated
504  // but has been used like that and is now documented as such
505  // in the html5-spec.
506  'rel',
507  ];
508 
509  // Specific features for attributes that allow a list of space-separated values
510  if ( in_array( $key, $spaceSeparatedListAttributes ) ) {
511  // Apply some normalization and remove duplicates
512 
513  // Convert into correct array. Array can contain space-separated
514  // values. Implode/explode to get those into the main array as well.
515  if ( is_array( $value ) ) {
516  // If input wasn't an array, we can skip this step
517  $newValue = [];
518  foreach ( $value as $k => $v ) {
519  if ( is_string( $v ) ) {
520  // String values should be normal `[ 'foo' ]`
521  // Just append them
522  if ( !isset( $value[$v] ) ) {
523  // As a special case don't set 'foo' if a
524  // separate 'foo' => true/false exists in the array
525  // keys should be authoritative
526  $newValue[] = $v;
527  }
528  } elseif ( $v ) {
529  // If the value is truthy but not a string this is likely
530  // an [ 'foo' => true ], falsy values don't add strings
531  $newValue[] = $k;
532  }
533  }
534  $value = implode( ' ', $newValue );
535  }
536  $value = explode( ' ', $value );
537 
538  // Normalize spacing by fixing up cases where people used
539  // more than 1 space and/or a trailing/leading space
540  $value = array_diff( $value, [ '', ' ' ] );
541 
542  // Remove duplicates and create the string
543  $value = implode( ' ', array_unique( $value ) );
544  } elseif ( is_array( $value ) ) {
545  throw new MWException( "HTML attribute $key can not contain a list of values" );
546  }
547 
548  $quote = '"';
549 
550  if ( in_array( $key, self::$boolAttribs ) ) {
551  $ret .= " $key=\"\"";
552  } else {
553  $ret .= " $key=$quote" . Sanitizer::encodeAttribute( $value ) . $quote;
554  }
555  }
556  return $ret;
557  }
558 
572  public static function inlineScript( $contents, $nonce = null ) {
573  $attrs = [];
574  if ( $nonce !== null ) {
575  $attrs['nonce'] = $nonce;
576  } elseif ( ContentSecurityPolicy::isNonceRequired( RequestContext::getMain()->getConfig() ) ) {
577  wfWarn( "no nonce set on script. CSP will break it" );
578  }
579 
580  if ( preg_match( '/<\/?script/i', $contents ) ) {
581  wfLogWarning( __METHOD__ . ': Illegal character sequence found in inline script.' );
582  $contents = '/* ERROR: Invalid script */';
583  }
584 
585  return self::rawElement( 'script', $attrs, $contents );
586  }
587 
596  public static function linkedScript( $url, $nonce = null ) {
597  $attrs = [ 'src' => $url ];
598  if ( $nonce !== null ) {
599  $attrs['nonce'] = $nonce;
600  } elseif ( ContentSecurityPolicy::isNonceRequired( RequestContext::getMain()->getConfig() ) ) {
601  wfWarn( "no nonce set on script. CSP will break it" );
602  }
603 
604  return self::element( 'script', $attrs );
605  }
606 
619  public static function inlineStyle( $contents, $media = 'all', $attribs = [] ) {
620  // Don't escape '>' since that is used
621  // as direct child selector.
622  // Remember, in css, there is no "x" for hexadecimal escapes, and
623  // the space immediately after an escape sequence is swallowed.
624  $contents = strtr( $contents, [
625  '<' => '\3C ',
626  // CDATA end tag for good measure, but the main security
627  // is from escaping the '<'.
628  ']]>' => '\5D\5D\3E '
629  ] );
630 
631  if ( preg_match( '/[<&]/', $contents ) ) {
632  $contents = "/*<![CDATA[*/$contents/*]]>*/";
633  }
634 
635  return self::rawElement( 'style', [
636  'media' => $media,
637  ] + $attribs, $contents );
638  }
639 
648  public static function linkedStyle( $url, $media = 'all' ) {
649  return self::element( 'link', [
650  'rel' => 'stylesheet',
651  'href' => $url,
652  'media' => $media,
653  ] );
654  }
655 
667  public static function input( $name, $value = '', $type = 'text', array $attribs = [] ) {
668  $attribs['type'] = $type;
669  $attribs['value'] = $value;
670  $attribs['name'] = $name;
671  if ( in_array( $type, [ 'text', 'search', 'email', 'password', 'number' ] ) ) {
672  $attribs = self::getTextInputAttributes( $attribs );
673  }
674  if ( in_array( $type, [ 'button', 'reset', 'submit' ] ) ) {
675  $attribs = self::buttonAttributes( $attribs );
676  }
677  return self::element( 'input', $attribs );
678  }
679 
688  public static function check( $name, $checked = false, array $attribs = [] ) {
689  if ( isset( $attribs['value'] ) ) {
690  $value = $attribs['value'];
691  unset( $attribs['value'] );
692  } else {
693  $value = 1;
694  }
695 
696  if ( $checked ) {
697  $attribs[] = 'checked';
698  }
699 
700  return self::input( $name, $value, 'checkbox', $attribs );
701  }
702 
711  private static function messageBox( $html, $className, $heading = '' ) {
712  if ( $heading !== '' ) {
713  $html = self::element( 'h2', [], $heading ) . $html;
714  }
715  return self::rawElement( 'div', [ 'class' => $className ], $html );
716  }
717 
724  public static function warningBox( $html ) {
725  return self::messageBox( $html, 'warningbox' );
726  }
727 
735  public static function errorBox( $html, $heading = '' ) {
736  return self::messageBox( $html, 'errorbox', $heading );
737  }
738 
745  public static function successBox( $html ) {
746  return self::messageBox( $html, 'successbox' );
747  }
748 
757  public static function radio( $name, $checked = false, array $attribs = [] ) {
758  if ( isset( $attribs['value'] ) ) {
759  $value = $attribs['value'];
760  unset( $attribs['value'] );
761  } else {
762  $value = 1;
763  }
764 
765  if ( $checked ) {
766  $attribs[] = 'checked';
767  }
768 
769  return self::input( $name, $value, 'radio', $attribs );
770  }
771 
780  public static function label( $label, $id, array $attribs = [] ) {
781  $attribs += [
782  'for' => $id
783  ];
784  return self::element( 'label', $attribs, $label );
785  }
786 
796  public static function hidden( $name, $value, array $attribs = [] ) {
797  return self::input( $name, $value, 'hidden', $attribs );
798  }
799 
812  public static function textarea( $name, $value = '', array $attribs = [] ) {
813  $attribs['name'] = $name;
814 
815  if ( substr( $value, 0, 1 ) == "\n" ) {
816  // Workaround for T14130: browsers eat the initial newline
817  // assuming that it's just for show, but they do keep the later
818  // newlines, which we may want to preserve during editing.
819  // Prepending a single newline
820  $spacedValue = "\n" . $value;
821  } else {
822  $spacedValue = $value;
823  }
824  return self::element( 'textarea', self::getTextInputAttributes( $attribs ), $spacedValue );
825  }
826 
832  public static function namespaceSelectorOptions( array $params = [] ) {
833  if ( !isset( $params['exclude'] ) || !is_array( $params['exclude'] ) ) {
834  $params['exclude'] = [];
835  }
836 
837  if ( $params['in-user-lang'] ?? false ) {
838  global $wgLang;
839  $lang = $wgLang;
840  } else {
841  $lang = MediaWikiServices::getInstance()->getContentLanguage();
842  }
843 
844  $optionsOut = [];
845  if ( isset( $params['all'] ) ) {
846  // add an option that would let the user select all namespaces.
847  // Value is provided by user, the name shown is localized for the user.
848  $optionsOut[$params['all']] = wfMessage( 'namespacesall' )->text();
849  }
850  // Add all namespaces as options
851  $options = $lang->getFormattedNamespaces();
852  // Filter out namespaces below 0 and massage labels
853  foreach ( $options as $nsId => $nsName ) {
854  if ( $nsId < NS_MAIN || in_array( $nsId, $params['exclude'] ) ) {
855  continue;
856  }
857  if ( $nsId === NS_MAIN ) {
858  // For other namespaces use the namespace prefix as label, but for
859  // main we don't use "" but the user message describing it (e.g. "(Main)" or "(Article)")
860  $nsName = wfMessage( 'blanknamespace' )->text();
861  } elseif ( is_int( $nsId ) ) {
862  $nsName = $lang->convertNamespace( $nsId );
863  }
864  $optionsOut[$nsId] = $nsName;
865  }
866 
867  return $optionsOut;
868  }
869 
886  public static function namespaceSelector( array $params = [],
887  array $selectAttribs = []
888  ) {
889  ksort( $selectAttribs );
890 
891  // Is a namespace selected?
892  if ( isset( $params['selected'] ) ) {
893  // If string only contains digits, convert to clean int. Selected could also
894  // be "all" or "" etc. which needs to be left untouched.
895  // PHP is_numeric() has issues with large strings, PHP ctype_digit has other issues
896  // and returns false for already clean ints. Use regex instead..
897  if ( preg_match( '/^\d+$/', $params['selected'] ) ) {
898  $params['selected'] = intval( $params['selected'] );
899  }
900  // else: leaves it untouched for later processing
901  } else {
902  $params['selected'] = '';
903  }
904 
905  if ( !isset( $params['disable'] ) || !is_array( $params['disable'] ) ) {
906  $params['disable'] = [];
907  }
908 
909  // Associative array between option-values and option-labels
910  $options = self::namespaceSelectorOptions( $params );
911 
912  // Convert $options to HTML
913  $optionsHtml = [];
914  foreach ( $options as $nsId => $nsName ) {
915  $optionsHtml[] = self::element(
916  'option', [
917  'disabled' => in_array( $nsId, $params['disable'] ),
918  'value' => $nsId,
919  'selected' => $nsId === $params['selected'],
920  ], $nsName
921  );
922  }
923 
924  if ( !array_key_exists( 'id', $selectAttribs ) ) {
925  $selectAttribs['id'] = 'namespace';
926  }
927 
928  if ( !array_key_exists( 'name', $selectAttribs ) ) {
929  $selectAttribs['name'] = 'namespace';
930  }
931 
932  $ret = '';
933  if ( isset( $params['label'] ) ) {
934  $ret .= self::element(
935  'label', [
936  'for' => $selectAttribs['id'] ?? null,
937  ], $params['label']
938  ) . "\u{00A0}";
939  }
940 
941  // Wrap options in a <select>
942  $ret .= self::openElement( 'select', $selectAttribs )
943  . "\n"
944  . implode( "\n", $optionsHtml )
945  . "\n"
946  . self::closeElement( 'select' );
947 
948  return $ret;
949  }
950 
959  public static function htmlHeader( array $attribs = [] ) {
960  $ret = '';
961 
963 
964  $isXHTML = self::isXmlMimeType( $wgMimeType );
965 
966  if ( $isXHTML ) { // XHTML5
967  // XML MIME-typed markup should have an xml header.
968  // However a DOCTYPE is not needed.
969  $ret .= "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
970 
971  // Add the standard xmlns
972  $attribs['xmlns'] = 'http://www.w3.org/1999/xhtml';
973 
974  // And support custom namespaces
975  foreach ( $wgXhtmlNamespaces as $tag => $ns ) {
976  $attribs["xmlns:$tag"] = $ns;
977  }
978  } else { // HTML5
979  $ret .= "<!DOCTYPE html>\n";
980  }
981 
982  if ( $wgHtml5Version ) {
983  $attribs['version'] = $wgHtml5Version;
984  }
985 
986  $ret .= self::openElement( 'html', $attribs );
987 
988  return $ret;
989  }
990 
997  public static function isXmlMimeType( $mimetype ) {
998  # https://html.spec.whatwg.org/multipage/infrastructure.html#xml-mime-type
999  # * text/xml
1000  # * application/xml
1001  # * Any MIME type with a subtype ending in +xml (this implicitly includes application/xhtml+xml)
1002  return (bool)preg_match( '!^(text|application)/xml$|^.+/.+\+xml$!', $mimetype );
1003  }
1004 
1015  public static function infoBox( $rawHtml, $icon, $alt, $class = '' ) {
1016  $s = self::openElement( 'div', [ 'class' => "mw-infobox $class" ] );
1017 
1018  $s .= self::openElement( 'div', [ 'class' => 'mw-infobox-left' ] ) .
1019  self::element( 'img',
1020  [
1021  'src' => $icon,
1022  'alt' => $alt,
1023  ]
1024  ) .
1025  self::closeElement( 'div' );
1026 
1027  $s .= self::openElement( 'div', [ 'class' => 'mw-infobox-right' ] ) .
1028  $rawHtml .
1029  self::closeElement( 'div' );
1030  $s .= self::element( 'div', [ 'style' => 'clear: left;' ], ' ' );
1031 
1032  $s .= self::closeElement( 'div' );
1033 
1034  $s .= self::element( 'div', [ 'style' => 'clear: left;' ], ' ' );
1035 
1036  return $s;
1037  }
1038 
1062  static function srcSet( array $urls ) {
1063  $candidates = [];
1064  foreach ( $urls as $density => $url ) {
1065  // Cast density to float to strip 'x', then back to string to serve
1066  // as array index.
1067  $density = (string)(float)$density;
1068  $candidates[$density] = $url;
1069  }
1070 
1071  // Remove duplicates that are the same as a smaller value
1072  ksort( $candidates, SORT_NUMERIC );
1073  $candidates = array_unique( $candidates );
1074 
1075  // Append density info to the url
1076  foreach ( $candidates as $density => $url ) {
1077  $candidates[$density] = $url . ' ' . $density . 'x';
1078  }
1079 
1080  return implode( ", ", $candidates );
1081  }
1082 }
static linkedScript( $url, $nonce=null)
Output a "<script>" tag linking to the given URL, e.g., "<script src=foo.js></script>".
Definition: Html.php:596
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:1971
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:648
static radio( $name, $checked=false, array $attribs=[])
Convenience function to produce a radio button (input element with type=radio)
Definition: Html.php:757
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
static namespaceSelectorOptions(array $params=[])
Helper for Html::namespaceSelector().
Definition: Html.php:832
const NS_MAIN
Definition: Defines.php:60
static messageBox( $html, $className, $heading='')
Return the HTML for a message box.
Definition: Html.php:711
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:1971
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:251
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
static warningBox( $html)
Return a warning box.
Definition: Html.php:724
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
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:572
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:165
static textarea( $name, $value='', array $attribs=[])
Convenience function to produce a <textarea> element.
Definition: Html.php:812
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:185
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:940
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:1971
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:315
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:1971
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:767
$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:480
static input( $name, $value='', $type='text', array $attribs=[])
Convenience function to produce an "<input>" element.
Definition: Html.php:667
static htmlHeader(array $attribs=[])
Constructs the opening html-tag with necessary doctypes depending on global variables.
Definition: Html.php:959
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:688
static srcSet(array $urls)
Generate a srcset attribute value.
Definition: Html.php:1062
static errorBox( $html, $heading='')
Return an error box.
Definition: Html.php:735
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:338
static encodeAttribute( $text)
Encode an attribute value for HTML output.
Definition: Sanitizer.php:1156
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:796
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:745
static infoBox( $rawHtml, $icon, $alt, $class='')
Get HTML for an information message box with an icon.
Definition: Html.php:1015
$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:997
static inlineStyle( $contents, $media='all', $attribs=[])
Output a "<style>" tag with the given contents for the given media type (if any). ...
Definition: Html.php:619
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:780
static namespaceSelector(array $params=[], array $selectAttribs=[])
Build a drop-down box for selecting a namespace.
Definition: Html.php:886