wfMsgForContentNoTrans() was removed
[mediawiki.git] / includes / export / DumpPipeOutput.php
blob61177abe2516dc3d0ae7c43d294003e07c86acb9
1 <?php
2 /**
3 * Stream outputter to send data to a file via some filter program.
4 * Even if compression is available in a library, using a separate
5 * program can allow us to make use of a multi-processor system.
7 * Copyright © 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
8 * https://www.mediawiki.org/
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * http://www.gnu.org/copyleft/gpl.html
25 * @file
28 /**
29 * @ingroup Dump
31 class DumpPipeOutput extends DumpFileOutput {
32 protected $command, $filename;
33 protected $procOpenResource = false;
35 /**
36 * @param string $command
37 * @param string $file
39 function __construct( $command, $file = null ) {
40 if ( !is_null( $file ) ) {
41 $command .= " > " . wfEscapeShellArg( $file );
44 $this->startCommand( $command );
45 $this->command = $command;
46 $this->filename = $file;
49 /**
50 * @param string $string
52 function writeCloseStream( $string ) {
53 parent::writeCloseStream( $string );
54 if ( $this->procOpenResource ) {
55 proc_close( $this->procOpenResource );
56 $this->procOpenResource = false;
60 /**
61 * @param string $command
63 function startCommand( $command ) {
64 $spec = array(
65 0 => array( "pipe", "r" ),
67 $pipes = array();
68 $this->procOpenResource = proc_open( $command, $spec, $pipes );
69 $this->handle = $pipes[0];
72 /**
73 * @param string $newname
75 function closeRenameAndReopen( $newname ) {
76 $this->closeAndRename( $newname, true );
79 /**
80 * @param string $newname
81 * @param bool $open
83 function closeAndRename( $newname, $open = false ) {
84 $newname = $this->checkRenameArgCount( $newname );
85 if ( $newname ) {
86 if ( $this->handle ) {
87 fclose( $this->handle );
88 $this->handle = false;
90 if ( $this->procOpenResource ) {
91 proc_close( $this->procOpenResource );
92 $this->procOpenResource = false;
94 $this->renameOrException( $newname );
95 if ( $open ) {
96 $command = $this->command;
97 $command .= " > " . wfEscapeShellArg( $this->filename );
98 $this->startCommand( $command );