1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
|
<?php
/**
* XmlDumpWriter
*
* Copyright © 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
* https://www.mediawiki.org/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
use MediaWiki\HookContainer\HookRunner;
use MediaWiki\MediaWikiServices;
use MediaWiki\Revision\RevisionRecord;
use MediaWiki\Revision\RevisionStore;
use MediaWiki\Revision\SlotRecord;
use MediaWiki\Revision\SuppressedDataException;
use MediaWiki\Storage\SqlBlobStore;
use Wikimedia\Assert\Assert;
use Wikimedia\IPUtils;
/**
* @ingroup Dump
*/
class XmlDumpWriter {
/** Output serialized revision content. */
public const WRITE_CONTENT = 0;
/** Only output subs for revision content. */
public const WRITE_STUB = 1;
/**
* Only output subs for revision content, indicating that the content has been
* deleted/suppressed.
*/
private const WRITE_STUB_DELETED = 2;
/**
* @var string[] the schema versions supported for output
* @final
*/
public static $supportedSchemas = [
XML_DUMP_SCHEMA_VERSION_10,
XML_DUMP_SCHEMA_VERSION_11
];
/**
* @var string which schema version the generated XML should comply to.
* One of the values from self::$supportedSchemas, using the SCHEMA_VERSION_XX
* constants.
*/
private $schemaVersion;
/**
* Title of the currently processed page
*
* @var Title|null
*/
private $currentTitle = null;
/**
* @var int Whether to output revision content or just stubs. WRITE_CONTENT or WRITE_STUB.
*/
private $contentMode;
/** @var HookRunner */
private $hookRunner;
/**
* @param int $contentMode WRITE_CONTENT or WRITE_STUB.
* @param string $schemaVersion which schema version the generated XML should comply to.
* One of the values from self::$supportedSchemas, using the XML_DUMP_SCHEMA_VERSION_XX
* constants.
*/
public function __construct(
$contentMode = self::WRITE_CONTENT,
$schemaVersion = XML_DUMP_SCHEMA_VERSION_11
) {
Assert::parameter(
in_array( $contentMode, [ self::WRITE_CONTENT, self::WRITE_STUB ] ),
'$contentMode',
'must be one of the following constants: WRITE_CONTENT or WRITE_STUB.'
);
Assert::parameter(
in_array( $schemaVersion, self::$supportedSchemas ),
'$schemaVersion',
'must be one of the following schema versions: '
. implode( ',', self::$supportedSchemas )
);
$this->contentMode = $contentMode;
$this->schemaVersion = $schemaVersion;
$this->hookRunner = new HookRunner( MediaWikiServices::getInstance()->getHookContainer() );
}
/**
* Opens the XML output stream's root "<mediawiki>" element.
* This does not include an xml directive, so is safe to include
* as a subelement in a larger XML stream. Namespace and XML Schema
* references are included.
*
* Output will be encoded in UTF-8.
*
* @return string
*/
public function openStream() {
$ver = $this->schemaVersion;
return Xml::element( 'mediawiki', [
'xmlns' => "http://www.mediawiki.org/xml/export-$ver/",
'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
/*
* When a new version of the schema is created, it needs staging on mediawiki.org.
* This requires a change in the operations/mediawiki-config git repo.
*
* Create a changeset like https://gerrit.wikimedia.org/r/#/c/149643/ in which
* you copy in the new xsd file.
*
* After it is reviewed, merged and deployed (sync-docroot), the index.html needs purging.
* echo "https://www.mediawiki.org/xml/index.html" | mwscript purgeList.php --wiki=aawiki
*/
'xsi:schemaLocation' => "http://www.mediawiki.org/xml/export-$ver/ " .
"http://www.mediawiki.org/xml/export-$ver.xsd",
'version' => $ver,
'xml:lang' => MediaWikiServices::getInstance()->getContentLanguage()->getHtmlCode() ],
null ) .
"\n" .
$this->siteInfo();
}
/**
* @return string
*/
private function siteInfo() {
$info = [
$this->sitename(),
$this->dbname(),
$this->homelink(),
$this->generator(),
$this->caseSetting(),
$this->namespaces() ];
return " <siteinfo>\n " .
implode( "\n ", $info ) .
"\n </siteinfo>\n";
}
/**
* @return string
*/
private function sitename() {
global $wgSitename;
return Xml::element( 'sitename', [], $wgSitename );
}
/**
* @return string
*/
private function dbname() {
global $wgDBname;
return Xml::element( 'dbname', [], $wgDBname );
}
/**
* @return string
*/
private function generator() {
return Xml::element( 'generator', [], 'MediaWiki ' . MW_VERSION );
}
/**
* @return string
*/
private function homelink() {
return Xml::element( 'base', [], Title::newMainPage()->getCanonicalURL() );
}
/**
* @return string
*/
private function caseSetting() {
global $wgCapitalLinks;
// "case-insensitive" option is reserved for future
$sensitivity = $wgCapitalLinks ? 'first-letter' : 'case-sensitive';
return Xml::element( 'case', [], $sensitivity );
}
/**
* @return string
*/
private function namespaces() {
$spaces = "<namespaces>\n";
$nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
foreach (
MediaWikiServices::getInstance()->getContentLanguage()->getFormattedNamespaces()
as $ns => $title
) {
$spaces .= ' ' .
Xml::element( 'namespace',
[
'key' => $ns,
'case' => $nsInfo->isCapitalized( $ns )
? 'first-letter' : 'case-sensitive',
], $title ) . "\n";
}
$spaces .= " </namespaces>";
return $spaces;
}
/**
* Closes the output stream with the closing root element.
* Call when finished dumping things.
*
* @return string
*/
public function closeStream() {
return "</mediawiki>\n";
}
/**
* Opens a "<page>" section on the output stream, with data
* from the given database row.
*
* @param object $row
* @return string
*/
public function openPage( $row ) {
$out = " <page>\n";
$this->currentTitle = Title::newFromRow( $row );
$canonicalTitle = self::canonicalTitle( $this->currentTitle );
$out .= ' ' . Xml::elementClean( 'title', [], $canonicalTitle ) . "\n";
$out .= ' ' . Xml::element( 'ns', [], strval( $row->page_namespace ) ) . "\n";
$out .= ' ' . Xml::element( 'id', [], strval( $row->page_id ) ) . "\n";
if ( $row->page_is_redirect ) {
$page = WikiPage::factory( $this->currentTitle );
$redirect = $this->invokeLenient(
$page,
'getRedirectTarget',
'Failed to get redirect target of page ' . $page->getId()
);
if ( $redirect instanceof Title && $redirect->isValidRedirectTarget() ) {
$out .= ' ';
$out .= Xml::element( 'redirect', [ 'title' => self::canonicalTitle( $redirect ) ] );
$out .= "\n";
}
}
if ( $row->page_restrictions != '' ) {
$out .= ' ' . Xml::element( 'restrictions', [],
strval( $row->page_restrictions ) ) . "\n";
}
$this->hookRunner->onXmlDumpWriterOpenPage( $this, $out, $row, $this->currentTitle );
return $out;
}
/**
* Closes a "<page>" section on the output stream.
*
* @private
* @return string
*/
public function closePage() {
if ( $this->currentTitle !== null ) {
$linkCache = MediaWikiServices::getInstance()->getLinkCache();
// In rare cases, link cache has the same key for some pages which
// might be read as part of the same batch. T220424 and T220316
$linkCache->clearLink( $this->currentTitle );
}
return " </page>\n";
}
/**
* @return RevisionStore
*/
private function getRevisionStore() {
return MediaWikiServices::getInstance()->getRevisionStore();
}
/**
* @return SqlBlobStore
*/
private function getBlobStore() {
return MediaWikiServices::getInstance()->getBlobStore();
}
/**
* Invokes the given method on the given object, catching and logging any storage related
* exceptions.
*
* @param object $obj
* @param string $method
* @param string $warning The warning to output in case of a storage related exception.
* @param array $args
*
* @return mixed Returns the method's return value,
* or null in case of a storage related exception.
* @throws Exception
*/
private function invokeLenient( $obj, $method, $warning, $args = [] ) {
try {
return call_user_func_array( [ $obj, $method ], $args );
} catch ( SuppressedDataException $ex ) {
return null;
} catch ( Exception $ex ) {
if ( $ex instanceof MWException || $ex instanceof RuntimeException ||
$ex instanceof InvalidArgumentException ) {
MWDebug::warning( $warning . ': ' . $ex->getMessage() );
return null;
} else {
throw $ex;
}
}
}
/**
* Dumps a "<revision>" section on the output stream, with
* data filled in from the given database row.
*
* @param object $row
* @param null|object[] $slotRows
*
* @return string
* @throws FatalError
* @throws MWException
*/
public function writeRevision( $row, $slotRows = null ) {
$rev = $this->getRevisionStore()->newRevisionFromRowAndSlots(
$row,
$slotRows,
0,
$this->currentTitle
);
$out = " <revision>\n";
$out .= " " . Xml::element( 'id', null, strval( $rev->getId() ) ) . "\n";
if ( $rev->getParentId() ) {
$out .= " " . Xml::element( 'parentid', null, strval( $rev->getParentId() ) ) . "\n";
}
$out .= $this->writeTimestamp( $rev->getTimestamp() );
if ( $rev->isDeleted( RevisionRecord::DELETED_USER ) ) {
$out .= " " . Xml::element( 'contributor', [ 'deleted' => 'deleted' ] ) . "\n";
} else {
// empty values get written out as uid 0, see T224221
$user = $rev->getUser();
$out .= $this->writeContributor(
$user ? $user->getId() : 0,
$user ? $user->getName() : ''
);
}
if ( $rev->isMinor() ) {
$out .= " <minor/>\n";
}
if ( $rev->isDeleted( RevisionRecord::DELETED_COMMENT ) ) {
$out .= " " . Xml::element( 'comment', [ 'deleted' => 'deleted' ] ) . "\n";
} else {
if ( $rev->getComment()->text != '' ) {
$out .= " "
. Xml::elementClean( 'comment', [], strval( $rev->getComment()->text ) )
. "\n";
}
}
$contentMode = $rev->isDeleted( RevisionRecord::DELETED_TEXT ) ? self::WRITE_STUB_DELETED
: $this->contentMode;
$slots = $rev->getSlots()->getSlots();
// use predictable order, put main slot first
ksort( $slots );
$out .= $this->writeSlot( $slots[SlotRecord::MAIN], $contentMode );
foreach ( $slots as $role => $slot ) {
if ( $role === SlotRecord::MAIN ) {
continue;
}
$out .= $this->writeSlot( $slot, $contentMode );
}
if ( $rev->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
$out .= " <sha1/>\n";
} else {
$sha1 = $this->invokeLenient(
$rev,
'getSha1',
'failed to determine sha1 for revision ' . $rev->getId()
);
$out .= " " . Xml::element( 'sha1', null, strval( $sha1 ) ) . "\n";
}
// Avoid PHP 7.1 warning from passing $this by reference
$writer = $this;
$text = '';
if ( $contentMode === self::WRITE_CONTENT ) {
/** @var Content $content */
$content = $this->invokeLenient(
$rev,
'getContent',
'Failed to load main slot content of revision ' . $rev->getId(),
[ SlotRecord::MAIN, RevisionRecord::RAW ]
);
$text = $content ? $content->serialize() : '';
}
$this->hookRunner->onXmlDumpWriterWriteRevision( $writer, $out, $row, $text, $rev );
$out .= " </revision>\n";
return $out;
}
/**
* @param SlotRecord $slot
* @param int $contentMode see the WRITE_XXX constants
*
* @return string
*/
private function writeSlot( SlotRecord $slot, $contentMode ) {
$isMain = $slot->getRole() === SlotRecord::MAIN;
$isV11 = $this->schemaVersion >= XML_DUMP_SCHEMA_VERSION_11;
if ( !$isV11 && !$isMain ) {
// ignore extra slots
return '';
}
$out = '';
$indent = ' ';
if ( !$isMain ) {
// non-main slots are wrapped into an additional element.
$out .= ' ' . Xml::openElement( 'content' ) . "\n";
$indent .= ' ';
$out .= $indent . Xml::element( 'role', null, strval( $slot->getRole() ) ) . "\n";
}
if ( $isV11 ) {
$out .= $indent . Xml::element( 'origin', null, strval( $slot->getOrigin() ) ) . "\n";
}
$contentModel = $slot->getModel();
$contentHandler = MediaWikiServices::getInstance()
->getContentHandlerFactory()
->getContentHandler( $contentModel );
$contentFormat = $contentHandler->getDefaultFormat();
// XXX: The content format is only relevant when actually outputting serialized content.
// It should probably be an attribute on the text tag.
$out .= $indent . Xml::element( 'model', null, strval( $contentModel ) ) . "\n";
$out .= $indent . Xml::element( 'format', null, strval( $contentFormat ) ) . "\n";
$textAttributes = [
'bytes' => $this->invokeLenient(
$slot,
'getSize',
'failed to determine size for slot ' . $slot->getRole() . ' of revision '
. $slot->getRevision()
) ?: '0'
];
if ( $isV11 ) {
$textAttributes['sha1'] = $this->invokeLenient(
$slot,
'getSha1',
'failed to determine sha1 for slot ' . $slot->getRole() . ' of revision '
. $slot->getRevision()
) ?: '';
}
if ( $contentMode === self::WRITE_CONTENT ) {
$content = $this->invokeLenient(
$slot,
'getContent',
'failed to load content for slot ' . $slot->getRole() . ' of revision '
. $slot->getRevision()
);
if ( $content === null ) {
$out .= $indent . Xml::element( 'text', $textAttributes ) . "\n";
} else {
$out .= $this->writeText( $content, $textAttributes, $indent );
}
} elseif ( $contentMode === self::WRITE_STUB_DELETED ) {
// write <text> placeholder tag
$textAttributes['deleted'] = 'deleted';
$out .= $indent . Xml::element( 'text', $textAttributes ) . "\n";
} else {
// write <text> stub tag
if ( $isV11 ) {
$textAttributes['location'] = $slot->getAddress();
}
if ( $isMain ) {
// Output the numerical text ID if possible, for backwards compatibility.
// Note that this is currently the ONLY reason we have a BlobStore here at all.
// When removing this line, check whether the BlobStore has become unused.
try {
// NOTE: this will only work for addresses of the form "tt:12345".
// If we want to support other kinds of addresses in the future,
// we will have to silently ignore failures here.
// For now, this fails for "tt:0", which is present in the WMF production
// database of of Juli 2019, due to data corruption.
$textId = $this->getBlobStore()->getTextIdFromAddress( $slot->getAddress() );
} catch ( InvalidArgumentException $ex ) {
MWDebug::warning( 'Bad content address for slot ' . $slot->getRole()
. ' of revision ' . $slot->getRevision() . ': ' . $ex->getMessage() );
$textId = 0;
}
if ( is_int( $textId ) ) {
$textAttributes['id'] = $textId;
}
}
$out .= $indent . Xml::element( 'text', $textAttributes ) . "\n";
}
if ( !$isMain ) {
$out .= ' ' . Xml::closeElement( 'content' ) . "\n";
}
return $out;
}
/**
* @param Content $content
* @param string[] $textAttributes
* @param string $indent
*
* @return string
*/
private function writeText( Content $content, $textAttributes, $indent ) {
$out = '';
$contentHandler = $content->getContentHandler();
$contentFormat = $contentHandler->getDefaultFormat();
if ( $content instanceof TextContent ) {
// HACK: For text based models, bypass the serialization step. This allows extensions (like Flow)
// that use incompatible combinations of serialization format and content model.
$data = $content->getNativeData();
} else {
$data = $content->serialize( $contentFormat );
}
$data = $contentHandler->exportTransform( $data, $contentFormat );
$textAttributes['bytes'] = $size = strlen( $data ); // make sure to use the actual size
$textAttributes['xml:space'] = 'preserve';
$out .= $indent . Xml::elementClean( 'text', $textAttributes, strval( $data ) ) . "\n";
return $out;
}
/**
* Dumps a "<logitem>" section on the output stream, with
* data filled in from the given database row.
*
* @param object $row
* @return string
*/
public function writeLogItem( $row ) {
$out = " <logitem>\n";
$out .= " " . Xml::element( 'id', null, strval( $row->log_id ) ) . "\n";
$out .= $this->writeTimestamp( $row->log_timestamp, " " );
if ( $row->log_deleted & LogPage::DELETED_USER ) {
$out .= " " . Xml::element( 'contributor', [ 'deleted' => 'deleted' ] ) . "\n";
} else {
$out .= $this->writeContributor( $row->log_user, $row->user_name, " " );
}
if ( $row->log_deleted & LogPage::DELETED_COMMENT ) {
$out .= " " . Xml::element( 'comment', [ 'deleted' => 'deleted' ] ) . "\n";
} else {
$comment = CommentStore::getStore()->getComment( 'log_comment', $row )->text;
if ( $comment != '' ) {
$out .= " " . Xml::elementClean( 'comment', null, strval( $comment ) ) . "\n";
}
}
$out .= " " . Xml::element( 'type', null, strval( $row->log_type ) ) . "\n";
$out .= " " . Xml::element( 'action', null, strval( $row->log_action ) ) . "\n";
if ( $row->log_deleted & LogPage::DELETED_ACTION ) {
$out .= " " . Xml::element( 'text', [ 'deleted' => 'deleted' ] ) . "\n";
} else {
$title = Title::makeTitle( $row->log_namespace, $row->log_title );
$out .= " " . Xml::elementClean( 'logtitle', null, self::canonicalTitle( $title ) ) . "\n";
$out .= " " . Xml::elementClean( 'params',
[ 'xml:space' => 'preserve' ],
strval( $row->log_params ) ) . "\n";
}
$out .= " </logitem>\n";
return $out;
}
/**
* @param string $timestamp
* @param string $indent Default to six spaces
* @return string
*/
public function writeTimestamp( $timestamp, $indent = " " ) {
$ts = wfTimestamp( TS_ISO_8601, $timestamp );
return $indent . Xml::element( 'timestamp', null, $ts ) . "\n";
}
/**
* @param int $id
* @param string $text
* @param string $indent Default to six spaces
* @return string
*/
public function writeContributor( $id, $text, $indent = " " ) {
$out = $indent . "<contributor>\n";
if ( $id || !IPUtils::isValid( $text ) ) {
$out .= $indent . " " . Xml::elementClean( 'username', null, strval( $text ) ) . "\n";
$out .= $indent . " " . Xml::element( 'id', null, strval( $id ) ) . "\n";
} else {
$out .= $indent . " " . Xml::elementClean( 'ip', null, strval( $text ) ) . "\n";
}
$out .= $indent . "</contributor>\n";
return $out;
}
/**
* Warning! This data is potentially inconsistent. :(
* @param object $row
* @param bool $dumpContents
* @return string
*/
public function writeUploads( $row, $dumpContents = false ) {
if ( $row->page_namespace == NS_FILE ) {
$img = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
->newFile( $row->page_title );
if ( $img && $img->exists() ) {
$out = '';
foreach ( array_reverse( $img->getHistory() ) as $ver ) {
$out .= $this->writeUpload( $ver, $dumpContents );
}
$out .= $this->writeUpload( $img, $dumpContents );
return $out;
}
}
return '';
}
/**
* @param File $file
* @param bool $dumpContents
* @return string
*/
private function writeUpload( $file, $dumpContents = false ) {
if ( $file->isOld() ) {
/** @var OldLocalFile $file */
'@phan-var OldLocalFile $file';
$archiveName = " " .
Xml::element( 'archivename', null, $file->getArchiveName() ) . "\n";
} else {
$archiveName = '';
}
if ( $dumpContents ) {
$be = $file->getRepo()->getBackend();
# Dump file as base64
# Uses only XML-safe characters, so does not need escaping
# @todo Too bad this loads the contents into memory (script might swap)
$contents = ' <contents encoding="base64">' .
chunk_split( base64_encode(
$be->getFileContents( [ 'src' => $file->getPath() ] ) ) ) .
" </contents>\n";
} else {
$contents = '';
}
if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
$comment = Xml::element( 'comment', [ 'deleted' => 'deleted' ] );
} else {
$comment = Xml::elementClean( 'comment', null, strval( $file->getDescription() ) );
}
return " <upload>\n" .
$this->writeTimestamp( $file->getTimestamp() ) .
$this->writeContributor( $file->getUser( 'id' ), $file->getUser( 'text' ) ) .
" " . $comment . "\n" .
" " . Xml::element( 'filename', null, $file->getName() ) . "\n" .
$archiveName .
" " . Xml::element( 'src', null, $file->getCanonicalUrl() ) . "\n" .
" " . Xml::element( 'size', null, $file->getSize() ) . "\n" .
" " . Xml::element( 'sha1base36', null, $file->getSha1() ) . "\n" .
" " . Xml::element( 'rel', null, $file->getRel() ) . "\n" .
$contents .
" </upload>\n";
}
/**
* Return prefixed text form of title, but using the content language's
* canonical namespace. This skips any special-casing such as gendered
* user namespaces -- which while useful, are not yet listed in the
* XML "<siteinfo>" data so are unsafe in export.
*
* @param Title $title
* @return string
* @since 1.18
*/
public static function canonicalTitle( Title $title ) {
if ( $title->isExternal() ) {
return $title->getPrefixedText();
}
$prefix = MediaWikiServices::getInstance()->getContentLanguage()->
getFormattedNsText( $title->getNamespace() );
// @todo Emit some kind of warning to the user if $title->getNamespace() !==
// NS_MAIN and $prefix === '' (viz. pages in an unregistered namespace)
if ( $prefix !== '' ) {
$prefix .= ':';
}
return $prefix . $title->getText();
}
}
|