45 'xmlns' =>
"http://www.mediawiki.org/xml/export-$ver/",
46 'xmlns:xsi' =>
"http://www.w3.org/2001/XMLSchema-instance",
57 'xsi:schemaLocation' =>
"http://www.mediawiki.org/xml/export-$ver/ " .
58 "http://www.mediawiki.org/xml/export-$ver.xsd",
60 'xml:lang' => MediaWikiServices::getInstance()->getContentLanguage()->getHtmlCode() ],
77 return " <siteinfo>\n " .
78 implode(
"\n ", $info ) .
103 return Xml::element(
'generator', [],
"MediaWiki $wgVersion" );
127 $spaces =
"<namespaces>\n";
129 MediaWikiServices::getInstance()->getContentLanguage()->getFormattedNamespaces()
139 $spaces .=
" </namespaces>";
150 return "</mediawiki>\n";
164 $out .=
' ' .
Xml::element(
'ns', [], strval( $row->page_namespace ) ) .
"\n";
166 if ( $row->page_is_redirect ) {
168 $redirect = $page->getRedirectTarget();
171 $out .=
Xml::element(
'redirect', [
'title' => self::canonicalTitle( $redirect ) ] );
176 if ( $row->page_restrictions !=
'' ) {
178 strval( $row->page_restrictions ) ) .
"\n";
205 $out =
" <revision>\n";
207 if ( isset( $row->rev_parent_id ) && $row->rev_parent_id ) {
208 $out .=
" " .
Xml::element(
'parentid',
null, strval( $row->rev_parent_id ) ) .
"\n";
214 $out .=
" " .
Xml::element(
'contributor', [
'deleted' =>
'deleted' ] ) .
"\n";
219 if ( isset( $row->rev_minor_edit ) && $row->rev_minor_edit ) {
220 $out .=
" <minor/>\n";
226 if ( $comment !=
'' ) {
231 if ( isset( $row->rev_content_model ) && !is_null( $row->rev_content_model ) ) {
232 $content_model = strval( $row->rev_content_model );
241 if ( isset( $row->rev_content_format ) && !is_null( $row->rev_content_format ) ) {
242 $content_format = strval( $row->rev_content_format );
245 $content_format = $content_handler->getDefaultFormat();
248 $out .=
" " .
Xml::element(
'model',
null, strval( $content_model ) ) .
"\n";
249 $out .=
" " .
Xml::element(
'format',
null, strval( $content_format ) ) .
"\n";
254 } elseif ( isset( $row->old_text ) ) {
257 $text = $content_handler->exportTransform( $text, $content_format );
259 [
'xml:space' =>
'preserve',
'bytes' => intval( $row->rev_len ) ],
260 strval( $text ) ) .
"\n";
264 [
'id' => $row->rev_text_id,
'bytes' => intval( $row->rev_len ) ],
268 if ( isset( $row->rev_sha1 )
272 $out .=
" " .
Xml::element(
'sha1',
null, strval( $row->rev_sha1 ) ) .
"\n";
274 $out .=
" <sha1/>\n";
279 Hooks::run(
'XmlDumpWriterWriteRevision', [ &$writer, &
$out, $row, $text ] );
281 $out .=
" </revision>\n";
295 $out =
" <logitem>\n";
301 $out .=
" " .
Xml::element(
'contributor', [
'deleted' =>
'deleted' ] ) .
"\n";
310 if ( $comment !=
'' ) {
315 $out .=
" " .
Xml::element(
'type',
null, strval( $row->log_type ) ) .
"\n";
316 $out .=
" " .
Xml::element(
'action',
null, strval( $row->log_action ) ) .
"\n";
324 [
'xml:space' =>
'preserve' ],
325 strval( $row->log_params ) ) .
"\n";
328 $out .=
" </logitem>\n";
340 return $indent .
Xml::element(
'timestamp',
null, $ts ) .
"\n";
350 $out = $indent .
"<contributor>\n";
357 $out .= $indent .
"</contributor>\n";
368 if ( $row->page_namespace ==
NS_FILE ) {
370 if ( $img && $img->exists() ) {
372 foreach ( array_reverse( $img->getHistory() )
as $ver ) {
388 if ( $file->isOld() ) {
390 Xml::element(
'archivename',
null, $file->getArchiveName() ) .
"\n";
394 if ( $dumpContents ) {
395 $be = $file->getRepo()->getBackend();
396 # Dump file as base64
397 # Uses only XML-safe characters, so does not need escaping
398 # @todo Too bad this loads the contents into memory (script might swap)
399 $contents =
' <contents encoding="base64">' .
400 chunk_split( base64_encode(
401 $be->getFileContents( [
'src' => $file->getPath() ] ) ) ) .
407 $comment =
Xml::element(
'comment', [
'deleted' =>
'deleted' ] );
409 $comment =
Xml::elementClean(
'comment',
null, strval( $file->getDescription() ) );
411 return " <upload>\n" .
413 $this->
writeContributor( $file->getUser(
'id' ), $file->getUser(
'text' ) ) .
414 " " . $comment .
"\n" .
415 " " .
Xml::element(
'filename',
null, $file->getName() ) .
"\n" .
417 " " .
Xml::element(
'src',
null, $file->getCanonicalUrl() ) .
"\n" .
418 " " .
Xml::element(
'size',
null, $file->getSize() ) .
"\n" .
419 " " .
Xml::element(
'sha1base36',
null, $file->getSha1() ) .
"\n" .
420 " " .
Xml::element(
'rel',
null, $file->getRel() ) .
"\n" .
436 if (
$title->isExternal() ) {
437 return $title->getPrefixedText();
440 $prefix = MediaWikiServices::getInstance()->getContentLanguage()->
441 getFormattedNsText(
$title->getNamespace() );
446 if ( $prefix !==
'' ) {
450 return $prefix .
$title->getText();