Go to the documentation of this file.
4 private $restoreWarnings;
6 protected function setUp() {
10 'wgUseMediaWikiUIEverywhere' =>
false,
18 $contLangObj->setNamespaces( [
30 9 =>
'MediaWiki_talk',
32 11 =>
'Template_talk',
34 15 =>
'Category_talk',
41 $userLangObj->setNamespaces( [
47 3 =>
"Usuario discusión",
49 5 =>
"Wiki discusión",
51 7 =>
"Archivo discusión",
53 9 =>
"MediaWiki discusión",
55 11 =>
"Plantilla discusión",
57 13 =>
"Ayuda discusión",
59 15 =>
"Categoría discusión",
60 100 =>
"Personalizado",
61 101 =>
"Personalizado discusión",
65 $this->restoreWarnings =
false;
71 if ( $this->restoreWarnings ) {
72 $this->restoreWarnings =
false;
73 Wikimedia\restoreWarnings();
85 public function testElementBasics() {
89 'Self-closing tag for short-tag elements'
93 '<element></element>',
95 'Close tag for empty element (null, null)'
99 '<element></element>',
101 'Close tag for empty element (array, string)'
105 public function dataXmlMimeType() {
108 # HTML is not an XML MimeType
109 [
'text/html',
false ],
110 # XML is an XML MimeType
111 [
'text/xml',
true ],
112 [
'application/xml',
true ],
113 # XHTML is an XML MimeType
114 [
'application/xhtml+xml',
true ],
115 # Make sure other +xml MimeTypes are supported
116 # SVG is another random MimeType even though we don't use it
117 [
'image/svg+xml',
true ],
118 # Complete random other MimeTypes are not XML
119 [
'text/plain',
false ],
127 public function testXmlMimeType( $mimetype, $isXmlMimeType ) {
134 public function testExpandAttributesSkipsNullAndFalse() {
138 'skip keys with null value'
142 'skip keys with false value'
147 'keep keys with an empty string'
154 public function testExpandAttributesForBooleans() {
158 'Boolean attributes do not generates output when value is false'
163 'Boolean attributes do not generates output when value is null'
169 'Boolean attributes have no value when value is true'
174 'Boolean attributes have no value when value is true (passed as numerical array)'
181 public function testExpandAttributesForNumbers() {
185 'Integer value is cast to a string'
190 'Float value is cast to a string'
197 public function testExpandAttributesForObjects() {
199 ' value="stringValue"',
201 'Object value is converted to a string'
210 public function testExpandAttributesVariousExpansions() {
215 'Empty string is always quoted'
220 'Simple string value needs no quotes'
225 'Number 1 value needs no quotes'
230 'Number 0 value needs no quotes'
240 public function testExpandAttributesListValueAttributes() {
243 ' class="redundant spaces here"',
245 'Normalization should strip redundant spaces'
250 'Normalization should remove duplicates in string-lists'
252 # ## "EMPTY" ARRAY VALUES
256 'Value with an empty array'
261 'Array with null, empty string and spaces'
263 # ## NON-EMPTY ARRAY VALUES
273 'Normalization should remove duplicates in the array'
283 'Normalization should remove duplicates in string-lists in the array'
292 public function testExpandAttributesSpaceSeparatedAttributesWithBoolean() {
294 ' class="booltrue one"',
299 # Method
use isset() internally, make sure we
do discard
302 'boolfalse' =>
false,
317 public function testValueIsAuthoritativeInSpaceSeparatedAttributesArrays() {
332 public function testExpandAttributes_ArrayOnNonListValueAttribute_ThrowsException() {
347 public function testNamespaceSelector() {
349 '<select id="namespace" name="namespace">' .
"\n" .
350 '<option value="0">(Principal)</option>' .
"\n" .
351 '<option value="1">Talk</option>' .
"\n" .
352 '<option value="2">User</option>' .
"\n" .
353 '<option value="3">User talk</option>' .
"\n" .
354 '<option value="4">MyWiki</option>' .
"\n" .
355 '<option value="5">MyWiki Talk</option>' .
"\n" .
356 '<option value="6">File</option>' .
"\n" .
357 '<option value="7">File talk</option>' .
"\n" .
358 '<option value="8">MediaWiki</option>' .
"\n" .
359 '<option value="9">MediaWiki talk</option>' .
"\n" .
360 '<option value="10">Template</option>' .
"\n" .
361 '<option value="11">Template talk</option>' .
"\n" .
362 '<option value="14">Category</option>' .
"\n" .
363 '<option value="15">Category talk</option>' .
"\n" .
364 '<option value="100">Custom</option>' .
"\n" .
365 '<option value="101">Custom talk</option>' .
"\n" .
368 'Basic namespace selector without custom options'
372 '<label for="mw-test-namespace">Select a namespace:</label>' .
"\u{00A0}" .
373 '<select id="mw-test-namespace" name="wpNamespace">' .
"\n" .
374 '<option value="all">todos</option>' .
"\n" .
375 '<option value="0">(Principal)</option>' .
"\n" .
376 '<option value="1">Talk</option>' .
"\n" .
377 '<option value="2" selected="">User</option>' .
"\n" .
378 '<option value="3">User talk</option>' .
"\n" .
379 '<option value="4">MyWiki</option>' .
"\n" .
380 '<option value="5">MyWiki Talk</option>' .
"\n" .
381 '<option value="6">File</option>' .
"\n" .
382 '<option value="7">File talk</option>' .
"\n" .
383 '<option value="8">MediaWiki</option>' .
"\n" .
384 '<option value="9">MediaWiki talk</option>' .
"\n" .
385 '<option value="10">Template</option>' .
"\n" .
386 '<option value="11">Template talk</option>' .
"\n" .
387 '<option value="14">Category</option>' .
"\n" .
388 '<option value="15">Category talk</option>' .
"\n" .
389 '<option value="100">Custom</option>' .
"\n" .
390 '<option value="101">Custom talk</option>' .
"\n" .
393 [
'selected' =>
'2',
'all' =>
'all',
'label' =>
'Select a namespace:' ],
394 [
'name' =>
'wpNamespace',
'id' =>
'mw-test-namespace' ]
396 'Basic namespace selector with custom values'
400 '<label for="namespace">Select a namespace:</label>' .
"\u{00A0}" .
401 '<select id="namespace" name="namespace">' .
"\n" .
402 '<option value="0">(Principal)</option>' .
"\n" .
403 '<option value="1">Talk</option>' .
"\n" .
404 '<option value="2">User</option>' .
"\n" .
405 '<option value="3">User talk</option>' .
"\n" .
406 '<option value="4">MyWiki</option>' .
"\n" .
407 '<option value="5">MyWiki Talk</option>' .
"\n" .
408 '<option value="6">File</option>' .
"\n" .
409 '<option value="7">File talk</option>' .
"\n" .
410 '<option value="8">MediaWiki</option>' .
"\n" .
411 '<option value="9">MediaWiki talk</option>' .
"\n" .
412 '<option value="10">Template</option>' .
"\n" .
413 '<option value="11">Template talk</option>' .
"\n" .
414 '<option value="14">Category</option>' .
"\n" .
415 '<option value="15">Category talk</option>' .
"\n" .
416 '<option value="100">Custom</option>' .
"\n" .
417 '<option value="101">Custom talk</option>' .
"\n" .
420 [
'label' =>
'Select a namespace:' ]
422 'Basic namespace selector with a custom label but no id attribtue for the <select>'
429 public function testCanFilterOutNamespaces() {
431 '<select id="namespace" name="namespace">' .
"\n" .
432 '<option value="2">User</option>' .
"\n" .
433 '<option value="4">MyWiki</option>' .
"\n" .
434 '<option value="5">MyWiki Talk</option>' .
"\n" .
435 '<option value="6">File</option>' .
"\n" .
436 '<option value="7">File talk</option>' .
"\n" .
437 '<option value="8">MediaWiki</option>' .
"\n" .
438 '<option value="9">MediaWiki talk</option>' .
"\n" .
439 '<option value="10">Template</option>' .
"\n" .
440 '<option value="11">Template talk</option>' .
"\n" .
441 '<option value="14">Category</option>' .
"\n" .
442 '<option value="15">Category talk</option>' .
"\n" .
445 [
'exclude' => [ 0, 1, 3, 100, 101 ] ]
447 'Namespace selector namespace filtering.'
454 public function testCanDisableANamespaces() {
456 '<select id="namespace" name="namespace">' .
"\n" .
457 '<option disabled="" value="0">(Principal)</option>' .
"\n" .
458 '<option disabled="" value="1">Talk</option>' .
"\n" .
459 '<option disabled="" value="2">User</option>' .
"\n" .
460 '<option disabled="" value="3">User talk</option>' .
"\n" .
461 '<option disabled="" value="4">MyWiki</option>' .
"\n" .
462 '<option value="5">MyWiki Talk</option>' .
"\n" .
463 '<option value="6">File</option>' .
"\n" .
464 '<option value="7">File talk</option>' .
"\n" .
465 '<option value="8">MediaWiki</option>' .
"\n" .
466 '<option value="9">MediaWiki talk</option>' .
"\n" .
467 '<option value="10">Template</option>' .
"\n" .
468 '<option value="11">Template talk</option>' .
"\n" .
469 '<option value="14">Category</option>' .
"\n" .
470 '<option value="15">Category talk</option>' .
"\n" .
471 '<option value="100">Custom</option>' .
"\n" .
472 '<option value="101">Custom talk</option>' .
"\n" .
475 'disable' => [ 0, 1, 2, 3, 4 ]
477 'Namespace selector namespace disabling'
485 public function testHtmlElementAcceptsNewHtml5TypesInHtml5Mode( $HTML5InputType ) {
487 '<input type="' . $HTML5InputType .
'"/>',
489 'In HTML5, Html::element() should accept type="' . $HTML5InputType .
'"'
497 public function testWarningBox() {
500 '<div class="warningbox">warn</div>'
508 public function testErrorBox() {
511 '<div class="errorbox">err</div>'
515 '<div class="errorbox"><h2>heading</h2>err</div>'
519 '<div class="errorbox"><h2>0</h2>err</div>'
527 public function testSuccessBox() {
530 '<div class="successbox">great</div>'
534 '<div class="successbox"><script>beware no escaping!</script></div>'
542 public static function provideHtml5InputTypes() {
560 $cases[] = [
$type ];
571 public function testDropDefaults( $expected, $element,
$attribs, $message =
'' ) {
575 public static function provideElementsWithAttributesHavingDefaultValues() {
576 # Use cases in a concise format:
577 # <expected>, <element name>, <array of attributes> [, <message>]
578 # Will be mapped to Html::element()
581 # ## Generic cases, match $attribDefault static array
582 $cases[] = [
'<area/>',
583 'area', [
'shape' =>
'rect' ]
586 $cases[] = [
'<button type="submit"></button>',
587 'button', [
'formaction' =>
'GET' ]
589 $cases[] = [
'<button type="submit"></button>',
590 'button', [
'formenctype' =>
'application/x-www-form-urlencoded' ]
593 $cases[] = [
'<canvas></canvas>',
594 'canvas', [
'height' =>
'150' ]
596 $cases[] = [
'<canvas></canvas>',
597 'canvas', [
'width' =>
'300' ]
599 # Also check with numeric values
600 $cases[] = [
'<canvas></canvas>',
601 'canvas', [
'height' => 150 ]
603 $cases[] = [
'<canvas></canvas>',
604 'canvas', [
'width' => 300 ]
607 $cases[] = [
'<form></form>',
608 'form', [
'action' =>
'GET' ]
610 $cases[] = [
'<form></form>',
611 'form', [
'autocomplete' =>
'on' ]
613 $cases[] = [
'<form></form>',
614 'form', [
'enctype' =>
'application/x-www-form-urlencoded' ]
617 $cases[] = [
'<input/>',
618 'input', [
'formaction' =>
'GET' ]
620 $cases[] = [
'<input/>',
621 'input', [
'type' =>
'text' ]
624 $cases[] = [
'<keygen/>',
625 'keygen', [
'keytype' =>
'rsa' ]
628 $cases[] = [
'<link/>',
629 'link', [
'media' =>
'all' ]
632 $cases[] = [
'<menu></menu>',
633 'menu', [
'type' =>
'list' ]
636 $cases[] = [
'<script></script>',
637 'script', [
'type' =>
'text/javascript' ]
640 $cases[] = [
'<style></style>',
641 'style', [
'media' =>
'all' ]
643 $cases[] = [
'<style></style>',
644 'style', [
'type' =>
'text/css' ]
647 $cases[] = [
'<textarea></textarea>',
648 'textarea', [
'wrap' =>
'soft' ]
653 # <link type="text/css">
654 $cases[] = [
'<link/>',
655 'link', [
'type' =>
'text/css' ]
658 # <input> specific handling
659 $cases[] = [
'<input type="checkbox"/>',
660 'input', [
'type' =>
'checkbox',
'value' =>
'on' ],
661 'Default value "on" is stripped of checkboxes',
663 $cases[] = [
'<input type="radio"/>',
664 'input', [
'type' =>
'radio',
'value' =>
'on' ],
665 'Default value "on" is stripped of radio buttons',
667 $cases[] = [
'<input type="submit" value="Submit"/>',
668 'input', [
'type' =>
'submit',
'value' =>
'Submit' ],
669 'Default value "Submit" is kept on submit buttons (for possible l10n issues)',
671 $cases[] = [
'<input type="color"/>',
672 'input', [
'type' =>
'color',
'value' =>
'' ],
674 $cases[] = [
'<input type="range"/>',
675 'input', [
'type' =>
'range',
'value' =>
'' ],
678 # <button> specific handling
679 # see remarks on https://msdn.microsoft.com/library/ms535211(v=vs.85).aspx
680 $cases[] = [
'<button type="submit"></button>',
681 'button', [
'type' =>
'submit' ],
682 'According to standard the default type is "submit". '
683 .
'Depending on compatibility mode IE might use "button", instead.',
686 # <select> specific handling
687 $cases[] = [
'<select multiple=""></select>',
688 'select', [
'size' =>
'4',
'multiple' =>
true ],
690 # .. with numeric value
691 $cases[] = [
'<select multiple=""></select>',
692 'select', [
'size' => 4,
'multiple' =>
true ],
694 $cases[] = [
'<select></select>',
695 'select', [
'size' =>
'1',
'multiple' =>
false ],
697 # .. with numeric value
698 $cases[] = [
'<select></select>',
699 'select', [
'size' => 1,
'multiple' =>
false ],
702 # Passing an array as value
703 $cases[] = [
'<a class="css-class-one css-class-two"></a>',
704 'a', [
'class' => [
'css-class-one',
'css-class-two' ] ],
705 "dropDefaults accepts values given as an array"
708 # FIXME: doDropDefault should remove defaults given in an array
709 # Expected should be '<a></a>'
710 $cases[] = [
'<a class=""></a>',
711 'a', [
'class' => [
'',
'' ] ],
712 "dropDefaults accepts values given as an array"
715 # Craft the Html elements
717 foreach ( $cases
as $case ) {
731 public function testWrapperInput() {
733 '<input type="radio" value="testval" name="testname"/>',
735 'Input wrapper with type and value.'
738 '<input name="testname"/>',
740 'Input wrapper with all default values.'
747 public function testWrapperCheck() {
749 '<input type="checkbox" value="1" name="testname"/>',
751 'Checkbox wrapper unchecked.'
754 '<input checked="" type="checkbox" value="1" name="testname"/>',
756 'Checkbox wrapper checked.'
759 '<input type="checkbox" value="testval" name="testname"/>',
760 Html::check(
'testname',
false, [
'value' =>
'testval' ] ),
761 'Checkbox wrapper with a value override.'
768 public function testWrapperRadio() {
770 '<input type="radio" value="1" name="testname"/>',
772 'Radio wrapper unchecked.'
775 '<input checked="" type="radio" value="1" name="testname"/>',
777 'Radio wrapper checked.'
780 '<input type="radio" value="testval" name="testname"/>',
781 Html::radio(
'testname',
false, [
'value' =>
'testval' ] ),
782 'Radio wrapper with a value override.'
789 public function testWrapperLabel() {
791 '<label for="testid">testlabel</label>',
797 public static function provideSrcSetImages() {
799 [ [],
'',
'when there are no images, return empty string' ],
801 [
'1x' =>
'1x.png',
'1.5x' =>
'1_5x.png',
'2x' =>
'2x.png' ],
802 '1x.png 1x, 1_5x.png 1.5x, 2x.png 2x',
803 'pixel depth keys may include a trailing "x"'
806 [
'1' =>
'1x.png',
'1.5' =>
'1_5x.png',
'2' =>
'2x.png' ],
807 '1x.png 1x, 1_5x.png 1.5x, 2x.png 2x',
808 'pixel depth keys may omit a trailing "x"'
811 [
'1' =>
'small.png',
'1.5' =>
'large.png',
'2' =>
'large.png' ],
812 'small.png 1x, large.png 1.5x',
813 'omit larger duplicates'
816 [
'1' =>
'small.png',
'2' =>
'large.png',
'1.5' =>
'large.png' ],
817 'small.png 1x, large.png 1.5x',
818 'omit larger duplicates in irregular order'
827 public function testSrcSet( $images, $expected, $message ) {
828 $this->assertEquals(
Html::srcSet( $images ), $expected, $message );
831 public static function provideInlineScript() {
838 'EXAMPLE.label("foo");',
839 '<script>EXAMPLE.label("foo");</script>'
842 'EXAMPLE.is(a && b);',
843 '<script>EXAMPLE.is(a && b);</script>'
846 'EXAMPLE.label("<a>");',
847 '<script>EXAMPLE.label("<a>");</script>'
849 'Script closing string (lower)' => [
850 'EXAMPLE.label("</script>");',
851 '<script>/* ERROR: Invalid script */</script>',
854 'Script closing with non-standard attributes (mixed)' => [
855 'EXAMPLE.label("</SCriPT and STyLE>");',
856 '<script>/* ERROR: Invalid script */</script>',
859 'HTML-comment-open and script-open' => [
864 'var a = "<!--<script>";',
865 '<script>/* ERROR: Invalid script */</script>',
875 public function testInlineScript(
$code, $expected, $error =
false ) {
877 Wikimedia\suppressWarnings();
878 $this->restoreWarnings =
true;
884 class HtmlTestValue {
885 function __toString() {
886 return 'stringValue';
static errorBox( $html, $heading='')
Return an error box.
processing should stop and the error should be shown to the user * false
static check( $name, $checked=false, array $attribs=[])
Convenience function to produce a checkbox (input element with type=checkbox)
static expandAttributes(array $attribs)
Given an associative array of element attributes, generate a string to stick after the element name i...
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
static successBox( $html)
Return a success box.
static input( $name, $value='', $type='text', array $attribs=[])
Convenience function to produce an "<input>" element.
static isXmlMimeType( $mimetype)
Determines if the given MIME type is xml.
static srcSet(array $urls)
Generate a srcset attribute value.
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
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
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
static radio( $name, $checked=false, array $attribs=[])
Convenience function to produce a radio button (input element with type=radio)
static warningBox( $html)
Return a warning box.
static label( $label, $id, array $attribs=[])
Convenience function for generating a label for inputs.
static inlineScript( $contents, $nonce=null)
Output an HTML script tag with the given contents.
static namespaceSelector(array $params=[], array $selectAttribs=[])
Build a drop-down box for selecting a namespace.
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
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible values
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
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 true
static factory( $code)
Get a cached or new language object for a given language code.
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).