00001 <?php 00002 00003 function compressOldPages( $start = 0 ) { 00004 $chunksize = 50; 00005 print "Starting from old_id $start...\n"; 00006 do { 00007 $end = $start + $chunksize; 00008 $sql = "SELECT old_id,old_flags,old_namespace,old_title,old_text FROM old WHERE old_id>=$start ORDER BY old_id LIMIT $chunksize"; 00009 $res = wfQuery( $sql, DB_READ, "compressOldPages" ); 00010 if( wfNumRows( $res ) == 0 ) { 00011 break; 00012 } 00013 $last = $start; 00014 while( $row = wfFetchObject( $res ) ) { 00015 # print " {$row->old_id} - {$row->old_namespace}:{$row->old_title}\n"; 00016 compressPage( $row ); 00017 $last = $row->old_id; 00018 } 00019 wfFreeResult( $res ); 00020 $start = $last + 1; # Deletion may leave long empty stretches 00021 print "$start...\n"; 00022 } while( true ); 00023 } 00024 00025 function compressPage( $row ) { 00026 if( false !== strpos( $row->old_flags, "gzip" ) ) { 00027 print "Already compressed row {$row->old_id}?\n"; 00028 return false; 00029 } 00030 $flags = $row->old_flags ? "{$row->old_flags},gzip" : "gzip"; 00031 $compress = wfStrencode( gzdeflate( $row->old_text ) ); 00032 00033 $sql = "UPDATE old SET old_flags='$flags', old_text='$compress' WHERE old_id={$row->old_id} LIMIT 1"; 00034 $res = wfQuery( $sql, DB_WRITE, 'compressPage' ); 00035 return $res; 00036 } 00037 00038 ?>