53 parent::__construct(
'Import',
'import' );
75 $this->
getOutput()->addModules(
'mediawiki.special.import' );
76 $this->
getOutput()->addModuleStyles(
'mediawiki.special.import.styles.ooui' );
78 $this->importSources = $this->
getConfig()->get( MainConfigNames::ImportSources );
80 if ( !is_array( $this->importSources ) ) {
81 throw new UnexpectedValueException(
'$wgImportSources must be an array' );
83 $this->
getHookRunner()->onImportSources( $this->importSources );
86 if ( !$this->permManager->userHasAnyRight( $user,
'import',
'importupload' ) ) {
90 # @todo Allow PermissionManager::getPermissionErrors() to take an array
92 $this->permManager->getPermissionErrors(
93 'import', $user, $this->getPageTitle(),
94 PermissionManager::RIGOR_FULL,
95 [
'ns-specialprotected',
'badaccess-group0',
'badaccess-groups' ]
97 $this->permManager->getPermissionErrors(
98 'importupload', $user, $this->getPageTitle(),
99 PermissionManager::RIGOR_FULL,
100 [
'ns-specialprotected',
'badaccess-group0',
'badaccess-groups' ]
111 if ( $request->wasPosted() && $request->getRawVal(
'action' ) ==
'submit' ) {
123 $sourceName = $request->getVal(
'source' );
124 $assignKnownUsers = $request->getCheck(
'assignKnownUsers' );
126 $logcomment = $request->getText(
'log-comment' );
127 $pageLinkDepth = $this->
getConfig()->get( MainConfigNames::ExportMaxLinkDepth ) == 0
129 : $request->getIntOrNull(
'pagelink-depth' );
132 $mapping = $request->getVal(
'mapping' );
133 $namespace = $this->
getConfig()->get( MainConfigNames::ImportTargetNamespace );
134 if ( $mapping ===
'namespace' ) {
135 $namespace = $request->getIntOrNull(
'namespace' );
136 } elseif ( $mapping ===
'subpage' ) {
137 $rootpage = $request->getText(
'rootpage' );
142 $fullInterwikiPrefix =
null;
143 if ( !$user->matchEditToken( $request->getVal(
'wpEditToken' ) ) ) {
145 } elseif ( $sourceName ===
'upload' ) {
147 $fullInterwikiPrefix = $request->getVal(
'usernamePrefix' );
148 if ( $this->permManager->userHasRight( $user,
'importupload' ) ) {
153 } elseif ( $sourceName ===
'interwiki' ) {
154 if ( !$this->permManager->userHasRight( $user,
'import' ) ) {
157 $interwiki = $fullInterwikiPrefix = $request->getVal(
'interwiki' );
159 $hasSubprojects = array_key_exists( $interwiki, $this->importSources );
160 if ( !$hasSubprojects && !in_array( $interwiki, $this->importSources ) ) {
164 if ( $hasSubprojects ) {
165 $subproject = $request->getVal(
'subproject' );
167 if ( strpos( $subproject, $interwiki .
'::' ) === 0 ) {
168 $subproject = substr( $subproject, strlen( $interwiki .
'::' ) );
170 $fullInterwikiPrefix .=
':' . $subproject;
172 if ( $hasSubprojects &&
173 !in_array( $subproject, $this->importSources[$interwiki] )
177 $history = $request->getCheck(
'interwikiHistory' );
178 $frompage = $request->getText(
'frompage' );
179 $includeTemplates = $request->getCheck(
'interwikiTemplates' );
182 $fullInterwikiPrefix,
193 if ( (
string)$fullInterwikiPrefix ===
'' ) {
194 $source->fatal(
'importnoprefix' );
199 $out->wrapWikiTextAsInterface(
'error',
200 $this->
msg(
'importfailed',
$source->getWikiText(
false,
false, $this->getLanguage() ) )
204 $importer = $this->wikiImporterFactory->getWikiImporter(
$source->value );
205 if ( $namespace !==
null ) {
206 $importer->setTargetNamespace( $namespace );
207 } elseif ( $rootpage !==
null ) {
208 $statusRootPage = $importer->setTargetRootPage( $rootpage );
209 if ( !$statusRootPage->isGood() ) {
211 "<div class=\"error\">\n$1\n</div>",
213 'import-options-wrong',
214 $statusRootPage->getWikiText(
false,
false, $this->getLanguage() ),
215 count( $statusRootPage->getErrorsArray() )
223 $importer->setUsernamePrefix( $fullInterwikiPrefix, $assignKnownUsers );
225 $out->addWikiMsg(
"importstart" );
231 $fullInterwikiPrefix,
239 $importer->doImport();
240 }
catch ( Exception $e ) {
243 $result = $reporter->close();
246 # No source or XML parse error
248 "<div class=\"error\">\n$1\n</div>",
249 [
'importfailed', $exception->getMessage() ]
251 } elseif ( !$result->isGood() ) {
254 "<div class=\"error\">\n$1\n</div>",
255 [
'importfailed', $result->getWikiText(
false,
false, $this->getLanguage() ) ]
259 $out->addWikiMsg(
'importsuccess' );
261 $out->addHTML(
'<hr />' );
266 $defaultNamespace = $this->
getConfig()->get( MainConfigNames::ImportTargetNamespace );
272 'id' =>
"mw-import-mapping-$sourceName",
273 'options-messages' => [
274 'import-mapping-default' =>
'default',
275 'import-mapping-namespace' =>
'namespace',
276 'import-mapping-subpage' =>
'subpage'
278 'default' => $defaultNamespace !==
null ?
'namespace' :
'default'
281 'type' =>
'namespaceselect',
282 'name' =>
'namespace',
284 'id' =>
"mw-import-namespace-$sourceName",
285 'default' => $defaultNamespace ?:
'',
290 'name' =>
'rootpage',
294 'id' =>
"mw-interwiki-rootpage-$sourceName",
300 $action = $this->
getPageTitle()->getLocalURL( [
'action' =>
'submit' ] );
303 $this->
addHelpLink(
'https://meta.wikimedia.org/wiki/Special:MyLanguage/Help:Import',
true );
305 $interwikiFormDescriptor = [];
306 $uploadFormDescriptor = [];
308 if ( $this->permManager->userHasRight( $user,
'importupload' ) ) {
310 $uploadFormDescriptor += [
314 'default' => $this->
msg(
'importtext' )->parseAsBlock()
318 'name' =>
'xmlimport',
319 'accept' => [
'application/xml',
'text/xml' ],
320 'label-message' =>
'import-upload-filename',
323 'usernamePrefix' => [
325 'name' =>
'usernamePrefix',
326 'label-message' =>
'import-upload-username-prefix',
329 'assignKnownUsers' => [
331 'name' =>
'assignKnownUsers',
332 'label-message' =>
'import-assign-known-users'
336 'name' =>
'log-comment',
337 'label-message' =>
'import-comment'
342 'default' =>
'upload',
347 $uploadFormDescriptor += $mappingSelection;
350 $htmlForm->setAction( $action );
351 $htmlForm->setId(
'mw-import-upload-form' );
352 $htmlForm->setWrapperLegendMsg(
'import-upload' );
353 $htmlForm->setSubmitTextMsg(
'uploadbtn' );
354 $htmlForm->prepareForm()->displayForm(
false );
356 } elseif ( empty( $this->importSources ) ) {
357 $out->addWikiMsg(
'importnosources' );
360 if ( $this->permManager->userHasRight( $user,
'import' ) && !empty( $this->importSources ) ) {
363 $needSubprojectField =
false;
364 foreach ( $this->importSources as $key => $value ) {
365 if ( is_int( $key ) ) {
367 } elseif ( $value !== $key ) {
368 $needSubprojectField =
true;
371 $projects[ $key ] = $key;
374 $interwikiFormDescriptor += [
378 'default' => $this->
msg(
'import-interwiki-text' )->parseAsBlock()
382 'name' =>
'interwiki',
383 'label-message' =>
'import-interwiki-sourcewiki',
384 'options' => $projects
388 if ( $needSubprojectField ) {
390 foreach ( $this->importSources as $key => $value ) {
391 if ( is_array( $value ) ) {
392 foreach ( $value as $subproject ) {
393 $subprojects[ $subproject ] = $key .
'::' . $subproject;
398 $interwikiFormDescriptor += [
401 'name' =>
'subproject',
402 'options' => $subprojects
407 $interwikiFormDescriptor += [
410 'name' =>
'frompage',
411 'label-message' =>
'import-interwiki-sourcepage'
413 'interwikiHistory' => [
415 'name' =>
'interwikiHistory',
416 'label-message' =>
'import-interwiki-history'
418 'interwikiTemplates' => [
420 'name' =>
'interwikiTemplates',
421 'label-message' =>
'import-interwiki-templates'
423 'assignKnownUsers' => [
425 'name' =>
'assignKnownUsers',
426 'label-message' =>
'import-assign-known-users'
430 if ( $this->
getConfig()->
get( MainConfigNames::ExportMaxLinkDepth ) > 0 ) {
431 $interwikiFormDescriptor += [
432 'pagelink-depth' => [
434 'name' =>
'pagelink-depth',
435 'label-message' =>
'export-pagelinks',
441 $interwikiFormDescriptor += [
444 'name' =>
'log-comment',
445 'label-message' =>
'import-comment'
450 'default' =>
'interwiki',
456 $interwikiFormDescriptor += $mappingSelection;
459 $htmlForm->setAction( $action );
460 $htmlForm->setId(
'mw-import-interwiki-form' );
461 $htmlForm->setWrapperLegendMsg(
'importinterwiki' );
462 $htmlForm->setSubmitTextMsg(
'import-interwiki-submit' );
463 $htmlForm->prepareForm()->displayForm(
false );
wfMergeErrorArrays(... $args)
Merge arrays in the style of PermissionManager::getPermissionErrors, with duplicate removal e....
static newFromInterwiki( $interwiki, $page, $history=false, $templates=false, $pageLinkDepth=0)
static newFromUpload( $fieldname="xmlimport")
A class containing constants representing the names of configuration variables.
Show an error when a user tries to do something they do not have the necessary permissions for.
MediaWiki page data importer.
WikiImporterFactory $wikiImporterFactory
doesWrites()
Indicates whether this special page may perform database writes.
getMappingFormPart( $sourceName)
PermissionManager $permManager
doImport()
Do the actual import.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
__construct(PermissionManager $permManager, WikiImporterFactory $wikiImporterFactory)
Parent class for all special pages.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User executing this instance.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
checkReadOnly()
If the wiki is currently in readonly mode, throws a ReadOnlyError.
getPageTitle( $subpage=false)
Get a self-referential title object.
useTransactionalTimeLimit()
Call wfTransactionalTimeLimit() if this request was POSTed.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
static newFatal( $message,... $parameters)
Factory function for fatal errors.
Factory service for WikiImporter instances.