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 ) {
418 Xml
::element( 'namespace',
420 'case' => MWNamespace
::isCapitalized( $ns ) ?
'first-letter' : 'case-sensitive',
423 $spaces .= " </namespaces>";
428 * Closes the output stream with the closing root element.
429 * Call when finished dumping things.
431 function closeStream() {
432 return "</mediawiki>\n";
437 * Opens a <page> section on the output stream, with data
438 * from the given database row.
444 function openPage( $row ) {
446 $title = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
447 $out .= ' ' . Xml
::elementClean( 'title', array(), $title->getPrefixedText() ) . "\n";
448 $out .= ' ' . Xml
::element( 'id', array(), strval( $row->page_id
) ) . "\n";
449 if( $row->page_is_redirect
) {
450 $out .= ' ' . Xml
::element( 'redirect', array() ) . "\n";
452 if( '' != $row->page_restrictions
) {
453 $out .= ' ' . Xml
::element( 'restrictions', array(),
454 strval( $row->page_restrictions
) ) . "\n";
457 wfRunHooks( 'XmlDumpWriterOpenPage', array( $this, &$out, $row, $title ) );
463 * Closes a <page> section on the output stream.
467 function closePage() {
472 * Dumps a <revision> section on the output stream, with
473 * data filled in from the given database row.
479 function writeRevision( $row ) {
480 $fname = 'WikiExporter::dumpRev';
481 wfProfileIn( $fname );
483 $out = " <revision>\n";
484 $out .= " " . Xml
::element( 'id', null, strval( $row->rev_id
) ) . "\n";
486 $out .= $this->writeTimestamp( $row->rev_timestamp
);
488 if( $row->rev_deleted
& Revision
::DELETED_USER
) {
489 $out .= " " . Xml
::element( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
491 $out .= $this->writeContributor( $row->rev_user
, $row->rev_user_text
);
494 if( $row->rev_minor_edit
) {
495 $out .= " <minor/>\n";
497 if( $row->rev_deleted
& Revision
::DELETED_COMMENT
) {
498 $out .= " " . Xml
::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
499 } elseif( $row->rev_comment
!= '' ) {
500 $out .= " " . Xml
::elementClean( 'comment', null, strval( $row->rev_comment
) ) . "\n";
503 if( $row->rev_deleted
& Revision
::DELETED_TEXT
) {
504 $out .= " " . Xml
::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
505 } elseif( isset( $row->old_text
) ) {
506 // Raw text from the database may have invalid chars
507 $text = strval( Revision
::getRevisionText( $row ) );
508 $out .= " " . Xml
::elementClean( 'text',
509 array( 'xml:space' => 'preserve' ),
510 strval( $text ) ) . "\n";
513 $out .= " " . Xml
::element( 'text',
514 array( 'id' => $row->rev_text_id
),
518 wfRunHooks( 'XmlDumpWriterWriteRevision', array( &$this, &$out, $row, $text ) );
520 $out .= " </revision>\n";
522 wfProfileOut( $fname );
527 * Dumps a <logitem> section on the output stream, with
528 * data filled in from the given database row.
534 function writeLogItem( $row ) {
535 $fname = 'WikiExporter::writeLogItem';
536 wfProfileIn( $fname );
538 $out = " <logitem>\n";
539 $out .= " " . Xml
::element( 'id', null, strval( $row->log_id
) ) . "\n";
541 $out .= $this->writeTimestamp( $row->log_timestamp
);
543 if( $row->log_deleted
& LogPage
::DELETED_USER
) {
544 $out .= " " . Xml
::element( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
546 $out .= $this->writeContributor( $row->log_user
, $row->user_name
);
549 if( $row->log_deleted
& LogPage
::DELETED_COMMENT
) {
550 $out .= " " . Xml
::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
551 } elseif( $row->log_comment
!= '' ) {
552 $out .= " " . Xml
::elementClean( 'comment', null, strval( $row->log_comment
) ) . "\n";
555 $out .= " " . Xml
::element( 'type', null, strval( $row->log_type
) ) . "\n";
556 $out .= " " . Xml
::element( 'action', null, strval( $row->log_action
) ) . "\n";
558 if( $row->log_deleted
& LogPage
::DELETED_ACTION
) {
559 $out .= " " . Xml
::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
561 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
562 $out .= " " . Xml
::elementClean( 'logtitle', null, $title->getPrefixedText() ) . "\n";
563 $out .= " " . Xml
::elementClean( 'params',
564 array( 'xml:space' => 'preserve' ),
565 strval( $row->log_params
) ) . "\n";
568 $out .= " </logitem>\n";
570 wfProfileOut( $fname );
574 function writeTimestamp( $timestamp ) {
575 $ts = wfTimestamp( TS_ISO_8601
, $timestamp );
576 return " " . Xml
::element( 'timestamp', null, $ts ) . "\n";
579 function writeContributor( $id, $text ) {
580 $out = " <contributor>\n";
582 $out .= " " . Xml
::elementClean( 'username', null, strval( $text ) ) . "\n";
583 $out .= " " . Xml
::element( 'id', null, strval( $id ) ) . "\n";
585 $out .= " " . Xml
::elementClean( 'ip', null, strval( $text ) ) . "\n";
587 $out .= " </contributor>\n";
592 * Warning! This data is potentially inconsistent. :(
594 function writeUploads( $row ) {
595 if( $row->page_namespace
== NS_IMAGE
) {
596 $img = wfFindFile( $row->page_title
);
599 foreach( array_reverse( $img->getHistory() ) as $ver ) {
600 $out .= $this->writeUpload( $ver );
602 $out .= $this->writeUpload( $img );
609 function writeUpload( $file ) {
610 return " <upload>\n" .
611 $this->writeTimestamp( $file->getTimestamp() ) .
612 $this->writeContributor( $file->getUser( 'id' ), $file->getUser( 'text' ) ) .
613 " " . Xml
::elementClean( 'comment', null, $file->getDescription() ) . "\n" .
614 " " . Xml
::element( 'filename', null, $file->getName() ) . "\n" .
615 " " . Xml
::element( 'src', null, $file->getFullUrl() ) . "\n" .
616 " " . Xml
::element( 'size', null, $file->getSize() ) . "\n" .
624 * Base class for output stream; prints to stdout or buffer or whereever.
628 function writeOpenStream( $string ) {
629 $this->write( $string );
632 function writeCloseStream( $string ) {
633 $this->write( $string );
636 function writeOpenPage( $page, $string ) {
637 $this->write( $string );
640 function writeClosePage( $string ) {
641 $this->write( $string );
644 function writeRevision( $rev, $string ) {
645 $this->write( $string );
648 function writeLogItem( $rev, $string ) {
649 $this->write( $string );
653 * Override to write to a different stream type.
656 function write( $string ) {
662 * Stream outputter to send data to a file.
665 class DumpFileOutput
extends DumpOutput
{
668 function DumpFileOutput( $file ) {
669 $this->handle
= fopen( $file, "wt" );
672 function write( $string ) {
673 fputs( $this->handle
, $string );
678 * Stream outputter to send data to a file via some filter program.
679 * Even if compression is available in a library, using a separate
680 * program can allow us to make use of a multi-processor system.
683 class DumpPipeOutput
extends DumpFileOutput
{
684 function DumpPipeOutput( $command, $file = null ) {
685 if( !is_null( $file ) ) {
686 $command .= " > " . wfEscapeShellArg( $file );
688 $this->handle
= popen( $command, "w" );
693 * Sends dump output via the gzip compressor.
696 class DumpGZipOutput
extends DumpPipeOutput
{
697 function DumpGZipOutput( $file ) {
698 parent
::DumpPipeOutput( "gzip", $file );
703 * Sends dump output via the bgzip2 compressor.
706 class DumpBZip2Output
extends DumpPipeOutput
{
707 function DumpBZip2Output( $file ) {
708 parent
::DumpPipeOutput( "bzip2", $file );
713 * Sends dump output via the p7zip compressor.
716 class Dump7ZipOutput
extends DumpPipeOutput
{
717 function Dump7ZipOutput( $file ) {
718 $command = "7za a -bd -si " . wfEscapeShellArg( $file );
719 // Suppress annoying useless crap from p7zip
720 // Unfortunately this could suppress real error messages too
721 $command .= ' >' . wfGetNull() . ' 2>&1';
722 parent
::DumpPipeOutput( $command );
729 * Dump output filter class.
730 * This just does output filtering and streaming; XML formatting is done
731 * higher up, so be careful in what you do.
735 function DumpFilter( &$sink ) {
736 $this->sink
=& $sink;
739 function writeOpenStream( $string ) {
740 $this->sink
->writeOpenStream( $string );
743 function writeCloseStream( $string ) {
744 $this->sink
->writeCloseStream( $string );
747 function writeOpenPage( $page, $string ) {
748 $this->sendingThisPage
= $this->pass( $page, $string );
749 if( $this->sendingThisPage
) {
750 $this->sink
->writeOpenPage( $page, $string );
754 function writeClosePage( $string ) {
755 if( $this->sendingThisPage
) {
756 $this->sink
->writeClosePage( $string );
757 $this->sendingThisPage
= false;
761 function writeRevision( $rev, $string ) {
762 if( $this->sendingThisPage
) {
763 $this->sink
->writeRevision( $rev, $string );
767 function writeLogItem( $rev, $string ) {
768 $this->sink
->writeRevision( $rev, $string );
772 * Override for page-based filter types.
775 function pass( $page ) {
781 * Simple dump output filter to exclude all talk pages.
784 class DumpNotalkFilter
extends DumpFilter
{
785 function pass( $page ) {
786 return !MWNamespace
::isTalk( $page->page_namespace
);
791 * Dump output filter to include or exclude pages in a given set of namespaces.
794 class DumpNamespaceFilter
extends DumpFilter
{
796 var $namespaces = array();
798 function DumpNamespaceFilter( &$sink, $param ) {
799 parent
::DumpFilter( $sink );
802 "NS_MAIN" => NS_MAIN
,
803 "NS_TALK" => NS_TALK
,
804 "NS_USER" => NS_USER
,
805 "NS_USER_TALK" => NS_USER_TALK
,
806 "NS_PROJECT" => NS_PROJECT
,
807 "NS_PROJECT_TALK" => NS_PROJECT_TALK
,
808 "NS_FILE" => NS_FILE
,
809 "NS_FILE_TALK" => NS_FILE_TALK
,
810 "NS_IMAGE" => NS_IMAGE
, // NS_IMAGE is an alias for NS_FILE
811 "NS_IMAGE_TALK" => NS_IMAGE_TALK
,
812 "NS_MEDIAWIKI" => NS_MEDIAWIKI
,
813 "NS_MEDIAWIKI_TALK" => NS_MEDIAWIKI_TALK
,
814 "NS_TEMPLATE" => NS_TEMPLATE
,
815 "NS_TEMPLATE_TALK" => NS_TEMPLATE_TALK
,
816 "NS_HELP" => NS_HELP
,
817 "NS_HELP_TALK" => NS_HELP_TALK
,
818 "NS_CATEGORY" => NS_CATEGORY
,
819 "NS_CATEGORY_TALK" => NS_CATEGORY_TALK
);
821 if( $param{0} == '!' ) {
822 $this->invert
= true;
823 $param = substr( $param, 1 );
826 foreach( explode( ',', $param ) as $key ) {
828 if( isset( $constants[$key] ) ) {
829 $ns = $constants[$key];
830 $this->namespaces
[$ns] = true;
831 } elseif( is_numeric( $key ) ) {
832 $ns = intval( $key );
833 $this->namespaces
[$ns] = true;
835 throw new MWException( "Unrecognized namespace key '$key'\n" );
840 function pass( $page ) {
841 $match = isset( $this->namespaces
[$page->page_namespace
] );
842 return $this->invert
xor $match;
848 * Dump output filter to include only the last revision in each page sequence.
851 class DumpLatestFilter
extends DumpFilter
{
852 var $page, $pageString, $rev, $revString;
854 function writeOpenPage( $page, $string ) {
856 $this->pageString
= $string;
859 function writeClosePage( $string ) {
861 $this->sink
->writeOpenPage( $this->page
, $this->pageString
);
862 $this->sink
->writeRevision( $this->rev
, $this->revString
);
863 $this->sink
->writeClosePage( $string );
866 $this->revString
= null;
868 $this->pageString
= null;
871 function writeRevision( $rev, $string ) {
872 if( $rev->rev_id
== $this->page
->page_latest
) {
874 $this->revString
= $string;
880 * Base class for output stream; prints to stdout or buffer or whereever.
883 class DumpMultiWriter
{
884 function DumpMultiWriter( $sinks ) {
885 $this->sinks
= $sinks;
886 $this->count
= count( $sinks );
889 function writeOpenStream( $string ) {
890 for( $i = 0; $i < $this->count
; $i++
) {
891 $this->sinks
[$i]->writeOpenStream( $string );
895 function writeCloseStream( $string ) {
896 for( $i = 0; $i < $this->count
; $i++
) {
897 $this->sinks
[$i]->writeCloseStream( $string );
901 function writeOpenPage( $page, $string ) {
902 for( $i = 0; $i < $this->count
; $i++
) {
903 $this->sinks
[$i]->writeOpenPage( $page, $string );
907 function writeClosePage( $string ) {
908 for( $i = 0; $i < $this->count
; $i++
) {
909 $this->sinks
[$i]->writeClosePage( $string );
913 function writeRevision( $rev, $string ) {
914 for( $i = 0; $i < $this->count
; $i++
) {
915 $this->sinks
[$i]->writeRevision( $rev, $string );
920 function xmlsafe( $string ) {
922 wfProfileIn( $fname );
925 * The page may contain old data which has not been properly normalized.
926 * Invalid UTF-8 sequences or forbidden control characters will make our
927 * XML output invalid, so be sure to strip them out.
929 $string = UtfNormal
::cleanUp( $string );
931 $string = htmlspecialchars( $string );
932 wfProfileOut( $fname );