MediaWiki REL1_28
ImportTest.php
Go to the documentation of this file.
1<?php
2
11
12 private function getDataSource( $xml ) {
13 return new ImportStringSource( $xml );
14 }
15
23 public function testUnknownXMLTags( $xml, $text, $title ) {
24 $source = $this->getDataSource( $xml );
25
26 $importer = new WikiImporter(
27 $source,
28 ConfigFactory::getDefaultInstance()->makeConfig( 'main' )
29 );
30
31 $importer->doImport();
32 $title = Title::newFromText( $title );
33 $this->assertTrue( $title->exists() );
34
35 $this->assertEquals( WikiPage::factory( $title )->getContent()->getNativeData(), $text );
36 }
37
38 public function getUnknownTagsXML() {
39 // @codingStandardsIgnoreStart Generic.Files.LineLength
40 return [
41 [
42 <<< EOF
43<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.10/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.10/ http://www.mediawiki.org/xml/export-0.10.xsd" version="0.10" xml:lang="en">
44 <page unknown="123" dontknow="533">
45 <title>TestImportPage</title>
46 <unknowntag>Should be ignored</unknowntag>
47 <ns>0</ns>
48 <id unknown="123" dontknow="533">14</id>
49 <revision>
50 <id unknown="123" dontknow="533">15</id>
51 <unknowntag>Should be ignored</unknowntag>
52 <timestamp>2016-01-03T11:18:43Z</timestamp>
53 <contributor>
54 <unknowntag>Should be ignored</unknowntag>
55 <username unknown="123" dontknow="533">Admin</username>
56 <id>1</id>
57 </contributor>
58 <model>wikitext</model>
60 <text xml:space="preserve" bytes="0">noitazinagro tseb eht si ikiWaideM</text>
61 <sha1>phoiac9h4m842xq45sp7s6u21eteeq1</sha1>
62 <unknowntag>Should be ignored</unknowntag>
63 </revision>
64 </page>
65 <unknowntag>Should be ignored</unknowntag>
66</mediawiki>
67EOF
68 ,
69 'noitazinagro tseb eht si ikiWaideM',
70 'TestImportPage'
71 ]
72 ];
73 // @codingStandardsIgnoreEnd
74 }
75
82 public function testHandlePageContainsRedirect( $xml, $redirectTitle ) {
83 $source = $this->getDataSource( $xml );
84
85 $redirect = null;
86 $callback = function ( Title $title, ForeignTitle $foreignTitle, $revCount,
87 $sRevCount, $pageInfo ) use ( &$redirect ) {
88 if ( array_key_exists( 'redirect', $pageInfo ) ) {
89 $redirect = $pageInfo['redirect'];
90 }
91 };
92
93 $importer = new WikiImporter(
94 $source,
95 ConfigFactory::getDefaultInstance()->makeConfig( 'main' )
96 );
97 $importer->setPageOutCallback( $callback );
98 $importer->doImport();
99
100 $this->assertEquals( $redirectTitle, $redirect );
101 }
102
103 public function getRedirectXML() {
104 // @codingStandardsIgnoreStart Generic.Files.LineLength
105 return [
106 [
107 <<< EOF
108<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.10/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.10/ http://www.mediawiki.org/xml/export-0.10.xsd" version="0.10" xml:lang="en">
109 <page>
110 <title>Test</title>
111 <ns>0</ns>
112 <id>21</id>
113 <redirect title="Test22"/>
114 <revision>
115 <id>20</id>
116 <timestamp>2014-05-27T10:00:00Z</timestamp>
117 <contributor>
118 <username>Admin</username>
119 <id>10</id>
120 </contributor>
121 <comment>Admin moved page [[Test]] to [[Test22]]</comment>
122 <model>wikitext</model>
124 <text xml:space="preserve" bytes="20">#REDIRECT [[Test22]]</text>
125 <sha1>tq456o9x3abm7r9ozi6km8yrbbc56o6</sha1>
126 </revision>
127 </page>
128</mediawiki>
129EOF
130 ,
131 'Test22'
132 ],
133 [
134 <<< EOF
135<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.9/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.9/ http://www.mediawiki.org/xml/export-0.9.xsd" version="0.9" xml:lang="en">
136 <page>
137 <title>Test</title>
138 <ns>0</ns>
139 <id>42</id>
140 <revision>
141 <id>421</id>
142 <timestamp>2014-05-27T11:00:00Z</timestamp>
143 <contributor>
144 <username>Admin</username>
145 <id>10</id>
146 </contributor>
147 <text xml:space="preserve" bytes="4">Abcd</text>
148 <sha1>n7uomjq96szt60fy5w3x7ahf7q8m8rh</sha1>
149 <model>wikitext</model>
151 </revision>
152 </page>
153</mediawiki>
154EOF
155 ,
156 null
157 ],
158 ];
159 // @codingStandardsIgnoreEnd
160 }
161
169 $source = $this->getDataSource( $xml );
170
171 $importNamespaces = null;
172 $callback = function ( array $siteinfo, $innerImporter ) use ( &$importNamespaces ) {
173 $importNamespaces = $siteinfo['_namespaces'];
174 };
175
176 $importer = new WikiImporter(
177 $source,
178 ConfigFactory::getDefaultInstance()->makeConfig( 'main' )
179 );
180 $importer->setSiteInfoCallback( $callback );
181 $importer->doImport();
182
183 $this->assertEquals( $importNamespaces, $namespaces );
184 }
185
186 public function getSiteInfoXML() {
187 // @codingStandardsIgnoreStart Generic.Files.LineLength
188 return [
189 [
190 <<< EOF
191<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.10/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.10/ http://www.mediawiki.org/xml/export-0.10.xsd" version="0.10" xml:lang="en">
192 <siteinfo>
193 <namespaces>
194 <namespace key="-2" case="first-letter">Media</namespace>
195 <namespace key="-1" case="first-letter">Special</namespace>
196 <namespace key="0" case="first-letter" />
197 <namespace key="1" case="first-letter">Talk</namespace>
198 <namespace key="2" case="first-letter">User</namespace>
199 <namespace key="3" case="first-letter">User talk</namespace>
200 <namespace key="100" case="first-letter">Portal</namespace>
201 <namespace key="101" case="first-letter">Portal talk</namespace>
202 </namespaces>
203 </siteinfo>
204</mediawiki>
205EOF
206 ,
207 [
208 '-2' => 'Media',
209 '-1' => 'Special',
210 '0' => '',
211 '1' => 'Talk',
212 '2' => 'User',
213 '3' => 'User talk',
214 '100' => 'Portal',
215 '101' => 'Portal talk',
216 ]
217 ],
218 ];
219 // @codingStandardsIgnoreEnd
220 }
221
222}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second redirect
to move a page</td >< td > &*You are moving the page across namespaces
A simple, immutable structure to hold the title of a page on a foreign MediaWiki installation.
Used for importing XML dumps where the content of the dump is in a string.
Test class for Import methods.
testSiteInfoContainsNamespaces( $xml, $namespaces)
WikiImporter::handleSiteInfo getSiteInfoXML.
testUnknownXMLTags( $xml, $text, $title)
WikiImporter getUnknownTagsXML.
testHandlePageContainsRedirect( $xml, $redirectTitle)
WikiImporter::handlePage getRedirectXML.
getUnknownTagsXML()
getDataSource( $xml)
Base class that store and restore the Language objects.
Represents a title within MediaWiki.
Definition Title.php:36
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:48
XML file reader for the page data importer.
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition WikiPage.php:115
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition design.txt:18
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an and does all the work of translating among various forms such as plain database key
Definition design.txt:26
the array() calling protocol came about after MediaWiki 1.4rc1.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object to manipulate or replace but no entry for that model exists in $wgContentHandlers if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok inclusive false for true for descending in case the handler function wants to provide a converted Content object Note that $result getContentModel() must return $toModel. 'CustomEditor' $rcid is used in generating this variable which contains information about the new such as the revision s whether the revision was marked as a minor edit or etc which include things like revision author revision comment
Definition hooks.txt:1210
namespace and then decline to actually register it & $namespaces
Definition hooks.txt:956
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object to manipulate or replace but no entry for that model exists in $wgContentHandlers if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok inclusive false for true for descending in case the handler function wants to provide a converted Content object Note that $result getContentModel() must return $toModel. 'CustomEditor' $rcid is used in generating this variable which contains information about the new revision
Definition hooks.txt:1206
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:986
if the prop value should be in the metadata multi language array format
Definition hooks.txt:1620
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 page
Definition hooks.txt:2543
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:37
Prior to version
Prior to maintenance scripts were a hodgepodge of code that had no cohesion or formal method of action Beginning maintenance scripts have been cleaned up to use a unified class Directory structure How to run a script How to write your own DIRECTORY STRUCTURE The maintenance directory of a MediaWiki installation contains several all of which have unique purposes HOW TO RUN A SCRIPT Ridiculously just call php someScript php that s in the top level maintenance directory if not default wiki
$source
title