* (bug 2658) Fix signature time, localtime to match timezone offset again
[lhc/web/wiklou.git] / maintenance / dumpBackup.php
1 <?php
2 /**
3 * Copyright (C) 2005 Brion Vibber <brion@pobox.com>
4 * http://www.mediawiki.org/
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * http://www.gnu.org/copyleft/gpl.html
20 *
21 * @package MediaWiki
22 * @subpackage SpecialPage
23 */
24
25 $options = array( 'full', 'current' );
26
27 require_once( 'commandLine.inc' );
28 require_once( 'SpecialExport.php' );
29
30 class BackupDumper {
31 var $reportingInterval = 100;
32 var $reporting = true;
33 var $pageCount = 0;
34 var $revCount = 0;
35
36 function BackupDumper() {
37 $this->stderr = fopen( "php://stderr", "wt" );
38 }
39
40 function dump( $history ) {
41 # This shouldn't happen if on console... ;)
42 header( 'Content-type: text/html; charset=UTF-8' );
43
44 # Notice messages will foul up your XML output even if they're
45 # relatively harmless.
46 ini_set( 'display_errors', false );
47
48 $this->startTime = wfTime();
49
50 $db =& $this->backupDb();
51 $exporter = new WikiExporter( $db, $history, MW_EXPORT_STREAM );
52 $exporter->setPageCallback( array( &$this, 'reportPage' ) );
53 $exporter->setRevCallback( array( &$this, 'revCount' ) );
54
55 $exporter->openStream();
56 $exporter->allPages();
57 $exporter->closeStream();
58
59 $this->report( true );
60 }
61
62 function &backupDb() {
63 global $wgDBadminuser, $wgDBadminpassword;
64 global $wgDBserver, $wgDBname;
65 $db =& new Database( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
66 return $db;
67 }
68
69 function reportPage( $page ) {
70 $this->pageCount++;
71 $this->report();
72 }
73
74 function revCount( $rev ) {
75 $this->revCount++;
76 }
77
78 function report( $final = false ) {
79 if( $final xor ( $this->pageCount % $this->reportingInterval == 0 ) ) {
80 $this->showReport();
81 }
82 }
83
84 function showReport() {
85 if( $this->reporting ) {
86 $delta = wfTime() - $this->startTime;
87 if( $delta ) {
88 $rate = $this->pageCount / $delta;
89 $revrate = $this->revCount / $delta;
90 } else {
91 $rate = '-';
92 $revrate = '-';
93 }
94 $this->progress( "$this->pageCount ($rate pages/sec $revrate revs/sec)" );
95 }
96 }
97
98 function progress( $string ) {
99 fwrite( $this->stderr, $string . "\n" );
100 }
101 }
102
103 $dumper = new BackupDumper();
104 if( isset( $options['quiet'] ) ) {
105 $dumper->reporting = false;
106 }
107 if( isset( $options['report'] ) ) {
108 $dumper->reportingInterval = IntVal( $options['report'] );
109 }
110 if( isset( $options['full'] ) ) {
111 $dumper->dump( MW_EXPORT_FULL );
112 } elseif( isset( $options['current'] ) ) {
113 $dumper->dump( MW_EXPORT_CURRENT );
114 } else {
115 $dumper->progress( <<<END
116 This script dumps the wiki page database into an XML interchange wrapper
117 format for export or backup.
118
119 XML output is sent to stdout; progress reports are sent to stderr.
120
121 Usage: php dumpBackup.php <action> [<options>]
122 Actions:
123 --full Dump complete history of every page.
124 --current Includes only the latest revision of each page.
125 Options:
126 --quiet Don't dump status reports to stderr.
127 --report=n Report position and speed after every n pages processed.
128 (Default: 100)
129 END
130 );
131 }
132
133 ?>