dumpBackup.php 4.9 KB

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