From 9db190c7e736ec8d063187d4241b59feaf7dc2d1 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Wed, 22 Jun 2011 11:28:20 +0200 Subject: update to MediaWiki 1.17.0 --- includes/specials/SpecialImport.php | 89 +++++++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 29 deletions(-) (limited to 'includes/specials/SpecialImport.php') diff --git a/includes/specials/SpecialImport.php b/includes/specials/SpecialImport.php index 248709a8..7d1cf0dd 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; @@ -51,7 +57,6 @@ class SpecialImport extends SpecialPage { $this->outputHeader(); if ( wfReadOnly() ) { - global $wgOut; $wgOut->readOnlyPage(); return; } @@ -97,7 +102,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' ) ) { @@ -111,7 +116,7 @@ class SpecialImport extends SpecialPage { } $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" ); @@ -124,30 +129,35 @@ 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' ); @@ -157,7 +167,7 @@ class SpecialImport extends SpecialPage { } private function showForm() { - global $wgUser, $wgOut, $wgRequest, $wgImportSources, $wgExportMaxLinkDepth; + global $wgUser, $wgOut, $wgImportSources, $wgExportMaxLinkDepth; $action = $this->getTitle()->getLocalUrl( array( 'action' => 'submit' ) ); @@ -167,8 +177,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' ) ) . " @@ -195,7 +205,7 @@ class SpecialImport extends SpecialPage { " " . Xml::closeElement( 'table' ). - Xml::hidden( 'editToken', $wgUser->editToken() ) . + Html::hidden( 'editToken', $wgUser->editToken() ) . Xml::closeElement( 'form' ) . Xml::closeElement( 'fieldset' ) ); @@ -223,9 +233,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' ) ) . " " . @@ -280,7 +290,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' ). @@ -297,9 +307,15 @@ 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; $this->mIsUpload = $upload; $this->mInterwiki = $interwiki; @@ -310,9 +326,19 @@ class ImportReporter { global $wgOut; $wgOut->addHTML( "\n" ); - return new WikiErrorMsg( "importnopages" ); + return Status::newFatal( 'importnopages' ); } $wgOut->addHTML( "\n" ); - return $this->mPageCount; + return Status::newGood( $this->mPageCount ); } } -- cgit v1.2.3-54-g00ecf