Remove last wfDie()s from maintenance
[lhc/web/wiklou.git] / maintenance / dumpBackup.php
1 <?php
2 /**
3 * Script that dumps wiki pages or logging database into an XML interchange
4 * wrapper format for export or backup
5 *
6 * Copyright © 2005 Brion Vibber <brion@pobox.com>
7 * http://www.mediawiki.org/
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
23 *
24 * @file
25 * @ingroup Dump Maintenance
26 */
27
28 $originalDir = getcwd();
29
30 $optionsWithArgs = array( 'pagelist', 'start', 'end' );
31
32 require_once( dirname( __FILE__ ) . '/commandLine.inc' );
33 require_once( 'backup.inc' );
34
35 $dumper = new BackupDumper( $argv );
36
37 if ( isset( $options['quiet'] ) ) {
38 $dumper->reporting = false;
39 }
40
41 if ( isset( $options['pagelist'] ) ) {
42 $olddir = getcwd();
43 chdir( $originalDir );
44 $pages = file( $options['pagelist'] );
45 chdir( $olddir );
46 if ( $pages === false ) {
47 echo( "Unable to open file {$options['pagelist']}\n" );
48 die(1);
49 }
50 $pages = array_map( 'trim', $pages );
51 $dumper->pages = array_filter( $pages, create_function( '$x', 'return $x !== "";' ) );
52 }
53
54 if ( isset( $options['start'] ) ) {
55 $dumper->startId = intval( $options['start'] );
56 }
57 if ( isset( $options['end'] ) ) {
58 $dumper->endId = intval( $options['end'] );
59 }
60 $dumper->skipHeader = isset( $options['skip-header'] );
61 $dumper->skipFooter = isset( $options['skip-footer'] );
62 $dumper->dumpUploads = isset( $options['uploads'] );
63 $dumper->dumpUploadFileContents = isset( $options['include-files'] );
64
65 $textMode = isset( $options['stub'] ) ? WikiExporter::STUB : WikiExporter::TEXT;
66
67 if ( isset( $options['full'] ) ) {
68 $dumper->dump( WikiExporter::FULL, $textMode );
69 } elseif ( isset( $options['current'] ) ) {
70 $dumper->dump( WikiExporter::CURRENT, $textMode );
71 } elseif ( isset( $options['stable'] ) ) {
72 $dumper->dump( WikiExporter::STABLE, $textMode );
73 } elseif ( isset( $options['logs'] ) ) {
74 $dumper->dump( WikiExporter::LOGS );
75 } else {
76 $dumper->progress( <<<ENDS
77 This script dumps the wiki page or logging database into an
78 XML interchange wrapper format for export or backup.
79
80 XML output is sent to stdout; progress reports are sent to stderr.
81
82 Usage: php dumpBackup.php <action> [<options>]
83 Actions:
84 --full Dump all revisions of every page.
85 --current Dump only the latest revision of every page.
86 --logs Dump all log events.
87 --stable Stable versions of pages?
88 --pagelist=<file>
89 Where <file> is a list of page titles to be dumped
90
91 Options:
92 --quiet Don't dump status reports to stderr.
93 --report=n Report position and speed after every n pages processed.
94 (Default: 100)
95 --server=h Force reading from MySQL server h
96 --start=n Start from page_id or log_id n
97 --end=n Stop before page_id or log_id n (exclusive)
98 --skip-header Don't output the <mediawiki> header
99 --skip-footer Don't output the </mediawiki> footer
100 --stub Don't perform old_text lookups; for 2-pass dump
101 --uploads Include upload records without files
102 --include-files Include files within the XML stream
103 --conf=<file> Use the specified configuration file (LocalSettings.php)
104
105 --wiki=<wiki> Only back up the specified <wiki>
106
107 Fancy stuff: (Works? Add examples please.)
108 --plugin=<class>[:<file>] Load a dump plugin class
109 --output=<type>:<file> Begin a filtered output stream;
110 <type>s: file, gzip, bzip2, 7zip
111 --filter=<type>[:<options>] Add a filter on an output branch
112
113 ENDS
114 );
115 }