export specified range of revisions (as stubs)
authorAriel Glenn <ariel@users.mediawiki.org>
Wed, 2 Nov 2011 07:58:43 +0000 (07:58 +0000)
committerAriel Glenn <ariel@users.mediawiki.org>
Wed, 2 Nov 2011 07:58:43 +0000 (07:58 +0000)
includes/Export.php
maintenance/backup.inc
maintenance/dumpBackup.php

index 489a928..3dcd3ba 100644 (file)
@@ -41,6 +41,7 @@ class WikiExporter {
        const CURRENT = 2;
        const STABLE = 4; // extension defined
        const LOGS = 8;
+       const RANGE = 16;
 
        const BUFFER = 0;
        const STREAM = 1;
@@ -56,7 +57,8 @@ class WikiExporter {
         * main query is still running.
         *
         * @param $db Database
-        * @param $history Mixed: one of WikiExporter::FULL or WikiExporter::CURRENT,
+        * @param $history Mixed: one of WikiExporter::FULL, WikiExporter::CURRENT,
+        *                 WikiExporter::RANGE or WikiExporter::STABLE,
         *                 or an associative array:
         *                   offset: non-inclusive offset at which to start the query
         *                   limit: maximum number of rows to return
@@ -119,6 +121,21 @@ class WikiExporter {
                return $this->dumpFrom( $condition );
        }
 
+       /**
+        * Dumps a series of page and revision records for those pages
+        * in the database with revisions falling within the rev_id range given.
+        * @param $start Int: inclusive lower limit (this id is included)
+        * @param $end   Int: Exclusive upper limit (this id is not included)
+        *                   If 0, no upper limit.
+        */
+       public function revsByRange( $start, $end ) {
+               $condition = 'rev_id >= ' . intval( $start );
+               if ( $end ) {
+                       $condition .= ' AND rev_id < ' . intval( $end );
+               }
+               return $this->dumpFrom( $condition );
+       }
+
        /**
         * @param $title Title
         */
@@ -259,6 +276,10 @@ class WikiExporter {
                                        wfProfileOut( __METHOD__ );
                                        throw new MWException( __METHOD__ . " given invalid history dump type." );
                                }
+                       } elseif ( $this->history & WikiExporter::RANGE ) {
+                               # Dump of revisions within a specified range
+                               $join['revision'] = array( 'INNER JOIN', 'page_id=rev_page' );
+                               $opts['ORDER BY'] = 'rev_page ASC, rev_id ASC';
                        } else {
                                # Uknown history specification parameter?
                                wfProfileOut( __METHOD__ );
index 36c3beb..814d0c0 100644 (file)
@@ -217,6 +217,8 @@ class BackupDumper {
                } else if ( is_null( $this->pages ) ) {
                        if ( $this->startId || $this->endId ) {
                                $exporter->pagesByRange( $this->startId, $this->endId );
+                       } elseif ( $this->revStartId || $this->revEndId ) {
+                               $exporter->revsByRange( $this->revStartId, $this->revEndId );
                        } else {
                                $exporter->allPages();
                        }
index e058198..1518926 100644 (file)
@@ -27,7 +27,7 @@
 
 $originalDir = getcwd();
 
-$optionsWithArgs = array( 'pagelist', 'start', 'end' );
+$optionsWithArgs = array( 'pagelist', 'start', 'end', 'revstart', 'revend');
 
 require_once( dirname( __FILE__ ) . '/commandLine.inc' );
 require_once( 'backup.inc' );
@@ -57,6 +57,13 @@ if ( isset( $options['start'] ) ) {
 if ( isset( $options['end'] ) ) {
        $dumper->endId = intval( $options['end'] );
 }
+
+if ( isset( $options['revstart'] ) ) {
+       $dumper->revStartId = intval( $options['revstart'] );
+}
+if ( isset( $options['revend'] ) ) {
+       $dumper->revEndId = intval( $options['revend'] );
+}
 $dumper->skipHeader = isset( $options['skip-header'] );
 $dumper->skipFooter = isset( $options['skip-footer'] );
 $dumper->dumpUploads = isset( $options['uploads'] );
@@ -72,6 +79,8 @@ if ( isset( $options['full'] ) ) {
        $dumper->dump( WikiExporter::STABLE, $textMode );
 } elseif ( isset( $options['logs'] ) ) {
        $dumper->dump( WikiExporter::LOGS );
+} elseif ( isset($options['revrange'] ) ) {
+       $dumper->dump( WikiExporter::RANGE, $textMode );
 } else {
        $dumper->progress( <<<ENDS
 This script dumps the wiki page or logging database into an
@@ -87,7 +96,8 @@ Actions:
   --stable    Stable versions of pages?
   --pagelist=<file>
                          Where <file> is a list of page titles to be dumped
-
+  --revrange  Dump specified range of revisions, requires
+              revstart and revend options.
 Options:
   --quiet     Don't dump status reports to stderr.
   --report=n  Report position and speed after every n pages processed.
@@ -95,6 +105,8 @@ Options:
   --server=h  Force reading from MySQL server h
   --start=n   Start from page_id or log_id n
   --end=n     Stop before page_id or log_id n (exclusive)
+  --revstart=n  Start from rev_id n
+  --revend=n    Stop before rev_id n (exclusive)
   --skip-header Don't output the <mediawiki> header
   --skip-footer Don't output the </mediawiki> footer
   --stub      Don't perform old_text lookups; for 2-pass dump