Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
19.08% covered (danger)
19.08%
62 / 325
13.64% covered (danger)
13.64%
3 / 22
CRAP
0.00% covered (danger)
0.00%
0 / 1
SpecialImportFile
19.08% covered (danger)
19.08%
62 / 325
13.64% covered (danger)
13.64%
3 / 22
3055.85
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 getRestriction
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isListed
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 doesWrites
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getGroupName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 userCanExecute
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
6
 executeStandardChecks
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
56
 getDescription
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 62
0.00% covered (danger)
0.00%
0 / 1
306
 handleAction
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
42
 makeImportPlan
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 1
2
 logErrorStats
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 doCodexImport
0.00% covered (danger)
0.00%
0 / 39
0.00% covered (danger)
0.00%
0 / 1
20
 doImport
84.00% covered (warning)
84.00%
42 / 50
0.00% covered (danger)
0.00%
0 / 1
6.15
 logActionStats
12.50% covered (danger)
12.50%
1 / 8
0.00% covered (danger)
0.00%
0 / 1
30.12
 performPostImportActions
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 getWarningMessage
33.33% covered (danger)
33.33%
2 / 6
0.00% covered (danger)
0.00%
0 / 1
5.67
 showWarningMessage
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
 showImportPage
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 getAutomatedCapabilities
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 1
90
 showCodexImportPage
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 1
6
 showLandingPage
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace FileImporter;
4
5use Exception;
6use FileImporter\Data\ImportPlan;
7use FileImporter\Data\ImportRequest;
8use FileImporter\Exceptions\AbuseFilterWarningsException;
9use FileImporter\Exceptions\CommunityPolicyException;
10use FileImporter\Exceptions\DuplicateFilesException;
11use FileImporter\Exceptions\HttpRequestException;
12use FileImporter\Exceptions\ImportException;
13use FileImporter\Exceptions\LocalizedImportException;
14use FileImporter\Exceptions\RecoverableTitleException;
15use FileImporter\Html\ChangeFileInfoForm;
16use FileImporter\Html\ChangeFileNameForm;
17use FileImporter\Html\DuplicateFilesErrorPage;
18use FileImporter\Html\ErrorPage;
19use FileImporter\Html\FileInfoDiffPage;
20use FileImporter\Html\HelpBanner;
21use FileImporter\Html\ImportPreviewPage;
22use FileImporter\Html\ImportSuccessSnippet;
23use FileImporter\Html\InfoPage;
24use FileImporter\Html\InputFormPage;
25use FileImporter\Html\RecoverableTitleExceptionPage;
26use FileImporter\Html\SourceWikiCleanupSnippet;
27use FileImporter\Remote\MediaWiki\RemoteApiActionExecutor;
28use FileImporter\Services\Importer;
29use FileImporter\Services\ImportPlanFactory;
30use FileImporter\Services\SourceSiteLocator;
31use FileImporter\Services\WikidataTemplateLookup;
32use MediaWiki\Config\Config;
33use MediaWiki\Content\IContentHandlerFactory;
34use MediaWiki\EditPage\EditPage;
35use MediaWiki\Exception\ErrorPageError;
36use MediaWiki\Exception\PermissionsError;
37use MediaWiki\Exception\UserBlockedError;
38use MediaWiki\Html\Html;
39use MediaWiki\Logger\LoggerFactory;
40use MediaWiki\Registration\ExtensionRegistry;
41use MediaWiki\Request\WebRequest;
42use MediaWiki\SpecialPage\SpecialPage;
43use MediaWiki\Status\Status;
44use MediaWiki\Upload\UploadBase;
45use MediaWiki\User\Options\UserOptionsManager;
46use MediaWiki\User\User;
47use OOUI\HtmlSnippet;
48use OOUI\MessageWidget;
49use Psr\Log\LoggerInterface;
50use StatusValue;
51use Wikimedia\Stats\StatsFactory;
52
53/**
54 * @license GPL-2.0-or-later
55 * @author Addshore
56 */
57class SpecialImportFile extends SpecialPage {
58
59    private const ERROR_UPLOAD_DISABLED = 'uploadDisabled';
60    private const ERROR_USER_PERMISSIONS = 'userPermissionsError';
61    private const ERROR_LOCAL_BLOCK = 'userBlocked';
62
63    private readonly StatsFactory $statsFactory;
64    private readonly LoggerInterface $logger;
65
66    public function __construct(
67        private readonly SourceSiteLocator $sourceSiteLocator,
68        private readonly Importer $importer,
69        private readonly ImportPlanFactory $importPlanFactory,
70        private readonly RemoteApiActionExecutor $remoteActionApi,
71        private readonly WikidataTemplateLookup $templateLookup,
72        private readonly IContentHandlerFactory $contentHandlerFactory,
73        StatsFactory $statsFactory,
74        private readonly UserOptionsManager $userOptionsManager,
75        private readonly Config $config,
76    ) {
77        parent::__construct( 'ImportFile' );
78
79        $this->statsFactory = $statsFactory->withComponent( 'FileImporter' );
80        $this->logger = LoggerFactory::getInstance( 'FileImporter' );
81    }
82
83    /** @inheritDoc */
84    public function getRestriction(): string {
85        return $this->config->get( 'FileImporterRequiredRight' );
86    }
87
88    /** @inheritDoc */
89    public function isListed(): bool {
90        return $this->config->get( 'FileImporterShowInputScreen' );
91    }
92
93    /** @inheritDoc */
94    public function doesWrites() {
95        return true;
96    }
97
98    /**
99     * @inheritDoc
100     */
101    public function getGroupName() {
102        return 'media';
103    }
104
105    /**
106     * @inheritDoc
107     */
108    public function userCanExecute( User $user ) {
109        return UploadBase::isEnabled() && parent::userCanExecute( $user );
110    }
111
112    /**
113     * Checks based on those in EditPage and SpecialUpload
114     *
115     * @throws ErrorPageError when one of the checks failed
116     */
117    private function executeStandardChecks(): void {
118        $unicodeCheck = $this->getRequest()->getText( 'wpUnicodeCheck' );
119        if ( $unicodeCheck && $unicodeCheck !== EditPage::UNICODE_CHECK ) {
120            throw new ErrorPageError( 'errorpagetitle', 'unicode-support-fail' );
121        }
122
123        # Check uploading enabled
124        if ( !UploadBase::isEnabled() ) {
125            $this->logErrorStats( self::ERROR_UPLOAD_DISABLED, false );
126            throw new ErrorPageError( 'uploaddisabled', 'uploaddisabledtext' );
127        }
128
129        $user = $this->getUser();
130
131        // Check if the user does have all the rights required via $wgFileImporterRequiredRight (set
132        // to "upload" by default), as well as "upload" and "edit" in case â€¦RequiredRight is more
133        // relaxed. Note special pages must call userCanExecute() manually when parent::execute()
134        // isn't called, {@see SpecialPage::__construct}.
135        $missingPermission = parent::userCanExecute( $user )
136            ? UploadBase::isAllowed( $user )
137            : $this->getRestriction();
138        if ( is_string( $missingPermission ) ) {
139            $this->logErrorStats( self::ERROR_USER_PERMISSIONS, false );
140            throw new PermissionsError( $missingPermission );
141        }
142
143        # Check blocks
144        $localBlock = $user->getBlock();
145        if ( $localBlock ) {
146            $this->logErrorStats( self::ERROR_LOCAL_BLOCK, false );
147            throw new UserBlockedError( $localBlock );
148        }
149
150        # Check whether we actually want to allow changing stuff
151        $this->checkReadOnly();
152    }
153
154    /** @inheritDoc */
155    public function getDescription() {
156        return $this->msg( 'fileimporter-specialpage' );
157    }
158
159    /**
160     * @param string|null $subPage
161     */
162    public function execute( $subPage ): void {
163        $webRequest = $this->getRequest();
164        $clientUrl = $webRequest->getVal( 'clientUrl', '' );
165        $action = $webRequest->getRawVal( ImportPreviewPage::ACTION_BUTTON );
166        if ( $action ) {
167            $this->logger->info( "Performing $action on ImportPlan for URL: $clientUrl" );
168        }
169
170        $isCodex = $webRequest->getBool( 'codex' ) &&
171            $this->getConfig()->get( 'FileImporterCodexMode' );
172        $isCodexSubmit = $isCodex && $this->getRequest()->wasPosted() && $action === 'submit';
173
174        if ( !$isCodexSubmit ) {
175            $this->setHeaders();
176            $this->getOutput()->enableOOUI();
177        }
178        $this->executeStandardChecks();
179
180        if ( !$isCodex ) {
181            $this->getOutput()->addModuleStyles( 'ext.FileImporter.SpecialCss' );
182            $this->getOutput()->addModuleStyles( 'ext.FileImporter.Images' );
183            $this->getOutput()->addModules( 'ext.FileImporter.SpecialJs' );
184        }
185
186        // Note: executions by users that don't have the rights to view the page etc will not be
187        // shown in this metric as executeStandardChecks will have already kicked them out,
188        $execTotalMetric = $this->statsFactory->getCounter( 'specialPage_executions_total' )
189            ->setLabel( 'parameter', 'none' );
190        // The importSource url parameter is added to requests from the FileExporter extension.
191        if ( $webRequest->getRawVal( 'importSource' ) === 'FileExporter' ) {
192            $execTotalMetric->setLabel( 'parameter', 'fromFileExporter' );
193        }
194
195        if ( $clientUrl === '' ) {
196            $execTotalMetric->setLabel( 'parameter', 'noClientUrl' );
197            $this->showLandingPage();
198            return;
199        }
200
201        if ( $webRequest->getBool( HelpBanner::HIDE_HELP_BANNER_CHECK_BOX ) &&
202            $this->getUser()->isNamed()
203        ) {
204            $this->userOptionsManager->setOption(
205                $this->getUser(),
206                HelpBanner::HIDE_HELP_BANNER_PREFERENCE,
207                '1'
208            );
209            $this->userOptionsManager->saveOptions( $this->getUser() );
210        }
211
212        try {
213            $this->logger->info( 'Getting ImportPlan for URL: ' . $clientUrl );
214            $importPlan = $this->makeImportPlan( $webRequest );
215
216            if ( $isCodexSubmit ) {
217                // disable all default output of the special page, like headers, title, navigation
218                $this->getOutput()->disable();
219                header( 'Content-type: application/json; charset=utf-8' );
220                $this->doCodexImport( $importPlan );
221            } elseif ( $isCodex ) {
222                $this->getOutput()->addModules( 'ext.FileImporter.SpecialCodexJs' );
223                $this->showCodexImportPage( $importPlan );
224            } else {
225                $this->handleAction( $action, $importPlan );
226            }
227        } catch ( ImportException $exception ) {
228            $this->logger->info( 'ImportException: ' . $exception->getMessage() );
229            $this->logErrorStats(
230                (string)$exception->getCode(),
231                $exception instanceof RecoverableTitleException
232            );
233
234            if ( $exception instanceof DuplicateFilesException ) {
235                $html = ( new DuplicateFilesErrorPage( $this ) )->getHtml(
236                    $exception->getFiles(),
237                    $clientUrl
238                );
239            } elseif ( $exception instanceof RecoverableTitleException ) {
240                $html = ( new RecoverableTitleExceptionPage( $this ) )->getHtml( $exception );
241            } else {
242                $html = ( new ErrorPage( $this ) )->getHtml(
243                    $this->getWarningMessage( $exception ),
244                    $clientUrl,
245                    $exception instanceof CommunityPolicyException ? 'warning' : 'error'
246                );
247            }
248            $this->getOutput()->enableOOUI();
249            $this->getOutput()->addHTML( $html );
250        }
251    }
252
253    private function handleAction( ?string $action, ImportPlan $importPlan ): void {
254        switch ( $action ) {
255            case ImportPreviewPage::ACTION_SUBMIT:
256                $this->doImport( $importPlan );
257                break;
258            case ImportPreviewPage::ACTION_EDIT_TITLE:
259                $importPlan->setActionIsPerformed( ImportPreviewPage::ACTION_EDIT_TITLE );
260                $this->getOutput()->addHTML(
261                    ( new ChangeFileNameForm( $this ) )->getHtml( $importPlan )
262                );
263                break;
264            case ImportPreviewPage::ACTION_EDIT_INFO:
265                $importPlan->setActionIsPerformed( ImportPreviewPage::ACTION_EDIT_INFO );
266                $this->getOutput()->addHTML(
267                    ( new ChangeFileInfoForm( $this ) )->getHtml( $importPlan )
268                );
269                break;
270            case ImportPreviewPage::ACTION_VIEW_DIFF:
271                $contentHandler = $this->contentHandlerFactory->getContentHandler( CONTENT_MODEL_WIKITEXT );
272                $this->getOutput()->addHTML(
273                    ( new FileInfoDiffPage( $this ) )->getHtml( $importPlan, $contentHandler )
274                );
275                break;
276            default:
277                $this->showImportPage( $importPlan );
278        }
279    }
280
281    /**
282     * @throws ImportException
283     */
284    private function makeImportPlan( WebRequest $webRequest ): ImportPlan {
285        $importRequest = new ImportRequest(
286            $webRequest->getVal( 'clientUrl' ),
287            $webRequest->getVal( 'intendedFileName' ),
288            $webRequest->getVal( 'intendedWikitext' ),
289            $webRequest->getVal( 'intendedRevisionSummary' ),
290            $webRequest->getRawVal( 'importDetailsHash' ) ?? ''
291        );
292
293        $url = $importRequest->getUrl();
294        $sourceSite = $this->sourceSiteLocator->getSourceSite( $url );
295        $importDetails = $sourceSite->retrieveImportDetails( $url );
296
297        $importPlan = $this->importPlanFactory->newPlan(
298            $importRequest,
299            $importDetails,
300            $this->getContext()
301        );
302        $importPlan->setActionStats(
303            json_decode( $webRequest->getVal( 'actionStats', '[]' ), true )
304        );
305        $importPlan->setValidationWarnings(
306            json_decode( $webRequest->getVal( 'validationWarnings', '[]' ), true )
307        );
308        $importPlan->setAutomateSourceWikiCleanUp(
309            $webRequest->getBool( 'automateSourceWikiCleanup' )
310        );
311        $importPlan->setAutomateSourceWikiDelete(
312            $webRequest->getBool( 'automateSourceWikiDelete' )
313        );
314
315        return $importPlan;
316    }
317
318    private function logErrorStats( string $type, bool $isRecoverable ): void {
319        $this->statsFactory->getCounter( 'errors_total' )
320            ->setLabel( 'recoverable', wfBoolToStr( $isRecoverable ) )
321            ->setLabel( 'type', $type )
322            ->increment();
323    }
324
325    private function doCodexImport( ImportPlan $importPlan ): void {
326        // TODO handle error cases and echo JSON to allow Codex to visualize the errors
327        try {
328            $this->importer->import(
329                $this->getUser(),
330                $importPlan
331            );
332            $this->statsFactory->getCounter( 'imports_total' )
333                ->setLabel( 'result', 'success' )
334                ->increment();
335            $this->logActionStats( $importPlan );
336
337            $postImportResult = $this->performPostImportActions( $importPlan );
338            $successRedirectUrl = ( new ImportSuccessSnippet() )->getRedirectWithNotice(
339                $importPlan->getTitle(),
340                $this->getUser(),
341                $postImportResult
342            );
343
344            echo json_encode( [
345                'success' => true,
346                'redirect' => $successRedirectUrl,
347            ] );
348        } catch ( ImportException $exception ) {
349            if ( $exception instanceof AbuseFilterWarningsException ) {
350                $warningMessages = [];
351                $warningMessages[] = [
352                    'type' => 'warning',
353                    'message' => $this->getWarningMessage( $exception )
354                ];
355
356                foreach ( $exception->getMessages() as $msg ) {
357                    $warningMessages[] = [
358                        'type' => 'warning',
359                        'message' => $this->msg( $msg )->parse()
360                    ];
361                }
362
363                echo json_encode( [
364                    'error' => true,
365                    'warningMessages' => $warningMessages,
366                    'validationWarnings' => $importPlan->getValidationWarnings()
367                ] );
368            } else {
369                // TODO: More graceful error handling
370                echo json_encode( [
371                    'error' => true,
372                    'output' => $exception->getTrace(),
373                ] );
374            }
375        }
376    }
377
378    private function doImport( ImportPlan $importPlan ): bool {
379        $out = $this->getOutput();
380        $importDetails = $importPlan->getDetails();
381
382        $importDetailsHash = $out->getRequest()->getRawVal( 'importDetailsHash' ) ?? '';
383        $token = $out->getRequest()->getRawVal( 'token' ) ?? '';
384
385        if ( !$this->getContext()->getCsrfTokenSet()->matchToken( $token ) ) {
386            $this->showWarningMessage( $this->msg( 'fileimporter-badtoken' )->parse() );
387            $this->logErrorStats( 'badToken', true );
388            return false;
389        }
390
391        if ( $importDetails->getOriginalHash() !== $importDetailsHash ) {
392            $this->showWarningMessage( $this->msg( 'fileimporter-badimporthash' )->parse() );
393            $this->logErrorStats( 'badImportHash', true );
394            return false;
395        }
396
397        try {
398            $this->importer->import(
399                $this->getUser(),
400                $importPlan
401            );
402            $this->statsFactory->getCounter( 'imports_total' )
403                ->setLabel( 'result', 'success' )
404                ->increment();
405            // TODO: inline at site of action
406            $this->logActionStats( $importPlan );
407
408            $postImportResult = $this->performPostImportActions( $importPlan );
409
410            $out->redirect(
411                ( new ImportSuccessSnippet() )->getRedirectWithNotice(
412                    $importPlan->getTitle(),
413                    $this->getUser(),
414                    $postImportResult
415                )
416            );
417
418            return true;
419        } catch ( ImportException $exception ) {
420            $this->logErrorStats(
421                (string)$exception->getCode(),
422                $exception instanceof RecoverableTitleException
423            );
424
425            if ( $exception instanceof AbuseFilterWarningsException ) {
426                $this->showWarningMessage( $this->getWarningMessage( $exception ), 'warning' );
427
428                foreach ( $exception->getMessages() as $msg ) {
429                    $this->showWarningMessage(
430                        $this->msg( $msg )->parse(),
431                        'warning',
432                        true
433                    );
434                }
435
436                $this->showImportPage( $importPlan );
437            } else {
438                $this->showWarningMessage(
439                    Html::rawElement( 'strong', [], $this->msg( 'fileimporter-importfailed' )->parse() ) .
440                    '<br>' .
441                    $this->getWarningMessage( $exception ),
442                    'error'
443                );
444            }
445            return false;
446        }
447    }
448
449    private function logActionStats( ImportPlan $importPlan ): void {
450        foreach ( $importPlan->getActionStats() as $key => $_ ) {
451            if (
452                $key === ImportPreviewPage::ACTION_EDIT_TITLE ||
453                $key === ImportPreviewPage::ACTION_EDIT_INFO ||
454                $key === SourceWikiCleanupSnippet::ACTION_OFFERED_SOURCE_DELETE ||
455                $key === SourceWikiCleanupSnippet::ACTION_OFFERED_SOURCE_EDIT
456            ) {
457                $this->statsFactory->getCounter( 'specialPage_actions_total' )
458                    ->setLabel( 'action', $key )
459                    ->increment();
460            }
461        }
462    }
463
464    private function performPostImportActions( ImportPlan $importPlan ): StatusValue {
465        $sourceSite = $importPlan->getRequest()->getUrl();
466        $postImportHandler = $this->sourceSiteLocator->getSourceSite( $sourceSite )
467            ->getPostImportHandler();
468
469        return $postImportHandler->execute( $importPlan, $this->getUser() );
470    }
471
472    /**
473     * @return string HTML
474     */
475    private function getWarningMessage( Exception $ex ): string {
476        if ( $ex instanceof LocalizedImportException ) {
477            return $ex->getMessageObject()->inLanguage( $this->getLanguage() )->parse();
478        }
479        if ( $ex instanceof HttpRequestException ) {
480            return Status::wrap( $ex->getStatusValue() )->getHTML( false, false,
481                $this->getLanguage() );
482        }
483
484        return htmlspecialchars( $ex->getMessage() );
485    }
486
487    /**
488     * @param string $html
489     * @param string $type Set to "notice" for a gray box, defaults to "error" (red)
490     * @param bool $inline
491     */
492    private function showWarningMessage( string $html, string $type = 'error', bool $inline = false ): void {
493        $this->getOutput()->enableOOUI();
494        $this->getOutput()->addHTML(
495            new MessageWidget( [
496                'label' => new HtmlSnippet( $html ),
497                'type' => $type,
498                'inline' => $inline,
499            ] ) .
500            '<br>'
501        );
502    }
503
504    private function showImportPage( ImportPlan $importPlan ): void {
505        $this->getOutput()->addHTML(
506            ( new ImportPreviewPage( $this ) )->getHtml( $importPlan )
507        );
508    }
509
510    /**
511     * @return array of automation features and whether they are available
512     */
513    private function getAutomatedCapabilities( ImportPlan $importPlan ) {
514        $capabilities = [];
515
516        $config = $this->getConfig();
517        $isCentralAuthEnabled = ExtensionRegistry::getInstance()->isLoaded( 'CentralAuth' );
518        $sourceUrl = $importPlan->getRequest()->getUrl();
519
520        $capabilities['canAutomateEdit'] =
521            $isCentralAuthEnabled &&
522            $config->get( 'FileImporterSourceWikiTemplating' ) &&
523            $this->templateLookup->fetchNowCommonsLocalTitle( $sourceUrl ) &&
524            $this->remoteActionApi->executeTestEditActionQuery(
525                $sourceUrl,
526                $this->getUser(),
527                $importPlan->getTitle()->getPrefixedText()
528            )->isGood();
529        $capabilities['canAutomateDelete'] =
530            $isCentralAuthEnabled &&
531            $config->get( 'FileImporterSourceWikiDeletion' ) &&
532            $this->remoteActionApi->executeUserRightsQuery( $sourceUrl, $this->getUser() )->isGood();
533
534        if ( $capabilities['canAutomateDelete'] ) {
535            $capabilities['automateDeleteSelected'] = $importPlan->getAutomateSourceWikiDelete();
536
537            $this->statsFactory->getCounter( 'specialPage_actions_total' )
538                ->setLabel( 'action', 'offeredSourceDelete' )
539                ->increment();
540        } elseif ( $capabilities['canAutomateEdit'] ) {
541            $capabilities['automateEditSelected'] =
542                $importPlan->getAutomateSourceWikiCleanUp() ||
543                $importPlan->getRequest()->getImportDetailsHash() === '';
544            $capabilities['cleanupTitle'] =
545                $this->templateLookup->fetchNowCommonsLocalTitle( $sourceUrl );
546            $this->statsFactory->getCounter( 'specialPage_actions_total' )
547                ->setLabel( 'action', 'offeredSourceEdit' )
548                ->increment();
549        }
550
551        return $capabilities;
552    }
553
554    private function showCodexImportPage( ImportPlan $importPlan ): void {
555        $this->getOutput()->addHTML(
556            Html::element( 'noscript', [], $this->msg( 'fileimporter-no-script-warning' )->text() )
557        );
558
559        $this->getOutput()->addHTML(
560            Html::rawElement( 'div', [ 'id' => 'ext-fileimporter-vue-root' ] )
561        );
562
563        $showHelpBanner = !$this->userOptionsManager
564            ->getBoolOption( $this->getUser(), 'userjs-fileimporter-hide-help-banner' );
565
566        $this->getOutput()->addJsConfigVars( [
567            'wgFileImporterAutomatedCapabilities' => $this->getAutomatedCapabilities( $importPlan ),
568            'wgFileImporterClientUrl' => $importPlan->getRequest()->getUrl()->getUrl(),
569            'wgFileImporterEditToken' => $this->getUser()->getEditToken(),
570            'wgFileImporterFileRevisionsCount' =>
571                count( $importPlan->getDetails()->getFileRevisions()->toArray() ),
572            'wgFileImporterHelpBannerContentHtml' => $showHelpBanner ?
573                FileImporterUtils::addTargetBlankToLinks(
574                    $this->msg( 'fileimporter-help-banner-text' )->parse()
575                ) : null,
576            'wgFileImporterTextRevisionsCount' =>
577                count( $importPlan->getDetails()->getTextRevisions()->toArray() ),
578            'wgFileImporterTitle' => $importPlan->getFileName(),
579            'wgFileImporterFileExtension' => $importPlan->getFileExtension(),
580            'wgFileImporterPrefixedTitle' => $importPlan->getTitle()->getPrefixedText(),
581            'wgFileImporterImageUrl' => $importPlan->getDetails()->getImageDisplayUrl(),
582            'wgFileImporterInitialFileInfoWikitext' => $importPlan->getInitialFileInfoText(),
583            'wgFileImporterFileInfoWikitext' =>
584                // FIXME: can assume the edit field is persistent
585                $importPlan->getRequest()->getIntendedText() ?? $importPlan->getFileInfoText(),
586            'wgFileImporterEditSummary' => $importPlan->getRequest()->getIntendedSummary(),
587            'wgFileImporterDetailsHash' => $importPlan->getDetails()->getOriginalHash(),
588            'wgFileImporterTemplateReplacementCount' => $importPlan->getNumberOfTemplateReplacements(),
589        ] );
590    }
591
592    private function showLandingPage(): void {
593        $page = $this->getConfig()->get( 'FileImporterShowInputScreen' )
594            ? new InputFormPage( $this )
595            : new InfoPage( $this );
596
597        $this->getOutput()->addHTML( $page->getHtml() );
598    }
599
600}