80 $this->
namespace = $this->
getConfig()->get( 'ImportTargetNamespace' );
82 $this->
getOutput()->addModules(
'mediawiki.special.import' );
84 $this->importSources = $this->
getConfig()->get(
'ImportSources' );
86 if ( !is_array( $this->importSources ) ) {
87 throw new UnexpectedValueException(
'$wgImportSources must be an array' );
89 $this->
getHookRunner()->onImportSources( $this->importSources );
92 if ( !$this->permManager->userHasAnyRight( $user,
'import',
'importupload' ) ) {
96 # @todo Allow PermissionManager::getPermissionErrors() to take an array
98 $this->permManager->getPermissionErrors(
99 'import', $user, $this->getPageTitle(),
100 PermissionManager::RIGOR_FULL,
101 [
'ns-specialprotected',
'badaccess-group0',
'badaccess-groups' ]
103 $this->permManager->getPermissionErrors(
104 'importupload', $user, $this->getPageTitle(),
105 PermissionManager::RIGOR_FULL,
106 [
'ns-specialprotected',
'badaccess-group0',
'badaccess-groups' ]
117 if ( $request->wasPosted() && $request->getVal(
'action' ) ==
'submit' ) {
129 $this->sourceName = $request->getVal(
"source" );
130 $this->assignKnownUsers = $request->getCheck(
'assignKnownUsers' );
132 $this->logcomment = $request->getText(
'log-comment' );
133 $this->pageLinkDepth = $this->
getConfig()->get(
'ExportMaxLinkDepth' ) == 0
135 : $request->getIntOrNull(
'pagelink-depth' );
137 $this->mapping = $request->getVal(
'mapping' );
138 if ( $this->mapping ===
'namespace' ) {
139 $this->
namespace = $request->getIntOrNull( 'namespace' );
140 } elseif ( $this->mapping ===
'subpage' ) {
141 $this->rootpage = $request->getText(
'rootpage' );
143 $this->mapping =
'default';
147 if ( !$user->matchEditToken( $request->getVal(
'editToken' ) ) ) {
148 $source = Status::newFatal(
'import-token-mismatch' );
149 } elseif ( $this->sourceName ===
'upload' ) {
151 $this->usernamePrefix = $this->fullInterwikiPrefix = $request->getVal(
'usernamePrefix' );
152 if ( $this->permManager->userHasRight( $user,
'importupload' ) ) {
157 } elseif ( $this->sourceName ===
'interwiki' ) {
158 if ( !$this->permManager->userHasRight( $user,
'import' ) ) {
161 $this->interwiki = $this->fullInterwikiPrefix = $request->getVal(
'interwiki' );
163 $hasSubprojects = array_key_exists( $this->interwiki, $this->importSources );
164 if ( !$hasSubprojects && !in_array( $this->interwiki, $this->importSources ) ) {
165 $source = Status::newFatal(
"import-invalid-interwiki" );
167 if ( $hasSubprojects ) {
168 $this->subproject = $request->getVal(
'subproject' );
169 $this->fullInterwikiPrefix .=
':' . $request->getVal(
'subproject' );
171 if ( $hasSubprojects &&
172 !in_array( $this->subproject, $this->importSources[$this->interwiki] )
174 $source = Status::newFatal(
"import-invalid-interwiki" );
176 $this->history = $request->getCheck(
'interwikiHistory' );
177 $this->frompage = $request->getText(
"frompage" );
178 $this->includeTemplates = $request->getCheck(
'interwikiTemplates' );
180 $this->fullInterwikiPrefix,
183 $this->includeTemplates,
184 $this->pageLinkDepth );
188 $source = Status::newFatal(
"importunknownsource" );
191 if ( (
string)$this->fullInterwikiPrefix ===
'' ) {
192 $source->fatal(
'importnoprefix' );
197 $out->wrapWikiTextAsInterface(
'error',
198 $this->
msg(
'importfailed',
$source->getWikiText(
false,
false, $this->getLanguage() ) )
203 if ( $this->
namespace !==
null ) {
204 $importer->setTargetNamespace( $this->
namespace );
205 } elseif ( $this->rootpage !==
null ) {
206 $statusRootPage = $importer->setTargetRootPage( $this->rootpage );
207 if ( !$statusRootPage->isGood() ) {
209 "<div class=\"error\">\n$1\n</div>",
211 'import-options-wrong',
212 $statusRootPage->getWikiText(
false,
false, $this->getLanguage() ),
213 count( $statusRootPage->getErrorsArray() )
220 $importer->setUsernamePrefix( $this->fullInterwikiPrefix, $this->assignKnownUsers );
222 $out->addWikiMsg(
"importstart" );
227 $this->fullInterwikiPrefix,
235 $importer->doImport();
236 }
catch ( Exception $e ) {
239 $result = $reporter->close();
242 # No source or XML parse error
244 "<div class=\"error\">\n$1\n</div>",
245 [
'importfailed', $exception->getMessage() ]
247 } elseif ( !$result->isGood() ) {
250 "<div class=\"error\">\n$1\n</div>",
251 [
'importfailed', $result->getWikiText(
false,
false, $this->getLanguage() ) ]
255 $out->addWikiMsg(
'importsuccess' );
257 $out->addHTML(
'<hr />' );
262 $isSameSourceAsBefore = ( $this->sourceName ===
$sourceName );
263 $defaultNamespace = $this->
getConfig()->get(
'ImportTargetNamespace' );
267 <td class='mw-input'>" .
269 $this->
msg(
'import-mapping-default' )->text(),
273 "mw-import-mapping-$sourceName-default",
274 ( $isSameSourceAsBefore ?
275 ( $this->mapping ===
'default' ) :
276 $defaultNamespace === null )
283 <td class='mw-input'>" .
285 $this->
msg(
'import-mapping-namespace' )->text(),
289 "mw-import-mapping-$sourceName-namespace",
290 ( $isSameSourceAsBefore ?
291 ( $this->mapping ===
'namespace' ) :
292 $defaultNamespace !== null )
294 Html::namespaceSelector(
296 'selected' => ( $isSameSourceAsBefore ?
298 ( $defaultNamespace ||
'' ) ),
299 'in-user-lang' =>
true,
301 'name' =>
"namespace",
303 'id' =>
"mw-import-namespace-$sourceName",
304 'class' =>
'namespaceselector',
312 <td class='mw-input'>" .
314 $this->
msg(
'import-mapping-subpage' )->text(),
318 "mw-import-mapping-$sourceName-subpage",
319 ( $isSameSourceAsBefore ? ( $this->mapping ===
'subpage' ) :
'' )
321 Xml::input(
'rootpage', 50,
322 ( $isSameSourceAsBefore ? $this->rootpage :
'' ),
327 'id' =>
"mw-interwiki-rootpage-$sourceName",
336 $action = $this->
getPageTitle()->getLocalURL( [
'action' =>
'submit' ] );
339 $this->
addHelpLink(
'https://meta.wikimedia.org/wiki/Special:MyLanguage/Help:Import',
true );
341 if ( $this->permManager->userHasRight( $user,
'importupload' ) ) {
344 Xml::fieldset( $this->
msg(
'import-upload' )->text() ) .
348 'enctype' =>
'multipart/form-data',
351 'id' =>
'mw-import-upload-form'
354 $this->
msg(
'importtext' )->parseAsBlock() .
355 Html::hidden(
'action',
'submit' ) .
356 Html::hidden(
'source',
'upload' ) .
357 Xml::openElement(
'table', [
'id' =>
'mw-import-table-upload' ] ) .
359 <td class='mw-label'>" .
360 Xml::label( $this->
msg(
'import-upload-filename' )->text(),
'xmlimport' ) .
362 <td class='mw-input'>" .
363 Html::input(
'xmlimport',
'',
'file', [
'id' =>
'xmlimport' ] ) .
' ' .
367 <td class='mw-label'>" .
368 Xml::label( $this->
msg(
'import-upload-username-prefix' )->text(),
369 'mw-import-usernamePrefix' ) .
371 <td class='mw-input'>" .
372 Xml::input(
'usernamePrefix', 50,
373 $this->usernamePrefix,
374 [
'id' =>
'usernamePrefix',
'type' =>
'text' ] ) .
' ' .
379 <td class='mw-input'>" .
381 $this->
msg(
'import-assign-known-users' )->text(),
384 $this->assignKnownUsers
389 <td class='mw-label'>" .
390 Xml::label( $this->
msg(
'import-comment' )->text(),
'mw-import-comment' ) .
392 <td class='mw-input'>" .
393 Xml::input(
'log-comment', 50,
394 ( $this->sourceName ===
'upload' ? $this->logcomment :
'' ),
395 [
'id' =>
'mw-import-comment',
'type' =>
'text' ] ) .
' ' .
401 <td class='mw-submit'>" .
402 Xml::submitButton( $this->
msg(
'uploadbtn' )->text() ) .
405 Xml::closeElement(
'table' ) .
406 Html::hidden(
'editToken', $user->getEditToken() ) .
407 Xml::closeElement(
'form' ) .
408 Xml::closeElement(
'fieldset' )
410 } elseif ( empty( $this->importSources ) ) {
411 $out->addWikiMsg(
'importnosources' );
414 if ( $this->permManager->userHasRight( $user,
'import' ) && !empty( $this->importSources ) ) {
415 # Show input field for import depth only if $wgExportMaxLinkDepth > 0
417 if ( $this->
getConfig()->
get(
'ExportMaxLinkDepth' ) > 0 ) {
419 <td class='mw-label'>" .
420 $this->
msg(
'export-pagelinks' )->parse() .
422 <td class='mw-input'>" .
423 Xml::input(
'pagelink-depth', 3, 0 ) .
430 Xml::fieldset( $this->
msg(
'importinterwiki' )->text() ) .
436 'id' =>
'mw-import-interwiki-form'
439 $this->
msg(
'import-interwiki-text' )->parseAsBlock() .
440 Html::hidden(
'action',
'submit' ) .
441 Html::hidden(
'source',
'interwiki' ) .
442 Html::hidden(
'editToken', $user->getEditToken() ) .
443 Xml::openElement(
'table', [
'id' =>
'mw-import-table-interwiki' ] ) .
445 <td class='mw-label'>" .
446 Xml::label( $this->msg(
'import-interwiki-sourcewiki' )->text(),
'interwiki' ) .
448 <td class='mw-input'>" .
451 [
'name' =>
'interwiki',
'id' =>
'interwiki' ]
455 $needSubprojectField =
false;
456 foreach ( $this->importSources as $key => $value ) {
457 if ( is_int( $key ) ) {
459 } elseif ( $value !== $key ) {
460 $needSubprojectField =
true;
466 if ( is_array( $value ) ) {
467 $attribs[
'data-subprojects'] = implode(
' ', $value );
469 if ( $this->interwiki === $key ) {
470 $attribs[
'selected'] =
'selected';
472 $out->addHTML( Html::element(
'option', $attribs, $key ) );
476 Xml::closeElement(
'select' )
479 if ( $needSubprojectField ) {
483 [
'name' =>
'subproject',
'id' =>
'subproject' ]
487 $subprojectsToAdd = [];
488 foreach ( $this->importSources as $key => $value ) {
489 if ( is_array( $value ) ) {
490 $subprojectsToAdd = array_merge( $subprojectsToAdd, $value );
493 $subprojectsToAdd = array_unique( $subprojectsToAdd );
494 sort( $subprojectsToAdd );
500 Xml::closeElement(
'select' )
508 <td class='mw-label'>" .
509 Xml::label( $this->
msg(
'import-interwiki-sourcepage' )->text(),
'frompage' ) .
511 <td class='mw-input'>" .
512 Xml::input(
'frompage', 50, $this->frompage, [
'id' =>
'frompage' ] ) .
518 <td class='mw-input'>" .
520 $this->
msg(
'import-interwiki-history' )->text(),
530 <td class='mw-input'>" .
532 $this->
msg(
'import-interwiki-templates' )->text(),
533 'interwikiTemplates',
534 'interwikiTemplates',
535 $this->includeTemplates
541 <td class='mw-input'>" .
543 $this->
msg(
'import-assign-known-users' )->text(),
545 'interwikiAssignKnownUsers',
546 $this->assignKnownUsers
552 <td class='mw-label'>" .
553 Xml::label( $this->
msg(
'import-comment' )->text(),
'mw-interwiki-comment' ) .
555 <td class='mw-input'>" .
556 Xml::input(
'log-comment', 50,
557 ( $this->sourceName ===
'interwiki' ? $this->logcomment :
'' ),
558 [
'id' =>
'mw-interwiki-comment',
'type' =>
'text' ] ) .
' ' .
565 <td class='mw-submit'>" .
567 $this->
msg(
'import-interwiki-submit' )->text(),
572 Xml::closeElement(
'table' ) .
573 Xml::closeElement(
'form' ) .
574 Xml::closeElement(
'fieldset' )