Fix DATA CORRUPTION BUG caused by double-escaping.
[lhc/web/wiklou.git] / maintenance / compressOld.inc
1 <?php
2 /**
3 * @package MediaWiki
4 * @subpackage Maintenance
5 */
6
7 /** */
8 function compressOldPages( $start = 0 ) {
9 $fname = 'compressOldPages';
10
11 $chunksize = 50;
12 print "Starting from old_id $start...\n";
13 $dbw =& wfGetDB( DB_MASTER );
14 $old = $dbw->tableName( 'old' );
15 do {
16 $end = $start + $chunksize;
17 $res = $dbw->select( 'old', array( 'old_id','old_flags','old_namespace','old_title','old_text' ),
18 "old_id>=$start", $fname, array( 'ORDER BY' => 'old_id', 'LIMIT' => $chunksize, 'FOR UPDATE' ) );
19 if( $dbw->numRows( $res ) == 0 ) {
20 break;
21 }
22 $last = $start;
23 while( $row = $dbw->fetchObject( $res ) ) {
24 # print " {$row->old_id} - {$row->old_namespace}:{$row->old_title}\n";
25 compressPage( $row );
26 $last = $row->old_id;
27 }
28 $dbw->freeResult( $res );
29 $start = $last + 1; # Deletion may leave long empty stretches
30 print "$start...\n";
31 } while( true );
32 }
33
34 function compressPage( $row ) {
35 $fname = 'compressPage';
36 if( false !== strpos( $row->old_flags, "gzip" ) ) {
37 print "Already compressed row {$row->old_id}?\n";
38 return false;
39 }
40 $dbw =& wfGetDB( DB_MASTER );
41 $flags = $row->old_flags ? "{$row->old_flags},gzip" : "gzip";
42 $compress = gzdeflate( $row->old_text );
43 $dbw->update( 'old',
44 array( /* SET */
45 'old_flags' => $flags,
46 'old_text' => $compress
47 ), array( /* WHERE */
48 'old_id' => $row->old_id
49 ), $fname, 'LIMIT 1'
50 );
51 return true;
52 }
53
54 ?>