*/
class SpecialImport extends SpecialPage {
private $interwiki = false;
+ private $subproject;
+ private $fullInterwikiPrefix;
private $namespace;
private $rootpage = '';
private $frompage = '';
$this->setHeaders();
$this->outputHeader();
+ $this->getOutput()->addModules( 'mediawiki.special.import' );
+
$user = $this->getUser();
if ( !$user->isAllowedAny( 'import', 'importupload' ) ) {
throw new PermissionsError( 'import' );
if ( !$user->isAllowed( 'import' ) ) {
throw new PermissionsError( 'import' );
}
- $this->interwiki = $request->getVal( 'interwiki' );
- if ( !in_array( $this->interwiki, $this->getConfig()->get( 'ImportSources' ) ) ) {
+ $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" );
$reporter = new ImportReporter(
$importer,
$isUpload,
- $this->interwiki,
+ $this->fullInterwikiPrefix,
$this->logcomment
);
$reporter->setContext( $this->getContext() );
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(
)
);
- foreach ( $importSources 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;
+ } else if ( $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>
"import-summary": "{{doc-specialpagesummary|import}}",
"importinterwiki": "Used as legend for the Import form in [[Special:Import]].",
"import-interwiki-text": "Used as summary for the Import form in [[Special:Import]].",
- "import-interwiki-source": "Used as label for input box in [[Special:Import]].",
+ "import-interwiki-sourcewiki": "Used as label for dropdown box in [[Special:Import]].",
+ "import-interwiki-sourcepage": "Used as label for input box in [[Special:Import]].",
"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}}",
--- /dev/null
+/*!
+ * JavaScript for Special:Import
+ */
+( function ( $ ) {
+ function updateImportSubprojectList() {
+ var $projectField = $( '#mw-import-table-interwiki #interwiki' ),
+ $subprojectField = $projectField.parent().find( '#subproject' ),
+ $selected = $projectField.find( ':selected' ),
+ oldValue = $subprojectField.val(),
+ option, options;
+
+ if ( $selected.attr( 'data-subprojects' ) ) {
+ options = $.map( $selected.attr( 'data-subprojects' ).split( ' ' ), function ( el ) {
+ option = document.createElement( 'option' );
+ option.appendChild( document.createTextNode( el ) );
+ option.setAttribute( 'value', el );
+ if ( oldValue === el ) {
+ option.setAttribute( 'selected', 'selected' );
+ }
+ return option;
+ } );
+ $subprojectField.show().empty().append( options );
+ } else {
+ $subprojectField.hide();
+ }
+ }
+
+ $( function () {
+ var $projectField = $( '#mw-import-table-interwiki #interwiki' );
+ if ( $projectField.length ) {
+ $projectField.change( updateImportSubprojectList );
+ updateImportSubprojectList();
+ }
+ } );
+}( jQuery ) );