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
00060 function __construct( &$db, $history = WikiExporter::CURRENT,
00061 $buffer = WikiExporter::BUFFER, $text = WikiExporter::TEXT ) {
00062 $this->db =& $db;
00063 $this->history = $history;
00064 $this->buffer = $buffer;
00065 $this->writer = new XmlDumpWriter();
00066 $this->sink = new DumpOutput();
00067 $this->text = $text;
00068 }
00069
00077 public function setOutputSink( &$sink ) {
00078 $this->sink =& $sink;
00079 }
00080
00081 public function openStream() {
00082 $output = $this->writer->openStream();
00083 $this->sink->writeOpenStream( $output );
00084 }
00085
00086 public function closeStream() {
00087 $output = $this->writer->closeStream();
00088 $this->sink->writeCloseStream( $output );
00089 }
00090
00096 public function allPages() {
00097 return $this->dumpFrom( '' );
00098 }
00099
00107 public function pagesByRange( $start, $end ) {
00108 $condition = 'page_id >= ' . intval( $start );
00109 if( $end ) {
00110 $condition .= ' AND page_id < ' . intval( $end );
00111 }
00112 return $this->dumpFrom( $condition );
00113 }
00114
00118 public function pageByTitle( $title ) {
00119 return $this->dumpFrom(
00120 'page_namespace=' . $title->getNamespace() .
00121 ' AND page_title=' . $this->db->addQuotes( $title->getDBkey() ) );
00122 }
00123
00124 public function pageByName( $name ) {
00125 $title = Title::newFromText( $name );
00126 if( is_null( $title ) ) {
00127 return new WikiError( "Can't export invalid title" );
00128 } else {
00129 return $this->pageByTitle( $title );
00130 }
00131 }
00132
00133 public function pagesByName( $names ) {
00134 foreach( $names as $name ) {
00135 $this->pageByName( $name );
00136 }
00137 }
00138
00139 public function allLogs() {
00140 return $this->dumpFrom( '' );
00141 }
00142
00143 public function logsByRange( $start, $end ) {
00144 $condition = 'log_id >= ' . intval( $start );
00145 if( $end ) {
00146 $condition .= ' AND log_id < ' . intval( $end );
00147 }
00148 return $this->dumpFrom( $condition );
00149 }
00150
00151 # Generates the distinct list of authors of an article
00152 # Not called by default (depends on $this->list_authors)
00153 # Can be set by Special:Export when not exporting whole history
00154 protected function do_list_authors( $page , $revision , $cond ) {
00155 $fname = "do_list_authors" ;
00156 wfProfileIn( $fname );
00157 $this->author_list = "<contributors>";
00158
00159 $nothidden = '('.$this->db->bitAnd('rev_deleted', Revision::DELETED_USER) . ') = 0';
00160
00161 $sql = "SELECT DISTINCT rev_user_text,rev_user FROM {$page},{$revision}
00162 WHERE page_id=rev_page AND $nothidden AND " . $cond ;
00163 $result = $this->db->query( $sql, $fname );
00164 $resultset = $this->db->resultObject( $result );
00165 while( $row = $resultset->fetchObject() ) {
00166 $this->author_list .= "<contributor>" .
00167 "<username>" .
00168 htmlentities( $row->rev_user_text ) .
00169 "</username>" .
00170 "<id>" .
00171 $row->rev_user .
00172 "</id>" .
00173 "</contributor>";
00174 }
00175 wfProfileOut( $fname );
00176 $this->author_list .= "</contributors>";
00177 }
00178
00179 protected function dumpFrom( $cond = '' ) {
00180 wfProfileIn( __METHOD__ );
00181 # For logging dumps...
00182 if( $this->history & self::LOGS ) {
00183 if( $this->buffer == WikiExporter::STREAM ) {
00184 $prev = $this->db->bufferResults( false );
00185 }
00186 $where = array( 'user_id = log_user' );
00187 # Hide private logs
00188 $hideLogs = LogEventsList::getExcludeClause( $this->db );
00189 if( $hideLogs ) $where[] = $hideLogs;
00190 # Add on any caller specified conditions
00191 if( $cond ) $where[] = $cond;
00192 # Get logging table name for logging.* clause
00193 $logging = $this->db->tableName('logging');
00194 $result = $this->db->select( array('logging','user'),
00195 array( "{$logging}.*", 'user_name' ),
00196 $where,
00197 __METHOD__,
00198 array( 'ORDER BY' => 'log_id', 'USE INDEX' => array('logging' => 'PRIMARY') )
00199 );
00200 $wrapper = $this->db->resultObject( $result );
00201 $this->outputLogStream( $wrapper );
00202 if( $this->buffer == WikiExporter::STREAM ) {
00203 $this->db->bufferResults( $prev );
00204 }
00205 # For page dumps...
00206 } else {
00207 $tables = array( 'page', 'revision' );
00208 $opts = array( 'ORDER BY' => 'page_id ASC' );
00209 $opts['USE INDEX'] = array();
00210 $join = array();
00211 if( is_array( $this->history ) ) {
00212 # Time offset/limit for all pages/history...
00213 $revJoin = 'page_id=rev_page';
00214 # Set time order
00215 if( $this->history['dir'] == 'asc' ) {
00216 $op = '>';
00217 $opts['ORDER BY'] = 'rev_timestamp ASC';
00218 } else {
00219 $op = '<';
00220 $opts['ORDER BY'] = 'rev_timestamp DESC';
00221 }
00222 # Set offset
00223 if( !empty( $this->history['offset'] ) ) {
00224 $revJoin .= " AND rev_timestamp $op " .
00225 $this->db->addQuotes( $this->db->timestamp( $this->history['offset'] ) );
00226 }
00227 $join['revision'] = array('INNER JOIN',$revJoin);
00228 # Set query limit
00229 if( !empty( $this->history['limit'] ) ) {
00230 $opts['LIMIT'] = intval( $this->history['limit'] );
00231 }
00232 } elseif( $this->history & WikiExporter::FULL ) {
00233 # Full history dumps...
00234 $join['revision'] = array('INNER JOIN','page_id=rev_page');
00235 } elseif( $this->history & WikiExporter::CURRENT ) {
00236 # Latest revision dumps...
00237 if( $this->list_authors && $cond != '' ) {
00238 list($page,$revision) = $this->db->tableNamesN('page','revision');
00239 $this->do_list_authors( $page, $revision, $cond );
00240 }
00241 $join['revision'] = array('INNER JOIN','page_id=rev_page AND page_latest=rev_id');
00242 } elseif( $this->history & WikiExporter::STABLE ) {
00243 # "Stable" revision dumps...
00244 # Default JOIN, to be overridden...
00245 $join['revision'] = array('INNER JOIN','page_id=rev_page AND page_latest=rev_id');
00246 # One, and only one hook should set this, and return false
00247 if( wfRunHooks( 'WikiExporter::dumpStableQuery', array(&$tables,&$opts,&$join) ) ) {
00248 wfProfileOut( __METHOD__ );
00249 return new WikiError( __METHOD__." given invalid history dump type." );
00250 }
00251 } else {
00252 # Uknown history specification parameter?
00253 wfProfileOut( __METHOD__ );
00254 return new WikiError( __METHOD__." given invalid history dump type." );
00255 }
00256 # Query optimization hacks
00257 if( $cond == '' ) {
00258 $opts[] = 'STRAIGHT_JOIN';
00259 $opts['USE INDEX']['page'] = 'PRIMARY';
00260 }
00261 # Build text join options
00262 if( $this->text != WikiExporter::STUB ) {
00263 $tables[] = 'text';
00264 $join['text'] = array('INNER JOIN','rev_text_id=old_id');
00265 }
00266
00267 if( $this->buffer == WikiExporter::STREAM ) {
00268 $prev = $this->db->bufferResults( false );
00269 }
00270
00271 wfRunHooks( 'ModifyExportQuery',
00272 array( $this->db, &$tables, &$cond, &$opts, &$join ) );
00273
00274 # Do the query!
00275 $result = $this->db->select( $tables, '*', $cond, __METHOD__, $opts, $join );
00276 $wrapper = $this->db->resultObject( $result );
00277 # Output dump results
00278 $this->outputPageStream( $wrapper );
00279 if( $this->list_authors ) {
00280 $this->outputPageStream( $wrapper );
00281 }
00282
00283 if( $this->buffer == WikiExporter::STREAM ) {
00284 $this->db->bufferResults( $prev );
00285 }
00286 }
00287 wfProfileOut( __METHOD__ );
00288 }
00289
00302 protected function outputPageStream( $resultset ) {
00303 $last = null;
00304 while( $row = $resultset->fetchObject() ) {
00305 if( is_null( $last ) ||
00306 $last->page_namespace != $row->page_namespace ||
00307 $last->page_title != $row->page_title ) {
00308 if( isset( $last ) ) {
00309 $output = '';
00310 if( $this->dumpUploads ) {
00311 $output .= $this->writer->writeUploads( $last );
00312 }
00313 $output .= $this->writer->closePage();
00314 $this->sink->writeClosePage( $output );
00315 }
00316 $output = $this->writer->openPage( $row );
00317 $this->sink->writeOpenPage( $row, $output );
00318 $last = $row;
00319 }
00320 $output = $this->writer->writeRevision( $row );
00321 $this->sink->writeRevision( $row, $output );
00322 }
00323 if( isset( $last ) ) {
00324 $output = '';
00325 if( $this->dumpUploads ) {
00326 $output .= $this->writer->writeUploads( $last );
00327 }
00328 $output .= $this->author_list;
00329 $output .= $this->writer->closePage();
00330 $this->sink->writeClosePage( $output );
00331 }
00332 }
00333
00334 protected function outputLogStream( $resultset ) {
00335 while( $row = $resultset->fetchObject() ) {
00336 $output = $this->writer->writeLogItem( $row );
00337 $this->sink->writeLogItem( $row, $output );
00338 }
00339 }
00340 }
00341
00345 class XmlDumpWriter {
00346
00351 function schemaVersion() {
00352 return "0.4";
00353 }
00354
00365 function openStream() {
00366 global $wgContLanguageCode;
00367 $ver = $this->schemaVersion();
00368 return Xml::element( 'mediawiki', array(
00369 'xmlns' => "http://www.mediawiki.org/xml/export-$ver/",
00370 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
00371 'xsi:schemaLocation' => "http://www.mediawiki.org/xml/export-$ver/ " .
00372 "http://www.mediawiki.org/xml/export-$ver.xsd",
00373 'version' => $ver,
00374 'xml:lang' => $wgContLanguageCode ),
00375 null ) .
00376 "\n" .
00377 $this->siteInfo();
00378 }
00379
00380 function siteInfo() {
00381 $info = array(
00382 $this->sitename(),
00383 $this->homelink(),
00384 $this->generator(),
00385 $this->caseSetting(),
00386 $this->namespaces() );
00387 return " <siteinfo>\n " .
00388 implode( "\n ", $info ) .
00389 "\n </siteinfo>\n";
00390 }
00391
00392 function sitename() {
00393 global $wgSitename;
00394 return Xml::element( 'sitename', array(), $wgSitename );
00395 }
00396
00397 function generator() {
00398 global $wgVersion;
00399 return Xml::element( 'generator', array(), "MediaWiki $wgVersion" );
00400 }
00401
00402 function homelink() {
00403 return Xml::element( 'base', array(), Title::newMainPage()->getFullUrl() );
00404 }
00405
00406 function caseSetting() {
00407 global $wgCapitalLinks;
00408
00409 $sensitivity = $wgCapitalLinks ? 'first-letter' : 'case-sensitive';
00410 return Xml::element( 'case', array(), $sensitivity );
00411 }
00412
00413 function namespaces() {
00414 global $wgContLang;
00415 $spaces = "<namespaces>\n";
00416 foreach( $wgContLang->getFormattedNamespaces() as $ns => $title ) {
00417 $spaces .= ' ' .
00418 Xml::element( 'namespace',
00419 array( 'key' => $ns,
00420 'case' => MWNamespace::isCapitalized( $ns ) ? 'first-letter' : 'case-sensitive',
00421 ), $title ) . "\n";
00422 }
00423 $spaces .= " </namespaces>";
00424 return $spaces;
00425 }
00426
00431 function closeStream() {
00432 return "</mediawiki>\n";
00433 }
00434
00435
00444 function openPage( $row ) {
00445 $out = " <page>\n";
00446 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
00447 $out .= ' ' . Xml::elementClean( 'title', array(), $title->getPrefixedText() ) . "\n";
00448 $out .= ' ' . Xml::element( 'id', array(), strval( $row->page_id ) ) . "\n";
00449 if( $row->page_is_redirect ) {
00450 $out .= ' ' . Xml::element( 'redirect', array() ) . "\n";
00451 }
00452 if( $row->page_restrictions != '' ) {
00453 $out .= ' ' . Xml::element( 'restrictions', array(),
00454 strval( $row->page_restrictions ) ) . "\n";
00455 }
00456
00457 wfRunHooks( 'XmlDumpWriterOpenPage', array( $this, &$out, $row, $title ) );
00458
00459 return $out;
00460 }
00461
00467 function closePage() {
00468 return " </page>\n";
00469 }
00470
00479 function writeRevision( $row ) {
00480 $fname = 'WikiExporter::dumpRev';
00481 wfProfileIn( $fname );
00482
00483 $out = " <revision>\n";
00484 $out .= " " . Xml::element( 'id', null, strval( $row->rev_id ) ) . "\n";
00485
00486 $out .= $this->writeTimestamp( $row->rev_timestamp );
00487
00488 if( $row->rev_deleted & Revision::DELETED_USER ) {
00489 $out .= " " . Xml::element( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
00490 } else {
00491 $out .= $this->writeContributor( $row->rev_user, $row->rev_user_text );
00492 }
00493
00494 if( $row->rev_minor_edit ) {
00495 $out .= " <minor/>\n";
00496 }
00497 if( $row->rev_deleted & Revision::DELETED_COMMENT ) {
00498 $out .= " " . Xml::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
00499 } elseif( $row->rev_comment != '' ) {
00500 $out .= " " . Xml::elementClean( 'comment', null, strval( $row->rev_comment ) ) . "\n";
00501 }
00502
00503 $text = '';
00504 if( $row->rev_deleted & Revision::DELETED_TEXT ) {
00505 $out .= " " . Xml::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
00506 } elseif( isset( $row->old_text ) ) {
00507
00508 $text = strval( Revision::getRevisionText( $row ) );
00509 $out .= " " . Xml::elementClean( 'text',
00510 array( 'xml:space' => 'preserve' ),
00511 strval( $text ) ) . "\n";
00512 } else {
00513
00514 $out .= " " . Xml::element( 'text',
00515 array( 'id' => $row->rev_text_id ),
00516 "" ) . "\n";
00517 }
00518
00519 wfRunHooks( 'XmlDumpWriterWriteRevision', array( &$this, &$out, $row, $text ) );
00520
00521 $out .= " </revision>\n";
00522
00523 wfProfileOut( $fname );
00524 return $out;
00525 }
00526
00535 function writeLogItem( $row ) {
00536 $fname = 'WikiExporter::writeLogItem';
00537 wfProfileIn( $fname );
00538
00539 $out = " <logitem>\n";
00540 $out .= " " . Xml::element( 'id', null, strval( $row->log_id ) ) . "\n";
00541
00542 $out .= $this->writeTimestamp( $row->log_timestamp );
00543
00544 if( $row->log_deleted & LogPage::DELETED_USER ) {
00545 $out .= " " . Xml::element( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
00546 } else {
00547 $out .= $this->writeContributor( $row->log_user, $row->user_name );
00548 }
00549
00550 if( $row->log_deleted & LogPage::DELETED_COMMENT ) {
00551 $out .= " " . Xml::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
00552 } elseif( $row->log_comment != '' ) {
00553 $out .= " " . Xml::elementClean( 'comment', null, strval( $row->log_comment ) ) . "\n";
00554 }
00555
00556 $out .= " " . Xml::element( 'type', null, strval( $row->log_type ) ) . "\n";
00557 $out .= " " . Xml::element( 'action', null, strval( $row->log_action ) ) . "\n";
00558
00559 if( $row->log_deleted & LogPage::DELETED_ACTION ) {
00560 $out .= " " . Xml::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
00561 } else {
00562 $title = Title::makeTitle( $row->log_namespace, $row->log_title );
00563 $out .= " " . Xml::elementClean( 'logtitle', null, $title->getPrefixedText() ) . "\n";
00564 $out .= " " . Xml::elementClean( 'params',
00565 array( 'xml:space' => 'preserve' ),
00566 strval( $row->log_params ) ) . "\n";
00567 }
00568
00569 $out .= " </logitem>\n";
00570
00571 wfProfileOut( $fname );
00572 return $out;
00573 }
00574
00575 function writeTimestamp( $timestamp ) {
00576 $ts = wfTimestamp( TS_ISO_8601, $timestamp );
00577 return " " . Xml::element( 'timestamp', null, $ts ) . "\n";
00578 }
00579
00580 function writeContributor( $id, $text ) {
00581 $out = " <contributor>\n";
00582 if( $id ) {
00583 $out .= " " . Xml::elementClean( 'username', null, strval( $text ) ) . "\n";
00584 $out .= " " . Xml::element( 'id', null, strval( $id ) ) . "\n";
00585 } else {
00586 $out .= " " . Xml::elementClean( 'ip', null, strval( $text ) ) . "\n";
00587 }
00588 $out .= " </contributor>\n";
00589 return $out;
00590 }
00591
00595 function writeUploads( $row ) {
00596 if( $row->page_namespace == NS_IMAGE ) {
00597 $img = wfFindFile( $row->page_title );
00598 if( $img ) {
00599 $out = '';
00600 foreach( array_reverse( $img->getHistory() ) as $ver ) {
00601 $out .= $this->writeUpload( $ver );
00602 }
00603 $out .= $this->writeUpload( $img );
00604 return $out;
00605 }
00606 }
00607 return '';
00608 }
00609
00610 function writeUpload( $file ) {
00611 return " <upload>\n" .
00612 $this->writeTimestamp( $file->getTimestamp() ) .
00613 $this->writeContributor( $file->getUser( 'id' ), $file->getUser( 'text' ) ) .
00614 " " . Xml::elementClean( 'comment', null, $file->getDescription() ) . "\n" .
00615 " " . Xml::element( 'filename', null, $file->getName() ) . "\n" .
00616 " " . Xml::element( 'src', null, $file->getFullUrl() ) . "\n" .
00617 " " . Xml::element( 'size', null, $file->getSize() ) . "\n" .
00618 " </upload>\n";
00619 }
00620
00621 }
00622
00623
00628 class DumpOutput {
00629 function writeOpenStream( $string ) {
00630 $this->write( $string );
00631 }
00632
00633 function writeCloseStream( $string ) {
00634 $this->write( $string );
00635 }
00636
00637 function writeOpenPage( $page, $string ) {
00638 $this->write( $string );
00639 }
00640
00641 function writeClosePage( $string ) {
00642 $this->write( $string );
00643 }
00644
00645 function writeRevision( $rev, $string ) {
00646 $this->write( $string );
00647 }
00648
00649 function writeLogItem( $rev, $string ) {
00650 $this->write( $string );
00651 }
00652
00657 function write( $string ) {
00658 print $string;
00659 }
00660 }
00661
00666 class DumpFileOutput extends DumpOutput {
00667 var $handle;
00668
00669 function DumpFileOutput( $file ) {
00670 $this->handle = fopen( $file, "wt" );
00671 }
00672
00673 function write( $string ) {
00674 fputs( $this->handle, $string );
00675 }
00676 }
00677
00684 class DumpPipeOutput extends DumpFileOutput {
00685 function DumpPipeOutput( $command, $file = null ) {
00686 if( !is_null( $file ) ) {
00687 $command .= " > " . wfEscapeShellArg( $file );
00688 }
00689 $this->handle = popen( $command, "w" );
00690 }
00691 }
00692
00697 class DumpGZipOutput extends DumpPipeOutput {
00698 function DumpGZipOutput( $file ) {
00699 parent::DumpPipeOutput( "gzip", $file );
00700 }
00701 }
00702
00707 class DumpBZip2Output extends DumpPipeOutput {
00708 function DumpBZip2Output( $file ) {
00709 parent::DumpPipeOutput( "bzip2", $file );
00710 }
00711 }
00712
00717 class Dump7ZipOutput extends DumpPipeOutput {
00718 function Dump7ZipOutput( $file ) {
00719 $command = "7za a -bd -si " . wfEscapeShellArg( $file );
00720
00721
00722 $command .= ' >' . wfGetNull() . ' 2>&1';
00723 parent::DumpPipeOutput( $command );
00724 }
00725 }
00726
00727
00728
00735 class DumpFilter {
00736 function DumpFilter( &$sink ) {
00737 $this->sink =& $sink;
00738 }
00739
00740 function writeOpenStream( $string ) {
00741 $this->sink->writeOpenStream( $string );
00742 }
00743
00744 function writeCloseStream( $string ) {
00745 $this->sink->writeCloseStream( $string );
00746 }
00747
00748 function writeOpenPage( $page, $string ) {
00749 $this->sendingThisPage = $this->pass( $page, $string );
00750 if( $this->sendingThisPage ) {
00751 $this->sink->writeOpenPage( $page, $string );
00752 }
00753 }
00754
00755 function writeClosePage( $string ) {
00756 if( $this->sendingThisPage ) {
00757 $this->sink->writeClosePage( $string );
00758 $this->sendingThisPage = false;
00759 }
00760 }
00761
00762 function writeRevision( $rev, $string ) {
00763 if( $this->sendingThisPage ) {
00764 $this->sink->writeRevision( $rev, $string );
00765 }
00766 }
00767
00768 function writeLogItem( $rev, $string ) {
00769 $this->sink->writeRevision( $rev, $string );
00770 }
00771
00776 function pass( $page ) {
00777 return true;
00778 }
00779 }
00780
00785 class DumpNotalkFilter extends DumpFilter {
00786 function pass( $page ) {
00787 return !MWNamespace::isTalk( $page->page_namespace );
00788 }
00789 }
00790
00795 class DumpNamespaceFilter extends DumpFilter {
00796 var $invert = false;
00797 var $namespaces = array();
00798
00799 function DumpNamespaceFilter( &$sink, $param ) {
00800 parent::DumpFilter( $sink );
00801
00802 $constants = array(
00803 "NS_MAIN" => NS_MAIN,
00804 "NS_TALK" => NS_TALK,
00805 "NS_USER" => NS_USER,
00806 "NS_USER_TALK" => NS_USER_TALK,
00807 "NS_PROJECT" => NS_PROJECT,
00808 "NS_PROJECT_TALK" => NS_PROJECT_TALK,
00809 "NS_FILE" => NS_FILE,
00810 "NS_FILE_TALK" => NS_FILE_TALK,
00811 "NS_IMAGE" => NS_IMAGE,
00812 "NS_IMAGE_TALK" => NS_IMAGE_TALK,
00813 "NS_MEDIAWIKI" => NS_MEDIAWIKI,
00814 "NS_MEDIAWIKI_TALK" => NS_MEDIAWIKI_TALK,
00815 "NS_TEMPLATE" => NS_TEMPLATE,
00816 "NS_TEMPLATE_TALK" => NS_TEMPLATE_TALK,
00817 "NS_HELP" => NS_HELP,
00818 "NS_HELP_TALK" => NS_HELP_TALK,
00819 "NS_CATEGORY" => NS_CATEGORY,
00820 "NS_CATEGORY_TALK" => NS_CATEGORY_TALK );
00821
00822 if( $param{0} == '!' ) {
00823 $this->invert = true;
00824 $param = substr( $param, 1 );
00825 }
00826
00827 foreach( explode( ',', $param ) as $key ) {
00828 $key = trim( $key );
00829 if( isset( $constants[$key] ) ) {
00830 $ns = $constants[$key];
00831 $this->namespaces[$ns] = true;
00832 } elseif( is_numeric( $key ) ) {
00833 $ns = intval( $key );
00834 $this->namespaces[$ns] = true;
00835 } else {
00836 throw new MWException( "Unrecognized namespace key '$key'\n" );
00837 }
00838 }
00839 }
00840
00841 function pass( $page ) {
00842 $match = isset( $this->namespaces[$page->page_namespace] );
00843 return $this->invert xor $match;
00844 }
00845 }
00846
00847
00852 class DumpLatestFilter extends DumpFilter {
00853 var $page, $pageString, $rev, $revString;
00854
00855 function writeOpenPage( $page, $string ) {
00856 $this->page = $page;
00857 $this->pageString = $string;
00858 }
00859
00860 function writeClosePage( $string ) {
00861 if( $this->rev ) {
00862 $this->sink->writeOpenPage( $this->page, $this->pageString );
00863 $this->sink->writeRevision( $this->rev, $this->revString );
00864 $this->sink->writeClosePage( $string );
00865 }
00866 $this->rev = null;
00867 $this->revString = null;
00868 $this->page = null;
00869 $this->pageString = null;
00870 }
00871
00872 function writeRevision( $rev, $string ) {
00873 if( $rev->rev_id == $this->page->page_latest ) {
00874 $this->rev = $rev;
00875 $this->revString = $string;
00876 }
00877 }
00878 }
00879
00884 class DumpMultiWriter {
00885 function DumpMultiWriter( $sinks ) {
00886 $this->sinks = $sinks;
00887 $this->count = count( $sinks );
00888 }
00889
00890 function writeOpenStream( $string ) {
00891 for( $i = 0; $i < $this->count; $i++ ) {
00892 $this->sinks[$i]->writeOpenStream( $string );
00893 }
00894 }
00895
00896 function writeCloseStream( $string ) {
00897 for( $i = 0; $i < $this->count; $i++ ) {
00898 $this->sinks[$i]->writeCloseStream( $string );
00899 }
00900 }
00901
00902 function writeOpenPage( $page, $string ) {
00903 for( $i = 0; $i < $this->count; $i++ ) {
00904 $this->sinks[$i]->writeOpenPage( $page, $string );
00905 }
00906 }
00907
00908 function writeClosePage( $string ) {
00909 for( $i = 0; $i < $this->count; $i++ ) {
00910 $this->sinks[$i]->writeClosePage( $string );
00911 }
00912 }
00913
00914 function writeRevision( $rev, $string ) {
00915 for( $i = 0; $i < $this->count; $i++ ) {
00916 $this->sinks[$i]->writeRevision( $rev, $string );
00917 }
00918 }
00919 }
00920
00921 function xmlsafe( $string ) {
00922 $fname = 'xmlsafe';
00923 wfProfileIn( $fname );
00924
00930 $string = UtfNormal::cleanUp( $string );
00931
00932 $string = htmlspecialchars( $string );
00933 wfProfileOut( $fname );
00934 return $string;
00935 }