Page MenuHomePhabricator

Add before execute hook into Special:Import and ApiImport
Open, MediumPublic


We have some hooks for Import related stuff. but we don't have handling extra validation or restriction hooks for Import.

I'd like to suggesting to introduce new Hook for above.

Event Timeline

Rxy created this task.Oct 17 2019, 2:24 PM
Restricted Application added a project: User-Rxy. · View Herald TranscriptOct 17 2019, 2:24 PM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Change 543864 had a related patch set uploaded (by Rxy; owner: Rxy):
[mediawiki/core@master] Add Hook 'ImportBeforeExecute' into api/ApiImport.php and specials/SpecialImport.php

Rxy moved this task from Backlog to Development on the User-Rxy board.Oct 17 2019, 2:33 PM
WDoranWMF triaged this task as Medium priority.Dec 3 2019, 5:08 PM
daniel added a subscriber: daniel.EditedMon, Jan 6, 2:23 PM

The hook as proposed in the patch seems problematic to me. The proposed signature is:

'ImportBeforeExecute': When a page import is requested before writing to DB.
&$source Status object to pass error messages to

The hook handler could prevent an import by calling $source->error() or otherwise marking the status as "not ok". But what would this decision be based on? $source->value contains an ImportStreamSource, but that's just a wrapper around a file handle.

The only way for the hook handler to make a decision would be based on global state, which is something we are trying to avoid. So more information would need to be passed into the hook, e.g. the title of the page to be imported. That however isn't know at this stage, since the input hasn't been parsed yet. I don't see how this hook can be made useful.

For restricting imports independently of the target title, just use the 'import' and 'importupload' permissions.

Is there a specific need that motivates this ticket? What's the use case?