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' );
*/
public function finishImportPage( $title, $origTitle, $revCount, $sRevCount, $pageInfo ) {
$args = func_get_args();
- return wfRunHooks( 'AfterImportPage', $args );
+ return Hooks::run( 'AfterImportPage', $args );
}
/**
$buffer = "";
while ( $this->reader->read() ) {
switch ( $this->reader->nodeType ) {
- case XmlReader::TEXT:
- case XmlReader::SIGNIFICANT_WHITESPACE:
+ case XMLReader::TEXT:
+ case XMLReader::SIGNIFICANT_WHITESPACE:
$buffer .= $this->reader->value;
break;
- case XmlReader::END_ELEMENT:
+ case XMLReader::END_ELEMENT:
return $buffer;
}
}
$tag = $this->reader->name;
$type = $this->reader->nodeType;
- if ( !wfRunHooks( 'ImportHandleToplevelXMLTag', array( $this ) ) ) {
+ if ( !Hooks::run( 'ImportHandleToplevelXMLTag', array( $this ) ) ) {
// Do nothing
- } elseif ( $tag == 'mediawiki' && $type == XmlReader::END_ELEMENT ) {
+ } elseif ( $tag == 'mediawiki' && $type == XMLReader::END_ELEMENT ) {
break;
} elseif ( $tag == 'siteinfo' ) {
$this->handleSiteInfo();
'logtitle', 'params' );
while ( $this->reader->read() ) {
- if ( $this->reader->nodeType == XmlReader::END_ELEMENT &&
+ if ( $this->reader->nodeType == XMLReader::END_ELEMENT &&
$this->reader->name == 'logitem' ) {
break;
}
$tag = $this->reader->name;
- if ( !wfRunHooks( 'ImportHandleLogItemXMLTag', array(
+ if ( !Hooks::run( 'ImportHandleLogItemXMLTag', array(
$this, $logInfo
) ) ) {
// Do nothing
* @return bool|mixed
*/
private function processLogItem( $logInfo ) {
- $revision = new WikiRevision;
+ $revision = new WikiRevision( $this->config );
$revision->setID( $logInfo['id'] );
$revision->setType( $logInfo['type'] );
$badTitle = false;
while ( $skip ? $this->reader->next() : $this->reader->read() ) {
- if ( $this->reader->nodeType == XmlReader::END_ELEMENT &&
+ if ( $this->reader->nodeType == XMLReader::END_ELEMENT &&
$this->reader->name == 'page' ) {
break;
}
if ( $badTitle ) {
// The title is invalid, bail out of this page
$skip = true;
- } elseif ( !wfRunHooks( 'ImportHandlePageXMLTag', array( $this,
+ } elseif ( !Hooks::run( 'ImportHandlePageXMLTag', array( $this,
&$pageInfo ) ) ) {
// Do nothing
} elseif ( in_array( $tag, $normalFields ) ) {
$skip = false;
while ( $skip ? $this->reader->next() : $this->reader->read() ) {
- if ( $this->reader->nodeType == XmlReader::END_ELEMENT &&
+ if ( $this->reader->nodeType == XMLReader::END_ELEMENT &&
$this->reader->name == 'revision' ) {
break;
}
$tag = $this->reader->name;
- if ( !wfRunHooks( 'ImportHandleRevisionXMLTag', array(
+ if ( !Hooks::run( 'ImportHandleRevisionXMLTag', array(
$this, $pageInfo, $revisionInfo
) ) ) {
// Do nothing
* @return bool|mixed
*/
private function processRevision( $pageInfo, $revisionInfo ) {
- $revision = new WikiRevision;
+ $revision = new WikiRevision( $this->config );
if ( isset( $revisionInfo['id'] ) ) {
$revision->setID( $revisionInfo['id'] );
$skip = false;
while ( $skip ? $this->reader->next() : $this->reader->read() ) {
- if ( $this->reader->nodeType == XmlReader::END_ELEMENT &&
+ if ( $this->reader->nodeType == XMLReader::END_ELEMENT &&
$this->reader->name == 'upload' ) {
break;
}
$tag = $this->reader->name;
- if ( !wfRunHooks( 'ImportHandleUploadXMLTag', array(
+ if ( !Hooks::run( 'ImportHandleUploadXMLTag', array(
$this, $pageInfo
) ) ) {
// Do nothing
* @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'] );
$info = array();
while ( $this->reader->read() ) {
- if ( $this->reader->nodeType == XmlReader::END_ELEMENT &&
+ if ( $this->reader->nodeType == XMLReader::END_ELEMENT &&
$this->reader->name == 'contributor' ) {
break;
}
* @return array|bool
*/
private function processTitle( $text ) {
- global $wgCommandLineMode;
-
$workTitle = $text;
$origTitle = Title::newFromText( $workTitle );
$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 );
} 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;
/** This is a horrible hack used to keep source compatibility */
class UploadSourceAdapter {
/** @var array */
- private static $sourceRegistrations = array();
+ public static $sourceRegistrations = array();
/** @var string */
private $mSource;
*/
class WikiRevision {
/** @todo Unused? */
- private $importer = null;
+ public $importer = null;
/** @var Title */
public $title = null;
/** @var int */
- private $id = 0;
+ public $id = 0;
/** @var string */
public $timestamp = "20010115000000";
public $user_text = "";
/** @var string */
- protected $model = null;
+ public $model = null;
/** @var string */
- protected $format = null;
+ public $format = null;
/** @var string */
public $text = "";
protected $size;
/** @var Content */
- protected $content = null;
+ public $content = null;
/** @var ContentHandler */
protected $contentHandler = null;
public $comment = "";
/** @var bool */
- protected $minor = false;
+ public $minor = false;
/** @var string */
- protected $type = "";
+ public $type = "";
/** @var string */
- protected $action = "";
+ public $action = "";
/** @var string */
- protected $params = "";
+ public $params = "";
/** @var string */
- protected $fileSrc = '';
+ public $fileSrc = '';
/** @var bool|string */
- protected $sha1base36 = false;
+ public $sha1base36 = false;
/**
* @var bool
* @todo Unused?
*/
- private $isTemp = false;
+ public $isTemp = false;
/** @var string */
- protected $archiveName = '';
+ public $archiveName = '';
protected $filename;
protected $src;
/** @todo Unused? */
- private $fileIsTemp;
+ public $fileIsTemp;
/** @var bool */
private $mNoUpdates = false;
+ /** @var Config $config */
+ private $config;
+
+ public function __construct( Config $config ) {
+ $this->config = $config;
+ }
+
/**
* @param Title $title
* @throws MWException
return true;
}
- /**
- * @return mixed
- */
function importLogItem() {
$dbw = wfGetDB( DB_MASTER );
# @todo FIXME: This will not record autoblocks
* @return bool|string
*/
function downloadSource() {
- global $wgEnableUploads;
- if ( !$wgEnableUploads ) {
+ if ( !$this->config->get( 'EnableUploads' ) ) {
return false;
}