simple script to generate phpdocumentor documentation and troubleshoot its generation
[mediawiki.git] / maintenance / compressOld.inc
blobc99eac4e22659631c73cba2d4cb06f792aa497e9
1 <?php
2 /**
3  * @package MediaWiki
4  * @subpackage Maintenance
5  */
7 /** */
8 function compressOldPages( $start = 0 ) {
9         $fname = 'compressOldPages';
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 );
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;