From: Aaron Schulz Date: Thu, 18 Sep 2008 00:02:57 +0000 (+0000) Subject: * Add XML log dump support X-Git-Tag: 1.31.0-rc.0~45241 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=7fafa40041136e92ad3d7fd298420584281dd947;p=lhc%2Fweb%2Fwiklou.git * Add XML log dump support * TODO: make importer --- diff --git a/includes/Export.php b/includes/Export.php index 7d0a824e32..61229e0fbb 100644 --- a/includes/Export.php +++ b/includes/Export.php @@ -32,6 +32,7 @@ class WikiExporter { const FULL = 0; const CURRENT = 1; + const LOGS = 2; const BUFFER = 0; const STREAM = 1; @@ -108,6 +109,18 @@ class WikiExporter { } return $this->dumpFrom( $condition ); } + + function allLogs() { + return $this->dumpFrom( '' ); + } + + function logsByRange( $start, $end ) { + $condition = 'log_id >= ' . intval( $start ); + if( $end ) { + $condition .= ' AND log_id < ' . intval( $end ); + } + return $this->dumpFrom( $condition ); + } /** * @param $title Title @@ -166,7 +179,25 @@ class WikiExporter { function dumpFrom( $cond = '' ) { $fname = 'WikiExporter::dumpFrom'; wfProfileIn( $fname ); - + + # For logs dumps... + if( $this->history & self::LOGS ) { + $where = array( 'user_id = log_user' ); + # Hide private logs + $where[] = LogEventsList::getExcludeClause( $this->db ); + if( $cond ) $where[] = $cond; + $result = $this->db->select( array('logging','user'), + '*', + $where, + $fname, + array( 'ORDER BY' => 'log_id') + ); + $wrapper = $this->db->resultObject( $result ); + $this->outputLogStream( $wrapper ); + wfProfileOut( $fname ); + return; + } + # For page dumps... $page = $this->db->tableName( 'page' ); $revision = $this->db->tableName( 'revision' ); $text = $this->db->tableName( 'text' ); @@ -234,10 +265,10 @@ class WikiExporter { } $result = $this->db->query( $sql, $fname ); $wrapper = $this->db->resultObject( $result ); - $this->outputStream( $wrapper ); + $this->outputPageStream( $wrapper ); if ( $this->list_authors ) { - $this->outputStream( $wrapper ); + $this->outputPageStream( $wrapper ); } if( $this->buffer == WikiExporter::STREAM ) { @@ -260,7 +291,7 @@ class WikiExporter { * @param $resultset ResultWrapper * @access private */ - function outputStream( $resultset ) { + function outputPageStream( $resultset ) { $last = null; while( $row = $resultset->fetchObject() ) { if( is_null( $last ) || @@ -292,6 +323,14 @@ class WikiExporter { } $resultset->free(); } + + function outputLogStream( $resultset ) { + while( $row = $resultset->fetchObject() ) { + $output = $this->writer->writeLogItem( $row ); + $this->sink->writeLogItem( $row, $output ); + } + $resultset->free(); + } } /** @@ -465,6 +504,54 @@ class XmlDumpWriter { wfProfileOut( $fname ); return $out; } + + /** + * Dumps a section on the output stream, with + * data filled in from the given database row. + * + * @param $row object + * @return string + * @access private + */ + function writeLogItem( $row ) { + $fname = 'WikiExporter::writeLogItem'; + wfProfileIn( $fname ); + + $out = " \n"; + $out .= " " . wfElement( 'id', null, strval( $row->log_id ) ) . "\n"; + + $out .= $this->writeTimestamp( $row->log_timestamp ); + + if( $row->log_deleted & LogPage::DELETED_USER ) { + $out .= " " . wfElement( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n"; + } else { + $out .= $this->writeContributor( $row->log_user, $row->user_name ); + } + + if( $row->log_deleted & LogPage::DELETED_COMMENT ) { + $out .= " " . wfElement( 'comment', array( 'deleted' => 'deleted' ) ) . "\n"; + } elseif( $row->log_comment != '' ) { + $out .= " " . wfElementClean( 'comment', null, strval( $row->log_comment ) ) . "\n"; + } + + $out .= " " . wfElement( 'type', null, strval( $row->log_type ) ) . "\n"; + $out .= " " . wfElement( 'action', null, strval( $row->log_action ) ) . "\n"; + + if( $row->log_deleted & LogPage::DELETED_ACTION ) { + $out .= " " . wfElement( 'text', array( 'deleted' => 'deleted' ) ) . "\n"; + } else { + $title = Title::makeTitle( $row->log_namespace, $row->log_title ); + $out .= " " . wfElementClean( 'title', null, $title->getPrefixedText() ) . "\n"; + $out .= " " . wfElementClean( 'params', + array( 'xml:space' => 'preserve' ), + strval( $row->log_params ) ) . "\n"; + } + + $out .= " \n"; + + wfProfileOut( $fname ); + return $out; + } function writeTimestamp( $timestamp ) { $ts = wfTimestamp( TS_ISO_8601, $timestamp ); @@ -539,6 +626,10 @@ class DumpOutput { function writeRevision( $rev, $string ) { $this->write( $string ); } + + function writeLogItem( $rev, $string ) { + $this->write( $string ); + } /** * Override to write to a different stream type. @@ -654,6 +745,10 @@ class DumpFilter { $this->sink->writeRevision( $rev, $string ); } } + + function writeLogItem( $rev, $string ) { + $this->sink->writeRevision( $rev, $string ); + } /** * Override for page-based filter types. diff --git a/maintenance/backup.inc b/maintenance/backup.inc index bf52c1f358..e2e5363ece 100644 --- a/maintenance/backup.inc +++ b/maintenance/backup.inc @@ -175,7 +175,7 @@ class BackupDumper { // extension point for subclasses to add options } - function dump( $history, $text = MW_EXPORT_TEXT ) { + function dump( $history, $text = WikiExporter::TEXT ) { # Notice messages will foul up your XML output even if they're # relatively harmless. if( ini_get( 'display_errors' ) ) @@ -192,13 +192,21 @@ class BackupDumper { if( !$this->skipHeader ) $exporter->openStream(); - - if( is_null( $this->pages ) ) { + # Log item dumps: all or by range + if( $history & WikiExporter::LOGS ) { + if( $this->startId || $this->endId ) { + $exporter->logsByRange( $this->startId, $this->endId ); + } else { + $exporter->allLogs(); + } + # Page dumps: all or by page ID range + } else if( is_null( $this->pages ) ) { if( $this->startId || $this->endId ) { $exporter->pagesByRange( $this->startId, $this->endId ); } else { $exporter->allPages(); } + # Dump of specific pages } else { $exporter->pagesByName( $this->pages ); } diff --git a/maintenance/dumpBackup.php b/maintenance/dumpBackup.php index bb4312428a..de7ce65529 100644 --- a/maintenance/dumpBackup.php +++ b/maintenance/dumpBackup.php @@ -63,6 +63,8 @@ if( isset( $options['full'] ) ) { $dumper->dump( WikiExporter::FULL, $textMode ); } elseif( isset( $options['current'] ) ) { $dumper->dump( WikiExporter::CURRENT, $textMode ); +} elseif( isset( $options['logs'] ) ) { + $dumper->dump( WikiExporter::LOGS ); } else { $dumper->progress( << [] Actions: --full Dump complete history of every page. --current Includes only the latest revision of each page. + --logs Dump action logs for every page. Options: --quiet Don't dump status reports to stderr.