MediaWiki  1.29.2
Html.php
Go to the documentation of this file.
1 <?php
48 class Html {
49  // List of void elements from HTML5, section 8.1.2 as of 2016-09-19
50  private static $voidElements = [
51  'area',
52  'base',
53  'br',
54  'col',
55  'embed',
56  'hr',
57  'img',
58  'input',
59  'keygen',
60  'link',
61  'meta',
62  'param',
63  'source',
64  'track',
65  'wbr',
66  ];
67 
68  // Boolean attributes, which may have the value omitted entirely. Manually
69  // collected from the HTML5 spec as of 2011-08-12.
70  private static $boolAttribs = [
71  'async',
72  'autofocus',
73  'autoplay',
74  'checked',
75  'controls',
76  'default',
77  'defer',
78  'disabled',
79  'formnovalidate',
80  'hidden',
81  'ismap',
82  'itemscope',
83  'loop',
84  'multiple',
85  'muted',
86  'novalidate',
87  'open',
88  'pubdate',
89  'readonly',
90  'required',
91  'reversed',
92  'scoped',
93  'seamless',
94  'selected',
95  'truespeed',
96  'typemustmatch',
97  // HTML5 Microdata
98  'itemscope',
99  ];
100 
109  public static function buttonAttributes( array $attrs, array $modifiers = [] ) {
110  global $wgUseMediaWikiUIEverywhere;
111  if ( $wgUseMediaWikiUIEverywhere ) {
112  if ( isset( $attrs['class'] ) ) {
113  if ( is_array( $attrs['class'] ) ) {
114  $attrs['class'][] = 'mw-ui-button';
115  $attrs['class'] = array_merge( $attrs['class'], $modifiers );
116  // ensure compatibility with Xml
117  $attrs['class'] = implode( ' ', $attrs['class'] );
118  } else {
119  $attrs['class'] .= ' mw-ui-button ' . implode( ' ', $modifiers );
120  }
121  } else {
122  // ensure compatibility with Xml
123  $attrs['class'] = 'mw-ui-button ' . implode( ' ', $modifiers );
124  }
125  }
126  return $attrs;
127  }
128 
136  public static function getTextInputAttributes( array $attrs ) {
137  global $wgUseMediaWikiUIEverywhere;
138  if ( $wgUseMediaWikiUIEverywhere ) {
139  if ( isset( $attrs['class'] ) ) {
140  if ( is_array( $attrs['class'] ) ) {
141  $attrs['class'][] = 'mw-ui-input';
142  } else {
143  $attrs['class'] .= ' mw-ui-input';
144  }
145  } else {
146  $attrs['class'] = 'mw-ui-input';
147  }
148  }
149  return $attrs;
150  }
151 
165  public static function linkButton( $contents, array $attrs, array $modifiers = [] ) {
166  return self::element( 'a',
167  self::buttonAttributes( $attrs, $modifiers ),
168  $contents
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 = [] ) {
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  // Remove invalid input types
258  if ( $element == 'input' ) {
259  $validTypes = [
260  'hidden',
261  'text',
262  'password',
263  'checkbox',
264  'radio',
265  'file',
266  'submit',
267  'image',
268  'reset',
269  'button',
270 
271  // HTML input types
272  'datetime',
273  'datetime-local',
274  'date',
275  'month',
276  'time',
277  'week',
278  'number',
279  'range',
280  'email',
281  'url',
282  'search',
283  'tel',
284  'color',
285  ];
286  if ( isset( $attribs['type'] ) && !in_array( $attribs['type'], $validTypes ) ) {
287  unset( $attribs['type'] );
288  }
289  }
290 
291  // According to standard the default type for <button> elements is "submit".
292  // Depending on compatibility mode IE might use "button", instead.
293  // We enforce the standard "submit".
294  if ( $element == 'button' && !isset( $attribs['type'] ) ) {
295  $attribs['type'] = 'submit';
296  }
297 
298  return "<$element" . self::expandAttributes(
299  self::dropDefaults( $element, $attribs ) ) . '>';
300  }
301 
309  public static function closeElement( $element ) {
310  $element = strtolower( $element );
311 
312  return "</$element>";
313  }
314 
332  private static function dropDefaults( $element, array $attribs ) {
333  // Whenever altering this array, please provide a covering test case
334  // in HtmlTest::provideElementsWithAttributesHavingDefaultValues
335  static $attribDefaults = [
336  'area' => [ 'shape' => 'rect' ],
337  'button' => [
338  'formaction' => 'GET',
339  'formenctype' => 'application/x-www-form-urlencoded',
340  ],
341  'canvas' => [
342  'height' => '150',
343  'width' => '300',
344  ],
345  'form' => [
346  'action' => 'GET',
347  'autocomplete' => 'on',
348  'enctype' => 'application/x-www-form-urlencoded',
349  ],
350  'input' => [
351  'formaction' => 'GET',
352  'type' => 'text',
353  ],
354  'keygen' => [ 'keytype' => 'rsa' ],
355  'link' => [ 'media' => 'all' ],
356  'menu' => [ 'type' => 'list' ],
357  'script' => [ 'type' => 'text/javascript' ],
358  'style' => [
359  'media' => 'all',
360  'type' => 'text/css',
361  ],
362  'textarea' => [ 'wrap' => 'soft' ],
363  ];
364 
365  $element = strtolower( $element );
366 
367  foreach ( $attribs as $attrib => $value ) {
368  $lcattrib = strtolower( $attrib );
369  if ( is_array( $value ) ) {
370  $value = implode( ' ', $value );
371  } else {
372  $value = strval( $value );
373  }
374 
375  // Simple checks using $attribDefaults
376  if ( isset( $attribDefaults[$element][$lcattrib] )
377  && $attribDefaults[$element][$lcattrib] == $value
378  ) {
379  unset( $attribs[$attrib] );
380  }
381 
382  if ( $lcattrib == 'class' && $value == '' ) {
383  unset( $attribs[$attrib] );
384  }
385  }
386 
387  // More subtle checks
388  if ( $element === 'link'
389  && isset( $attribs['type'] ) && strval( $attribs['type'] ) == 'text/css'
390  ) {
391  unset( $attribs['type'] );
392  }
393  if ( $element === 'input' ) {
394  $type = isset( $attribs['type'] ) ? $attribs['type'] : null;
395  $value = isset( $attribs['value'] ) ? $attribs['value'] : null;
396  if ( $type === 'checkbox' || $type === 'radio' ) {
397  // The default value for checkboxes and radio buttons is 'on'
398  // not ''. By stripping value="" we break radio boxes that
399  // actually wants empty values.
400  if ( $value === 'on' ) {
401  unset( $attribs['value'] );
402  }
403  } elseif ( $type === 'submit' ) {
404  // The default value for submit appears to be "Submit" but
405  // let's not bother stripping out localized text that matches
406  // that.
407  } else {
408  // The default value for nearly every other field type is ''
409  // The 'range' and 'color' types use different defaults but
410  // stripping a value="" does not hurt them.
411  if ( $value === '' ) {
412  unset( $attribs['value'] );
413  }
414  }
415  }
416  if ( $element === 'select' && isset( $attribs['size'] ) ) {
417  if ( in_array( 'multiple', $attribs )
418  || ( isset( $attribs['multiple'] ) && $attribs['multiple'] !== false )
419  ) {
420  // A multi-select
421  if ( strval( $attribs['size'] ) == '4' ) {
422  unset( $attribs['size'] );
423  }
424  } else {
425  // Single select
426  if ( strval( $attribs['size'] ) == '1' ) {
427  unset( $attribs['size'] );
428  }
429  }
430  }
431 
432  return $attribs;
433  }
434 
474  public static function expandAttributes( array $attribs ) {
475  $ret = '';
476  foreach ( $attribs as $key => $value ) {
477  // Support intuitive [ 'checked' => true/false ] form
478  if ( $value === false || is_null( $value ) ) {
479  continue;
480  }
481 
482  // For boolean attributes, support [ 'foo' ] instead of
483  // requiring [ 'foo' => 'meaningless' ].
484  if ( is_int( $key ) && in_array( strtolower( $value ), self::$boolAttribs ) ) {
485  $key = $value;
486  }
487 
488  // Not technically required in HTML5 but we'd like consistency
489  // and better compression anyway.
490  $key = strtolower( $key );
491 
492  // https://www.w3.org/TR/html401/index/attributes.html ("space-separated")
493  // https://www.w3.org/TR/html5/index.html#attributes-1 ("space-separated")
494  $spaceSeparatedListAttributes = [
495  'class', // html4, html5
496  'accesskey', // as of html5, multiple space-separated values allowed
497  // html4-spec doesn't document rel= as space-separated
498  // but has been used like that and is now documented as such
499  // in the html5-spec.
500  'rel',
501  ];
502 
503  // Specific features for attributes that allow a list of space-separated values
504  if ( in_array( $key, $spaceSeparatedListAttributes ) ) {
505  // Apply some normalization and remove duplicates
506 
507  // Convert into correct array. Array can contain space-separated
508  // values. Implode/explode to get those into the main array as well.
509  if ( is_array( $value ) ) {
510  // If input wasn't an array, we can skip this step
511  $newValue = [];
512  foreach ( $value as $k => $v ) {
513  if ( is_string( $v ) ) {
514  // String values should be normal `array( 'foo' )`
515  // Just append them
516  if ( !isset( $value[$v] ) ) {
517  // As a special case don't set 'foo' if a
518  // separate 'foo' => true/false exists in the array
519  // keys should be authoritative
520  $newValue[] = $v;
521  }
522  } elseif ( $v ) {
523  // If the value is truthy but not a string this is likely
524  // an [ 'foo' => true ], falsy values don't add strings
525  $newValue[] = $k;
526  }
527  }
528  $value = implode( ' ', $newValue );
529  }
530  $value = explode( ' ', $value );
531 
532  // Normalize spacing by fixing up cases where people used
533  // more than 1 space and/or a trailing/leading space
534  $value = array_diff( $value, [ '', ' ' ] );
535 
536  // Remove duplicates and create the string
537  $value = implode( ' ', array_unique( $value ) );
538  } elseif ( is_array( $value ) ) {
539  throw new MWException( "HTML attribute $key can not contain a list of values" );
540  }
541 
542  $quote = '"';
543 
544  if ( in_array( $key, self::$boolAttribs ) ) {
545  $ret .= " $key=\"\"";
546  } else {
547  // Apparently we need to entity-encode \n, \r, \t, although the
548  // spec doesn't mention that. Since we're doing strtr() anyway,
549  // we may as well not call htmlspecialchars().
550  // @todo FIXME: Verify that we actually need to
551  // escape \n\r\t here, and explain why, exactly.
552  // We could call Sanitizer::encodeAttribute() for this, but we
553  // don't because we're stubborn and like our marginal savings on
554  // byte size from not having to encode unnecessary quotes.
555  // The only difference between this transform and the one by
556  // Sanitizer::encodeAttribute() is ' is not encoded.
557  $map = [
558  '&' => '&amp;',
559  '"' => '&quot;',
560  '>' => '&gt;',
561  // '<' allegedly allowed per spec
562  // but breaks some tools if not escaped.
563  "<" => '&lt;',
564  "\n" => '&#10;',
565  "\r" => '&#13;',
566  "\t" => '&#9;'
567  ];
568  $ret .= " $key=$quote" . strtr( $value, $map ) . $quote;
569  }
570  }
571  return $ret;
572  }
573 
583  public static function inlineScript( $contents ) {
584  $attrs = [];
585 
586  if ( preg_match( '/[<&]/', $contents ) ) {
587  $contents = "/*<![CDATA[*/$contents/*]]>*/";
588  }
589 
590  return self::rawElement( 'script', $attrs, $contents );
591  }
592 
600  public static function linkedScript( $url ) {
601  $attrs = [ 'src' => $url ];
602 
603  return self::element( 'script', $attrs );
604  }
605 
615  public static function inlineStyle( $contents, $media = 'all' ) {
616  // Don't escape '>' since that is used
617  // as direct child selector.
618  // Remember, in css, there is no "x" for hexadecimal escapes, and
619  // the space immediately after an escape sequence is swallowed.
620  $contents = strtr( $contents, [
621  '<' => '\3C ',
622  // CDATA end tag for good measure, but the main security
623  // is from escaping the '<'.
624  ']]>' => '\5D\5D\3E '
625  ] );
626 
627  if ( preg_match( '/[<&]/', $contents ) ) {
628  $contents = "/*<![CDATA[*/$contents/*]]>*/";
629  }
630 
631  return self::rawElement( 'style', [
632  'media' => $media,
633  ], $contents );
634  }
635 
644  public static function linkedStyle( $url, $media = 'all' ) {
645  return self::element( 'link', [
646  'rel' => 'stylesheet',
647  'href' => $url,
648  'media' => $media,
649  ] );
650  }
651 
663  public static function input( $name, $value = '', $type = 'text', array $attribs = [] ) {
664  $attribs['type'] = $type;
665  $attribs['value'] = $value;
666  $attribs['name'] = $name;
667  if ( in_array( $type, [ 'text', 'search', 'email', 'password', 'number' ] ) ) {
669  }
670  if ( in_array( $type, [ 'button', 'reset', 'submit' ] ) ) {
672  }
673  return self::element( 'input', $attribs );
674  }
675 
684  public static function check( $name, $checked = false, array $attribs = [] ) {
685  if ( isset( $attribs['value'] ) ) {
686  $value = $attribs['value'];
687  unset( $attribs['value'] );
688  } else {
689  $value = 1;
690  }
691 
692  if ( $checked ) {
693  $attribs[] = 'checked';
694  }
695 
696  return self::input( $name, $value, 'checkbox', $attribs );
697  }
698 
707  public static function radio( $name, $checked = false, array $attribs = [] ) {
708  if ( isset( $attribs['value'] ) ) {
709  $value = $attribs['value'];
710  unset( $attribs['value'] );
711  } else {
712  $value = 1;
713  }
714 
715  if ( $checked ) {
716  $attribs[] = 'checked';
717  }
718 
719  return self::input( $name, $value, 'radio', $attribs );
720  }
721 
730  public static function label( $label, $id, array $attribs = [] ) {
731  $attribs += [
732  'for' => $id
733  ];
734  return self::element( 'label', $attribs, $label );
735  }
736 
746  public static function hidden( $name, $value, array $attribs = [] ) {
747  return self::input( $name, $value, 'hidden', $attribs );
748  }
749 
762  public static function textarea( $name, $value = '', array $attribs = [] ) {
763  $attribs['name'] = $name;
764 
765  if ( substr( $value, 0, 1 ) == "\n" ) {
766  // Workaround for T14130: browsers eat the initial newline
767  // assuming that it's just for show, but they do keep the later
768  // newlines, which we may want to preserve during editing.
769  // Prepending a single newline
770  $spacedValue = "\n" . $value;
771  } else {
772  $spacedValue = $value;
773  }
774  return self::element( 'textarea', self::getTextInputAttributes( $attribs ), $spacedValue );
775  }
776 
782  public static function namespaceSelectorOptions( array $params = [] ) {
784 
785  $options = [];
786 
787  if ( !isset( $params['exclude'] ) || !is_array( $params['exclude'] ) ) {
788  $params['exclude'] = [];
789  }
790 
791  if ( isset( $params['all'] ) ) {
792  // add an option that would let the user select all namespaces.
793  // Value is provided by user, the name shown is localized for the user.
794  $options[$params['all']] = wfMessage( 'namespacesall' )->text();
795  }
796  // Add all namespaces as options (in the content language)
797  $options += $wgContLang->getFormattedNamespaces();
798 
799  $optionsOut = [];
800  // Filter out namespaces below 0 and massage labels
801  foreach ( $options as $nsId => $nsName ) {
802  if ( $nsId < NS_MAIN || in_array( $nsId, $params['exclude'] ) ) {
803  continue;
804  }
805  if ( $nsId === NS_MAIN ) {
806  // For other namespaces use the namespace prefix as label, but for
807  // main we don't use "" but the user message describing it (e.g. "(Main)" or "(Article)")
808  $nsName = wfMessage( 'blanknamespace' )->text();
809  } elseif ( is_int( $nsId ) ) {
810  $nsName = $wgContLang->convertNamespace( $nsId );
811  }
812  $optionsOut[$nsId] = $nsName;
813  }
814 
815  return $optionsOut;
816  }
817 
834  public static function namespaceSelector( array $params = [],
835  array $selectAttribs = []
836  ) {
837  ksort( $selectAttribs );
838 
839  // Is a namespace selected?
840  if ( isset( $params['selected'] ) ) {
841  // If string only contains digits, convert to clean int. Selected could also
842  // be "all" or "" etc. which needs to be left untouched.
843  // PHP is_numeric() has issues with large strings, PHP ctype_digit has other issues
844  // and returns false for already clean ints. Use regex instead..
845  if ( preg_match( '/^\d+$/', $params['selected'] ) ) {
846  $params['selected'] = intval( $params['selected'] );
847  }
848  // else: leaves it untouched for later processing
849  } else {
850  $params['selected'] = '';
851  }
852 
853  if ( !isset( $params['disable'] ) || !is_array( $params['disable'] ) ) {
854  $params['disable'] = [];
855  }
856 
857  // Associative array between option-values and option-labels
859 
860  // Convert $options to HTML
861  $optionsHtml = [];
862  foreach ( $options as $nsId => $nsName ) {
863  $optionsHtml[] = self::element(
864  'option', [
865  'disabled' => in_array( $nsId, $params['disable'] ),
866  'value' => $nsId,
867  'selected' => $nsId === $params['selected'],
868  ], $nsName
869  );
870  }
871 
872  if ( !array_key_exists( 'id', $selectAttribs ) ) {
873  $selectAttribs['id'] = 'namespace';
874  }
875 
876  if ( !array_key_exists( 'name', $selectAttribs ) ) {
877  $selectAttribs['name'] = 'namespace';
878  }
879 
880  $ret = '';
881  if ( isset( $params['label'] ) ) {
882  $ret .= self::element(
883  'label', [
884  'for' => isset( $selectAttribs['id'] ) ? $selectAttribs['id'] : null,
885  ], $params['label']
886  ) . '&#160;';
887  }
888 
889  // Wrap options in a <select>
890  $ret .= self::openElement( 'select', $selectAttribs )
891  . "\n"
892  . implode( "\n", $optionsHtml )
893  . "\n"
894  . self::closeElement( 'select' );
895 
896  return $ret;
897  }
898 
907  public static function htmlHeader( array $attribs = [] ) {
908  $ret = '';
909 
910  global $wgHtml5Version, $wgMimeType, $wgXhtmlNamespaces;
911 
912  $isXHTML = self::isXmlMimeType( $wgMimeType );
913 
914  if ( $isXHTML ) { // XHTML5
915  // XML MIME-typed markup should have an xml header.
916  // However a DOCTYPE is not needed.
917  $ret .= "<?xml version=\"1.0\" encoding=\"UTF-8\" ?" . ">\n";
918 
919  // Add the standard xmlns
920  $attribs['xmlns'] = 'http://www.w3.org/1999/xhtml';
921 
922  // And support custom namespaces
923  foreach ( $wgXhtmlNamespaces as $tag => $ns ) {
924  $attribs["xmlns:$tag"] = $ns;
925  }
926  } else { // HTML5
927  // DOCTYPE
928  $ret .= "<!DOCTYPE html>\n";
929  }
930 
931  if ( $wgHtml5Version ) {
932  $attribs['version'] = $wgHtml5Version;
933  }
934 
935  $ret .= self::openElement( 'html', $attribs );
936 
937  return $ret;
938  }
939 
946  public static function isXmlMimeType( $mimetype ) {
947  # https://html.spec.whatwg.org/multipage/infrastructure.html#xml-mime-type
948  # * text/xml
949  # * application/xml
950  # * Any MIME type with a subtype ending in +xml (this implicitly includes application/xhtml+xml)
951  return (bool)preg_match( '!^(text|application)/xml$|^.+/.+\+xml$!', $mimetype );
952  }
953 
964  static function infoBox( $text, $icon, $alt, $class = '' ) {
965  $s = self::openElement( 'div', [ 'class' => "mw-infobox $class" ] );
966 
967  $s .= self::openElement( 'div', [ 'class' => 'mw-infobox-left' ] ) .
968  self::element( 'img',
969  [
970  'src' => $icon,
971  'alt' => $alt,
972  ]
973  ) .
974  self::closeElement( 'div' );
975 
976  $s .= self::openElement( 'div', [ 'class' => 'mw-infobox-right' ] ) .
977  $text .
978  self::closeElement( 'div' );
979  $s .= self::element( 'div', [ 'style' => 'clear: left;' ], ' ' );
980 
981  $s .= self::closeElement( 'div' );
982 
983  $s .= self::element( 'div', [ 'style' => 'clear: left;' ], ' ' );
984 
985  return $s;
986  }
987 
1011  static function srcSet( array $urls ) {
1012  $candidates = [];
1013  foreach ( $urls as $density => $url ) {
1014  // Cast density to float to strip 'x', then back to string to serve
1015  // as array index.
1016  $density = (string)(float)$density;
1017  $candidates[$density] = $url;
1018  }
1019 
1020  // Remove duplicates that are the same as a smaller value
1021  ksort( $candidates, SORT_NUMERIC );
1022  $candidates = array_unique( $candidates );
1023 
1024  // Append density info to the url
1025  foreach ( $candidates as $density => $url ) {
1026  $candidates[$density] = $url . ' ' . $density . 'x';
1027  }
1028 
1029  return implode( ", ", $candidates );
1030  }
1031 }
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:165
Html\textarea
static textarea( $name, $value='', array $attribs=[])
Convenience function to produce a <textarea> element.
Definition: Html.php:762
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:136
Html\check
static check( $name, $checked=false, array $attribs=[])
Convenience function to produce a checkbox (input element with type=checkbox)
Definition: Html.php:684
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:474
$params
$params
Definition: styleTest.css.php:40
Html\htmlHeader
static htmlHeader(array $attribs=[])
Constructs the opening html-tag with necessary doctypes depending on global variables.
Definition: Html.php:907
$s
$s
Definition: mergeMessageFileList.php:188
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:304
$type
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition: hooks.txt:2536
Html\inlineScript
static inlineScript( $contents)
Output a "<script>" tag with the given contents.
Definition: Html.php:583
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:109
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\input
static input( $name, $value='', $type='text', array $attribs=[])
Convenience function to produce an "<input>" element.
Definition: Html.php:663
NS_MAIN
const NS_MAIN
Definition: Defines.php:62
Html\closeElement
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:309
Html\isXmlMimeType
static isXmlMimeType( $mimetype)
Determines if the given MIME type is xml.
Definition: Html.php:946
Html\srcSet
static srcSet(array $urls)
Generate a srcset attribute value.
Definition: Html.php:1011
MWException
MediaWiki exception.
Definition: MWException.php:26
$tag
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books $tag
Definition: hooks.txt:1028
Html\linkedScript
static linkedScript( $url)
Output a "<script>" tag linking to the given URL, e.g., "<script src=foo.js></script>".
Definition: Html.php:600
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:332
$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:1956
Html\$voidElements
static $voidElements
Definition: Html.php:50
Html\radio
static radio( $name, $checked=false, array $attribs=[])
Convenience function to produce a radio button (input element with type=radio)
Definition: Html.php:707
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
Html\$boolAttribs
static $boolAttribs
Definition: Html.php:70
Html\label
static label( $label, $id, array $attribs=[])
Convenience function for generating a label for inputs.
Definition: Html.php:730
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:177
Html\infoBox
static infoBox( $text, $icon, $alt, $class='')
Get HTML for an info box with an icon.
Definition: Html.php:964
Html\hidden
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:746
$value
$value
Definition: styleTest.css.php:45
Html\namespaceSelectorOptions
static namespaceSelectorOptions(array $params=[])
Helper for Html::namespaceSelector().
Definition: Html.php:782
Html\namespaceSelector
static namespaceSelector(array $params=[], array $selectAttribs=[])
Build a drop-down box for selecting a namespace.
Definition: Html.php:834
$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:1956
Html\inlineStyle
static inlineStyle( $contents, $media='all')
Output a "<style>" tag with the given contents for the given media type (if any).
Definition: Html.php:615
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:185
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:644
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:251
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
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 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\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
$options
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Definition: hooks.txt:1049
array
the array() calling protocol came about after MediaWiki 1.4rc1.
Html
This class is a collection of static functions that serve two purposes:
Definition: Html.php:48
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56