* $wgAjaxSearch has been removed; use $wgEnableMWSuggest instead.
[lhc/web/wiklou.git] / includes / Export.php
1 <?php
2 # Copyright (C) 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
3 # http://www.mediawiki.org/
4 #
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.
9 #
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.
14 #
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
19
20 /**
21 * @defgroup Dump Dump
22 */
23
24 /**
25 * @ingroup SpecialPage Dump
26 */
27 class WikiExporter {
28 var $list_authors = false ; # Return distinct author list (when not returning full history)
29 var $author_list = "" ;
30
31 var $dumpUploads = false;
32
33 const FULL = 0;
34 const CURRENT = 1;
35
36 const BUFFER = 0;
37 const STREAM = 1;
38
39 const TEXT = 0;
40 const STUB = 1;
41
42 /**
43 * If using WikiExporter::STREAM to stream a large amount of data,
44 * provide a database connection which is not managed by
45 * LoadBalancer to read from: some history blob types will
46 * make additional queries to pull source data while the
47 * main query is still running.
48 *
49 * @param $db Database
50 * @param $history Mixed: one of WikiExporter::FULL or WikiExporter::CURRENT,
51 * or an associative array:
52 * offset: non-inclusive offset at which to start the query
53 * limit: maximum number of rows to return
54 * dir: "asc" or "desc" timestamp order
55 * @param $buffer Int: one of WikiExporter::BUFFER or WikiExporter::STREAM
56 */
57 function __construct( &$db, $history = WikiExporter::CURRENT,
58 $buffer = WikiExporter::BUFFER, $text = WikiExporter::TEXT ) {
59 $this->db =& $db;
60 $this->history = $history;
61 $this->buffer = $buffer;
62 $this->writer = new XmlDumpWriter();
63 $this->sink = new DumpOutput();
64 $this->text = $text;
65 }
66
67 /**
68 * Set the DumpOutput or DumpFilter object which will receive
69 * various row objects and XML output for filtering. Filters
70 * can be chained or used as callbacks.
71 *
72 * @param $sink mixed
73 */
74 function setOutputSink( &$sink ) {
75 $this->sink =& $sink;
76 }
77
78 function openStream() {
79 $output = $this->writer->openStream();
80 $this->sink->writeOpenStream( $output );
81 }
82
83 function closeStream() {
84 $output = $this->writer->closeStream();
85 $this->sink->writeCloseStream( $output );
86 }
87
88 /**
89 * Dumps a series of page and revision records for all pages
90 * in the database, either including complete history or only
91 * the most recent version.
92 */
93 function allPages() {
94 return $this->dumpFrom( '' );
95 }
96
97 /**
98 * Dumps a series of page and revision records for those pages
99 * in the database falling within the page_id range given.
100 * @param $start Int: inclusive lower limit (this id is included)
101 * @param $end Int: Exclusive upper limit (this id is not included)
102 * If 0, no upper limit.
103 */
104 function pagesByRange( $start, $end ) {
105 $condition = 'page_id >= ' . intval( $start );
106 if( $end ) {
107 $condition .= ' AND page_id < ' . intval( $end );
108 }
109 return $this->dumpFrom( $condition );
110 }
111
112 /**
113 * @param $title Title
114 */
115 function pageByTitle( $title ) {
116 return $this->dumpFrom(
117 'page_namespace=' . $title->getNamespace() .
118 ' AND page_title=' . $this->db->addQuotes( $title->getDBkey() ) );
119 }
120
121 function pageByName( $name ) {
122 $title = Title::newFromText( $name );
123 if( is_null( $title ) ) {
124 return new WikiError( "Can't export invalid title" );
125 } else {
126 return $this->pageByTitle( $title );
127 }
128 }
129
130 function pagesByName( $names ) {
131 foreach( $names as $name ) {
132 $this->pageByName( $name );
133 }
134 }
135
136
137 // -------------------- private implementation below --------------------
138
139 # Generates the distinct list of authors of an article
140 # Not called by default (depends on $this->list_authors)
141 # Can be set by Special:Export when not exporting whole history
142 function do_list_authors ( $page , $revision , $cond ) {
143 $fname = "do_list_authors" ;
144 wfProfileIn( $fname );
145 $this->author_list = "<contributors>";
146 //rev_deleted
147 $nothidden = '(rev_deleted & '.Revision::DELETED_USER.') = 0';
148
149 $sql = "SELECT DISTINCT rev_user_text,rev_user FROM {$page},{$revision} WHERE page_id=rev_page AND $nothidden AND " . $cond ;
150 $result = $this->db->query( $sql, $fname );
151 $resultset = $this->db->resultObject( $result );
152 while( $row = $resultset->fetchObject() ) {
153 $this->author_list .= "<contributor>" .
154 "<username>" .
155 htmlentities( $row->rev_user_text ) .
156 "</username>" .
157 "<id>" .
158 $row->rev_user .
159 "</id>" .
160 "</contributor>";
161 }
162 wfProfileOut( $fname );
163 $this->author_list .= "</contributors>";
164 }
165
166 function dumpFrom( $cond = '' ) {
167 $fname = 'WikiExporter::dumpFrom';
168 wfProfileIn( $fname );
169
170 $page = $this->db->tableName( 'page' );
171 $revision = $this->db->tableName( 'revision' );
172 $text = $this->db->tableName( 'text' );
173
174 $order = 'ORDER BY page_id';
175 $limit = '';
176
177 if( $this->history == WikiExporter::FULL ) {
178 $join = 'page_id=rev_page';
179 } elseif( $this->history == WikiExporter::CURRENT ) {
180 if ( $this->list_authors && $cond != '' ) { // List authors, if so desired
181 $this->do_list_authors ( $page , $revision , $cond );
182 }
183 $join = 'page_id=rev_page AND page_latest=rev_id';
184 } elseif ( is_array( $this->history ) ) {
185 $join = 'page_id=rev_page';
186 if ( $this->history['dir'] == 'asc' ) {
187 $op = '>';
188 $order .= ', rev_timestamp';
189 } else {
190 $op = '<';
191 $order .= ', rev_timestamp DESC';
192 }
193 if ( !empty( $this->history['offset'] ) ) {
194 $join .= " AND rev_timestamp $op " . $this->db->addQuotes(
195 $this->db->timestamp( $this->history['offset'] ) );
196 }
197 if ( !empty( $this->history['limit'] ) ) {
198 $limitNum = intval( $this->history['limit'] );
199 if ( $limitNum > 0 ) {
200 $limit = "LIMIT $limitNum";
201 }
202 }
203 } else {
204 wfProfileOut( $fname );
205 return new WikiError( "$fname given invalid history dump type." );
206 }
207 $where = ( $cond == '' ) ? '' : "$cond AND";
208
209 if( $this->buffer == WikiExporter::STREAM ) {
210 $prev = $this->db->bufferResults( false );
211 }
212 if( $cond == '' ) {
213 // Optimization hack for full-database dump
214 $revindex = $pageindex = $this->db->useIndexClause("PRIMARY");
215 $straight = ' /*! STRAIGHT_JOIN */ ';
216 } else {
217 $pageindex = '';
218 $revindex = '';
219 $straight = '';
220 }
221 if( $this->text == WikiExporter::STUB ) {
222 $sql = "SELECT $straight * FROM
223 $page $pageindex,
224 $revision $revindex
225 WHERE $where $join
226 $order $limit";
227 } else {
228 $sql = "SELECT $straight * FROM
229 $page $pageindex,
230 $revision $revindex,
231 $text
232 WHERE $where $join AND rev_text_id=old_id
233 $order $limit";
234 }
235 $result = $this->db->query( $sql, $fname );
236 $wrapper = $this->db->resultObject( $result );
237 $this->outputStream( $wrapper );
238
239 if ( $this->list_authors ) {
240 $this->outputStream( $wrapper );
241 }
242
243 if( $this->buffer == WikiExporter::STREAM ) {
244 $this->db->bufferResults( $prev );
245 }
246
247 wfProfileOut( $fname );
248 }
249
250 /**
251 * Runs through a query result set dumping page and revision records.
252 * The result set should be sorted/grouped by page to avoid duplicate
253 * page records in the output.
254 *
255 * The result set will be freed once complete. Should be safe for
256 * streaming (non-buffered) queries, as long as it was made on a
257 * separate database connection not managed by LoadBalancer; some
258 * blob storage types will make queries to pull source data.
259 *
260 * @param $resultset ResultWrapper
261 * @access private
262 */
263 function outputStream( $resultset ) {
264 $last = null;
265 while( $row = $resultset->fetchObject() ) {
266 if( is_null( $last ) ||
267 $last->page_namespace != $row->page_namespace ||
268 $last->page_title != $row->page_title ) {
269 if( isset( $last ) ) {
270 $output = '';
271 if( $this->dumpUploads ) {
272 $output .= $this->writer->writeUploads( $last );
273 }
274 $output .= $this->writer->closePage();
275 $this->sink->writeClosePage( $output );
276 }
277 $output = $this->writer->openPage( $row );
278 $this->sink->writeOpenPage( $row, $output );
279 $last = $row;
280 }
281 $output = $this->writer->writeRevision( $row );
282 $this->sink->writeRevision( $row, $output );
283 }
284 if( isset( $last ) ) {
285 $output = '';
286 if( $this->dumpUploads ) {
287 $output .= $this->writer->writeUploads( $last );
288 }
289 $output .= $this->author_list;
290 $output .= $this->writer->closePage();
291 $this->sink->writeClosePage( $output );
292 }
293 $resultset->free();
294 }
295 }
296
297 /**
298 * @ingroup Dump
299 */
300 class XmlDumpWriter {
301
302 /**
303 * Returns the export schema version.
304 * @return string
305 */
306 function schemaVersion() {
307 return "0.3"; // FIXME: upgrade to 0.4 when updated XSD is ready, for the revision deletion bits
308 }
309
310 /**
311 * Opens the XML output stream's root <mediawiki> element.
312 * This does not include an xml directive, so is safe to include
313 * as a subelement in a larger XML stream. Namespace and XML Schema
314 * references are included.
315 *
316 * Output will be encoded in UTF-8.
317 *
318 * @return string
319 */
320 function openStream() {
321 global $wgContLanguageCode;
322 $ver = $this->schemaVersion();
323 return wfElement( 'mediawiki', array(
324 'xmlns' => "http://www.mediawiki.org/xml/export-$ver/",
325 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
326 'xsi:schemaLocation' => "http://www.mediawiki.org/xml/export-$ver/ " .
327 "http://www.mediawiki.org/xml/export-$ver.xsd",
328 'version' => $ver,
329 'xml:lang' => $wgContLanguageCode ),
330 null ) .
331 "\n" .
332 $this->siteInfo();
333 }
334
335 function siteInfo() {
336 $info = array(
337 $this->sitename(),
338 $this->homelink(),
339 $this->generator(),
340 $this->caseSetting(),
341 $this->namespaces() );
342 return " <siteinfo>\n " .
343 implode( "\n ", $info ) .
344 "\n </siteinfo>\n";
345 }
346
347 function sitename() {
348 global $wgSitename;
349 return wfElement( 'sitename', array(), $wgSitename );
350 }
351
352 function generator() {
353 global $wgVersion;
354 return wfElement( 'generator', array(), "MediaWiki $wgVersion" );
355 }
356
357 function homelink() {
358 return wfElement( 'base', array(), Title::newMainPage()->getFullUrl() );
359 }
360
361 function caseSetting() {
362 global $wgCapitalLinks;
363 // "case-insensitive" option is reserved for future
364 $sensitivity = $wgCapitalLinks ? 'first-letter' : 'case-sensitive';
365 return wfElement( 'case', array(), $sensitivity );
366 }
367
368 function namespaces() {
369 global $wgContLang;
370 $spaces = " <namespaces>\n";
371 foreach( $wgContLang->getFormattedNamespaces() as $ns => $title ) {
372 $spaces .= ' ' . wfElement( 'namespace', array( 'key' => $ns ), $title ) . "\n";
373 }
374 $spaces .= " </namespaces>";
375 return $spaces;
376 }
377
378 /**
379 * Closes the output stream with the closing root element.
380 * Call when finished dumping things.
381 */
382 function closeStream() {
383 return "</mediawiki>\n";
384 }
385
386
387 /**
388 * Opens a <page> section on the output stream, with data
389 * from the given database row.
390 *
391 * @param $row object
392 * @return string
393 * @access private
394 */
395 function openPage( $row ) {
396 $out = " <page>\n";
397 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
398 $out .= ' ' . wfElementClean( 'title', array(), $title->getPrefixedText() ) . "\n";
399 $out .= ' ' . wfElement( 'id', array(), strval( $row->page_id ) ) . "\n";
400 if( '' != $row->page_restrictions ) {
401 $out .= ' ' . wfElement( 'restrictions', array(),
402 strval( $row->page_restrictions ) ) . "\n";
403 }
404 return $out;
405 }
406
407 /**
408 * Closes a <page> section on the output stream.
409 *
410 * @access private
411 */
412 function closePage() {
413 return " </page>\n";
414 }
415
416 /**
417 * Dumps a <revision> section on the output stream, with
418 * data filled in from the given database row.
419 *
420 * @param $row object
421 * @return string
422 * @access private
423 */
424 function writeRevision( $row ) {
425 $fname = 'WikiExporter::dumpRev';
426 wfProfileIn( $fname );
427
428 $out = " <revision>\n";
429 $out .= " " . wfElement( 'id', null, strval( $row->rev_id ) ) . "\n";
430
431 $out .= $this->writeTimestamp( $row->rev_timestamp );
432
433 if( $row->rev_deleted & Revision::DELETED_USER ) {
434 $out .= " " . wfElement( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
435 } else {
436 $out .= $this->writeContributor( $row->rev_user, $row->rev_user_text );
437 }
438
439 if( $row->rev_minor_edit ) {
440 $out .= " <minor/>\n";
441 }
442 if( $row->rev_deleted & Revision::DELETED_COMMENT ) {
443 $out .= " " . wfElement( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
444 } elseif( $row->rev_comment != '' ) {
445 $out .= " " . wfElementClean( 'comment', null, strval( $row->rev_comment ) ) . "\n";
446 }
447
448 if( $row->rev_deleted & Revision::DELETED_TEXT ) {
449 $out .= " " . wfElement( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
450 } elseif( isset( $row->old_text ) ) {
451 // Raw text from the database may have invalid chars
452 $text = strval( Revision::getRevisionText( $row ) );
453 $out .= " " . wfElementClean( 'text',
454 array( 'xml:space' => 'preserve' ),
455 strval( $text ) ) . "\n";
456 } else {
457 // Stub output
458 $out .= " " . wfElement( 'text',
459 array( 'id' => $row->rev_text_id ),
460 "" ) . "\n";
461 }
462
463 $out .= " </revision>\n";
464
465 wfProfileOut( $fname );
466 return $out;
467 }
468
469 function writeTimestamp( $timestamp ) {
470 $ts = wfTimestamp( TS_ISO_8601, $timestamp );
471 return " " . wfElement( 'timestamp', null, $ts ) . "\n";
472 }
473
474 function writeContributor( $id, $text ) {
475 $out = " <contributor>\n";
476 if( $id ) {
477 $out .= " " . wfElementClean( 'username', null, strval( $text ) ) . "\n";
478 $out .= " " . wfElement( 'id', null, strval( $id ) ) . "\n";
479 } else {
480 $out .= " " . wfElementClean( 'ip', null, strval( $text ) ) . "\n";
481 }
482 $out .= " </contributor>\n";
483 return $out;
484 }
485
486 /**
487 * Warning! This data is potentially inconsistent. :(
488 */
489 function writeUploads( $row ) {
490 if( $row->page_namespace == NS_IMAGE ) {
491 $img = wfFindFile( $row->page_title );
492 if( $img ) {
493 $out = '';
494 foreach( array_reverse( $img->getHistory() ) as $ver ) {
495 $out .= $this->writeUpload( $ver );
496 }
497 $out .= $this->writeUpload( $img );
498 return $out;
499 }
500 }
501 return '';
502 }
503
504 function writeUpload( $file ) {
505 return " <upload>\n" .
506 $this->writeTimestamp( $file->getTimestamp() ) .
507 $this->writeContributor( $file->getUser( 'id' ), $file->getUser( 'text' ) ) .
508 " " . wfElementClean( 'comment', null, $file->getDescription() ) . "\n" .
509 " " . wfElement( 'filename', null, $file->getName() ) . "\n" .
510 " " . wfElement( 'src', null, $file->getFullUrl() ) . "\n" .
511 " " . wfElement( 'size', null, $file->getSize() ) . "\n" .
512 " </upload>\n";
513 }
514
515 }
516
517
518 /**
519 * Base class for output stream; prints to stdout or buffer or whereever.
520 * @ingroup Dump
521 */
522 class DumpOutput {
523 function writeOpenStream( $string ) {
524 $this->write( $string );
525 }
526
527 function writeCloseStream( $string ) {
528 $this->write( $string );
529 }
530
531 function writeOpenPage( $page, $string ) {
532 $this->write( $string );
533 }
534
535 function writeClosePage( $string ) {
536 $this->write( $string );
537 }
538
539 function writeRevision( $rev, $string ) {
540 $this->write( $string );
541 }
542
543 /**
544 * Override to write to a different stream type.
545 * @return bool
546 */
547 function write( $string ) {
548 print $string;
549 }
550 }
551
552 /**
553 * Stream outputter to send data to a file.
554 * @ingroup Dump
555 */
556 class DumpFileOutput extends DumpOutput {
557 var $handle;
558
559 function DumpFileOutput( $file ) {
560 $this->handle = fopen( $file, "wt" );
561 }
562
563 function write( $string ) {
564 fputs( $this->handle, $string );
565 }
566 }
567
568 /**
569 * Stream outputter to send data to a file via some filter program.
570 * Even if compression is available in a library, using a separate
571 * program can allow us to make use of a multi-processor system.
572 * @ingroup Dump
573 */
574 class DumpPipeOutput extends DumpFileOutput {
575 function DumpPipeOutput( $command, $file = null ) {
576 if( !is_null( $file ) ) {
577 $command .= " > " . wfEscapeShellArg( $file );
578 }
579 $this->handle = popen( $command, "w" );
580 }
581 }
582
583 /**
584 * Sends dump output via the gzip compressor.
585 * @ingroup Dump
586 */
587 class DumpGZipOutput extends DumpPipeOutput {
588 function DumpGZipOutput( $file ) {
589 parent::DumpPipeOutput( "gzip", $file );
590 }
591 }
592
593 /**
594 * Sends dump output via the bgzip2 compressor.
595 * @ingroup Dump
596 */
597 class DumpBZip2Output extends DumpPipeOutput {
598 function DumpBZip2Output( $file ) {
599 parent::DumpPipeOutput( "bzip2", $file );
600 }
601 }
602
603 /**
604 * Sends dump output via the p7zip compressor.
605 * @ingroup Dump
606 */
607 class Dump7ZipOutput extends DumpPipeOutput {
608 function Dump7ZipOutput( $file ) {
609 $command = "7za a -bd -si " . wfEscapeShellArg( $file );
610 // Suppress annoying useless crap from p7zip
611 // Unfortunately this could suppress real error messages too
612 $command .= ' >' . wfGetNull() . ' 2>&1';
613 parent::DumpPipeOutput( $command );
614 }
615 }
616
617
618
619 /**
620 * Dump output filter class.
621 * This just does output filtering and streaming; XML formatting is done
622 * higher up, so be careful in what you do.
623 * @ingroup Dump
624 */
625 class DumpFilter {
626 function DumpFilter( &$sink ) {
627 $this->sink =& $sink;
628 }
629
630 function writeOpenStream( $string ) {
631 $this->sink->writeOpenStream( $string );
632 }
633
634 function writeCloseStream( $string ) {
635 $this->sink->writeCloseStream( $string );
636 }
637
638 function writeOpenPage( $page, $string ) {
639 $this->sendingThisPage = $this->pass( $page, $string );
640 if( $this->sendingThisPage ) {
641 $this->sink->writeOpenPage( $page, $string );
642 }
643 }
644
645 function writeClosePage( $string ) {
646 if( $this->sendingThisPage ) {
647 $this->sink->writeClosePage( $string );
648 $this->sendingThisPage = false;
649 }
650 }
651
652 function writeRevision( $rev, $string ) {
653 if( $this->sendingThisPage ) {
654 $this->sink->writeRevision( $rev, $string );
655 }
656 }
657
658 /**
659 * Override for page-based filter types.
660 * @return bool
661 */
662 function pass( $page ) {
663 return true;
664 }
665 }
666
667 /**
668 * Simple dump output filter to exclude all talk pages.
669 * @ingroup Dump
670 */
671 class DumpNotalkFilter extends DumpFilter {
672 function pass( $page ) {
673 return !MWNamespace::isTalk( $page->page_namespace );
674 }
675 }
676
677 /**
678 * Dump output filter to include or exclude pages in a given set of namespaces.
679 * @ingroup Dump
680 */
681 class DumpNamespaceFilter extends DumpFilter {
682 var $invert = false;
683 var $namespaces = array();
684
685 function DumpNamespaceFilter( &$sink, $param ) {
686 parent::DumpFilter( $sink );
687
688 $constants = array(
689 "NS_MAIN" => NS_MAIN,
690 "NS_TALK" => NS_TALK,
691 "NS_USER" => NS_USER,
692 "NS_USER_TALK" => NS_USER_TALK,
693 "NS_PROJECT" => NS_PROJECT,
694 "NS_PROJECT_TALK" => NS_PROJECT_TALK,
695 "NS_IMAGE" => NS_IMAGE,
696 "NS_IMAGE_TALK" => NS_IMAGE_TALK,
697 "NS_MEDIAWIKI" => NS_MEDIAWIKI,
698 "NS_MEDIAWIKI_TALK" => NS_MEDIAWIKI_TALK,
699 "NS_TEMPLATE" => NS_TEMPLATE,
700 "NS_TEMPLATE_TALK" => NS_TEMPLATE_TALK,
701 "NS_HELP" => NS_HELP,
702 "NS_HELP_TALK" => NS_HELP_TALK,
703 "NS_CATEGORY" => NS_CATEGORY,
704 "NS_CATEGORY_TALK" => NS_CATEGORY_TALK );
705
706 if( $param{0} == '!' ) {
707 $this->invert = true;
708 $param = substr( $param, 1 );
709 }
710
711 foreach( explode( ',', $param ) as $key ) {
712 $key = trim( $key );
713 if( isset( $constants[$key] ) ) {
714 $ns = $constants[$key];
715 $this->namespaces[$ns] = true;
716 } elseif( is_numeric( $key ) ) {
717 $ns = intval( $key );
718 $this->namespaces[$ns] = true;
719 } else {
720 throw new MWException( "Unrecognized namespace key '$key'\n" );
721 }
722 }
723 }
724
725 function pass( $page ) {
726 $match = isset( $this->namespaces[$page->page_namespace] );
727 return $this->invert xor $match;
728 }
729 }
730
731
732 /**
733 * Dump output filter to include only the last revision in each page sequence.
734 * @ingroup Dump
735 */
736 class DumpLatestFilter extends DumpFilter {
737 var $page, $pageString, $rev, $revString;
738
739 function writeOpenPage( $page, $string ) {
740 $this->page = $page;
741 $this->pageString = $string;
742 }
743
744 function writeClosePage( $string ) {
745 if( $this->rev ) {
746 $this->sink->writeOpenPage( $this->page, $this->pageString );
747 $this->sink->writeRevision( $this->rev, $this->revString );
748 $this->sink->writeClosePage( $string );
749 }
750 $this->rev = null;
751 $this->revString = null;
752 $this->page = null;
753 $this->pageString = null;
754 }
755
756 function writeRevision( $rev, $string ) {
757 if( $rev->rev_id == $this->page->page_latest ) {
758 $this->rev = $rev;
759 $this->revString = $string;
760 }
761 }
762 }
763
764 /**
765 * Base class for output stream; prints to stdout or buffer or whereever.
766 * @ingroup Dump
767 */
768 class DumpMultiWriter {
769 function DumpMultiWriter( $sinks ) {
770 $this->sinks = $sinks;
771 $this->count = count( $sinks );
772 }
773
774 function writeOpenStream( $string ) {
775 for( $i = 0; $i < $this->count; $i++ ) {
776 $this->sinks[$i]->writeOpenStream( $string );
777 }
778 }
779
780 function writeCloseStream( $string ) {
781 for( $i = 0; $i < $this->count; $i++ ) {
782 $this->sinks[$i]->writeCloseStream( $string );
783 }
784 }
785
786 function writeOpenPage( $page, $string ) {
787 for( $i = 0; $i < $this->count; $i++ ) {
788 $this->sinks[$i]->writeOpenPage( $page, $string );
789 }
790 }
791
792 function writeClosePage( $string ) {
793 for( $i = 0; $i < $this->count; $i++ ) {
794 $this->sinks[$i]->writeClosePage( $string );
795 }
796 }
797
798 function writeRevision( $rev, $string ) {
799 for( $i = 0; $i < $this->count; $i++ ) {
800 $this->sinks[$i]->writeRevision( $rev, $string );
801 }
802 }
803 }
804
805 function xmlsafe( $string ) {
806 $fname = 'xmlsafe';
807 wfProfileIn( $fname );
808
809 /**
810 * The page may contain old data which has not been properly normalized.
811 * Invalid UTF-8 sequences or forbidden control characters will make our
812 * XML output invalid, so be sure to strip them out.
813 */
814 $string = UtfNormal::cleanUp( $string );
815
816 $string = htmlspecialchars( $string );
817 wfProfileOut( $fname );
818 return $string;
819 }