Merge "Remove $wgTitle from LanguageConverter subclasses"
[lhc/web/wiklou.git] / includes / Export.php
1 <?php
2 /**
3 * Base classes for dumps and export
4 *
5 * Copyright © 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
6 * https://www.mediawiki.org/
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
22 *
23 * @file
24 */
25
26 /**
27 * @defgroup Dump Dump
28 */
29
30 /**
31 * @ingroup SpecialPage Dump
32 */
33 class WikiExporter {
34 /** @var bool Return distinct author list (when not returning full history) */
35 public $list_authors = false;
36
37 /** @var bool */
38 public $dumpUploads = false;
39
40 /** @var bool */
41 public $dumpUploadFileContents = false;
42
43 /** @var string */
44 protected $author_list = "";
45
46 const FULL = 1;
47 const CURRENT = 2;
48 const STABLE = 4; // extension defined
49 const LOGS = 8;
50 const RANGE = 16;
51
52 const BUFFER = 0;
53 const STREAM = 1;
54
55 const TEXT = 0;
56 const STUB = 1;
57
58 /** @var int */
59 protected $buffer;
60
61 /** @var int */
62 protected $text;
63
64 /** @var DumpOutput */
65 protected $sink;
66
67 /**
68 * Returns the export schema version.
69 * @return string
70 */
71 public static function schemaVersion() {
72 return "0.8";
73 }
74
75 /**
76 * If using WikiExporter::STREAM to stream a large amount of data,
77 * provide a database connection which is not managed by
78 * LoadBalancer to read from: some history blob types will
79 * make additional queries to pull source data while the
80 * main query is still running.
81 *
82 * @param DatabaseBase $db
83 * @param int|array $history One of WikiExporter::FULL, WikiExporter::CURRENT,
84 * WikiExporter::RANGE or WikiExporter::STABLE, or an associative array:
85 * - offset: non-inclusive offset at which to start the query
86 * - limit: maximum number of rows to return
87 * - dir: "asc" or "desc" timestamp order
88 * @param int $buffer One of WikiExporter::BUFFER or WikiExporter::STREAM
89 * @param int $text One of WikiExporter::TEXT or WikiExporter::STUB
90 */
91 function __construct( $db, $history = WikiExporter::CURRENT,
92 $buffer = WikiExporter::BUFFER, $text = WikiExporter::TEXT ) {
93 $this->db = $db;
94 $this->history = $history;
95 $this->buffer = $buffer;
96 $this->writer = new XmlDumpWriter();
97 $this->sink = new DumpOutput();
98 $this->text = $text;
99 }
100
101 /**
102 * Set the DumpOutput or DumpFilter object which will receive
103 * various row objects and XML output for filtering. Filters
104 * can be chained or used as callbacks.
105 *
106 * @param DumpOutput $sink
107 */
108 public function setOutputSink( &$sink ) {
109 $this->sink =& $sink;
110 }
111
112 public function openStream() {
113 $output = $this->writer->openStream();
114 $this->sink->writeOpenStream( $output );
115 }
116
117 public function closeStream() {
118 $output = $this->writer->closeStream();
119 $this->sink->writeCloseStream( $output );
120 }
121
122 /**
123 * Dumps a series of page and revision records for all pages
124 * in the database, either including complete history or only
125 * the most recent version.
126 */
127 public function allPages() {
128 $this->dumpFrom( '' );
129 }
130
131 /**
132 * Dumps a series of page and revision records for those pages
133 * in the database falling within the page_id range given.
134 * @param int $start Inclusive lower limit (this id is included)
135 * @param int $end Exclusive upper limit (this id is not included)
136 * If 0, no upper limit.
137 */
138 public function pagesByRange( $start, $end ) {
139 $condition = 'page_id >= ' . intval( $start );
140 if ( $end ) {
141 $condition .= ' AND page_id < ' . intval( $end );
142 }
143 $this->dumpFrom( $condition );
144 }
145
146 /**
147 * Dumps a series of page and revision records for those pages
148 * in the database with revisions falling within the rev_id range given.
149 * @param int $start Inclusive lower limit (this id is included)
150 * @param int $end Exclusive upper limit (this id is not included)
151 * If 0, no upper limit.
152 */
153 public function revsByRange( $start, $end ) {
154 $condition = 'rev_id >= ' . intval( $start );
155 if ( $end ) {
156 $condition .= ' AND rev_id < ' . intval( $end );
157 }
158 $this->dumpFrom( $condition );
159 }
160
161 /**
162 * @param Title $title
163 */
164 public function pageByTitle( $title ) {
165 $this->dumpFrom(
166 'page_namespace=' . $title->getNamespace() .
167 ' AND page_title=' . $this->db->addQuotes( $title->getDBkey() ) );
168 }
169
170 /**
171 * @param string $name
172 * @throws MWException
173 */
174 public function pageByName( $name ) {
175 $title = Title::newFromText( $name );
176 if ( is_null( $title ) ) {
177 throw new MWException( "Can't export invalid title" );
178 } else {
179 $this->pageByTitle( $title );
180 }
181 }
182
183 /**
184 * @param array $names
185 */
186 public function pagesByName( $names ) {
187 foreach ( $names as $name ) {
188 $this->pageByName( $name );
189 }
190 }
191
192 public function allLogs() {
193 $this->dumpFrom( '' );
194 }
195
196 /**
197 * @param int $start
198 * @param int $end
199 */
200 public function logsByRange( $start, $end ) {
201 $condition = 'log_id >= ' . intval( $start );
202 if ( $end ) {
203 $condition .= ' AND log_id < ' . intval( $end );
204 }
205 $this->dumpFrom( $condition );
206 }
207
208 /**
209 * Generates the distinct list of authors of an article
210 * Not called by default (depends on $this->list_authors)
211 * Can be set by Special:Export when not exporting whole history
212 *
213 * @param array $cond
214 */
215 protected function do_list_authors( $cond ) {
216 wfProfileIn( __METHOD__ );
217 $this->author_list = "<contributors>";
218 // rev_deleted
219
220 $res = $this->db->select(
221 array( 'page', 'revision' ),
222 array( 'DISTINCT rev_user_text', 'rev_user' ),
223 array(
224 $this->db->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0',
225 $cond,
226 'page_id = rev_id',
227 ),
228 __METHOD__
229 );
230
231 foreach ( $res as $row ) {
232 $this->author_list .= "<contributor>" .
233 "<username>" .
234 htmlentities( $row->rev_user_text ) .
235 "</username>" .
236 "<id>" .
237 $row->rev_user .
238 "</id>" .
239 "</contributor>";
240 }
241 $this->author_list .= "</contributors>";
242 wfProfileOut( __METHOD__ );
243 }
244
245 /**
246 * @param string $cond
247 * @throws MWException
248 * @throws Exception
249 */
250 protected function dumpFrom( $cond = '' ) {
251 wfProfileIn( __METHOD__ );
252 # For logging dumps...
253 if ( $this->history & self::LOGS ) {
254 $where = array( 'user_id = log_user' );
255 # Hide private logs
256 $hideLogs = LogEventsList::getExcludeClause( $this->db );
257 if ( $hideLogs ) {
258 $where[] = $hideLogs;
259 }
260 # Add on any caller specified conditions
261 if ( $cond ) {
262 $where[] = $cond;
263 }
264 # Get logging table name for logging.* clause
265 $logging = $this->db->tableName( 'logging' );
266
267 if ( $this->buffer == WikiExporter::STREAM ) {
268 $prev = $this->db->bufferResults( false );
269 }
270 $wrapper = null; // Assuring $wrapper is not undefined, if exception occurs early
271 try {
272 $result = $this->db->select( array( 'logging', 'user' ),
273 array( "{$logging}.*", 'user_name' ), // grab the user name
274 $where,
275 __METHOD__,
276 array( 'ORDER BY' => 'log_id', 'USE INDEX' => array( 'logging' => 'PRIMARY' ) )
277 );
278 $wrapper = $this->db->resultObject( $result );
279 $this->outputLogStream( $wrapper );
280 if ( $this->buffer == WikiExporter::STREAM ) {
281 $this->db->bufferResults( $prev );
282 }
283 } catch ( Exception $e ) {
284 // Throwing the exception does not reliably free the resultset, and
285 // would also leave the connection in unbuffered mode.
286
287 // Freeing result
288 try {
289 if ( $wrapper ) {
290 $wrapper->free();
291 }
292 } catch ( Exception $e2 ) {
293 // Already in panic mode -> ignoring $e2 as $e has
294 // higher priority
295 }
296
297 // Putting database back in previous buffer mode
298 try {
299 if ( $this->buffer == WikiExporter::STREAM ) {
300 $this->db->bufferResults( $prev );
301 }
302 } catch ( Exception $e2 ) {
303 // Already in panic mode -> ignoring $e2 as $e has
304 // higher priority
305 }
306
307 // Inform caller about problem
308 wfProfileOut( __METHOD__ );
309 throw $e;
310 }
311 # For page dumps...
312 } else {
313 $tables = array( 'page', 'revision' );
314 $opts = array( 'ORDER BY' => 'page_id ASC' );
315 $opts['USE INDEX'] = array();
316 $join = array();
317 if ( is_array( $this->history ) ) {
318 # Time offset/limit for all pages/history...
319 $revJoin = 'page_id=rev_page';
320 # Set time order
321 if ( $this->history['dir'] == 'asc' ) {
322 $op = '>';
323 $opts['ORDER BY'] = 'rev_timestamp ASC';
324 } else {
325 $op = '<';
326 $opts['ORDER BY'] = 'rev_timestamp DESC';
327 }
328 # Set offset
329 if ( !empty( $this->history['offset'] ) ) {
330 $revJoin .= " AND rev_timestamp $op " .
331 $this->db->addQuotes( $this->db->timestamp( $this->history['offset'] ) );
332 }
333 $join['revision'] = array( 'INNER JOIN', $revJoin );
334 # Set query limit
335 if ( !empty( $this->history['limit'] ) ) {
336 $opts['LIMIT'] = intval( $this->history['limit'] );
337 }
338 } elseif ( $this->history & WikiExporter::FULL ) {
339 # Full history dumps...
340 $join['revision'] = array( 'INNER JOIN', 'page_id=rev_page' );
341 } elseif ( $this->history & WikiExporter::CURRENT ) {
342 # Latest revision dumps...
343 if ( $this->list_authors && $cond != '' ) { // List authors, if so desired
344 $this->do_list_authors( $cond );
345 }
346 $join['revision'] = array( 'INNER JOIN', 'page_id=rev_page AND page_latest=rev_id' );
347 } elseif ( $this->history & WikiExporter::STABLE ) {
348 # "Stable" revision dumps...
349 # Default JOIN, to be overridden...
350 $join['revision'] = array( 'INNER JOIN', 'page_id=rev_page AND page_latest=rev_id' );
351 # One, and only one hook should set this, and return false
352 if ( wfRunHooks( 'WikiExporter::dumpStableQuery', array( &$tables, &$opts, &$join ) ) ) {
353 wfProfileOut( __METHOD__ );
354 throw new MWException( __METHOD__ . " given invalid history dump type." );
355 }
356 } elseif ( $this->history & WikiExporter::RANGE ) {
357 # Dump of revisions within a specified range
358 $join['revision'] = array( 'INNER JOIN', 'page_id=rev_page' );
359 $opts['ORDER BY'] = array( 'rev_page ASC', 'rev_id ASC' );
360 } else {
361 # Unknown history specification parameter?
362 wfProfileOut( __METHOD__ );
363 throw new MWException( __METHOD__ . " given invalid history dump type." );
364 }
365 # Query optimization hacks
366 if ( $cond == '' ) {
367 $opts[] = 'STRAIGHT_JOIN';
368 $opts['USE INDEX']['page'] = 'PRIMARY';
369 }
370 # Build text join options
371 if ( $this->text != WikiExporter::STUB ) { // 1-pass
372 $tables[] = 'text';
373 $join['text'] = array( 'INNER JOIN', 'rev_text_id=old_id' );
374 }
375
376 if ( $this->buffer == WikiExporter::STREAM ) {
377 $prev = $this->db->bufferResults( false );
378 }
379
380 $wrapper = null; // Assuring $wrapper is not undefined, if exception occurs early
381 try {
382 wfRunHooks( 'ModifyExportQuery',
383 array( $this->db, &$tables, &$cond, &$opts, &$join ) );
384
385 # Do the query!
386 $result = $this->db->select( $tables, '*', $cond, __METHOD__, $opts, $join );
387 $wrapper = $this->db->resultObject( $result );
388 # Output dump results
389 $this->outputPageStream( $wrapper );
390
391 if ( $this->buffer == WikiExporter::STREAM ) {
392 $this->db->bufferResults( $prev );
393 }
394 } catch ( Exception $e ) {
395 // Throwing the exception does not reliably free the resultset, and
396 // would also leave the connection in unbuffered mode.
397
398 // Freeing result
399 try {
400 if ( $wrapper ) {
401 $wrapper->free();
402 }
403 } catch ( Exception $e2 ) {
404 // Already in panic mode -> ignoring $e2 as $e has
405 // higher priority
406 }
407
408 // Putting database back in previous buffer mode
409 try {
410 if ( $this->buffer == WikiExporter::STREAM ) {
411 $this->db->bufferResults( $prev );
412 }
413 } catch ( Exception $e2 ) {
414 // Already in panic mode -> ignoring $e2 as $e has
415 // higher priority
416 }
417
418 // Inform caller about problem
419 throw $e;
420 }
421 }
422 wfProfileOut( __METHOD__ );
423 }
424
425 /**
426 * Runs through a query result set dumping page and revision records.
427 * The result set should be sorted/grouped by page to avoid duplicate
428 * page records in the output.
429 *
430 * Should be safe for
431 * streaming (non-buffered) queries, as long as it was made on a
432 * separate database connection not managed by LoadBalancer; some
433 * blob storage types will make queries to pull source data.
434 *
435 * @param ResultWrapper $resultset
436 */
437 protected function outputPageStream( $resultset ) {
438 $last = null;
439 foreach ( $resultset as $row ) {
440 if ( $last === null ||
441 $last->page_namespace != $row->page_namespace ||
442 $last->page_title != $row->page_title ) {
443 if ( $last !== null ) {
444 $output = '';
445 if ( $this->dumpUploads ) {
446 $output .= $this->writer->writeUploads( $last, $this->dumpUploadFileContents );
447 }
448 $output .= $this->writer->closePage();
449 $this->sink->writeClosePage( $output );
450 }
451 $output = $this->writer->openPage( $row );
452 $this->sink->writeOpenPage( $row, $output );
453 $last = $row;
454 }
455 $output = $this->writer->writeRevision( $row );
456 $this->sink->writeRevision( $row, $output );
457 }
458 if ( $last !== null ) {
459 $output = '';
460 if ( $this->dumpUploads ) {
461 $output .= $this->writer->writeUploads( $last, $this->dumpUploadFileContents );
462 }
463 $output .= $this->author_list;
464 $output .= $this->writer->closePage();
465 $this->sink->writeClosePage( $output );
466 }
467 }
468
469 /**
470 * @param array $resultset
471 */
472 protected function outputLogStream( $resultset ) {
473 foreach ( $resultset as $row ) {
474 $output = $this->writer->writeLogItem( $row );
475 $this->sink->writeLogItem( $row, $output );
476 }
477 }
478 }
479
480 /**
481 * @ingroup Dump
482 */
483 class XmlDumpWriter {
484 /**
485 * Returns the export schema version.
486 * @deprecated since 1.20; use WikiExporter::schemaVersion() instead
487 * @return string
488 */
489 function schemaVersion() {
490 wfDeprecated( __METHOD__, '1.20' );
491 return WikiExporter::schemaVersion();
492 }
493
494 /**
495 * Opens the XML output stream's root "<mediawiki>" element.
496 * This does not include an xml directive, so is safe to include
497 * as a subelement in a larger XML stream. Namespace and XML Schema
498 * references are included.
499 *
500 * Output will be encoded in UTF-8.
501 *
502 * @return string
503 */
504 function openStream() {
505 global $wgLanguageCode;
506 $ver = WikiExporter::schemaVersion();
507 return Xml::element( 'mediawiki', array(
508 'xmlns' => "http://www.mediawiki.org/xml/export-$ver/",
509 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
510 /*
511 * When a new version of the schema is created, it needs staging on mediawiki.org.
512 * This requires a change in the operations/mediawiki-config git repo.
513 *
514 * Create a changeset like https://gerrit.wikimedia.org/r/#/c/149643/ in which
515 * you copy in the new xsd file.
516 *
517 * After it is reviewed, merged and deployed (sync-docroot), the index.html needs purging.
518 * echo "http://www.mediawiki.org/xml/index.html" | mwscript purgeList.php --wiki=aawiki
519 */
520 'xsi:schemaLocation' => "http://www.mediawiki.org/xml/export-$ver/ " .
521 "http://www.mediawiki.org/xml/export-$ver.xsd",
522 'version' => $ver,
523 'xml:lang' => $wgLanguageCode ),
524 null ) .
525 "\n" .
526 $this->siteInfo();
527 }
528
529 /**
530 * @return string
531 */
532 function siteInfo() {
533 $info = array(
534 $this->sitename(),
535 $this->homelink(),
536 $this->generator(),
537 $this->caseSetting(),
538 $this->namespaces() );
539 return " <siteinfo>\n " .
540 implode( "\n ", $info ) .
541 "\n </siteinfo>\n";
542 }
543
544 /**
545 * @return string
546 */
547 function sitename() {
548 global $wgSitename;
549 return Xml::element( 'sitename', array(), $wgSitename );
550 }
551
552 /**
553 * @return string
554 */
555 function generator() {
556 global $wgVersion;
557 return Xml::element( 'generator', array(), "MediaWiki $wgVersion" );
558 }
559
560 /**
561 * @return string
562 */
563 function homelink() {
564 return Xml::element( 'base', array(), Title::newMainPage()->getCanonicalURL() );
565 }
566
567 /**
568 * @return string
569 */
570 function caseSetting() {
571 global $wgCapitalLinks;
572 // "case-insensitive" option is reserved for future
573 $sensitivity = $wgCapitalLinks ? 'first-letter' : 'case-sensitive';
574 return Xml::element( 'case', array(), $sensitivity );
575 }
576
577 /**
578 * @return string
579 */
580 function namespaces() {
581 global $wgContLang;
582 $spaces = "<namespaces>\n";
583 foreach ( $wgContLang->getFormattedNamespaces() as $ns => $title ) {
584 $spaces .= ' ' .
585 Xml::element( 'namespace',
586 array(
587 'key' => $ns,
588 'case' => MWNamespace::isCapitalized( $ns ) ? 'first-letter' : 'case-sensitive',
589 ), $title ) . "\n";
590 }
591 $spaces .= " </namespaces>";
592 return $spaces;
593 }
594
595 /**
596 * Closes the output stream with the closing root element.
597 * Call when finished dumping things.
598 *
599 * @return string
600 */
601 function closeStream() {
602 return "</mediawiki>\n";
603 }
604
605 /**
606 * Opens a "<page>" section on the output stream, with data
607 * from the given database row.
608 *
609 * @param object $row
610 * @return string
611 */
612 public function openPage( $row ) {
613 $out = " <page>\n";
614 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
615 $out .= ' ' . Xml::elementClean( 'title', array(), self::canonicalTitle( $title ) ) . "\n";
616 $out .= ' ' . Xml::element( 'ns', array(), strval( $row->page_namespace ) ) . "\n";
617 $out .= ' ' . Xml::element( 'id', array(), strval( $row->page_id ) ) . "\n";
618 if ( $row->page_is_redirect ) {
619 $page = WikiPage::factory( $title );
620 $redirect = $page->getRedirectTarget();
621 if ( $redirect instanceof Title && $redirect->isValidRedirectTarget() ) {
622 $out .= ' ';
623 $out .= Xml::element( 'redirect', array( 'title' => self::canonicalTitle( $redirect ) ) );
624 $out .= "\n";
625 }
626 }
627
628 if ( $row->page_restrictions != '' ) {
629 $out .= ' ' . Xml::element( 'restrictions', array(),
630 strval( $row->page_restrictions ) ) . "\n";
631 }
632
633 wfRunHooks( 'XmlDumpWriterOpenPage', array( $this, &$out, $row, $title ) );
634
635 return $out;
636 }
637
638 /**
639 * Closes a "<page>" section on the output stream.
640 *
641 * @access private
642 * @return string
643 */
644 function closePage() {
645 return " </page>\n";
646 }
647
648 /**
649 * Dumps a "<revision>" section on the output stream, with
650 * data filled in from the given database row.
651 *
652 * @param object $row
653 * @return string
654 * @access private
655 */
656 function writeRevision( $row ) {
657 wfProfileIn( __METHOD__ );
658
659 $out = " <revision>\n";
660 $out .= " " . Xml::element( 'id', null, strval( $row->rev_id ) ) . "\n";
661 if ( isset( $row->rev_parent_id ) && $row->rev_parent_id ) {
662 $out .= " " . Xml::element( 'parentid', null, strval( $row->rev_parent_id ) ) . "\n";
663 }
664
665 $out .= $this->writeTimestamp( $row->rev_timestamp );
666
667 if ( isset( $row->rev_deleted ) && ( $row->rev_deleted & Revision::DELETED_USER ) ) {
668 $out .= " " . Xml::element( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
669 } else {
670 $out .= $this->writeContributor( $row->rev_user, $row->rev_user_text );
671 }
672
673 if ( isset( $row->rev_minor_edit ) && $row->rev_minor_edit ) {
674 $out .= " <minor/>\n";
675 }
676 if ( isset( $row->rev_deleted ) && ( $row->rev_deleted & Revision::DELETED_COMMENT ) ) {
677 $out .= " " . Xml::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
678 } elseif ( $row->rev_comment != '' ) {
679 $out .= " " . Xml::elementClean( 'comment', array(), strval( $row->rev_comment ) ) . "\n";
680 }
681
682 if ( isset( $row->rev_content_model ) && !is_null( $row->rev_content_model ) ) {
683 $content_model = strval( $row->rev_content_model );
684 } else {
685 // probably using $wgContentHandlerUseDB = false;
686 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
687 $content_model = ContentHandler::getDefaultModelFor( $title );
688 }
689
690 $content_handler = ContentHandler::getForModelID( $content_model );
691
692 if ( isset( $row->rev_content_format ) && !is_null( $row->rev_content_format ) ) {
693 $content_format = strval( $row->rev_content_format );
694 } else {
695 // probably using $wgContentHandlerUseDB = false;
696 $content_format = $content_handler->getDefaultFormat();
697 }
698
699 $text = '';
700 if ( isset( $row->rev_deleted ) && ( $row->rev_deleted & Revision::DELETED_TEXT ) ) {
701 $out .= " " . Xml::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
702 } elseif ( isset( $row->old_text ) ) {
703 // Raw text from the database may have invalid chars
704 $text = strval( Revision::getRevisionText( $row ) );
705 $text = $content_handler->exportTransform( $text, $content_format );
706 $out .= " " . Xml::elementClean( 'text',
707 array( 'xml:space' => 'preserve', 'bytes' => intval( $row->rev_len ) ),
708 strval( $text ) ) . "\n";
709 } else {
710 // Stub output
711 $out .= " " . Xml::element( 'text',
712 array( 'id' => $row->rev_text_id, 'bytes' => intval( $row->rev_len ) ),
713 "" ) . "\n";
714 }
715
716 if ( isset( $row->rev_sha1 )
717 && $row->rev_sha1
718 && !( $row->rev_deleted & Revision::DELETED_TEXT )
719 ) {
720 $out .= " " . Xml::element( 'sha1', null, strval( $row->rev_sha1 ) ) . "\n";
721 } else {
722 $out .= " <sha1/>\n";
723 }
724
725 $out .= " " . Xml::element( 'model', null, strval( $content_model ) ) . "\n";
726 $out .= " " . Xml::element( 'format', null, strval( $content_format ) ) . "\n";
727
728 wfRunHooks( 'XmlDumpWriterWriteRevision', array( &$this, &$out, $row, $text ) );
729
730 $out .= " </revision>\n";
731
732 wfProfileOut( __METHOD__ );
733 return $out;
734 }
735
736 /**
737 * Dumps a "<logitem>" section on the output stream, with
738 * data filled in from the given database row.
739 *
740 * @param object $row
741 * @return string
742 * @access private
743 */
744 function writeLogItem( $row ) {
745 wfProfileIn( __METHOD__ );
746
747 $out = " <logitem>\n";
748 $out .= " " . Xml::element( 'id', null, strval( $row->log_id ) ) . "\n";
749
750 $out .= $this->writeTimestamp( $row->log_timestamp, " " );
751
752 if ( $row->log_deleted & LogPage::DELETED_USER ) {
753 $out .= " " . Xml::element( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
754 } else {
755 $out .= $this->writeContributor( $row->log_user, $row->user_name, " " );
756 }
757
758 if ( $row->log_deleted & LogPage::DELETED_COMMENT ) {
759 $out .= " " . Xml::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
760 } elseif ( $row->log_comment != '' ) {
761 $out .= " " . Xml::elementClean( 'comment', null, strval( $row->log_comment ) ) . "\n";
762 }
763
764 $out .= " " . Xml::element( 'type', null, strval( $row->log_type ) ) . "\n";
765 $out .= " " . Xml::element( 'action', null, strval( $row->log_action ) ) . "\n";
766
767 if ( $row->log_deleted & LogPage::DELETED_ACTION ) {
768 $out .= " " . Xml::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
769 } else {
770 $title = Title::makeTitle( $row->log_namespace, $row->log_title );
771 $out .= " " . Xml::elementClean( 'logtitle', null, self::canonicalTitle( $title ) ) . "\n";
772 $out .= " " . Xml::elementClean( 'params',
773 array( 'xml:space' => 'preserve' ),
774 strval( $row->log_params ) ) . "\n";
775 }
776
777 $out .= " </logitem>\n";
778
779 wfProfileOut( __METHOD__ );
780 return $out;
781 }
782
783 /**
784 * @param string $timestamp
785 * @param string $indent Default to six spaces
786 * @return string
787 */
788 function writeTimestamp( $timestamp, $indent = " " ) {
789 $ts = wfTimestamp( TS_ISO_8601, $timestamp );
790 return $indent . Xml::element( 'timestamp', null, $ts ) . "\n";
791 }
792
793 /**
794 * @param int $id
795 * @param string $text
796 * @param string $indent Default to six spaces
797 * @return string
798 */
799 function writeContributor( $id, $text, $indent = " " ) {
800 $out = $indent . "<contributor>\n";
801 if ( $id || !IP::isValid( $text ) ) {
802 $out .= $indent . " " . Xml::elementClean( 'username', null, strval( $text ) ) . "\n";
803 $out .= $indent . " " . Xml::element( 'id', null, strval( $id ) ) . "\n";
804 } else {
805 $out .= $indent . " " . Xml::elementClean( 'ip', null, strval( $text ) ) . "\n";
806 }
807 $out .= $indent . "</contributor>\n";
808 return $out;
809 }
810
811 /**
812 * Warning! This data is potentially inconsistent. :(
813 * @param object $row
814 * @param bool $dumpContents
815 * @return string
816 */
817 function writeUploads( $row, $dumpContents = false ) {
818 if ( $row->page_namespace == NS_FILE ) {
819 $img = wfLocalFile( $row->page_title );
820 if ( $img && $img->exists() ) {
821 $out = '';
822 foreach ( array_reverse( $img->getHistory() ) as $ver ) {
823 $out .= $this->writeUpload( $ver, $dumpContents );
824 }
825 $out .= $this->writeUpload( $img, $dumpContents );
826 return $out;
827 }
828 }
829 return '';
830 }
831
832 /**
833 * @param File $file
834 * @param bool $dumpContents
835 * @return string
836 */
837 function writeUpload( $file, $dumpContents = false ) {
838 if ( $file->isOld() ) {
839 $archiveName = " " .
840 Xml::element( 'archivename', null, $file->getArchiveName() ) . "\n";
841 } else {
842 $archiveName = '';
843 }
844 if ( $dumpContents ) {
845 $be = $file->getRepo()->getBackend();
846 # Dump file as base64
847 # Uses only XML-safe characters, so does not need escaping
848 # @todo Too bad this loads the contents into memory (script might swap)
849 $contents = ' <contents encoding="base64">' .
850 chunk_split( base64_encode(
851 $be->getFileContents( array( 'src' => $file->getPath() ) ) ) ) .
852 " </contents>\n";
853 } else {
854 $contents = '';
855 }
856 if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
857 $comment = Xml::element( 'comment', array( 'deleted' => 'deleted' ) );
858 } else {
859 $comment = Xml::elementClean( 'comment', null, $file->getDescription() );
860 }
861 return " <upload>\n" .
862 $this->writeTimestamp( $file->getTimestamp() ) .
863 $this->writeContributor( $file->getUser( 'id' ), $file->getUser( 'text' ) ) .
864 " " . $comment . "\n" .
865 " " . Xml::element( 'filename', null, $file->getName() ) . "\n" .
866 $archiveName .
867 " " . Xml::element( 'src', null, $file->getCanonicalURL() ) . "\n" .
868 " " . Xml::element( 'size', null, $file->getSize() ) . "\n" .
869 " " . Xml::element( 'sha1base36', null, $file->getSha1() ) . "\n" .
870 " " . Xml::element( 'rel', null, $file->getRel() ) . "\n" .
871 $contents .
872 " </upload>\n";
873 }
874
875 /**
876 * Return prefixed text form of title, but using the content language's
877 * canonical namespace. This skips any special-casing such as gendered
878 * user namespaces -- which while useful, are not yet listed in the
879 * XML "<siteinfo>" data so are unsafe in export.
880 *
881 * @param Title $title
882 * @return string
883 * @since 1.18
884 */
885 public static function canonicalTitle( Title $title ) {
886 if ( $title->isExternal() ) {
887 return $title->getPrefixedText();
888 }
889
890 global $wgContLang;
891 $prefix = str_replace( '_', ' ', $wgContLang->getNsText( $title->getNamespace() ) );
892
893 if ( $prefix !== '' ) {
894 $prefix .= ':';
895 }
896
897 return $prefix . $title->getText();
898 }
899 }
900
901 /**
902 * Base class for output stream; prints to stdout or buffer or wherever.
903 * @ingroup Dump
904 */
905 class DumpOutput {
906
907 /**
908 * @param string $string
909 */
910 function writeOpenStream( $string ) {
911 $this->write( $string );
912 }
913
914 /**
915 * @param string $string
916 */
917 function writeCloseStream( $string ) {
918 $this->write( $string );
919 }
920
921 /**
922 * @param object $page
923 * @param string $string
924 */
925 function writeOpenPage( $page, $string ) {
926 $this->write( $string );
927 }
928
929 /**
930 * @param string $string
931 */
932 function writeClosePage( $string ) {
933 $this->write( $string );
934 }
935
936 /**
937 * @param object $rev
938 * @param string $string
939 */
940 function writeRevision( $rev, $string ) {
941 $this->write( $string );
942 }
943
944 /**
945 * @param object $rev
946 * @param string $string
947 */
948 function writeLogItem( $rev, $string ) {
949 $this->write( $string );
950 }
951
952 /**
953 * Override to write to a different stream type.
954 * @param string $string
955 * @return bool
956 */
957 function write( $string ) {
958 print $string;
959 }
960
961 /**
962 * Close the old file, move it to a specified name,
963 * and reopen new file with the old name. Use this
964 * for writing out a file in multiple pieces
965 * at specified checkpoints (e.g. every n hours).
966 * @param string|array $newname File name. May be a string or an array with one element
967 */
968 function closeRenameAndReopen( $newname ) {
969 }
970
971 /**
972 * Close the old file, and move it to a specified name.
973 * Use this for the last piece of a file written out
974 * at specified checkpoints (e.g. every n hours).
975 * @param string|array $newname File name. May be a string or an array with one element
976 * @param bool $open If true, a new file with the old filename will be opened
977 * again for writing (default: false)
978 */
979 function closeAndRename( $newname, $open = false ) {
980 }
981
982 /**
983 * Returns the name of the file or files which are
984 * being written to, if there are any.
985 * @return null
986 */
987 function getFilenames() {
988 return null;
989 }
990 }
991
992 /**
993 * Stream outputter to send data to a file.
994 * @ingroup Dump
995 */
996 class DumpFileOutput extends DumpOutput {
997 protected $handle = false, $filename;
998
999 /**
1000 * @param string $file
1001 */
1002 function __construct( $file ) {
1003 $this->handle = fopen( $file, "wt" );
1004 $this->filename = $file;
1005 }
1006
1007 /**
1008 * @param string $string
1009 */
1010 function writeCloseStream( $string ) {
1011 parent::writeCloseStream( $string );
1012 if ( $this->handle ) {
1013 fclose( $this->handle );
1014 $this->handle = false;
1015 }
1016 }
1017
1018 /**
1019 * @param string $string
1020 */
1021 function write( $string ) {
1022 fputs( $this->handle, $string );
1023 }
1024
1025 /**
1026 * @param string $newname
1027 */
1028 function closeRenameAndReopen( $newname ) {
1029 $this->closeAndRename( $newname, true );
1030 }
1031
1032 /**
1033 * @param string $newname
1034 * @throws MWException
1035 */
1036 function renameOrException( $newname ) {
1037 if ( !rename( $this->filename, $newname ) ) {
1038 throw new MWException( __METHOD__ . ": rename of file {$this->filename} to $newname failed\n" );
1039 }
1040 }
1041
1042 /**
1043 * @param array $newname
1044 * @return string
1045 * @throws MWException
1046 */
1047 function checkRenameArgCount( $newname ) {
1048 if ( is_array( $newname ) ) {
1049 if ( count( $newname ) > 1 ) {
1050 throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" );
1051 } else {
1052 $newname = $newname[0];
1053 }
1054 }
1055 return $newname;
1056 }
1057
1058 /**
1059 * @param string $newname
1060 * @param bool $open
1061 */
1062 function closeAndRename( $newname, $open = false ) {
1063 $newname = $this->checkRenameArgCount( $newname );
1064 if ( $newname ) {
1065 if ( $this->handle ) {
1066 fclose( $this->handle );
1067 $this->handle = false;
1068 }
1069 $this->renameOrException( $newname );
1070 if ( $open ) {
1071 $this->handle = fopen( $this->filename, "wt" );
1072 }
1073 }
1074 }
1075
1076 /**
1077 * @return string|null
1078 */
1079 function getFilenames() {
1080 return $this->filename;
1081 }
1082 }
1083
1084 /**
1085 * Stream outputter to send data to a file via some filter program.
1086 * Even if compression is available in a library, using a separate
1087 * program can allow us to make use of a multi-processor system.
1088 * @ingroup Dump
1089 */
1090 class DumpPipeOutput extends DumpFileOutput {
1091 protected $command, $filename;
1092 protected $procOpenResource = false;
1093
1094 /**
1095 * @param string $command
1096 * @param string $file
1097 */
1098 function __construct( $command, $file = null ) {
1099 if ( !is_null( $file ) ) {
1100 $command .= " > " . wfEscapeShellArg( $file );
1101 }
1102
1103 $this->startCommand( $command );
1104 $this->command = $command;
1105 $this->filename = $file;
1106 }
1107
1108 /**
1109 * @param string $string
1110 */
1111 function writeCloseStream( $string ) {
1112 parent::writeCloseStream( $string );
1113 if ( $this->procOpenResource ) {
1114 proc_close( $this->procOpenResource );
1115 $this->procOpenResource = false;
1116 }
1117 }
1118
1119 /**
1120 * @param string $command
1121 */
1122 function startCommand( $command ) {
1123 $spec = array(
1124 0 => array( "pipe", "r" ),
1125 );
1126 $pipes = array();
1127 $this->procOpenResource = proc_open( $command, $spec, $pipes );
1128 $this->handle = $pipes[0];
1129 }
1130
1131 /**
1132 * @param string $newname
1133 */
1134 function closeRenameAndReopen( $newname ) {
1135 $this->closeAndRename( $newname, true );
1136 }
1137
1138 /**
1139 * @param string $newname
1140 * @param bool $open
1141 */
1142 function closeAndRename( $newname, $open = false ) {
1143 $newname = $this->checkRenameArgCount( $newname );
1144 if ( $newname ) {
1145 if ( $this->handle ) {
1146 fclose( $this->handle );
1147 $this->handle = false;
1148 }
1149 if ( $this->procOpenResource ) {
1150 proc_close( $this->procOpenResource );
1151 $this->procOpenResource = false;
1152 }
1153 $this->renameOrException( $newname );
1154 if ( $open ) {
1155 $command = $this->command;
1156 $command .= " > " . wfEscapeShellArg( $this->filename );
1157 $this->startCommand( $command );
1158 }
1159 }
1160 }
1161 }
1162
1163 /**
1164 * Sends dump output via the gzip compressor.
1165 * @ingroup Dump
1166 */
1167 class DumpGZipOutput extends DumpPipeOutput {
1168 /**
1169 * @param string $file
1170 */
1171 function __construct( $file ) {
1172 parent::__construct( "gzip", $file );
1173 }
1174 }
1175
1176 /**
1177 * Sends dump output via the bgzip2 compressor.
1178 * @ingroup Dump
1179 */
1180 class DumpBZip2Output extends DumpPipeOutput {
1181 /**
1182 * @param string $file
1183 */
1184 function __construct( $file ) {
1185 parent::__construct( "bzip2", $file );
1186 }
1187 }
1188
1189 /**
1190 * Sends dump output via the p7zip compressor.
1191 * @ingroup Dump
1192 */
1193 class Dump7ZipOutput extends DumpPipeOutput {
1194 /**
1195 * @param string $file
1196 */
1197 function __construct( $file ) {
1198 $command = $this->setup7zCommand( $file );
1199 parent::__construct( $command );
1200 $this->filename = $file;
1201 }
1202
1203 /**
1204 * @param string $file
1205 * @return string
1206 */
1207 function setup7zCommand( $file ) {
1208 $command = "7za a -bd -si " . wfEscapeShellArg( $file );
1209 // Suppress annoying useless crap from p7zip
1210 // Unfortunately this could suppress real error messages too
1211 $command .= ' >' . wfGetNull() . ' 2>&1';
1212 return $command;
1213 }
1214
1215 /**
1216 * @param string $newname
1217 * @param bool $open
1218 */
1219 function closeAndRename( $newname, $open = false ) {
1220 $newname = $this->checkRenameArgCount( $newname );
1221 if ( $newname ) {
1222 fclose( $this->handle );
1223 proc_close( $this->procOpenResource );
1224 $this->renameOrException( $newname );
1225 if ( $open ) {
1226 $command = $this->setup7zCommand( $this->filename );
1227 $this->startCommand( $command );
1228 }
1229 }
1230 }
1231 }
1232
1233 /**
1234 * Dump output filter class.
1235 * This just does output filtering and streaming; XML formatting is done
1236 * higher up, so be careful in what you do.
1237 * @ingroup Dump
1238 */
1239 class DumpFilter {
1240 /**
1241 * @var DumpOutput
1242 * FIXME will need to be made protected whenever legacy code
1243 * is updated.
1244 */
1245 public $sink;
1246
1247 /**
1248 * @var bool
1249 */
1250 protected $sendingThisPage;
1251
1252 /**
1253 * @param DumpOutput $sink
1254 */
1255 function __construct( &$sink ) {
1256 $this->sink =& $sink;
1257 }
1258
1259 /**
1260 * @param string $string
1261 */
1262 function writeOpenStream( $string ) {
1263 $this->sink->writeOpenStream( $string );
1264 }
1265
1266 /**
1267 * @param string $string
1268 */
1269 function writeCloseStream( $string ) {
1270 $this->sink->writeCloseStream( $string );
1271 }
1272
1273 /**
1274 * @param object $page
1275 * @param string $string
1276 */
1277 function writeOpenPage( $page, $string ) {
1278 $this->sendingThisPage = $this->pass( $page, $string );
1279 if ( $this->sendingThisPage ) {
1280 $this->sink->writeOpenPage( $page, $string );
1281 }
1282 }
1283
1284 /**
1285 * @param string $string
1286 */
1287 function writeClosePage( $string ) {
1288 if ( $this->sendingThisPage ) {
1289 $this->sink->writeClosePage( $string );
1290 $this->sendingThisPage = false;
1291 }
1292 }
1293
1294 /**
1295 * @param object $rev
1296 * @param string $string
1297 */
1298 function writeRevision( $rev, $string ) {
1299 if ( $this->sendingThisPage ) {
1300 $this->sink->writeRevision( $rev, $string );
1301 }
1302 }
1303
1304 /**
1305 * @param object $rev
1306 * @param string $string
1307 */
1308 function writeLogItem( $rev, $string ) {
1309 $this->sink->writeRevision( $rev, $string );
1310 }
1311
1312 /**
1313 * @param string $newname
1314 */
1315 function closeRenameAndReopen( $newname ) {
1316 $this->sink->closeRenameAndReopen( $newname );
1317 }
1318
1319 /**
1320 * @param string $newname
1321 * @param bool $open
1322 */
1323 function closeAndRename( $newname, $open = false ) {
1324 $this->sink->closeAndRename( $newname, $open );
1325 }
1326
1327 /**
1328 * @return array
1329 */
1330 function getFilenames() {
1331 return $this->sink->getFilenames();
1332 }
1333
1334 /**
1335 * Override for page-based filter types.
1336 * @param object $page
1337 * @return bool
1338 */
1339 function pass( $page ) {
1340 return true;
1341 }
1342 }
1343
1344 /**
1345 * Simple dump output filter to exclude all talk pages.
1346 * @ingroup Dump
1347 */
1348 class DumpNotalkFilter extends DumpFilter {
1349 /**
1350 * @param object $page
1351 * @return bool
1352 */
1353 function pass( $page ) {
1354 return !MWNamespace::isTalk( $page->page_namespace );
1355 }
1356 }
1357
1358 /**
1359 * Dump output filter to include or exclude pages in a given set of namespaces.
1360 * @ingroup Dump
1361 */
1362 class DumpNamespaceFilter extends DumpFilter {
1363 /** @var bool */
1364 protected $invert = false;
1365
1366 /** @var array */
1367 protected $namespaces = array();
1368
1369 /**
1370 * @param DumpOutput $sink
1371 * @param array $param
1372 * @throws MWException
1373 */
1374 function __construct( &$sink, $param ) {
1375 parent::__construct( $sink );
1376
1377 $constants = array(
1378 "NS_MAIN" => NS_MAIN,
1379 "NS_TALK" => NS_TALK,
1380 "NS_USER" => NS_USER,
1381 "NS_USER_TALK" => NS_USER_TALK,
1382 "NS_PROJECT" => NS_PROJECT,
1383 "NS_PROJECT_TALK" => NS_PROJECT_TALK,
1384 "NS_FILE" => NS_FILE,
1385 "NS_FILE_TALK" => NS_FILE_TALK,
1386 "NS_IMAGE" => NS_IMAGE, // NS_IMAGE is an alias for NS_FILE
1387 "NS_IMAGE_TALK" => NS_IMAGE_TALK,
1388 "NS_MEDIAWIKI" => NS_MEDIAWIKI,
1389 "NS_MEDIAWIKI_TALK" => NS_MEDIAWIKI_TALK,
1390 "NS_TEMPLATE" => NS_TEMPLATE,
1391 "NS_TEMPLATE_TALK" => NS_TEMPLATE_TALK,
1392 "NS_HELP" => NS_HELP,
1393 "NS_HELP_TALK" => NS_HELP_TALK,
1394 "NS_CATEGORY" => NS_CATEGORY,
1395 "NS_CATEGORY_TALK" => NS_CATEGORY_TALK );
1396
1397 if ( $param { 0 } == '!' ) {
1398 $this->invert = true;
1399 $param = substr( $param, 1 );
1400 }
1401
1402 foreach ( explode( ',', $param ) as $key ) {
1403 $key = trim( $key );
1404 if ( isset( $constants[$key] ) ) {
1405 $ns = $constants[$key];
1406 $this->namespaces[$ns] = true;
1407 } elseif ( is_numeric( $key ) ) {
1408 $ns = intval( $key );
1409 $this->namespaces[$ns] = true;
1410 } else {
1411 throw new MWException( "Unrecognized namespace key '$key'\n" );
1412 }
1413 }
1414 }
1415
1416 /**
1417 * @param object $page
1418 * @return bool
1419 */
1420 function pass( $page ) {
1421 $match = isset( $this->namespaces[$page->page_namespace] );
1422 return $this->invert xor $match;
1423 }
1424 }
1425
1426 /**
1427 * Dump output filter to include only the last revision in each page sequence.
1428 * @ingroup Dump
1429 */
1430 class DumpLatestFilter extends DumpFilter {
1431 protected $page;
1432
1433 protected $pageString;
1434
1435 protected $rev;
1436
1437 protected $revString;
1438
1439 /**
1440 * @param object $page
1441 * @param string $string
1442 */
1443 function writeOpenPage( $page, $string ) {
1444 $this->page = $page;
1445 $this->pageString = $string;
1446 }
1447
1448 /**
1449 * @param string $string
1450 */
1451 function writeClosePage( $string ) {
1452 if ( $this->rev ) {
1453 $this->sink->writeOpenPage( $this->page, $this->pageString );
1454 $this->sink->writeRevision( $this->rev, $this->revString );
1455 $this->sink->writeClosePage( $string );
1456 }
1457 $this->rev = null;
1458 $this->revString = null;
1459 $this->page = null;
1460 $this->pageString = null;
1461 }
1462
1463 /**
1464 * @param object $rev
1465 * @param string $string
1466 */
1467 function writeRevision( $rev, $string ) {
1468 if ( $rev->rev_id == $this->page->page_latest ) {
1469 $this->rev = $rev;
1470 $this->revString = $string;
1471 }
1472 }
1473 }
1474
1475 /**
1476 * Base class for output stream; prints to stdout or buffer or wherever.
1477 * @ingroup Dump
1478 */
1479 class DumpMultiWriter {
1480
1481 /**
1482 * @param array $sinks
1483 */
1484 function __construct( $sinks ) {
1485 $this->sinks = $sinks;
1486 $this->count = count( $sinks );
1487 }
1488
1489 /**
1490 * @param string $string
1491 */
1492 function writeOpenStream( $string ) {
1493 for ( $i = 0; $i < $this->count; $i++ ) {
1494 $this->sinks[$i]->writeOpenStream( $string );
1495 }
1496 }
1497
1498 /**
1499 * @param string $string
1500 */
1501 function writeCloseStream( $string ) {
1502 for ( $i = 0; $i < $this->count; $i++ ) {
1503 $this->sinks[$i]->writeCloseStream( $string );
1504 }
1505 }
1506
1507 /**
1508 * @param object $page
1509 * @param string $string
1510 */
1511 function writeOpenPage( $page, $string ) {
1512 for ( $i = 0; $i < $this->count; $i++ ) {
1513 $this->sinks[$i]->writeOpenPage( $page, $string );
1514 }
1515 }
1516
1517 /**
1518 * @param string $string
1519 */
1520 function writeClosePage( $string ) {
1521 for ( $i = 0; $i < $this->count; $i++ ) {
1522 $this->sinks[$i]->writeClosePage( $string );
1523 }
1524 }
1525
1526 /**
1527 * @param object $rev
1528 * @param string $string
1529 */
1530 function writeRevision( $rev, $string ) {
1531 for ( $i = 0; $i < $this->count; $i++ ) {
1532 $this->sinks[$i]->writeRevision( $rev, $string );
1533 }
1534 }
1535
1536 /**
1537 * @param array $newnames
1538 */
1539 function closeRenameAndReopen( $newnames ) {
1540 $this->closeAndRename( $newnames, true );
1541 }
1542
1543 /**
1544 * @param array $newnames
1545 * @param bool $open
1546 */
1547 function closeAndRename( $newnames, $open = false ) {
1548 for ( $i = 0; $i < $this->count; $i++ ) {
1549 $this->sinks[$i]->closeAndRename( $newnames[$i], $open );
1550 }
1551 }
1552
1553 /**
1554 * @return array
1555 */
1556 function getFilenames() {
1557 $filenames = array();
1558 for ( $i = 0; $i < $this->count; $i++ ) {
1559 $filenames[] = $this->sinks[$i]->getFilenames();
1560 }
1561 return $filenames;
1562 }
1563 }