Example #1
0
	public function execute() {
		$user = $this->getUser();
		$params = $this->extractRequestParams();

		$isUpload = false;
		if ( isset( $params['interwikisource'] ) ) {
			if ( !$user->isAllowed( 'import' ) ) {
				$this->dieUsageMsg( 'cantimport' );
			}
			if ( !isset( $params['interwikipage'] ) ) {
				$this->dieUsageMsg( array( 'missingparam', 'interwikipage' ) );
			}
			$source = ImportStreamSource::newFromInterwiki(
				$params['interwikisource'],
				$params['interwikipage'],
				$params['fullhistory'],
				$params['templates']
			);
		} else {
			$isUpload = true;
			if ( !$user->isAllowed( 'importupload' ) ) {
				$this->dieUsageMsg( 'cantimport-upload' );
			}
			$source = ImportStreamSource::newFromUpload( 'xml' );
		}
		if ( !$source->isOK() ) {
			$this->dieStatus( $source );
		}

		$importer = new WikiImporter( $source->value );
		if ( isset( $params['namespace'] ) ) {
			$importer->setTargetNamespace( $params['namespace'] );
		}
		if ( isset( $params['rootpage'] ) ) {
			$statusRootPage = $importer->setTargetRootPage( $params['rootpage'] );
			if ( !$statusRootPage->isGood() ) {
				$this->dieStatus( $statusRootPage );
			}
		}
		$reporter = new ApiImportReporter(
			$importer,
			$isUpload,
			$params['interwikisource'],
			$params['summary']
		);

		try {
			$importer->doImport();
		} catch ( MWException $e ) {
			$this->dieUsageMsg( array( 'import-unknownerror', $e->getMessage() ) );
		}

		$resultData = $reporter->getData();
		$result = $this->getResult();
		$result->setIndexedTagName( $resultData, 'page' );
		$result->addValue( null, $this->getModuleName(), $resultData );
	}
Example #2
0
 public function execute()
 {
     global $wgUser;
     if (!$wgUser->isAllowed('import')) {
         $this->dieUsageMsg(array('cantimport'));
     }
     $params = $this->extractRequestParams();
     $source = null;
     $isUpload = false;
     if (isset($params['interwikisource'])) {
         if (!isset($params['interwikipage'])) {
             $this->dieUsageMsg(array('missingparam', 'interwikipage'));
         }
         $source = ImportStreamSource::newFromInterwiki($params['interwikisource'], $params['interwikipage'], $params['fullhistory'], $params['templates']);
     } else {
         $isUpload = true;
         if (!$wgUser->isAllowed('importupload')) {
             $this->dieUsageMsg(array('cantimport-upload'));
         }
         $source = ImportStreamSource::newFromUpload('xml');
     }
     if ($source instanceof WikiErrorMsg) {
         $this->dieUsageMsg(array_merge(array($source->getMessageKey()), $source->getMessageArgs()));
     } else {
         if (WikiError::isError($source)) {
             // This shouldn't happen
             $this->dieUsageMsg(array('import-unknownerror', $source->getMessage()));
         }
     }
     $importer = new WikiImporter($source);
     if (isset($params['namespace'])) {
         $importer->setTargetNamespace($params['namespace']);
     }
     $reporter = new ApiImportReporter($importer, $isUpload, $params['interwikisource'], $params['summary']);
     $result = $importer->doImport();
     if ($result instanceof WikiXmlError) {
         $this->dieUsageMsg(array('import-xml-error', $result->mLine, $result->mColumn, $result->mByte . $result->mContext, xml_error_string($result->mXmlError)));
     } else {
         if (WikiError::isError($result)) {
             $this->dieUsageMsg(array('import-unknownerror', $result->getMessage()));
         }
     }
     // This shouldn't happen
     $resultData = $reporter->getData();
     $this->getResult()->setIndexedTagName($resultData, 'page');
     $this->getResult()->addValue(null, $this->getModuleName(), $resultData);
 }