r40968 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40967‎ | r40968 | r40969 >
Date:00:02, 18 September 2008
Author:aaron
Status:old
Tags:
Comment:
* Add XML log dump support
* TODO: make importer
Modified paths:
  • /trunk/phase3/includes/Export.php (modified) (history)
  • /trunk/phase3/maintenance/backup.inc (modified) (history)
  • /trunk/phase3/maintenance/dumpBackup.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/backup.inc
@@ -175,7 +175,7 @@
176176 // extension point for subclasses to add options
177177 }
178178
179 - function dump( $history, $text = MW_EXPORT_TEXT ) {
 179+ function dump( $history, $text = WikiExporter::TEXT ) {
180180 # Notice messages will foul up your XML output even if they're
181181 # relatively harmless.
182182 if( ini_get( 'display_errors' ) )
@@ -192,13 +192,21 @@
193193
194194 if( !$this->skipHeader )
195195 $exporter->openStream();
196 -
197 - if( is_null( $this->pages ) ) {
 196+ # Log item dumps: all or by range
 197+ if( $history & WikiExporter::LOGS ) {
198198 if( $this->startId || $this->endId ) {
 199+ $exporter->logsByRange( $this->startId, $this->endId );
 200+ } else {
 201+ $exporter->allLogs();
 202+ }
 203+ # Page dumps: all or by page ID range
 204+ } else if( is_null( $this->pages ) ) {
 205+ if( $this->startId || $this->endId ) {
199206 $exporter->pagesByRange( $this->startId, $this->endId );
200207 } else {
201208 $exporter->allPages();
202209 }
 210+ # Dump of specific pages
203211 } else {
204212 $exporter->pagesByName( $this->pages );
205213 }
Index: trunk/phase3/maintenance/dumpBackup.php
@@ -63,6 +63,8 @@
6464 $dumper->dump( WikiExporter::FULL, $textMode );
6565 } elseif( isset( $options['current'] ) ) {
6666 $dumper->dump( WikiExporter::CURRENT, $textMode );
 67+} elseif( isset( $options['logs'] ) ) {
 68+ $dumper->dump( WikiExporter::LOGS );
6769 } else {
6870 $dumper->progress( <<<ENDS
6971 This script dumps the wiki page database into an XML interchange wrapper
@@ -74,6 +76,7 @@
7577 Actions:
7678 --full Dump complete history of every page.
7779 --current Includes only the latest revision of each page.
 80+ --logs Dump action logs for every page.
7881
7982 Options:
8083 --quiet Don't dump status reports to stderr.
Index: trunk/phase3/includes/Export.php
@@ -32,6 +32,7 @@
3333
3434 const FULL = 0;
3535 const CURRENT = 1;
 36+ const LOGS = 2;
3637
3738 const BUFFER = 0;
3839 const STREAM = 1;
@@ -108,6 +109,18 @@
109110 }
110111 return $this->dumpFrom( $condition );
111112 }
 113+
 114+ function allLogs() {
 115+ return $this->dumpFrom( '' );
 116+ }
 117+
 118+ function logsByRange( $start, $end ) {
 119+ $condition = 'log_id >= ' . intval( $start );
 120+ if( $end ) {
 121+ $condition .= ' AND log_id < ' . intval( $end );
 122+ }
 123+ return $this->dumpFrom( $condition );
 124+ }
112125
113126 /**
114127 * @param $title Title
@@ -166,7 +179,25 @@
167180 function dumpFrom( $cond = '' ) {
168181 $fname = 'WikiExporter::dumpFrom';
169182 wfProfileIn( $fname );
170 -
 183+
 184+ # For logs dumps...
 185+ if( $this->history & self::LOGS ) {
 186+ $where = array( 'user_id = log_user' );
 187+ # Hide private logs
 188+ $where[] = LogEventsList::getExcludeClause( $this->db );
 189+ if( $cond ) $where[] = $cond;
 190+ $result = $this->db->select( array('logging','user'),
 191+ '*',
 192+ $where,
 193+ $fname,
 194+ array( 'ORDER BY' => 'log_id')
 195+ );
 196+ $wrapper = $this->db->resultObject( $result );
 197+ $this->outputLogStream( $wrapper );
 198+ wfProfileOut( $fname );
 199+ return;
 200+ }
 201+ # For page dumps...
171202 $page = $this->db->tableName( 'page' );
172203 $revision = $this->db->tableName( 'revision' );
173204 $text = $this->db->tableName( 'text' );
@@ -234,10 +265,10 @@
235266 }
236267 $result = $this->db->query( $sql, $fname );
237268 $wrapper = $this->db->resultObject( $result );
238 - $this->outputStream( $wrapper );
 269+ $this->outputPageStream( $wrapper );
239270
240271 if ( $this->list_authors ) {
241 - $this->outputStream( $wrapper );
 272+ $this->outputPageStream( $wrapper );
242273 }
243274
244275 if( $this->buffer == WikiExporter::STREAM ) {
@@ -260,7 +291,7 @@
261292 * @param $resultset ResultWrapper
262293 * @access private
263294 */
264 - function outputStream( $resultset ) {
 295+ function outputPageStream( $resultset ) {
265296 $last = null;
266297 while( $row = $resultset->fetchObject() ) {
267298 if( is_null( $last ) ||
@@ -292,6 +323,14 @@
293324 }
294325 $resultset->free();
295326 }
 327+
 328+ function outputLogStream( $resultset ) {
 329+ while( $row = $resultset->fetchObject() ) {
 330+ $output = $this->writer->writeLogItem( $row );
 331+ $this->sink->writeLogItem( $row, $output );
 332+ }
 333+ $resultset->free();
 334+ }
296335 }
297336
298337 /**
@@ -465,7 +504,55 @@
466505 wfProfileOut( $fname );
467506 return $out;
468507 }
 508+
 509+ /**
 510+ * Dumps a <logitem> section on the output stream, with
 511+ * data filled in from the given database row.
 512+ *
 513+ * @param $row object
 514+ * @return string
 515+ * @access private
 516+ */
 517+ function writeLogItem( $row ) {
 518+ $fname = 'WikiExporter::writeLogItem';
 519+ wfProfileIn( $fname );
469520
 521+ $out = " <logitem>\n";
 522+ $out .= " " . wfElement( 'id', null, strval( $row->log_id ) ) . "\n";
 523+
 524+ $out .= $this->writeTimestamp( $row->log_timestamp );
 525+
 526+ if( $row->log_deleted & LogPage::DELETED_USER ) {
 527+ $out .= " " . wfElement( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
 528+ } else {
 529+ $out .= $this->writeContributor( $row->log_user, $row->user_name );
 530+ }
 531+
 532+ if( $row->log_deleted & LogPage::DELETED_COMMENT ) {
 533+ $out .= " " . wfElement( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
 534+ } elseif( $row->log_comment != '' ) {
 535+ $out .= " " . wfElementClean( 'comment', null, strval( $row->log_comment ) ) . "\n";
 536+ }
 537+
 538+ $out .= " " . wfElement( 'type', null, strval( $row->log_type ) ) . "\n";
 539+ $out .= " " . wfElement( 'action', null, strval( $row->log_action ) ) . "\n";
 540+
 541+ if( $row->log_deleted & LogPage::DELETED_ACTION ) {
 542+ $out .= " " . wfElement( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
 543+ } else {
 544+ $title = Title::makeTitle( $row->log_namespace, $row->log_title );
 545+ $out .= " " . wfElementClean( 'title', null, $title->getPrefixedText() ) . "\n";
 546+ $out .= " " . wfElementClean( 'params',
 547+ array( 'xml:space' => 'preserve' ),
 548+ strval( $row->log_params ) ) . "\n";
 549+ }
 550+
 551+ $out .= " </logitem>\n";
 552+
 553+ wfProfileOut( $fname );
 554+ return $out;
 555+ }
 556+
470557 function writeTimestamp( $timestamp ) {
471558 $ts = wfTimestamp( TS_ISO_8601, $timestamp );
472559 return " " . wfElement( 'timestamp', null, $ts ) . "\n";
@@ -539,6 +626,10 @@
540627 function writeRevision( $rev, $string ) {
541628 $this->write( $string );
542629 }
 630+
 631+ function writeLogItem( $rev, $string ) {
 632+ $this->write( $string );
 633+ }
543634
544635 /**
545636 * Override to write to a different stream type.
@@ -654,6 +745,10 @@
655746 $this->sink->writeRevision( $rev, $string );
656747 }
657748 }
 749+
 750+ function writeLogItem( $rev, $string ) {
 751+ $this->sink->writeRevision( $rev, $string );
 752+ }
658753
659754 /**
660755 * Override for page-based filter types.