Phpdoc comments and place holder. Part of the subpackage "maintenance", archives...
[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 if( false !== strpos( $row->old_flags, "gzip" ) ) {
36 print "Already compressed row {$row->old_id}?\n";
37 return false;
38 }
39 $dbw =& wfGetDB( DB_MASTER );
40 $flags = $row->old_flags ? "{$row->old_flags},gzip" : "gzip";
41 $compress = $dbw->strencode( gzdeflate( $row->old_text ) );
42 $dbw->update( 'old',
43 array( /* SET */
44 'old_flags' => $flags,
45 'old_text' => $compress
46 ), array( /* WHERE */
47 'old_id' => $row->old_id
48 ), $fname, 'LIMIT 1'
49 );
50 return $res;
51 }
52
53 ?>