00001 <?php
00002 # Copyright (C) 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
00003 # http://www.mediawiki.org/
00004 #
00005 # This program is free software; you can redistribute it and/or modify
00006 # it under the terms of the GNU General Public License as published by
00007 # the Free Software Foundation; either version 2 of the License, or
00008 # (at your option) any later version.
00009 #
00010 # This program is distributed in the hope that it will be useful,
00011 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013 # GNU General Public License for more details.
00014 #
00015 # You should have received a copy of the GNU General Public License along
00016 # with this program; if not, write to the Free Software Foundation, Inc.,
00017 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018 # http://www.gnu.org/copyleft/gpl.html
00019
00027 class WikiExporter {
00028 var $list_authors = false ; # Return distinct author list (when not returning full history)
00029 var $author_list = "" ;
00030
00031 var $dumpUploads = false;
00032
00033 const FULL = 1;
00034 const CURRENT = 2;
00035 const STABLE = 4;
00036 const LOGS = 8;
00037
00038 const BUFFER = 0;
00039 const STREAM = 1;
00040
00041 const TEXT = 0;
00042 const STUB = 1;
00043
00059 function __construct( &$db, $history = WikiExporter::CURRENT,
00060 $buffer = WikiExporter::BUFFER, $text = WikiExporter::TEXT ) {
00061 $this->db =& $db;
00062 $this->history = $history;
00063 $this->buffer = $buffer;
00064 $this->writer = new XmlDumpWriter();
00065 $this->sink = new DumpOutput();
00066 $this->text = $text;
00067 }
00068
00076 public function setOutputSink( &$sink ) {
00077 $this->sink =& $sink;
00078 }
00079
00080 public function openStream() {
00081 $output = $this->writer->openStream();
00082 $this->sink->writeOpenStream( $output );
00083 }
00084
00085 public function closeStream() {
00086 $output = $this->writer->closeStream();
00087 $this->sink->writeCloseStream( $output );
00088 }
00089
00095 public function allPages() {
00096 return $this->dumpFrom( '' );
00097 }
00098
00106 public function pagesByRange( $start, $end ) {
00107 $condition = 'page_id >= ' . intval( $start );
00108 if( $end ) {
00109 $condition .= ' AND page_id < ' . intval( $end );
00110 }
00111 return $this->dumpFrom( $condition );
00112 }
00113
00117 public function pageByTitle( $title ) {
00118 return $this->dumpFrom(
00119 'page_namespace=' . $title->getNamespace() .
00120 ' AND page_title=' . $this->db->addQuotes( $title->getDBkey() ) );
00121 }
00122
00123 public function pageByName( $name ) {
00124 $title = Title::newFromText( $name );
00125 if( is_null( $title ) ) {
00126 return new WikiError( "Can't export invalid title" );
00127 } else {
00128 return $this->pageByTitle( $title );
00129 }
00130 }
00131
00132 public function pagesByName( $names ) {
00133 foreach( $names as $name ) {
00134 $this->pageByName( $name );
00135 }
00136 }
00137
00138 public function allLogs() {
00139 return $this->dumpFrom( '' );
00140 }
00141
00142 public function logsByRange( $start, $end ) {
00143 $condition = 'log_id >= ' . intval( $start );
00144 if( $end ) {
00145 $condition .= ' AND log_id < ' . intval( $end );
00146 }
00147 return $this->dumpFrom( $condition );
00148 }
00149
00150 # Generates the distinct list of authors of an article
00151 # Not called by default (depends on $this->list_authors)
00152 # Can be set by Special:Export when not exporting whole history
00153 protected function do_list_authors( $page , $revision , $cond ) {
00154 $fname = "do_list_authors" ;
00155 wfProfileIn( $fname );
00156 $this->author_list = "<contributors>";
00157
00158 $nothidden = '(rev_deleted & '.Revision::DELETED_USER.') = 0';
00159
00160 $sql = "SELECT DISTINCT rev_user_text,rev_user FROM {$page},{$revision}
00161 WHERE page_id=rev_page AND $nothidden AND " . $cond ;
00162 $result = $this->db->query( $sql, $fname );
00163 $resultset = $this->db->resultObject( $result );
00164 while( $row = $resultset->fetchObject() ) {
00165 $this->author_list .= "<contributor>" .
00166 "<username>" .
00167 htmlentities( $row->rev_user_text ) .
00168 "</username>" .
00169 "<id>" .
00170 $row->rev_user .
00171 "</id>" .
00172 "</contributor>";
00173 }
00174 wfProfileOut( $fname );
00175 $this->author_list .= "</contributors>";
00176 }
00177
00178 protected function dumpFrom( $cond = '' ) {
00179 wfProfileIn( __METHOD__ );
00180 # For logging dumps...
00181 if( $this->history & self::LOGS ) {
00182 if( $this->buffer == WikiExporter::STREAM ) {
00183 $prev = $this->db->bufferResults( false );
00184 }
00185 $where = array( 'user_id = log_user' );
00186 # Hide private logs
00187 $hideLogs = LogEventsList::getExcludeClause( $this->db );
00188 if( $hideLogs ) $where[] = $hideLogs;
00189 # Add on any caller specified conditions
00190 if( $cond ) $where[] = $cond;
00191 # Get logging table name for logging.* clause
00192 $logging = $this->db->tableName('logging');
00193 $result = $this->db->select( array('logging','user'),
00194 array( "{$logging}.*", 'user_name' ),
00195 $where,
00196 __METHOD__,
00197 array( 'ORDER BY' => 'log_id', 'USE INDEX' => array('logging' => 'PRIMARY') )
00198 );
00199 $wrapper = $this->db->resultObject( $result );
00200 if( $this->buffer == WikiExporter::STREAM ) {
00201 $this->db->bufferResults( $prev );
00202 }
00203 $this->outputLogStream( $wrapper );
00204 # For page dumps...
00205 } else {
00206 $tables = array( 'page', 'revision' );
00207 $opts = array( 'ORDER BY' => 'page_id ASC' );
00208 $opts['USE INDEX'] = array();
00209 $join = array();
00210 # Full history dumps...
00211 if( $this->history & WikiExporter::FULL ) {
00212 $join['revision'] = array('INNER JOIN','page_id=rev_page');
00213 # Latest revision dumps...
00214 } elseif( $this->history & WikiExporter::CURRENT ) {
00215 if( $this->list_authors && $cond != '' ) {
00216 list($page,$revision) = $this->db->tableNamesN('page','revision');
00217 $this->do_list_authors( $page, $revision, $cond );
00218 }
00219 $join['revision'] = array('INNER JOIN','page_id=rev_page AND page_latest=rev_id');
00220 # "Stable" revision dumps...
00221 } elseif( $this->history & WikiExporter::STABLE ) {
00222 # Default JOIN, to be overridden...
00223 $join['revision'] = array('INNER JOIN','page_id=rev_page AND page_latest=rev_id');
00224 # One, and only one hook should set this, and return false
00225 if( wfRunHooks( 'WikiExporter::dumpStableQuery', array(&$tables,&$opts,&$join) ) ) {
00226 wfProfileOut( __METHOD__ );
00227 return new WikiError( __METHOD__." given invalid history dump type." );
00228 }
00229 # Time offset/limit for all pages/history...
00230 } elseif( is_array( $this->history ) ) {
00231 $revJoin = 'page_id=rev_page';
00232 # Set time order
00233 if( $this->history['dir'] == 'asc' ) {
00234 $op = '>';
00235 $opts['ORDER BY'] = 'rev_timestamp ASC';
00236 } else {
00237 $op = '<';
00238 $opts['ORDER BY'] = 'rev_timestamp DESC';
00239 }
00240 # Set offset
00241 if( !empty( $this->history['offset'] ) ) {
00242 $revJoin .= " AND rev_timestamp $op " .
00243 $this->db->addQuotes( $this->db->timestamp( $this->history['offset'] ) );
00244 }
00245 $join['revision'] = array('INNER JOIN',$revJoin);
00246 # Set query limit
00247 if( !empty( $this->history['limit'] ) ) {
00248 $opts['LIMIT'] = intval( $this->history['limit'] );
00249 }
00250 # Uknown history specification parameter?
00251 } else {
00252 wfProfileOut( __METHOD__ );
00253 return new WikiError( __METHOD__." given invalid history dump type." );
00254 }
00255 # Query optimization hacks
00256 if( $cond == '' ) {
00257 $opts[] = 'STRAIGHT_JOIN';
00258 $opts['USE INDEX']['page'] = 'PRIMARY';
00259 }
00260 # Build text join options
00261 if( $this->text != WikiExporter::STUB ) {
00262 $tables[] = 'text';
00263 $join['text'] = array('INNER JOIN','rev_text_id=old_id');
00264 }
00265
00266 if( $this->buffer == WikiExporter::STREAM ) {
00267 $prev = $this->db->bufferResults( false );
00268 }
00269
00270 # Do the query!
00271 $result = $this->db->select( $tables, '*', $cond, __METHOD__, $opts, $join );
00272 $wrapper = $this->db->resultObject( $result );
00273 # Output dump results
00274 $this->outputPageStream( $wrapper );
00275 if( $this->list_authors ) {
00276 $this->outputPageStream( $wrapper );
00277 }
00278
00279 if( $this->buffer == WikiExporter::STREAM ) {
00280 $this->db->bufferResults( $prev );
00281 }
00282 }
00283 wfProfileOut( __METHOD__ );
00284 }
00285
00298 protected function outputPageStream( $resultset ) {
00299 $last = null;
00300 while( $row = $resultset->fetchObject() ) {
00301 if( is_null( $last ) ||
00302 $last->page_namespace != $row->page_namespace ||
00303 $last->page_title != $row->page_title ) {
00304 if( isset( $last ) ) {
00305 $output = '';
00306 if( $this->dumpUploads ) {
00307 $output .= $this->writer->writeUploads( $last );
00308 }
00309 $output .= $this->writer->closePage();
00310 $this->sink->writeClosePage( $output );
00311 }
00312 $output = $this->writer->openPage( $row );
00313 $this->sink->writeOpenPage( $row, $output );
00314 $last = $row;
00315 }
00316 $output = $this->writer->writeRevision( $row );
00317 $this->sink->writeRevision( $row, $output );
00318 }
00319 if( isset( $last ) ) {
00320 $output = '';
00321 if( $this->dumpUploads ) {
00322 $output .= $this->writer->writeUploads( $last );
00323 }
00324 $output .= $this->author_list;
00325 $output .= $this->writer->closePage();
00326 $this->sink->writeClosePage( $output );
00327 }
00328 $resultset->free();
00329 }
00330
00331 protected function outputLogStream( $resultset ) {
00332 while( $row = $resultset->fetchObject() ) {
00333 $output = $this->writer->writeLogItem( $row );
00334 $this->sink->writeLogItem( $row, $output );
00335 }
00336 $resultset->free();
00337 }
00338 }
00339
00343 class XmlDumpWriter {
00344
00349 function schemaVersion() {
00350 return "0.3";
00351 }
00352
00363 function openStream() {
00364 global $wgContLanguageCode;
00365 $ver = $this->schemaVersion();
00366 return Xml::element( 'mediawiki', array(
00367 'xmlns' => "http://www.mediawiki.org/xml/export-$ver/",
00368 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
00369 'xsi:schemaLocation' => "http://www.mediawiki.org/xml/export-$ver/ " .
00370 "http://www.mediawiki.org/xml/export-$ver.xsd",
00371 'version' => $ver,
00372 'xml:lang' => $wgContLanguageCode ),
00373 null ) .
00374 "\n" .
00375 $this->siteInfo();
00376 }
00377
00378 function siteInfo() {
00379 $info = array(
00380 $this->sitename(),
00381 $this->homelink(),
00382 $this->generator(),
00383 $this->caseSetting(),
00384 $this->namespaces() );
00385 return " <siteinfo>\n " .
00386 implode( "\n ", $info ) .
00387 "\n </siteinfo>\n";
00388 }
00389
00390 function sitename() {
00391 global $wgSitename;
00392 return Xml::element( 'sitename', array(), $wgSitename );
00393 }
00394
00395 function generator() {
00396 global $wgVersion;
00397 return Xml::element( 'generator', array(), "MediaWiki $wgVersion" );
00398 }
00399
00400 function homelink() {
00401 return Xml::element( 'base', array(), Title::newMainPage()->getFullUrl() );
00402 }
00403
00404 function caseSetting() {
00405 global $wgCapitalLinks;
00406
00407 $sensitivity = $wgCapitalLinks ? 'first-letter' : 'case-sensitive';
00408 return Xml::element( 'case', array(), $sensitivity );
00409 }
00410
00411 function namespaces() {
00412 global $wgContLang;
00413 $spaces = "<namespaces>\n";
00414 foreach( $wgContLang->getFormattedNamespaces() as $ns => $title ) {
00415 $spaces .= ' ' . Xml::element( 'namespace', array( 'key' => $ns ), $title ) . "\n";
00416 }
00417 $spaces .= " </namespaces>";
00418 return $spaces;
00419 }
00420
00425 function closeStream() {
00426 return "</mediawiki>\n";
00427 }
00428
00429
00438 function openPage( $row ) {
00439 $out = " <page>\n";
00440 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
00441 $out .= ' ' . Xml::elementClean( 'title', array(), $title->getPrefixedText() ) . "\n";
00442 $out .= ' ' . Xml::element( 'id', array(), strval( $row->page_id ) ) . "\n";
00443 if( '' != $row->page_restrictions ) {
00444 $out .= ' ' . Xml::element( 'restrictions', array(),
00445 strval( $row->page_restrictions ) ) . "\n";
00446 }
00447 return $out;
00448 }
00449
00455 function closePage() {
00456 return " </page>\n";
00457 }
00458
00467 function writeRevision( $row ) {
00468 $fname = 'WikiExporter::dumpRev';
00469 wfProfileIn( $fname );
00470
00471 $out = " <revision>\n";
00472 $out .= " " . Xml::element( 'id', null, strval( $row->rev_id ) ) . "\n";
00473
00474 $out .= $this->writeTimestamp( $row->rev_timestamp );
00475
00476 if( $row->rev_deleted & Revision::DELETED_USER ) {
00477 $out .= " " . Xml::element( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
00478 } else {
00479 $out .= $this->writeContributor( $row->rev_user, $row->rev_user_text );
00480 }
00481
00482 if( $row->rev_minor_edit ) {
00483 $out .= " <minor/>\n";
00484 }
00485 if( $row->rev_deleted & Revision::DELETED_COMMENT ) {
00486 $out .= " " . Xml::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
00487 } elseif( $row->rev_comment != '' ) {
00488 $out .= " " . Xml::elementClean( 'comment', null, strval( $row->rev_comment ) ) . "\n";
00489 }
00490
00491 if( $row->rev_deleted & Revision::DELETED_TEXT ) {
00492 $out .= " " . Xml::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
00493 } elseif( isset( $row->old_text ) ) {
00494
00495 $text = strval( Revision::getRevisionText( $row ) );
00496 $out .= " " . Xml::elementClean( 'text',
00497 array( 'xml:space' => 'preserve' ),
00498 strval( $text ) ) . "\n";
00499 } else {
00500
00501 $out .= " " . Xml::element( 'text',
00502 array( 'id' => $row->rev_text_id ),
00503 "" ) . "\n";
00504 }
00505
00506 $out .= " </revision>\n";
00507
00508 wfProfileOut( $fname );
00509 return $out;
00510 }
00511
00520 function writeLogItem( $row ) {
00521 $fname = 'WikiExporter::writeLogItem';
00522 wfProfileIn( $fname );
00523
00524 $out = " <logitem>\n";
00525 $out .= " " . Xml::element( 'id', null, strval( $row->log_id ) ) . "\n";
00526
00527 $out .= $this->writeTimestamp( $row->log_timestamp );
00528
00529 if( $row->log_deleted & LogPage::DELETED_USER ) {
00530 $out .= " " . Xml::element( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
00531 } else {
00532 $out .= $this->writeContributor( $row->log_user, $row->user_name );
00533 }
00534
00535 if( $row->log_deleted & LogPage::DELETED_COMMENT ) {
00536 $out .= " " . Xml::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
00537 } elseif( $row->log_comment != '' ) {
00538 $out .= " " . Xml::elementClean( 'comment', null, strval( $row->log_comment ) ) . "\n";
00539 }
00540
00541 $out .= " " . Xml::element( 'type', null, strval( $row->log_type ) ) . "\n";
00542 $out .= " " . Xml::element( 'action', null, strval( $row->log_action ) ) . "\n";
00543
00544 if( $row->log_deleted & LogPage::DELETED_ACTION ) {
00545 $out .= " " . Xml::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
00546 } else {
00547 $title = Title::makeTitle( $row->log_namespace, $row->log_title );
00548 $out .= " " . Xml::elementClean( 'logtitle', null, $title->getPrefixedText() ) . "\n";
00549 $out .= " " . Xml::elementClean( 'params',
00550 array( 'xml:space' => 'preserve' ),
00551 strval( $row->log_params ) ) . "\n";
00552 }
00553
00554 $out .= " </logitem>\n";
00555
00556 wfProfileOut( $fname );
00557 return $out;
00558 }
00559
00560 function writeTimestamp( $timestamp ) {
00561 $ts = wfTimestamp( TS_ISO_8601, $timestamp );
00562 return " " . Xml::element( 'timestamp', null, $ts ) . "\n";
00563 }
00564
00565 function writeContributor( $id, $text ) {
00566 $out = " <contributor>\n";
00567 if( $id ) {
00568 $out .= " " . Xml::elementClean( 'username', null, strval( $text ) ) . "\n";
00569 $out .= " " . Xml::element( 'id', null, strval( $id ) ) . "\n";
00570 } else {
00571 $out .= " " . Xml::elementClean( 'ip', null, strval( $text ) ) . "\n";
00572 }
00573 $out .= " </contributor>\n";
00574 return $out;
00575 }
00576
00580 function writeUploads( $row ) {
00581 if( $row->page_namespace == NS_IMAGE ) {
00582 $img = wfFindFile( $row->page_title );
00583 if( $img ) {
00584 $out = '';
00585 foreach( array_reverse( $img->getHistory() ) as $ver ) {
00586 $out .= $this->writeUpload( $ver );
00587 }
00588 $out .= $this->writeUpload( $img );
00589 return $out;
00590 }
00591 }
00592 return '';
00593 }
00594
00595 function writeUpload( $file ) {
00596 return " <upload>\n" .
00597 $this->writeTimestamp( $file->getTimestamp() ) .
00598 $this->writeContributor( $file->getUser( 'id' ), $file->getUser( 'text' ) ) .
00599 " " . Xml::elementClean( 'comment', null, $file->getDescription() ) . "\n" .
00600 " " . Xml::element( 'filename', null, $file->getName() ) . "\n" .
00601 " " . Xml::element( 'src', null, $file->getFullUrl() ) . "\n" .
00602 " " . Xml::element( 'size', null, $file->getSize() ) . "\n" .
00603 " </upload>\n";
00604 }
00605
00606 }
00607
00608
00613 class DumpOutput {
00614 function writeOpenStream( $string ) {
00615 $this->write( $string );
00616 }
00617
00618 function writeCloseStream( $string ) {
00619 $this->write( $string );
00620 }
00621
00622 function writeOpenPage( $page, $string ) {
00623 $this->write( $string );
00624 }
00625
00626 function writeClosePage( $string ) {
00627 $this->write( $string );
00628 }
00629
00630 function writeRevision( $rev, $string ) {
00631 $this->write( $string );
00632 }
00633
00634 function writeLogItem( $rev, $string ) {
00635 $this->write( $string );
00636 }
00637
00642 function write( $string ) {
00643 print $string;
00644 }
00645 }
00646
00651 class DumpFileOutput extends DumpOutput {
00652 var $handle;
00653
00654 function DumpFileOutput( $file ) {
00655 $this->handle = fopen( $file, "wt" );
00656 }
00657
00658 function write( $string ) {
00659 fputs( $this->handle, $string );
00660 }
00661 }
00662
00669 class DumpPipeOutput extends DumpFileOutput {
00670 function DumpPipeOutput( $command, $file = null ) {
00671 if( !is_null( $file ) ) {
00672 $command .= " > " . wfEscapeShellArg( $file );
00673 }
00674 $this->handle = popen( $command, "w" );
00675 }
00676 }
00677
00682 class DumpGZipOutput extends DumpPipeOutput {
00683 function DumpGZipOutput( $file ) {
00684 parent::DumpPipeOutput( "gzip", $file );
00685 }
00686 }
00687
00692 class DumpBZip2Output extends DumpPipeOutput {
00693 function DumpBZip2Output( $file ) {
00694 parent::DumpPipeOutput( "bzip2", $file );
00695 }
00696 }
00697
00702 class Dump7ZipOutput extends DumpPipeOutput {
00703 function Dump7ZipOutput( $file ) {
00704 $command = "7za a -bd -si " . wfEscapeShellArg( $file );
00705
00706
00707 $command .= ' >' . wfGetNull() . ' 2>&1';
00708 parent::DumpPipeOutput( $command );
00709 }
00710 }
00711
00712
00713
00720 class DumpFilter {
00721 function DumpFilter( &$sink ) {
00722 $this->sink =& $sink;
00723 }
00724
00725 function writeOpenStream( $string ) {
00726 $this->sink->writeOpenStream( $string );
00727 }
00728
00729 function writeCloseStream( $string ) {
00730 $this->sink->writeCloseStream( $string );
00731 }
00732
00733 function writeOpenPage( $page, $string ) {
00734 $this->sendingThisPage = $this->pass( $page, $string );
00735 if( $this->sendingThisPage ) {
00736 $this->sink->writeOpenPage( $page, $string );
00737 }
00738 }
00739
00740 function writeClosePage( $string ) {
00741 if( $this->sendingThisPage ) {
00742 $this->sink->writeClosePage( $string );
00743 $this->sendingThisPage = false;
00744 }
00745 }
00746
00747 function writeRevision( $rev, $string ) {
00748 if( $this->sendingThisPage ) {
00749 $this->sink->writeRevision( $rev, $string );
00750 }
00751 }
00752
00753 function writeLogItem( $rev, $string ) {
00754 $this->sink->writeRevision( $rev, $string );
00755 }
00756
00761 function pass( $page ) {
00762 return true;
00763 }
00764 }
00765
00770 class DumpNotalkFilter extends DumpFilter {
00771 function pass( $page ) {
00772 return !MWNamespace::isTalk( $page->page_namespace );
00773 }
00774 }
00775
00780 class DumpNamespaceFilter extends DumpFilter {
00781 var $invert = false;
00782 var $namespaces = array();
00783
00784 function DumpNamespaceFilter( &$sink, $param ) {
00785 parent::DumpFilter( $sink );
00786
00787 $constants = array(
00788 "NS_MAIN" => NS_MAIN,
00789 "NS_TALK" => NS_TALK,
00790 "NS_USER" => NS_USER,
00791 "NS_USER_TALK" => NS_USER_TALK,
00792 "NS_PROJECT" => NS_PROJECT,
00793 "NS_PROJECT_TALK" => NS_PROJECT_TALK,
00794 "NS_FILE" => NS_FILE,
00795 "NS_FILE_TALK" => NS_FILE_TALK,
00796 "NS_IMAGE" => NS_IMAGE,
00797 "NS_IMAGE_TALK" => NS_IMAGE_TALK,
00798 "NS_MEDIAWIKI" => NS_MEDIAWIKI,
00799 "NS_MEDIAWIKI_TALK" => NS_MEDIAWIKI_TALK,
00800 "NS_TEMPLATE" => NS_TEMPLATE,
00801 "NS_TEMPLATE_TALK" => NS_TEMPLATE_TALK,
00802 "NS_HELP" => NS_HELP,
00803 "NS_HELP_TALK" => NS_HELP_TALK,
00804 "NS_CATEGORY" => NS_CATEGORY,
00805 "NS_CATEGORY_TALK" => NS_CATEGORY_TALK );
00806
00807 if( $param{0} == '!' ) {
00808 $this->invert = true;
00809 $param = substr( $param, 1 );
00810 }
00811
00812 foreach( explode( ',', $param ) as $key ) {
00813 $key = trim( $key );
00814 if( isset( $constants[$key] ) ) {
00815 $ns = $constants[$key];
00816 $this->namespaces[$ns] = true;
00817 } elseif( is_numeric( $key ) ) {
00818 $ns = intval( $key );
00819 $this->namespaces[$ns] = true;
00820 } else {
00821 throw new MWException( "Unrecognized namespace key '$key'\n" );
00822 }
00823 }
00824 }
00825
00826 function pass( $page ) {
00827 $match = isset( $this->namespaces[$page->page_namespace] );
00828 return $this->invert xor $match;
00829 }
00830 }
00831
00832
00837 class DumpLatestFilter extends DumpFilter {
00838 var $page, $pageString, $rev, $revString;
00839
00840 function writeOpenPage( $page, $string ) {
00841 $this->page = $page;
00842 $this->pageString = $string;
00843 }
00844
00845 function writeClosePage( $string ) {
00846 if( $this->rev ) {
00847 $this->sink->writeOpenPage( $this->page, $this->pageString );
00848 $this->sink->writeRevision( $this->rev, $this->revString );
00849 $this->sink->writeClosePage( $string );
00850 }
00851 $this->rev = null;
00852 $this->revString = null;
00853 $this->page = null;
00854 $this->pageString = null;
00855 }
00856
00857 function writeRevision( $rev, $string ) {
00858 if( $rev->rev_id == $this->page->page_latest ) {
00859 $this->rev = $rev;
00860 $this->revString = $string;
00861 }
00862 }
00863 }
00864
00869 class DumpMultiWriter {
00870 function DumpMultiWriter( $sinks ) {
00871 $this->sinks = $sinks;
00872 $this->count = count( $sinks );
00873 }
00874
00875 function writeOpenStream( $string ) {
00876 for( $i = 0; $i < $this->count; $i++ ) {
00877 $this->sinks[$i]->writeOpenStream( $string );
00878 }
00879 }
00880
00881 function writeCloseStream( $string ) {
00882 for( $i = 0; $i < $this->count; $i++ ) {
00883 $this->sinks[$i]->writeCloseStream( $string );
00884 }
00885 }
00886
00887 function writeOpenPage( $page, $string ) {
00888 for( $i = 0; $i < $this->count; $i++ ) {
00889 $this->sinks[$i]->writeOpenPage( $page, $string );
00890 }
00891 }
00892
00893 function writeClosePage( $string ) {
00894 for( $i = 0; $i < $this->count; $i++ ) {
00895 $this->sinks[$i]->writeClosePage( $string );
00896 }
00897 }
00898
00899 function writeRevision( $rev, $string ) {
00900 for( $i = 0; $i < $this->count; $i++ ) {
00901 $this->sinks[$i]->writeRevision( $rev, $string );
00902 }
00903 }
00904 }
00905
00906 function xmlsafe( $string ) {
00907 $fname = 'xmlsafe';
00908 wfProfileIn( $fname );
00909
00915 $string = UtfNormal::cleanUp( $string );
00916
00917 $string = htmlspecialchars( $string );
00918 wfProfileOut( $fname );
00919 return $string;
00920 }