diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-12-17 09:15:42 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-12-17 09:44:51 +0100 |
commit | a1789ddde42033f1b05cc4929491214ee6e79383 (patch) | |
tree | 63615735c4ddffaaabf2428946bb26f90899f7bf /includes/specials/SpecialImport.php | |
parent | 9e06a62f265e3a2aaabecc598d4bc617e06fa32d (diff) |
Update to MediaWiki 1.26.0
Diffstat (limited to 'includes/specials/SpecialImport.php')
-rw-r--r-- | includes/specials/SpecialImport.php | 144 |
1 files changed, 95 insertions, 49 deletions
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 "<tr> + <td> + </td> + <td class='mw-input'>" . + 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 ) ) + ) . + "</td> + </tr> + <tr> + <td> + </td> + <td class='mw-input'>" . + 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', + ) + ) . + "</td> + </tr> + <tr> + <td> + </td> + <td class='mw-input'>" . + 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' + ) + ) . ' ' . + "</td> + </tr>"; + } + 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 { "</td> <td class='mw-input'>" . Xml::input( 'log-comment', 50, - ( $this->sourceName == 'upload' ? $this->logcomment : '' ), + ( $this->sourceName === 'upload' ? $this->logcomment : '' ), array( 'id' => 'mw-import-comment', 'type' => 'text' ) ) . ' ' . "</td> </tr> - <tr> - <td class='mw-label'>" . - Xml::label( - $this->msg( 'import-interwiki-rootpage' )->text(), - 'mw-interwiki-rootpage-upload' - ) . - "</td> - <td class='mw-input'>" . - Xml::input( 'rootpage', 50, $this->rootpage, - array( 'id' => 'mw-interwiki-rootpage-upload', 'type' => 'text' ) ) . ' ' . - "</td> - </tr> + $mappingSelection <tr> <td></td> <td class='mw-submit'>" . @@ -301,6 +374,7 @@ class SpecialImport extends SpecialPage { "</td> </tr>"; } + $mappingSelection = $this->getMappingFormPart( 'interwiki' ); $out->addHTML( Xml::fieldset( $this->msg( 'importinterwiki' )->text() ) . @@ -415,43 +489,15 @@ class SpecialImport extends SpecialPage { $importDepth <tr> <td class='mw-label'>" . - Xml::label( $this->msg( 'import-interwiki-namespace' )->text(), 'namespace' ) . - "</td> - <td class='mw-input'>" . - Html::namespaceSelector( - array( - 'selected' => $this->namespace, - 'all' => '', - ), array( - 'name' => 'namespace', - 'id' => 'namespace', - 'class' => 'namespaceselector', - ) - ) . - "</td> - </tr> - <tr> - <td class='mw-label'>" . Xml::label( $this->msg( 'import-comment' )->text(), 'mw-interwiki-comment' ) . "</td> <td class='mw-input'>" . Xml::input( 'log-comment', 50, - ( $this->sourceName == 'interwiki' ? $this->logcomment : '' ), + ( $this->sourceName === 'interwiki' ? $this->logcomment : '' ), array( 'id' => 'mw-interwiki-comment', 'type' => 'text' ) ) . ' ' . "</td> </tr> - <tr> - <td class='mw-label'>" . - Xml::label( - $this->msg( 'import-interwiki-rootpage' )->text(), - 'mw-interwiki-rootpage-interwiki' - ) . - "</td> - <td class='mw-input'>" . - Xml::input( 'rootpage', 50, $this->rootpage, - array( 'id' => 'mw-interwiki-rootpage-interwiki', 'type' => 'text' ) ) . ' ' . - "</td> - </tr> + $mappingSelection <tr> <td> </td> |