From a1789ddde42033f1b05cc4929491214ee6e79383 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 17 Dec 2015 09:15:42 +0100 Subject: Update to MediaWiki 1.26.0 --- includes/specials/SpecialImport.php | 144 ++++++++++++++++++++++++------------ 1 file changed, 95 insertions(+), 49 deletions(-) (limited to 'includes/specials/SpecialImport.php') diff --git a/includes/specials/SpecialImport.php b/includes/specials/SpecialImport.php index af869647..4cdf6ddf 100644 --- a/includes/specials/SpecialImport.php +++ b/includes/specials/SpecialImport.php @@ -34,6 +34,7 @@ class SpecialImport extends SpecialPage { private $interwiki = false; private $subproject; private $fullInterwikiPrefix; + private $mapping = 'default'; private $namespace; private $rootpage = ''; private $frompage = ''; @@ -56,6 +57,8 @@ class SpecialImport extends SpecialPage { * @throws ReadOnlyError */ function execute( $par ) { + $this->useTransactionalTimeLimit(); + $this->setHeaders(); $this->outputHeader(); @@ -101,26 +104,33 @@ class SpecialImport extends SpecialPage { private function doImport() { $isUpload = false; $request = $this->getRequest(); - $this->namespace = $request->getIntOrNull( 'namespace' ); $this->sourceName = $request->getVal( "source" ); $this->logcomment = $request->getText( 'log-comment' ); $this->pageLinkDepth = $this->getConfig()->get( 'ExportMaxLinkDepth' ) == 0 ? 0 : $request->getIntOrNull( 'pagelink-depth' ); - $this->rootpage = $request->getText( 'rootpage' ); + + $this->mapping = $request->getVal( 'mapping' ); + if ( $this->mapping === 'namespace' ) { + $this->namespace = $request->getIntOrNull( 'namespace' ); + } elseif ( $this->mapping === 'subpage' ) { + $this->rootpage = $request->getText( 'rootpage' ); + } else { + $this->mapping = 'default'; + } $user = $this->getUser(); if ( !$user->matchEditToken( $request->getVal( 'editToken' ) ) ) { $source = Status::newFatal( 'import-token-mismatch' ); - } elseif ( $this->sourceName == 'upload' ) { + } elseif ( $this->sourceName === 'upload' ) { $isUpload = true; if ( $user->isAllowed( 'importupload' ) ) { $source = ImportStreamSource::newFromUpload( "xmlimport" ); } else { throw new PermissionsError( 'importupload' ); } - } elseif ( $this->sourceName == "interwiki" ) { + } elseif ( $this->sourceName === 'interwiki' ) { if ( !$user->isAllowed( 'import' ) ) { throw new PermissionsError( 'import' ); } @@ -163,8 +173,7 @@ class SpecialImport extends SpecialPage { $importer = new WikiImporter( $source->value, $this->getConfig() ); if ( !is_null( $this->namespace ) ) { $importer->setTargetNamespace( $this->namespace ); - } - if ( !is_null( $this->rootpage ) ) { + } elseif ( !is_null( $this->rootpage ) ) { $statusRootPage = $importer->setTargetRootPage( $this->rootpage ); if ( !$statusRootPage->isGood() ) { $out->wrapWikiMsg( @@ -219,13 +228,88 @@ class SpecialImport extends SpecialPage { } } + private function getMappingFormPart( $sourceName ) { + $isSameSourceAsBefore = ( $this->sourceName === $sourceName ); + $defaultNamespace = $this->getConfig()->get( 'ImportTargetNamespace' ); + return " + + + " . + Xml::radioLabel( + $this->msg( 'import-mapping-default' )->text(), + 'mapping', + 'default', + // mw-import-mapping-interwiki-default, mw-import-mapping-upload-default + "mw-import-mapping-$sourceName-default", + ( $isSameSourceAsBefore ? + ( $this->mapping === 'default' ) : + is_null( $defaultNamespace ) ) + ) . + " + + + + + " . + Xml::radioLabel( + $this->msg( 'import-mapping-namespace' )->text(), + 'mapping', + 'namespace', + // mw-import-mapping-interwiki-namespace, mw-import-mapping-upload-namespace + "mw-import-mapping-$sourceName-namespace", + ( $isSameSourceAsBefore ? + ( $this->mapping === 'namespace' ) : + !is_null( $defaultNamespace ) ) + ) . ' ' . + Html::namespaceSelector( + array( + 'selected' => ( $isSameSourceAsBefore ? + $this->namespace : + ( $defaultNamespace || '' ) ), + ), array( + 'name' => "namespace", + // mw-import-namespace-interwiki, mw-import-namespace-upload + 'id' => "mw-import-namespace-$sourceName", + 'class' => 'namespaceselector', + ) + ) . + " + + + + + " . + Xml::radioLabel( + $this->msg( 'import-mapping-subpage' )->text(), + 'mapping', + 'subpage', + // mw-import-mapping-interwiki-subpage, mw-import-mapping-upload-subpage + "mw-import-mapping-$sourceName-subpage", + ( $isSameSourceAsBefore ? ( $this->mapping === 'subpage' ) : '' ) + ) . ' ' . + Xml::input( 'rootpage', 50, + ( $isSameSourceAsBefore ? $this->rootpage : '' ), + array( + // Should be "mw-import-rootpage-...", but we keep this inaccurate + // ID for legacy reasons + // mw-interwiki-rootpage-interwiki, mw-interwiki-rootpage-upload + 'id' => "mw-interwiki-rootpage-$sourceName", + 'type' => 'text' + ) + ) . ' ' . + " + "; + } + private function showForm() { $action = $this->getPageTitle()->getLocalURL( array( 'action' => 'submit' ) ); $user = $this->getUser(); $out = $this->getOutput(); + $this->addHelpLink( '//meta.wikimedia.org/wiki/Special:MyLanguage/Help:Import', true ); $importSources = $this->getConfig()->get( 'ImportSources' ); if ( $user->isAllowed( 'importupload' ) ) { + $mappingSelection = $this->getMappingFormPart( 'upload' ); $out->addHTML( Xml::fieldset( $this->msg( 'import-upload' )->text() ) . Xml::openElement( @@ -255,22 +339,11 @@ class SpecialImport extends SpecialPage { " " . Xml::input( 'log-comment', 50, - ( $this->sourceName == 'upload' ? $this->logcomment : '' ), + ( $this->sourceName === 'upload' ? $this->logcomment : '' ), array( 'id' => 'mw-import-comment', 'type' => 'text' ) ) . ' ' . " - - " . - Xml::label( - $this->msg( 'import-interwiki-rootpage' )->text(), - 'mw-interwiki-rootpage-upload' - ) . - " - " . - Xml::input( 'rootpage', 50, $this->rootpage, - array( 'id' => 'mw-interwiki-rootpage-upload', 'type' => 'text' ) ) . ' ' . - " - + $mappingSelection " . @@ -301,6 +374,7 @@ class SpecialImport extends SpecialPage { " "; } + $mappingSelection = $this->getMappingFormPart( 'interwiki' ); $out->addHTML( Xml::fieldset( $this->msg( 'importinterwiki' )->text() ) . @@ -413,45 +487,17 @@ class SpecialImport extends SpecialPage { " $importDepth - - " . - Xml::label( $this->msg( 'import-interwiki-namespace' )->text(), 'namespace' ) . - " - " . - Html::namespaceSelector( - array( - 'selected' => $this->namespace, - 'all' => '', - ), array( - 'name' => 'namespace', - 'id' => 'namespace', - 'class' => 'namespaceselector', - ) - ) . - " - " . Xml::label( $this->msg( 'import-comment' )->text(), 'mw-interwiki-comment' ) . " " . Xml::input( 'log-comment', 50, - ( $this->sourceName == 'interwiki' ? $this->logcomment : '' ), + ( $this->sourceName === 'interwiki' ? $this->logcomment : '' ), array( 'id' => 'mw-interwiki-comment', 'type' => 'text' ) ) . ' ' . " - - " . - Xml::label( - $this->msg( 'import-interwiki-rootpage' )->text(), - 'mw-interwiki-rootpage-interwiki' - ) . - " - " . - Xml::input( 'rootpage', 50, $this->rootpage, - array( 'id' => 'mw-interwiki-rootpage-interwiki', 'type' => 'text' ) ) . ' ' . - " - + $mappingSelection -- cgit v1.2.3-54-g00ecf