X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialImport.php;h=73416a8e0a52fe718a7ded533901ee99356e9b59;hb=1731f820159cf99865e791e2d40fbad687b1e491;hp=9d451f67885ba0b0c21fa902823034879e14f36c;hpb=84e13464afd5f6d8dd1f625f7aab76152df94e05;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialImport.php b/includes/specials/SpecialImport.php index 9d451f6788..73416a8e0a 100644 --- a/includes/specials/SpecialImport.php +++ b/includes/specials/SpecialImport.php @@ -1,7 +1,8 @@ + * Implements Special:Import + * + * Copyright © 2003,2005 Brion Vibber * http://www.mediawiki.org/ * * This program is free software; you can redistribute it and/or modify @@ -23,6 +24,11 @@ * @ingroup SpecialPage */ +/** + * MediaWiki page data importer + * + * @ingroup SpecialPage + */ class SpecialImport extends SpecialPage { private $interwiki = false; @@ -75,7 +81,7 @@ class SpecialImport extends SpecialPage { $this->pageLinkDepth = $wgExportMaxLinkDepth == 0 ? 0 : $wgRequest->getIntOrNull( 'pagelink-depth' ); if ( !$wgUser->matchEditToken( $wgRequest->getVal( 'editToken' ) ) ) { - $source = new WikiErrorMsg( 'import-token-mismatch' ); + $source = Status::newFatal( 'import-token-mismatch' ); } elseif ( $sourceName == 'upload' ) { $isUpload = true; if( $wgUser->isAllowed( 'importupload' ) ) { @@ -86,7 +92,7 @@ class SpecialImport extends SpecialPage { } elseif ( $sourceName == "interwiki" ) { $this->interwiki = $wgRequest->getVal( 'interwiki' ); if ( !in_array( $this->interwiki, $wgImportSources ) ) { - $source = new WikiErrorMsg( "import-invalid-interwiki" ); + $source = Status::newFatal( "import-invalid-interwiki" ); } else { $this->history = $wgRequest->getCheck( 'interwikiHistory' ); $this->frompage = $wgRequest->getText( "frompage" ); @@ -99,40 +105,45 @@ class SpecialImport extends SpecialPage { $this->pageLinkDepth ); } } else { - $source = new WikiErrorMsg( "importunknownsource" ); + $source = Status::newFatal( "importunknownsource" ); } - if( WikiError::isError( $source ) ) { - $wgOut->wrapWikiMsg( '

$1

', array( 'importfailed', $source->getMessage() ) ); + if( !$source->isGood() ) { + $wgOut->wrapWikiMsg( "

\n$1\n

", array( 'importfailed', $source->getWikiText() ) ); } else { $wgOut->addWikiMsg( "importstart" ); - $importer = new WikiImporter( $source ); + $importer = new WikiImporter( $source->value ); if( !is_null( $this->namespace ) ) { $importer->setTargetNamespace( $this->namespace ); } $reporter = new ImportReporter( $importer, $isUpload, $this->interwiki , $this->logcomment); + $exception = false; $reporter->open(); - $result = $importer->doImport(); - $resultCount = $reporter->close(); + try { + $importer->doImport(); + } catch ( MWException $e ) { + $exception = $e; + } + $result = $reporter->close(); - if( WikiError::isError( $result ) ) { + if ( $exception ) { # No source or XML parse error - $wgOut->wrapWikiMsg( '

$1

', array( 'importfailed', $result->getMessage() ) ); - } elseif( WikiError::isError( $resultCount ) ) { + $wgOut->wrapWikiMsg( "

\n$1\n

", array( 'importfailed', $exception->getMessage() ) ); + } elseif( !$result->isGood() ) { # Zero revisions - $wgOut->wrapWikiMsg( '

$1

', array( 'importfailed', $resultCount->getMessage() ) ); + $wgOut->wrapWikiMsg( "

\n$1\n

", array( 'importfailed', $result->getWikiText() ) ); } else { # Success! $wgOut->addWikiMsg( 'importsuccess' ); } - $wgOut->addWikiText( '
' ); + $wgOut->addHTML( '
' ); } } private function showForm() { - global $wgUser, $wgOut, $wgRequest, $wgImportSources, $wgExportMaxLinkDepth; + global $wgUser, $wgOut, $wgImportSources, $wgExportMaxLinkDepth; if( !$wgUser->isAllowed( 'import' ) && !$wgUser->isAllowed( 'importupload' ) ) return $wgOut->permissionRequired( 'import' ); @@ -144,8 +155,8 @@ class SpecialImport extends SpecialPage { Xml::fieldset( wfMsg( 'import-upload' ) ). Xml::openElement( 'form', array( 'enctype' => 'multipart/form-data', 'method' => 'post', 'action' => $action, 'id' => 'mw-import-upload-form' ) ) . - Xml::hidden( 'action', 'submit' ) . - Xml::hidden( 'source', 'upload' ) . + Html::hidden( 'action', 'submit' ) . + Html::hidden( 'source', 'upload' ) . Xml::openElement( 'table', array( 'id' => 'mw-import-table' ) ) . " @@ -172,7 +183,7 @@ class SpecialImport extends SpecialPage { " " . Xml::closeElement( 'table' ). - Xml::hidden( 'editToken', $wgUser->editToken() ) . + Html::hidden( 'editToken', $wgUser->editToken() ) . Xml::closeElement( 'form' ) . Xml::closeElement( 'fieldset' ) ); @@ -200,9 +211,9 @@ class SpecialImport extends SpecialPage { Xml::fieldset( wfMsg( 'importinterwiki' ) ) . Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'mw-import-interwiki-form' ) ) . wfMsgExt( 'import-interwiki-text', array( 'parse' ) ) . - Xml::hidden( 'action', 'submit' ) . - Xml::hidden( 'source', 'interwiki' ) . - Xml::hidden( 'editToken', $wgUser->editToken() ) . + Html::hidden( 'action', 'submit' ) . + Html::hidden( 'source', 'interwiki' ) . + Html::hidden( 'editToken', $wgUser->editToken() ) . Xml::openElement( 'table', array( 'id' => 'mw-import-table' ) ) . " " . @@ -257,7 +268,7 @@ class SpecialImport extends SpecialPage { " . - Xml::submitButton( wfMsg( 'import-interwiki-submit' ), array( 'accesskey' => 's' ) ) . + Xml::submitButton( wfMsg( 'import-interwiki-submit' ), $wgUser->getSkin()->tooltipAndAccessKeyAttribs( 'import' ) ) . " " . Xml::closeElement( 'table' ). @@ -275,10 +286,12 @@ class SpecialImport extends SpecialPage { class ImportReporter { private $reason=false; private $mOriginalLogCallback = null; + private $mOriginalPageOutCallback = null; private $mLogItemCount = 0; function __construct( $importer, $upload, $interwiki , $reason=false ) { - $importer->setPageOutCallback( array( $this, 'reportPage' ) ); + $this->mOriginalPageOutCallback = + $importer->setPageOutCallback( array( $this, 'reportPage' ) ); $this->mOriginalLogCallback = $importer->setLogItemCallback( array( $this, 'reportLogItem' ) ); $this->mPageCount = 0; @@ -299,8 +312,11 @@ class ImportReporter { } } - function reportPage( $title, $origTitle, $revisionCount, $successCount ) { + function reportPage( $title, $origTitle, $revisionCount, $successCount, $pageInfo ) { global $wgOut, $wgUser, $wgLang, $wgContLang; + + $args = func_get_args(); + call_user_func_array( $this->mOriginalPageOutCallback, $args ); $skin = $wgUser->getSkin(); @@ -358,10 +374,10 @@ class ImportReporter { $wgOut->addHTML( Xml::tags( 'li', null, $msg ) ); } elseif( $this->mPageCount == 0 && $this->mLogItemCount == 0 ) { $wgOut->addHTML( "\n" ); - return new WikiErrorMsg( "importnopages" ); + return Status::newFatal( 'importnopages' ); } $wgOut->addHTML( "\n" ); - return $this->mPageCount; + return Status::newGood( $this->mPageCount ); } }