61 'xmlns' =>
"http://www.mediawiki.org/xml/export-$ver/",
62 'xmlns:xsi' =>
"http://www.w3.org/2001/XMLSchema-instance",
73 'xsi:schemaLocation' =>
"http://www.mediawiki.org/xml/export-$ver/ " .
74 "http://www.mediawiki.org/xml/export-$ver.xsd",
76 'xml:lang' => MediaWikiServices::getInstance()->getContentLanguage()->getHtmlCode() ],
93 return " <siteinfo>\n " .
94 implode(
"\n ", $info ) .
119 return Xml::element(
'generator', [],
"MediaWiki $wgVersion" );
143 $spaces =
"<namespaces>\n";
145 MediaWikiServices::getInstance()->getContentLanguage()->getFormattedNamespaces()
155 $spaces .=
" </namespaces>";
166 return "</mediawiki>\n";
178 $this->currentTitle =
Title::makeTitle( $row->page_namespace, $row->page_title );
181 $out .=
' ' .
Xml::element(
'ns', [], strval( $row->page_namespace ) ) .
"\n";
183 if ( $row->page_is_redirect ) {
185 $redirect = $page->getRedirectTarget();
188 $out .=
Xml::element(
'redirect', [
'title' => self::canonicalTitle( $redirect ) ] );
193 if ( $row->page_restrictions !=
'' ) {
195 strval( $row->page_restrictions ) ) .
"\n";
198 Hooks::run(
'XmlDumpWriterOpenPage', [ $this, &
$out, $row, $this->currentTitle ] );
210 if ( $this->currentTitle !==
null ) {
211 $linkCache = MediaWikiServices::getInstance()->getLinkCache();
214 $linkCache->clearLink( $this->currentTitle );
223 return MediaWikiServices::getInstance()->getRevisionStore();
230 return MediaWikiServices::getInstance()->getBlobStore();
242 $out =
" <revision>\n";
244 if ( isset( $row->rev_parent_id ) && $row->rev_parent_id ) {
245 $out .=
" " .
Xml::element(
'parentid',
null, strval( $row->rev_parent_id ) ) .
"\n";
251 $out .=
" " .
Xml::element(
'contributor', [
'deleted' =>
'deleted' ] ) .
"\n";
256 if ( isset( $row->rev_minor_edit ) && $row->rev_minor_edit ) {
257 $out .=
" <minor/>\n";
263 if ( $comment !=
'' ) {
269 if ( isset( $row->rev_content_model ) && !is_null( $row->rev_content_model ) ) {
270 $content_model = strval( $row->rev_content_model );
279 if ( isset( $row->rev_content_format ) && !is_null( $row->rev_content_format ) ) {
280 $content_format = strval( $row->rev_content_format );
283 $content_format = $content_handler->getDefaultFormat();
286 $out .=
" " .
Xml::element(
'model',
null, strval( $content_model ) ) .
"\n";
287 $out .=
" " .
Xml::element(
'format',
null, strval( $content_format ) ) .
"\n";
292 } elseif ( isset( $row->old_text ) ) {
296 $text = $content_handler->exportTransform( $text, $content_format );
298 catch ( Exception $ex ) {
299 if ( $ex instanceof
MWException || $ex instanceof RuntimeException ) {
301 wfLogWarning(
'exportTransform failed on text for revid ' . $row->rev_id .
"\n" );
307 [
'xml:space' =>
'preserve',
'bytes' => intval( $row->rev_len ) ],
308 strval( $text ) ) .
"\n";
309 } elseif ( isset( $row->_load_content ) ) {
312 $slot =
$rev->getSlot(
'main' );
322 $text =
$content->serialize( $content_format );
324 $text = $content_handler->exportTransform( $text, $content_format );
326 [
'xml:space' =>
'preserve',
'bytes' => intval( $slot->getSize() ) ],
327 strval( $text ) ) .
"\n";
329 catch ( Exception $ex ) {
330 if ( $ex instanceof
MWException || $ex instanceof RuntimeException ) {
335 wfLogWarning(
'failed to load content for revid ' . $row->rev_id .
"\n" );
340 } elseif ( isset( $row->rev_text_id ) ) {
345 [
'id' => $row->rev_text_id,
'bytes' => intval( $row->rev_len ) ],
351 $slot =
$rev->getSlot(
'main' );
355 $textId = $this->
getBlobStore()->getTextIdFromAddress( $slot->getAddress() );
357 [
'id' => $textId,
'bytes' => intval( $slot->getSize() ) ],
361 if ( isset( $row->rev_sha1 )
365 $out .=
" " .
Xml::element(
'sha1',
null, strval( $row->rev_sha1 ) ) .
"\n";
367 $out .=
" <sha1/>\n";
372 Hooks::run(
'XmlDumpWriterWriteRevision', [ &$writer, &
$out, $row, $text ] );
374 $out .=
" </revision>\n";
388 $out =
" <logitem>\n";
394 $out .=
" " .
Xml::element(
'contributor', [
'deleted' =>
'deleted' ] ) .
"\n";
403 if ( $comment !=
'' ) {
408 $out .=
" " .
Xml::element(
'type',
null, strval( $row->log_type ) ) .
"\n";
409 $out .=
" " .
Xml::element(
'action',
null, strval( $row->log_action ) ) .
"\n";
417 [
'xml:space' =>
'preserve' ],
418 strval( $row->log_params ) ) .
"\n";
421 $out .=
" </logitem>\n";
433 return $indent .
Xml::element(
'timestamp',
null, $ts ) .
"\n";
443 $out = $indent .
"<contributor>\n";
450 $out .= $indent .
"</contributor>\n";
461 if ( $row->page_namespace ==
NS_FILE ) {
463 if ( $img && $img->exists() ) {
465 foreach ( array_reverse( $img->getHistory() )
as $ver ) {
481 if (
$file->isOld() ) {
487 if ( $dumpContents ) {
488 $be =
$file->getRepo()->getBackend();
489 # Dump file as base64
490 # Uses only XML-safe characters, so does not need escaping
491 # @todo Too bad this loads the contents into memory (script might swap)
492 $contents =
' <contents encoding="base64">' .
493 chunk_split( base64_encode(
494 $be->getFileContents( [
'src' =>
$file->getPath() ] ) ) ) .
500 $comment =
Xml::element(
'comment', [
'deleted' =>
'deleted' ] );
504 return " <upload>\n" .
507 " " . $comment .
"\n" .
529 if (
$title->isExternal() ) {
530 return $title->getPrefixedText();
533 $prefix = MediaWikiServices::getInstance()->getContentLanguage()->
534 getFormattedNsText(
$title->getNamespace() );
539 if ( $prefix !==
'' ) {
543 return $prefix .
$title->getText();