Part of bug 26280: added license headers to PHP files in maintenance
[lhc/web/wiklou.git] / maintenance / storage / compressOld.php
1 <?php
2 /**
3 * Compress the text of a wiki.
4 *
5 * Usage:
6 *
7 * Non-wikimedia
8 * php compressOld.php [options...]
9 *
10 * Wikimedia
11 * php compressOld.php <database> [options...]
12 *
13 * Options are:
14 * -t <type> set compression type to either:
15 * gzip: compress revisions independently
16 * concat: concatenate revisions and compress in chunks (default)
17 * -c <chunk-size> maximum number of revisions in a concat chunk
18 * -b <begin-date> earliest date to check for uncompressed revisions
19 * -e <end-date> latest revision date to compress
20 * -s <start-id> the old_id to start from
21 * --extdb <cluster> store specified revisions in an external cluster (untested)
22 *
23 * This program is free software; you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by
25 * the Free Software Foundation; either version 2 of the License, or
26 * (at your option) any later version.
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License along
34 * with this program; if not, write to the Free Software Foundation, Inc.,
35 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
36 * http://www.gnu.org/copyleft/gpl.html
37 *
38 * @file
39 * @ingroup Maintenance ExternalStorage
40 */
41
42 $optionsWithArgs = array( 't', 'c', 's', 'f', 'h', 'extdb', 'endid', 'e' );
43 require_once( dirname( __FILE__ ) . '/../commandLine.inc' );
44 require_once( "compressOld.inc" );
45
46 if ( !function_exists( "gzdeflate" ) ) {
47 print "You must enable zlib support in PHP to compress old revisions!\n";
48 print "Please see http://www.php.net/manual/en/ref.zlib.php\n\n";
49 wfDie();
50 }
51
52 $defaults = array(
53 't' => 'concat',
54 'c' => 20,
55 's' => 0,
56 'b' => '',
57 'e' => '',
58 'extdb' => '',
59 'endid' => false,
60 );
61
62 $options = $options + $defaults;
63
64 if ( $options['t'] != 'concat' && $options['t'] != 'gzip' ) {
65 print "Type \"{$options['t']}\" not supported\n";
66 }
67
68 if ( $options['extdb'] != '' ) {
69 print "Compressing database $wgDBname to external cluster {$options['extdb']}\n" . str_repeat( '-', 76 ) . "\n\n";
70 } else {
71 print "Compressing database $wgDBname\n" . str_repeat( '-', 76 ) . "\n\n";
72 }
73
74 $success = true;
75 if ( $options['t'] == 'concat' ) {
76 $success = compressWithConcat( $options['s'], $options['c'], $options['b'],
77 $options['e'], $options['extdb'], $options['endid'] );
78 } else {
79 compressOldPages( $options['s'], $options['extdb'] );
80 }
81
82 if ( $success ) {
83 print "Done.\n";
84 }
85
86 exit( 0 );
87
88