3 * Base classes for dumps and export
5 * Copyright © 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
6 * http://www.mediawiki.org/
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.
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.
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
31 * @ingroup SpecialPage Dump
34 var $list_authors = false ; # Return distinct author list (when not returning full history)
35 var $author_list = "" ;
37 var $dumpUploads = false;
41 const STABLE
= 4; // extension defined
51 * If using WikiExporter::STREAM to stream a large amount of data,
52 * provide a database connection which is not managed by
53 * LoadBalancer to read from: some history blob types will
54 * make additional queries to pull source data while the
55 * main query is still running.
58 * @param $history Mixed: one of WikiExporter::FULL or WikiExporter::CURRENT,
59 * or an associative array:
60 * offset: non-inclusive offset at which to start the query
61 * limit: maximum number of rows to return
62 * dir: "asc" or "desc" timestamp order
63 * @param $buffer Int: one of WikiExporter::BUFFER or WikiExporter::STREAM
64 * @param $text Int: one of WikiExporter::TEXT or WikiExporter::STUB
66 function __construct( &$db, $history = WikiExporter
::CURRENT
,
67 $buffer = WikiExporter
::BUFFER
, $text = WikiExporter
::TEXT
) {
69 $this->history
= $history;
70 $this->buffer
= $buffer;
71 $this->writer
= new XmlDumpWriter();
72 $this->sink
= new DumpOutput();
77 * Set the DumpOutput or DumpFilter object which will receive
78 * various row objects and XML output for filtering. Filters
79 * can be chained or used as callbacks.
83 public function setOutputSink( &$sink ) {
87 public function openStream() {
88 $output = $this->writer
->openStream();
89 $this->sink
->writeOpenStream( $output );
92 public function closeStream() {
93 $output = $this->writer
->closeStream();
94 $this->sink
->writeCloseStream( $output );
98 * Dumps a series of page and revision records for all pages
99 * in the database, either including complete history or only
100 * the most recent version.
102 public function allPages() {
103 return $this->dumpFrom( '' );
107 * Dumps a series of page and revision records for those pages
108 * in the database falling within the page_id range given.
109 * @param $start Int: inclusive lower limit (this id is included)
110 * @param $end Int: Exclusive upper limit (this id is not included)
111 * If 0, no upper limit.
113 public function pagesByRange( $start, $end ) {
114 $condition = 'page_id >= ' . intval( $start );
116 $condition .= ' AND page_id < ' . intval( $end );
118 return $this->dumpFrom( $condition );
122 * @param $title Title
124 public function pageByTitle( $title ) {
125 return $this->dumpFrom(
126 'page_namespace=' . $title->getNamespace() .
127 ' AND page_title=' . $this->db
->addQuotes( $title->getDBkey() ) );
130 public function pageByName( $name ) {
131 $title = Title
::newFromText( $name );
132 if( is_null( $title ) ) {
133 return new WikiError( "Can't export invalid title" );
135 return $this->pageByTitle( $title );
139 public function pagesByName( $names ) {
140 foreach( $names as $name ) {
141 $this->pageByName( $name );
145 public function allLogs() {
146 return $this->dumpFrom( '' );
149 public function logsByRange( $start, $end ) {
150 $condition = 'log_id >= ' . intval( $start );
152 $condition .= ' AND log_id < ' . intval( $end );
154 return $this->dumpFrom( $condition );
157 # Generates the distinct list of authors of an article
158 # Not called by default (depends on $this->list_authors)
159 # Can be set by Special:Export when not exporting whole history
160 protected function do_list_authors( $page , $revision , $cond ) {
161 wfProfileIn( __METHOD__
);
162 $this->author_list
= "<contributors>";
164 $nothidden = '('.$this->db
->bitAnd('rev_deleted', Revision
::DELETED_USER
) . ') = 0';
166 $sql = "SELECT DISTINCT rev_user_text,rev_user FROM {$page},{$revision}
167 WHERE page_id=rev_page AND $nothidden AND " . $cond ;
168 $result = $this->db
->query( $sql, __METHOD__
);
169 $resultset = $this->db
->resultObject( $result );
170 foreach ( $resultset as $row ) {
171 $this->author_list
.= "<contributor>" .
173 htmlentities( $row->rev_user_text
) .
180 wfProfileOut( __METHOD__
);
181 $this->author_list
.= "</contributors>";
184 protected function dumpFrom( $cond = '' ) {
185 wfProfileIn( __METHOD__
);
186 # For logging dumps...
187 if( $this->history
& self
::LOGS
) {
188 if( $this->buffer
== WikiExporter
::STREAM
) {
189 $prev = $this->db
->bufferResults( false );
191 $where = array( 'user_id = log_user' );
193 $hideLogs = LogEventsList
::getExcludeClause( $this->db
);
194 if( $hideLogs ) $where[] = $hideLogs;
195 # Add on any caller specified conditions
196 if( $cond ) $where[] = $cond;
197 # Get logging table name for logging.* clause
198 $logging = $this->db
->tableName('logging');
199 $result = $this->db
->select( array('logging','user'),
200 array( "{$logging}.*", 'user_name' ), // grab the user name
203 array( 'ORDER BY' => 'log_id', 'USE INDEX' => array('logging' => 'PRIMARY') )
205 $wrapper = $this->db
->resultObject( $result );
206 $this->outputLogStream( $wrapper );
207 if( $this->buffer
== WikiExporter
::STREAM
) {
208 $this->db
->bufferResults( $prev );
212 $tables = array( 'page', 'revision' );
213 $opts = array( 'ORDER BY' => 'page_id ASC' );
214 $opts['USE INDEX'] = array();
216 if( is_array( $this->history
) ) {
217 # Time offset/limit for all pages/history...
218 $revJoin = 'page_id=rev_page';
220 if( $this->history
['dir'] == 'asc' ) {
222 $opts['ORDER BY'] = 'rev_timestamp ASC';
225 $opts['ORDER BY'] = 'rev_timestamp DESC';
228 if( !empty( $this->history
['offset'] ) ) {
229 $revJoin .= " AND rev_timestamp $op " .
230 $this->db
->addQuotes( $this->db
->timestamp( $this->history
['offset'] ) );
232 $join['revision'] = array('INNER JOIN',$revJoin);
234 if( !empty( $this->history
['limit'] ) ) {
235 $opts['LIMIT'] = intval( $this->history
['limit'] );
237 } elseif( $this->history
& WikiExporter
::FULL
) {
238 # Full history dumps...
239 $join['revision'] = array('INNER JOIN','page_id=rev_page');
240 } elseif( $this->history
& WikiExporter
::CURRENT
) {
241 # Latest revision dumps...
242 if( $this->list_authors
&& $cond != '' ) { // List authors, if so desired
243 list($page,$revision) = $this->db
->tableNamesN('page','revision');
244 $this->do_list_authors( $page, $revision, $cond );
246 $join['revision'] = array('INNER JOIN','page_id=rev_page AND page_latest=rev_id');
247 } elseif( $this->history
& WikiExporter
::STABLE
) {
248 # "Stable" revision dumps...
249 # Default JOIN, to be overridden...
250 $join['revision'] = array('INNER JOIN','page_id=rev_page AND page_latest=rev_id');
251 # One, and only one hook should set this, and return false
252 if( wfRunHooks( 'WikiExporter::dumpStableQuery', array(&$tables,&$opts,&$join) ) ) {
253 wfProfileOut( __METHOD__
);
254 return new WikiError( __METHOD__
." given invalid history dump type." );
257 # Uknown history specification parameter?
258 wfProfileOut( __METHOD__
);
259 return new WikiError( __METHOD__
." given invalid history dump type." );
261 # Query optimization hacks
263 $opts[] = 'STRAIGHT_JOIN';
264 $opts['USE INDEX']['page'] = 'PRIMARY';
266 # Build text join options
267 if( $this->text
!= WikiExporter
::STUB
) { // 1-pass
269 $join['text'] = array('INNER JOIN','rev_text_id=old_id');
272 if( $this->buffer
== WikiExporter
::STREAM
) {
273 $prev = $this->db
->bufferResults( false );
276 wfRunHooks( 'ModifyExportQuery',
277 array( $this->db
, &$tables, &$cond, &$opts, &$join ) );
280 $result = $this->db
->select( $tables, '*', $cond, __METHOD__
, $opts, $join );
281 $wrapper = $this->db
->resultObject( $result );
282 # Output dump results
283 $this->outputPageStream( $wrapper );
284 if( $this->list_authors
) {
285 $this->outputPageStream( $wrapper );
288 if( $this->buffer
== WikiExporter
::STREAM
) {
289 $this->db
->bufferResults( $prev );
292 wfProfileOut( __METHOD__
);
296 * Runs through a query result set dumping page and revision records.
297 * The result set should be sorted/grouped by page to avoid duplicate
298 * page records in the output.
300 * The result set will be freed once complete. Should be safe for
301 * streaming (non-buffered) queries, as long as it was made on a
302 * separate database connection not managed by LoadBalancer; some
303 * blob storage types will make queries to pull source data.
305 * @param $resultset ResultWrapper
307 protected function outputPageStream( $resultset ) {
309 foreach ( $resultset as $row ) {
310 if( is_null( $last ) ||
311 $last->page_namespace
!= $row->page_namespace ||
312 $last->page_title
!= $row->page_title
) {
313 if( isset( $last ) ) {
315 if( $this->dumpUploads
) {
316 $output .= $this->writer
->writeUploads( $last );
318 $output .= $this->writer
->closePage();
319 $this->sink
->writeClosePage( $output );
321 $output = $this->writer
->openPage( $row );
322 $this->sink
->writeOpenPage( $row, $output );
325 $output = $this->writer
->writeRevision( $row );
326 $this->sink
->writeRevision( $row, $output );
328 if( isset( $last ) ) {
330 if( $this->dumpUploads
) {
331 $output .= $this->writer
->writeUploads( $last );
333 $output .= $this->author_list
;
334 $output .= $this->writer
->closePage();
335 $this->sink
->writeClosePage( $output );
339 protected function outputLogStream( $resultset ) {
340 foreach ( $resultset as $row ) {
341 $output = $this->writer
->writeLogItem( $row );
342 $this->sink
->writeLogItem( $row, $output );
350 class XmlDumpWriter
{
353 * Returns the export schema version.
356 function schemaVersion() {
361 * Opens the XML output stream's root <mediawiki> element.
362 * This does not include an xml directive, so is safe to include
363 * as a subelement in a larger XML stream. Namespace and XML Schema
364 * references are included.
366 * Output will be encoded in UTF-8.
370 function openStream() {
371 global $wgLanguageCode;
372 $ver = $this->schemaVersion();
373 return Xml
::element( 'mediawiki', array(
374 'xmlns' => "http://www.mediawiki.org/xml/export-$ver/",
375 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
376 'xsi:schemaLocation' => "http://www.mediawiki.org/xml/export-$ver/ " .
377 "http://www.mediawiki.org/xml/export-$ver.xsd",
379 'xml:lang' => $wgLanguageCode ),
385 function siteInfo() {
390 $this->caseSetting(),
391 $this->namespaces() );
392 return " <siteinfo>\n " .
393 implode( "\n ", $info ) .
397 function sitename() {
399 return Xml
::element( 'sitename', array(), $wgSitename );
402 function generator() {
404 return Xml
::element( 'generator', array(), "MediaWiki $wgVersion" );
407 function homelink() {
408 return Xml
::element( 'base', array(), Title
::newMainPage()->getFullUrl() );
411 function caseSetting() {
412 global $wgCapitalLinks;
413 // "case-insensitive" option is reserved for future
414 $sensitivity = $wgCapitalLinks ?
'first-letter' : 'case-sensitive';
415 return Xml
::element( 'case', array(), $sensitivity );
418 function namespaces() {
420 $spaces = "<namespaces>\n";
421 foreach( $wgContLang->getFormattedNamespaces() as $ns => $title ) {
423 Xml
::element( 'namespace',
425 'case' => MWNamespace
::isCapitalized( $ns ) ?
'first-letter' : 'case-sensitive',
428 $spaces .= " </namespaces>";
433 * Closes the output stream with the closing root element.
434 * Call when finished dumping things.
436 function closeStream() {
437 return "</mediawiki>\n";
442 * Opens a <page> section on the output stream, with data
443 * from the given database row.
449 function openPage( $row ) {
451 $title = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
452 $out .= ' ' . Xml
::elementClean( 'title', array(), $title->getPrefixedText() ) . "\n";
453 $out .= ' ' . Xml
::element( 'id', array(), strval( $row->page_id
) ) . "\n";
454 if( $row->page_is_redirect
) {
455 $out .= ' ' . Xml
::element( 'redirect', array() ) . "\n";
457 if( $row->page_restrictions
!= '' ) {
458 $out .= ' ' . Xml
::element( 'restrictions', array(),
459 strval( $row->page_restrictions
) ) . "\n";
462 wfRunHooks( 'XmlDumpWriterOpenPage', array( $this, &$out, $row, $title ) );
468 * Closes a <page> section on the output stream.
472 function closePage() {
477 * Dumps a <revision> section on the output stream, with
478 * data filled in from the given database row.
484 function writeRevision( $row ) {
485 wfProfileIn( __METHOD__
);
487 $out = " <revision>\n";
488 $out .= " " . Xml
::element( 'id', null, strval( $row->rev_id
) ) . "\n";
490 $out .= $this->writeTimestamp( $row->rev_timestamp
);
492 if( $row->rev_deleted
& Revision
::DELETED_USER
) {
493 $out .= " " . Xml
::element( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
495 $out .= $this->writeContributor( $row->rev_user
, $row->rev_user_text
);
498 if( $row->rev_minor_edit
) {
499 $out .= " <minor/>\n";
501 if( $row->rev_deleted
& Revision
::DELETED_COMMENT
) {
502 $out .= " " . Xml
::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
503 } elseif( $row->rev_comment
!= '' ) {
504 $out .= " " . Xml
::elementClean( 'comment', null, strval( $row->rev_comment
) ) . "\n";
508 if( $row->rev_deleted
& Revision
::DELETED_TEXT
) {
509 $out .= " " . Xml
::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
510 } elseif( isset( $row->old_text
) ) {
511 // Raw text from the database may have invalid chars
512 $text = strval( Revision
::getRevisionText( $row ) );
513 $out .= " " . Xml
::elementClean( 'text',
514 array( 'xml:space' => 'preserve' ),
515 strval( $text ) ) . "\n";
518 $out .= " " . Xml
::element( 'text',
519 array( 'id' => $row->rev_text_id
),
523 wfRunHooks( 'XmlDumpWriterWriteRevision', array( &$this, &$out, $row, $text ) );
525 $out .= " </revision>\n";
527 wfProfileOut( __METHOD__
);
532 * Dumps a <logitem> section on the output stream, with
533 * data filled in from the given database row.
539 function writeLogItem( $row ) {
540 wfProfileIn( __METHOD__
);
542 $out = " <logitem>\n";
543 $out .= " " . Xml
::element( 'id', null, strval( $row->log_id
) ) . "\n";
545 $out .= $this->writeTimestamp( $row->log_timestamp
);
547 if( $row->log_deleted
& LogPage
::DELETED_USER
) {
548 $out .= " " . Xml
::element( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
550 $out .= $this->writeContributor( $row->log_user
, $row->user_name
);
553 if( $row->log_deleted
& LogPage
::DELETED_COMMENT
) {
554 $out .= " " . Xml
::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
555 } elseif( $row->log_comment
!= '' ) {
556 $out .= " " . Xml
::elementClean( 'comment', null, strval( $row->log_comment
) ) . "\n";
559 $out .= " " . Xml
::element( 'type', null, strval( $row->log_type
) ) . "\n";
560 $out .= " " . Xml
::element( 'action', null, strval( $row->log_action
) ) . "\n";
562 if( $row->log_deleted
& LogPage
::DELETED_ACTION
) {
563 $out .= " " . Xml
::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
565 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
566 $out .= " " . Xml
::elementClean( 'logtitle', null, $title->getPrefixedText() ) . "\n";
567 $out .= " " . Xml
::elementClean( 'params',
568 array( 'xml:space' => 'preserve' ),
569 strval( $row->log_params
) ) . "\n";
572 $out .= " </logitem>\n";
574 wfProfileOut( __METHOD__
);
578 function writeTimestamp( $timestamp ) {
579 $ts = wfTimestamp( TS_ISO_8601
, $timestamp );
580 return " " . Xml
::element( 'timestamp', null, $ts ) . "\n";
583 function writeContributor( $id, $text ) {
584 $out = " <contributor>\n";
586 $out .= " " . Xml
::elementClean( 'username', null, strval( $text ) ) . "\n";
587 $out .= " " . Xml
::element( 'id', null, strval( $id ) ) . "\n";
589 $out .= " " . Xml
::elementClean( 'ip', null, strval( $text ) ) . "\n";
591 $out .= " </contributor>\n";
596 * Warning! This data is potentially inconsistent. :(
598 function writeUploads( $row ) {
599 if( $row->page_namespace
== NS_IMAGE
) {
600 $img = wfFindFile( $row->page_title
);
603 foreach( array_reverse( $img->getHistory() ) as $ver ) {
604 $out .= $this->writeUpload( $ver );
606 $out .= $this->writeUpload( $img );
613 function writeUpload( $file ) {
614 return " <upload>\n" .
615 $this->writeTimestamp( $file->getTimestamp() ) .
616 $this->writeContributor( $file->getUser( 'id' ), $file->getUser( 'text' ) ) .
617 " " . Xml
::elementClean( 'comment', null, $file->getDescription() ) . "\n" .
618 " " . Xml
::element( 'filename', null, $file->getName() ) . "\n" .
619 " " . Xml
::element( 'src', null, $file->getFullUrl() ) . "\n" .
620 " " . Xml
::element( 'size', null, $file->getSize() ) . "\n" .
628 * Base class for output stream; prints to stdout or buffer or whereever.
632 function writeOpenStream( $string ) {
633 $this->write( $string );
636 function writeCloseStream( $string ) {
637 $this->write( $string );
640 function writeOpenPage( $page, $string ) {
641 $this->write( $string );
644 function writeClosePage( $string ) {
645 $this->write( $string );
648 function writeRevision( $rev, $string ) {
649 $this->write( $string );
652 function writeLogItem( $rev, $string ) {
653 $this->write( $string );
657 * Override to write to a different stream type.
660 function write( $string ) {
666 * Stream outputter to send data to a file.
669 class DumpFileOutput
extends DumpOutput
{
672 function __construct( $file ) {
673 $this->handle
= fopen( $file, "wt" );
676 function write( $string ) {
677 fputs( $this->handle
, $string );
682 * Stream outputter to send data to a file via some filter program.
683 * Even if compression is available in a library, using a separate
684 * program can allow us to make use of a multi-processor system.
687 class DumpPipeOutput
extends DumpFileOutput
{
688 function __construct( $command, $file = null ) {
689 if( !is_null( $file ) ) {
690 $command .= " > " . wfEscapeShellArg( $file );
692 $this->handle
= popen( $command, "w" );
697 * Sends dump output via the gzip compressor.
700 class DumpGZipOutput
extends DumpPipeOutput
{
701 function __construct( $file ) {
702 parent
::__construct( "gzip", $file );
707 * Sends dump output via the bgzip2 compressor.
710 class DumpBZip2Output
extends DumpPipeOutput
{
711 function __construct( $file ) {
712 parent
::__construct( "bzip2", $file );
717 * Sends dump output via the p7zip compressor.
720 class Dump7ZipOutput
extends DumpPipeOutput
{
721 function __construct( $file ) {
722 $command = "7za a -bd -si " . wfEscapeShellArg( $file );
723 // Suppress annoying useless crap from p7zip
724 // Unfortunately this could suppress real error messages too
725 $command .= ' >' . wfGetNull() . ' 2>&1';
726 parent
::__construct( $command );
733 * Dump output filter class.
734 * This just does output filtering and streaming; XML formatting is done
735 * higher up, so be careful in what you do.
739 function __construct( &$sink ) {
740 $this->sink
=& $sink;
743 function writeOpenStream( $string ) {
744 $this->sink
->writeOpenStream( $string );
747 function writeCloseStream( $string ) {
748 $this->sink
->writeCloseStream( $string );
751 function writeOpenPage( $page, $string ) {
752 $this->sendingThisPage
= $this->pass( $page, $string );
753 if( $this->sendingThisPage
) {
754 $this->sink
->writeOpenPage( $page, $string );
758 function writeClosePage( $string ) {
759 if( $this->sendingThisPage
) {
760 $this->sink
->writeClosePage( $string );
761 $this->sendingThisPage
= false;
765 function writeRevision( $rev, $string ) {
766 if( $this->sendingThisPage
) {
767 $this->sink
->writeRevision( $rev, $string );
771 function writeLogItem( $rev, $string ) {
772 $this->sink
->writeRevision( $rev, $string );
776 * Override for page-based filter types.
779 function pass( $page ) {
785 * Simple dump output filter to exclude all talk pages.
788 class DumpNotalkFilter
extends DumpFilter
{
789 function pass( $page ) {
790 return !MWNamespace
::isTalk( $page->page_namespace
);
795 * Dump output filter to include or exclude pages in a given set of namespaces.
798 class DumpNamespaceFilter
extends DumpFilter
{
800 var $namespaces = array();
802 function __construct( &$sink, $param ) {
803 parent
::__construct( $sink );
806 "NS_MAIN" => NS_MAIN
,
807 "NS_TALK" => NS_TALK
,
808 "NS_USER" => NS_USER
,
809 "NS_USER_TALK" => NS_USER_TALK
,
810 "NS_PROJECT" => NS_PROJECT
,
811 "NS_PROJECT_TALK" => NS_PROJECT_TALK
,
812 "NS_FILE" => NS_FILE
,
813 "NS_FILE_TALK" => NS_FILE_TALK
,
814 "NS_IMAGE" => NS_IMAGE
, // NS_IMAGE is an alias for NS_FILE
815 "NS_IMAGE_TALK" => NS_IMAGE_TALK
,
816 "NS_MEDIAWIKI" => NS_MEDIAWIKI
,
817 "NS_MEDIAWIKI_TALK" => NS_MEDIAWIKI_TALK
,
818 "NS_TEMPLATE" => NS_TEMPLATE
,
819 "NS_TEMPLATE_TALK" => NS_TEMPLATE_TALK
,
820 "NS_HELP" => NS_HELP
,
821 "NS_HELP_TALK" => NS_HELP_TALK
,
822 "NS_CATEGORY" => NS_CATEGORY
,
823 "NS_CATEGORY_TALK" => NS_CATEGORY_TALK
);
825 if( $param{0} == '!' ) {
826 $this->invert
= true;
827 $param = substr( $param, 1 );
830 foreach( explode( ',', $param ) as $key ) {
832 if( isset( $constants[$key] ) ) {
833 $ns = $constants[$key];
834 $this->namespaces
[$ns] = true;
835 } elseif( is_numeric( $key ) ) {
836 $ns = intval( $key );
837 $this->namespaces
[$ns] = true;
839 throw new MWException( "Unrecognized namespace key '$key'\n" );
844 function pass( $page ) {
845 $match = isset( $this->namespaces
[$page->page_namespace
] );
846 return $this->invert
xor $match;
852 * Dump output filter to include only the last revision in each page sequence.
855 class DumpLatestFilter
extends DumpFilter
{
856 var $page, $pageString, $rev, $revString;
858 function writeOpenPage( $page, $string ) {
860 $this->pageString
= $string;
863 function writeClosePage( $string ) {
865 $this->sink
->writeOpenPage( $this->page
, $this->pageString
);
866 $this->sink
->writeRevision( $this->rev
, $this->revString
);
867 $this->sink
->writeClosePage( $string );
870 $this->revString
= null;
872 $this->pageString
= null;
875 function writeRevision( $rev, $string ) {
876 if( $rev->rev_id
== $this->page
->page_latest
) {
878 $this->revString
= $string;
884 * Base class for output stream; prints to stdout or buffer or whereever.
887 class DumpMultiWriter
{
888 function __construct( $sinks ) {
889 $this->sinks
= $sinks;
890 $this->count
= count( $sinks );
893 function writeOpenStream( $string ) {
894 for( $i = 0; $i < $this->count
; $i++
) {
895 $this->sinks
[$i]->writeOpenStream( $string );
899 function writeCloseStream( $string ) {
900 for( $i = 0; $i < $this->count
; $i++
) {
901 $this->sinks
[$i]->writeCloseStream( $string );
905 function writeOpenPage( $page, $string ) {
906 for( $i = 0; $i < $this->count
; $i++
) {
907 $this->sinks
[$i]->writeOpenPage( $page, $string );
911 function writeClosePage( $string ) {
912 for( $i = 0; $i < $this->count
; $i++
) {
913 $this->sinks
[$i]->writeClosePage( $string );
917 function writeRevision( $rev, $string ) {
918 for( $i = 0; $i < $this->count
; $i++
) {
919 $this->sinks
[$i]->writeRevision( $rev, $string );
924 function xmlsafe( $string ) {
925 wfProfileIn( __FUNCTION__
);
928 * The page may contain old data which has not been properly normalized.
929 * Invalid UTF-8 sequences or forbidden control characters will make our
930 * XML output invalid, so be sure to strip them out.
932 $string = UtfNormal
::cleanUp( $string );
934 $string = htmlspecialchars( $string );
935 wfProfileOut( __FUNCTION__
);