const FULL = 0;
const CURRENT = 1;
+ const LOGS = 2;
const BUFFER = 0;
const STREAM = 1;
}
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
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' );
}
$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 ) {
* @param $resultset ResultWrapper
* @access private
*/
- function outputStream( $resultset ) {
+ function outputPageStream( $resultset ) {
$last = null;
while( $row = $resultset->fetchObject() ) {
if( is_null( $last ) ||
}
$resultset->free();
}
+
+ function outputLogStream( $resultset ) {
+ while( $row = $resultset->fetchObject() ) {
+ $output = $this->writer->writeLogItem( $row );
+ $this->sink->writeLogItem( $row, $output );
+ }
+ $resultset->free();
+ }
}
/**
wfProfileOut( $fname );
return $out;
}
+
+ /**
+ * Dumps a <logitem> 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 = " <logitem>\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 .= " </logitem>\n";
+
+ wfProfileOut( $fname );
+ return $out;
+ }
function writeTimestamp( $timestamp ) {
$ts = wfTimestamp( TS_ISO_8601, $timestamp );
function writeRevision( $rev, $string ) {
$this->write( $string );
}
+
+ function writeLogItem( $rev, $string ) {
+ $this->write( $string );
+ }
/**
* Override to write to a different stream type.
$this->sink->writeRevision( $rev, $string );
}
}
+
+ function writeLogItem( $rev, $string ) {
+ $this->sink->writeRevision( $rev, $string );
+ }
/**
* Override for page-based filter types.
// 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' ) )
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 );
}