2005-07-05 03:16:56 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2005 Brion Vibber <brion@pobox.com>
|
|
|
|
|
* http://www.mediawiki.org/
|
2005-08-02 13:35:19 +00:00
|
|
|
*
|
2005-07-05 03:16:56 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2005-08-02 13:35:19 +00:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
2005-07-05 03:16:56 +00:00
|
|
|
* (at your option) any later version.
|
2005-08-02 13:35:19 +00:00
|
|
|
*
|
2005-07-05 03:16:56 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
2005-08-02 13:35:19 +00:00
|
|
|
*
|
2005-07-05 03:16:56 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
2006-04-05 07:43:17 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-07-05 03:16:56 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @file
|
|
|
|
|
* @ingroup Maintenance
|
2005-07-05 03:16:56 +00:00
|
|
|
*/
|
|
|
|
|
|
2005-07-22 23:31:11 +00:00
|
|
|
$optionsWithArgs = array( 'report' );
|
2005-07-05 03:16:56 +00:00
|
|
|
|
2009-08-03 21:56:41 +00:00
|
|
|
require_once( dirname(__FILE__) . '/commandLine.inc' );
|
2005-07-05 03:16:56 +00:00
|
|
|
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
/**
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2005-07-05 03:16:56 +00:00
|
|
|
class BackupReader {
|
|
|
|
|
var $reportingInterval = 100;
|
|
|
|
|
var $reporting = true;
|
|
|
|
|
var $pageCount = 0;
|
|
|
|
|
var $revCount = 0;
|
|
|
|
|
var $dryRun = false;
|
2008-03-06 07:24:29 +00:00
|
|
|
var $debug = false;
|
2008-03-07 23:14:30 +00:00
|
|
|
var $uploads = false;
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-07-05 03:16:56 +00:00
|
|
|
function BackupReader() {
|
|
|
|
|
$this->stderr = fopen( "php://stderr", "wt" );
|
|
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-07-05 03:16:56 +00:00
|
|
|
function reportPage( $page ) {
|
|
|
|
|
$this->pageCount++;
|
|
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-07-05 03:16:56 +00:00
|
|
|
function handleRevision( $rev ) {
|
|
|
|
|
$title = $rev->getTitle();
|
2008-09-18 20:52:34 +00:00
|
|
|
if( !$title ) {
|
2005-09-24 03:44:54 +00:00
|
|
|
$this->progress( "Got bogus revision with null title!" );
|
2005-08-02 13:35:19 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-05 03:16:56 +00:00
|
|
|
$this->revCount++;
|
|
|
|
|
$this->report();
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-07-05 03:16:56 +00:00
|
|
|
if( !$this->dryRun ) {
|
|
|
|
|
call_user_func( $this->importCallback, $rev );
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-03-06 07:24:29 +00:00
|
|
|
|
2008-03-07 23:14:30 +00:00
|
|
|
function handleUpload( $revision ) {
|
|
|
|
|
if( $this->uploads ) {
|
|
|
|
|
$this->uploadCount++;
|
|
|
|
|
//$this->report();
|
|
|
|
|
$this->progress( "upload: " . $revision->getFilename() );
|
|
|
|
|
|
|
|
|
|
if( !$this->dryRun ) {
|
|
|
|
|
// bluuuh hack
|
|
|
|
|
//call_user_func( $this->uploadCallback, $revision );
|
|
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
|
|
|
|
return $dbw->deadlockLoop( array( $revision, 'importUpload' ) );
|
|
|
|
|
}
|
2008-03-06 07:24:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2008-09-18 20:52:34 +00:00
|
|
|
function handleLogItem( $rev ) {
|
|
|
|
|
$this->revCount++;
|
|
|
|
|
$this->report();
|
|
|
|
|
|
|
|
|
|
if( !$this->dryRun ) {
|
|
|
|
|
call_user_func( $this->logItemCallback, $rev );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-05 03:16:56 +00:00
|
|
|
function report( $final = false ) {
|
|
|
|
|
if( $final xor ( $this->pageCount % $this->reportingInterval == 0 ) ) {
|
|
|
|
|
$this->showReport();
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-07-05 03:16:56 +00:00
|
|
|
function showReport() {
|
|
|
|
|
if( $this->reporting ) {
|
|
|
|
|
$delta = wfTime() - $this->startTime;
|
|
|
|
|
if( $delta ) {
|
2007-03-28 18:49:49 +00:00
|
|
|
$rate = sprintf("%.2f", $this->pageCount / $delta);
|
|
|
|
|
$revrate = sprintf("%.2f", $this->revCount / $delta);
|
2005-07-05 03:16:56 +00:00
|
|
|
} else {
|
|
|
|
|
$rate = '-';
|
|
|
|
|
$revrate = '-';
|
|
|
|
|
}
|
2008-09-18 21:48:55 +00:00
|
|
|
# Logs dumps don't have page tallies
|
|
|
|
|
if( $this->pageCount )
|
|
|
|
|
$this->progress( "$this->pageCount ($rate pages/sec $revrate revs/sec)" );
|
|
|
|
|
else
|
|
|
|
|
$this->progress( "$this->revCount ($revrate revs/sec)" );
|
2005-07-05 03:16:56 +00:00
|
|
|
}
|
2008-07-07 03:31:00 +00:00
|
|
|
wfWaitForSlaves(5);
|
2005-07-05 03:16:56 +00:00
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-07-05 03:16:56 +00:00
|
|
|
function progress( $string ) {
|
|
|
|
|
fwrite( $this->stderr, $string . "\n" );
|
|
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-07-05 03:16:56 +00:00
|
|
|
function importFromFile( $filename ) {
|
2009-08-07 00:53:21 +00:00
|
|
|
$t = true;
|
2005-07-05 03:16:56 +00:00
|
|
|
if( preg_match( '/\.gz$/', $filename ) ) {
|
|
|
|
|
$filename = 'compress.zlib://' . $filename;
|
|
|
|
|
}
|
2009-08-07 00:53:21 +00:00
|
|
|
elseif( preg_match( '/\.bz2$/', $filename ) ) {
|
|
|
|
|
$filename = 'compress.bzip2://' . $filename;
|
|
|
|
|
}
|
|
|
|
|
elseif( preg_match( '/\.7z$/', $filename ) ) {
|
|
|
|
|
$filename = 'mediawiki.compress.7z://' . $filename;
|
|
|
|
|
$t = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$file = fopen( $filename, $t ? 'rt' : 't' ); //our 7zip wrapper uses popen, which seems not to like two-letter modes
|
2005-09-17 11:10:15 +00:00
|
|
|
return $this->importFromHandle( $file );
|
2005-07-05 03:16:56 +00:00
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-07-05 03:16:56 +00:00
|
|
|
function importFromStdin() {
|
|
|
|
|
$file = fopen( 'php://stdin', 'rt' );
|
2005-09-17 11:10:15 +00:00
|
|
|
return $this->importFromHandle( $file );
|
2005-07-05 03:16:56 +00:00
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-07-05 03:16:56 +00:00
|
|
|
function importFromHandle( $handle ) {
|
|
|
|
|
$this->startTime = wfTime();
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-07-05 03:16:56 +00:00
|
|
|
$source = new ImportStreamSource( $handle );
|
2010-05-12 13:38:56 +00:00
|
|
|
$importer = new WikiImporter( $source );
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2008-03-06 07:24:29 +00:00
|
|
|
$importer->setDebug( $this->debug );
|
2005-07-05 03:16:56 +00:00
|
|
|
$importer->setPageCallback( array( &$this, 'reportPage' ) );
|
|
|
|
|
$this->importCallback = $importer->setRevisionCallback(
|
|
|
|
|
array( &$this, 'handleRevision' ) );
|
2008-03-06 07:24:29 +00:00
|
|
|
$this->uploadCallback = $importer->setUploadCallback(
|
|
|
|
|
array( &$this, 'handleUpload' ) );
|
2008-09-18 20:52:34 +00:00
|
|
|
$this->logItemCallback = $importer->setLogItemCallback(
|
|
|
|
|
array( &$this, 'handleLogItem' ) );
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-09-17 11:10:15 +00:00
|
|
|
return $importer->doImport();
|
2005-07-05 03:16:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-10-05 01:23:22 +00:00
|
|
|
if( wfReadOnly() ) {
|
2006-01-14 02:49:43 +00:00
|
|
|
wfDie( "Wiki is in read-only mode; you'll need to disable it for import to work.\n" );
|
2005-10-05 01:23:22 +00:00
|
|
|
}
|
|
|
|
|
|
2005-07-05 03:16:56 +00:00
|
|
|
$reader = new BackupReader();
|
|
|
|
|
if( isset( $options['quiet'] ) ) {
|
|
|
|
|
$reader->reporting = false;
|
|
|
|
|
}
|
|
|
|
|
if( isset( $options['report'] ) ) {
|
2005-08-16 23:36:16 +00:00
|
|
|
$reader->reportingInterval = intval( $options['report'] );
|
2005-07-05 03:16:56 +00:00
|
|
|
}
|
|
|
|
|
if( isset( $options['dry-run'] ) ) {
|
|
|
|
|
$reader->dryRun = true;
|
|
|
|
|
}
|
2008-03-06 07:24:29 +00:00
|
|
|
if( isset( $options['debug'] ) ) {
|
|
|
|
|
$reader->debug = true;
|
|
|
|
|
}
|
2008-03-07 23:14:30 +00:00
|
|
|
if( isset( $options['uploads'] ) ) {
|
|
|
|
|
$reader->uploads = true; // experimental!
|
|
|
|
|
}
|
2005-07-05 03:16:56 +00:00
|
|
|
|
|
|
|
|
if( isset( $args[0] ) ) {
|
2005-09-17 11:10:15 +00:00
|
|
|
$result = $reader->importFromFile( $args[0] );
|
2005-07-05 03:16:56 +00:00
|
|
|
} else {
|
2005-09-17 11:10:15 +00:00
|
|
|
$result = $reader->importFromStdin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( WikiError::isError( $result ) ) {
|
|
|
|
|
echo $result->getMessage() . "\n";
|
|
|
|
|
} else {
|
|
|
|
|
echo "Done!\n";
|
2007-01-07 18:50:26 +00:00
|
|
|
echo "You might want to run rebuildrecentchanges.php to regenerate\n";
|
2007-03-09 02:06:34 +00:00
|
|
|
echo "the recentchanges page.\n";
|
2005-07-05 03:16:56 +00:00
|
|
|
}
|
|
|
|
|
|
2007-06-29 01:19:14 +00:00
|
|
|
|