diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2011-06-22 11:28:20 +0200 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2011-06-22 11:28:20 +0200 |
commit | 9db190c7e736ec8d063187d4241b59feaf7dc2d1 (patch) | |
tree | 46d1a0dee7febef5c2d57a9f7b972be16a163b3d /includes/specials/SpecialImport.php | |
parent | 78677c7bbdcc9739f6c10c75935898a20e1acd9e (diff) |
update to MediaWiki 1.17.0
Diffstat (limited to 'includes/specials/SpecialImport.php')
-rw-r--r-- | includes/specials/SpecialImport.php | 89 |
1 files changed, 60 insertions, 29 deletions
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 @@ <?php /** - * MediaWiki page data importer - * Copyright (C) 2003,2005 Brion Vibber <brion@pobox.com> + * Implements Special:Import + * + * Copyright © 2003,2005 Brion Vibber <brion@pobox.com> * 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( '<p class="error">$1</p>', array( 'importfailed', $source->getMessage() ) ); + if( !$source->isGood() ) { + $wgOut->wrapWikiMsg( "<p class=\"error\">\n$1\n</p>", 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( '<p class="error">$1</p>', array( 'importfailed', $result->getMessage() ) ); - } elseif( WikiError::isError( $resultCount ) ) { + $wgOut->wrapWikiMsg( "<p class=\"error\">\n$1\n</p>", array( 'importfailed', $exception->getMessage() ) ); + } elseif( !$result->isGood() ) { # Zero revisions - $wgOut->wrapWikiMsg( '<p class="error">$1</p>', array( 'importfailed', $resultCount->getMessage() ) ); + $wgOut->wrapWikiMsg( "<p class=\"error\">\n$1\n</p>", 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' ) ) . "<tr> @@ -195,7 +205,7 @@ class SpecialImport extends SpecialPage { "</td> </tr>" . 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' ) ) . "<tr> <td class='mw-label'>" . @@ -280,7 +290,7 @@ class SpecialImport extends SpecialPage { <td> </td> <td class='mw-submit'>" . - Xml::submitButton( wfMsg( 'import-interwiki-submit' ), array( 'accesskey' => 's' ) ) . + Xml::submitButton( wfMsg( 'import-interwiki-submit' ), $wgUser->getSkin()->tooltipAndAccessKeyAttribs( 'import' ) ) . "</td> </tr>" . 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( "<ul>\n" ); } + + function reportLogItem( /* ... */ ) { + $this->mLogItemCount++; + if ( is_callable( $this->mOriginalLogCallback ) ) { + call_user_func_array( $this->mOriginalLogCallback, func_get_args() ); + } + } - 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(); @@ -362,13 +388,18 @@ class ImportReporter { } function close() { - global $wgOut; - if( $this->mPageCount == 0 ) { + global $wgOut, $wgLang; + + if ( $this->mLogItemCount > 0 ) { + $msg = wfMsgExt( 'imported-log-entries', 'parseinline', + $wgLang->formatNum( $this->mLogItemCount ) ); + $wgOut->addHTML( Xml::tags( 'li', null, $msg ) ); + } elseif( $this->mPageCount == 0 && $this->mLogItemCount == 0 ) { $wgOut->addHTML( "</ul>\n" ); - return new WikiErrorMsg( "importnopages" ); + return Status::newFatal( 'importnopages' ); } $wgOut->addHTML( "</ul>\n" ); - return $this->mPageCount; + return Status::newGood( $this->mPageCount ); } } |