Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 67 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| DumpBackup | |
0.00% |
0 / 67 |
|
0.00% |
0 / 3 |
306 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
6 | |||
| execute | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
56 | |||
| processOptions | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
72 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Script that dumps wiki pages or logging database into an XML interchange |
| 4 | * wrapper format for export or backup |
| 5 | * |
| 6 | * Copyright © 2005 Brooke Vibber <bvibber@wikimedia.org> |
| 7 | * https://www.mediawiki.org/ |
| 8 | * |
| 9 | * @license GPL-2.0-or-later |
| 10 | * @file |
| 11 | * @ingroup Dump |
| 12 | * @ingroup Maintenance |
| 13 | */ |
| 14 | |
| 15 | use MediaWiki\Export\WikiExporter; |
| 16 | use MediaWiki\Maintenance\BackupDumper; |
| 17 | |
| 18 | // @codeCoverageIgnoreStart |
| 19 | require_once __DIR__ . '/includes/BackupDumper.php'; |
| 20 | // @codeCoverageIgnoreEnd |
| 21 | |
| 22 | class DumpBackup extends BackupDumper { |
| 23 | public function __construct( ?array $args = null ) { |
| 24 | parent::__construct(); |
| 25 | |
| 26 | $this->addDescription( <<<TEXT |
| 27 | This script dumps the wiki page or logging database into an |
| 28 | XML interchange wrapper format for export or backup. |
| 29 | |
| 30 | XML output is sent to stdout; progress reports are sent to stderr. |
| 31 | |
| 32 | WARNING: this is not a full database dump! It is merely for public export |
| 33 | of your wiki. For full backup, see our online help at: |
| 34 | https://www.mediawiki.org/wiki/Backup |
| 35 | TEXT |
| 36 | ); |
| 37 | |
| 38 | // Actions |
| 39 | $this->addOption( 'full', 'Dump all revisions of every page' ); |
| 40 | $this->addOption( 'current', 'Dump only the latest revision of every page.' ); |
| 41 | $this->addOption( 'logs', 'Dump all log events' ); |
| 42 | $this->addOption( 'stable', 'Dump stable versions of pages' ); |
| 43 | $this->addOption( 'revrange', 'Dump range of revisions specified by revstart and ' . |
| 44 | 'revend parameters' ); |
| 45 | $this->addOption( 'orderrevs', 'Dump revisions in ascending revision order ' . |
| 46 | '(implies dump of a range of pages)' ); |
| 47 | $this->addOption( 'pagelist', |
| 48 | 'Dump only pages included in the file', false, true ); |
| 49 | // Options |
| 50 | $this->addOption( 'start', 'Start from page_id or log_id', false, true ); |
| 51 | $this->addOption( 'end', 'Stop before page_id or log_id n (exclusive)', false, true ); |
| 52 | $this->addOption( 'revstart', 'Start from rev_id', false, true ); |
| 53 | $this->addOption( 'revend', 'Stop before rev_id n (exclusive)', false, true ); |
| 54 | $this->addOption( 'skip-header', 'Don\'t output the <mediawiki> header' ); |
| 55 | $this->addOption( 'skip-footer', 'Don\'t output the </mediawiki> footer' ); |
| 56 | $this->addOption( 'stub', 'Don\'t perform old_text lookups; for 2-pass dump' ); |
| 57 | $this->addOption( 'uploads', 'Include upload records without files' ); |
| 58 | $this->addOption( 'include-files', 'Include files within the XML stream' ); |
| 59 | $this->addOption( 'namespaces', 'Limit to this comma-separated list of namespace numbers' ); |
| 60 | |
| 61 | if ( $args ) { |
| 62 | $this->loadWithArgv( $args ); |
| 63 | $this->processOptions(); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | public function execute() { |
| 68 | $this->processOptions(); |
| 69 | |
| 70 | $textMode = $this->hasOption( 'stub' ) ? WikiExporter::STUB : WikiExporter::TEXT; |
| 71 | |
| 72 | if ( $this->hasOption( 'full' ) ) { |
| 73 | $this->dump( WikiExporter::FULL, $textMode ); |
| 74 | } elseif ( $this->hasOption( 'current' ) ) { |
| 75 | $this->dump( WikiExporter::CURRENT, $textMode ); |
| 76 | } elseif ( $this->hasOption( 'stable' ) ) { |
| 77 | $this->dump( WikiExporter::STABLE, $textMode ); |
| 78 | } elseif ( $this->hasOption( 'logs' ) ) { |
| 79 | $this->dump( WikiExporter::LOGS ); |
| 80 | } elseif ( $this->hasOption( 'revrange' ) ) { |
| 81 | $this->dump( WikiExporter::RANGE, $textMode ); |
| 82 | } else { |
| 83 | $this->fatalError( 'No valid action specified.' ); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | protected function processOptions() { |
| 88 | parent::processOptions(); |
| 89 | |
| 90 | // Evaluate options specific to this class |
| 91 | $this->reporting = !$this->hasOption( 'quiet' ); |
| 92 | |
| 93 | if ( $this->hasOption( 'pagelist' ) ) { |
| 94 | $filename = $this->getOption( 'pagelist' ); |
| 95 | $pages = file( $filename ); |
| 96 | if ( $pages === false ) { |
| 97 | $this->fatalError( "Unable to open file {$filename}\n" ); |
| 98 | } |
| 99 | $pages = array_map( 'trim', $pages ); |
| 100 | $this->pages = array_filter( $pages, static function ( $x ) { |
| 101 | return $x !== ''; |
| 102 | } ); |
| 103 | } |
| 104 | |
| 105 | if ( $this->hasOption( 'start' ) ) { |
| 106 | $this->startId = intval( $this->getOption( 'start' ) ); |
| 107 | } |
| 108 | |
| 109 | if ( $this->hasOption( 'end' ) ) { |
| 110 | $this->endId = intval( $this->getOption( 'end' ) ); |
| 111 | } |
| 112 | |
| 113 | if ( $this->hasOption( 'revstart' ) ) { |
| 114 | $this->revStartId = intval( $this->getOption( 'revstart' ) ); |
| 115 | } |
| 116 | |
| 117 | if ( $this->hasOption( 'revend' ) ) { |
| 118 | $this->revEndId = intval( $this->getOption( 'revend' ) ); |
| 119 | } |
| 120 | |
| 121 | $this->skipHeader = $this->hasOption( 'skip-header' ); |
| 122 | $this->skipFooter = $this->hasOption( 'skip-footer' ); |
| 123 | $this->dumpUploads = $this->hasOption( 'uploads' ); |
| 124 | $this->dumpUploadFileContents = $this->hasOption( 'include-files' ); |
| 125 | $this->orderRevs = $this->hasOption( 'orderrevs' ); |
| 126 | if ( $this->hasOption( 'namespaces' ) ) { |
| 127 | $this->limitNamespaces = explode( ',', $this->getOption( 'namespaces' ) ); |
| 128 | } else { |
| 129 | $this->limitNamespaces = null; |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | // @codeCoverageIgnoreStart |
| 135 | $maintClass = DumpBackup::class; |
| 136 | require_once RUN_MAINTENANCE_IF_MAIN; |
| 137 | // @codeCoverageIgnoreEnd |