MediaWiki  1.29.2
ApiFormatXmlTest.php
Go to the documentation of this file.
1 <?php
2 
8 class ApiFormatXmlTest extends ApiFormatTestBase {
9 
10  protected $printerName = 'xml';
11 
12  public static function setUpBeforeClass() {
13  parent::setUpBeforeClass();
14  $page = WikiPage::factory( Title::newFromText( 'MediaWiki:ApiFormatXmlTest.xsl' ) );
15  // @codingStandardsIgnoreStart Generic.Files.LineLength
16  $page->doEditContent( new WikitextContent(
17  '<?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" />'
18  ), 'Summary' );
19  // @codingStandardsIgnoreEnd
20  $page = WikiPage::factory( Title::newFromText( 'MediaWiki:ApiFormatXmlTest' ) );
21  $page->doEditContent( new WikitextContent( 'Bogus' ), 'Summary' );
22  $page = WikiPage::factory( Title::newFromText( 'ApiFormatXmlTest' ) );
23  $page->doEditContent( new WikitextContent( 'Bogus' ), 'Summary' );
24  }
25 
26  public static function provideGeneralEncoding() {
27  // @codingStandardsIgnoreStart Generic.Files.LineLength
28  return [
29  // Basic types
30  [ [ null, 'a' => null ], '<?xml version="1.0"?><api><_v _idx="0" /></api>' ],
31  [ [ true, 'a' => true ], '<?xml version="1.0"?><api a=""><_v _idx="0">true</_v></api>' ],
32  [ [ false, 'a' => false ], '<?xml version="1.0"?><api><_v _idx="0">false</_v></api>' ],
33  [ [ true, 'a' => true, ApiResult::META_BC_BOOLS => [ 0, 'a' ] ],
34  '<?xml version="1.0"?><api a=""><_v _idx="0">1</_v></api>' ],
35  [ [ false, 'a' => false, ApiResult::META_BC_BOOLS => [ 0, 'a' ] ],
36  '<?xml version="1.0"?><api><_v _idx="0"></_v></api>' ],
37  [ [ 42, 'a' => 42 ], '<?xml version="1.0"?><api a="42"><_v _idx="0">42</_v></api>' ],
38  [ [ 42.5, 'a' => 42.5 ], '<?xml version="1.0"?><api a="42.5"><_v _idx="0">42.5</_v></api>' ],
39  [ [ 1e42, 'a' => 1e42 ], '<?xml version="1.0"?><api a="1.0E+42"><_v _idx="0">1.0E+42</_v></api>' ],
40  [ [ 'foo', 'a' => 'foo' ], '<?xml version="1.0"?><api a="foo"><_v _idx="0">foo</_v></api>' ],
41  [ [ 'fóo', 'a' => 'fóo' ], '<?xml version="1.0"?><api a="fóo"><_v _idx="0">fóo</_v></api>' ],
42 
43  // Arrays and objects
44  [ [ [] ], '<?xml version="1.0"?><api><_v /></api>' ],
45  [ [ [ 'x' => 1 ] ], '<?xml version="1.0"?><api><_v x="1" /></api>' ],
46  [ [ [ 2 => 1 ] ], '<?xml version="1.0"?><api><_v><_v _idx="2">1</_v></_v></api>' ],
47  [ [ (object)[] ], '<?xml version="1.0"?><api><_v /></api>' ],
48  [ [ [ 1, ApiResult::META_TYPE => 'assoc' ] ], '<?xml version="1.0"?><api><_v><_v _idx="0">1</_v></_v></api>' ],
49  [ [ [ 'x' => 1, ApiResult::META_TYPE => 'array' ] ], '<?xml version="1.0"?><api><_v><_v>1</_v></_v></api>' ],
50  [ [ [ 'x' => 1, 'y' => [ 'z' => 1 ], ApiResult::META_TYPE => 'kvp' ] ],
51  '<?xml version="1.0"?><api><_v><_v _name="x" xml:space="preserve">1</_v><_v _name="y"><z xml:space="preserve">1</z></_v></_v></api>' ],
52  [ [ [ 'x' => 1, ApiResult::META_TYPE => 'kvp', ApiResult::META_INDEXED_TAG_NAME => 'i', ApiResult::META_KVP_KEY_NAME => 'key' ] ],
53  '<?xml version="1.0"?><api><_v><i key="x" xml:space="preserve">1</i></_v></api>' ],
54  [ [ [ 'x' => 1, ApiResult::META_TYPE => 'BCkvp', ApiResult::META_KVP_KEY_NAME => 'key' ] ],
55  '<?xml version="1.0"?><api><_v><_v key="x" xml:space="preserve">1</_v></_v></api>' ],
56  [ [ [ 'x' => 1, ApiResult::META_TYPE => 'BCarray' ] ], '<?xml version="1.0"?><api><_v x="1" /></api>' ],
57  [ [ [ 'a', 'b', ApiResult::META_TYPE => 'BCassoc' ] ], '<?xml version="1.0"?><api><_v><_v _idx="0">a</_v><_v _idx="1">b</_v></_v></api>' ],
58 
59  // Content
60  [ [ 'content' => 'foo', ApiResult::META_CONTENT => 'content' ],
61  '<?xml version="1.0"?><api xml:space="preserve">foo</api>' ],
62 
63  // Specified element name
64  [ [ 'foo', 'bar', ApiResult::META_INDEXED_TAG_NAME => 'itn' ],
65  '<?xml version="1.0"?><api><itn>foo</itn><itn>bar</itn></api>' ],
66 
67  // Subelements
68  [ [ 'a' => 1, 's' => 1, '_subelements' => [ 's' ] ],
69  '<?xml version="1.0"?><api a="1"><s xml:space="preserve">1</s></api>' ],
70 
71  // Content and subelement
72  [ [ 'a' => 1, 'content' => 'foo', ApiResult::META_CONTENT => 'content' ],
73  '<?xml version="1.0"?><api a="1" xml:space="preserve">foo</api>' ],
74  [ [ 's' => [], 'content' => 'foo', ApiResult::META_CONTENT => 'content' ],
75  '<?xml version="1.0"?><api><s /><content xml:space="preserve">foo</content></api>' ],
76  [
77  [
78  's' => 1,
79  'content' => 'foo',
80  ApiResult::META_CONTENT => 'content',
82  ],
83  '<?xml version="1.0"?><api><s xml:space="preserve">1</s><content xml:space="preserve">foo</content></api>'
84  ],
85 
86  // BC Subelements
87  [ [ 'foo' => 'foo', ApiResult::META_BC_SUBELEMENTS => [ 'foo' ] ],
88  '<?xml version="1.0"?><api><foo xml:space="preserve">foo</foo></api>' ],
89 
90  // Name mangling
91  [ [ 'foo.bar' => 1 ], '<?xml version="1.0"?><api foo.bar="1" />' ],
92  [ [ '' => 1 ], '<?xml version="1.0"?><api _="1" />' ],
93  [ [ 'foo bar' => 1 ], '<?xml version="1.0"?><api _foo.20.bar="1" />' ],
94  [ [ 'foo:bar' => 1 ], '<?xml version="1.0"?><api _foo.3A.bar="1" />' ],
95  [ [ 'foo%.bar' => 1 ], '<?xml version="1.0"?><api _foo.25..2E.bar="1" />' ],
96  [ [ '4foo' => 1, 'foo4' => 1 ], '<?xml version="1.0"?><api _4foo="1" foo4="1" />' ],
97  [ [ "foo\xe3\x80\x80bar" => 1 ], '<?xml version="1.0"?><api _foo.3000.bar="1" />' ],
98  [ [ 'foo:bar' => 1, ApiResult::META_PRESERVE_KEYS => [ 'foo:bar' ] ],
99  '<?xml version="1.0"?><api foo:bar="1" />' ],
100  [ [ 'a', 'b', ApiResult::META_INDEXED_TAG_NAME => 'foo bar' ],
101  '<?xml version="1.0"?><api><_foo.20.bar>a</_foo.20.bar><_foo.20.bar>b</_foo.20.bar></api>' ],
102 
103  // includenamespace param
104  [ [ 'x' => 'foo' ], '<?xml version="1.0"?><api x="foo" xmlns="http://www.mediawiki.org/xml/api/" />',
105  [ 'includexmlnamespace' => 1 ] ],
106 
107  // xslt param
108  [ [], '<?xml version="1.0"?><api><warnings><xml xml:space="preserve">Invalid or non-existent stylesheet specified.</xml></warnings></api>',
109  [ 'xslt' => 'DoesNotExist' ] ],
110  [ [], '<?xml version="1.0"?><api><warnings><xml xml:space="preserve">Stylesheet should be in the MediaWiki namespace.</xml></warnings></api>',
111  [ 'xslt' => 'ApiFormatXmlTest' ] ],
112  [ [], '<?xml version="1.0"?><api><warnings><xml xml:space="preserve">Stylesheet should have &quot;.xsl&quot; extension.</xml></warnings></api>',
113  [ 'xslt' => 'MediaWiki:ApiFormatXmlTest' ] ],
114  [ [],
115  '<?xml version="1.0"?><?xml-stylesheet href="' .
116  htmlspecialchars( Title::newFromText( 'MediaWiki:ApiFormatXmlTest.xsl' )->getLocalURL( 'action=raw' ) ) .
117  '" type="text/xsl" ?><api />',
118  [ 'xslt' => 'MediaWiki:ApiFormatXmlTest.xsl' ] ],
119  ];
120  // @codingStandardsIgnoreEnd
121  }
122 
123 }
object
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
Definition: globals.txt:25
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:265
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
MediaWikiTestCase\setUpBeforeClass
static setUpBeforeClass()
Definition: MediaWikiTestCase.php:131
ApiResult\META_TYPE
const META_TYPE
Key for the 'type' metadata item.
Definition: ApiResult.php:108
ApiResult\META_BC_SUBELEMENTS
const META_BC_SUBELEMENTS
Key for the 'BC subelements' metadata item.
Definition: ApiResult.php:141
ApiResult\META_PRESERVE_KEYS
const META_PRESERVE_KEYS
Key for the 'preserve keys' metadata item.
Definition: ApiResult.php:82
ApiResult\META_KVP_KEY_NAME
const META_KVP_KEY_NAME
Key for the metadata item whose value specifies the name used for the kvp key in the alternative outp...
Definition: ApiResult.php:117
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
ApiFormatTestBase
Definition: ApiFormatTestBase.php:3
ApiFormatTestBase\provideGeneralEncoding
static provideGeneralEncoding()
Return general data to be encoded for testing.
Definition: ApiFormatTestBase.php:16
ApiResult\META_INDEXED_TAG_NAME
const META_INDEXED_TAG_NAME
Key for the 'indexed tag name' metadata item.
Definition: ApiResult.php:70
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:120
$page
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 $page
Definition: hooks.txt:2536
ApiResult\META_SUBELEMENTS
const META_SUBELEMENTS
Key for the 'subelements' metadata item.
Definition: ApiResult.php:76
ApiResult\META_BC_BOOLS
const META_BC_BOOLS
Key for the 'BC bools' metadata item.
Definition: ApiResult.php:134
WikitextContent
Content object for wiki text pages.
Definition: WikitextContent.php:33
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
ApiResult\META_CONTENT
const META_CONTENT
Key for the 'content' metadata item.
Definition: ApiResult.php:88