From a827739fb5e494ad657719d58ca5158247ed632f Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 7 Jun 2012 13:02:54 +0200 Subject: [PATCH] always record content model and format in export/dumps --- includes/Export.php | 46 ++++++++++++------- tests/phpunit/maintenance/DumpTestCase.php | 37 +++++++++------ .../maintenance/backupPrefetchTest.php | 8 ++++ .../maintenance/backupTextPassTest.php | 12 +++++ 4 files changed, 74 insertions(+), 29 deletions(-) diff --git a/includes/Export.php b/includes/Export.php index e453ce0f3d..4e02ffa4a1 100644 --- a/includes/Export.php +++ b/includes/Export.php @@ -644,22 +644,6 @@ class XmlDumpWriter { $out .= " " . Xml::elementClean( 'comment', array(), strval( $row->rev_comment ) ) . "\n"; } - if ( isset( $row->rev_content_model ) && !is_null( $row->rev_content_model ) ) { - $name = ContentHandler::getContentModelName( $row->rev_content_model ); - $out .= " " . Xml::element('model', array( 'name' => $name ), strval( $row->rev_content_model ) ) . "\n"; - } - - if ( isset( $row->rev_content_format ) && !is_null( $row->rev_content_format ) ) { - $mime = ContentHandler::getContentFormatMimeType( $row->rev_content_format ); - $out .= " " . Xml::element('format', array( 'mime' => $mime ), strval( $row->rev_content_format ) ) . "\n"; - } - - if ( $row->rev_sha1 && !( $row->rev_deleted & Revision::DELETED_TEXT ) ) { - $out .= " " . Xml::element('sha1', null, strval( $row->rev_sha1 ) ) . "\n"; - } else { - $out .= " \n"; - } - $text = ''; if ( $row->rev_deleted & Revision::DELETED_TEXT ) { $out .= " " . Xml::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n"; @@ -676,6 +660,36 @@ class XmlDumpWriter { "" ) . "\n"; } + if ( $row->rev_sha1 && !( $row->rev_deleted & Revision::DELETED_TEXT ) ) { + $out .= " " . Xml::element('sha1', null, strval( $row->rev_sha1 ) ) . "\n"; + } else { + $out .= " \n"; + } + + if ( isset( $row->rev_content_model ) && !is_null( $row->rev_content_model ) ) { + $content_model = intval( $row->rev_content_model ); + } else { + // probably using $wgContentHandlerUseDB = false; + // @todo: test! + $title = Title::makeTitle( $row->page_namespace, $row->page_title ); + $content_model = ContentHandler::getDefaultModelFor( $title ); + } + + $name = ContentHandler::getContentModelName( $content_model ); + $out .= " " . Xml::element('model', array( 'name' => $name ), strval( $content_model ) ) . "\n"; + + if ( isset( $row->rev_content_format ) && !is_null( $row->rev_content_format ) ) { + $content_format = intval( $row->rev_content_format ); + } else { + // probably using $wgContentHandlerUseDB = false; + // @todo: test! + $content_handler = ContentHandler::getForModelID( $content_model ); + $content_format = $content_handler->getDefaultFormat(); + } + + $mime = ContentHandler::getContentFormatMimeType( $content_format ); + $out .= " " . Xml::element('format', array( 'mime' => $mime ), strval( $content_format ) ) . "\n"; + wfRunHooks( 'XmlDumpWriterWriteRevision', array( &$this, &$out, $row, $text ) ); $out .= " \n"; diff --git a/tests/phpunit/maintenance/DumpTestCase.php b/tests/phpunit/maintenance/DumpTestCase.php index 71cd988ac5..89ae68841f 100644 --- a/tests/phpunit/maintenance/DumpTestCase.php +++ b/tests/phpunit/maintenance/DumpTestCase.php @@ -295,8 +295,11 @@ abstract class DumpTestCase extends MediaWikiLangTestCase { * @param $text_sha1 string: the base36 SHA-1 of the revision's text * @param $text string|false: (optional) The revision's string, or false to check for a * revision stub + * @param $model int: the expected content model id (default: CONTENT_MODEL_WIKITEXT) + * @param $format int: the expected format model id (default: CONTENT_FORMAT_WIKITEXT) */ - protected function assertRevision( $id, $summary, $text_id, $text_bytes, $text_sha1, $text = false ) { + protected function assertRevision( $id, $summary, $text_id, $text_bytes, $text_sha1, $text = false, + $model = CONTENT_MODEL_WIKITEXT, $format = CONTENT_FORMAT_WIKITEXT ) { $this->assertNodeStart( "revision" ); $this->skipWhitespace(); @@ -313,19 +316,31 @@ abstract class DumpTestCase extends MediaWikiLangTestCase { $this->assertTextNode( "comment", $summary ); $this->skipWhitespace(); - if ( $this->xml->name == "model" ) { // model tag is optional - $this->assertTextNode( "model", CONTENT_MODEL_WIKITEXT ); //@todo: make this a test parameter - $this->skipWhitespace(); + if ( $this->xml->name == "text" ) { + // note: tag may occur here or at the very end. + $text_found = true; + $this->assertText( $id, $text_id, $text_bytes, $text ); + } else { + $text_found = false; } + $this->assertTextNode( "sha1", $text_sha1 ); - if ( $this->xml->name == "format" ) { // format tag is optional - $this->assertTextNode( "format", CONTENT_FORMAT_WIKITEXT ); //@todo: make this a test parameter - $this->skipWhitespace(); + $this->assertTextNode( "model", $model ); + $this->skipWhitespace(); + + $this->assertTextNode( "format", $format ); + $this->skipWhitespace(); + + if ( !$text_found ) { + $this->assertText( $id, $text_id, $text_bytes, $text ); } - $this->assertTextNode( "sha1", $text_sha1 ); + $this->assertNodeEnd( "revision" ); + $this->skipWhitespace(); + } + protected function assertText( $id, $text_id, $text_bytes, $text ) { $this->assertNodeStart( "text", false ); if ( $text_bytes !== false ) { $this->assertEquals( $this->xml->getAttribute( "bytes" ), $text_bytes, @@ -352,9 +367,5 @@ abstract class DumpTestCase extends MediaWikiLangTestCase { $this->assertNodeEnd( "text" ); $this->skipWhitespace(); } - - $this->assertNodeEnd( "revision" ); - $this->skipWhitespace(); } - -} +} \ No newline at end of file diff --git a/tests/phpunit/maintenance/backupPrefetchTest.php b/tests/phpunit/maintenance/backupPrefetchTest.php index 9273233b1d..e66bbd745b 100644 --- a/tests/phpunit/maintenance/backupPrefetchTest.php +++ b/tests/phpunit/maintenance/backupPrefetchTest.php @@ -197,6 +197,8 @@ class BaseDumpTest extends MediaWikiTestCase { BackupDumperTestP1Summary1 BackupDumperTestP1Text1 0bolhl6ol7i6x0e7yq91gxgaan39j87 + 1 + 1 '; @@ -214,6 +216,8 @@ class BaseDumpTest extends MediaWikiTestCase { BackupDumperTestP2Summary1 BackupDumperTestP2Text1 jprywrymfhysqllua29tj3sc7z39dl2 + 1 + 1 5 @@ -224,6 +228,8 @@ class BaseDumpTest extends MediaWikiTestCase { BackupDumperTestP2Summary4 extra BackupDumperTestP2Text4 some additional Text 6o1ciaxa6pybnqprmungwofc4lv00wv + 1 + 1 '; @@ -241,6 +247,8 @@ class BaseDumpTest extends MediaWikiTestCase { Talk BackupDumperTestP1 Summary1 Talk about BackupDumperTestP1 Text1 nktofwzd0tl192k3zfepmlzxoax1lpe + 1 + 1 '; diff --git a/tests/phpunit/maintenance/backupTextPassTest.php b/tests/phpunit/maintenance/backupTextPassTest.php index 0d7f155f3f..6428295730 100644 --- a/tests/phpunit/maintenance/backupTextPassTest.php +++ b/tests/phpunit/maintenance/backupTextPassTest.php @@ -479,6 +479,8 @@ class TextPassDumperTest extends DumpTestCase { BackupDumperTestP1Summary1 0bolhl6ol7i6x0e7yq91gxgaan39j87 + 1 + 1 @@ -495,6 +497,8 @@ class TextPassDumperTest extends DumpTestCase { BackupDumperTestP2Summary1 jprywrymfhysqllua29tj3sc7z39dl2 + 1 + 1 @@ -505,6 +509,8 @@ class TextPassDumperTest extends DumpTestCase { BackupDumperTestP2Summary2 b7vj5ks32po5m1z1t1br4o7scdwwy95 + 1 + 1 @@ -515,6 +521,8 @@ class TextPassDumperTest extends DumpTestCase { BackupDumperTestP2Summary3 jfunqmh1ssfb8rs43r19w98k28gg56r + 1 + 1 @@ -525,6 +533,8 @@ class TextPassDumperTest extends DumpTestCase { BackupDumperTestP2Summary4 extra 6o1ciaxa6pybnqprmungwofc4lv00wv + 1 + 1 @@ -543,6 +553,8 @@ class TextPassDumperTest extends DumpTestCase { Talk BackupDumperTestP1 Summary1 nktofwzd0tl192k3zfepmlzxoax1lpe + 1 + 1 -- 2.20.1