MediaWiki  master
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 2011-08-12
50  private static $voidElements = [
51  'area',
52  'base',
53  'br',
54  'col',
55  'command',
56  'embed',
57  'hr',
58  'img',
59  'input',
60  'keygen',
61  'link',
62  'meta',
63  'param',
64  'source',
65  'track',
66  'wbr',
67  ];
68 
69  // Boolean attributes, which may have the value omitted entirely. Manually
70  // collected from the HTML5 spec as of 2011-08-12.
71  private static $boolAttribs = [
72  'async',
73  'autofocus',
74  'autoplay',
75  'checked',
76  'controls',
77  'default',
78  'defer',
79  'disabled',
80  'formnovalidate',
81  'hidden',
82  'ismap',
83  'itemscope',
84  'loop',
85  'multiple',
86  'muted',
87  'novalidate',
88  'open',
89  'pubdate',
90  'readonly',
91  'required',
92  'reversed',
93  'scoped',
94  'seamless',
95  'selected',
96  'truespeed',
97  'typemustmatch',
98  // HTML5 Microdata
99  'itemscope',
100  ];
101 
110  public static function buttonAttributes( array $attrs, array $modifiers = [] ) {
112  if ( $wgUseMediaWikiUIEverywhere ) {
113  if ( isset( $attrs['class'] ) ) {
114  if ( is_array( $attrs['class'] ) ) {
115  $attrs['class'][] = 'mw-ui-button';
116  $attrs['class'] = array_merge( $attrs['class'], $modifiers );
117  // ensure compatibility with Xml
118  $attrs['class'] = implode( ' ', $attrs['class'] );
119  } else {
120  $attrs['class'] .= ' mw-ui-button ' . implode( ' ', $modifiers );
121  }
122  } else {
123  // ensure compatibility with Xml
124  $attrs['class'] = 'mw-ui-button ' . implode( ' ', $modifiers );
125  }
126  }
127  return $attrs;
128  }
129 
137  public static function getTextInputAttributes( array $attrs ) {
139  if ( $wgUseMediaWikiUIEverywhere ) {
140  if ( isset( $attrs['class'] ) ) {
141  if ( is_array( $attrs['class'] ) ) {
142  $attrs['class'][] = 'mw-ui-input';
143  } else {
144  $attrs['class'] .= ' mw-ui-input';
145  }
146  } else {
147  $attrs['class'] = 'mw-ui-input';
148  }
149  }
150  return $attrs;
151  }
152 
166  public static function linkButton( $contents, array $attrs, array $modifiers = [] ) {
167  return self::element( 'a',
168  self::buttonAttributes( $attrs, $modifiers ),
169  $contents
170  );
171  }
172 
186  public static function submitButton( $contents, array $attrs, array $modifiers = [] ) {
187  $attrs['type'] = 'submit';
188  $attrs['value'] = $contents;
189  return self::element( 'input', self::buttonAttributes( $attrs, $modifiers ) );
190  }
191 
210  public static function rawElement( $element, $attribs = [], $contents = '' ) {
211  $start = self::openElement( $element, $attribs );
212  if ( in_array( $element, self::$voidElements ) ) {
213  // Silly XML.
214  return substr( $start, 0, -1 ) . '/>';
215  } else {
216  return "$start$contents" . self::closeElement( $element );
217  }
218  }
219 
230  public static function element( $element, $attribs = [], $contents = '' ) {
231  return self::rawElement( $element, $attribs, strtr( $contents, [
232  // There's no point in escaping quotes, >, etc. in the contents of
233  // elements.
234  '&' => '&amp;',
235  '<' => '&lt;'
236  ] ) );
237  }
238 
248  public static function openElement( $element, $attribs = [] ) {
250  // This is not required in HTML5, but let's do it anyway, for
251  // consistency and better compression.
252  $element = strtolower( $element );
253 
254  // Remove invalid input types
255  if ( $element == 'input' ) {
256  $validTypes = [
257  'hidden',
258  'text',
259  'password',
260  'checkbox',
261  'radio',
262  'file',
263  'submit',
264  'image',
265  'reset',
266  'button',
267 
268  // HTML input types
269  'datetime',
270  'datetime-local',
271  'date',
272  'month',
273  'time',
274  'week',
275  'number',
276  'range',
277  'email',
278  'url',
279  'search',
280  'tel',
281  'color',
282  ];
283  if ( isset( $attribs['type'] ) && !in_array( $attribs['type'], $validTypes ) ) {
284  unset( $attribs['type'] );
285  }
286  }
287 
288  // According to standard the default type for <button> elements is "submit".
289  // Depending on compatibility mode IE might use "button", instead.
290  // We enforce the standard "submit".
291  if ( $element == 'button' && !isset( $attribs['type'] ) ) {
292  $attribs['type'] = 'submit';
293  }
294 
295  return "<$element" . self::expandAttributes(
296  self::dropDefaults( $element, $attribs ) ) . '>';
297  }
298 
306  public static function closeElement( $element ) {
307  $element = strtolower( $element );
308 
309  return "</$element>";
310  }
311 
329  private static function dropDefaults( $element, array $attribs ) {
330  // Whenever altering this array, please provide a covering test case
331  // in HtmlTest::provideElementsWithAttributesHavingDefaultValues
332  static $attribDefaults = [
333  'area' => [ 'shape' => 'rect' ],
334  'button' => [
335  'formaction' => 'GET',
336  'formenctype' => 'application/x-www-form-urlencoded',
337  ],
338  'canvas' => [
339  'height' => '150',
340  'width' => '300',
341  ],
342  'command' => [ 'type' => 'command' ],
343  'form' => [
344  'action' => 'GET',
345  'autocomplete' => 'on',
346  'enctype' => 'application/x-www-form-urlencoded',
347  ],
348  'input' => [
349  'formaction' => 'GET',
350  'type' => 'text',
351  ],
352  'keygen' => [ 'keytype' => 'rsa' ],
353  'link' => [ 'media' => 'all' ],
354  'menu' => [ 'type' => 'list' ],
355  'script' => [ 'type' => 'text/javascript' ],
356  'style' => [
357  'media' => 'all',
358  'type' => 'text/css',
359  ],
360  'textarea' => [ 'wrap' => 'soft' ],
361  ];
362 
363  $element = strtolower( $element );
364 
365  foreach ( $attribs as $attrib => $value ) {
366  $lcattrib = strtolower( $attrib );
367  if ( is_array( $value ) ) {
368  $value = implode( ' ', $value );
369  } else {
370  $value = strval( $value );
371  }
372 
373  // Simple checks using $attribDefaults
374  if ( isset( $attribDefaults[$element][$lcattrib] )
375  && $attribDefaults[$element][$lcattrib] == $value
376  ) {
377  unset( $attribs[$attrib] );
378  }
379 
380  if ( $lcattrib == 'class' && $value == '' ) {
381  unset( $attribs[$attrib] );
382  }
383  }
384 
385  // More subtle checks
386  if ( $element === 'link'
387  && isset( $attribs['type'] ) && strval( $attribs['type'] ) == 'text/css'
388  ) {
389  unset( $attribs['type'] );
390  }
391  if ( $element === 'input' ) {
392  $type = isset( $attribs['type'] ) ? $attribs['type'] : null;
393  $value = isset( $attribs['value'] ) ? $attribs['value'] : null;
394  if ( $type === 'checkbox' || $type === 'radio' ) {
395  // The default value for checkboxes and radio buttons is 'on'
396  // not ''. By stripping value="" we break radio boxes that
397  // actually wants empty values.
398  if ( $value === 'on' ) {
399  unset( $attribs['value'] );
400  }
401  } elseif ( $type === 'submit' ) {
402  // The default value for submit appears to be "Submit" but
403  // let's not bother stripping out localized text that matches
404  // that.
405  } else {
406  // The default value for nearly every other field type is ''
407  // The 'range' and 'color' types use different defaults but
408  // stripping a value="" does not hurt them.
409  if ( $value === '' ) {
410  unset( $attribs['value'] );
411  }
412  }
413  }
414  if ( $element === 'select' && isset( $attribs['size'] ) ) {
415  if ( in_array( 'multiple', $attribs )
416  || ( isset( $attribs['multiple'] ) && $attribs['multiple'] !== false )
417  ) {
418  // A multi-select
419  if ( strval( $attribs['size'] ) == '4' ) {
420  unset( $attribs['size'] );
421  }
422  } else {
423  // Single select
424  if ( strval( $attribs['size'] ) == '1' ) {
425  unset( $attribs['size'] );
426  }
427  }
428  }
429 
430  return $attribs;
431  }
432 
472  public static function expandAttributes( array $attribs ) {
473  $ret = '';
474  foreach ( $attribs as $key => $value ) {
475  // Support intuitive array( 'checked' => true/false ) form
476  if ( $value === false || is_null( $value ) ) {
477  continue;
478  }
479 
480  // For boolean attributes, support array( 'foo' ) instead of
481  // requiring array( 'foo' => 'meaningless' ).
482  if ( is_int( $key ) && in_array( strtolower( $value ), self::$boolAttribs ) ) {
483  $key = $value;
484  }
485 
486  // Not technically required in HTML5 but we'd like consistency
487  // and better compression anyway.
488  $key = strtolower( $key );
489 
490  // Bug 23769: Blacklist all form validation attributes for now. Current
491  // (June 2010) WebKit has no UI, so the form just refuses to submit
492  // without telling the user why, which is much worse than failing
493  // server-side validation. Opera is the only other implementation at
494  // this time, and has ugly UI, so just kill the feature entirely until
495  // we have at least one good implementation.
496 
497  // As the default value of "1" for "step" rejects decimal
498  // numbers to be entered in 'type="number"' fields, allow
499  // the special case 'step="any"'.
500 
501  if ( in_array( $key, [ 'max', 'min', 'pattern', 'required' ] )
502  || $key === 'step' && $value !== 'any' ) {
503  continue;
504  }
505 
506  // http://www.w3.org/TR/html401/index/attributes.html ("space-separated")
507  // http://www.w3.org/TR/html5/index.html#attributes-1 ("space-separated")
508  $spaceSeparatedListAttributes = [
509  'class', // html4, html5
510  'accesskey', // as of html5, multiple space-separated values allowed
511  // html4-spec doesn't document rel= as space-separated
512  // but has been used like that and is now documented as such
513  // in the html5-spec.
514  'rel',
515  ];
516 
517  // Specific features for attributes that allow a list of space-separated values
518  if ( in_array( $key, $spaceSeparatedListAttributes ) ) {
519  // Apply some normalization and remove duplicates
520 
521  // Convert into correct array. Array can contain space-separated
522  // values. Implode/explode to get those into the main array as well.
523  if ( is_array( $value ) ) {
524  // If input wasn't an array, we can skip this step
525  $newValue = [];
526  foreach ( $value as $k => $v ) {
527  if ( is_string( $v ) ) {
528  // String values should be normal `array( 'foo' )`
529  // Just append them
530  if ( !isset( $value[$v] ) ) {
531  // As a special case don't set 'foo' if a
532  // separate 'foo' => true/false exists in the array
533  // keys should be authoritative
534  $newValue[] = $v;
535  }
536  } elseif ( $v ) {
537  // If the value is truthy but not a string this is likely
538  // an array( 'foo' => true ), falsy values don't add strings
539  $newValue[] = $k;
540  }
541  }
542  $value = implode( ' ', $newValue );
543  }
544  $value = explode( ' ', $value );
545 
546  // Normalize spacing by fixing up cases where people used
547  // more than 1 space and/or a trailing/leading space
548  $value = array_diff( $value, [ '', ' ' ] );
549 
550  // Remove duplicates and create the string
551  $value = implode( ' ', array_unique( $value ) );
552  } elseif ( is_array( $value ) ) {
553  throw new MWException( "HTML attribute $key can not contain a list of values" );
554  }
555 
556  $quote = '"';
557 
558  if ( in_array( $key, self::$boolAttribs ) ) {
559  $ret .= " $key=\"\"";
560  } else {
561  // Apparently we need to entity-encode \n, \r, \t, although the
562  // spec doesn't mention that. Since we're doing strtr() anyway,
563  // we may as well not call htmlspecialchars().
564  // @todo FIXME: Verify that we actually need to
565  // escape \n\r\t here, and explain why, exactly.
566  // We could call Sanitizer::encodeAttribute() for this, but we
567  // don't because we're stubborn and like our marginal savings on
568  // byte size from not having to encode unnecessary quotes.
569  // The only difference between this transform and the one by
570  // Sanitizer::encodeAttribute() is ' is not encoded.
571  $map = [
572  '&' => '&amp;',
573  '"' => '&quot;',
574  '>' => '&gt;',
575  // '<' allegedly allowed per spec
576  // but breaks some tools if not escaped.
577  "<" => '&lt;',
578  "\n" => '&#10;',
579  "\r" => '&#13;',
580  "\t" => '&#9;'
581  ];
582  $ret .= " $key=$quote" . strtr( $value, $map ) . $quote;
583  }
584  }
585  return $ret;
586  }
587 
597  public static function inlineScript( $contents ) {
598  $attrs = [];
599 
600  if ( preg_match( '/[<&]/', $contents ) ) {
601  $contents = "/*<![CDATA[*/$contents/*]]>*/";
602  }
603 
604  return self::rawElement( 'script', $attrs, $contents );
605  }
606 
614  public static function linkedScript( $url ) {
615  $attrs = [ 'src' => $url ];
616 
617  return self::element( 'script', $attrs );
618  }
619 
629  public static function inlineStyle( $contents, $media = 'all' ) {
630  if ( preg_match( '/[<&]/', $contents ) ) {
631  $contents = "/*<![CDATA[*/$contents/*]]>*/";
632  }
633 
634  return self::rawElement( 'style', [
635  'media' => $media,
636  ], $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' ] ) ) {
671  $attribs = self::getTextInputAttributes( $attribs );
672  }
673  if ( in_array( $type, [ 'button', 'reset', 'submit' ] ) ) {
674  $attribs = self::buttonAttributes( $attribs );
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  public static function radio( $name, $checked = false, array $attribs = [] ) {
711  if ( isset( $attribs['value'] ) ) {
712  $value = $attribs['value'];
713  unset( $attribs['value'] );
714  } else {
715  $value = 1;
716  }
717 
718  if ( $checked ) {
719  $attribs[] = 'checked';
720  }
721 
722  return self::input( $name, $value, 'radio', $attribs );
723  }
724 
733  public static function label( $label, $id, array $attribs = [] ) {
734  $attribs += [
735  'for' => $id
736  ];
737  return self::element( 'label', $attribs, $label );
738  }
739 
749  public static function hidden( $name, $value, array $attribs = [] ) {
750  return self::input( $name, $value, 'hidden', $attribs );
751  }
752 
765  public static function textarea( $name, $value = '', array $attribs = [] ) {
766  $attribs['name'] = $name;
767 
768  if ( substr( $value, 0, 1 ) == "\n" ) {
769  // Workaround for bug 12130: browsers eat the initial newline
770  // assuming that it's just for show, but they do keep the later
771  // newlines, which we may want to preserve during editing.
772  // Prepending a single newline
773  $spacedValue = "\n" . $value;
774  } else {
775  $spacedValue = $value;
776  }
777  return self::element( 'textarea', self::getTextInputAttributes( $attribs ), $spacedValue );
778  }
779 
785  public static function namespaceSelectorOptions( array $params = [] ) {
787 
788  $options = [];
789 
790  if ( !isset( $params['exclude'] ) || !is_array( $params['exclude'] ) ) {
791  $params['exclude'] = [];
792  }
793 
794  if ( isset( $params['all'] ) ) {
795  // add an option that would let the user select all namespaces.
796  // Value is provided by user, the name shown is localized for the user.
797  $options[$params['all']] = wfMessage( 'namespacesall' )->text();
798  }
799  // Add all namespaces as options (in the content language)
800  $options += $wgContLang->getFormattedNamespaces();
801 
802  $optionsOut = [];
803  // Filter out namespaces below 0 and massage labels
804  foreach ( $options as $nsId => $nsName ) {
805  if ( $nsId < NS_MAIN || in_array( $nsId, $params['exclude'] ) ) {
806  continue;
807  }
808  if ( $nsId === NS_MAIN ) {
809  // For other namespaces use the namespace prefix as label, but for
810  // main we don't use "" but the user message describing it (e.g. "(Main)" or "(Article)")
811  $nsName = wfMessage( 'blanknamespace' )->text();
812  } elseif ( is_int( $nsId ) ) {
813  $nsName = $wgContLang->convertNamespace( $nsId );
814  }
815  $optionsOut[$nsId] = $nsName;
816  }
817 
818  return $optionsOut;
819  }
820 
837  public static function namespaceSelector( array $params = [],
838  array $selectAttribs = []
839  ) {
840  ksort( $selectAttribs );
841 
842  // Is a namespace selected?
843  if ( isset( $params['selected'] ) ) {
844  // If string only contains digits, convert to clean int. Selected could also
845  // be "all" or "" etc. which needs to be left untouched.
846  // PHP is_numeric() has issues with large strings, PHP ctype_digit has other issues
847  // and returns false for already clean ints. Use regex instead..
848  if ( preg_match( '/^\d+$/', $params['selected'] ) ) {
849  $params['selected'] = intval( $params['selected'] );
850  }
851  // else: leaves it untouched for later processing
852  } else {
853  $params['selected'] = '';
854  }
855 
856  if ( !isset( $params['disable'] ) || !is_array( $params['disable'] ) ) {
857  $params['disable'] = [];
858  }
859 
860  // Associative array between option-values and option-labels
861  $options = self::namespaceSelectorOptions( $params );
862 
863  // Convert $options to HTML
864  $optionsHtml = [];
865  foreach ( $options as $nsId => $nsName ) {
866  $optionsHtml[] = self::element(
867  'option', [
868  'disabled' => in_array( $nsId, $params['disable'] ),
869  'value' => $nsId,
870  'selected' => $nsId === $params['selected'],
871  ], $nsName
872  );
873  }
874 
875  if ( !array_key_exists( 'id', $selectAttribs ) ) {
876  $selectAttribs['id'] = 'namespace';
877  }
878 
879  if ( !array_key_exists( 'name', $selectAttribs ) ) {
880  $selectAttribs['name'] = 'namespace';
881  }
882 
883  $ret = '';
884  if ( isset( $params['label'] ) ) {
885  $ret .= self::element(
886  'label', [
887  'for' => isset( $selectAttribs['id'] ) ? $selectAttribs['id'] : null,
888  ], $params['label']
889  ) . '&#160;';
890  }
891 
892  // Wrap options in a <select>
893  $ret .= self::openElement( 'select', $selectAttribs )
894  . "\n"
895  . implode( "\n", $optionsHtml )
896  . "\n"
897  . self::closeElement( 'select' );
898 
899  return $ret;
900  }
901 
910  public static function htmlHeader( array $attribs = [] ) {
911  $ret = '';
912 
914 
915  $isXHTML = self::isXmlMimeType( $wgMimeType );
916 
917  if ( $isXHTML ) { // XHTML5
918  // XML MIME-typed markup should have an xml header.
919  // However a DOCTYPE is not needed.
920  $ret .= "<?xml version=\"1.0\" encoding=\"UTF-8\" ?" . ">\n";
921 
922  // Add the standard xmlns
923  $attribs['xmlns'] = 'http://www.w3.org/1999/xhtml';
924 
925  // And support custom namespaces
926  foreach ( $wgXhtmlNamespaces as $tag => $ns ) {
927  $attribs["xmlns:$tag"] = $ns;
928  }
929  } else { // HTML5
930  // DOCTYPE
931  $ret .= "<!DOCTYPE html>\n";
932  }
933 
934  if ( $wgHtml5Version ) {
935  $attribs['version'] = $wgHtml5Version;
936  }
937 
938  $ret .= self::openElement( 'html', $attribs );
939 
940  return $ret;
941  }
942 
949  public static function isXmlMimeType( $mimetype ) {
950  # http://www.whatwg.org/html/infrastructure.html#xml-mime-type
951  # * text/xml
952  # * application/xml
953  # * Any MIME type with a subtype ending in +xml (this implicitly includes application/xhtml+xml)
954  return (bool)preg_match( '!^(text|application)/xml$|^.+/.+\+xml$!', $mimetype );
955  }
956 
967  static function infoBox( $text, $icon, $alt, $class = '' ) {
968  $s = self::openElement( 'div', [ 'class' => "mw-infobox $class" ] );
969 
970  $s .= self::openElement( 'div', [ 'class' => 'mw-infobox-left' ] ) .
971  self::element( 'img',
972  [
973  'src' => $icon,
974  'alt' => $alt,
975  ]
976  ) .
977  self::closeElement( 'div' );
978 
979  $s .= self::openElement( 'div', [ 'class' => 'mw-infobox-right' ] ) .
980  $text .
981  self::closeElement( 'div' );
982  $s .= self::element( 'div', [ 'style' => 'clear: left;' ], ' ' );
983 
984  $s .= self::closeElement( 'div' );
985 
986  $s .= self::element( 'div', [ 'style' => 'clear: left;' ], ' ' );
987 
988  return $s;
989  }
990 
1014  static function srcSet( array $urls ) {
1015  $candidates = [];
1016  foreach ( $urls as $density => $url ) {
1017  // Cast density to float to strip 'x', then back to string to serve
1018  // as array index.
1019  $density = (string)(float)$density;
1020  $candidates[$density] = $url;
1021  }
1022 
1023  // Remove duplicates that are the same as a smaller value
1024  ksort( $candidates, SORT_NUMERIC );
1025  $candidates = array_unique( $candidates );
1026 
1027  // Append density info to the url
1028  foreach ( $candidates as $density => $url ) {
1029  $candidates[$density] = $url . ' ' . $density . 'x';
1030  }
1031 
1032  return implode( ", ", $candidates );
1033  }
1034 }
static closeElement($element)
Returns "</$element>".
Definition: Html.php:306
static inlineScript($contents)
Output a "<script>" tag with the given contents.
Definition: Html.php:597
the array() calling protocol came about after MediaWiki 1.4rc1.
static namespaceSelectorOptions(array $params=[])
Helper for Html::namespaceSelector().
Definition: Html.php:785
const NS_MAIN
Definition: Defines.php:69
$wgMimeType
The default Content-Type header.
static rawElement($element, $attribs=[], $contents= '')
Returns an HTML element in a string.
Definition: Html.php:210
static $boolAttribs
Definition: Html.php:71
static hidden($name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:749
$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:177
$value
static linkedScript($url)
Output a "<script>" tag linking to the given URL, e.g., "<script src=foo.js></script>".
Definition: Html.php:614
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
static infoBox($text, $icon, $alt, $class= '')
Get HTML for an info box with an icon.
Definition: Html.php:967
static radio($name, $checked=false, array $attribs=[])
Convenience function to produce a radio button (input element with type=radio)
Definition: Html.php:710
static $voidElements
Definition: Html.php:50
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
static openElement($element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:248
static textarea($name, $value= '', array $attribs=[])
Convenience function to produce a <textarea> element.
Definition: Html.php:765
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:329
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist 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:1020
MediaWiki exception.
Definition: MWException.php:26
static check($name, $checked=false, array $attribs=[])
Convenience function to produce a checkbox (input element with type=checkbox)
Definition: Html.php:687
$params
$wgUseMediaWikiUIEverywhere
Temporary variable that applies MediaWiki UI wherever it can be supported.
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 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 after processing 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 unsetoffset-wrap String Wrap the message in html(usually something like"&lt
This class is a collection of static functions that serve two purposes:
Definition: Html.php:48
static inlineStyle($contents, $media= 'all')
Output a "<style>" tag with the given contents for the given media type (if any). ...
Definition: Html.php:629
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist 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:981
static expandAttributes(array $attribs)
Given an associative array of element attributes, generate a string to stick after the element name i...
Definition: Html.php:472
static htmlHeader(array $attribs=[])
Constructs the opening html-tag with necessary doctypes depending on global variables.
Definition: Html.php:910
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:1816
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 srcSet(array $urls)
Generate a srcset attribute value.
Definition: Html.php:1014
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 submitButton($contents, array $attrs, array $modifiers=[])
Returns an HTML link element in a string styled as a button (when $wgUseMediaWikiUIEverywhere is enab...
Definition: Html.php:186
static input($name, $value= '', $type= 'text', array $attribs=[])
Convenience function to produce an "<input>" element.
Definition: Html.php:666
static isXmlMimeType($mimetype)
Determines if the given MIME type is xml.
Definition: Html.php:949
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
$wgXhtmlNamespaces
Permit other namespaces in addition to the w3.org default.
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 local content language as $wgContLang
Definition: design.txt:56
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:1816
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
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
static element($element, $attribs=[], $contents= '')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:230
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 one of or reset 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:2376
static label($label, $id, array $attribs=[])
Convenience function for generating a label for inputs.
Definition: Html.php:733
static namespaceSelector(array $params=[], array $selectAttribs=[])
Build a drop-down box for selecting a namespace.
Definition: Html.php:837
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:310