From: Kunal Mehta Date: Sat, 23 Aug 2014 07:40:00 +0000 (-0700) Subject: Import.php: Use Config instead of globals X-Git-Tag: 1.31.0-rc.0~13432^2 X-Git-Url: http://git.cyclocoop.org/%24self?a=commitdiff_plain;h=4a2ecaa04666d18adfd14dc1765bf4188c284fd2;p=lhc%2Fweb%2Fwiklou.git Import.php: Use Config instead of globals Change-Id: I4d1a8c443cfa360c5d388364c580d48fa7124099 --- diff --git a/includes/Import.php b/includes/Import.php index 5319076e82..4eb8e97488 100644 --- a/includes/Import.php +++ b/includes/Import.php @@ -37,13 +37,21 @@ class WikiImporter { private $mNoticeCallback, $mDebug; private $mImportUploads, $mImageBasePath; private $mNoUpdates = false; + /** @var Config */ + private $config; /** * Creates an ImportXMLReader drawing from the source provided * @param ImportStreamSource $source + * @param Config $config */ - function __construct( ImportStreamSource $source ) { + function __construct( ImportStreamSource $source, Config $config = null ) { $this->reader = new XMLReader(); + if ( !$config ) { + wfDeprecated( __METHOD__ . ' without a Config instance', '1.25' ); + $config = ConfigFactory::getDefaultInstance()->makeConfig( 'main' ); + } + $this->config = $config; if ( !in_array( 'uploadsource', stream_get_wrappers() ) ) { stream_wrapper_register( 'uploadsource', 'UploadSourceAdapter' ); @@ -536,7 +544,7 @@ class WikiImporter { * @return bool|mixed */ private function processLogItem( $logInfo ) { - $revision = new WikiRevision; + $revision = new WikiRevision( $this->config ); $revision->setID( $logInfo['id'] ); $revision->setType( $logInfo['type'] ); @@ -670,7 +678,7 @@ class WikiImporter { * @return bool|mixed */ private function processRevision( $pageInfo, $revisionInfo ) { - $revision = new WikiRevision; + $revision = new WikiRevision( $this->config ); if ( isset( $revisionInfo['id'] ) ) { $revision->setID( $revisionInfo['id'] ); @@ -786,7 +794,7 @@ class WikiImporter { * @return mixed */ private function processUpload( $pageInfo, $uploadInfo ) { - $revision = new WikiRevision; + $revision = new WikiRevision( $this->config ); $text = isset( $uploadInfo['text'] ) ? $uploadInfo['text'] : ''; $revision->setTitle( $pageInfo['_title'] ); @@ -847,8 +855,6 @@ class WikiImporter { * @return array|bool */ private function processTitle( $text ) { - global $wgCommandLineMode; - $workTitle = $text; $origTitle = Title::newFromText( $workTitle ); @@ -864,6 +870,7 @@ class WikiImporter { $title = Title::newFromText( $workTitle ); } + $commandLineMode = $this->config->get( 'CommandLineMode' ); if ( is_null( $title ) ) { # Invalid page title? Ignore the page $this->notice( 'import-error-invalid', $workTitle ); @@ -874,11 +881,11 @@ class WikiImporter { } elseif ( !$title->canExist() ) { $this->notice( 'import-error-special', $title->getPrefixedText() ); return false; - } elseif ( !$title->userCan( 'edit' ) && !$wgCommandLineMode ) { + } elseif ( !$title->userCan( 'edit' ) && !$commandLineMode ) { # Do not import if the importing wiki user cannot edit this page $this->notice( 'import-error-edit', $title->getPrefixedText() ); return false; - } elseif ( !$title->exists() && !$title->userCan( 'create' ) && !$wgCommandLineMode ) { + } elseif ( !$title->exists() && !$title->userCan( 'create' ) && !$commandLineMode ) { # Do not import if the importing wiki user cannot create this page $this->notice( 'import-error-create', $title->getPrefixedText() ); return false; @@ -1093,6 +1100,13 @@ class WikiRevision { /** @var bool */ private $mNoUpdates = false; + /** @var Config $config */ + private $config; + + public function __construct( Config $config ) { + $this->config = $config; + } + /** * @param Title $title * @throws MWException @@ -1608,8 +1622,7 @@ class WikiRevision { * @return bool|string */ function downloadSource() { - global $wgEnableUploads; - if ( !$wgEnableUploads ) { + if ( !$this->config->get( 'EnableUploads' ) ) { return false; } diff --git a/includes/api/ApiImport.php b/includes/api/ApiImport.php index b11348e5b1..12b36f399a 100644 --- a/includes/api/ApiImport.php +++ b/includes/api/ApiImport.php @@ -60,7 +60,7 @@ class ApiImport extends ApiBase { $this->dieStatus( $source ); } - $importer = new WikiImporter( $source->value ); + $importer = new WikiImporter( $source->value, $this->getConfig() ); if ( isset( $params['namespace'] ) ) { $importer->setTargetNamespace( $params['namespace'] ); } diff --git a/includes/specials/SpecialImport.php b/includes/specials/SpecialImport.php index 3d762aa313..2bdb227385 100644 --- a/includes/specials/SpecialImport.php +++ b/includes/specials/SpecialImport.php @@ -157,7 +157,7 @@ class SpecialImport extends SpecialPage { array( 'importfailed', $source->getWikiText() ) ); } else { - $importer = new WikiImporter( $source->value ); + $importer = new WikiImporter( $source->value, $this->getConfig() ); if ( !is_null( $this->namespace ) ) { $importer->setTargetNamespace( $this->namespace ); } diff --git a/maintenance/dumpIterator.php b/maintenance/dumpIterator.php index 4b2ff717e3..d8bc3a4da7 100644 --- a/maintenance/dumpIterator.php +++ b/maintenance/dumpIterator.php @@ -54,7 +54,7 @@ abstract class DumpIterator extends Maintenance { $this->checkOptions(); if ( $this->hasOption( 'file' ) ) { - $revision = new WikiRevision; + $revision = new WikiRevision( $this->getConfig() ); $revision->setText( file_get_contents( $this->getOption( 'file' ) ) ); $revision->setTitle( Title::newFromText( @@ -73,7 +73,7 @@ abstract class DumpIterator extends Maintenance { $this->error( "Sorry, I don't support dump filenames yet. " . "Use - and provide it on stdin on the meantime.", true ); } - $importer = new WikiImporter( $source ); + $importer = new WikiImporter( $source, $this->getConfig() ); $importer->setRevisionCallback( array( &$this, 'handleRevision' ) ); diff --git a/maintenance/importDump.php b/maintenance/importDump.php index 1f75bccfc5..ea8c84bbbf 100644 --- a/maintenance/importDump.php +++ b/maintenance/importDump.php @@ -270,7 +270,7 @@ TEXT; $this->startTime = microtime( true ); $source = new ImportStreamSource( $handle ); - $importer = new WikiImporter( $source ); + $importer = new WikiImporter( $source, $this->getConfig() ); if ( $this->hasOption( 'debug' ) ) { $importer->setDebug( true ); diff --git a/maintenance/renderDump.php b/maintenance/renderDump.php index 169f512cfa..2218a5e7a3 100644 --- a/maintenance/renderDump.php +++ b/maintenance/renderDump.php @@ -61,7 +61,7 @@ class DumpRenderer extends Maintenance { } $source = new ImportStreamSource( $this->getStdin() ); - $importer = new WikiImporter( $source ); + $importer = new WikiImporter( $source, $this->getConfig() ); $importer->setRevisionCallback( array( &$this, 'handleRevision' ) ); diff --git a/maintenance/storage/checkStorage.php b/maintenance/storage/checkStorage.php index 0f996625fe..c0f6c7b6fa 100644 --- a/maintenance/storage/checkStorage.php +++ b/maintenance/storage/checkStorage.php @@ -39,6 +39,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { /** * Maintenance script to do various checks on external storage. * + * @fixme this should extend the base Maintenance class * @ingroup Maintenance ExternalStorage */ class CheckStorage { @@ -466,7 +467,10 @@ class CheckStorage { $dbw->ping(); $source = new ImportStreamSource( $file ); - $importer = new WikiImporter( $source ); + $importer = new WikiImporter( + $source, + ConfigFactory::getDefaultInstance()->makeConfig( 'main' ) + ); $importer->setRevisionCallback( array( &$this, 'importRevision' ) ); $importer->doImport(); } diff --git a/tests/phpunit/includes/ImportTest.php b/tests/phpunit/includes/ImportTest.php index 2fce6bfb87..77e8169f03 100644 --- a/tests/phpunit/includes/ImportTest.php +++ b/tests/phpunit/includes/ImportTest.php @@ -34,7 +34,7 @@ class ImportTest extends MediaWikiLangTestCase { } }; - $importer = new WikiImporter( $source ); + $importer = new WikiImporter( $source, ConfigFactory::getDefaultInstance()->makeConfig( 'main' ) ); $importer->setPageOutCallback( $callback ); $importer->doImport();