show link cursor
[mediawiki.git] / maintenance / compressOld.inc
blobff47e15f96d7cca406481dd729ebf60c4843ac58
1 <?php
3 include_once( "Article.php" );
5 function compressOldPages( $start = 0 ) {
6         $chunksize = 50;
7         print "Starting from old_id $start...\n";
8         do {
9                 $end = $start + $chunksize;
10                 $sql = "SELECT old_id,old_flags,old_namespace,old_title,old_text FROM old WHERE old_id>=$start ORDER BY old_id LIMIT $chunksize";
11                 $res = wfQuery( $sql, DB_READ, "compressOldPages" );
12                 if( wfNumRows( $res ) == 0 ) {
13                         break;
14                 }
15                 $last = $start;
16                 while( $row = wfFetchObject( $res ) ) {
17                         # print "  {$row->old_id} - {$row->old_namespace}:{$row->old_title}\n";
18                         compressPage( $row );
19                         $last = $row->old_id;
20                 }
21                 wfFreeResult( $res );
22                 $start = $last + 1; # Deletion may leave long empty stretches
23                 print "$start...\n";
24         } while( true );
27 function compressPage( $row ) {
28         if( false !== strpos( $row->old_flags, "gzip" ) ) {
29                 print "Already compressed row {$row->old_id}?\n";
30                 return false;
31         }
32         $flags = $row->old_flags ? "{$row->old_flags},gzip" : "gzip";
33         $compress = wfStrencode( gzdeflate( $row->old_text ) );
34         
35         $sql = "UPDATE old SET old_flags='$flags', old_text='$compress' WHERE old_id={$row->old_id} LIMIT 1";
36          $res = wfQuery( $sql, DB_WRITE, 'compressPage' );
37         return $res;