r85644 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85643‎ | r85644 | r85645 >
Date:21:44, 7 April 2011
Author:btongminh
Status:reverted
Tags:
Comment:
Second part of bug bug 22881: Allow exporting files along with the XML as mimepart/related file. The patch attached to that bug was unfortunately not up to coding standards, so I rewrote this part myself.
Modified paths:
  • /trunk/phase3/includes/Export.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Export.php
@@ -35,6 +35,8 @@
3636 var $author_list = "" ;
3737
3838 var $dumpUploads = false;
 39+ var $multiPart = false;
 40+ var $files = array();
3941
4042 const FULL = 1;
4143 const CURRENT = 2;
@@ -86,12 +88,23 @@
8789
8890 public function openStream() {
8991 $output = $this->writer->openStream();
90 - $this->sink->writeOpenStream( $output );
 92+
 93+ if ( $this->multiPart ) {
 94+ $this->openMultipart();
 95+ $this->sink->write( $output );
 96+ } else {
 97+ $this->sink->writeOpenStream( $output );
 98+ }
9199 }
92100
93101 public function closeStream() {
94102 $output = $this->writer->closeStream();
95 - $this->sink->writeCloseStream( $output );
 103+ if ( $this->multiPart ) {
 104+ $this->sink->write( $output );
 105+ $this->closeMultipart();
 106+ } else {
 107+ $this->sink->writeCloseStream( $output );
 108+ }
96109 }
97110
98111 /**
@@ -314,6 +327,7 @@
315328 $output = '';
316329 if ( $this->dumpUploads ) {
317330 $output .= $this->writer->writeUploads( $last );
 331+ $this->attachUploads( $last );
318332 }
319333 $output .= $this->writer->closePage();
320334 $this->sink->writeClosePage( $output );
@@ -329,6 +343,7 @@
330344 $output = '';
331345 if ( $this->dumpUploads ) {
332346 $output .= $this->writer->writeUploads( $last );
 347+ $this->attachUploads( $last );
333348 }
334349 $output .= $this->author_list;
335350 $output .= $this->writer->closePage();
@@ -342,6 +357,38 @@
343358 $this->sink->writeLogItem( $row, $output );
344359 }
345360 }
 361+
 362+ protected function attachUploads( $row ) {
 363+ $title = Title::newFromRow( $row );
 364+ $file = wfLocalFile( $title );
 365+ $this->files[] = $file;
 366+ $this->files = array_merge( $this->files, $file->getHistory() );
 367+ }
 368+
 369+ protected function openMultipart() {
 370+ # Multipart boundary purposely invalid XML
 371+ $this->boundary = '<' . dechex( mt_rand() ) . dechex( mt_rand() ) . '<';
 372+ $this->sink->writeOpenStream(
 373+ "Content-Type: multipart/related; boundary={$this->boundary};" .
 374+ " type=text/xml\n\n" .
 375+ "--{$this->boundary}\nContent-Type: text/xml\n\n"
 376+ );
 377+ }
 378+
 379+ protected function closeMultipart() {
 380+ $output = '';
 381+
 382+ foreach ( $this->files as $file ) {
 383+ $output .= "\n--{$this->boundary}\n" .
 384+ 'Content-Type: ' . $file->getMimeType() . "\n" .
 385+ 'Content-ID: ' . $file->getRel() . "\n" .
 386+ 'Content-Length: ' . $file->getSize() . "\n" .
 387+ 'X-Sha1Base36: ' . $file->getSha1() . "\n\n";
 388+ $this->sink->write( $output );
 389+ $this->sink->write( file_get_contents( $file->getPath() ) );
 390+ }
 391+ $this->sink->writeCloseStream( "\n--{$this->boundary}\n" );
 392+ }
346393 }
347394
348395 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r85722Revert r85644. Multipart sucks because it is hard to parse and because you ne...btongminh14:43, 9 April 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r85635First part of bug 22881: Allow uploading directly into the archive to support...btongminh20:19, 7 April 2011

Status & tagging log