Go to the documentation of this file.
8 protected function setUp() {
12 $langObj->setNamespaces( [
24 9 =>
'MediaWiki_talk',
26 11 =>
'Template_talk',
33 'wgUseMediaWikiUIEverywhere' =>
false,
47 'Converting a null list of attributes'
50 'Converting an empty list of attributes'
69 'Opening element with no attributes'
80 'Terminated empty element'
89 '<input name="name" value="0" />',
91 'Input with a value of 0 (T25797)'
100 '<element>"hello <there> your\'s & you"</element>',
101 Xml::element(
'element',
null,
'"hello <there> your\'s & you"' ),
102 'Element with no attributes and content that needs escaping'
111 'replace " > and < with their HTML entitites'
120 '<element key="value" <>="<>">',
121 Xml::element(
'element', [
'key' =>
'value',
'<>' =>
'<>' ],
null ),
122 'Element attributes, keys are not escaped'
133 'openElement() shortcut'
141 $this->assertEquals(
'</element>',
Xml::closeElement(
'element' ),
'closeElement() shortcut' );
147 $header =
'<select name="month" id="month" class="mw-month-selector">';
148 $header2 =
'<select name="month" id="monthSelector" class="mw-month-selector">';
150 for ( $i = 1; $i < 13; $i++ ) {
151 $monthName =
$wgLang->getMonthName( $i );
152 $monthsString .=
"<option value=\"{$i}\">{$monthName}</option>";
154 $monthsString .=
"\n";
157 $monthsString2 = str_replace(
158 '<option value="12">December</option>',
159 '<option value="12" selected="">December</option>',
164 $allMonths =
"<option value=\"AllMonths\">all</option>\n";
166 [
$header . $monthsString . $end,
'',
null,
'month' ],
167 [
$header . $monthsString2 . $end, 12,
null,
'month' ],
168 [ $header2 . $monthsString . $end,
'',
null,
'monthSelector' ],
169 [
$header . $allMonths . $monthsString . $end,
'',
'AllMonths',
'month' ],
190 '<span class="foo" id="testSpan">element</span>',
191 Xml::span(
'element',
'foo', [
'id' =>
'testSpan' ] )
199 $curYear = intval( gmdate(
'Y' ) );
200 $prevYear = $curYear - 1;
202 $curMonth = intval( gmdate(
'n' ) );
204 $nextMonth = $curMonth + 1;
205 if ( $nextMonth == 13 ) {
210 '<label for="year">From year (and earlier):</label> ' .
211 '<input id="year" maxlength="4" size="7" type="number" value="2011" name="year"/> ' .
212 '<label for="month">From month (and earlier):</label> ' .
213 '<select name="month" id="month" class="mw-month-selector">' .
214 '<option value="-1">all</option>' .
"\n" .
215 '<option value="1">January</option>' .
"\n" .
216 '<option value="2" selected="">February</option>' .
"\n" .
217 '<option value="3">March</option>' .
"\n" .
218 '<option value="4">April</option>' .
"\n" .
219 '<option value="5">May</option>' .
"\n" .
220 '<option value="6">June</option>' .
"\n" .
221 '<option value="7">July</option>' .
"\n" .
222 '<option value="8">August</option>' .
"\n" .
223 '<option value="9">September</option>' .
"\n" .
224 '<option value="10">October</option>' .
"\n" .
225 '<option value="11">November</option>' .
"\n" .
226 '<option value="12">December</option></select>',
228 "Date menu for february 2011"
231 '<label for="year">From year (and earlier):</label> ' .
232 '<input id="year" maxlength="4" size="7" type="number" value="2011" name="year"/> ' .
233 '<label for="month">From month (and earlier):</label> ' .
234 '<select name="month" id="month" class="mw-month-selector">' .
235 '<option value="-1">all</option>' .
"\n" .
236 '<option value="1">January</option>' .
"\n" .
237 '<option value="2">February</option>' .
"\n" .
238 '<option value="3">March</option>' .
"\n" .
239 '<option value="4">April</option>' .
"\n" .
240 '<option value="5">May</option>' .
"\n" .
241 '<option value="6">June</option>' .
"\n" .
242 '<option value="7">July</option>' .
"\n" .
243 '<option value="8">August</option>' .
"\n" .
244 '<option value="9">September</option>' .
"\n" .
245 '<option value="10">October</option>' .
"\n" .
246 '<option value="11">November</option>' .
"\n" .
247 '<option value="12">December</option></select>',
249 "Date menu with negative month for 'All'"
254 "Date menu year is the current one when not specified"
257 $wantedYear = $nextMonth == 1 ? $curYear : $prevYear;
261 "Date menu next month is 11 months ago"
265 '<label for="year">From year (and earlier):</label> ' .
266 '<input id="year" maxlength="4" size="7" type="number" name="year"/> ' .
267 '<label for="month">From month (and earlier):</label> ' .
268 '<select name="month" id="month" class="mw-month-selector">' .
269 '<option value="-1">all</option>' .
"\n" .
270 '<option value="1">January</option>' .
"\n" .
271 '<option value="2">February</option>' .
"\n" .
272 '<option value="3">March</option>' .
"\n" .
273 '<option value="4">April</option>' .
"\n" .
274 '<option value="5">May</option>' .
"\n" .
275 '<option value="6">June</option>' .
"\n" .
276 '<option value="7">July</option>' .
"\n" .
277 '<option value="8">August</option>' .
"\n" .
278 '<option value="9">September</option>' .
"\n" .
279 '<option value="10">October</option>' .
"\n" .
280 '<option value="11">November</option>' .
"\n" .
281 '<option value="12">December</option></select>',
283 "Date menu with neither year or month"
292 '<textarea name="name" id="name" cols="40" rows="5"></textarea>',
294 'textarea() with not content'
303 '<textarea name="name" id="name" cols="20" rows="10"><txt></textarea>',
305 'textarea() with custom attribs'
314 '<label for="id">name</label>',
316 'label() with no attribs'
325 '<label for="id">name</label>',
326 Xml::label(
'name',
'id', [
'generated' =>
true ] ),
327 'label() can not be given a generated attribute'
330 '<label for="id" class="nice">name</label>',
331 Xml::label(
'name',
'id', [
'class' =>
'nice' ] ),
332 'label() can get a class attribute'
335 '<label for="id" title="nice tooltip">name</label>',
336 Xml::label(
'name',
'id', [
'title' =>
'nice tooltip' ] ),
337 'label() can get a title attribute'
340 '<label for="id" class="nice" title="nice tooltip">name</label>',
344 'title' =>
'nice tooltip',
345 'anotherattr' =>
'value',
348 'label() skip all attributes but "class" and "title"'
357 [
'id' =>
'testlang' ],
wfMessage(
'yourlanguage' ) );
359 '<label for="testlang">Language:</label>',
371 'encodeJsVar() with boolean'
382 'encodeJsVar() with null'
393 'encodeJsVar() with array'
398 'encodeJsVar() with associative array'
409 'encodeJsVar() with object'
420 'encodeJsVar() with int'
431 'encodeJsVar() with float'
442 'encodeJsVar() with int-like string'
453 'encodeJsVar() with float-like string'
462 '<select name="test-name" id="test-name" class="test-css" tabindex="2">' .
463 '<option value="other">other reasons</option>' .
"\n" .
464 '<optgroup label="Foo">' .
465 '<option value="Foo 1">Foo 1</option>' .
"\n" .
466 '<option value="Example" selected="">Example</option>' .
"\n" .
467 '</optgroup>' .
"\n" .
468 '<optgroup label="Bar">' .
469 '<option value="Bar 1">Bar 1</option>' .
"\n" .
476 "* Foo\n** Foo 1\n** Example\n* Bar\n** Bar 1",
495 'other reasons' =>
'other',
498 'Example' =>
'Example',
505 "* Foo\n** Foo 1\n** Example\n* Bar\n** Bar 1",
506 [
'other' =>
'other reasons' ]
517 [
'data' =>
'other',
'label' =>
'other reasons' ],
518 [
'optgroup' =>
'Foo' ],
519 [
'data' =>
'Foo 1',
'label' =>
'Foo 1' ],
520 [
'data' =>
'Example',
'label' =>
'Example' ],
521 [
'optgroup' =>
'Bar' ],
522 [
'data' =>
'Bar 1',
'label' =>
'Bar 1' ],
525 'other reasons' =>
'other',
528 'Example' =>
'Example',
549 'Opening tag (false means no legend)'
554 'Opening tag (empty string also means no legend)'
557 "<fieldset>\n<legend>Foo</legend>\n",
559 'Opening tag with legend'
562 "<fieldset>\n<legend>Foo</legend>\nBar\n</fieldset>\n",
564 'Entire element with legend'
567 "<fieldset>\n<legend>Foo</legend>\n",
569 'Opening tag with legend (false means no content and no closing tag)'
572 "<fieldset>\n<legend>Foo</legend>\n\n</fieldset>\n",
574 'Entire element with legend but no content (empty string generates a closing tag)'
577 "<fieldset class=\"bar\">\n<legend>Foo</legend>\nBar\n</fieldset>\n",
579 'Opening tag with legend and attributes'
582 "<fieldset class=\"bar\">\n<legend>Foo</legend>\n",
584 'Entire element with legend and attributes'
592 $firstRow = [
'foo',
'bar' ];
593 $secondRow = [
'Berlin',
'Tehran' ];
594 $headers = [
'header1',
'header2' ];
595 $expected =
'<table id="testTable"><thead id="testTable"><th>header1</th>' .
596 '<th>header2</th></thead><tr><td>foo</td><td>bar</td></tr><tr><td>Berlin</td>' .
597 '<td>Tehran</td></tr></table>';
601 [ $firstRow, $secondRow ],
602 [
'id' =>
'testTable' ],
613 '<tr id="testRow"><td>foo</td><td>bar</td></tr>',
testElementInputCanHaveAValueOfZero()
Xml::input.
testEncodeJsVarBoolean()
Xml::encodeJsVar.
static buildTableRow( $attribs, $cells)
Build a row for a table.
testLabelAttributeCanOnlyBeClassOrTitle()
Xml::label.
testBuildTable()
Xml::buildTable.
testMonthSelector( $expected, $selected, $allmonths, $id)
Xml::monthSelector provideMonthSelector.
static expandAttributes( $attribs)
Given an array of ('attributename' => 'value'), it generates the code to set the XML attributes : att...
testCloseElement()
Xml::closeElement.
testEncodeJsVarFloatString()
Xml::encodeJsVar.
testEncodeJsVarInt()
Xml::encodeJsVar.
static listDropDownOptionsOoui( $options)
Convert options for a drop-down box into a format accepted by OOUI\DropdownInputWidget etc.
static label( $label, $id, $attribs=[])
Convenience function to build an HTML form label.
testListDropDownOptionsOoui()
Xml::listDropDownOptionsOoui.
testTextareaNoContent()
Xml::textarea.
static textarea( $name, $content, $cols=40, $rows=5, $attribs=[])
Shortcut for creating textareas.
testLabelCreation()
Xml::label.
testTextareaAttribs()
Xml::textarea.
testListDropDown()
Xml::listDropDown.
static openElement( $element, $attribs=null)
This opens an XML element.
static encodeJsVar( $value, $pretty=false)
Encode a variable of arbitrary type to JavaScript.
static languageSelector( $selected, $customisedOnly=true, $inLanguage=null, $overrideAttrs=[], Message $msg=null)
Construct a language selector appropriate for use in a form or preferences.
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
testExpandAttributesException()
Xml::expandAttributes.
static fieldset( $legend=false, $content=false, $attribs=[])
Shortcut for creating fieldsets.
testExpandAttributes()
Xml::expandAttributes.
testElementEscaping()
Xml::element.
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
testListDropDownOptions()
Xml::listDropDownOptions.
testLanguageSelector()
Xml::languageSelector.
testOpenElement()
Xml::openElement.
testElementOpen()
Xml::element.
testEncodeJsVarFloat()
Xml::encodeJsVar.
static span( $text, $class, $attribs=[])
Shortcut to make a span element.
testElementAttributes()
Xml::element.
testEncodeJsVarIntString()
Xml::encodeJsVar.
static closeElement( $element)
Shortcut to close an XML element.
static listDropDown( $name='', $list='', $other='', $selected='', $class='', $tabindex=null)
Build a drop-down box from a textual list.
testBuildTableRow()
Xml::buildTableRow.
static dateMenu( $year, $month)
testDateMenu()
Xml::dateMenu.
testEscapeTagsOnly()
Xml::escapeTagsOnly.
testElementEmpty()
Xml::element.
static factory( $code)
Get a cached or new language object for a given language code.
static input( $name, $size=false, $value=false, $attribs=[])
Convenience function to build an HTML text input field.
static buildTable( $rows, $attribs=[], $headers=null)
Build a table of data.
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
testFieldset()
Xml::fieldset.
static monthSelector( $selected='', $allmonths=null, $id='month')
Create a date selector.
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead 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 unset offset - wrap String Wrap the message in html(usually something like "<
testEncodeJsVarNull()
Xml::encodeJsVar.
static escapeTagsOnly( $in)
Replace " > and < with their respective HTML entities ( ", >, <)
testEncodeJsVarArray()
Xml::encodeJsVar.
static listDropDownOptions( $list, $params=[])
Build options for a drop-down box from a textual list.
testEncodeJsVarObject()
Xml::encodeJsVar.