3 require_once __DIR__ .
"/../../../maintenance/backupTextPass.inc";
26 $this->tablesUsed[] =
'page';
27 $this->tablesUsed[] =
'revision';
28 $this->tablesUsed[] =
'text';
37 "BackupDumperTestP1Text1",
"BackupDumperTestP1Summary1" );
38 $this->pageId1 = $page->getId();
44 "BackupDumperTestP2Text1",
"BackupDumperTestP2Summary1" );
46 "BackupDumperTestP2Text2",
"BackupDumperTestP2Summary2" );
48 "BackupDumperTestP2Text3",
"BackupDumperTestP2Summary3" );
50 "BackupDumperTestP2Text4 some additional Text ",
51 "BackupDumperTestP2Summary4 extra " );
52 $this->pageId2 = $page->getId();
58 "BackupDumperTestP3Text1",
"BackupDumperTestP2Summary1" );
60 "BackupDumperTestP3Text2",
"BackupDumperTestP2Summary2" );
61 $this->pageId3 = $page->getId();
62 $page->doDeleteArticle(
"Testing ;)" );
68 throw new MWException(
"The default wikitext namespace is the talk namespace. "
69 .
" We can't currently deal with that." );
75 "Talk about BackupDumperTestP1 Text1",
76 "Talk BackupDumperTestP1 Summary1" );
77 $this->pageId4 = $page->getId();
78 }
catch ( Exception
$e ) {
82 $this->exceptionFromAddDBData =
$e;
94 array( $this->pageId2, $this->pageId3, $this->pageId4 ),
95 array( $this->pageId1 + 1, $this->pageId2 + 1, $this->pageId3 + 1 ),
96 "Page ids increasing without holes" );
104 "--output=file:" . $nameFull ) );
116 $this->
assertRevision( $this->revId1_1,
"BackupDumperTestP1Summary1",
117 $this->textId1_1,
false,
"0bolhl6ol7i6x0e7yq91gxgaan39j87",
118 "BackupDumperTestP1Text1" );
123 $this->
assertRevision( $this->revId2_1,
"BackupDumperTestP2Summary1",
124 $this->textId2_1,
false,
"jprywrymfhysqllua29tj3sc7z39dl2",
125 "BackupDumperTestP2Text1" );
126 $this->
assertRevision( $this->revId2_2,
"BackupDumperTestP2Summary2",
127 $this->textId2_2,
false,
"b7vj5ks32po5m1z1t1br4o7scdwwy95",
128 "BackupDumperTestP2Text2", $this->revId2_1 );
129 $this->
assertRevision( $this->revId2_3,
"BackupDumperTestP2Summary3",
130 $this->textId2_3,
false,
"jfunqmh1ssfb8rs43r19w98k28gg56r",
131 "BackupDumperTestP2Text3", $this->revId2_2 );
132 $this->
assertRevision( $this->revId2_4,
"BackupDumperTestP2Summary4 extra",
133 $this->textId2_4,
false,
"6o1ciaxa6pybnqprmungwofc4lv00wv",
134 "BackupDumperTestP2Text4 some additional Text", $this->revId2_3 );
142 $this->
assertRevision( $this->revId4_1,
"Talk BackupDumperTestP1 Summary1",
143 $this->textId4_1,
false,
"nktofwzd0tl192k3zfepmlzxoax1lpe",
144 "Talk about BackupDumperTestP1 Text1" );
152 $prefetchMap =
array(
153 array( $this->pageId1, $this->revId1_1,
"Prefetch_________1Text1" ),
154 array( $this->pageId2, $this->revId2_3,
"Prefetch_________2Text3" )
158 $prefetchMock = $this->getMock(
'BaseDump',
array(
'prefetch' ),
array(),
'',
false );
159 $prefetchMock->expects( $this->exactly( 6 ) )
160 ->method(
'prefetch' )
161 ->will( $this->returnValueMap( $prefetchMap ) );
167 . $nameStub,
"--output=file:" . $nameFull ) );
168 $dumper->prefetch = $prefetchMock;
182 $this->
assertRevision( $this->revId1_1,
"BackupDumperTestP1Summary1",
183 $this->textId1_1,
false,
"0bolhl6ol7i6x0e7yq91gxgaan39j87",
184 "Prefetch_________1Text1" );
189 $this->
assertRevision( $this->revId2_1,
"BackupDumperTestP2Summary1",
190 $this->textId2_1,
false,
"jprywrymfhysqllua29tj3sc7z39dl2",
191 "BackupDumperTestP2Text1" );
192 $this->
assertRevision( $this->revId2_2,
"BackupDumperTestP2Summary2",
193 $this->textId2_2,
false,
"b7vj5ks32po5m1z1t1br4o7scdwwy95",
194 "BackupDumperTestP2Text2", $this->revId2_1 );
197 $this->
assertRevision( $this->revId2_3,
"BackupDumperTestP2Summary3",
198 $this->textId2_3,
false,
"jfunqmh1ssfb8rs43r19w98k28gg56r",
199 "Prefetch_________2Text3", $this->revId2_2 );
200 $this->
assertRevision( $this->revId2_4,
"BackupDumperTestP2Summary4 extra",
201 $this->textId2_4,
false,
"6o1ciaxa6pybnqprmungwofc4lv00wv",
202 "BackupDumperTestP2Text4 some additional Text", $this->revId2_3 );
210 $this->
assertRevision( $this->revId4_1,
"Talk BackupDumperTestP1 Summary1",
211 $this->textId4_1,
false,
"nktofwzd0tl192k3zfepmlzxoax1lpe",
212 "Talk about BackupDumperTestP1 Text1" );
230 $stderr = fopen(
'php://output',
'a' );
231 if ( $stderr ===
false ) {
232 $this->
fail(
"Could not open stream for stderr" );
238 $checkpointAfter = 0.5;
243 while ( $lastDuration < $minDuration ) {
248 "Creating temporary output directory " );
249 $this->
setUpStub( $nameStub, $iterations );
251 "--output=" . $checkpointFormat .
":" . $nameOutputDir .
"/full",
253 "--checkpointfile=checkpoint-%s-%s.xml.gz" ) );
255 $dumper->maxTimeAllowed = $checkpointAfter;
259 $ts_before = microtime(
true );
261 $ts_after = microtime(
true );
262 $lastDuration = $ts_after - $ts_before;
265 if ( $lastDuration < $minDuration ) {
266 $old_iterations = $iterations;
267 if ( $lastDuration > 0.2 ) {
269 $factor = ( $minDuration + 0.5 ) / $lastDuration;
270 if ( ( $factor > 1.1 ) && ( $factor < 100 ) ) {
272 $iterations = (int)( $iterations * $factor );
276 if ( $old_iterations == $iterations ) {
281 $this->assertLessThan( 50000, $iterations,
282 "Emergency stop against infinitely increasing iteration "
283 .
"count ( last duration: $lastDuration )" );
292 $files = scandir( $nameOutputDir );
293 $this->assertTrue( asort(
$files ),
"Sorting files in temporary directory" );
296 $checkpointFiles = 0;
300 for ( $i = 0; $i < $iterations; ) {
304 if ( !$fileOpened ) {
305 $this->assertNotEmpty(
$files,
"No more existing dump files, "
306 .
"but not yet all pages found" );
309 $this->assertNotEmpty(
$files,
"No more existing dump"
310 .
" files, but not yet all pages found" );
313 if ( $checkpointFormat ==
"gzip" ) {
322 switch ( $lookingForPage ) {
326 "BackupDumperTestP1" );
327 $this->
assertRevision( $this->revId1_1 + $i * self::$numOfRevs,
"BackupDumperTestP1Summary1",
328 $this->textId1_1,
false,
"0bolhl6ol7i6x0e7yq91gxgaan39j87",
329 "BackupDumperTestP1Text1" );
338 "BackupDumperTestP2" );
339 $this->
assertRevision( $this->revId2_1 + $i * self::$numOfRevs,
"BackupDumperTestP2Summary1",
340 $this->textId2_1,
false,
"jprywrymfhysqllua29tj3sc7z39dl2",
341 "BackupDumperTestP2Text1" );
342 $this->
assertRevision( $this->revId2_2 + $i * self::$numOfRevs,
"BackupDumperTestP2Summary2",
343 $this->textId2_2,
false,
"b7vj5ks32po5m1z1t1br4o7scdwwy95",
344 "BackupDumperTestP2Text2", $this->revId2_1 + $i * self::$numOfRevs );
345 $this->
assertRevision( $this->revId2_3 + $i * self::$numOfRevs,
"BackupDumperTestP2Summary3",
346 $this->textId2_3,
false,
"jfunqmh1ssfb8rs43r19w98k28gg56r",
347 "BackupDumperTestP2Text3", $this->revId2_2 + $i * self::$numOfRevs );
349 "BackupDumperTestP2Summary4 extra",
350 $this->textId2_4,
false,
"6o1ciaxa6pybnqprmungwofc4lv00wv",
351 "BackupDumperTestP2Text4 some additional Text",
352 $this->revId2_3 + $i * self::$numOfRevs );
361 "Talk:BackupDumperTestP1" );
363 "Talk BackupDumperTestP1 Summary1",
364 $this->textId4_1,
false,
"nktofwzd0tl192k3zfepmlzxoax1lpe",
365 "Talk about BackupDumperTestP1 Text1" );
375 $this->
fail(
"Bad setting for lookingForPage ($lookingForPage)" );
379 if ( $this->xml->nodeType == XMLReader::END_ELEMENT
380 && $this->xml->name ==
"mediawiki"
388 $this->assertFalse( $fileOpened,
"Currently read file still open?" );
389 $this->assertEmpty(
$files,
"Remaining unchecked files" );
392 $this->assertGreaterThan( 1, $checkpointFiles,
"expected more than 1 checkpoint to have been created. Checkpoint interval is $checkpointAfter seconds, maybe your computer is too fast?" );
440 $header =
'<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.7/" '
441 .
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
442 .
'xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.7/ '
443 .
'http://www.mediawiki.org/xml/export-0.7.xsd" version="0.7" xml:lang="en">
445 <sitename>wikisvn</sitename>
446 <base>http://localhost/wiki-svn/index.php/Main_Page</base>
447 <generator>MediaWiki 1.21alpha</generator>
448 <case>first-letter</case>
450 <namespace key="-2" case="first-letter">Media</namespace>
451 <namespace key="-1" case="first-letter">Special</namespace>
452 <namespace key="0" case="first-letter" />
453 <namespace key="1" case="first-letter">Talk</namespace>
454 <namespace key="2" case="first-letter">User</namespace>
455 <namespace key="3" case="first-letter">User talk</namespace>
456 <namespace key="4" case="first-letter">Wikisvn</namespace>
457 <namespace key="5" case="first-letter">Wikisvn talk</namespace>
458 <namespace key="6" case="first-letter">File</namespace>
459 <namespace key="7" case="first-letter">File talk</namespace>
460 <namespace key="8" case="first-letter">MediaWiki</namespace>
461 <namespace key="9" case="first-letter">MediaWiki talk</namespace>
462 <namespace key="10" case="first-letter">Template</namespace>
463 <namespace key="11" case="first-letter">Template talk</namespace>
464 <namespace key="12" case="first-letter">Help</namespace>
465 <namespace key="13" case="first-letter">Help talk</namespace>
466 <namespace key="14" case="first-letter">Category</namespace>
467 <namespace key="15" case="first-letter">Category talk</namespace>
471 $tail =
'</mediawiki>
475 $iterations = intval( $iterations );
476 for ( $i = 0; $i < $iterations; $i++ ) {
479 <title>BackupDumperTestP1</title>
483 <id>' . ( $this->revId1_1 + $i * self::$numOfRevs ) .
'</id>
484 <timestamp>2012-04-01T16:46:05Z</timestamp>
488 <comment>BackupDumperTestP1Summary1</comment>
489 <sha1>0bolhl6ol7i6x0e7yq91gxgaan39j87</sha1>
490 <model>wikitext</model>
491 <format>text/x-wiki</format>
492 <text id="' . $this->textId1_1 .
'" bytes="23" />
497 <title>BackupDumperTestP2</title>
501 <id>' . ( $this->revId2_1 + $i * self::$numOfRevs ) .
'</id>
502 <timestamp>2012-04-01T16:46:05Z</timestamp>
506 <comment>BackupDumperTestP2Summary1</comment>
507 <sha1>jprywrymfhysqllua29tj3sc7z39dl2</sha1>
508 <model>wikitext</model>
509 <format>text/x-wiki</format>
510 <text id="' . $this->textId2_1 .
'" bytes="23" />
514 <parentid>' . ( $this->revId2_1 + $i * self::$numOfRevs ) .
'</parentid>
515 <timestamp>2012-04-01T16:46:05Z</timestamp>
519 <comment>BackupDumperTestP2Summary2</comment>
520 <sha1>b7vj5ks32po5m1z1t1br4o7scdwwy95</sha1>
521 <model>wikitext</model>
522 <format>text/x-wiki</format>
523 <text id="' . $this->textId2_2 .
'" bytes="23" />
527 <parentid>' . ( $this->revId2_2 + $i * self::$numOfRevs ) .
'</parentid>
528 <timestamp>2012-04-01T16:46:05Z</timestamp>
532 <comment>BackupDumperTestP2Summary3</comment>
533 <sha1>jfunqmh1ssfb8rs43r19w98k28gg56r</sha1>
534 <model>wikitext</model>
535 <format>text/x-wiki</format>
536 <text id="' . $this->textId2_3 .
'" bytes="23" />
540 <parentid>' . ( $this->revId2_3 + $i * self::$numOfRevs ) .
'</parentid>
541 <timestamp>2012-04-01T16:46:05Z</timestamp>
545 <comment>BackupDumperTestP2Summary4 extra</comment>
546 <sha1>6o1ciaxa6pybnqprmungwofc4lv00wv</sha1>
547 <model>wikitext</model>
548 <format>text/x-wiki</format>
549 <text id="' . $this->textId2_4 .
'" bytes="44" />
556 <title>Talk:BackupDumperTestP1</title>
560 <id>' . ( $this->revId4_1 + $i * self::$numOfRevs ) .
'</id>
561 <timestamp>2012-04-01T16:46:05Z</timestamp>
565 <comment>Talk BackupDumperTestP1 Summary1</comment>
566 <sha1>nktofwzd0tl192k3zfepmlzxoax1lpe</sha1>
567 <model>wikitext</model>
568 <format>text/x-wiki</format>
569 <text id="' . $this->textId4_1 .
'" bytes="35" />
573 $content .= $page1 . $page2 . $page4;
576 $this->assertEquals( strlen( $content ), file_put_contents(
577 $fname, $content ),
"Length of prepared stub" );