2005-05-08 08:17:12 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2010-10-03 09:25:28 +00:00
|
|
|
* Script that dumps wiki pages or logging database into an XML interchange
|
|
|
|
|
* wrapper format for export or backup
|
|
|
|
|
*
|
2024-02-09 01:02:16 +00:00
|
|
|
* Copyright © 2005 Brooke Vibber <bvibber@wikimedia.org>
|
2014-03-20 15:45:01 +00:00
|
|
|
* https://www.mediawiki.org/
|
2006-01-07 13:09:30 +00:00
|
|
|
*
|
2005-05-08 08:17:12 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2006-01-07 13:09:30 +00:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
2005-05-08 08:17:12 +00:00
|
|
|
* (at your option) any later version.
|
2006-01-07 13:09:30 +00:00
|
|
|
*
|
2005-05-08 08:17:12 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
2006-01-07 13:09:30 +00:00
|
|
|
*
|
2005-05-08 08:17:12 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
2006-04-05 07:43:17 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-05-08 08:17:12 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @file
|
2018-08-02 05:10:29 +00:00
|
|
|
* @ingroup Dump
|
|
|
|
|
* @ingroup Maintenance
|
2005-05-08 08:17:12 +00:00
|
|
|
*/
|
|
|
|
|
|
2024-08-11 16:32:58 +00:00
|
|
|
use MediaWiki\Maintenance\BackupDumper;
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2018-08-02 05:10:29 +00:00
|
|
|
require_once __DIR__ . '/includes/BackupDumper.php';
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2005-10-02 04:05:40 +00:00
|
|
|
|
2015-12-31 09:46:54 +00:00
|
|
|
class DumpBackup extends BackupDumper {
|
2019-10-09 18:41:33 +00:00
|
|
|
public function __construct( $args = null ) {
|
2015-12-31 09:46:54 +00:00
|
|
|
parent::__construct();
|
2005-10-02 04:05:40 +00:00
|
|
|
|
2016-01-30 02:48:47 +00:00
|
|
|
$this->addDescription( <<<TEXT
|
2009-05-17 19:28:02 +00:00
|
|
|
This script dumps the wiki page or logging database into an
|
|
|
|
|
XML interchange wrapper format for export or backup.
|
2005-05-08 08:17:12 +00:00
|
|
|
|
|
|
|
|
XML output is sent to stdout; progress reports are sent to stderr.
|
|
|
|
|
|
2012-03-07 10:07:32 +00:00
|
|
|
WARNING: this is not a full database dump! It is merely for public export
|
2015-12-31 09:46:54 +00:00
|
|
|
of your wiki. For full backup, see our online help at:
|
2012-03-07 10:07:32 +00:00
|
|
|
https://www.mediawiki.org/wiki/Backup
|
2016-01-30 02:48:47 +00:00
|
|
|
TEXT
|
|
|
|
|
);
|
2020-10-12 02:57:02 +00:00
|
|
|
|
2015-12-31 09:46:54 +00:00
|
|
|
// Actions
|
|
|
|
|
$this->addOption( 'full', 'Dump all revisions of every page' );
|
|
|
|
|
$this->addOption( 'current', 'Dump only the latest revision of every page.' );
|
|
|
|
|
$this->addOption( 'logs', 'Dump all log events' );
|
|
|
|
|
$this->addOption( 'stable', 'Dump stable versions of pages' );
|
|
|
|
|
$this->addOption( 'revrange', 'Dump range of revisions specified by revstart and ' .
|
|
|
|
|
'revend parameters' );
|
2016-06-21 20:08:29 +00:00
|
|
|
$this->addOption( 'orderrevs', 'Dump revisions in ascending revision order ' .
|
|
|
|
|
'(implies dump of a range of pages)' );
|
2015-12-31 09:46:54 +00:00
|
|
|
$this->addOption( 'pagelist',
|
|
|
|
|
'Dump only pages included in the file', false, true );
|
|
|
|
|
// Options
|
|
|
|
|
$this->addOption( 'start', 'Start from page_id or log_id', false, true );
|
|
|
|
|
$this->addOption( 'end', 'Stop before page_id or log_id n (exclusive)', false, true );
|
|
|
|
|
$this->addOption( 'revstart', 'Start from rev_id', false, true );
|
|
|
|
|
$this->addOption( 'revend', 'Stop before rev_id n (exclusive)', false, true );
|
|
|
|
|
$this->addOption( 'skip-header', 'Don\'t output the <mediawiki> header' );
|
|
|
|
|
$this->addOption( 'skip-footer', 'Don\'t output the </mediawiki> footer' );
|
|
|
|
|
$this->addOption( 'stub', 'Don\'t perform old_text lookups; for 2-pass dump' );
|
|
|
|
|
$this->addOption( 'uploads', 'Include upload records without files' );
|
|
|
|
|
$this->addOption( 'include-files', 'Include files within the XML stream' );
|
2019-04-17 10:49:22 +00:00
|
|
|
$this->addOption( 'namespaces', 'Limit to this comma-separated list of namespace numbers' );
|
2015-12-31 09:46:54 +00:00
|
|
|
|
|
|
|
|
if ( $args ) {
|
|
|
|
|
$this->loadWithArgv( $args );
|
|
|
|
|
$this->processOptions();
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-07 10:07:32 +00:00
|
|
|
|
2019-10-09 18:41:33 +00:00
|
|
|
public function execute() {
|
2015-12-31 09:46:54 +00:00
|
|
|
$this->processOptions();
|
|
|
|
|
|
|
|
|
|
$textMode = $this->hasOption( 'stub' ) ? WikiExporter::STUB : WikiExporter::TEXT;
|
|
|
|
|
|
|
|
|
|
if ( $this->hasOption( 'full' ) ) {
|
|
|
|
|
$this->dump( WikiExporter::FULL, $textMode );
|
|
|
|
|
} elseif ( $this->hasOption( 'current' ) ) {
|
|
|
|
|
$this->dump( WikiExporter::CURRENT, $textMode );
|
|
|
|
|
} elseif ( $this->hasOption( 'stable' ) ) {
|
|
|
|
|
$this->dump( WikiExporter::STABLE, $textMode );
|
|
|
|
|
} elseif ( $this->hasOption( 'logs' ) ) {
|
|
|
|
|
$this->dump( WikiExporter::LOGS );
|
|
|
|
|
} elseif ( $this->hasOption( 'revrange' ) ) {
|
|
|
|
|
$this->dump( WikiExporter::RANGE, $textMode );
|
|
|
|
|
} else {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( 'No valid action specified.' );
|
2015-12-31 09:46:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-11 19:07:32 +00:00
|
|
|
protected function processOptions() {
|
2015-12-31 09:46:54 +00:00
|
|
|
parent::processOptions();
|
|
|
|
|
|
|
|
|
|
// Evaluate options specific to this class
|
|
|
|
|
$this->reporting = !$this->hasOption( 'quiet' );
|
|
|
|
|
|
|
|
|
|
if ( $this->hasOption( 'pagelist' ) ) {
|
2016-01-05 23:42:23 +00:00
|
|
|
$filename = $this->getOption( 'pagelist' );
|
|
|
|
|
$pages = file( $filename );
|
2015-12-31 09:46:54 +00:00
|
|
|
if ( $pages === false ) {
|
2016-01-05 23:42:23 +00:00
|
|
|
$this->fatalError( "Unable to open file {$filename}\n" );
|
2015-12-31 09:46:54 +00:00
|
|
|
}
|
|
|
|
|
$pages = array_map( 'trim', $pages );
|
2021-02-07 02:17:10 +00:00
|
|
|
$this->pages = array_filter( $pages, static function ( $x ) {
|
2016-03-10 23:04:07 +00:00
|
|
|
return $x !== '';
|
|
|
|
|
} );
|
2015-12-31 09:46:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $this->hasOption( 'start' ) ) {
|
|
|
|
|
$this->startId = intval( $this->getOption( 'start' ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $this->hasOption( 'end' ) ) {
|
|
|
|
|
$this->endId = intval( $this->getOption( 'end' ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $this->hasOption( 'revstart' ) ) {
|
|
|
|
|
$this->revStartId = intval( $this->getOption( 'revstart' ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $this->hasOption( 'revend' ) ) {
|
|
|
|
|
$this->revEndId = intval( $this->getOption( 'revend' ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->skipHeader = $this->hasOption( 'skip-header' );
|
|
|
|
|
$this->skipFooter = $this->hasOption( 'skip-footer' );
|
|
|
|
|
$this->dumpUploads = $this->hasOption( 'uploads' );
|
|
|
|
|
$this->dumpUploadFileContents = $this->hasOption( 'include-files' );
|
2016-06-21 20:08:29 +00:00
|
|
|
$this->orderRevs = $this->hasOption( 'orderrevs' );
|
2019-04-17 10:49:22 +00:00
|
|
|
if ( $this->hasOption( 'namespaces' ) ) {
|
|
|
|
|
$this->limitNamespaces = explode( ',', $this->getOption( 'namespaces' ) );
|
|
|
|
|
} else {
|
|
|
|
|
$this->limitNamespaces = null;
|
|
|
|
|
}
|
2015-12-31 09:46:54 +00:00
|
|
|
}
|
2005-05-08 08:17:12 +00:00
|
|
|
}
|
2015-12-31 09:46:54 +00:00
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = DumpBackup::class;
|
2015-12-31 09:46:54 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|