private $reader = null;
private $foreignNamespaces = null;
private $mLogItemCallback, $mUploadCallback, $mRevisionCallback, $mPageCallback;
- private $mSiteInfoCallback, $mTargetNamespace, $mPageOutCallback;
+ private $mSiteInfoCallback, $mPageOutCallback;
private $mNoticeCallback, $mDebug;
private $mImportUploads, $mImageBasePath;
private $mNoUpdates = false;
public function setTargetNamespace( $namespace ) {
if ( is_null( $namespace ) ) {
// Don't override namespaces
- $this->mTargetNamespace = null;
$this->setImportTitleFactory( new NaiveImportTitleFactory() );
return true;
} elseif (
MWNamespace::exists( intval( $namespace ) )
) {
$namespace = intval( $namespace );
- $this->mTargetNamespace = $namespace;
$this->setImportTitleFactory( new NamespaceImportTitleFactory( $namespace ) );
return true;
} else {
$this->setImportTitleFactory( new NaiveImportTitleFactory() );
} elseif ( $rootpage !== '' ) {
$rootpage = rtrim( $rootpage, '/' ); //avoid double slashes
- $title = Title::newFromText( $rootpage, !is_null( $this->mTargetNamespace )
- ? $this->mTargetNamespace
- : NS_MAIN
- );
+ $title = Title::newFromText( $rootpage );
if ( !$title || $title->isExternal() ) {
$status->fatal( 'import-rootpage-invalid' );
private $interwiki = false;
private $subproject;
private $fullInterwikiPrefix;
+ private $mapping = 'default';
private $namespace;
private $rootpage = '';
private $frompage = '';
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' );
}
$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(
}
}
+ 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();
$importSources = $this->getConfig()->get( 'ImportSources' );
if ( $user->isAllowed( 'importupload' ) ) {
+ $mappingSelection = $this->getMappingFormPart( 'upload' );
$out->addHTML(
Xml::fieldset( $this->msg( 'import-upload' )->text() ) .
Xml::openElement(
"</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'>" .
"</td>
</tr>";
}
+ $mappingSelection = $this->getMappingFormPart( 'interwiki' );
$out->addHTML(
Xml::fieldset( $this->msg( 'importinterwiki' )->text() ) .
"</td>
</tr>
$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>
"import-interwiki-history": "This is an option on [[Special:Import]]. Usually, when unchecked, only the first version of a page is imported. When you check the option, all versions are imported. This is important often to check for licensing reasons.\n\nSee also:\n* {{msg-mw|Import-interwiki-templates}}\n* {{msg-mw|Import-interwiki-namespace}}\n* {{msg-mw|Import-comment}}\n* {{msg-mw|Import-interwiki-rootpage}}\n* {{msg-mw|Import-interwiki-submit}}",
"import-interwiki-templates": "Used as label for the checkbox in [[Special:Import]].\n\nSee also:\n* {{msg-mw|Import-interwiki-history}}\n* {{msg-mw|Import-interwiki-namespace}}\n* {{msg-mw|Import-comment}}\n* {{msg-mw|Import-interwiki-rootpage}}\n* {{msg-mw|Import-interwiki-submit}}",
"import-interwiki-submit": "Used as Submit button text in [[Special:Import]].\n\nSee also:\n* {{msg-mw|Import-interwiki-history}}\n* {{msg-mw|Import-interwiki-templates}}\n* {{msg-mw|Import-interwiki-namespace}}\n* {{msg-mw|Import-comment}}\n* {{msg-mw|Import-interwiki-rootpage}}\n{{Identical|Import}}",
- "import-interwiki-namespace": "Used as label in Import form on [[Special:Import]].\n\nSee also:\n* {{msg-mw|Import-interwiki-history}}\n* {{msg-mw|Import-interwiki-templates}}\n* {{msg-mw|Import-comment}}\n* {{msg-mw|Import-interwiki-rootpage}}\n* {{msg-mw|Import-interwiki-submit}}",
- "import-interwiki-rootpage": "Used on [[Special:Import]] as label.\n\nSee also:\n* {{msg-mw|Import-interwiki-history}}\n* {{msg-mw|Import-interwiki-templates}}\n* {{msg-mw|Import-interwiki-namespace}}\n* {{msg-mw|Import-comment}}\n* {{msg-mw|Import-interwiki-submit}}",
+ "import-mapping-default": "Used as label for the first of three radio buttons in Import form on [[Special:Import]].\n\nSee also:\n* {{msg-mw|Import-mapping-namespace}}\n* {{msg-mw|Import-mapping-subpage}}",
+ "import-mapping-namespace": "Used as label for the second of three radio buttons in Import form on [[Special:Import]]. The radio button is followed by a drop-down list from which the user can select a namespace.\n\nSee also:\n* {{msg-mw|Import-mapping-default}}\n* {{msg-mw|Import-mapping-subpage}}",
+ "import-mapping-subpage": "Used as label for the third of three radio buttons in Import form on [[Special:Import]]. The radio button is followed by a text box in which the user can type a page name. The imported pages will be created as subpages of the entered page name.\n\nSee also:\n* {{msg-mw|Import-mapping-default}}\n* {{msg-mw|Import-mapping-namespace}}",
"import-upload-filename": "Used on [[Special:Import]] as label for upload of an XML file containing the pages to import.\n{{Identical|Filename}}",
"import-comment": "Used as label for input box in [[Special:Import]].\n\nSee also:\n* {{msg-mw|Import-interwiki-history}}\n* {{msg-mw|Import-interwiki-templates}}\n* {{msg-mw|Import-interwiki-namespace}}\n* {{msg-mw|Import-interwiki-rootpage}}\n* {{msg-mw|Import-interwiki-submit}}\n{{Identical|Comment}}",
"importtext": "Used in the Import form on [[Special:Import]].",