From 222b01f5169f1c7e69762e0e8904c24f78f71882 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Wed, 28 Jul 2010 11:52:48 +0200 Subject: update to MediaWiki 1.16.0 --- includes/api/ApiImport.php | 98 ++++++++++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 43 deletions(-) (limited to 'includes/api/ApiImport.php') diff --git a/includes/api/ApiImport.php b/includes/api/ApiImport.php index 4b1518bb..032b684c 100644 --- a/includes/api/ApiImport.php +++ b/includes/api/ApiImport.php @@ -23,9 +23,9 @@ * http://www.gnu.org/copyleft/gpl.html */ -if (!defined('MEDIAWIKI')) { +if ( !defined( 'MEDIAWIKI' ) ) { // Eclipse helper - will be ignored in production - require_once ('ApiBase.php'); + require_once ( 'ApiBase.php' ); } /** @@ -35,70 +35,68 @@ if (!defined('MEDIAWIKI')) { */ class ApiImport extends ApiBase { - public function __construct($main, $action) { - parent :: __construct($main, $action); + public function __construct( $main, $action ) { + parent :: __construct( $main, $action ); } public function execute() { global $wgUser; - if(!$wgUser->isAllowed('import')) - $this->dieUsageMsg(array('cantimport')); + if ( !$wgUser->isAllowed( 'import' ) ) + $this->dieUsageMsg( array( 'cantimport' ) ); $params = $this->extractRequestParams(); - if(!isset($params['token'])) - $this->dieUsageMsg(array('missingparam', 'token')); - if(!$wgUser->matchEditToken($params['token'])) - $this->dieUsageMsg(array('sessionfailure')); $source = null; $isUpload = false; - if(isset($params['interwikisource'])) + if ( isset( $params['interwikisource'] ) ) { - if(!isset($params['interwikipage'])) - $this->dieUsageMsg(array('missingparam', 'interwikipage')); + if ( !isset( $params['interwikipage'] ) ) + $this->dieUsageMsg( array( 'missingparam', 'interwikipage' ) ); $source = ImportStreamSource::newFromInterwiki( $params['interwikisource'], $params['interwikipage'], $params['fullhistory'], - $params['templates']); + $params['templates'] ); } else { $isUpload = true; - if(!$wgUser->isAllowed('importupload')) - $this->dieUsageMsg(array('cantimport-upload')); - $source = ImportStreamSource::newFromUpload('xml'); + 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)) + 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())); + $this->dieUsageMsg( array( 'import-unknownerror', $source->getMessage() ) ); - $importer = new WikiImporter($source); - if(isset($params['namespace'])) - $importer->setTargetNamespace($params['namespace']); - $reporter = new ApiImportReporter($importer, $isUpload, + $importer = new WikiImporter( $source ); + if ( isset( $params['namespace'] ) ) + $importer->setTargetNamespace( $params['namespace'] ); + $reporter = new ApiImportReporter( $importer, $isUpload, $params['interwikisource'], - $params['summary']); + $params['summary'] ); $result = $importer->doImport(); - if($result instanceof WikiXmlError) - $this->dieUsageMsg(array('import-xml-error', + 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 shouldn't happen - $this->dieUsageMsg(array('import-unknownerror', $result->getMessage())); + 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); + $this->getResult()->setIndexedTagName( $resultData, 'page' ); + $this->getResult()->addValue( null, $this->getModuleName(), $resultData ); } - public function mustBePosted() { return true; } + public function mustBePosted() { + return true; + } public function isWriteMode() { return true; @@ -140,6 +138,20 @@ class ApiImport extends ApiBase { 'Import a page from another wiki, or an XML file' ); } + + public function getPossibleErrors() { + return array_merge( parent::getPossibleErrors(), array( + array( 'cantimport' ), + array( 'missingparam', 'interwikipage' ), + array( 'cantimport-upload' ), + array( 'import-unknownerror', 'source' ), + array( 'import-unknownerror', 'result' ), + ) ); + } + + public function getTokenSalt() { + return ''; + } protected function getExamples() { return array( @@ -149,7 +161,7 @@ class ApiImport extends ApiBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiImport.php 48091 2009-03-06 13:49:44Z catrope $'; + return __CLASS__ . ': $Id: ApiImport.php 62599 2010-02-16 21:59:16Z reedy $'; } } @@ -160,20 +172,20 @@ class ApiImport extends ApiBase { class ApiImportReporter extends ImportReporter { private $mResultArr = array(); - function reportPage($title, $origTitle, $revisionCount, $successCount) + function reportPage( $title, $origTitle, $revisionCount, $successCount ) { // Add a result entry $r = array(); - ApiQueryBase::addTitleInfo($r, $title); - $r['revisions'] = intval($successCount); + ApiQueryBase::addTitleInfo( $r, $title ); + $r['revisions'] = intval( $successCount ); $this->mResultArr[] = $r; // Piggyback on the parent to do the logging - parent::reportPage($title, $origTitle, $revisionCount, $successCount); + parent::reportPage( $title, $origTitle, $revisionCount, $successCount ); } function getData() { return $this->mResultArr; } -} +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf