Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 25 |
|
0.00% |
0 / 11 |
CRAP | |
0.00% |
0 / 1 |
SevenZipStream | |
0.00% |
0 / 25 |
|
0.00% |
0 / 11 |
240 | |
0.00% |
0 / 1 |
register | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
stripPath | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
stream_open | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
20 | |||
url_stat | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
stream_close | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
stream_flush | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
stream_read | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
stream_write | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
stream_tell | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
stream_eof | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
stream_seek | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * 7z stream wrapper |
4 | * |
5 | * Copyright © 2005 Brooke Vibber <bvibber@wikimedia.org> |
6 | * https://www.mediawiki.org/ |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
17 | * |
18 | * You should have received a copy of the GNU General Public License along |
19 | * with this program; if not, write to the Free Software Foundation, Inc., |
20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
21 | * http://www.gnu.org/copyleft/gpl.html |
22 | * |
23 | * @file |
24 | * @ingroup Maintenance |
25 | */ |
26 | |
27 | use MediaWiki\Shell\Shell; |
28 | |
29 | /** |
30 | * Stream wrapper around 7za filter program. |
31 | * Required since we can't pass an open file resource to XMLReader->open() |
32 | * which is used for the text prefetch. |
33 | * |
34 | * @ingroup Maintenance |
35 | */ |
36 | class SevenZipStream { |
37 | /** @var resource|false */ |
38 | protected $stream; |
39 | |
40 | /** @var resource|null Must exists on stream wrapper class */ |
41 | public $context; |
42 | |
43 | public static function register() { |
44 | static $done = false; |
45 | if ( !$done ) { |
46 | $done = true; |
47 | stream_wrapper_register( 'mediawiki.compress.7z', self::class ); |
48 | } |
49 | } |
50 | |
51 | private function stripPath( $path ) { |
52 | $prefix = 'mediawiki.compress.7z://'; |
53 | |
54 | return substr( $path, strlen( $prefix ) ); |
55 | } |
56 | |
57 | public function stream_open( $path, $mode, $options, &$opened_path ) { |
58 | if ( $mode[0] == 'r' ) { |
59 | $options = 'e -bd -so'; |
60 | } elseif ( $mode[0] == 'w' ) { |
61 | $options = 'a -bd -si'; |
62 | } else { |
63 | return false; |
64 | } |
65 | $arg = Shell::escape( $this->stripPath( $path ) ); |
66 | $command = "7za $options $arg"; |
67 | if ( !wfIsWindows() ) { |
68 | // Suppress the stupid messages on stderr |
69 | $command .= ' 2>/dev/null'; |
70 | } |
71 | // popen() doesn't like two-letter modes |
72 | $this->stream = popen( $command, $mode[0] ); |
73 | return ( $this->stream !== false ); |
74 | } |
75 | |
76 | public function url_stat( $path, $flags ) { |
77 | return stat( $this->stripPath( $path ) ); |
78 | } |
79 | |
80 | public function stream_close() { |
81 | return fclose( $this->stream ); |
82 | } |
83 | |
84 | public function stream_flush() { |
85 | return fflush( $this->stream ); |
86 | } |
87 | |
88 | public function stream_read( $count ) { |
89 | return fread( $this->stream, $count ); |
90 | } |
91 | |
92 | public function stream_write( $data ) { |
93 | return fwrite( $this->stream, $data ); |
94 | } |
95 | |
96 | public function stream_tell() { |
97 | return ftell( $this->stream ); |
98 | } |
99 | |
100 | public function stream_eof() { |
101 | return feof( $this->stream ); |
102 | } |
103 | |
104 | public function stream_seek( $offset, $whence ) { |
105 | return fseek( $this->stream, $offset, $whence ); |
106 | } |
107 | } |