4 * @subpackage Maintenance
8 function compressOldPages( $start = 0 ) {
9 $fname = 'compressOldPages';
12 print "Starting from old_id $start...\n";
13 $dbw =& wfGetDB( DB_MASTER );
14 $old = $dbw->tableName( 'old' );
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 ) {
23 while( $row = $dbw->fetchObject( $res ) ) {
24 # print " {$row->old_id} - {$row->old_namespace}:{$row->old_title}\n";
28 $dbw->freeResult( $res );
29 $start = $last + 1; # Deletion may leave long empty stretches
34 function compressPage( $row ) {
35 $fname = 'compressPage';
36 if( false !== strpos( $row->old_flags, "gzip" ) ) {
37 print "Already compressed row {$row->old_id}?\n";
40 $dbw =& wfGetDB( DB_MASTER );
41 $flags = $row->old_flags ? "{$row->old_flags},gzip" : "gzip";
42 $compress = gzdeflate( $row->old_text );
45 'old_flags' => $flags,
46 'old_text' => $compress
48 'old_id' => $row->old_id
54 define( 'LS_INDIVIDUAL', 0 );
55 define( 'LS_CHUNKED', 1 );
57 function compressWithConcat( $startId, $maxChunkSize, $maxChunkFactor, $factorThreshold, $beginDate, $endDate )
59 $fname = 'compressWithConcat';
60 $loadStyle = LS_CHUNKED;
62 $dbw =& wfGetDB( DB_MASTER );
64 # First get a list of all pages
65 $pageRes = $dbw->select( 'cur', array('cur_namespace', 'cur_title'), false, $fname );
67 # For each of those, get a list of revisions which fit the criteria
70 $conds[] = "old_timestamp>'" . $beginDate . "'";
73 $conds[] = "old_timestamp<'" . $endDate . "'";
76 $conds[] = 'old_id>=' . $startId;
78 if ( $loadStyle == LS_CHUNKED ) {
79 $fields = array( 'old_id', 'old_flags', 'old_text' );
80 $revLoadOptions = 'FOR UPDATE';
82 $fields = array( 'old_id' );
83 $revLoadOptions = array();
86 while ( $pageRow = $dbw->fetchObject( $pageRes ) ) {
88 $titleObj = Title::makeTitle( $pageRow->cur_namespace, $pageRow->cur_title );
89 print $titleObj->getPrefixedDBkey() . " ";
92 $revRes = $dbw->select( 'old', $fields,
93 array( 'old_namespace' => $pageRow->cur_namespace, 'old_title' => $pageRow->cur_title ) + $conds,
98 while ( $revRow = $dbw->fetchObject( $revRes ) ) {
102 if ( count( $revs ) < 2) {
103 # No revisions matching, no further processing
110 while ( $i < count( $revs ) ) {
111 if ( $i < count( $revs ) - $maxChunkSize ) {
112 $thisChunkSize = $maxChunkSize;
114 $thisChunkSize = count( $revs ) - $i;
117 $chunk = new ConcatenatedGzipHistoryBlob();
121 $primaryOldid = $revs[$i]->old_id;
123 # Get the text of each revision and add it to the object
124 for ( $j = 0; $j < $thisChunkSize && $chunk->isHappy( $maxChunkFactor, $factorThreshold ); $j++ ) {
125 $oldid = $revs[$i + $j]->old_id;
128 if ( $loadStyle == LS_INDIVIDUAL ) {
129 $textRow = $dbw->selectRow( 'old',
130 array( 'old_flags', 'old_text' ),
131 array( 'old_id' => $oldid ),
135 $text = Article::getRevisionText( $textRow );
137 $text = Article::getRevisionText( $revs[$i + $j] );
140 if ( $text === false ) {
141 print "\nError, unable to get text in old_id $oldid\n";
142 #$dbw->delete( 'old', array( 'old_id' => $oldid ) );
146 $chunk->setText( $text );
149 # Don't make a stub if it's going to be longer than the article
150 # Stubs are typically about 100 bytes
151 if ( strlen( $text ) < 120 ) {
155 $stub = $chunk->addItem( $text );
156 $stub->setLocation( $primaryOldid );
157 $hash = $stub->getHash();
158 $stub = serialize( $stub );
167 # If we couldn't actually use any stubs because the pages were too small, do nothing
169 # Store the main object
172 'old_text' => serialize( $chunk ),
173 'old_flags' => 'object',
174 ), array( /* WHERE */
175 'old_id' => $primaryOldid
179 # Store the stub objects
180 for ( $j = 1; $j < $thisChunkSize; $j++ ) {
181 # Skip if not compressing
182 if ( $stubs[$j] !== false ) {
185 'old_text' => $stubs[$j],
186 'old_flags' => 'object',
187 ), array( /* WHERE */
188 'old_id' => $revs[$i + $j]->old_id
197 $i += $thisChunkSize;