MediaWiki master
dumpBackup.php
Go to the documentation of this file.
1<?php
29// @codeCoverageIgnoreStart
30require_once __DIR__ . '/includes/BackupDumper.php';
31// @codeCoverageIgnoreEnd
32
33class DumpBackup extends BackupDumper {
34 public function __construct( $args = null ) {
35 parent::__construct();
36
37 $this->addDescription( <<<TEXT
38This script dumps the wiki page or logging database into an
39XML interchange wrapper format for export or backup.
40
41XML output is sent to stdout; progress reports are sent to stderr.
42
43WARNING: this is not a full database dump! It is merely for public export
44 of your wiki. For full backup, see our online help at:
45 https://www.mediawiki.org/wiki/Backup
46TEXT
47 );
48
49 // Actions
50 $this->addOption( 'full', 'Dump all revisions of every page' );
51 $this->addOption( 'current', 'Dump only the latest revision of every page.' );
52 $this->addOption( 'logs', 'Dump all log events' );
53 $this->addOption( 'stable', 'Dump stable versions of pages' );
54 $this->addOption( 'revrange', 'Dump range of revisions specified by revstart and ' .
55 'revend parameters' );
56 $this->addOption( 'orderrevs', 'Dump revisions in ascending revision order ' .
57 '(implies dump of a range of pages)' );
58 $this->addOption( 'pagelist',
59 'Dump only pages included in the file', false, true );
60 // Options
61 $this->addOption( 'start', 'Start from page_id or log_id', false, true );
62 $this->addOption( 'end', 'Stop before page_id or log_id n (exclusive)', false, true );
63 $this->addOption( 'revstart', 'Start from rev_id', false, true );
64 $this->addOption( 'revend', 'Stop before rev_id n (exclusive)', false, true );
65 $this->addOption( 'skip-header', 'Don\'t output the <mediawiki> header' );
66 $this->addOption( 'skip-footer', 'Don\'t output the </mediawiki> footer' );
67 $this->addOption( 'stub', 'Don\'t perform old_text lookups; for 2-pass dump' );
68 $this->addOption( 'uploads', 'Include upload records without files' );
69 $this->addOption( 'include-files', 'Include files within the XML stream' );
70 $this->addOption( 'namespaces', 'Limit to this comma-separated list of namespace numbers' );
71
72 if ( $args ) {
73 $this->loadWithArgv( $args );
74 $this->processOptions();
75 }
76 }
77
78 public function execute() {
79 $this->processOptions();
80
81 $textMode = $this->hasOption( 'stub' ) ? WikiExporter::STUB : WikiExporter::TEXT;
82
83 if ( $this->hasOption( 'full' ) ) {
84 $this->dump( WikiExporter::FULL, $textMode );
85 } elseif ( $this->hasOption( 'current' ) ) {
86 $this->dump( WikiExporter::CURRENT, $textMode );
87 } elseif ( $this->hasOption( 'stable' ) ) {
88 $this->dump( WikiExporter::STABLE, $textMode );
89 } elseif ( $this->hasOption( 'logs' ) ) {
90 $this->dump( WikiExporter::LOGS );
91 } elseif ( $this->hasOption( 'revrange' ) ) {
92 $this->dump( WikiExporter::RANGE, $textMode );
93 } else {
94 $this->fatalError( 'No valid action specified.' );
95 }
96 }
97
98 protected function processOptions() {
99 parent::processOptions();
100
101 // Evaluate options specific to this class
102 $this->reporting = !$this->hasOption( 'quiet' );
103
104 if ( $this->hasOption( 'pagelist' ) ) {
105 $filename = $this->getOption( 'pagelist' );
106 $pages = file( $filename );
107 if ( $pages === false ) {
108 $this->fatalError( "Unable to open file {$filename}\n" );
109 }
110 $pages = array_map( 'trim', $pages );
111 $this->pages = array_filter( $pages, static function ( $x ) {
112 return $x !== '';
113 } );
114 }
115
116 if ( $this->hasOption( 'start' ) ) {
117 $this->startId = intval( $this->getOption( 'start' ) );
118 }
119
120 if ( $this->hasOption( 'end' ) ) {
121 $this->endId = intval( $this->getOption( 'end' ) );
122 }
123
124 if ( $this->hasOption( 'revstart' ) ) {
125 $this->revStartId = intval( $this->getOption( 'revstart' ) );
126 }
127
128 if ( $this->hasOption( 'revend' ) ) {
129 $this->revEndId = intval( $this->getOption( 'revend' ) );
130 }
131
132 $this->skipHeader = $this->hasOption( 'skip-header' );
133 $this->skipFooter = $this->hasOption( 'skip-footer' );
134 $this->dumpUploads = $this->hasOption( 'uploads' );
135 $this->dumpUploadFileContents = $this->hasOption( 'include-files' );
136 $this->orderRevs = $this->hasOption( 'orderrevs' );
137 if ( $this->hasOption( 'namespaces' ) ) {
138 $this->limitNamespaces = explode( ',', $this->getOption( 'namespaces' ) );
139 } else {
140 $this->limitNamespaces = null;
141 }
142 }
143}
144
145// @codeCoverageIgnoreStart
146$maintClass = DumpBackup::class;
147require_once RUN_MAINTENANCE_IF_MAIN;
148// @codeCoverageIgnoreEnd
dump( $history, $text=WikiExporter::TEXT)
progress( $string)
string[] null $pages
null means all pages
execute()
Do the actual work.
processOptions()
Processes arguments and sets $this->$sink accordingly.
__construct( $args=null)
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
addDescription( $text)
Set the description text.
loadWithArgv( $argv)
Load params and arguments from a given array of command-line arguments.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
$maintClass