dumpBackup.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 Brion Vibber <brion@pobox.com>
  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 Maintenance
  26. */
  27. require_once __DIR__ . '/backup.inc';
  28. class DumpBackup extends BackupDumper {
  29. function __construct( $args = null ) {
  30. parent::__construct();
  31. $this->addDescription( <<<TEXT
  32. This script dumps the wiki page or logging database into an
  33. XML interchange wrapper format for export or backup.
  34. XML output is sent to stdout; progress reports are sent to stderr.
  35. WARNING: this is not a full database dump! It is merely for public export
  36. of your wiki. For full backup, see our online help at:
  37. https://www.mediawiki.org/wiki/Backup
  38. TEXT
  39. );
  40. $this->stderr = fopen( "php://stderr", "wt" );
  41. // Actions
  42. $this->addOption( 'full', 'Dump all revisions of every page' );
  43. $this->addOption( 'current', 'Dump only the latest revision of every page.' );
  44. $this->addOption( 'logs', 'Dump all log events' );
  45. $this->addOption( 'stable', 'Dump stable versions of pages' );
  46. $this->addOption( 'revrange', 'Dump range of revisions specified by revstart and ' .
  47. 'revend parameters' );
  48. $this->addOption( 'orderrevs', 'Dump revisions in ascending revision order ' .
  49. '(implies dump of a range of pages)' );
  50. $this->addOption( 'pagelist',
  51. 'Dump only pages included in the file', false, true );
  52. // Options
  53. $this->addOption( 'start', 'Start from page_id or log_id', false, true );
  54. $this->addOption( 'end', 'Stop before page_id or log_id n (exclusive)', false, true );
  55. $this->addOption( 'revstart', 'Start from rev_id', false, true );
  56. $this->addOption( 'revend', 'Stop before rev_id n (exclusive)', false, true );
  57. $this->addOption( 'skip-header', 'Don\'t output the <mediawiki> header' );
  58. $this->addOption( 'skip-footer', 'Don\'t output the </mediawiki> footer' );
  59. $this->addOption( 'stub', 'Don\'t perform old_text lookups; for 2-pass dump' );
  60. $this->addOption( 'uploads', 'Include upload records without files' );
  61. $this->addOption( 'include-files', 'Include files within the XML stream' );
  62. if ( $args ) {
  63. $this->loadWithArgv( $args );
  64. $this->processOptions();
  65. }
  66. }
  67. function execute() {
  68. $this->processOptions();
  69. $textMode = $this->hasOption( 'stub' ) ? WikiExporter::STUB : WikiExporter::TEXT;
  70. if ( $this->hasOption( 'full' ) ) {
  71. $this->dump( WikiExporter::FULL, $textMode );
  72. } elseif ( $this->hasOption( 'current' ) ) {
  73. $this->dump( WikiExporter::CURRENT, $textMode );
  74. } elseif ( $this->hasOption( 'stable' ) ) {
  75. $this->dump( WikiExporter::STABLE, $textMode );
  76. } elseif ( $this->hasOption( 'logs' ) ) {
  77. $this->dump( WikiExporter::LOGS );
  78. } elseif ( $this->hasOption( 'revrange' ) ) {
  79. $this->dump( WikiExporter::RANGE, $textMode );
  80. } else {
  81. $this->error( 'No valid action specified.', 1 );
  82. }
  83. }
  84. function processOptions() {
  85. parent::processOptions();
  86. // Evaluate options specific to this class
  87. $this->reporting = !$this->hasOption( 'quiet' );
  88. if ( $this->hasOption( 'pagelist' ) ) {
  89. $filename = $this->getOption( 'pagelist' );
  90. $pages = file( $filename );
  91. if ( $pages === false ) {
  92. $this->fatalError( "Unable to open file {$filename}\n" );
  93. }
  94. $pages = array_map( 'trim', $pages );
  95. $this->pages = array_filter( $pages, function ( $x ) {
  96. return $x !== '';
  97. } );
  98. }
  99. if ( $this->hasOption( 'start' ) ) {
  100. $this->startId = intval( $this->getOption( 'start' ) );
  101. }
  102. if ( $this->hasOption( 'end' ) ) {
  103. $this->endId = intval( $this->getOption( 'end' ) );
  104. }
  105. if ( $this->hasOption( 'revstart' ) ) {
  106. $this->revStartId = intval( $this->getOption( 'revstart' ) );
  107. }
  108. if ( $this->hasOption( 'revend' ) ) {
  109. $this->revEndId = intval( $this->getOption( 'revend' ) );
  110. }
  111. $this->skipHeader = $this->hasOption( 'skip-header' );
  112. $this->skipFooter = $this->hasOption( 'skip-footer' );
  113. $this->dumpUploads = $this->hasOption( 'uploads' );
  114. $this->dumpUploadFileContents = $this->hasOption( 'include-files' );
  115. $this->orderRevs = $this->hasOption( 'orderrevs' );
  116. }
  117. }
  118. $maintClass = 'DumpBackup';
  119. require_once RUN_MAINTENANCE_IF_MAIN;