r54561 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54560‎ | r54561 | r54562 >
Date:00:53, 7 August 2009
Author:emufarmers
Status:resolved (Comments)
Tags:
Comment:
(bug 19289) importDump.php can now handle bzip2 and 7zip.

I split out our 7zip stream wrapper into its own file, 7zip.inc.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/maintenance/7zip.inc (added) (history)
  • /trunk/phase3/maintenance/dumpTextPass.php (modified) (history)
  • /trunk/phase3/maintenance/importDump.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/dumpTextPass.php
@@ -26,79 +26,11 @@
2727
2828 require_once( dirname(__FILE__) . '/commandLine.inc' );
2929 require_once( 'backup.inc' );
 30+require_once( '7zip.inc' );
3031
3132 /**
32 - * Stream wrapper around 7za filter program.
33 - * Required since we can't pass an open file resource to XMLReader->open()
34 - * which is used for the text prefetch.
35 - *
3633 * @ingroup Maintenance
3734 */
38 -class SevenZipStream {
39 - var $stream;
40 -
41 - private function stripPath( $path ) {
42 - $prefix = 'mediawiki.compress.7z://';
43 - return substr( $path, strlen( $prefix ) );
44 - }
45 -
46 - function stream_open( $path, $mode, $options, &$opened_path ) {
47 - if( $mode{0} == 'r' ) {
48 - $options = 'e -bd -so';
49 - } elseif( $mode{0} == 'w' ) {
50 - $options = 'a -bd -si';
51 - } else {
52 - return false;
53 - }
54 - $arg = wfEscapeShellArg( $this->stripPath( $path ) );
55 - $command = "7za $options $arg";
56 - if( !wfIsWindows() ) {
57 - // Suppress the stupid messages on stderr
58 - $command .= ' 2>/dev/null';
59 - }
60 - $this->stream = popen( $command, $mode );
61 - return ($this->stream !== false);
62 - }
63 -
64 - function url_stat( $path, $flags ) {
65 - return stat( $this->stripPath( $path ) );
66 - }
67 -
68 - // This is all so lame; there should be a default class we can extend
69 -
70 - function stream_close() {
71 - return fclose( $this->stream );
72 - }
73 -
74 - function stream_flush() {
75 - return fflush( $this->stream );
76 - }
77 -
78 - function stream_read( $count ) {
79 - return fread( $this->stream, $count );
80 - }
81 -
82 - function stream_write( $data ) {
83 - return fwrite( $this->stream, $data );
84 - }
85 -
86 - function stream_tell() {
87 - return ftell( $this->stream );
88 - }
89 -
90 - function stream_eof() {
91 - return feof( $this->stream );
92 - }
93 -
94 - function stream_seek( $offset, $whence ) {
95 - return fseek( $this->stream, $offset, $whence );
96 - }
97 -}
98 -stream_wrapper_register( 'mediawiki.compress.7z', 'SevenZipStream' );
99 -
100 -/**
101 - * @ingroup Maintenance
102 - */
10335 class TextPassDumper extends BackupDumper {
10436 var $prefetch = null;
10537 var $input = "php://stdin";
Index: trunk/phase3/maintenance/7zip.inc
@@ -0,0 +1,69 @@
 2+<?php
 3+/**
 4+ * Stream wrapper around 7za filter program.
 5+ * Required since we can't pass an open file resource to XMLReader->open()
 6+ * which is used for the text prefetch.
 7+ *
 8+ * @ingroup Maintenance
 9+ */
 10+class SevenZipStream {
 11+ var $stream;
 12+
 13+ private function stripPath( $path ) {
 14+ $prefix = 'mediawiki.compress.7z://';
 15+ return substr( $path, strlen( $prefix ) );
 16+ }
 17+
 18+ function stream_open( $path, $mode, $options, &$opened_path ) {
 19+ if( $mode[0] == 'r' ) {
 20+ $options = 'e -bd -so';
 21+ } elseif( $mode[0] == 'w' ) {
 22+ $options = 'a -bd -si';
 23+ } else {
 24+ return false;
 25+ }
 26+ $arg = wfEscapeShellArg( $this->stripPath( $path ) );
 27+ $command = "7za $options $arg";
 28+ if( !wfIsWindows() ) {
 29+ // Suppress the stupid messages on stderr
 30+ $command .= ' 2>/dev/null';
 31+ }
 32+ $this->stream = popen( $command, $mode );
 33+ return ($this->stream !== false);
 34+ }
 35+
 36+ function url_stat( $path, $flags ) {
 37+ return stat( $this->stripPath( $path ) );
 38+ }
 39+
 40+ // This is all so lame; there should be a default class we can extend
 41+
 42+ function stream_close() {
 43+ return fclose( $this->stream );
 44+ }
 45+
 46+ function stream_flush() {
 47+ return fflush( $this->stream );
 48+ }
 49+
 50+ function stream_read( $count ) {
 51+ return fread( $this->stream, $count );
 52+ }
 53+
 54+ function stream_write( $data ) {
 55+ return fwrite( $this->stream, $data );
 56+ }
 57+
 58+ function stream_tell() {
 59+ return ftell( $this->stream );
 60+ }
 61+
 62+ function stream_eof() {
 63+ return feof( $this->stream );
 64+ }
 65+
 66+ function stream_seek( $offset, $whence ) {
 67+ return fseek( $this->stream, $offset, $whence );
 68+ }
 69+}
 70+stream_wrapper_register( 'mediawiki.compress.7z', 'SevenZipStream' );
\ No newline at end of file
Property changes on: trunk/phase3/maintenance/7zip.inc
___________________________________________________________________
Added: svn:eol-style
171 + native
Index: trunk/phase3/maintenance/importDump.php
@@ -25,6 +25,7 @@
2626 $optionsWithArgs = array( 'report' );
2727
2828 require_once( dirname(__FILE__) . '/commandLine.inc' );
 29+require_once( '7zip.inc' );
2930
3031 /**
3132 * @ingroup Maintenance
@@ -115,10 +116,19 @@
116117 }
117118
118119 function importFromFile( $filename ) {
 120+ $t = true;
119121 if( preg_match( '/\.gz$/', $filename ) ) {
120122 $filename = 'compress.zlib://' . $filename;
121123 }
122 - $file = fopen( $filename, 'rt' );
 124+ elseif( preg_match( '/\.bz2$/', $filename ) ) {
 125+ $filename = 'compress.bzip2://' . $filename;
 126+ }
 127+ elseif( preg_match( '/\.7z$/', $filename ) ) {
 128+ $filename = 'mediawiki.compress.7z://' . $filename;
 129+ $t = false;
 130+ }
 131+
 132+ $file = fopen( $filename, $t ? 'rt' : 't' ); //our 7zip wrapper uses popen, which seems not to like two-letter modes
123133 return $this->importFromHandle( $file );
124134 }
125135
Index: trunk/phase3/RELEASE-NOTES
@@ -393,6 +393,7 @@
394394 * (bug 16084) Default memory limit has be increased to 50M, see $wgMemoryLimit
395395 * (bug 17864/19519) Added proper input normalization in Special:UserRights
396396 * (bug 20086) Add Hook to add extra statistics at the end of Special:Statistics
 397+* (bug 19289) importDump.php can now handle bzip2 and 7zip
397398
398399 == API changes in 1.16 ==
399400

Follow-up revisions

RevisionCommit summaryAuthorDate
r74253Fix issues after r54561 which avoided use of the 7z wrapper....platonides15:04, 4 October 2010

Comments

#Comment by Brion VIBBER (talk | contribs)   05:14, 19 August 2009

Use the class autoloader rather than an explicit require_once here...

#Comment by 😂 (talk | contribs)   11:29, 19 August 2009

Resolved in r55309

Status & tagging log