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