53 parent::__construct(
'Import',
'import' );
72 $this->
namespace = $this->
getConfig()->get( 'ImportTargetNamespace' );
74 $this->
getOutput()->addModules(
'mediawiki.special.import' );
76 $this->importSources = $this->
getConfig()->get(
'ImportSources' );
77 Hooks::run(
'ImportSources', [ &$this->importSources ] );
80 if ( !MediaWikiServices::getInstance()
82 ->userHasAnyRight( $user,
'import',
'importupload' )
87 # @todo Allow Title::getUserPermissionsErrors() to take an array
88 # @todo FIXME: Title::checkSpecialsAndNSPermissions() has a very weird expectation of what
89 # getUserPermissionsErrors() might actually be used for, hence the 'ns-specialprotected'
92 'import', $user, PermissionManager::RIGOR_FULL,
93 [
'ns-specialprotected',
'badaccess-group0',
'badaccess-groups' ]
96 'importupload', $user, PermissionManager::RIGOR_FULL,
97 [
'ns-specialprotected',
'badaccess-group0',
'badaccess-groups' ]
108 if ( $request->wasPosted() && $request->getVal(
'action' ) ==
'submit' ) {
120 $this->sourceName = $request->getVal(
"source" );
121 $this->assignKnownUsers = $request->getCheck(
'assignKnownUsers' );
123 $this->logcomment = $request->getText(
'log-comment' );
124 $this->pageLinkDepth = $this->
getConfig()->get(
'ExportMaxLinkDepth' ) == 0
126 : $request->getIntOrNull(
'pagelink-depth' );
128 $this->mapping = $request->getVal(
'mapping' );
129 if ( $this->mapping ===
'namespace' ) {
130 $this->
namespace = $request->getIntOrNull( 'namespace' );
131 } elseif ( $this->mapping ===
'subpage' ) {
132 $this->rootpage = $request->getText(
'rootpage' );
134 $this->mapping =
'default';
138 $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
139 if ( !$user->matchEditToken( $request->getVal(
'editToken' ) ) ) {
141 } elseif ( $this->sourceName ===
'upload' ) {
143 $this->usernamePrefix = $this->fullInterwikiPrefix = $request->getVal(
'usernamePrefix' );
144 if ( $permissionManager->userHasRight( $user,
'importupload' ) ) {
149 } elseif ( $this->sourceName ===
'interwiki' ) {
150 if ( !$permissionManager->userHasRight( $user,
'import' ) ) {
153 $this->interwiki = $this->fullInterwikiPrefix = $request->getVal(
'interwiki' );
155 $hasSubprojects = array_key_exists( $this->interwiki, $this->importSources );
156 if ( !$hasSubprojects && !in_array( $this->interwiki, $this->importSources ) ) {
159 if ( $hasSubprojects ) {
160 $this->subproject = $request->getVal(
'subproject' );
161 $this->fullInterwikiPrefix .=
':' . $request->getVal(
'subproject' );
163 if ( $hasSubprojects &&
164 !in_array( $this->subproject, $this->importSources[$this->interwiki] )
168 $this->history = $request->getCheck(
'interwikiHistory' );
169 $this->frompage = $request->getText(
"frompage" );
170 $this->includeTemplates = $request->getCheck(
'interwikiTemplates' );
172 $this->fullInterwikiPrefix,
175 $this->includeTemplates,
176 $this->pageLinkDepth );
183 if ( (
string)$this->fullInterwikiPrefix ===
'' ) {
184 $source->fatal(
'importnoprefix' );
189 $out->wrapWikiTextAsInterface(
'error',
190 $this->
msg(
'importfailed',
$source->getWikiText(
false,
false, $this->getLanguage() ) )
195 if ( !is_null( $this->
namespace ) ) {
196 $importer->setTargetNamespace( $this->
namespace );
197 } elseif ( !is_null( $this->rootpage ) ) {
198 $statusRootPage = $importer->setTargetRootPage( $this->rootpage );
199 if ( !$statusRootPage->isGood() ) {
201 "<div class=\"error\">\n$1\n</div>",
203 'import-options-wrong',
204 $statusRootPage->getWikiText(
false,
false, $this->getLanguage() ),
205 count( $statusRootPage->getErrorsArray() )
212 $importer->setUsernamePrefix( $this->fullInterwikiPrefix, $this->assignKnownUsers );
214 $out->addWikiMsg(
"importstart" );
219 $this->fullInterwikiPrefix,
227 $importer->doImport();
228 }
catch ( Exception $e ) {
231 $result = $reporter->close();
234 # No source or XML parse error
236 "<div class=\"error\">\n$1\n</div>",
237 [
'importfailed', $exception->getMessage() ]
239 } elseif ( !$result->isGood() ) {
242 "<div class=\"error\">\n$1\n</div>",
243 [
'importfailed', $result->getWikiText(
false,
false, $this->getLanguage() ) ]
247 $out->addWikiMsg(
'importsuccess' );
249 $out->addHTML(
'<hr />' );
254 $isSameSourceAsBefore = ( $this->sourceName ===
$sourceName );
255 $defaultNamespace = $this->
getConfig()->get(
'ImportTargetNamespace' );
259 <td class='mw-input'>" .
261 $this->
msg(
'import-mapping-default' )->text(),
265 "mw-import-mapping-$sourceName-default",
266 ( $isSameSourceAsBefore ?
267 ( $this->mapping ===
'default' ) :
268 is_null( $defaultNamespace ) )
275 <td class='mw-input'>" .
277 $this->
msg(
'import-mapping-namespace' )->text(),
281 "mw-import-mapping-$sourceName-namespace",
282 ( $isSameSourceAsBefore ?
283 ( $this->mapping ===
'namespace' ) :
284 !is_null( $defaultNamespace ) )
288 'selected' => ( $isSameSourceAsBefore ?
290 ( $defaultNamespace ||
'' ) ),
291 'in-user-lang' =>
true,
293 'name' =>
"namespace",
295 'id' =>
"mw-import-namespace-$sourceName",
296 'class' =>
'namespaceselector',
304 <td class='mw-input'>" .
306 $this->
msg(
'import-mapping-subpage' )->text(),
310 "mw-import-mapping-$sourceName-subpage",
311 ( $isSameSourceAsBefore ? ( $this->mapping ===
'subpage' ) :
'' )
314 ( $isSameSourceAsBefore ? $this->rootpage :
'' ),
319 'id' =>
"mw-interwiki-rootpage-$sourceName",
328 $action = $this->
getPageTitle()->getLocalURL( [
'action' =>
'submit' ] );
330 $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
332 $this->
addHelpLink(
'https://meta.wikimedia.org/wiki/Special:MyLanguage/Help:Import',
true );
334 if ( $permissionManager->userHasRight( $user,
'importupload' ) ) {
341 'enctype' =>
'multipart/form-data',
344 'id' =>
'mw-import-upload-form'
347 $this->
msg(
'importtext' )->parseAsBlock() .
352 <td class='mw-label'>" .
353 Xml::label( $this->
msg(
'import-upload-filename' )->text(),
'xmlimport' ) .
355 <td class='mw-input'>" .
356 Html::input(
'xmlimport',
'',
'file', [
'id' =>
'xmlimport' ] ) .
' ' .
360 <td class='mw-label'>" .
361 Xml::label( $this->
msg(
'import-upload-username-prefix' )->text(),
362 'mw-import-usernamePrefix' ) .
364 <td class='mw-input'>" .
366 $this->usernamePrefix,
367 [
'id' =>
'usernamePrefix',
'type' =>
'text' ] ) .
' ' .
372 <td class='mw-input'>" .
374 $this->
msg(
'import-assign-known-users' )->text(),
377 $this->assignKnownUsers
382 <td class='mw-label'>" .
383 Xml::label( $this->
msg(
'import-comment' )->text(),
'mw-import-comment' ) .
385 <td class='mw-input'>" .
387 ( $this->sourceName ===
'upload' ? $this->logcomment :
'' ),
388 [
'id' =>
'mw-import-comment',
'type' =>
'text' ] ) .
' ' .
394 <td class='mw-submit'>" .
403 } elseif ( empty( $this->importSources ) ) {
404 $out->addWikiMsg(
'importnosources' );
407 if ( $permissionManager->userHasRight( $user,
'import' ) && !empty( $this->importSources ) ) {
408 # Show input field for import depth only if $wgExportMaxLinkDepth > 0
410 if ( $this->
getConfig()->
get(
'ExportMaxLinkDepth' ) > 0 ) {
412 <td class='mw-label'>" .
413 $this->
msg(
'export-pagelinks' )->parse() .
415 <td class='mw-input'>" .
429 'id' =>
'mw-import-interwiki-form'
432 $this->
msg(
'import-interwiki-text' )->parseAsBlock() .
438 <td class='mw-label'>" .
439 Xml::label( $this->msg(
'import-interwiki-sourcewiki' )->text(),
'interwiki' ) .
441 <td class='mw-input'>" .
444 [
'name' =>
'interwiki',
'id' =>
'interwiki' ]
448 $needSubprojectField =
false;
449 foreach ( $this->importSources as $key => $value ) {
450 if ( is_int( $key ) ) {
452 } elseif ( $value !== $key ) {
453 $needSubprojectField =
true;
459 if ( is_array( $value ) ) {
460 $attribs[
'data-subprojects'] = implode(
' ', $value );
462 if ( $this->interwiki === $key ) {
463 $attribs[
'selected'] =
'selected';
472 if ( $needSubprojectField ) {
476 [
'name' =>
'subproject',
'id' =>
'subproject' ]
480 $subprojectsToAdd = [];
481 foreach ( $this->importSources as $key => $value ) {
482 if ( is_array( $value ) ) {
483 $subprojectsToAdd = array_merge( $subprojectsToAdd, $value );
486 $subprojectsToAdd = array_unique( $subprojectsToAdd );
487 sort( $subprojectsToAdd );
501 <td class='mw-label'>" .
502 Xml::label( $this->
msg(
'import-interwiki-sourcepage' )->text(),
'frompage' ) .
504 <td class='mw-input'>" .
505 Xml::input(
'frompage', 50, $this->frompage, [
'id' =>
'frompage' ] ) .
511 <td class='mw-input'>" .
513 $this->
msg(
'import-interwiki-history' )->text(),
523 <td class='mw-input'>" .
525 $this->
msg(
'import-interwiki-templates' )->text(),
526 'interwikiTemplates',
527 'interwikiTemplates',
528 $this->includeTemplates
534 <td class='mw-input'>" .
536 $this->
msg(
'import-assign-known-users' )->text(),
538 'interwikiAssignKnownUsers',
539 $this->assignKnownUsers
545 <td class='mw-label'>" .
546 Xml::label( $this->
msg(
'import-comment' )->text(),
'mw-interwiki-comment' ) .
548 <td class='mw-input'>" .
550 ( $this->sourceName ===
'interwiki' ? $this->logcomment :
'' ),
551 [
'id' =>
'mw-interwiki-comment',
'type' =>
'text' ] ) .
' ' .
558 <td class='mw-submit'>" .
560 $this->
msg(
'import-interwiki-submit' )->text(),