40 $this->tablesUsed[] =
'page';
41 $this->tablesUsed[] =
'revision';
42 $this->tablesUsed[] =
'ip_changes';
43 $this->tablesUsed[] =
'text';
56 "BackupDumperTestP1Text1",
"BackupDumperTestP1Summary1" );
57 $this->pageId1 = $page->getId();
63 "BackupDumperTestP2Text1",
"BackupDumperTestP2Summary1" );
65 "BackupDumperTestP2Text2",
"BackupDumperTestP2Summary2" );
67 "BackupDumperTestP2Text3",
"BackupDumperTestP2Summary3" );
69 "BackupDumperTestP2Text4 some additional Text ",
70 "BackupDumperTestP2Summary4 extra " );
71 $this->pageId2 = $page->getId();
77 "BackupDumperTestP3Text1",
"BackupDumperTestP2Summary1" );
79 "BackupDumperTestP3Text2",
"BackupDumperTestP2Summary2" );
80 $this->pageId3 = $page->getId();
81 $page->doDeleteArticle(
"Testing ;)" );
88 throw new MWException(
"The default wikitext namespace is the talk namespace. "
89 .
" We can't currently deal with that." );
95 "Talk about BackupDumperTestP1 Text1",
96 "Talk BackupDumperTestP1 Summary1",
97 "BackupTextPassTestModel" );
98 $this->pageId4 = $page->getId();
99 }
catch ( Exception
$e ) {
103 $this->exceptionFromAddDBData =
$e;
115 [ $this->pageId2, $this->pageId3, $this->pageId4 ],
116 [ $this->pageId1 + 1, $this->pageId1 + 2, $this->pageId1 + 3 ],
117 "Page ids increasing without holes" );
125 "--output=file:" . $nameFull ] );
126 $dumper->reporting =
false;
127 $dumper->setDB( $this->db );
134 $asserter->assertDumpStart( $nameFull );
137 $asserter->assertPageStart( $this->pageId1,
NS_MAIN,
"BackupDumperTestP1" );
138 $asserter->assertRevision( $this->revId1_1,
"BackupDumperTestP1Summary1",
139 $this->textId1_1,
false,
"0bolhl6ol7i6x0e7yq91gxgaan39j87",
140 "BackupDumperTestP1Text1" );
141 $asserter->assertPageEnd();
144 $asserter->assertPageStart( $this->pageId2,
NS_MAIN,
"BackupDumperTestP2" );
145 $asserter->assertRevision( $this->revId2_1,
"BackupDumperTestP2Summary1",
146 $this->textId2_1,
false,
"jprywrymfhysqllua29tj3sc7z39dl2",
147 "BackupDumperTestP2Text1" );
148 $asserter->assertRevision( $this->revId2_2,
"BackupDumperTestP2Summary2",
149 $this->textId2_2,
false,
"b7vj5ks32po5m1z1t1br4o7scdwwy95",
150 "BackupDumperTestP2Text2", $this->revId2_1 );
151 $asserter->assertRevision( $this->revId2_3,
"BackupDumperTestP2Summary3",
152 $this->textId2_3,
false,
"jfunqmh1ssfb8rs43r19w98k28gg56r",
153 "BackupDumperTestP2Text3", $this->revId2_2 );
154 $asserter->assertRevision( $this->revId2_4,
"BackupDumperTestP2Summary4 extra",
155 $this->textId2_4,
false,
"6o1ciaxa6pybnqprmungwofc4lv00wv",
156 "BackupDumperTestP2Text4 some additional Text", $this->revId2_3 );
157 $asserter->assertPageEnd();
163 $asserter->assertPageStart( $this->pageId4,
NS_TALK,
"Talk:BackupDumperTestP1" );
164 $asserter->assertRevision( $this->revId4_1,
"Talk BackupDumperTestP1 Summary1",
165 $this->textId4_1,
false,
"nktofwzd0tl192k3zfepmlzxoax1lpe",
166 "TALK ABOUT BACKUPDUMPERTESTP1 TEXT1",
168 "BackupTextPassTestModel",
170 $asserter->assertPageEnd();
172 $asserter->assertDumpEnd();
184 ->setMethods( [
'prefetch' ] )
185 ->disableOriginalConstructor()
187 $prefetchMock->expects( $this->exactly( 6 ) )
188 ->method(
'prefetch' )
189 ->will( $this->returnValueMap( $prefetchMap ) );
196 "--output=file:" . $nameFull ] );
198 $dumper->prefetch = $prefetchMock;
199 $dumper->reporting =
false;
200 $dumper->setDB( $this->db );
207 $asserter->assertDumpStart( $nameFull );
210 $asserter->assertPageStart( $this->pageId1,
NS_MAIN,
"BackupDumperTestP1" );
213 $asserter->assertRevision( $this->revId1_1,
"BackupDumperTestP1Summary1",
214 $this->textId1_1,
false,
"0bolhl6ol7i6x0e7yq91gxgaan39j87",
215 "Prefetch_________1Text1" );
216 $asserter->assertPageEnd();
219 $asserter->assertPageStart( $this->pageId2,
NS_MAIN,
"BackupDumperTestP2" );
220 $asserter->assertRevision( $this->revId2_1,
"BackupDumperTestP2Summary1",
221 $this->textId2_1,
false,
"jprywrymfhysqllua29tj3sc7z39dl2",
222 "BackupDumperTestP2Text1" );
223 $asserter->assertRevision( $this->revId2_2,
"BackupDumperTestP2Summary2",
224 $this->textId2_2,
false,
"b7vj5ks32po5m1z1t1br4o7scdwwy95",
225 "BackupDumperTestP2Text2", $this->revId2_1 );
228 $asserter->assertRevision( $this->revId2_3,
"BackupDumperTestP2Summary3",
229 $this->textId2_3,
false,
"jfunqmh1ssfb8rs43r19w98k28gg56r",
230 "Prefetch_________2Text3", $this->revId2_2 );
231 $asserter->assertRevision( $this->revId2_4,
"BackupDumperTestP2Summary4 extra",
232 $this->textId2_4,
false,
"6o1ciaxa6pybnqprmungwofc4lv00wv",
233 "BackupDumperTestP2Text4 some additional Text", $this->revId2_3 );
234 $asserter->assertPageEnd();
240 $asserter->assertPageStart( $this->pageId4,
NS_TALK,
"Talk:BackupDumperTestP1" );
241 $asserter->assertRevision( $this->revId4_1,
"Talk BackupDumperTestP1 Summary1",
242 $this->textId4_1,
false,
"nktofwzd0tl192k3zfepmlzxoax1lpe",
243 "TALK ABOUT BACKUPDUMPERTESTP1 TEXT1",
245 "BackupTextPassTestModel",
247 $asserter->assertPageEnd();
249 $asserter->assertDumpEnd();
264 $stderr = fopen(
'php://output',
'a' );
265 if ( $stderr ===
false ) {
266 $this->fail(
"Could not open stream for stderr" );
274 $checkpointAfter = 0.5;
279 while ( $lastDuration < $minDuration ) {
283 "Creating temporary output directory " );
284 $this->
setUpStub( $nameStub, $iterations );
286 $dumper->loadWithArgv( [
"--stub=file:" . $nameStub,
287 "--output=" . $checkpointFormat .
":" . $nameOutputDir .
"/full",
289 "--buffersize=32768",
290 "--checkpointfile=checkpoint-%s-%s.xml.gz" ] );
291 $dumper->setDB( $this->db );
292 $dumper->maxTimeAllowed = $checkpointAfter;
293 $dumper->stderr = $stderr;
296 $ts_before = microtime(
true );
298 $ts_after = microtime(
true );
299 $lastDuration = $ts_after - $ts_before;
302 if ( $lastDuration < $minDuration ) {
303 $old_iterations = $iterations;
304 if ( $lastDuration > 0.2 ) {
306 $factor = ( $minDuration + 0.5 ) / $lastDuration;
307 if ( ( $factor > 1.1 ) && ( $factor < 100 ) ) {
309 $iterations = (int)( $iterations * $factor );
313 if ( $old_iterations == $iterations ) {
318 $this->assertLessThan( 50000, $iterations,
319 "Emergency stop against infinitely increasing iteration "
320 .
"count ( last duration: $lastDuration )" );
328 $files = scandir( $nameOutputDir );
329 $this->assertTrue( asort( $files ),
"Sorting files in temporary directory" );
332 $checkpointFiles = 0;
338 for ( $i = 0; $i < $iterations; ) {
341 if ( !$fileOpened ) {
342 $this->assertNotEmpty( $files,
"No more existing dump files, "
343 .
"but not yet all pages found" );
344 $fname = array_shift( $files );
346 $this->assertNotEmpty( $files,
"No more existing dump"
347 .
" files, but not yet all pages found" );
348 $fname = array_shift( $files );
350 if ( $checkpointFormat ==
"gzip" ) {
353 $asserter->assertDumpStart( $nameOutputDir .
"/" .
$fname );
359 switch ( $lookingForPage ) {
362 $asserter->assertPageStart(
363 $this->pageId1 + $i * self::$numOfPages,
367 $asserter->assertRevision(
368 $this->revId1_1 + $i * self::$numOfRevs,
369 "BackupDumperTestP1Summary1",
372 "0bolhl6ol7i6x0e7yq91gxgaan39j87",
373 "BackupDumperTestP1Text1"
375 $asserter->assertPageEnd();
382 $asserter->assertPageStart(
383 $this->pageId2 + $i * self::$numOfPages,
387 $asserter->assertRevision(
388 $this->revId2_1 + $i * self::$numOfRevs,
389 "BackupDumperTestP2Summary1",
392 "jprywrymfhysqllua29tj3sc7z39dl2",
393 "BackupDumperTestP2Text1"
395 $asserter->assertRevision(
396 $this->revId2_2 + $i * self::$numOfRevs,
397 "BackupDumperTestP2Summary2",
400 "b7vj5ks32po5m1z1t1br4o7scdwwy95",
401 "BackupDumperTestP2Text2",
402 $this->revId2_1 + $i * self::$numOfRevs
404 $asserter->assertRevision(
405 $this->revId2_3 + $i * self::$numOfRevs,
406 "BackupDumperTestP2Summary3",
409 "jfunqmh1ssfb8rs43r19w98k28gg56r",
410 "BackupDumperTestP2Text3",
411 $this->revId2_2 + $i * self::$numOfRevs
413 $asserter->assertRevision(
414 $this->revId2_4 + $i * self::$numOfRevs,
415 "BackupDumperTestP2Summary4 extra",
418 "6o1ciaxa6pybnqprmungwofc4lv00wv",
419 "BackupDumperTestP2Text4 some additional Text",
420 $this->revId2_3 + $i * self::$numOfRevs
422 $asserter->assertPageEnd();
429 $asserter->assertPageStart(
430 $this->pageId4 + $i * self::$numOfPages,
432 "Talk:BackupDumperTestP1"
434 $asserter->assertRevision(
435 $this->revId4_1 + $i * self::$numOfRevs,
436 "Talk BackupDumperTestP1 Summary1",
439 "nktofwzd0tl192k3zfepmlzxoax1lpe",
440 "TALK ABOUT BACKUPDUMPERTESTP1 TEXT1",
442 "BackupTextPassTestModel",
445 $asserter->assertPageEnd();
454 $this->fail(
"Bad setting for lookingForPage ($lookingForPage)" );
458 if ( $this->xml->nodeType == XMLReader::END_ELEMENT
459 && $this->xml->name ==
"mediawiki"
461 $asserter->assertDumpEnd();
467 $this->assertFalse( $fileOpened,
"Currently read file still open?" );
468 $this->assertEmpty( $files,
"Remaining unchecked files" );
471 $this->assertGreaterThan(
474 "expected more than 1 checkpoint to have been created. "
475 .
"Checkpoint interval is $checkpointAfter seconds, maybe your computer is too fast?"
528 $header =
'<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.10/" '
529 .
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
530 .
'xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.10/ '
531 .
'http://www.mediawiki.org/xml/export-0.10.xsd" version="0.10" xml:lang="en">
533 <sitename>wikisvn</sitename>
534 <base>http://localhost/wiki-svn/index.php/Main_Page</base>
535 <generator>MediaWiki 1.21alpha</generator>
536 <case>first-letter</case>
538 <namespace key="-2" case="first-letter">Media</namespace>
539 <namespace key="-1" case="first-letter">Special</namespace>
540 <namespace key="0" case="first-letter" />
541 <namespace key="1" case="first-letter">Talk</namespace>
542 <namespace key="2" case="first-letter">User</namespace>
543 <namespace key="3" case="first-letter">User talk</namespace>
544 <namespace key="4" case="first-letter">Wikisvn</namespace>
545 <namespace key="5" case="first-letter">Wikisvn talk</namespace>
546 <namespace key="6" case="first-letter">File</namespace>
547 <namespace key="7" case="first-letter">File talk</namespace>
548 <namespace key="8" case="first-letter">MediaWiki</namespace>
549 <namespace key="9" case="first-letter">MediaWiki talk</namespace>
550 <namespace key="10" case="first-letter">Template</namespace>
551 <namespace key="11" case="first-letter">Template talk</namespace>
552 <namespace key="12" case="first-letter">Help</namespace>
553 <namespace key="13" case="first-letter">Help talk</namespace>
554 <namespace key="14" case="first-letter">Category</namespace>
555 <namespace key="15" case="first-letter">Category talk</namespace>
559 $tail =
'</mediawiki>
563 $iterations = intval( $iterations );
565 $userid = $this->
getTestUser()->getUser()->getId();
566 for ( $i = 0; $i < $iterations; $i++ ) {
568 <title>BackupDumperTestP1</title>
572 <id>' . ( $this->revId1_1 + $i * self::$numOfRevs ) .
'</id>
573 <timestamp>2012-04-01T16:46:05Z</timestamp>
576 <id>' . $userid .
'</id>
578 <comment>BackupDumperTestP1Summary1</comment>
579 <model>wikitext</model>
580 <format>text/x-wiki</format>
581 <text id="' . $this->textId1_1 .
'" bytes="23" />
582 <sha1>0bolhl6ol7i6x0e7yq91gxgaan39j87</sha1>
587 <title>BackupDumperTestP2</title>
591 <id>' . ( $this->revId2_1 + $i * self::$numOfRevs ) .
'</id>
592 <timestamp>2012-04-01T16:46:05Z</timestamp>
595 <id>' . $userid .
'</id>
597 <comment>BackupDumperTestP2Summary1</comment>
598 <model>wikitext</model>
599 <format>text/x-wiki</format>
600 <text id="' . $this->textId2_1 .
'" bytes="23" />
601 <sha1>jprywrymfhysqllua29tj3sc7z39dl2</sha1>
605 <parentid>' . ( $this->revId2_1 + $i * self::$numOfRevs ) .
'</parentid>
606 <timestamp>2012-04-01T16:46:05Z</timestamp>
609 <id>' . $userid .
'</id>
611 <comment>BackupDumperTestP2Summary2</comment>
612 <model>wikitext</model>
613 <format>text/x-wiki</format>
614 <text id="' . $this->textId2_2 .
'" bytes="23" />
615 <sha1>b7vj5ks32po5m1z1t1br4o7scdwwy95</sha1>
619 <parentid>' . ( $this->revId2_2 + $i * self::$numOfRevs ) .
'</parentid>
620 <timestamp>2012-04-01T16:46:05Z</timestamp>
623 <id>' . $userid .
'</id>
625 <comment>BackupDumperTestP2Summary3</comment>
626 <model>wikitext</model>
627 <format>text/x-wiki</format>
628 <text id="' . $this->textId2_3 .
'" bytes="23" />
629 <sha1>jfunqmh1ssfb8rs43r19w98k28gg56r</sha1>
633 <parentid>' . ( $this->revId2_3 + $i * self::$numOfRevs ) .
'</parentid>
634 <timestamp>2012-04-01T16:46:05Z</timestamp>
637 <id>' . $userid .
'</id>
639 <comment>BackupDumperTestP2Summary4 extra</comment>
640 <model>wikitext</model>
641 <format>text/x-wiki</format>
642 <text id="' . $this->textId2_4 .
'" bytes="44" />
643 <sha1>6o1ciaxa6pybnqprmungwofc4lv00wv</sha1>
650 <title>Talk:BackupDumperTestP1</title>
654 <id>' . ( $this->revId4_1 + $i * self::$numOfRevs ) .
'</id>
655 <timestamp>2012-04-01T16:46:05Z</timestamp>
658 <id>' . $userid .
'</id>
660 <comment>Talk BackupDumperTestP1 Summary1</comment>
661 <model>BackupTextPassTestModel</model>
662 <format>text/plain</format>
663 <text id="' . $this->textId4_1 .
'" bytes="35" />
664 <sha1>nktofwzd0tl192k3zfepmlzxoax1lpe</sha1>
668 $content .= $page1 . $page2 . $page4;
671 $this->assertEquals( strlen(
$content ), file_put_contents(
681 parent::__construct(
'BackupTextPassTestModel' );
685 return strtoupper( $text );
707 $dumper->loadWithArgv( [
"--buffersize=" . $size ] );
709 $this->assertEquals( $expected, $dumper->getBufferSize(), $msg );
720 [ 512 * 1024, 512 * 1024,
"Setting 512KB is not effective" ],
721 [ 8192, 8192,
"Setting 8KB is not effective" ],
722 [ 4096, 2048,
"Could set buffer size below lower bound" ]