private $reader = null;
private $foreignNamespaces = null;
private $mLogItemCallback, $mUploadCallback, $mRevisionCallback, $mPageCallback;
- private $mSiteInfoCallback, $mTargetNamespace, $mPageOutCallback;
+ private $mSiteInfoCallback, $mPageOutCallback;
private $mNoticeCallback, $mDebug;
private $mImportUploads, $mImageBasePath;
private $mNoUpdates = false;
* Creates an ImportXMLReader drawing from the source provided
* @param ImportSource $source
* @param Config $config
+ * @throws Exception
*/
function __construct( ImportSource $source, Config $config = null ) {
+ if ( !class_exists( 'XMLReader' ) ) {
+ throw new Exception( 'Import requires PHP to have been compiled with libxml support' );
+ }
+
$this->reader = new XMLReader();
if ( !$config ) {
wfDeprecated( __METHOD__ . ' without a Config instance', '1.25' );
stream_wrapper_register( 'uploadsource', 'UploadSourceAdapter' );
}
$id = UploadSourceAdapter::registerSource( $source );
+
+ // Enable the entity loader, as it is needed for loading external URLs via
+ // XMLReader::open (T86036)
+ $oldDisable = libxml_disable_entity_loader( false );
if ( defined( 'LIBXML_PARSEHUGE' ) ) {
- $this->reader->open( "uploadsource://$id", null, LIBXML_PARSEHUGE );
+ $status = $this->reader->open( "uploadsource://$id", null, LIBXML_PARSEHUGE );
} else {
- $this->reader->open( "uploadsource://$id" );
+ $status = $this->reader->open( "uploadsource://$id" );
}
+ if ( !$status ) {
+ $error = libxml_get_last_error();
+ libxml_disable_entity_loader( $oldDisable );
+ throw new MWException( 'Encountered an internal error while initializing WikiImporter object: ' .
+ $error->message );
+ }
+ libxml_disable_entity_loader( $oldDisable );
// Default callbacks
$this->setPageCallback( array( $this, 'beforeImportPage' ) );
public function setTargetNamespace( $namespace ) {
if ( is_null( $namespace ) ) {
// Don't override namespaces
- $this->mTargetNamespace = null;
$this->setImportTitleFactory( new NaiveImportTitleFactory() );
return true;
} elseif (
MWNamespace::exists( intval( $namespace ) )
) {
$namespace = intval( $namespace );
- $this->mTargetNamespace = $namespace;
$this->setImportTitleFactory( new NamespaceImportTitleFactory( $namespace ) );
return true;
} else {
$this->setImportTitleFactory( new NaiveImportTitleFactory() );
} elseif ( $rootpage !== '' ) {
$rootpage = rtrim( $rootpage, '/' ); //avoid double slashes
- $title = Title::newFromText( $rootpage, !is_null( $this->mTargetNamespace )
- ? $this->mTargetNamespace
- : NS_MAIN
- );
+ $title = Title::newFromText( $rootpage );
if ( !$title || $title->isExternal() ) {
$status->fatal( 'import-rootpage-invalid' );
$countKey = 'title_' . $title->getPrefixedText();
$countable = $page->isCountable( $editInfo );
if ( array_key_exists( $countKey, $this->countableCache ) &&
- $countable != $this->countableCache[ $countKey ] ) {
+ $countable != $this->countableCache[$countKey] ) {
DeferredUpdates::addUpdate( SiteStatsUpdate::factory( array(
- 'articles' => ( (int)$countable - (int)$this->countableCache[ $countKey ] )
+ 'articles' => ( (int)$countable - (int)$this->countableCache[$countKey] )
) ) );
}
}
$tag = $this->reader->localName;
if ( $tag == 'namespace' ) {
- $this->foreignNamespaces[ $this->nodeAttribute( 'key' ) ] =
+ $this->foreignNamespaces[$this->nodeAttribute( 'key' )] =
$this->nodeContents();
} elseif ( in_array( $tag, $normalFields ) ) {
$siteInfo[$tag] = $this->nodeContents();
}
// avoid memory leak...?
- $linkCache = LinkCache::singleton();
- $linkCache->clear();
+ Title::clearCaches();
$page = WikiPage::factory( $this->title );
$page->loadPageData( 'fromdbmaster' );
* @return Status
*/
static function newFromFile( $filename ) {
- wfSuppressWarnings();
+ MediaWiki\suppressWarnings();
$file = fopen( $filename, 'rt' );
- wfRestoreWarnings();
+ MediaWiki\restoreWarnings();
if ( !$file ) {
return Status::newFatal( "importcantopen" );
}