2 # Copyright (C) 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
3 # http://www.mediawiki.org/
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # http://www.gnu.org/copyleft/gpl.html
25 * @ingroup SpecialPage Dump
28 var $list_authors = false ; # Return distinct author list (when not returning full history)
29 var $author_list = "" ;
31 var $dumpUploads = false;
35 const STABLE
= 4; // extension defined
45 * If using WikiExporter::STREAM to stream a large amount of data,
46 * provide a database connection which is not managed by
47 * LoadBalancer to read from: some history blob types will
48 * make additional queries to pull source data while the
49 * main query is still running.
52 * @param $history Mixed: one of WikiExporter::FULL or WikiExporter::CURRENT,
53 * or an associative array:
54 * offset: non-inclusive offset at which to start the query
55 * limit: maximum number of rows to return
56 * dir: "asc" or "desc" timestamp order
57 * @param $buffer Int: one of WikiExporter::BUFFER or WikiExporter::STREAM
58 * @param $text Int: one of WikiExporter::TEXT or WikiExporter::STUB
60 function __construct( &$db, $history = WikiExporter
::CURRENT
,
61 $buffer = WikiExporter
::BUFFER
, $text = WikiExporter
::TEXT
) {
63 $this->history
= $history;
64 $this->buffer
= $buffer;
65 $this->writer
= new XmlDumpWriter();
66 $this->sink
= new DumpOutput();
71 * Set the DumpOutput or DumpFilter object which will receive
72 * various row objects and XML output for filtering. Filters
73 * can be chained or used as callbacks.
77 public function setOutputSink( &$sink ) {
81 public function openStream() {
82 $output = $this->writer
->openStream();
83 $this->sink
->writeOpenStream( $output );
86 public function closeStream() {
87 $output = $this->writer
->closeStream();
88 $this->sink
->writeCloseStream( $output );
92 * Dumps a series of page and revision records for all pages
93 * in the database, either including complete history or only
94 * the most recent version.
96 public function allPages() {
97 return $this->dumpFrom( '' );
101 * Dumps a series of page and revision records for those pages
102 * in the database falling within the page_id range given.
103 * @param $start Int: inclusive lower limit (this id is included)
104 * @param $end Int: Exclusive upper limit (this id is not included)
105 * If 0, no upper limit.
107 public function pagesByRange( $start, $end ) {
108 $condition = 'page_id >= ' . intval( $start );
110 $condition .= ' AND page_id < ' . intval( $end );
112 return $this->dumpFrom( $condition );
116 * @param $title Title
118 public function pageByTitle( $title ) {
119 return $this->dumpFrom(
120 'page_namespace=' . $title->getNamespace() .
121 ' AND page_title=' . $this->db
->addQuotes( $title->getDBkey() ) );
124 public function pageByName( $name ) {
125 $title = Title
::newFromText( $name );
126 if( is_null( $title ) ) {
127 return new WikiError( "Can't export invalid title" );
129 return $this->pageByTitle( $title );
133 public function pagesByName( $names ) {
134 foreach( $names as $name ) {
135 $this->pageByName( $name );
139 public function allLogs() {
140 return $this->dumpFrom( '' );
143 public function logsByRange( $start, $end ) {
144 $condition = 'log_id >= ' . intval( $start );
146 $condition .= ' AND log_id < ' . intval( $end );
148 return $this->dumpFrom( $condition );
151 # Generates the distinct list of authors of an article
152 # Not called by default (depends on $this->list_authors)
153 # Can be set by Special:Export when not exporting whole history
154 protected function do_list_authors( $page , $revision , $cond ) {
155 $fname = "do_list_authors" ;
156 wfProfileIn( $fname );
157 $this->author_list
= "<contributors>";
159 $nothidden = '('.$this->db
->bitAnd('rev_deleted', Revision
::DELETED_USER
) . ') = 0';
161 $sql = "SELECT DISTINCT rev_user_text,rev_user FROM {$page},{$revision}
162 WHERE page_id=rev_page AND $nothidden AND " . $cond ;
163 $result = $this->db
->query( $sql, $fname );
164 $resultset = $this->db
->resultObject( $result );
165 while( $row = $resultset->fetchObject() ) {
166 $this->author_list
.= "<contributor>" .
168 htmlentities( $row->rev_user_text
) .
175 wfProfileOut( $fname );
176 $this->author_list
.= "</contributors>";
179 protected function dumpFrom( $cond = '' ) {
180 wfProfileIn( __METHOD__
);
181 # For logging dumps...
182 if( $this->history
& self
::LOGS
) {
183 if( $this->buffer
== WikiExporter
::STREAM
) {
184 $prev = $this->db
->bufferResults( false );
186 $where = array( 'user_id = log_user' );
188 $hideLogs = LogEventsList
::getExcludeClause( $this->db
);
189 if( $hideLogs ) $where[] = $hideLogs;
190 # Add on any caller specified conditions
191 if( $cond ) $where[] = $cond;
192 # Get logging table name for logging.* clause
193 $logging = $this->db
->tableName('logging');
194 $result = $this->db
->select( array('logging','user'),
195 array( "{$logging}.*", 'user_name' ), // grab the user name
198 array( 'ORDER BY' => 'log_id', 'USE INDEX' => array('logging' => 'PRIMARY') )
200 $wrapper = $this->db
->resultObject( $result );
201 $this->outputLogStream( $wrapper );
202 if( $this->buffer
== WikiExporter
::STREAM
) {
203 $this->db
->bufferResults( $prev );
207 $tables = array( 'page', 'revision' );
208 $opts = array( 'ORDER BY' => 'page_id ASC' );
209 $opts['USE INDEX'] = array();
211 if( is_array( $this->history
) ) {
212 # Time offset/limit for all pages/history...
213 $revJoin = 'page_id=rev_page';
215 if( $this->history
['dir'] == 'asc' ) {
217 $opts['ORDER BY'] = 'rev_timestamp ASC';
220 $opts['ORDER BY'] = 'rev_timestamp DESC';
223 if( !empty( $this->history
['offset'] ) ) {
224 $revJoin .= " AND rev_timestamp $op " .
225 $this->db
->addQuotes( $this->db
->timestamp( $this->history
['offset'] ) );
227 $join['revision'] = array('INNER JOIN',$revJoin);
229 if( !empty( $this->history
['limit'] ) ) {
230 $opts['LIMIT'] = intval( $this->history
['limit'] );
232 } elseif( $this->history
& WikiExporter
::FULL
) {
233 # Full history dumps...
234 $join['revision'] = array('INNER JOIN','page_id=rev_page');
235 } elseif( $this->history
& WikiExporter
::CURRENT
) {
236 # Latest revision dumps...
237 if( $this->list_authors
&& $cond != '' ) { // List authors, if so desired
238 list($page,$revision) = $this->db
->tableNamesN('page','revision');
239 $this->do_list_authors( $page, $revision, $cond );
241 $join['revision'] = array('INNER JOIN','page_id=rev_page AND page_latest=rev_id');
242 } elseif( $this->history
& WikiExporter
::STABLE
) {
243 # "Stable" revision dumps...
244 # Default JOIN, to be overridden...
245 $join['revision'] = array('INNER JOIN','page_id=rev_page AND page_latest=rev_id');
246 # One, and only one hook should set this, and return false
247 if( wfRunHooks( 'WikiExporter::dumpStableQuery', array(&$tables,&$opts,&$join) ) ) {
248 wfProfileOut( __METHOD__
);
249 return new WikiError( __METHOD__
." given invalid history dump type." );
252 # Uknown history specification parameter?
253 wfProfileOut( __METHOD__
);
254 return new WikiError( __METHOD__
." given invalid history dump type." );
256 # Query optimization hacks
258 $opts[] = 'STRAIGHT_JOIN';
259 $opts['USE INDEX']['page'] = 'PRIMARY';
261 # Build text join options
262 if( $this->text
!= WikiExporter
::STUB
) { // 1-pass
264 $join['text'] = array('INNER JOIN','rev_text_id=old_id');
267 if( $this->buffer
== WikiExporter
::STREAM
) {
268 $prev = $this->db
->bufferResults( false );
271 wfRunHooks( 'ModifyExportQuery',
272 array( $this->db
, &$tables, &$cond, &$opts, &$join ) );
275 $result = $this->db
->select( $tables, '*', $cond, __METHOD__
, $opts, $join );
276 $wrapper = $this->db
->resultObject( $result );
277 # Output dump results
278 $this->outputPageStream( $wrapper );
279 if( $this->list_authors
) {
280 $this->outputPageStream( $wrapper );
283 if( $this->buffer
== WikiExporter
::STREAM
) {
284 $this->db
->bufferResults( $prev );
287 wfProfileOut( __METHOD__
);
291 * Runs through a query result set dumping page and revision records.
292 * The result set should be sorted/grouped by page to avoid duplicate
293 * page records in the output.
295 * The result set will be freed once complete. Should be safe for
296 * streaming (non-buffered) queries, as long as it was made on a
297 * separate database connection not managed by LoadBalancer; some
298 * blob storage types will make queries to pull source data.
300 * @param $resultset ResultWrapper
302 protected function outputPageStream( $resultset ) {
304 while( $row = $resultset->fetchObject() ) {
305 if( is_null( $last ) ||
306 $last->page_namespace
!= $row->page_namespace ||
307 $last->page_title
!= $row->page_title
) {
308 if( isset( $last ) ) {
310 if( $this->dumpUploads
) {
311 $output .= $this->writer
->writeUploads( $last );
313 $output .= $this->writer
->closePage();
314 $this->sink
->writeClosePage( $output );
316 $output = $this->writer
->openPage( $row );
317 $this->sink
->writeOpenPage( $row, $output );
320 $output = $this->writer
->writeRevision( $row );
321 $this->sink
->writeRevision( $row, $output );
323 if( isset( $last ) ) {
325 if( $this->dumpUploads
) {
326 $output .= $this->writer
->writeUploads( $last );
328 $output .= $this->author_list
;
329 $output .= $this->writer
->closePage();
330 $this->sink
->writeClosePage( $output );
334 protected function outputLogStream( $resultset ) {
335 while( $row = $resultset->fetchObject() ) {
336 $output = $this->writer
->writeLogItem( $row );
337 $this->sink
->writeLogItem( $row, $output );
345 class XmlDumpWriter
{
348 * Returns the export schema version.
351 function schemaVersion() {
356 * Opens the XML output stream's root <mediawiki> element.
357 * This does not include an xml directive, so is safe to include
358 * as a subelement in a larger XML stream. Namespace and XML Schema
359 * references are included.
361 * Output will be encoded in UTF-8.
365 function openStream() {
366 global $wgContLanguageCode;
367 $ver = $this->schemaVersion();
368 return Xml
::element( 'mediawiki', array(
369 'xmlns' => "http://www.mediawiki.org/xml/export-$ver/",
370 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
371 'xsi:schemaLocation' => "http://www.mediawiki.org/xml/export-$ver/ " .
372 "http://www.mediawiki.org/xml/export-$ver.xsd",
374 'xml:lang' => $wgContLanguageCode ),
380 function siteInfo() {
385 $this->caseSetting(),
386 $this->namespaces() );
387 return " <siteinfo>\n " .
388 implode( "\n ", $info ) .
392 function sitename() {
394 return Xml
::element( 'sitename', array(), $wgSitename );
397 function generator() {
399 return Xml
::element( 'generator', array(), "MediaWiki $wgVersion" );
402 function homelink() {
403 return Xml
::element( 'base', array(), Title
::newMainPage()->getFullUrl() );
406 function caseSetting() {
407 global $wgCapitalLinks;
408 // "case-insensitive" option is reserved for future
409 $sensitivity = $wgCapitalLinks ?
'first-letter' : 'case-sensitive';
410 return Xml
::element( 'case', array(), $sensitivity );
413 function namespaces() {
415 $spaces = "<namespaces>\n";
416 foreach( $wgContLang->getFormattedNamespaces() as $ns => $title ) {
417 $spaces .= ' ' . Xml
::element( 'namespace', array( 'key' => $ns ), $title ) . "\n";
419 $spaces .= " </namespaces>";
424 * Closes the output stream with the closing root element.
425 * Call when finished dumping things.
427 function closeStream() {
428 return "</mediawiki>\n";
433 * Opens a <page> section on the output stream, with data
434 * from the given database row.
440 function openPage( $row ) {
442 $title = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
443 $out .= ' ' . Xml
::elementClean( 'title', array(), $title->getPrefixedText() ) . "\n";
444 $out .= ' ' . Xml
::element( 'id', array(), strval( $row->page_id
) ) . "\n";
445 if( $row->page_is_redirect
) {
446 $out .= ' ' . Xml
::element( 'redirect', array() ) . "\n";
448 if( '' != $row->page_restrictions
) {
449 $out .= ' ' . Xml
::element( 'restrictions', array(),
450 strval( $row->page_restrictions
) ) . "\n";
453 wfRunHooks( 'XmlDumpWriterOpenPage', array( $this, &$out, $row, $title ) );
459 * Closes a <page> section on the output stream.
463 function closePage() {
468 * Dumps a <revision> section on the output stream, with
469 * data filled in from the given database row.
475 function writeRevision( $row ) {
476 $fname = 'WikiExporter::dumpRev';
477 wfProfileIn( $fname );
479 $out = " <revision>\n";
480 $out .= " " . Xml
::element( 'id', null, strval( $row->rev_id
) ) . "\n";
482 $out .= $this->writeTimestamp( $row->rev_timestamp
);
484 if( $row->rev_deleted
& Revision
::DELETED_USER
) {
485 $out .= " " . Xml
::element( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
487 $out .= $this->writeContributor( $row->rev_user
, $row->rev_user_text
);
490 if( $row->rev_minor_edit
) {
491 $out .= " <minor/>\n";
493 if( $row->rev_deleted
& Revision
::DELETED_COMMENT
) {
494 $out .= " " . Xml
::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
495 } elseif( $row->rev_comment
!= '' ) {
496 $out .= " " . Xml
::elementClean( 'comment', null, strval( $row->rev_comment
) ) . "\n";
499 if( $row->rev_deleted
& Revision
::DELETED_TEXT
) {
500 $out .= " " . Xml
::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
501 } elseif( isset( $row->old_text
) ) {
502 // Raw text from the database may have invalid chars
503 $text = strval( Revision
::getRevisionText( $row ) );
504 $out .= " " . Xml
::elementClean( 'text',
505 array( 'xml:space' => 'preserve' ),
506 strval( $text ) ) . "\n";
509 $out .= " " . Xml
::element( 'text',
510 array( 'id' => $row->rev_text_id
),
514 wfRunHooks( 'XmlDumpWriterWriteRevision', array( &$this, &$out, $row, $text ) );
516 $out .= " </revision>\n";
518 wfProfileOut( $fname );
523 * Dumps a <logitem> section on the output stream, with
524 * data filled in from the given database row.
530 function writeLogItem( $row ) {
531 $fname = 'WikiExporter::writeLogItem';
532 wfProfileIn( $fname );
534 $out = " <logitem>\n";
535 $out .= " " . Xml
::element( 'id', null, strval( $row->log_id
) ) . "\n";
537 $out .= $this->writeTimestamp( $row->log_timestamp
);
539 if( $row->log_deleted
& LogPage
::DELETED_USER
) {
540 $out .= " " . Xml
::element( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
542 $out .= $this->writeContributor( $row->log_user
, $row->user_name
);
545 if( $row->log_deleted
& LogPage
::DELETED_COMMENT
) {
546 $out .= " " . Xml
::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
547 } elseif( $row->log_comment
!= '' ) {
548 $out .= " " . Xml
::elementClean( 'comment', null, strval( $row->log_comment
) ) . "\n";
551 $out .= " " . Xml
::element( 'type', null, strval( $row->log_type
) ) . "\n";
552 $out .= " " . Xml
::element( 'action', null, strval( $row->log_action
) ) . "\n";
554 if( $row->log_deleted
& LogPage
::DELETED_ACTION
) {
555 $out .= " " . Xml
::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
557 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
558 $out .= " " . Xml
::elementClean( 'logtitle', null, $title->getPrefixedText() ) . "\n";
559 $out .= " " . Xml
::elementClean( 'params',
560 array( 'xml:space' => 'preserve' ),
561 strval( $row->log_params
) ) . "\n";
564 $out .= " </logitem>\n";
566 wfProfileOut( $fname );
570 function writeTimestamp( $timestamp ) {
571 $ts = wfTimestamp( TS_ISO_8601
, $timestamp );
572 return " " . Xml
::element( 'timestamp', null, $ts ) . "\n";
575 function writeContributor( $id, $text ) {
576 $out = " <contributor>\n";
578 $out .= " " . Xml
::elementClean( 'username', null, strval( $text ) ) . "\n";
579 $out .= " " . Xml
::element( 'id', null, strval( $id ) ) . "\n";
581 $out .= " " . Xml
::elementClean( 'ip', null, strval( $text ) ) . "\n";
583 $out .= " </contributor>\n";
588 * Warning! This data is potentially inconsistent. :(
590 function writeUploads( $row ) {
591 if( $row->page_namespace
== NS_IMAGE
) {
592 $img = wfFindFile( $row->page_title
);
595 foreach( array_reverse( $img->getHistory() ) as $ver ) {
596 $out .= $this->writeUpload( $ver );
598 $out .= $this->writeUpload( $img );
605 function writeUpload( $file ) {
606 return " <upload>\n" .
607 $this->writeTimestamp( $file->getTimestamp() ) .
608 $this->writeContributor( $file->getUser( 'id' ), $file->getUser( 'text' ) ) .
609 " " . Xml
::elementClean( 'comment', null, $file->getDescription() ) . "\n" .
610 " " . Xml
::element( 'filename', null, $file->getName() ) . "\n" .
611 " " . Xml
::element( 'src', null, $file->getFullUrl() ) . "\n" .
612 " " . Xml
::element( 'size', null, $file->getSize() ) . "\n" .
620 * Base class for output stream; prints to stdout or buffer or whereever.
624 function writeOpenStream( $string ) {
625 $this->write( $string );
628 function writeCloseStream( $string ) {
629 $this->write( $string );
632 function writeOpenPage( $page, $string ) {
633 $this->write( $string );
636 function writeClosePage( $string ) {
637 $this->write( $string );
640 function writeRevision( $rev, $string ) {
641 $this->write( $string );
644 function writeLogItem( $rev, $string ) {
645 $this->write( $string );
649 * Override to write to a different stream type.
652 function write( $string ) {
658 * Stream outputter to send data to a file.
661 class DumpFileOutput
extends DumpOutput
{
664 function DumpFileOutput( $file ) {
665 $this->handle
= fopen( $file, "wt" );
668 function write( $string ) {
669 fputs( $this->handle
, $string );
674 * Stream outputter to send data to a file via some filter program.
675 * Even if compression is available in a library, using a separate
676 * program can allow us to make use of a multi-processor system.
679 class DumpPipeOutput
extends DumpFileOutput
{
680 function DumpPipeOutput( $command, $file = null ) {
681 if( !is_null( $file ) ) {
682 $command .= " > " . wfEscapeShellArg( $file );
684 $this->handle
= popen( $command, "w" );
689 * Sends dump output via the gzip compressor.
692 class DumpGZipOutput
extends DumpPipeOutput
{
693 function DumpGZipOutput( $file ) {
694 parent
::DumpPipeOutput( "gzip", $file );
699 * Sends dump output via the bgzip2 compressor.
702 class DumpBZip2Output
extends DumpPipeOutput
{
703 function DumpBZip2Output( $file ) {
704 parent
::DumpPipeOutput( "bzip2", $file );
709 * Sends dump output via the p7zip compressor.
712 class Dump7ZipOutput
extends DumpPipeOutput
{
713 function Dump7ZipOutput( $file ) {
714 $command = "7za a -bd -si " . wfEscapeShellArg( $file );
715 // Suppress annoying useless crap from p7zip
716 // Unfortunately this could suppress real error messages too
717 $command .= ' >' . wfGetNull() . ' 2>&1';
718 parent
::DumpPipeOutput( $command );
725 * Dump output filter class.
726 * This just does output filtering and streaming; XML formatting is done
727 * higher up, so be careful in what you do.
731 function DumpFilter( &$sink ) {
732 $this->sink
=& $sink;
735 function writeOpenStream( $string ) {
736 $this->sink
->writeOpenStream( $string );
739 function writeCloseStream( $string ) {
740 $this->sink
->writeCloseStream( $string );
743 function writeOpenPage( $page, $string ) {
744 $this->sendingThisPage
= $this->pass( $page, $string );
745 if( $this->sendingThisPage
) {
746 $this->sink
->writeOpenPage( $page, $string );
750 function writeClosePage( $string ) {
751 if( $this->sendingThisPage
) {
752 $this->sink
->writeClosePage( $string );
753 $this->sendingThisPage
= false;
757 function writeRevision( $rev, $string ) {
758 if( $this->sendingThisPage
) {
759 $this->sink
->writeRevision( $rev, $string );
763 function writeLogItem( $rev, $string ) {
764 $this->sink
->writeRevision( $rev, $string );
768 * Override for page-based filter types.
771 function pass( $page ) {
777 * Simple dump output filter to exclude all talk pages.
780 class DumpNotalkFilter
extends DumpFilter
{
781 function pass( $page ) {
782 return !MWNamespace
::isTalk( $page->page_namespace
);
787 * Dump output filter to include or exclude pages in a given set of namespaces.
790 class DumpNamespaceFilter
extends DumpFilter
{
792 var $namespaces = array();
794 function DumpNamespaceFilter( &$sink, $param ) {
795 parent
::DumpFilter( $sink );
798 "NS_MAIN" => NS_MAIN
,
799 "NS_TALK" => NS_TALK
,
800 "NS_USER" => NS_USER
,
801 "NS_USER_TALK" => NS_USER_TALK
,
802 "NS_PROJECT" => NS_PROJECT
,
803 "NS_PROJECT_TALK" => NS_PROJECT_TALK
,
804 "NS_FILE" => NS_FILE
,
805 "NS_FILE_TALK" => NS_FILE_TALK
,
806 "NS_IMAGE" => NS_IMAGE
, // NS_IMAGE is an alias for NS_FILE
807 "NS_IMAGE_TALK" => NS_IMAGE_TALK
,
808 "NS_MEDIAWIKI" => NS_MEDIAWIKI
,
809 "NS_MEDIAWIKI_TALK" => NS_MEDIAWIKI_TALK
,
810 "NS_TEMPLATE" => NS_TEMPLATE
,
811 "NS_TEMPLATE_TALK" => NS_TEMPLATE_TALK
,
812 "NS_HELP" => NS_HELP
,
813 "NS_HELP_TALK" => NS_HELP_TALK
,
814 "NS_CATEGORY" => NS_CATEGORY
,
815 "NS_CATEGORY_TALK" => NS_CATEGORY_TALK
);
817 if( $param{0} == '!' ) {
818 $this->invert
= true;
819 $param = substr( $param, 1 );
822 foreach( explode( ',', $param ) as $key ) {
824 if( isset( $constants[$key] ) ) {
825 $ns = $constants[$key];
826 $this->namespaces
[$ns] = true;
827 } elseif( is_numeric( $key ) ) {
828 $ns = intval( $key );
829 $this->namespaces
[$ns] = true;
831 throw new MWException( "Unrecognized namespace key '$key'\n" );
836 function pass( $page ) {
837 $match = isset( $this->namespaces
[$page->page_namespace
] );
838 return $this->invert
xor $match;
844 * Dump output filter to include only the last revision in each page sequence.
847 class DumpLatestFilter
extends DumpFilter
{
848 var $page, $pageString, $rev, $revString;
850 function writeOpenPage( $page, $string ) {
852 $this->pageString
= $string;
855 function writeClosePage( $string ) {
857 $this->sink
->writeOpenPage( $this->page
, $this->pageString
);
858 $this->sink
->writeRevision( $this->rev
, $this->revString
);
859 $this->sink
->writeClosePage( $string );
862 $this->revString
= null;
864 $this->pageString
= null;
867 function writeRevision( $rev, $string ) {
868 if( $rev->rev_id
== $this->page
->page_latest
) {
870 $this->revString
= $string;
876 * Base class for output stream; prints to stdout or buffer or whereever.
879 class DumpMultiWriter
{
880 function DumpMultiWriter( $sinks ) {
881 $this->sinks
= $sinks;
882 $this->count
= count( $sinks );
885 function writeOpenStream( $string ) {
886 for( $i = 0; $i < $this->count
; $i++
) {
887 $this->sinks
[$i]->writeOpenStream( $string );
891 function writeCloseStream( $string ) {
892 for( $i = 0; $i < $this->count
; $i++
) {
893 $this->sinks
[$i]->writeCloseStream( $string );
897 function writeOpenPage( $page, $string ) {
898 for( $i = 0; $i < $this->count
; $i++
) {
899 $this->sinks
[$i]->writeOpenPage( $page, $string );
903 function writeClosePage( $string ) {
904 for( $i = 0; $i < $this->count
; $i++
) {
905 $this->sinks
[$i]->writeClosePage( $string );
909 function writeRevision( $rev, $string ) {
910 for( $i = 0; $i < $this->count
; $i++
) {
911 $this->sinks
[$i]->writeRevision( $rev, $string );
916 function xmlsafe( $string ) {
918 wfProfileIn( $fname );
921 * The page may contain old data which has not been properly normalized.
922 * Invalid UTF-8 sequences or forbidden control characters will make our
923 * XML output invalid, so be sure to strip them out.
925 $string = UtfNormal
::cleanUp( $string );
927 $string = htmlspecialchars( $string );
928 wfProfileOut( $fname );