6 protected function setUp() {
10 'wgUseMediaWikiUIEverywhere' =>
false,
18 $langObj->setNamespaces( [
30 9 =>
'MediaWiki_talk',
32 11 =>
'Template_talk',
34 15 =>
'Category_talk',
49 'No close tag for short-tag elements'
53 '<element></element>',
55 'Close tag for empty element (null, null)'
59 '<element></element>',
61 'Close tag for empty element (array, string)'
67 'Self-closing tag for short-tag elements'
74 # HTML is not an XML MimeType
75 [
'text/html',
false ],
76 # XML is an XML MimeType
78 [
'application/xml',
true ],
79 # XHTML is an XML MimeType
80 [
'application/xhtml+xml',
true ],
81 # Make sure other +xml MimeTypes are supported
82 # SVG is another random MimeType even though we don't use it
83 [
'image/svg+xml',
true ],
84 # Complete random other MimeTypes are not XML
85 [
'text/plain',
false ],
105 'skip keys with null value'
109 'skip keys with false value'
114 'keep keys with an empty string'
125 'Boolean attributes do not generates output when value is false'
130 'Boolean attributes do not generates output when value is null'
136 'Boolean attributes have no value when value is true'
141 'Boolean attributes have no value when value is true (passed as numerical array)'
147 'Boolean attributes have empty string value when value is true'
158 'Integer value is cast to a string'
163 'Float value is cast to a string'
172 ' value="stringValue"',
174 'Object value is converted to a string'
188 'Empty string is always quoted'
193 'Simple string value needs no quotes'
198 'Number 1 value needs no quotes'
203 'Number 0 value needs no quotes'
217 ' class="redundant spaces here"',
219 'Normalization should strip redundant spaces'
224 'Normalization should remove duplicates in string-lists'
226 # ## "EMPTY" ARRAY VALUES
230 'Value with an empty array'
235 'Array with null, empty string and spaces'
237 # ## NON-EMPTY ARRAY VALUES
247 'Normalization should remove duplicates in the array'
257 'Normalization should remove duplicates in string-lists in the array'
268 ' class="booltrue one"',
273 # Method
use isset() internally, make sure we
do discard
276 'boolfalse' =>
false,
322 '<select id="namespace" name="namespace">' .
"\n" .
323 '<option value="0">(Main)</option>' .
"\n" .
324 '<option value="1">Talk</option>' .
"\n" .
325 '<option value="2">User</option>' .
"\n" .
326 '<option value="3">User talk</option>' .
"\n" .
327 '<option value="4">MyWiki</option>' .
"\n" .
328 '<option value="5">MyWiki Talk</option>' .
"\n" .
329 '<option value="6">File</option>' .
"\n" .
330 '<option value="7">File talk</option>' .
"\n" .
331 '<option value="8">MediaWiki</option>' .
"\n" .
332 '<option value="9">MediaWiki talk</option>' .
"\n" .
333 '<option value="10">Template</option>' .
"\n" .
334 '<option value="11">Template talk</option>' .
"\n" .
335 '<option value="14">Category</option>' .
"\n" .
336 '<option value="15">Category talk</option>' .
"\n" .
337 '<option value="100">Custom</option>' .
"\n" .
338 '<option value="101">Custom talk</option>' .
"\n" .
341 'Basic namespace selector without custom options'
345 '<label for="mw-test-namespace">Select a namespace:</label> ' .
346 '<select id="mw-test-namespace" name="wpNamespace">' .
"\n" .
347 '<option value="all">all</option>' .
"\n" .
348 '<option value="0">(Main)</option>' .
"\n" .
349 '<option value="1">Talk</option>' .
"\n" .
350 '<option value="2" selected="">User</option>' .
"\n" .
351 '<option value="3">User talk</option>' .
"\n" .
352 '<option value="4">MyWiki</option>' .
"\n" .
353 '<option value="5">MyWiki Talk</option>' .
"\n" .
354 '<option value="6">File</option>' .
"\n" .
355 '<option value="7">File talk</option>' .
"\n" .
356 '<option value="8">MediaWiki</option>' .
"\n" .
357 '<option value="9">MediaWiki talk</option>' .
"\n" .
358 '<option value="10">Template</option>' .
"\n" .
359 '<option value="11">Template talk</option>' .
"\n" .
360 '<option value="14">Category</option>' .
"\n" .
361 '<option value="15">Category talk</option>' .
"\n" .
362 '<option value="100">Custom</option>' .
"\n" .
363 '<option value="101">Custom talk</option>' .
"\n" .
366 [
'selected' =>
'2',
'all' =>
'all',
'label' =>
'Select a namespace:' ],
367 [
'name' =>
'wpNamespace',
'id' =>
'mw-test-namespace' ]
369 'Basic namespace selector with custom values'
373 '<label for="namespace">Select a namespace:</label> ' .
374 '<select id="namespace" name="namespace">' .
"\n" .
375 '<option value="0">(Main)</option>' .
"\n" .
376 '<option value="1">Talk</option>' .
"\n" .
377 '<option value="2">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 [
'label' =>
'Select a namespace:' ]
395 'Basic namespace selector with a custom label but no id attribtue for the <select>'
401 '<select id="namespace" name="namespace">' .
"\n" .
402 '<option value="2">User</option>' .
"\n" .
403 '<option value="4">MyWiki</option>' .
"\n" .
404 '<option value="5">MyWiki Talk</option>' .
"\n" .
405 '<option value="6">File</option>' .
"\n" .
406 '<option value="7">File talk</option>' .
"\n" .
407 '<option value="8">MediaWiki</option>' .
"\n" .
408 '<option value="9">MediaWiki talk</option>' .
"\n" .
409 '<option value="10">Template</option>' .
"\n" .
410 '<option value="11">Template talk</option>' .
"\n" .
411 '<option value="14">Category</option>' .
"\n" .
412 '<option value="15">Category talk</option>' .
"\n" .
415 [
'exclude' => [ 0, 1, 3, 100, 101 ] ]
417 'Namespace selector namespace filtering.'
423 '<select id="namespace" name="namespace">' .
"\n" .
424 '<option disabled="" value="0">(Main)</option>' .
"\n" .
425 '<option disabled="" value="1">Talk</option>' .
"\n" .
426 '<option disabled="" value="2">User</option>' .
"\n" .
427 '<option disabled="" value="3">User talk</option>' .
"\n" .
428 '<option disabled="" value="4">MyWiki</option>' .
"\n" .
429 '<option value="5">MyWiki Talk</option>' .
"\n" .
430 '<option value="6">File</option>' .
"\n" .
431 '<option value="7">File talk</option>' .
"\n" .
432 '<option value="8">MediaWiki</option>' .
"\n" .
433 '<option value="9">MediaWiki talk</option>' .
"\n" .
434 '<option value="10">Template</option>' .
"\n" .
435 '<option value="11">Template talk</option>' .
"\n" .
436 '<option value="14">Category</option>' .
"\n" .
437 '<option value="15">Category talk</option>' .
"\n" .
438 '<option value="100">Custom</option>' .
"\n" .
439 '<option value="101">Custom talk</option>' .
"\n" .
442 'disable' => [ 0, 1, 2, 3, 4 ]
444 'Namespace selector namespace disabling'
454 '<input type="' . $HTML5InputType .
'"/>',
456 'In HTML5, Html::element() should accept type="' . $HTML5InputType .
'"'
482 $cases[] = [
$type ];
498 # Use cases in a concise format:
499 # <expected>, <element name>, <array of attributes> [, <message>]
500 # Will be mapped to Html::element()
503 # ## Generic cases, match $attribDefault static array
504 $cases[] = [
'<area/>',
505 'area', [
'shape' =>
'rect' ]
508 $cases[] = [
'<button type="submit"></button>',
509 'button', [
'formaction' =>
'GET' ]
511 $cases[] = [
'<button type="submit"></button>',
512 'button', [
'formenctype' =>
'application/x-www-form-urlencoded' ]
515 $cases[] = [
'<canvas></canvas>',
516 'canvas', [
'height' =>
'150' ]
518 $cases[] = [
'<canvas></canvas>',
519 'canvas', [
'width' =>
'300' ]
521 # Also check with numeric values
522 $cases[] = [
'<canvas></canvas>',
523 'canvas', [
'height' => 150 ]
525 $cases[] = [
'<canvas></canvas>',
526 'canvas', [
'width' => 300 ]
529 $cases[] = [
'<command/>',
530 'command', [
'type' =>
'command' ]
533 $cases[] = [
'<form></form>',
534 'form', [
'action' =>
'GET' ]
536 $cases[] = [
'<form></form>',
537 'form', [
'autocomplete' =>
'on' ]
539 $cases[] = [
'<form></form>',
540 'form', [
'enctype' =>
'application/x-www-form-urlencoded' ]
543 $cases[] = [
'<input/>',
544 'input', [
'formaction' =>
'GET' ]
546 $cases[] = [
'<input/>',
547 'input', [
'type' =>
'text' ]
550 $cases[] = [
'<keygen/>',
551 'keygen', [
'keytype' =>
'rsa' ]
554 $cases[] = [
'<link/>',
555 'link', [
'media' =>
'all' ]
558 $cases[] = [
'<menu></menu>',
559 'menu', [
'type' =>
'list' ]
562 $cases[] = [
'<script></script>',
563 'script', [
'type' =>
'text/javascript' ]
566 $cases[] = [
'<style></style>',
567 'style', [
'media' =>
'all' ]
569 $cases[] = [
'<style></style>',
570 'style', [
'type' =>
'text/css' ]
573 $cases[] = [
'<textarea></textarea>',
574 'textarea', [
'wrap' =>
'soft' ]
579 # <link type="text/css">
580 $cases[] = [
'<link/>',
581 'link', [
'type' =>
'text/css' ]
584 # <input> specific handling
585 $cases[] = [
'<input type="checkbox"/>',
586 'input', [
'type' =>
'checkbox',
'value' =>
'on' ],
587 'Default value "on" is stripped of checkboxes',
589 $cases[] = [
'<input type="radio"/>',
590 'input', [
'type' =>
'radio',
'value' =>
'on' ],
591 'Default value "on" is stripped of radio buttons',
593 $cases[] = [
'<input type="submit" value="Submit"/>',
594 'input', [
'type' =>
'submit',
'value' =>
'Submit' ],
595 'Default value "Submit" is kept on submit buttons (for possible l10n issues)',
597 $cases[] = [
'<input type="color"/>',
598 'input', [
'type' =>
'color',
'value' =>
'' ],
600 $cases[] = [
'<input type="range"/>',
601 'input', [
'type' =>
'range',
'value' =>
'' ],
604 # <button> specific handling
605 # see remarks on http://msdn.microsoft.com/en-us/library/ie/ms535211%28v=vs.85%29.aspx
606 $cases[] = [
'<button type="submit"></button>',
607 'button', [
'type' =>
'submit' ],
608 'According to standard the default type is "submit". '
609 .
'Depending on compatibility mode IE might use "button", instead.',
612 # <select> specific handling
613 $cases[] = [
'<select multiple=""></select>',
614 'select', [
'size' =>
'4',
'multiple' =>
true ],
616 # .. with numeric value
617 $cases[] = [
'<select multiple=""></select>',
618 'select', [
'size' => 4,
'multiple' =>
true ],
620 $cases[] = [
'<select></select>',
621 'select', [
'size' =>
'1',
'multiple' =>
false ],
623 # .. with numeric value
624 $cases[] = [
'<select></select>',
625 'select', [
'size' => 1,
'multiple' =>
false ],
628 # Passing an array as value
629 $cases[] = [
'<a class="css-class-one css-class-two"></a>',
630 'a', [
'class' => [
'css-class-one',
'css-class-two' ] ],
631 "dropDefaults accepts values given as an array"
634 # FIXME: doDropDefault should remove defaults given in an array
635 # Expected should be '<a></a>'
636 $cases[] = [
'<a class=""></a>',
637 'a', [
'class' => [
'',
'' ] ],
638 "dropDefaults accepts values given as an array"
641 # Craft the Html elements
643 foreach ( $cases
as $case ) {
647 isset( $case[3] ) ? $case[3] :
''
666 'Blacklist form validation attributes.'
678 'Allow special case "step=any".'
685 '<input type="radio" value="testval" name="testname"/>',
687 'Input wrapper with type and value.'
690 '<input name="testname"/>',
692 'Input wrapper with all default values.'
698 '<input type="checkbox" value="1" name="testname"/>',
700 'Checkbox wrapper unchecked.'
703 '<input checked="" type="checkbox" value="1" name="testname"/>',
705 'Checkbox wrapper checked.'
708 '<input type="checkbox" value="testval" name="testname"/>',
709 Html::check(
'testname',
false, [
'value' =>
'testval' ] ),
710 'Checkbox wrapper with a value override.'
716 '<input type="radio" value="1" name="testname"/>',
718 'Radio wrapper unchecked.'
721 '<input checked="" type="radio" value="1" name="testname"/>',
723 'Radio wrapper checked.'
726 '<input type="radio" value="testval" name="testname"/>',
727 Html::radio(
'testname',
false, [
'value' =>
'testval' ] ),
728 'Radio wrapper with a value override.'
734 '<label for="testid">testlabel</label>',
742 [ [],
'',
'when there are no images, return empty string' ],
744 [
'1x' =>
'1x.png',
'1.5x' =>
'1_5x.png',
'2x' =>
'2x.png' ],
745 '1x.png 1x, 1_5x.png 1.5x, 2x.png 2x',
746 'pixel depth keys may include a trailing "x"'
749 [
'1' =>
'1x.png',
'1.5' =>
'1_5x.png',
'2' =>
'2x.png' ],
750 '1x.png 1x, 1_5x.png 1.5x, 2x.png 2x',
751 'pixel depth keys may omit a trailing "x"'
761 $this->assertEquals(
Html::srcSet( $images ), $expected, $message );
767 return 'stringValue';
testExpandAttributes_ArrayOnNonListValueAttribute_ThrowsException()
Html::expandAttributes MWException
testHtmlElementAcceptsNewHtml5TypesInHtml5Mode($HTML5InputType)
provideHtml5InputTypes Html::element
testCanDisableANamespaces()
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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
static provideHtml5InputTypes()
List of input element types values introduced by HTML5 Full list at http://www.w3.org/TR/html-markup/input.html.
processing should stop and the error should be shown to the user * false
testElementBasics()
Html::element.
testXmlMimeType($mimetype, $isXmlMimeType)
dataXmlMimeType Html::isXmlMimeType
testExpandAttributesVariousExpansions()
Test for Html::expandAttributes() Please note it output a string prefixed with a space! Html::expand...
static radio($name, $checked=false, array $attribs=[])
Convenience function to produce a radio button (input element with type=radio)
testCanFilterOutNamespaces()
tests for includes/Html.php
testFormValidationBlacklist()
Html::expandAttributes
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
testExpandAttributesForNumbers()
Html::expandAttributes
static check($name, $checked=false, array $attribs=[])
Convenience function to produce a checkbox (input element with type=checkbox)
testExpandAttributesSpaceSeparatedAttributesWithBoolean()
Test feature added by r96188, let pass attributes values as a PHP array.
testExpandAttributesListValueAttributes()
Html::expandAttributes has special features for HTML attributes that use space separated lists and al...
testExpandAttributesForObjects()
Html::expandAttributes
static expandAttributes(array $attribs)
Given an associative array of element attributes, generate a string to stick after the element name i...
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
testExpandAttributesForBooleans()
Html::expandAttributes
testDropDefaults($expected, $element, $attribs, $message= '')
Test out Html::element drops or enforces default value Html::dropDefaults provideElementsWithAttrib...
static srcSet(array $urls)
Generate a srcset attribute value.
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
testNamespaceSelector()
Html::namespaceSelector
static isXmlMimeType($mimetype)
Determines if the given MIME type is xml.
static provideSrcSetImages()
!html< table >< tr >< td > broken</td ></tr ></table >!end!test Table cell attributes
testExpandAttributesSkipsNullAndFalse()
Html::expandAttributes
testValueIsAuthoritativeInSpaceSeparatedAttributesArrays()
How do we handle duplicate keys in HTML attributes expansion? We could pass a "class" the values: 'GR...
static factory($code)
Get a cached or new language object for a given language code.
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible values
static element($element, $attribs=[], $contents= '')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
testSrcSet($images, $expected, $message)
provideSrcSetImages Html::srcSet
static provideElementsWithAttributesHavingDefaultValues()
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 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
static label($label, $id, array $attribs=[])
Convenience function for generating a label for inputs.
static namespaceSelector(array $params=[], array $selectAttribs=[])
Build a drop-down box for selecting a namespace.