6 protected function setUp() {
10 'wgUseMediaWikiUIEverywhere' =>
false,
13 $langObj = Language::factory(
'en' );
18 $langObj->setNamespaces( [
30 9 =>
'MediaWiki_talk',
32 11 =>
'Template_talk',
34 15 =>
'Category_talk',
48 Html::element(
'img',
null,
'' ),
49 'Self-closing tag for short-tag elements'
53 '<element></element>',
54 Html::element(
'element',
null,
null ),
55 'Close tag for empty element (null, null)'
59 '<element></element>',
60 Html::element(
'element', [],
'' ),
61 'Close tag for empty element (array, string)'
68 # HTML is not an XML MimeType
69 [
'text/html',
false ],
70 # XML is an XML MimeType
72 [
'application/xml',
true ],
73 # XHTML is an XML MimeType
74 [
'application/xhtml+xml',
true ],
75 # Make sure other +xml MimeTypes are supported
76 # SVG is another random MimeType even though we don't use it
77 [
'image/svg+xml',
true ],
78 # Complete random other MimeTypes are not XML
79 [
'text/plain',
false ],
88 $this->assertEquals( $isXmlMimeType, Html::isXmlMimeType( $mimetype ) );
98 Html::expandAttributes( [
'foo' =>
null ] ),
99 'skip keys with null value'
102 Html::expandAttributes( [
'foo' =>
false ] ),
103 'skip keys with false value'
107 Html::expandAttributes( [
'foo' =>
'' ] ),
108 'keep keys with an empty string'
118 Html::expandAttributes( [
'selected' =>
false ] ),
119 'Boolean attributes do not generates output when value is false'
123 Html::expandAttributes( [
'selected' =>
null ] ),
124 'Boolean attributes do not generates output when value is null'
129 Html::expandAttributes( [
'selected' =>
true ] ),
130 'Boolean attributes have no value when value is true'
134 Html::expandAttributes( [
'selected' ] ),
135 'Boolean attributes have no value when value is true (passed as numerical array)'
145 Html::expandAttributes( [
'value' => 1 ] ),
146 'Integer value is cast to a string'
150 Html::expandAttributes( [
'value' => 1.1 ] ),
151 'Float value is cast to a string'
160 ' value="stringValue"',
161 Html::expandAttributes( [
'value' =>
new HtmlTestValue() ] ),
162 'Object value is converted to a string'
175 Html::expandAttributes( [
'empty_string' =>
'' ] ),
176 'Empty string is always quoted'
180 Html::expandAttributes( [
'key' =>
'value' ] ),
181 'Simple string value needs no quotes'
185 Html::expandAttributes( [
'one' => 1 ] ),
186 'Number 1 value needs no quotes'
190 Html::expandAttributes( [
'zero' => 0 ] ),
191 'Number 0 value needs no quotes'
205 ' class="redundant spaces here"',
206 Html::expandAttributes( [
'class' =>
' redundant spaces here ' ] ),
207 'Normalization should strip redundant spaces'
211 Html::expandAttributes( [
'class' =>
'foo bar foo bar bar' ] ),
212 'Normalization should remove duplicates in string-lists'
214 # ## "EMPTY" ARRAY VALUES
217 Html::expandAttributes( [
'class' => [] ] ),
218 'Value with an empty array'
222 Html::expandAttributes( [
'class' => [
null,
'',
' ',
' ' ] ] ),
223 'Array with null, empty string and spaces'
225 # ## NON-EMPTY ARRAY VALUES
228 Html::expandAttributes( [
'class' => [
235 'Normalization should remove duplicates in the array'
239 Html::expandAttributes( [
'class' => [
245 'Normalization should remove duplicates in string-lists in the array'
256 ' class="booltrue one"',
257 Html::expandAttributes( [
'class' => [
261 # Method
use isset() internally, make sure we
do discard
264 'boolfalse' =>
false,
282 Html::expandAttributes( [
'class' => [
297 Html::expandAttributes( [
310 '<select id="namespace" name="namespace">' .
"\n" .
311 '<option value="0">(Main)</option>' .
"\n" .
312 '<option value="1">Talk</option>' .
"\n" .
313 '<option value="2">User</option>' .
"\n" .
314 '<option value="3">User talk</option>' .
"\n" .
315 '<option value="4">MyWiki</option>' .
"\n" .
316 '<option value="5">MyWiki Talk</option>' .
"\n" .
317 '<option value="6">File</option>' .
"\n" .
318 '<option value="7">File talk</option>' .
"\n" .
319 '<option value="8">MediaWiki</option>' .
"\n" .
320 '<option value="9">MediaWiki talk</option>' .
"\n" .
321 '<option value="10">Template</option>' .
"\n" .
322 '<option value="11">Template talk</option>' .
"\n" .
323 '<option value="14">Category</option>' .
"\n" .
324 '<option value="15">Category talk</option>' .
"\n" .
325 '<option value="100">Custom</option>' .
"\n" .
326 '<option value="101">Custom talk</option>' .
"\n" .
328 Html::namespaceSelector(),
329 'Basic namespace selector without custom options'
333 '<label for="mw-test-namespace">Select a namespace:</label> ' .
334 '<select id="mw-test-namespace" name="wpNamespace">' .
"\n" .
335 '<option value="all">all</option>' .
"\n" .
336 '<option value="0">(Main)</option>' .
"\n" .
337 '<option value="1">Talk</option>' .
"\n" .
338 '<option value="2" selected="">User</option>' .
"\n" .
339 '<option value="3">User talk</option>' .
"\n" .
340 '<option value="4">MyWiki</option>' .
"\n" .
341 '<option value="5">MyWiki Talk</option>' .
"\n" .
342 '<option value="6">File</option>' .
"\n" .
343 '<option value="7">File talk</option>' .
"\n" .
344 '<option value="8">MediaWiki</option>' .
"\n" .
345 '<option value="9">MediaWiki talk</option>' .
"\n" .
346 '<option value="10">Template</option>' .
"\n" .
347 '<option value="11">Template talk</option>' .
"\n" .
348 '<option value="14">Category</option>' .
"\n" .
349 '<option value="15">Category talk</option>' .
"\n" .
350 '<option value="100">Custom</option>' .
"\n" .
351 '<option value="101">Custom talk</option>' .
"\n" .
353 Html::namespaceSelector(
354 [
'selected' =>
'2',
'all' =>
'all',
'label' =>
'Select a namespace:' ],
355 [
'name' =>
'wpNamespace',
'id' =>
'mw-test-namespace' ]
357 'Basic namespace selector with custom values'
361 '<label for="namespace">Select a namespace:</label> ' .
362 '<select id="namespace" name="namespace">' .
"\n" .
363 '<option value="0">(Main)</option>' .
"\n" .
364 '<option value="1">Talk</option>' .
"\n" .
365 '<option value="2">User</option>' .
"\n" .
366 '<option value="3">User talk</option>' .
"\n" .
367 '<option value="4">MyWiki</option>' .
"\n" .
368 '<option value="5">MyWiki Talk</option>' .
"\n" .
369 '<option value="6">File</option>' .
"\n" .
370 '<option value="7">File talk</option>' .
"\n" .
371 '<option value="8">MediaWiki</option>' .
"\n" .
372 '<option value="9">MediaWiki talk</option>' .
"\n" .
373 '<option value="10">Template</option>' .
"\n" .
374 '<option value="11">Template talk</option>' .
"\n" .
375 '<option value="14">Category</option>' .
"\n" .
376 '<option value="15">Category talk</option>' .
"\n" .
377 '<option value="100">Custom</option>' .
"\n" .
378 '<option value="101">Custom talk</option>' .
"\n" .
380 Html::namespaceSelector(
381 [
'label' =>
'Select a namespace:' ]
383 'Basic namespace selector with a custom label but no id attribtue for the <select>'
389 '<select id="namespace" name="namespace">' .
"\n" .
390 '<option value="2">User</option>' .
"\n" .
391 '<option value="4">MyWiki</option>' .
"\n" .
392 '<option value="5">MyWiki Talk</option>' .
"\n" .
393 '<option value="6">File</option>' .
"\n" .
394 '<option value="7">File talk</option>' .
"\n" .
395 '<option value="8">MediaWiki</option>' .
"\n" .
396 '<option value="9">MediaWiki talk</option>' .
"\n" .
397 '<option value="10">Template</option>' .
"\n" .
398 '<option value="11">Template talk</option>' .
"\n" .
399 '<option value="14">Category</option>' .
"\n" .
400 '<option value="15">Category talk</option>' .
"\n" .
402 Html::namespaceSelector(
403 [
'exclude' => [ 0, 1, 3, 100, 101 ] ]
405 'Namespace selector namespace filtering.'
411 '<select id="namespace" name="namespace">' .
"\n" .
412 '<option disabled="" value="0">(Main)</option>' .
"\n" .
413 '<option disabled="" value="1">Talk</option>' .
"\n" .
414 '<option disabled="" value="2">User</option>' .
"\n" .
415 '<option disabled="" value="3">User talk</option>' .
"\n" .
416 '<option disabled="" value="4">MyWiki</option>' .
"\n" .
417 '<option value="5">MyWiki Talk</option>' .
"\n" .
418 '<option value="6">File</option>' .
"\n" .
419 '<option value="7">File talk</option>' .
"\n" .
420 '<option value="8">MediaWiki</option>' .
"\n" .
421 '<option value="9">MediaWiki talk</option>' .
"\n" .
422 '<option value="10">Template</option>' .
"\n" .
423 '<option value="11">Template talk</option>' .
"\n" .
424 '<option value="14">Category</option>' .
"\n" .
425 '<option value="15">Category talk</option>' .
"\n" .
426 '<option value="100">Custom</option>' .
"\n" .
427 '<option value="101">Custom talk</option>' .
"\n" .
429 Html::namespaceSelector( [
430 'disable' => [ 0, 1, 2, 3, 4 ]
432 'Namespace selector namespace disabling'
442 '<input type="' . $HTML5InputType .
'"/>',
443 Html::element(
'input', [
'type' => $HTML5InputType ] ),
444 'In HTML5, Html::element() should accept type="' . $HTML5InputType .
'"'
470 $cases[] = [
$type ];
482 $this->assertEquals( $expected, Html::element( $element,
$attribs ), $message );
486 # Use cases in a concise format:
487 # <expected>, <element name>, <array of attributes> [, <message>]
488 # Will be mapped to Html::element()
491 # ## Generic cases, match $attribDefault static array
492 $cases[] = [
'<area/>',
493 'area', [
'shape' =>
'rect' ]
496 $cases[] = [
'<button type="submit"></button>',
497 'button', [
'formaction' =>
'GET' ]
499 $cases[] = [
'<button type="submit"></button>',
500 'button', [
'formenctype' =>
'application/x-www-form-urlencoded' ]
503 $cases[] = [
'<canvas></canvas>',
504 'canvas', [
'height' =>
'150' ]
506 $cases[] = [
'<canvas></canvas>',
507 'canvas', [
'width' =>
'300' ]
509 # Also check with numeric values
510 $cases[] = [
'<canvas></canvas>',
511 'canvas', [
'height' => 150 ]
513 $cases[] = [
'<canvas></canvas>',
514 'canvas', [
'width' => 300 ]
517 $cases[] = [
'<form></form>',
518 'form', [
'action' =>
'GET' ]
520 $cases[] = [
'<form></form>',
521 'form', [
'autocomplete' =>
'on' ]
523 $cases[] = [
'<form></form>',
524 'form', [
'enctype' =>
'application/x-www-form-urlencoded' ]
527 $cases[] = [
'<input/>',
528 'input', [
'formaction' =>
'GET' ]
530 $cases[] = [
'<input/>',
531 'input', [
'type' =>
'text' ]
534 $cases[] = [
'<keygen/>',
535 'keygen', [
'keytype' =>
'rsa' ]
538 $cases[] = [
'<link/>',
539 'link', [
'media' =>
'all' ]
542 $cases[] = [
'<menu></menu>',
543 'menu', [
'type' =>
'list' ]
546 $cases[] = [
'<script></script>',
547 'script', [
'type' =>
'text/javascript' ]
550 $cases[] = [
'<style></style>',
551 'style', [
'media' =>
'all' ]
553 $cases[] = [
'<style></style>',
554 'style', [
'type' =>
'text/css' ]
557 $cases[] = [
'<textarea></textarea>',
558 'textarea', [
'wrap' =>
'soft' ]
563 # <link type="text/css">
564 $cases[] = [
'<link/>',
565 'link', [
'type' =>
'text/css' ]
568 # <input> specific handling
569 $cases[] = [
'<input type="checkbox"/>',
570 'input', [
'type' =>
'checkbox',
'value' =>
'on' ],
571 'Default value "on" is stripped of checkboxes',
573 $cases[] = [
'<input type="radio"/>',
574 'input', [
'type' =>
'radio',
'value' =>
'on' ],
575 'Default value "on" is stripped of radio buttons',
577 $cases[] = [
'<input type="submit" value="Submit"/>',
578 'input', [
'type' =>
'submit',
'value' =>
'Submit' ],
579 'Default value "Submit" is kept on submit buttons (for possible l10n issues)',
581 $cases[] = [
'<input type="color"/>',
582 'input', [
'type' =>
'color',
'value' =>
'' ],
584 $cases[] = [
'<input type="range"/>',
585 'input', [
'type' =>
'range',
'value' =>
'' ],
588 # <button> specific handling
589 # see remarks on http:
590 $cases[] = [
'<button type="submit"></button>',
591 'button', [
'type' =>
'submit' ],
592 'According to standard the default type is "submit". '
593 .
'Depending on compatibility mode IE might use "button", instead.',
596 # <select> specific handling
597 $cases[] = [
'<select multiple=""></select>',
598 'select', [
'size' =>
'4',
'multiple' =>
true ],
600 # .. with numeric value
601 $cases[] = [
'<select multiple=""></select>',
602 'select', [
'size' => 4,
'multiple' =>
true ],
604 $cases[] = [
'<select></select>',
605 'select', [
'size' =>
'1',
'multiple' =>
false ],
607 # .. with numeric value
608 $cases[] = [
'<select></select>',
609 'select', [
'size' => 1,
'multiple' =>
false ],
612 # Passing an array as value
613 $cases[] = [
'<a class="css-class-one css-class-two"></a>',
614 'a', [
'class' => [
'css-class-one',
'css-class-two' ] ],
615 "dropDefaults accepts values given as an array"
618 # FIXME: doDropDefault should remove defaults given in an array
619 # Expected should be '<a></a>'
620 $cases[] = [
'<a class=""></a>',
621 'a', [
'class' => [
'',
'' ] ],
622 "dropDefaults accepts values given as an array"
625 # Craft the Html elements
627 foreach ( $cases
as $case ) {
631 isset( $case[3] ) ? $case[3] :
''
643 Html::expandAttributes( [
650 'Blacklist form validation attributes.'
654 Html::expandAttributes(
662 'Allow special case "step=any".'
669 '<input type="radio" value="testval" name="testname"/>',
670 Html::input(
'testname',
'testval',
'radio' ),
671 'Input wrapper with type and value.'
674 '<input name="testname"/>',
675 Html::input(
'testname' ),
676 'Input wrapper with all default values.'
682 '<input type="checkbox" value="1" name="testname"/>',
683 Html::check(
'testname' ),
684 'Checkbox wrapper unchecked.'
687 '<input checked="" type="checkbox" value="1" name="testname"/>',
688 Html::check(
'testname',
true ),
689 'Checkbox wrapper checked.'
692 '<input type="checkbox" value="testval" name="testname"/>',
693 Html::check(
'testname',
false, [
'value' =>
'testval' ] ),
694 'Checkbox wrapper with a value override.'
700 '<input type="radio" value="1" name="testname"/>',
701 Html::radio(
'testname' ),
702 'Radio wrapper unchecked.'
705 '<input checked="" type="radio" value="1" name="testname"/>',
706 Html::radio(
'testname',
true ),
707 'Radio wrapper checked.'
710 '<input type="radio" value="testval" name="testname"/>',
711 Html::radio(
'testname',
false, [
'value' =>
'testval' ] ),
712 'Radio wrapper with a value override.'
718 '<label for="testid">testlabel</label>',
719 Html::label(
'testlabel',
'testid' ),
726 [ [],
'',
'when there are no images, return empty string' ],
728 [
'1x' =>
'1x.png',
'1.5x' =>
'1_5x.png',
'2x' =>
'2x.png' ],
729 '1x.png 1x, 1_5x.png 1.5x, 2x.png 2x',
730 'pixel depth keys may include a trailing "x"'
733 [
'1' =>
'1x.png',
'1.5' =>
'1_5x.png',
'2' =>
'2x.png' ],
734 '1x.png 1x, 1_5x.png 1.5x, 2x.png 2x',
735 'pixel depth keys may omit a trailing "x"'
738 [
'1' =>
'small.png',
'1.5' =>
'large.png',
'2' =>
'large.png' ],
739 'small.png 1x, large.png 1.5x',
740 'omit larger duplicates'
743 [
'1' =>
'small.png',
'2' =>
'large.png',
'1.5' =>
'large.png' ],
744 'small.png 1x, large.png 1.5x',
745 'omit larger duplicates in irregular order'
755 $this->assertEquals( Html::srcSet( $images ), $expected, $message );
761 return 'stringValue';
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
tests for includes/Html.php
testExpandAttributesSkipsNullAndFalse()
Html::expandAttributes.
testCanDisableANamespaces()
testValueIsAuthoritativeInSpaceSeparatedAttributesArrays()
How do we handle duplicate keys in HTML attributes expansion? We could pass a "class" the values: 'GR...
testExpandAttributesForObjects()
Html::expandAttributes.
testXmlMimeType( $mimetype, $isXmlMimeType)
dataXmlMimeType Html::isXmlMimeType
static provideElementsWithAttributesHavingDefaultValues()
testExpandAttributesListValueAttributes()
Html::expandAttributes has special features for HTML attributes that use space separated lists and al...
static provideSrcSetImages()
testNamespaceSelector()
Html::namespaceSelector.
testFormValidationBlacklist()
Html::expandAttributes.
testExpandAttributesVariousExpansions()
Test for Html::expandAttributes() Please note it output a string prefixed with a space!...
testExpandAttributesSpaceSeparatedAttributesWithBoolean()
Test feature added by r96188, let pass attributes values as a PHP array.
testExpandAttributes_ArrayOnNonListValueAttribute_ThrowsException()
Html::expandAttributes MWException.
testCanFilterOutNamespaces()
testDropDefaults( $expected, $element, $attribs, $message='')
Test out Html::element drops or enforces default value Html::dropDefaults provideElementsWithAttribut...
testExpandAttributesForBooleans()
Html::expandAttributes.
testSrcSet( $images, $expected, $message)
provideSrcSetImages Html::srcSet
testExpandAttributesForNumbers()
Html::expandAttributes.
testElementBasics()
Html::element.
testHtmlElementAcceptsNewHtml5TypesInHtml5Mode( $HTML5InputType)
provideHtml5InputTypes Html::element
static provideHtml5InputTypes()
List of input element types values introduced by HTML5 Full list at http://www.w3....
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
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible values
namespace are movable Hooks may change this value to override the return value of MWNamespace::isMovable(). 'NewDifferenceEngine' 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
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
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
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
processing should stop and the error should be shown to the user * false
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