* main query is still running.
*
* @param Database $db
- * @param int $history one of MW_EXPORT_FULL or MW_EXPORT_CURRENT
+ * @param mixed $history one of MW_EXPORT_FULL or MW_EXPORT_CURRENT, or an
+ * associative array:
+ * offset: non-inclusive offset at which to start the query
+ * limit: maximum number of rows to return
+ * dir: "asc" or "desc" timestamp order
* @param int $buffer one of MW_EXPORT_BUFFER or MW_EXPORT_STREAM
*/
function WikiExporter( &$db, $history = MW_EXPORT_CURRENT,
$revision = $this->db->tableName( 'revision' );
$text = $this->db->tableName( 'text' );
+ $order = 'ORDER BY page_id';
+ $limit = '';
+
if( $this->history == MW_EXPORT_FULL ) {
$join = 'page_id=rev_page';
} elseif( $this->history == MW_EXPORT_CURRENT ) {
$this->do_list_authors ( $page , $revision , $cond );
}
$join = 'page_id=rev_page AND page_latest=rev_id';
+ } elseif ( is_array( $this->history ) ) {
+ $join = 'page_id=rev_page';
+ if ( $this->history['dir'] == 'asc' ) {
+ $op = '>';
+ $order .= ', rev_timestamp';
+ } else {
+ $op = '<';
+ $order .= ', rev_timestamp DESC';
+ }
+ if ( !empty( $this->history['offset'] ) ) {
+ $join .= " AND rev_timestamp $op " . $this->db->addQuotes(
+ $this->db->timestamp( $this->history['offset'] ) );
+ }
+ if ( !empty( $this->history['limit'] ) ) {
+ $limitNum = intval( $this->history['limit'] );
+ if ( $limitNum > 0 ) {
+ $limit = "LIMIT $limitNum";
+ }
+ }
} else {
wfProfileOut( $fname );
return new WikiError( "$fname given invalid history dump type." );
$page $pageindex,
$revision $revindex
WHERE $where $join
- ORDER BY page_id";
+ $order $limit";
} else {
$sql = "SELECT $straight * FROM
$page $pageindex,
$revision $revindex,
$text
WHERE $where $join AND rev_text_id=old_id
- ORDER BY page_id";
+ $order $limit";
}
$result = $this->db->query( $sql, $fname );
$wrapper = $this->db->resultObject( $result );
function wfSpecialExport( $page = '' ) {
global $wgOut, $wgRequest, $wgExportAllowListContributors;
global $wgExportAllowHistory, $wgExportMaxHistory;
+ $maxLimit = 200;
$curonly = true;
+ $fullHistory = array(
+ 'dir' => 'asc',
+ 'offset' => false,
+ 'limit' => $maxLimit,
+ );
if( $wgRequest->getVal( 'action' ) == 'submit') {
$page = $wgRequest->getText( 'pages' );
$curonly = $wgRequest->getCheck( 'curonly' );
- }
- if( $wgRequest->getCheck( 'history' ) ) {
- $curonly = false;
+ $offset = wfTimestamp( TS_MW, $wgRequest->getVal( 'offset' ) );
+ $limit = $wgRequest->getInt( 'limit' );
+ $dir = $wgRequest->getVal( 'dir' );
+ $history = array(
+ 'dir' => 'asc',
+ 'offset' => false,
+ 'limit' => $maxLimit,
+ );
+ $historyCheck = $wgRequest->getCheck( 'history' );
+ if ( $curonly ) {
+ $history = MW_EXPORT_CURRENT;
+ } elseif ( !$historyCheck ) {
+ if ( $limit > 0 && $limit < $maxLimit ) {
+ $history['limit'] = $limit;
+ }
+ if ( !is_null( $offset ) ) {
+ $history['offset'] = $offset;
+ }
+ if ( strtolower( $dir ) == 'desc' ) {
+ $history['dir'] = 'desc';
+ }
+ }
}
if( !$wgExportAllowHistory ) {
// Override
- $curonly = true;
+ $history = MW_EXPORT_CURRENT;
}
$list_authors = $wgRequest->getCheck( 'listauthors' );
$pages = explode( "\n", $page );
$db =& wfGetDB( DB_SLAVE );
- $history = $curonly ? MW_EXPORT_CURRENT : MW_EXPORT_FULL;
$exporter = new WikiExporter( $db, $history );
$exporter->list_authors = $list_authors ;
$exporter->openStream();