var $author_list = "" ;
var $dumpUploads = false;
+ var $dumpUploadFileContents = false;
const FULL = 1;
const CURRENT = 2;
# Generates the distinct list of authors of an article
# Not called by default (depends on $this->list_authors)
# Can be set by Special:Export when not exporting whole history
- protected function do_list_authors( $page , $revision , $cond ) {
+ protected function do_list_authors( $cond ) {
wfProfileIn( __METHOD__ );
$this->author_list = "<contributors>";
// rev_deleted
- $nothidden = '(' . $this->db->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ') = 0';
- $sql = "SELECT DISTINCT rev_user_text,rev_user FROM {$page},{$revision}
- WHERE page_id=rev_page AND $nothidden AND " . $cond ;
- $result = $this->db->query( $sql, __METHOD__ );
- $resultset = $this->db->resultObject( $result );
- foreach ( $resultset as $row ) {
+ $res = $this->db->select(
+ array( 'page', 'revision' ),
+ array( 'DISTINCT rev_user_text', 'rev_user' ),
+ array(
+ $this->db->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0',
+ $cond,
+ 'page_id = rev_id',
+ ),
+ __METHOD__
+ );
+
+ foreach ( $res as $row ) {
$this->author_list .= "<contributor>" .
"<username>" .
htmlentities( $row->rev_user_text ) .
} elseif ( $this->history & WikiExporter::CURRENT ) {
# Latest revision dumps...
if ( $this->list_authors && $cond != '' ) { // List authors, if so desired
- list( $page, $revision ) = $this->db->tableNamesN( 'page', 'revision' );
- $this->do_list_authors( $page, $revision, $cond );
+ $this->do_list_authors( $cond );
}
$join['revision'] = array( 'INNER JOIN', 'page_id=rev_page AND page_latest=rev_id' );
} elseif ( $this->history & WikiExporter::STABLE ) {
if ( isset( $last ) ) {
$output = '';
if ( $this->dumpUploads ) {
- $output .= $this->writer->writeUploads( $last );
+ $output .= $this->writer->writeUploads( $last, $this->dumpUploadFileContents );
}
$output .= $this->writer->closePage();
$this->sink->writeClosePage( $output );
if ( isset( $last ) ) {
$output = '';
if ( $this->dumpUploads ) {
- $output .= $this->writer->writeUploads( $last );
+ $output .= $this->writer->writeUploads( $last, $this->dumpUploadFileContents );
}
$output .= $this->author_list;
$output .= $this->writer->closePage();
/**
* Warning! This data is potentially inconsistent. :(
*/
- function writeUploads( $row ) {
+ function writeUploads( $row, $dumpContents = false ) {
if ( $row->page_namespace == NS_IMAGE ) {
- $img = wfFindFile( $row->page_title );
- if ( $img ) {
+ $img = wfLocalFile( $row->page_title );
+ if ( $img && $img->exists() ) {
$out = '';
foreach ( array_reverse( $img->getHistory() ) as $ver ) {
- $out .= $this->writeUpload( $ver );
+ $out .= $this->writeUpload( $ver, $dumpContents );
}
- $out .= $this->writeUpload( $img );
+ $out .= $this->writeUpload( $img, $dumpContents );
return $out;
}
}
return '';
}
- function writeUpload( $file ) {
+ function writeUpload( $file, $dumpContents = false ) {
+ if ( $file->isOld() ) {
+ $archiveName = " " .
+ Xml::element( 'archivename', null, $file->getArchiveName() ) . "\n";
+ } else {
+ $archiveName = '';
+ }
+ if ( $dumpContents ) {
+ # Dump file as base64
+ # Uses only XML-safe characters, so does not need escaping
+ $contents = ' <contents encoding="base64">' .
+ chunk_split( base64_encode( file_get_contents( $file->getPath() ) ) ) .
+ " </contents>\n";
+ } else {
+ $contents = '';
+ }
return " <upload>\n" .
$this->writeTimestamp( $file->getTimestamp() ) .
$this->writeContributor( $file->getUser( 'id' ), $file->getUser( 'text' ) ) .
" " . Xml::elementClean( 'comment', null, $file->getDescription() ) . "\n" .
" " . Xml::element( 'filename', null, $file->getName() ) . "\n" .
+ $archiveName .
" " . Xml::element( 'src', null, $file->getFullUrl() ) . "\n" .
" " . Xml::element( 'size', null, $file->getSize() ) . "\n" .
+ " " . Xml::element( 'sha1base36', null, $file->getSha1() ) . "\n" .
+ " " . Xml::element( 'rel', null, $file->getRel() ) . "\n" .
+ $contents .
" </upload>\n";
}