public function setImageBasePath( $dir ) {
$this->mImageBasePath = $dir;
}
+ public function setImportUploads( $import ) {
+ $this->mImportUploads = $import;
+ }
/**
* Default per-revision callback, performs the import.
$encoding = $this->reader->getAttribute( 'encoding' );
if ( $encoding === 'base64' ) {
$uploadInfo['fileSrc'] = $this->dumpTemp( base64_decode( $contents ) );
+ $uploadInfo['isTempSrc'] = true;
}
} elseif ( $tag != '#text' ) {
$this->warn( "Unhandled upload XML tag $tag" );
$path = "{$this->mImageBasePath}/{$uploadInfo['rel']}";
if ( file_exists( $path ) ) {
$uploadInfo['fileSrc'] = $path;
+ $uploadInfo['isTempSrc'] = false;
}
}
}
$revision->setSrc( $uploadInfo['src'] );
if ( isset( $uploadInfo['fileSrc'] ) ) {
- $revision->setFileSrc( $uploadInfo['fileSrc'] );
+ $revision->setFileSrc( $uploadInfo['fileSrc'],
+ !empty( $uploadInfo['isTempSrc'] ) );
+ }
+ if ( isset( $uploadInfo['sha1base36'] ) ) {
+ $revision->setSha1Base36( $uploadInfo['sha1base36'] );
}
$revision->setSize( intval( $uploadInfo['size'] ) );
$revision->setComment( $uploadInfo['comment'] );
var $action = "";
var $params = "";
var $fileSrc = '';
+ var $sha1base36 = false;
+ var $isTemp = false;
var $archiveName = '';
function setTitle( $title ) {
function setSrc( $src ) {
$this->src = $src;
}
- function setFileSrc( $src ) {
+ function setFileSrc( $src, $isTemp ) {
$this->fileSrc = $src;
+ $this->fileIsTemp = $isTemp;
+ }
+ function setSha1Base36( $sha1base36 ) {
+ $this->sha1base36 = $sha1base36;
}
function setFilename( $filename ) {
function getSrc() {
return $this->src;
}
+ function getSha1() {
+ if ( $this->sha1base36 ) {
+ return wfBaseConvert( $this->sha1base36, 36, 16 );
+ }
+ return false;
+ }
function getFileSrc() {
return $this->fileSrc;
}
+ function isTempSrc() {
+ return $this->isTemp;
+ }
function getFilename() {
return $this->filename;
# Get the file source or download if necessary
$source = $this->getFileSrc();
+ $flags = $this->isTempSrc() ? File::DELETE_SOURCE : 0;
if ( !$source ) {
$source = $this->downloadSource();
+ $flags |= File::DELETE_SOURCE;
}
if( !$source ) {
wfDebug( __METHOD__ . ": Could not fetch remote file.\n" );
return false;
}
+ $sha1 = $this->getSha1();
+ if ( $sha1 && ( $sha1 !== sha1_file( $source ) ) ) {
+ wfDebug( __METHOD__ . ": Corrupt file $source.\n" );
+ return false;
+ }
$user = User::newFromName( $this->user_text );
# Do the actual upload
if ( $archiveName ) {
$status = $file->uploadOld( $source, $archiveName,
- $this->getTimestamp(), $this->getComment(), $user, File::DELETE_SOURCE );
+ $this->getTimestamp(), $this->getComment(), $user, $flags );
} else {
$status = $file->upload( $source, $this->getComment(), $this->getComment(),
- File::DELETE_SOURCE, false, $this->getTimestamp(), $user );
+ $flags, false, $this->getTimestamp(), $user );
}
if ( $status->isGood() ) {
var $dryRun = false;
var $debug = false;
var $uploads = false;
+ var $imageBasePath = false;
var $nsFilter = false;
function __construct() {
array( &$this, 'handleUpload' ) );
$this->logItemCallback = $importer->setLogItemCallback(
array( &$this, 'handleLogItem' ) );
+ if ( $this->uploads ) {
+ $importer->setImportUploads( true );
+ }
+ if ( $this->imageBasePath ) {
+ $importer->setImageBasePath( $this->imageBasePath );
+ }
if ( $this->dryRun ) {
$importer->setPageOutCallback( null );
echo " --dry-run Parse dump without actually importing pages.\n";
echo " --debug Output extra verbose debug information\n";
echo " --uploads Process file upload data if included (experimental)\n";
+ echo " --image-base-path=path Import files from a specified path\n";
echo "\n";
echo "Compressed XML files may be read directly:\n";
echo " .gz $gz\n";
if ( isset( $options['uploads'] ) ) {
$reader->uploads = true; // experimental!
}
+if ( isset( $options['image-base-path'] ) ) {
+ $reader->imageBasePath = $options['image-base-path'];
+}
if ( isset( $options['namespaces'] ) ) {
$reader->setNsfilter( explode( '|', $options['namespaces'] ) );
}