MediaWiki  1.29.1
HtmlTest.php
Go to the documentation of this file.
1 <?php
4 class HtmlTest extends MediaWikiTestCase {
5 
6  protected function setUp() {
7  parent::setUp();
8 
9  $this->setMwGlobals( [
10  'wgUseMediaWikiUIEverywhere' => false,
11  ] );
12 
13  $langObj = Language::factory( 'en' );
14 
15  // Hardcode namespaces during test runs,
16  // so that html output based on existing namespaces
17  // can be properly evaluated.
18  $langObj->setNamespaces( [
19  -2 => 'Media',
20  -1 => 'Special',
21  0 => '',
22  1 => 'Talk',
23  2 => 'User',
24  3 => 'User_talk',
25  4 => 'MyWiki',
26  5 => 'MyWiki_Talk',
27  6 => 'File',
28  7 => 'File_talk',
29  8 => 'MediaWiki',
30  9 => 'MediaWiki_talk',
31  10 => 'Template',
32  11 => 'Template_talk',
33  14 => 'Category',
34  15 => 'Category_talk',
35  100 => 'Custom',
36  101 => 'Custom_talk',
37  ] );
38  $this->setUserLang( $langObj );
39  $this->setContentLang( $langObj );
40  }
41 
48  public function testElementBasics() {
49  $this->assertEquals(
50  '<img/>',
51  Html::element( 'img', null, '' ),
52  'Self-closing tag for short-tag elements'
53  );
54 
55  $this->assertEquals(
56  '<element></element>',
57  Html::element( 'element', null, null ),
58  'Close tag for empty element (null, null)'
59  );
60 
61  $this->assertEquals(
62  '<element></element>',
63  Html::element( 'element', [], '' ),
64  'Close tag for empty element (array, string)'
65  );
66  }
67 
68  public function dataXmlMimeType() {
69  return [
70  // ( $mimetype, $isXmlMimeType )
71  # HTML is not an XML MimeType
72  [ 'text/html', false ],
73  # XML is an XML MimeType
74  [ 'text/xml', true ],
75  [ 'application/xml', true ],
76  # XHTML is an XML MimeType
77  [ 'application/xhtml+xml', true ],
78  # Make sure other +xml MimeTypes are supported
79  # SVG is another random MimeType even though we don't use it
80  [ 'image/svg+xml', true ],
81  # Complete random other MimeTypes are not XML
82  [ 'text/plain', false ],
83  ];
84  }
85 
90  public function testXmlMimeType( $mimetype, $isXmlMimeType ) {
91  $this->assertEquals( $isXmlMimeType, Html::isXmlMimeType( $mimetype ) );
92  }
93 
97  public function testExpandAttributesSkipsNullAndFalse() {
98  # ## EMPTY ########
99  $this->assertEmpty(
100  Html::expandAttributes( [ 'foo' => null ] ),
101  'skip keys with null value'
102  );
103  $this->assertEmpty(
104  Html::expandAttributes( [ 'foo' => false ] ),
105  'skip keys with false value'
106  );
107  $this->assertEquals(
108  ' foo=""',
109  Html::expandAttributes( [ 'foo' => '' ] ),
110  'keep keys with an empty string'
111  );
112  }
113 
117  public function testExpandAttributesForBooleans() {
118  $this->assertEquals(
119  '',
120  Html::expandAttributes( [ 'selected' => false ] ),
121  'Boolean attributes do not generates output when value is false'
122  );
123  $this->assertEquals(
124  '',
125  Html::expandAttributes( [ 'selected' => null ] ),
126  'Boolean attributes do not generates output when value is null'
127  );
128 
129  $this->assertEquals(
130  ' selected=""',
131  Html::expandAttributes( [ 'selected' => true ] ),
132  'Boolean attributes have no value when value is true'
133  );
134  $this->assertEquals(
135  ' selected=""',
136  Html::expandAttributes( [ 'selected' ] ),
137  'Boolean attributes have no value when value is true (passed as numerical array)'
138  );
139  }
140 
144  public function testExpandAttributesForNumbers() {
145  $this->assertEquals(
146  ' value="1"',
147  Html::expandAttributes( [ 'value' => 1 ] ),
148  'Integer value is cast to a string'
149  );
150  $this->assertEquals(
151  ' value="1.1"',
152  Html::expandAttributes( [ 'value' => 1.1 ] ),
153  'Float value is cast to a string'
154  );
155  }
156 
160  public function testExpandAttributesForObjects() {
161  $this->assertEquals(
162  ' value="stringValue"',
163  Html::expandAttributes( [ 'value' => new HtmlTestValue() ] ),
164  'Object value is converted to a string'
165  );
166  }
167 
173  public function testExpandAttributesVariousExpansions() {
174  # ## NOT EMPTY ####
175  $this->assertEquals(
176  ' empty_string=""',
177  Html::expandAttributes( [ 'empty_string' => '' ] ),
178  'Empty string is always quoted'
179  );
180  $this->assertEquals(
181  ' key="value"',
182  Html::expandAttributes( [ 'key' => 'value' ] ),
183  'Simple string value needs no quotes'
184  );
185  $this->assertEquals(
186  ' one="1"',
187  Html::expandAttributes( [ 'one' => 1 ] ),
188  'Number 1 value needs no quotes'
189  );
190  $this->assertEquals(
191  ' zero="0"',
192  Html::expandAttributes( [ 'zero' => 0 ] ),
193  'Number 0 value needs no quotes'
194  );
195  }
196 
203  public function testExpandAttributesListValueAttributes() {
204  # ## STRING VALUES
205  $this->assertEquals(
206  ' class="redundant spaces here"',
207  Html::expandAttributes( [ 'class' => ' redundant spaces here ' ] ),
208  'Normalization should strip redundant spaces'
209  );
210  $this->assertEquals(
211  ' class="foo bar"',
212  Html::expandAttributes( [ 'class' => 'foo bar foo bar bar' ] ),
213  'Normalization should remove duplicates in string-lists'
214  );
215  # ## "EMPTY" ARRAY VALUES
216  $this->assertEquals(
217  ' class=""',
218  Html::expandAttributes( [ 'class' => [] ] ),
219  'Value with an empty array'
220  );
221  $this->assertEquals(
222  ' class=""',
223  Html::expandAttributes( [ 'class' => [ null, '', ' ', ' ' ] ] ),
224  'Array with null, empty string and spaces'
225  );
226  # ## NON-EMPTY ARRAY VALUES
227  $this->assertEquals(
228  ' class="foo bar"',
229  Html::expandAttributes( [ 'class' => [
230  'foo',
231  'bar',
232  'foo',
233  'bar',
234  'bar',
235  ] ] ),
236  'Normalization should remove duplicates in the array'
237  );
238  $this->assertEquals(
239  ' class="foo bar"',
240  Html::expandAttributes( [ 'class' => [
241  'foo bar',
242  'bar foo',
243  'foo',
244  'bar bar',
245  ] ] ),
246  'Normalization should remove duplicates in string-lists in the array'
247  );
248  }
249 
255  public function testExpandAttributesSpaceSeparatedAttributesWithBoolean() {
256  $this->assertEquals(
257  ' class="booltrue one"',
258  Html::expandAttributes( [ 'class' => [
259  'booltrue' => true,
260  'one' => 1,
261 
262  # Method use isset() internally, make sure we do discard
263  # attributes values which have been assigned well known values
264  'emptystring' => '',
265  'boolfalse' => false,
266  'zero' => 0,
267  'null' => null,
268  ] ] )
269  );
270  }
271 
280  public function testValueIsAuthoritativeInSpaceSeparatedAttributesArrays() {
281  $this->assertEquals(
282  ' class=""',
283  Html::expandAttributes( [ 'class' => [
284  'GREEN',
285  'GREEN' => false,
286  'GREEN',
287  ] ] )
288  );
289  }
290 
295  public function testExpandAttributes_ArrayOnNonListValueAttribute_ThrowsException() {
296  // Real-life test case found in the Popups extension (see Gerrit cf0fd64),
297  // when used with an outdated BetaFeatures extension (see Gerrit deda1e7)
299  'src' => [
300  'ltr' => 'ltr.svg',
301  'rtl' => 'rtl.svg'
302  ]
303  ] );
304  }
305 
310  public function testNamespaceSelector() {
311  $this->assertEquals(
312  '<select id="namespace" name="namespace">' . "\n" .
313  '<option value="0">(Main)</option>' . "\n" .
314  '<option value="1">Talk</option>' . "\n" .
315  '<option value="2">User</option>' . "\n" .
316  '<option value="3">User talk</option>' . "\n" .
317  '<option value="4">MyWiki</option>' . "\n" .
318  '<option value="5">MyWiki Talk</option>' . "\n" .
319  '<option value="6">File</option>' . "\n" .
320  '<option value="7">File talk</option>' . "\n" .
321  '<option value="8">MediaWiki</option>' . "\n" .
322  '<option value="9">MediaWiki talk</option>' . "\n" .
323  '<option value="10">Template</option>' . "\n" .
324  '<option value="11">Template talk</option>' . "\n" .
325  '<option value="14">Category</option>' . "\n" .
326  '<option value="15">Category talk</option>' . "\n" .
327  '<option value="100">Custom</option>' . "\n" .
328  '<option value="101">Custom talk</option>' . "\n" .
329  '</select>',
331  'Basic namespace selector without custom options'
332  );
333 
334  $this->assertEquals(
335  '<label for="mw-test-namespace">Select a namespace:</label>&#160;' .
336  '<select id="mw-test-namespace" name="wpNamespace">' . "\n" .
337  '<option value="all">all</option>' . "\n" .
338  '<option value="0">(Main)</option>' . "\n" .
339  '<option value="1">Talk</option>' . "\n" .
340  '<option value="2" selected="">User</option>' . "\n" .
341  '<option value="3">User talk</option>' . "\n" .
342  '<option value="4">MyWiki</option>' . "\n" .
343  '<option value="5">MyWiki Talk</option>' . "\n" .
344  '<option value="6">File</option>' . "\n" .
345  '<option value="7">File talk</option>' . "\n" .
346  '<option value="8">MediaWiki</option>' . "\n" .
347  '<option value="9">MediaWiki talk</option>' . "\n" .
348  '<option value="10">Template</option>' . "\n" .
349  '<option value="11">Template talk</option>' . "\n" .
350  '<option value="14">Category</option>' . "\n" .
351  '<option value="15">Category talk</option>' . "\n" .
352  '<option value="100">Custom</option>' . "\n" .
353  '<option value="101">Custom talk</option>' . "\n" .
354  '</select>',
356  [ 'selected' => '2', 'all' => 'all', 'label' => 'Select a namespace:' ],
357  [ 'name' => 'wpNamespace', 'id' => 'mw-test-namespace' ]
358  ),
359  'Basic namespace selector with custom values'
360  );
361 
362  $this->assertEquals(
363  '<label for="namespace">Select a namespace:</label>&#160;' .
364  '<select id="namespace" name="namespace">' . "\n" .
365  '<option value="0">(Main)</option>' . "\n" .
366  '<option value="1">Talk</option>' . "\n" .
367  '<option value="2">User</option>' . "\n" .
368  '<option value="3">User talk</option>' . "\n" .
369  '<option value="4">MyWiki</option>' . "\n" .
370  '<option value="5">MyWiki Talk</option>' . "\n" .
371  '<option value="6">File</option>' . "\n" .
372  '<option value="7">File talk</option>' . "\n" .
373  '<option value="8">MediaWiki</option>' . "\n" .
374  '<option value="9">MediaWiki talk</option>' . "\n" .
375  '<option value="10">Template</option>' . "\n" .
376  '<option value="11">Template talk</option>' . "\n" .
377  '<option value="14">Category</option>' . "\n" .
378  '<option value="15">Category talk</option>' . "\n" .
379  '<option value="100">Custom</option>' . "\n" .
380  '<option value="101">Custom talk</option>' . "\n" .
381  '</select>',
383  [ 'label' => 'Select a namespace:' ]
384  ),
385  'Basic namespace selector with a custom label but no id attribtue for the <select>'
386  );
387  }
388 
389  public function testCanFilterOutNamespaces() {
390  $this->assertEquals(
391  '<select id="namespace" name="namespace">' . "\n" .
392  '<option value="2">User</option>' . "\n" .
393  '<option value="4">MyWiki</option>' . "\n" .
394  '<option value="5">MyWiki Talk</option>' . "\n" .
395  '<option value="6">File</option>' . "\n" .
396  '<option value="7">File talk</option>' . "\n" .
397  '<option value="8">MediaWiki</option>' . "\n" .
398  '<option value="9">MediaWiki talk</option>' . "\n" .
399  '<option value="10">Template</option>' . "\n" .
400  '<option value="11">Template talk</option>' . "\n" .
401  '<option value="14">Category</option>' . "\n" .
402  '<option value="15">Category talk</option>' . "\n" .
403  '</select>',
405  [ 'exclude' => [ 0, 1, 3, 100, 101 ] ]
406  ),
407  'Namespace selector namespace filtering.'
408  );
409  }
410 
411  public function testCanDisableANamespaces() {
412  $this->assertEquals(
413  '<select id="namespace" name="namespace">' . "\n" .
414  '<option disabled="" value="0">(Main)</option>' . "\n" .
415  '<option disabled="" value="1">Talk</option>' . "\n" .
416  '<option disabled="" value="2">User</option>' . "\n" .
417  '<option disabled="" value="3">User talk</option>' . "\n" .
418  '<option disabled="" value="4">MyWiki</option>' . "\n" .
419  '<option value="5">MyWiki Talk</option>' . "\n" .
420  '<option value="6">File</option>' . "\n" .
421  '<option value="7">File talk</option>' . "\n" .
422  '<option value="8">MediaWiki</option>' . "\n" .
423  '<option value="9">MediaWiki talk</option>' . "\n" .
424  '<option value="10">Template</option>' . "\n" .
425  '<option value="11">Template talk</option>' . "\n" .
426  '<option value="14">Category</option>' . "\n" .
427  '<option value="15">Category talk</option>' . "\n" .
428  '<option value="100">Custom</option>' . "\n" .
429  '<option value="101">Custom talk</option>' . "\n" .
430  '</select>',
432  'disable' => [ 0, 1, 2, 3, 4 ]
433  ] ),
434  'Namespace selector namespace disabling'
435  );
436  }
437 
442  public function testHtmlElementAcceptsNewHtml5TypesInHtml5Mode( $HTML5InputType ) {
443  $this->assertEquals(
444  '<input type="' . $HTML5InputType . '"/>',
445  Html::element( 'input', [ 'type' => $HTML5InputType ] ),
446  'In HTML5, Html::element() should accept type="' . $HTML5InputType . '"'
447  );
448  }
449 
454  public static function provideHtml5InputTypes() {
455  $types = [
456  'datetime',
457  'datetime-local',
458  'date',
459  'month',
460  'time',
461  'week',
462  'number',
463  'range',
464  'email',
465  'url',
466  'search',
467  'tel',
468  'color',
469  ];
470  $cases = [];
471  foreach ( $types as $type ) {
472  $cases[] = [ $type ];
473  }
474 
475  return $cases;
476  }
477 
483  public function testDropDefaults( $expected, $element, $attribs, $message = '' ) {
484  $this->assertEquals( $expected, Html::element( $element, $attribs ), $message );
485  }
486 
487  public static function provideElementsWithAttributesHavingDefaultValues() {
488  # Use cases in a concise format:
489  # <expected>, <element name>, <array of attributes> [, <message>]
490  # Will be mapped to Html::element()
491  $cases = [];
492 
493  # ## Generic cases, match $attribDefault static array
494  $cases[] = [ '<area/>',
495  'area', [ 'shape' => 'rect' ]
496  ];
497 
498  $cases[] = [ '<button type="submit"></button>',
499  'button', [ 'formaction' => 'GET' ]
500  ];
501  $cases[] = [ '<button type="submit"></button>',
502  'button', [ 'formenctype' => 'application/x-www-form-urlencoded' ]
503  ];
504 
505  $cases[] = [ '<canvas></canvas>',
506  'canvas', [ 'height' => '150' ]
507  ];
508  $cases[] = [ '<canvas></canvas>',
509  'canvas', [ 'width' => '300' ]
510  ];
511  # Also check with numeric values
512  $cases[] = [ '<canvas></canvas>',
513  'canvas', [ 'height' => 150 ]
514  ];
515  $cases[] = [ '<canvas></canvas>',
516  'canvas', [ 'width' => 300 ]
517  ];
518 
519  $cases[] = [ '<form></form>',
520  'form', [ 'action' => 'GET' ]
521  ];
522  $cases[] = [ '<form></form>',
523  'form', [ 'autocomplete' => 'on' ]
524  ];
525  $cases[] = [ '<form></form>',
526  'form', [ 'enctype' => 'application/x-www-form-urlencoded' ]
527  ];
528 
529  $cases[] = [ '<input/>',
530  'input', [ 'formaction' => 'GET' ]
531  ];
532  $cases[] = [ '<input/>',
533  'input', [ 'type' => 'text' ]
534  ];
535 
536  $cases[] = [ '<keygen/>',
537  'keygen', [ 'keytype' => 'rsa' ]
538  ];
539 
540  $cases[] = [ '<link/>',
541  'link', [ 'media' => 'all' ]
542  ];
543 
544  $cases[] = [ '<menu></menu>',
545  'menu', [ 'type' => 'list' ]
546  ];
547 
548  $cases[] = [ '<script></script>',
549  'script', [ 'type' => 'text/javascript' ]
550  ];
551 
552  $cases[] = [ '<style></style>',
553  'style', [ 'media' => 'all' ]
554  ];
555  $cases[] = [ '<style></style>',
556  'style', [ 'type' => 'text/css' ]
557  ];
558 
559  $cases[] = [ '<textarea></textarea>',
560  'textarea', [ 'wrap' => 'soft' ]
561  ];
562 
563  # ## SPECIFIC CASES
564 
565  # <link type="text/css">
566  $cases[] = [ '<link/>',
567  'link', [ 'type' => 'text/css' ]
568  ];
569 
570  # <input> specific handling
571  $cases[] = [ '<input type="checkbox"/>',
572  'input', [ 'type' => 'checkbox', 'value' => 'on' ],
573  'Default value "on" is stripped of checkboxes',
574  ];
575  $cases[] = [ '<input type="radio"/>',
576  'input', [ 'type' => 'radio', 'value' => 'on' ],
577  'Default value "on" is stripped of radio buttons',
578  ];
579  $cases[] = [ '<input type="submit" value="Submit"/>',
580  'input', [ 'type' => 'submit', 'value' => 'Submit' ],
581  'Default value "Submit" is kept on submit buttons (for possible l10n issues)',
582  ];
583  $cases[] = [ '<input type="color"/>',
584  'input', [ 'type' => 'color', 'value' => '' ],
585  ];
586  $cases[] = [ '<input type="range"/>',
587  'input', [ 'type' => 'range', 'value' => '' ],
588  ];
589 
590  # <button> specific handling
591  # see remarks on http://msdn.microsoft.com/en-us/library/ie/ms535211%28v=vs.85%29.aspx
592  $cases[] = [ '<button type="submit"></button>',
593  'button', [ 'type' => 'submit' ],
594  'According to standard the default type is "submit". '
595  . 'Depending on compatibility mode IE might use "button", instead.',
596  ];
597 
598  # <select> specific handling
599  $cases[] = [ '<select multiple=""></select>',
600  'select', [ 'size' => '4', 'multiple' => true ],
601  ];
602  # .. with numeric value
603  $cases[] = [ '<select multiple=""></select>',
604  'select', [ 'size' => 4, 'multiple' => true ],
605  ];
606  $cases[] = [ '<select></select>',
607  'select', [ 'size' => '1', 'multiple' => false ],
608  ];
609  # .. with numeric value
610  $cases[] = [ '<select></select>',
611  'select', [ 'size' => 1, 'multiple' => false ],
612  ];
613 
614  # Passing an array as value
615  $cases[] = [ '<a class="css-class-one css-class-two"></a>',
616  'a', [ 'class' => [ 'css-class-one', 'css-class-two' ] ],
617  "dropDefaults accepts values given as an array"
618  ];
619 
620  # FIXME: doDropDefault should remove defaults given in an array
621  # Expected should be '<a></a>'
622  $cases[] = [ '<a class=""></a>',
623  'a', [ 'class' => [ '', '' ] ],
624  "dropDefaults accepts values given as an array"
625  ];
626 
627  # Craft the Html elements
628  $ret = [];
629  foreach ( $cases as $case ) {
630  $ret[] = [
631  $case[0],
632  $case[1], $case[2],
633  isset( $case[3] ) ? $case[3] : ''
634  ];
635  }
636 
637  return $ret;
638  }
639 
640  public function testWrapperInput() {
641  $this->assertEquals(
642  '<input type="radio" value="testval" name="testname"/>',
643  Html::input( 'testname', 'testval', 'radio' ),
644  'Input wrapper with type and value.'
645  );
646  $this->assertEquals(
647  '<input name="testname"/>',
648  Html::input( 'testname' ),
649  'Input wrapper with all default values.'
650  );
651  }
652 
653  public function testWrapperCheck() {
654  $this->assertEquals(
655  '<input type="checkbox" value="1" name="testname"/>',
656  Html::check( 'testname' ),
657  'Checkbox wrapper unchecked.'
658  );
659  $this->assertEquals(
660  '<input checked="" type="checkbox" value="1" name="testname"/>',
661  Html::check( 'testname', true ),
662  'Checkbox wrapper checked.'
663  );
664  $this->assertEquals(
665  '<input type="checkbox" value="testval" name="testname"/>',
666  Html::check( 'testname', false, [ 'value' => 'testval' ] ),
667  'Checkbox wrapper with a value override.'
668  );
669  }
670 
671  public function testWrapperRadio() {
672  $this->assertEquals(
673  '<input type="radio" value="1" name="testname"/>',
674  Html::radio( 'testname' ),
675  'Radio wrapper unchecked.'
676  );
677  $this->assertEquals(
678  '<input checked="" type="radio" value="1" name="testname"/>',
679  Html::radio( 'testname', true ),
680  'Radio wrapper checked.'
681  );
682  $this->assertEquals(
683  '<input type="radio" value="testval" name="testname"/>',
684  Html::radio( 'testname', false, [ 'value' => 'testval' ] ),
685  'Radio wrapper with a value override.'
686  );
687  }
688 
689  public function testWrapperLabel() {
690  $this->assertEquals(
691  '<label for="testid">testlabel</label>',
692  Html::label( 'testlabel', 'testid' ),
693  'Label wrapper'
694  );
695  }
696 
697  public static function provideSrcSetImages() {
698  return [
699  [ [], '', 'when there are no images, return empty string' ],
700  [
701  [ '1x' => '1x.png', '1.5x' => '1_5x.png', '2x' => '2x.png' ],
702  '1x.png 1x, 1_5x.png 1.5x, 2x.png 2x',
703  'pixel depth keys may include a trailing "x"'
704  ],
705  [
706  [ '1' => '1x.png', '1.5' => '1_5x.png', '2' => '2x.png' ],
707  '1x.png 1x, 1_5x.png 1.5x, 2x.png 2x',
708  'pixel depth keys may omit a trailing "x"'
709  ],
710  [
711  [ '1' => 'small.png', '1.5' => 'large.png', '2' => 'large.png' ],
712  'small.png 1x, large.png 1.5x',
713  'omit larger duplicates'
714  ],
715  [
716  [ '1' => 'small.png', '2' => 'large.png', '1.5' => 'large.png' ],
717  'small.png 1x, large.png 1.5x',
718  'omit larger duplicates in irregular order'
719  ],
720  ];
721  }
722 
727  public function testSrcSet( $images, $expected, $message ) {
728  $this->assertEquals( Html::srcSet( $images ), $expected, $message );
729  }
730 }
731 
732 class HtmlTestValue {
733  function __toString() {
734  return 'stringValue';
735  }
736 }
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
well
page as well
Definition: All_system_messages.txt:2725
Html\check
static check( $name, $checked=false, array $attribs=[])
Convenience function to produce a checkbox (input element with type=checkbox)
Definition: Html.php:684
use
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
Definition: MIT-LICENSE.txt:10
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
$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
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
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
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:658
MediaWikiTestCase
Definition: MediaWikiTestCase.php:13
$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\radio
static radio( $name, $checked=false, array $attribs=[])
Convenience function to produce a radio button (input element with type=radio)
Definition: Html.php:707
MediaWikiTestCase\setUserLang
setUserLang( $lang)
Definition: MediaWikiTestCase.php:834
Html\label
static label( $label, $id, array $attribs=[])
Convenience function for generating a label for inputs.
Definition: Html.php:730
MediaWikiTestCase\setContentLang
setContentLang( $lang)
Definition: MediaWikiTestCase.php:843
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
MediaWikiTestCase\setUp
setUp()
Definition: MediaWikiTestCase.php:473
values
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible values
Definition: hooks.txt:177
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
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 just before the function returns a value If you return true
Definition: hooks.txt:1956
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:183
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231