tested for stubs, text, logging with and without start/end values,
with and without orderrevs, seems to work as expected, with the
appropriate changes to the query.
Bug: T29112
Change-Id: I94ca4a06235bdbed384bb997deb7432bb5aaa5b9
* @param int $start Inclusive lower limit (this id is included)
* @param int $end Exclusive upper limit (this id is not included)
* If 0, no upper limit.
* @param int $start Inclusive lower limit (this id is included)
* @param int $end Exclusive upper limit (this id is not included)
* If 0, no upper limit.
+ * @param bool $orderRevs order revisions within pages in ascending order
- public function pagesByRange( $start, $end ) {
- $condition = 'page_id >= ' . intval( $start );
- if ( $end ) {
- $condition .= ' AND page_id < ' . intval( $end );
+ public function pagesByRange( $start, $end, $orderRevs ) {
+ if ( $orderRevs ) {
+ $condition = 'rev_page >= ' . intval( $start );
+ if ( $end ) {
+ $condition .= ' AND rev_page < ' . intval( $end );
+ }
+ } else {
+ $condition = 'page_id >= ' . intval( $start );
+ if ( $end ) {
+ $condition .= ' AND page_id < ' . intval( $end );
+ }
- $this->dumpFrom( $condition );
+ $this->dumpFrom( $condition, $orderRevs );
* @throws MWException
* @throws Exception
*/
* @throws MWException
* @throws Exception
*/
- protected function dumpFrom( $cond = '' ) {
+ protected function dumpFrom( $cond = '', $orderRevs = false ) {
# For logging dumps...
if ( $this->history & self::LOGS ) {
$where = [ 'user_id = log_user' ];
# For logging dumps...
if ( $this->history & self::LOGS ) {
$where = [ 'user_id = log_user' ];
}
} elseif ( $this->history & WikiExporter::FULL ) {
# Full history dumps...
}
} elseif ( $this->history & WikiExporter::FULL ) {
# Full history dumps...
- $join['revision'] = [ 'INNER JOIN', 'page_id=rev_page' ];
+ # query optimization for history stub dumps
+ if ( $this->text == WikiExporter::STUB && $orderRevs ) {
+ $tables = [ 'revision', 'page' ];
+ $opts[] = 'STRAIGHT_JOIN';
+ $opts['ORDER BY'] = [ 'rev_page ASC', 'rev_id ASC' ];
+ $opts['USE INDEX']['revision'] = 'rev_page_id';
+ $join['page'] = [ 'INNER JOIN', 'rev_page=page_id' ];
+ } else {
+ $join['revision'] = [ 'INNER JOIN', 'page_id=rev_page' ];
+ }
} elseif ( $this->history & WikiExporter::CURRENT ) {
# Latest revision dumps...
if ( $this->list_authors && $cond != '' ) { // List authors, if so desired
} elseif ( $this->history & WikiExporter::CURRENT ) {
# Latest revision dumps...
if ( $this->list_authors && $cond != '' ) { // List authors, if so desired
if ( $this->buffer == WikiExporter::STREAM ) {
$prev = $this->db->bufferResults( false );
}
if ( $this->buffer == WikiExporter::STREAM ) {
$prev = $this->db->bufferResults( false );
}
$result = null; // Assuring $result is not undefined, if exception occurs early
try {
Hooks::run( 'ModifyExportQuery',
$result = null; // Assuring $result is not undefined, if exception occurs early
try {
Hooks::run( 'ModifyExportQuery',
public $revEndId = 0;
public $dumpUploads = false;
public $dumpUploadFileContents = false;
public $revEndId = 0;
public $dumpUploads = false;
public $dumpUploadFileContents = false;
+ public $orderRevs = false;
protected $reportingInterval = 100;
protected $pageCount = 0;
protected $reportingInterval = 100;
protected $pageCount = 0;
} elseif ( is_null( $this->pages ) ) {
# Page dumps: all or by page ID range
if ( $this->startId || $this->endId ) {
} elseif ( is_null( $this->pages ) ) {
# Page dumps: all or by page ID range
if ( $this->startId || $this->endId ) {
- $exporter->pagesByRange( $this->startId, $this->endId );
+ $exporter->pagesByRange( $this->startId, $this->endId, $this->orderRevs );
} elseif ( $this->revStartId || $this->revEndId ) {
$exporter->revsByRange( $this->revStartId, $this->revEndId );
} else {
} elseif ( $this->revStartId || $this->revEndId ) {
$exporter->revsByRange( $this->revStartId, $this->revEndId );
} else {
$this->addOption( 'stable', 'Dump stable versions of pages' );
$this->addOption( 'revrange', 'Dump range of revisions specified by revstart and ' .
'revend parameters' );
$this->addOption( 'stable', 'Dump stable versions of pages' );
$this->addOption( 'revrange', 'Dump range of revisions specified by revstart and ' .
'revend parameters' );
+ $this->addOption( 'orderrevs', 'Dump revisions in ascending revision order ' .
+ '(implies dump of a range of pages)' );
$this->addOption( 'pagelist',
'Dump only pages included in the file', false, true );
// Options
$this->addOption( 'pagelist',
'Dump only pages included in the file', false, true );
// Options
$this->skipFooter = $this->hasOption( 'skip-footer' );
$this->dumpUploads = $this->hasOption( 'uploads' );
$this->dumpUploadFileContents = $this->hasOption( 'include-files' );
$this->skipFooter = $this->hasOption( 'skip-footer' );
$this->dumpUploads = $this->hasOption( 'uploads' );
$this->dumpUploadFileContents = $this->hasOption( 'include-files' );
+ $this->orderRevs = $this->hasOption( 'orderrevs' );