83 function __construct( $db, $history = self::CURRENT, $text = self::TEXT ) {
104 $this->sink->writeOpenStream(
$output );
109 $this->sink->writeCloseStream(
$output );
131 $condition =
'rev_page >= ' . intval( $start );
133 $condition .=
' AND rev_page < ' . intval( $end );
136 $condition =
'page_id >= ' . intval( $start );
138 $condition .=
' AND page_id < ' . intval( $end );
141 $this->
dumpFrom( $condition, $orderRevs );
152 $condition =
'rev_id >= ' . intval( $start );
154 $condition .=
' AND rev_id < ' . intval( $end );
164 'page_namespace=' . $title->getNamespace() .
165 ' AND page_title=' . $this->db->addQuotes( $title->getDBkey() ) );
173 $title = Title::newFromText( $name );
174 if ( is_null( $title ) ) {
175 throw new MWException(
"Can't export invalid title" );
185 foreach ( $names as $name ) {
199 $condition =
'log_id >= ' . intval( $start );
201 $condition .=
' AND log_id < ' . intval( $end );
214 $this->author_list =
"<contributors>";
218 $res = $this->db->select(
221 'rev_user_text' =>
$revQuery[
'fields'][
'rev_user_text'],
222 'rev_user' =>
$revQuery[
'fields'][
'rev_user'],
233 foreach (
$res as $row ) {
234 $this->author_list .=
"<contributor>" .
236 htmlentities( $row->rev_user_text ) .
243 $this->author_list .=
"</contributors>";
252 protected function dumpFrom( $cond =
'', $orderRevs =
false ) {
253 if ( $this->
history & self::LOGS ) {
269 $where[] = $hideLogs;
271 # Add on any caller specified conditions
275 # Get logging table name for logging.* clause
276 $logging = $this->db->tableName(
'logging' );
280 $commentQuery = CommentStore::getStore()->getJoin(
'log_comment' );
281 $actorQuery = ActorMigration::newMigration()->getJoin(
'log_user' );
285 $result = $this->db->select(
286 array_merge( [
'logging' ], $commentQuery[
'tables'], $actorQuery[
'tables'], [
'user' ] ),
287 [
"{$logging}.*",
'user_name' ] + $commentQuery[
'fields'] + $actorQuery[
'fields'],
288 array_merge( $where, [
'log_id > ' . intval( $lastLogId ) ] ),
291 'ORDER BY' =>
'log_id',
292 'USE INDEX' => [
'logging' =>
'PRIMARY' ],
293 'LIMIT' => self::BATCH_SIZE,
296 'user' => [
'JOIN',
'user_id = ' . $actorQuery[
'fields'][
'log_user'] ]
297 ] + $commentQuery[
'joins'] + $actorQuery[
'joins']
300 if ( !$result->numRows() ) {
319 'Cannot use WikiExporter with SCHEMA_COMPAT_WRITE_OLD mode disabled!'
320 .
' Support for dumping from the new schema is not implemented yet!'
324 $revOpts = [
'page' ];
325 if ( $this->text != self::STUB ) {
332 $tables = array_merge( [
'page' ], array_diff(
$revQuery[
'tables'], [
'page' ] ) );
336 unset( $join[
'page'] );
339 $fields = array_merge(
$revQuery[
'fields'], [
'page_restrictions, rev_text_id' ] );
342 if ( $cond !==
'' ) {
345 $opts = [
'ORDER BY' => [
'rev_page ASC',
'rev_id ASC' ] ];
346 $opts[
'USE INDEX'] = [];
349 if ( is_array( $this->
history ) ) {
350 # Time offset/limit for all pages/history...
352 if ( $this->
history[
'dir'] ==
'asc' ) {
353 $opts[
'ORDER BY'] =
'rev_timestamp ASC';
356 $opts[
'ORDER BY'] =
'rev_timestamp DESC';
359 if ( !empty( $this->
history[
'offset'] ) ) {
360 $conds[] =
"rev_timestamp $op " .
361 $this->db->addQuotes( $this->db->timestamp( $this->history[
'offset'] ) );
364 if ( !empty( $this->
history[
'limit'] ) ) {
365 $maxRowCount = intval( $this->
history[
'limit'] );
367 } elseif ( $this->
history & self::FULL ) {
368 # Full history dumps...
369 # query optimization for history stub dumps
370 if ( $this->text == self::STUB ) {
372 $opts[] =
'STRAIGHT_JOIN';
373 $opts[
'USE INDEX'][
'revision'] =
'rev_page_id';
374 unset( $join[
'revision'] );
375 $join[
'page'] = [
'INNER JOIN',
'rev_page=page_id' ];
377 } elseif ( $this->
history & self::CURRENT ) {
378 # Latest revision dumps...
379 if ( $this->list_authors && $cond !=
'' ) {
382 $join[
'revision'] = [
'INNER JOIN',
'page_id=rev_page AND page_latest=rev_id' ];
383 } elseif ( $this->
history & self::STABLE ) {
384 # "Stable" revision dumps...
385 # Default JOIN, to be overridden...
386 $join[
'revision'] = [
'INNER JOIN',
'page_id=rev_page AND page_latest=rev_id' ];
387 # One, and only one hook should set this, and return false
388 if ( Hooks::run(
'WikiExporter::dumpStableQuery', [ &
$tables, &$opts, &$join ] ) ) {
389 throw new MWException( __METHOD__ .
" given invalid history dump type." );
391 } elseif ( $this->
history & self::RANGE ) {
392 # Dump of revisions within a specified range. Condition already set in revsByRange().
394 # Unknown history specification parameter?
395 throw new MWException( __METHOD__ .
" given invalid history dump type." );
405 $opts[
'LIMIT'] = self::BATCH_SIZE;
407 Hooks::run(
'ModifyExportQuery',
408 [ $this->db, &
$tables, &$cond, &$opts, &$join ] );
412 if ( !empty( $maxRowCount ) && $rowCount + self::BATCH_SIZE > $maxRowCount ) {
413 $opts[
'LIMIT'] = $maxRowCount - $rowCount;
417 $queryConds = $conds;
418 $queryConds[] =
'rev_page>' . intval( $revPage ) .
' OR (rev_page=' .
419 intval( $revPage ) .
' AND rev_id' . $op . intval( $revId ) .
')';
422 $result = $this->db->select(
430 # Output dump results, get new max ids.
433 if ( !$result->numRows() || !$lastRow ) {
436 $rowCount += $result->numRows();
437 $revPage = $lastRow->rev_page;
438 $revId = $lastRow->rev_id;
453 if ( $resultset->numRows() ) {
454 foreach ( $resultset as $row ) {
455 if ( $lastRow ===
null ||
456 $lastRow->page_namespace != $row->page_namespace ||
457 $lastRow->page_title != $row->page_title ) {
458 if ( $lastRow !==
null ) {
460 if ( $this->dumpUploads ) {
461 $output .= $this->
writer->writeUploads( $lastRow, $this->dumpUploadFileContents );
464 $this->sink->writeClosePage(
$output );
467 $this->sink->writeOpenPage( $row,
$output );
470 $this->sink->writeRevision( $row,
$output );
473 } elseif ( $lastRow !==
null ) {
476 if ( $this->dumpUploads ) {
477 $output .= $this->
writer->writeUploads( $lastRow, $this->dumpUploadFileContents );
481 $this->sink->writeClosePage(
$output );
493 foreach ( $resultset as $row ) {
495 $this->sink->writeLogItem( $row,
$output );
497 return isset( $row ) ? $row->log_id :
null;
int $wgMultiContentRevisionSchemaMigrationStage
RevisionStore table schema migration stage (content, slots, content_models & slot_roles tables).
static getExcludeClause( $db, $audience='public', User $user=null)
SQL clause to skip forbidden log types for this user.
static getQueryInfo( $options=[])
Return the tables, fields, and join conditions to be selected to create a new revision object.
revsByRange( $start, $end)
Dumps a series of page and revision records for those pages in the database with revisions falling wi...
dumpFrom( $cond='', $orderRevs=false)
setOutputSink(&$sink)
Set the DumpOutput or DumpFilter object which will receive various row objects and XML output for fil...
outputPageStream( $resultset, $lastRow)
Runs through a query result set dumping page and revision records.
pagesByRange( $start, $end, $orderRevs)
Dumps a series of page and revision records for those pages in the database falling within the page_i...
bool $dumpUploadFileContents
allPages()
Dumps a series of page and revision records for all pages in the database, either including complete ...
logsByRange( $start, $end)
do_list_authors( $cond)
Generates the distinct list of authors of an article Not called by default (depends on $this->list_au...
dumpPages( $cond, $orderRevs)
__construct( $db, $history=self::CURRENT, $text=self::TEXT)
outputLogStream( $resultset)
static schemaVersion()
Returns the export schema version.
bool $list_authors
Return distinct author list (when not returning full history)
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc next in line in page history
this hook is for auditing only RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place $output
const SCHEMA_COMPAT_WRITE_OLD