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 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation; either version 2 of the License, or |
12 | * (at your option) any later version. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License along |
20 | * with this program; if not, write to the Free Software Foundation, Inc., |
21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
22 | * http://www.gnu.org/copyleft/gpl.html |
23 | * |
24 | * @file |
25 | * @ingroup Dump |
26 | * @ingroup Maintenance |
27 | */ |
28 | |
29 | use MediaWiki\Maintenance\BackupDumper; |
30 | |
31 | // @codeCoverageIgnoreStart |
32 | require_once __DIR__ . '/includes/BackupDumper.php'; |
33 | // @codeCoverageIgnoreEnd |
34 | |
35 | class DumpBackup extends BackupDumper { |
36 | public function __construct( $args = null ) { |
37 | parent::__construct(); |
38 | |
39 | $this->addDescription( <<<TEXT |
40 | This script dumps the wiki page or logging database into an |
41 | XML interchange wrapper format for export or backup. |
42 | |
43 | XML output is sent to stdout; progress reports are sent to stderr. |
44 | |
45 | WARNING: this is not a full database dump! It is merely for public export |
46 | of your wiki. For full backup, see our online help at: |
47 | https://www.mediawiki.org/wiki/Backup |
48 | TEXT |
49 | ); |
50 | |
51 | // Actions |
52 | $this->addOption( 'full', 'Dump all revisions of every page' ); |
53 | $this->addOption( 'current', 'Dump only the latest revision of every page.' ); |
54 | $this->addOption( 'logs', 'Dump all log events' ); |
55 | $this->addOption( 'stable', 'Dump stable versions of pages' ); |
56 | $this->addOption( 'revrange', 'Dump range of revisions specified by revstart and ' . |
57 | 'revend parameters' ); |
58 | $this->addOption( 'orderrevs', 'Dump revisions in ascending revision order ' . |
59 | '(implies dump of a range of pages)' ); |
60 | $this->addOption( 'pagelist', |
61 | 'Dump only pages included in the file', false, true ); |
62 | // Options |
63 | $this->addOption( 'start', 'Start from page_id or log_id', false, true ); |
64 | $this->addOption( 'end', 'Stop before page_id or log_id n (exclusive)', false, true ); |
65 | $this->addOption( 'revstart', 'Start from rev_id', false, true ); |
66 | $this->addOption( 'revend', 'Stop before rev_id n (exclusive)', false, true ); |
67 | $this->addOption( 'skip-header', 'Don\'t output the <mediawiki> header' ); |
68 | $this->addOption( 'skip-footer', 'Don\'t output the </mediawiki> footer' ); |
69 | $this->addOption( 'stub', 'Don\'t perform old_text lookups; for 2-pass dump' ); |
70 | $this->addOption( 'uploads', 'Include upload records without files' ); |
71 | $this->addOption( 'include-files', 'Include files within the XML stream' ); |
72 | $this->addOption( 'namespaces', 'Limit to this comma-separated list of namespace numbers' ); |
73 | |
74 | if ( $args ) { |
75 | $this->loadWithArgv( $args ); |
76 | $this->processOptions(); |
77 | } |
78 | } |
79 | |
80 | public function execute() { |
81 | $this->processOptions(); |
82 | |
83 | $textMode = $this->hasOption( 'stub' ) ? WikiExporter::STUB : WikiExporter::TEXT; |
84 | |
85 | if ( $this->hasOption( 'full' ) ) { |
86 | $this->dump( WikiExporter::FULL, $textMode ); |
87 | } elseif ( $this->hasOption( 'current' ) ) { |
88 | $this->dump( WikiExporter::CURRENT, $textMode ); |
89 | } elseif ( $this->hasOption( 'stable' ) ) { |
90 | $this->dump( WikiExporter::STABLE, $textMode ); |
91 | } elseif ( $this->hasOption( 'logs' ) ) { |
92 | $this->dump( WikiExporter::LOGS ); |
93 | } elseif ( $this->hasOption( 'revrange' ) ) { |
94 | $this->dump( WikiExporter::RANGE, $textMode ); |
95 | } else { |
96 | $this->fatalError( 'No valid action specified.' ); |
97 | } |
98 | } |
99 | |
100 | protected function processOptions() { |
101 | parent::processOptions(); |
102 | |
103 | // Evaluate options specific to this class |
104 | $this->reporting = !$this->hasOption( 'quiet' ); |
105 | |
106 | if ( $this->hasOption( 'pagelist' ) ) { |
107 | $filename = $this->getOption( 'pagelist' ); |
108 | $pages = file( $filename ); |
109 | if ( $pages === false ) { |
110 | $this->fatalError( "Unable to open file {$filename}\n" ); |
111 | } |
112 | $pages = array_map( 'trim', $pages ); |
113 | $this->pages = array_filter( $pages, static function ( $x ) { |
114 | return $x !== ''; |
115 | } ); |
116 | } |
117 | |
118 | if ( $this->hasOption( 'start' ) ) { |
119 | $this->startId = intval( $this->getOption( 'start' ) ); |
120 | } |
121 | |
122 | if ( $this->hasOption( 'end' ) ) { |
123 | $this->endId = intval( $this->getOption( 'end' ) ); |
124 | } |
125 | |
126 | if ( $this->hasOption( 'revstart' ) ) { |
127 | $this->revStartId = intval( $this->getOption( 'revstart' ) ); |
128 | } |
129 | |
130 | if ( $this->hasOption( 'revend' ) ) { |
131 | $this->revEndId = intval( $this->getOption( 'revend' ) ); |
132 | } |
133 | |
134 | $this->skipHeader = $this->hasOption( 'skip-header' ); |
135 | $this->skipFooter = $this->hasOption( 'skip-footer' ); |
136 | $this->dumpUploads = $this->hasOption( 'uploads' ); |
137 | $this->dumpUploadFileContents = $this->hasOption( 'include-files' ); |
138 | $this->orderRevs = $this->hasOption( 'orderrevs' ); |
139 | if ( $this->hasOption( 'namespaces' ) ) { |
140 | $this->limitNamespaces = explode( ',', $this->getOption( 'namespaces' ) ); |
141 | } else { |
142 | $this->limitNamespaces = null; |
143 | } |
144 | } |
145 | } |
146 | |
147 | // @codeCoverageIgnoreStart |
148 | $maintClass = DumpBackup::class; |
149 | require_once RUN_MAINTENANCE_IF_MAIN; |
150 | // @codeCoverageIgnoreEnd |