BUG#1849 - Count images as used if they are put into a category (site pref)
[lhc/web/wiklou.git] / maintenance / compressOld.inc
index d5159ba..3114647 100644 (file)
@@ -5,6 +5,9 @@
  */
 
 /** */
+require_once( 'includes/Revision.php' );
+
+/** @todo document */
 function compressOldPages( $start = 0 ) {
        $fname = 'compressOldPages';
 
@@ -31,6 +34,7 @@ function compressOldPages( $start = 0 ) {
        } while( true );
 }
 
+/** @todo document */
 function compressPage( $row ) {
        $fname = 'compressPage';
        if( false !== strpos( $row->old_flags, "gzip" ) ) {
@@ -54,6 +58,7 @@ function compressPage( $row ) {
 define( 'LS_INDIVIDUAL', 0 );
 define( 'LS_CHUNKED', 1 );
 
+/** @todo document */
 function compressWithConcat( $startId, $maxChunkSize, $maxChunkFactor, $factorThreshold, $beginDate, $endDate )
 {
        $fname = 'compressWithConcat';
@@ -62,24 +67,27 @@ function compressWithConcat( $startId, $maxChunkSize, $maxChunkFactor, $factorTh
        $dbw =& wfGetDB( DB_MASTER );
 
        # First get a list of all pages
-       $pageRes = $dbw->select( 'cur', array('cur_namespace', 'cur_title'), false, $fname );
+       $pageRes = $dbw->select( 'page', 'page_id', false, $fname );
 
        # For each of those, get a list of revisions which fit the criteria
        $conds = array();
        if ( $beginDate ) {
-               $conds[] = "old_timestamp>'" . $beginDate . "'";
+               $conds[] = "rev_timestamp>'" . $beginDate . "'";
        } 
        if ( $endDate )  {
-               $conds[] = "old_timestamp<'" . $endDate . "'";
+               $conds[] = "rev_timestamp<'" . $endDate . "'";
        }
        if ( $startId ) {
-               $conds[] = 'old_id>=' . $startId;
+               $conds[] = 'rev_id>=' . $startId;
        }
        if ( $loadStyle == LS_CHUNKED ) {
-               $fields = array( 'old_id', 'old_flags', 'old_text' );
+               $tables = array( 'revision', 'text' );
+               $fields = array( 'rev_id', 'rev_text_id', 'old_flags', 'old_text' );
+               $conds[] = 'rev_text_id=old_id';
                $revLoadOptions = 'FOR UPDATE';
        } else {
-               $fields = array( 'old_id' );
+               $tables = array( 'revision' );
+               $fields = array( 'rev_id', 'rev_text_id' );
                $revLoadOptions = array();
        }
 
@@ -89,8 +97,8 @@ function compressWithConcat( $startId, $maxChunkSize, $maxChunkFactor, $factorTh
                print $titleObj->getPrefixedDBkey() . " ";
 
                # Load revisions
-               $revRes = $dbw->select( 'old', $fields,
-                       array( 'old_namespace' => $pageRow->cur_namespace, 'old_title' => $pageRow->cur_title ) + $conds, 
+               $revRes = $dbw->select( $tables, $fields,
+                       array( 'rev_page' => $pageRow->page_id ) + $conds, 
                        $fname,
                        $revLoadOptions
                );
@@ -118,23 +126,23 @@ function compressWithConcat( $startId, $maxChunkSize, $maxChunkFactor, $factorTh
                        $stubs = array();
                        $dbw->begin();
                        $usedChunk = false;
-                       $primaryOldid = $revs[$i]->old_id;
+                       $primaryOldid = $revs[$i]->rev_text_id;
                        
                        # Get the text of each revision and add it to the object
                        for ( $j = 0; $j < $thisChunkSize && $chunk->isHappy( $maxChunkFactor, $factorThreshold ); $j++ ) {
-                               $oldid = $revs[$i + $j]->old_id;
+                               $oldid = $revs[$i + $j]->rev_text_id;
                                
                                # Get text
                                if ( $loadStyle == LS_INDIVIDUAL ) {
-                                       $textRow = $dbw->selectRow( 'old', 
+                                       $textRow = $dbw->selectRow( 'text', 
                                                array( 'old_flags', 'old_text' ),
                                                array( 'old_id' => $oldid ),
                                                $fname,
                                                'FOR UPDATE'
                                        );
-                                       $text = Article::getRevisionText( $textRow );
+                                       $text = Revision::getRevisionText( $textRow );
                                } else {
-                                       $text = Article::getRevisionText( $revs[$i + $j] );
+                                       $text = Revision::getRevisionText( $revs[$i + $j] );
                                }
 
                                if ( $text === false ) {
@@ -167,7 +175,7 @@ function compressWithConcat( $startId, $maxChunkSize, $maxChunkFactor, $factorTh
                        # If we couldn't actually use any stubs because the pages were too small, do nothing
                        if ( $usedChunk ) {
                                # Store the main object
-                               $dbw->update( 'old',
+                               $dbw->update( 'text',
                                        array( /* SET */
                                                'old_text' => serialize( $chunk ),
                                                'old_flags' => 'object',
@@ -180,7 +188,7 @@ function compressWithConcat( $startId, $maxChunkSize, $maxChunkFactor, $factorTh
                                for ( $j = 1; $j < $thisChunkSize; $j++ ) {
                                        # Skip if not compressing
                                        if ( $stubs[$j] !== false ) {
-                                               $dbw->update( 'old',
+                                               $dbw->update( 'text',
                                                        array( /* SET */
                                                                'old_text' => $stubs[$j],
                                                                'old_flags' => 'object',
@@ -200,4 +208,4 @@ function compressWithConcat( $startId, $maxChunkSize, $maxChunkFactor, $factorTh
        }
        return true;
 }
-?>
+?>
\ No newline at end of file