12require_once __DIR__ .
"/../../../maintenance/dumpTextPass.php";
40 $this->tablesUsed[] =
'page';
41 $this->tablesUsed[] =
'revision';
42 $this->tablesUsed[] =
'ip_changes';
43 $this->tablesUsed[] =
'text';
46 "BackupTextPassTestModel" => BackupTextPassTestModelHandler::class,
53 $title = Title::newFromText(
'BackupDumperTestP1', $ns );
54 $page = WikiPage::factory( $title );
56 "BackupDumperTestP1Text1",
"BackupDumperTestP1Summary1" );
57 $this->pageId1 = $page->getId();
60 $title = Title::newFromText(
'BackupDumperTestP2', $ns );
61 $page = WikiPage::factory( $title );
63 "BackupDumperTestP2Text1",
"BackupDumperTestP2Summary1" );
65 "BackupDumperTestP2Text2",
"BackupDumperTestP2Summary2" );
67 "BackupDumperTestP2Text3",
"BackupDumperTestP2Summary3" );
69 "BackupDumperTestP2Text4 some additional Text ",
70 "BackupDumperTestP2Summary4 extra " );
71 $this->pageId2 = $page->getId();
74 $title = Title::newFromText(
'BackupDumperTestP3', $ns );
75 $page = WikiPage::factory( $title );
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." );
92 $title = Title::newFromText(
'BackupDumperTestP1',
NS_TALK );
93 $page = WikiPage::factory( $title );
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 );
130 $dumper->dump( WikiExporter::FULL, WikiExporter::TEXT );
137 $this->
assertRevision( $this->revId1_1,
"BackupDumperTestP1Summary1",
138 $this->textId1_1,
false,
"0bolhl6ol7i6x0e7yq91gxgaan39j87",
139 "BackupDumperTestP1Text1" );
144 $this->
assertRevision( $this->revId2_1,
"BackupDumperTestP2Summary1",
145 $this->textId2_1,
false,
"jprywrymfhysqllua29tj3sc7z39dl2",
146 "BackupDumperTestP2Text1" );
147 $this->
assertRevision( $this->revId2_2,
"BackupDumperTestP2Summary2",
148 $this->textId2_2,
false,
"b7vj5ks32po5m1z1t1br4o7scdwwy95",
149 "BackupDumperTestP2Text2", $this->revId2_1 );
150 $this->
assertRevision( $this->revId2_3,
"BackupDumperTestP2Summary3",
151 $this->textId2_3,
false,
"jfunqmh1ssfb8rs43r19w98k28gg56r",
152 "BackupDumperTestP2Text3", $this->revId2_2 );
153 $this->
assertRevision( $this->revId2_4,
"BackupDumperTestP2Summary4 extra",
154 $this->textId2_4,
false,
"6o1ciaxa6pybnqprmungwofc4lv00wv",
155 "BackupDumperTestP2Text4 some additional Text", $this->revId2_3 );
163 $this->
assertRevision( $this->revId4_1,
"Talk BackupDumperTestP1 Summary1",
164 $this->textId4_1,
false,
"nktofwzd0tl192k3zfepmlzxoax1lpe",
165 "TALK ABOUT BACKUPDUMPERTESTP1 TEXT1",
167 "BackupTextPassTestModel",
182 $prefetchMock = $this->getMockBuilder( BaseDump::class )
183 ->setMethods( [
'prefetch' ] )
184 ->disableOriginalConstructor()
186 $prefetchMock->expects( $this->exactly( 6 ) )
187 ->method(
'prefetch' )
188 ->will( $this->returnValueMap( $prefetchMap ) );
195 "--output=file:" . $nameFull ] );
197 $dumper->prefetch = $prefetchMock;
198 $dumper->reporting =
false;
199 $dumper->setDB( $this->db );
202 $dumper->dump( WikiExporter::FULL, WikiExporter::TEXT );
211 $this->
assertRevision( $this->revId1_1,
"BackupDumperTestP1Summary1",
212 $this->textId1_1,
false,
"0bolhl6ol7i6x0e7yq91gxgaan39j87",
213 "Prefetch_________1Text1" );
218 $this->
assertRevision( $this->revId2_1,
"BackupDumperTestP2Summary1",
219 $this->textId2_1,
false,
"jprywrymfhysqllua29tj3sc7z39dl2",
220 "BackupDumperTestP2Text1" );
221 $this->
assertRevision( $this->revId2_2,
"BackupDumperTestP2Summary2",
222 $this->textId2_2,
false,
"b7vj5ks32po5m1z1t1br4o7scdwwy95",
223 "BackupDumperTestP2Text2", $this->revId2_1 );
226 $this->
assertRevision( $this->revId2_3,
"BackupDumperTestP2Summary3",
227 $this->textId2_3,
false,
"jfunqmh1ssfb8rs43r19w98k28gg56r",
228 "Prefetch_________2Text3", $this->revId2_2 );
229 $this->
assertRevision( $this->revId2_4,
"BackupDumperTestP2Summary4 extra",
230 $this->textId2_4,
false,
"6o1ciaxa6pybnqprmungwofc4lv00wv",
231 "BackupDumperTestP2Text4 some additional Text", $this->revId2_3 );
239 $this->
assertRevision( $this->revId4_1,
"Talk BackupDumperTestP1 Summary1",
240 $this->textId4_1,
false,
"nktofwzd0tl192k3zfepmlzxoax1lpe",
241 "TALK ABOUT BACKUPDUMPERTESTP1 TEXT1",
243 "BackupTextPassTestModel",
262 $stderr = fopen(
'php://output',
'a' );
263 if ( $stderr ===
false ) {
264 $this->fail(
"Could not open stream for stderr" );
272 $checkpointAfter = 0.5;
277 while ( $lastDuration < $minDuration ) {
281 "Creating temporary output directory " );
282 $this->
setUpStub( $nameStub, $iterations );
284 $dumper->loadWithArgv( [
"--stub=file:" . $nameStub,
285 "--output=" . $checkpointFormat .
":" . $nameOutputDir .
"/full",
287 "--buffersize=32768",
288 "--checkpointfile=checkpoint-%s-%s.xml.gz" ] );
289 $dumper->setDB( $this->db );
290 $dumper->maxTimeAllowed = $checkpointAfter;
291 $dumper->stderr = $stderr;
294 $ts_before = microtime(
true );
296 $ts_after = microtime(
true );
297 $lastDuration = $ts_after - $ts_before;
300 if ( $lastDuration < $minDuration ) {
301 $old_iterations = $iterations;
302 if ( $lastDuration > 0.2 ) {
304 $factor = ( $minDuration + 0.5 ) / $lastDuration;
305 if ( ( $factor > 1.1 ) && ( $factor < 100 ) ) {
307 $iterations = (int)( $iterations * $factor );
311 if ( $old_iterations == $iterations ) {
316 $this->assertLessThan( 50000, $iterations,
317 "Emergency stop against infinitely increasing iteration "
318 .
"count ( last duration: $lastDuration )" );
326 $files = scandir( $nameOutputDir );
327 $this->assertTrue( asort( $files ),
"Sorting files in temporary directory" );
330 $checkpointFiles = 0;
334 for ( $i = 0; $i < $iterations; ) {
337 if ( !$fileOpened ) {
338 $this->assertNotEmpty( $files,
"No more existing dump files, "
339 .
"but not yet all pages found" );
340 $fname = array_shift( $files );
342 $this->assertNotEmpty( $files,
"No more existing dump"
343 .
" files, but not yet all pages found" );
344 $fname = array_shift( $files );
346 if ( $checkpointFormat ==
"gzip" ) {
355 switch ( $lookingForPage ) {
359 "BackupDumperTestP1" );
360 $this->
assertRevision( $this->revId1_1 + $i * self::$numOfRevs,
"BackupDumperTestP1Summary1",
361 $this->textId1_1,
false,
"0bolhl6ol7i6x0e7yq91gxgaan39j87",
362 "BackupDumperTestP1Text1" );
371 "BackupDumperTestP2" );
372 $this->
assertRevision( $this->revId2_1 + $i * self::$numOfRevs,
"BackupDumperTestP2Summary1",
373 $this->textId2_1,
false,
"jprywrymfhysqllua29tj3sc7z39dl2",
374 "BackupDumperTestP2Text1" );
375 $this->
assertRevision( $this->revId2_2 + $i * self::$numOfRevs,
"BackupDumperTestP2Summary2",
376 $this->textId2_2,
false,
"b7vj5ks32po5m1z1t1br4o7scdwwy95",
377 "BackupDumperTestP2Text2", $this->revId2_1 + $i * self::$numOfRevs );
378 $this->
assertRevision( $this->revId2_3 + $i * self::$numOfRevs,
"BackupDumperTestP2Summary3",
379 $this->textId2_3,
false,
"jfunqmh1ssfb8rs43r19w98k28gg56r",
380 "BackupDumperTestP2Text3", $this->revId2_2 + $i * self::$numOfRevs );
382 "BackupDumperTestP2Summary4 extra",
383 $this->textId2_4,
false,
"6o1ciaxa6pybnqprmungwofc4lv00wv",
384 "BackupDumperTestP2Text4 some additional Text",
385 $this->revId2_3 + $i * self::$numOfRevs );
394 "Talk:BackupDumperTestP1" );
396 "Talk BackupDumperTestP1 Summary1",
397 $this->textId4_1,
false,
"nktofwzd0tl192k3zfepmlzxoax1lpe",
398 "TALK ABOUT BACKUPDUMPERTESTP1 TEXT1",
400 "BackupTextPassTestModel",
411 $this->fail(
"Bad setting for lookingForPage ($lookingForPage)" );
415 if ( $this->xml->nodeType == XMLReader::END_ELEMENT
416 && $this->xml->name ==
"mediawiki"
424 $this->assertFalse( $fileOpened,
"Currently read file still open?" );
425 $this->assertEmpty( $files,
"Remaining unchecked files" );
428 $this->assertGreaterThan(
431 "expected more than 1 checkpoint to have been created. "
432 .
"Checkpoint interval is $checkpointAfter seconds, maybe your computer is too fast?"
485 $header =
'<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.10/" '
486 .
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
487 .
'xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.10/ '
488 .
'http://www.mediawiki.org/xml/export-0.10.xsd" version="0.10" xml:lang="en">
490 <sitename>wikisvn</sitename>
491 <base>http://localhost/wiki-svn/index.php/Main_Page</base>
492 <generator>MediaWiki 1.21alpha</generator>
493 <case>first-letter</case>
495 <namespace key="-2" case="first-letter">Media</namespace>
496 <namespace key="-1" case="first-letter">Special</namespace>
497 <namespace key="0" case="first-letter" />
498 <namespace key="1" case="first-letter">Talk</namespace>
499 <namespace key="2" case="first-letter">User</namespace>
500 <namespace key="3" case="first-letter">User talk</namespace>
501 <namespace key="4" case="first-letter">Wikisvn</namespace>
502 <namespace key="5" case="first-letter">Wikisvn talk</namespace>
503 <namespace key="6" case="first-letter">File</namespace>
504 <namespace key="7" case="first-letter">File talk</namespace>
505 <namespace key="8" case="first-letter">MediaWiki</namespace>
506 <namespace key="9" case="first-letter">MediaWiki talk</namespace>
507 <namespace key="10" case="first-letter">Template</namespace>
508 <namespace key="11" case="first-letter">Template talk</namespace>
509 <namespace key="12" case="first-letter">Help</namespace>
510 <namespace key="13" case="first-letter">Help talk</namespace>
511 <namespace key="14" case="first-letter">Category</namespace>
512 <namespace key="15" case="first-letter">Category talk</namespace>
516 $tail =
'</mediawiki>
520 $iterations = intval( $iterations );
521 for ( $i = 0; $i < $iterations; $i++ ) {
523 <title>BackupDumperTestP1</title>
527 <id>' . ( $this->revId1_1 + $i * self::$numOfRevs ) .
'</id>
528 <timestamp>2012-04-01T16:46:05Z</timestamp>
532 <comment>BackupDumperTestP1Summary1</comment>
533 <model>wikitext</model>
534 <format>text/x-wiki</format>
535 <text id="' . $this->textId1_1 .
'" bytes="23" />
536 <sha1>0bolhl6ol7i6x0e7yq91gxgaan39j87</sha1>
541 <title>BackupDumperTestP2</title>
545 <id>' . ( $this->revId2_1 + $i * self::$numOfRevs ) .
'</id>
546 <timestamp>2012-04-01T16:46:05Z</timestamp>
550 <comment>BackupDumperTestP2Summary1</comment>
551 <model>wikitext</model>
552 <format>text/x-wiki</format>
553 <text id="' . $this->textId2_1 .
'" bytes="23" />
554 <sha1>jprywrymfhysqllua29tj3sc7z39dl2</sha1>
558 <parentid>' . ( $this->revId2_1 + $i * self::$numOfRevs ) .
'</parentid>
559 <timestamp>2012-04-01T16:46:05Z</timestamp>
563 <comment>BackupDumperTestP2Summary2</comment>
564 <model>wikitext</model>
565 <format>text/x-wiki</format>
566 <text id="' . $this->textId2_2 .
'" bytes="23" />
567 <sha1>b7vj5ks32po5m1z1t1br4o7scdwwy95</sha1>
571 <parentid>' . ( $this->revId2_2 + $i * self::$numOfRevs ) .
'</parentid>
572 <timestamp>2012-04-01T16:46:05Z</timestamp>
576 <comment>BackupDumperTestP2Summary3</comment>
577 <model>wikitext</model>
578 <format>text/x-wiki</format>
579 <text id="' . $this->textId2_3 .
'" bytes="23" />
580 <sha1>jfunqmh1ssfb8rs43r19w98k28gg56r</sha1>
584 <parentid>' . ( $this->revId2_3 + $i * self::$numOfRevs ) .
'</parentid>
585 <timestamp>2012-04-01T16:46:05Z</timestamp>
589 <comment>BackupDumperTestP2Summary4 extra</comment>
590 <model>wikitext</model>
591 <format>text/x-wiki</format>
592 <text id="' . $this->textId2_4 .
'" bytes="44" />
593 <sha1>6o1ciaxa6pybnqprmungwofc4lv00wv</sha1>
600 <title>Talk:BackupDumperTestP1</title>
604 <id>' . ( $this->revId4_1 + $i * self::$numOfRevs ) .
'</id>
605 <timestamp>2012-04-01T16:46:05Z</timestamp>
609 <comment>Talk BackupDumperTestP1 Summary1</comment>
610 <model>BackupTextPassTestModel</model>
611 <format>text/plain</format>
612 <text id="' . $this->textId4_1 .
'" bytes="35" />
613 <sha1>nktofwzd0tl192k3zfepmlzxoax1lpe</sha1>
617 $content .= $page1 . $page2 . $page4;
620 $this->assertEquals( strlen( $content ), file_put_contents(
621 $fname, $content ),
"Length of prepared stub" );
630 parent::__construct(
'BackupTextPassTestModel' );
634 return strtoupper( $text );
656 $dumper->loadWithArgv( [
"--buffersize=" . $size ] );
658 $this->assertEquals( $expected, $dumper->getBufferSize(), $msg );
669 [ 512 * 1024, 512 * 1024,
"Setting 512KB is not effective" ],
670 [ 8192, 8192,
"Setting 8KB is not effective" ],
671 [ 4096, 2048,
"Could set buffer size below lower bound" ]
wfRecursiveRemoveDir( $dir)
Remove a directory and all its content.
wfMkdirParents( $dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
exportTransform( $text, $format=null)
Applies transformations on export (returns the blob unchanged per default).
gunzip( $fname)
gunzips the given file and stores the result in the original file name
assertDumpStart( $fname, $skip_siteinfo=true)
Opens an XML file to analyze and optionally skips past siteinfo.
assertPageEnd()
Asserts that the xml reader is at the page's closing element and skips to the next element.
addRevision(Page $page, $text, $summary, $model=CONTENT_MODEL_WIKITEXT)
Adds a revision to a page, while returning the resuting revision's id.
assertDumpEnd( $name="mediawiki")
Asserts that the xml reader is at the final closing tag of an xml file and closes the reader.
expectETAOutput()
Checks for test output consisting only of lines containing ETA announcements.
checkHasGzip()
Skip the test if 'gzip' is not in $PATH.
assertRevision( $id, $summary, $text_id, $text_bytes, $text_sha1, $text=false, $parentid=false, $model=CONTENT_MODEL_WIKITEXT, $format=CONTENT_FORMAT_WIKITEXT)
Asserts that the xml reader is at a revision and checks its representation before skipping over it.
assertPageStart( $id, $ns, $name)
Asserts that the xml reader is at the start of a page element and skips over the first tags,...
Accessor for internal state of TextPassDumper.
dump( $history, $text=null)
getBufferSize()
Gets the bufferSize.
Tests for TextPassDumper that rely on the database.
setUp()
Default set up function.
setUpStub( $fname=null, $iterations=1)
Creates a stub file that is used for testing the text pass of dumps.
checkpointHelper( $checkpointFormat="file")
Ensures that checkpoint dumps are used and written, by successively increasing the stub size and dump...
testCheckpointPlain()
Broken per T70653.
testCheckpointGzip()
tests for working checkpoint generation in gzip format work.
Tests for TextPassDumper that do not rely on the database.
bufferSizeProvider()
Ensures that setting the buffer size is effective.
testBufferSizeSetting( $expected, $size, $msg)
Ensures that setting the buffer size is effective.
Base content handler implementation for flat text contents.
Represents a title within MediaWiki.
Class representing a MediaWiki article and history.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
returning false will NOT prevent logging $e