summaryrefslogtreecommitdiff
path: root/includes/specials/SpecialImport.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/specials/SpecialImport.php')
-rw-r--r--includes/specials/SpecialImport.php164
1 files changed, 122 insertions, 42 deletions
diff --git a/includes/specials/SpecialImport.php b/includes/specials/SpecialImport.php
index d7d860de..eab4784c 100644
--- a/includes/specials/SpecialImport.php
+++ b/includes/specials/SpecialImport.php
@@ -3,7 +3,7 @@
* Implements Special:Import
*
* Copyright © 2003,2005 Brion Vibber <brion@pobox.com>
- * http://www.mediawiki.org/
+ * https://www.mediawiki.org/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -31,6 +31,8 @@
*/
class SpecialImport extends SpecialPage {
private $interwiki = false;
+ private $subproject;
+ private $fullInterwikiPrefix;
private $namespace;
private $rootpage = '';
private $frompage = '';
@@ -44,17 +46,19 @@ class SpecialImport extends SpecialPage {
*/
public function __construct() {
parent::__construct( 'Import', 'import' );
- global $wgImportTargetNamespace;
- $this->namespace = $wgImportTargetNamespace;
+ $this->namespace = $this->getConfig()->get( 'ImportTargetNamespace' );
}
/**
* Execute
+ * @param string|null $par
*/
function execute( $par ) {
$this->setHeaders();
$this->outputHeader();
+ $this->getOutput()->addModules( 'mediawiki.special.import' );
+
$user = $this->getUser();
if ( !$user->isAllowedAny( 'import', 'importupload' ) ) {
throw new PermissionsError( 'import' );
@@ -64,11 +68,11 @@ class SpecialImport extends SpecialPage {
# @todo FIXME: Title::checkSpecialsAndNSPermissions() has a very wierd expectation of what
# getUserPermissionsErrors() might actually be used for, hence the 'ns-specialprotected'
$errors = wfMergeErrorArrays(
- $this->getTitle()->getUserPermissionsErrors(
+ $this->getPageTitle()->getUserPermissionsErrors(
'import', $user, true,
array( 'ns-specialprotected', 'badaccess-group0', 'badaccess-groups' )
),
- $this->getTitle()->getUserPermissionsErrors(
+ $this->getPageTitle()->getUserPermissionsErrors(
'importupload', $user, true,
array( 'ns-specialprotected', 'badaccess-group0', 'badaccess-groups' )
)
@@ -91,15 +95,15 @@ class SpecialImport extends SpecialPage {
* Do the actual import
*/
private function doImport() {
- global $wgImportSources, $wgExportMaxLinkDepth;
-
$isUpload = false;
$request = $this->getRequest();
$this->namespace = $request->getIntOrNull( 'namespace' );
$sourceName = $request->getVal( "source" );
$this->logcomment = $request->getText( 'log-comment' );
- $this->pageLinkDepth = $wgExportMaxLinkDepth == 0 ? 0 : $request->getIntOrNull( 'pagelink-depth' );
+ $this->pageLinkDepth = $this->getConfig()->get( 'ExportMaxLinkDepth' ) == 0
+ ? 0
+ : $request->getIntOrNull( 'pagelink-depth' );
$this->rootpage = $request->getText( 'rootpage' );
$user = $this->getUser();
@@ -116,19 +120,30 @@ class SpecialImport extends SpecialPage {
if ( !$user->isAllowed( 'import' ) ) {
throw new PermissionsError( 'import' );
}
- $this->interwiki = $request->getVal( 'interwiki' );
- if ( !in_array( $this->interwiki, $wgImportSources ) ) {
+ $this->interwiki = $this->fullInterwikiPrefix = $request->getVal( 'interwiki' );
+ // does this interwiki have subprojects?
+ $importSources = $this->getConfig()->get( 'ImportSources' );
+ $hasSubprojects = array_key_exists( $this->interwiki, $importSources );
+ if ( !$hasSubprojects && !in_array( $this->interwiki, $importSources ) ) {
$source = Status::newFatal( "import-invalid-interwiki" );
} else {
- $this->history = $request->getCheck( 'interwikiHistory' );
- $this->frompage = $request->getText( "frompage" );
- $this->includeTemplates = $request->getCheck( 'interwikiTemplates' );
- $source = ImportStreamSource::newFromInterwiki(
- $this->interwiki,
- $this->frompage,
- $this->history,
- $this->includeTemplates,
- $this->pageLinkDepth );
+ if ( $hasSubprojects ) {
+ $this->subproject = $request->getVal( 'subproject' );
+ $this->fullInterwikiPrefix .= ':' . $request->getVal( 'subproject' );
+ }
+ if ( $hasSubprojects && !in_array( $this->subproject, $importSources[$this->interwiki] ) ) {
+ $source = Status::newFatal( "import-invalid-interwiki" );
+ } else {
+ $this->history = $request->getCheck( 'interwikiHistory' );
+ $this->frompage = $request->getText( "frompage" );
+ $this->includeTemplates = $request->getCheck( 'interwikiTemplates' );
+ $source = ImportStreamSource::newFromInterwiki(
+ $this->fullInterwikiPrefix,
+ $this->frompage,
+ $this->history,
+ $this->includeTemplates,
+ $this->pageLinkDepth );
+ }
}
} else {
$source = Status::newFatal( "importunknownsource" );
@@ -166,7 +181,7 @@ class SpecialImport extends SpecialPage {
$reporter = new ImportReporter(
$importer,
$isUpload,
- $this->interwiki,
+ $this->fullInterwikiPrefix,
$this->logcomment
);
$reporter->setContext( $this->getContext() );
@@ -201,11 +216,10 @@ class SpecialImport extends SpecialPage {
}
private function showForm() {
- global $wgImportSources, $wgExportMaxLinkDepth;
-
- $action = $this->getTitle()->getLocalURL( array( 'action' => 'submit' ) );
+ $action = $this->getPageTitle()->getLocalURL( array( 'action' => 'submit' ) );
$user = $this->getUser();
$out = $this->getOutput();
+ $importSources = $this->getConfig()->get( 'ImportSources' );
if ( $user->isAllowed( 'importupload' ) ) {
$out->addHTML(
@@ -242,7 +256,10 @@ class SpecialImport extends SpecialPage {
</tr>
<tr>
<td class='mw-label'>" .
- Xml::label( $this->msg( 'import-interwiki-rootpage' )->text(), 'mw-interwiki-rootpage-upload' ) .
+ Xml::label(
+ $this->msg( 'import-interwiki-rootpage' )->text(),
+ 'mw-interwiki-rootpage-upload'
+ ) .
"</td>
<td class='mw-input'>" .
Xml::input( 'rootpage', 50, $this->rootpage,
@@ -261,15 +278,15 @@ class SpecialImport extends SpecialPage {
Xml::closeElement( 'fieldset' )
);
} else {
- if ( empty( $wgImportSources ) ) {
+ if ( empty( $importSources ) ) {
$out->addWikiMsg( 'importnosources' );
}
}
- if ( $user->isAllowed( 'import' ) && !empty( $wgImportSources ) ) {
+ if ( $user->isAllowed( 'import' ) && !empty( $importSources ) ) {
# Show input field for import depth only if $wgExportMaxLinkDepth > 0
$importDepth = '';
- if ( $wgExportMaxLinkDepth > 0 ) {
+ if ( $this->getConfig()->get( 'ExportMaxLinkDepth' ) > 0 ) {
$importDepth = "<tr>
<td class='mw-label'>" .
$this->msg( 'export-pagelinks' )->parse() .
@@ -297,7 +314,7 @@ class SpecialImport extends SpecialPage {
Xml::openElement( 'table', array( 'id' => 'mw-import-table-interwiki' ) ) .
"<tr>
<td class='mw-label'>" .
- Xml::label( $this->msg( 'import-interwiki-source' )->text(), 'interwiki' ) .
+ Xml::label( $this->msg( 'import-interwiki-sourcewiki' )->text(), 'interwiki' ) .
"</td>
<td class='mw-input'>" .
Xml::openElement(
@@ -306,13 +323,63 @@ class SpecialImport extends SpecialPage {
)
);
- foreach ( $wgImportSources as $prefix ) {
- $selected = ( $this->interwiki === $prefix ) ? ' selected="selected"' : '';
- $out->addHTML( Xml::option( $prefix, $prefix, $selected ) );
+ $needSubprojectField = false;
+ foreach ( $importSources as $key => $value ) {
+ if ( is_int( $key ) ) {
+ $key = $value;
+ } elseif ( $value !== $key ) {
+ $needSubprojectField = true;
+ }
+
+ $attribs = array(
+ 'value' => $key,
+ );
+ if ( is_array( $value ) ) {
+ $attribs['data-subprojects'] = implode( ' ', $value );
+ }
+ if ( $this->interwiki === $key ) {
+ $attribs['selected'] = 'selected';
+ }
+ $out->addHTML( Html::element( 'option', $attribs, $key ) );
+ }
+
+ $out->addHTML(
+ Xml::closeElement( 'select' )
+ );
+
+ if ( $needSubprojectField ) {
+ $out->addHTML(
+ Xml::openElement(
+ 'select',
+ array( 'name' => 'subproject', 'id' => 'subproject' )
+ )
+ );
+
+ $subprojectsToAdd = array();
+ foreach ( $importSources as $key => $value ) {
+ if ( is_array( $value ) ) {
+ $subprojectsToAdd = array_merge( $subprojectsToAdd, $value );
+ }
+ }
+ $subprojectsToAdd = array_unique( $subprojectsToAdd );
+ sort( $subprojectsToAdd );
+ foreach ( $subprojectsToAdd as $subproject ) {
+ $out->addHTML( Xml::option( $subproject, $subproject, $this->subproject === $subproject ) );
+ }
+
+ $out->addHTML(
+ Xml::closeElement( 'select' )
+ );
}
$out->addHTML(
- Xml::closeElement( 'select' ) .
+ "</td>
+ </tr>
+ <tr>
+ <td class='mw-label'>" .
+ Xml::label( $this->msg( 'import-interwiki-sourcepage' )->text(), 'frompage' ) .
+ "</td>
+ <td class='mw-input'>" .
Xml::input( 'frompage', 50, $this->frompage, array( 'id' => 'frompage' ) ) .
"</td>
</tr>
@@ -411,11 +478,10 @@ class ImportReporter extends ContextSource {
private $mOriginalPageOutCallback = null;
private $mLogItemCount = 0;
-
/**
* @param WikiImporter $importer
- * @param $upload
- * @param $interwiki
+ * @param bool $upload
+ * @param string $interwiki
* @param string|bool $reason
*/
function __construct( $importer, $upload, $interwiki, $reason = false ) {
@@ -435,7 +501,9 @@ class ImportReporter extends ContextSource {
}
function reportNotice( $msg, array $params ) {
- $this->getOutput()->addHTML( Html::element( 'li', array(), $this->msg( $msg, $params )->text() ) );
+ $this->getOutput()->addHTML(
+ Html::element( 'li', array(), $this->msg( $msg, $params )->text() )
+ );
}
function reportLogItem( /* ... */ ) {
@@ -449,8 +517,8 @@ class ImportReporter extends ContextSource {
* @param Title $title
* @param Title $origTitle
* @param int $revisionCount
- * @param $successCount
- * @param $pageInfo
+ * @param int $successCount
+ * @param array $pageInfo
* @return void
*/
function reportPage( $title, $origTitle, $revisionCount, $successCount, $pageInfo ) {
@@ -476,7 +544,8 @@ class ImportReporter extends ContextSource {
$detail = $this->msg( 'import-logentry-upload-detail' )->numParams(
$successCount )->inContentLanguage()->text();
if ( $this->reason ) {
- $detail .= $this->msg( 'colon-separator' )->inContentLanguage()->text() . $this->reason;
+ $detail .= $this->msg( 'colon-separator' )->inContentLanguage()->text()
+ . $this->reason;
}
$log->addEntry( 'upload', $title, $detail, array(), $this->getUser() );
} else {
@@ -485,7 +554,8 @@ class ImportReporter extends ContextSource {
$detail = $this->msg( 'import-logentry-interwiki-detail' )->numParams(
$successCount )->params( $interwiki )->inContentLanguage()->text();
if ( $this->reason ) {
- $detail .= $this->msg( 'colon-separator' )->inContentLanguage()->text() . $this->reason;
+ $detail .= $this->msg( 'colon-separator' )->inContentLanguage()->text()
+ . $this->reason;
}
$log->addEntry( 'interwiki', $title, $detail, array(), $this->getUser() );
}
@@ -493,13 +563,23 @@ class ImportReporter extends ContextSource {
$comment = $detail; // quick
$dbw = wfGetDB( DB_MASTER );
$latest = $title->getLatestRevID();
- $nullRevision = Revision::newNullRevision( $dbw, $title->getArticleID(), $comment, true );
+ $nullRevision = Revision::newNullRevision(
+ $dbw,
+ $title->getArticleID(),
+ $comment,
+ true,
+ $this->getUser()
+ );
+
if ( !is_null( $nullRevision ) ) {
$nullRevision->insertOn( $dbw );
$page = WikiPage::factory( $title );
# Update page record
$page->updateRevisionOn( $dbw, $nullRevision );
- wfRunHooks( 'NewRevisionFromEditComplete', array( $page, $nullRevision, $latest, $this->getUser() ) );
+ wfRunHooks(
+ 'NewRevisionFromEditComplete',
+ array( $page, $nullRevision, $latest, $this->getUser() )
+ );
}
} else {
$this->getOutput()->addHTML( "<li>" . Linker::linkKnown( $title ) . " " .