Page MenuHomePhabricator

Special:Import should have a hook
Closed, ResolvedPublic

Description

Some extensions (for instance, http://www.mediawiki.org/wiki/Extension:DataTable)use the onArticleSaveComplete or similar triggers to modify data or store new data. This hook is not execute when importing pages through Special:Import, and Special:Import does not execute any hook. Hence, when importing such pages, one must subsequently edit and save each of them manually.

I'd suggest to create a new hook which is executed at the end of WikiRevision::importOldRevision in SpecialImport.php.


Version: 1.11.x
Severity: enhancement

Details

Reference
bz11537

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 9:58 PM
bzimport set Reference to bz11537.
bzimport added a subscriber: Unknown Object (MLST).

The following patch to SpecialImport.php (as of MW 1.11.0) will do. It is designed such that the parameters passed to RevisionImportComplete hooks are the same as for ArticleSaveComplete (except that some flags which are specific to manual editing will never appear). Thus, in many cases, existing extensions which use the ArticleSaveComplete hook can simply map RevisionImportComplete to the same function.


  • 374,393 ****
  • 374,400 ----

    wfDebug( METHOD . ": running edit updates\n" ); $article->editUpdates( $this->getText(), $this->getComment(), $this->minor, $this->timestamp, $revId ); }

+ $flags = ($created ? EDIT_NEW : 0)
+ | ($changed ? EDIT_UPDATE : 0)
+ | ($this->minor ? EDIT_MINOR : 0);
+ wfRunHooks( 'RevisionImportComplete',
+ array( $article, $user, $this->getText(),
+ $this->getComment(), $flags & EDIT_MINOR,
+ null, null, &$flags, $revision ) );

		return true;
	}

}

/**
 * implements Special:Import
 * @addtogroup SpecialPage
 */
class WikiImporter {

Please post patches as attachments so they can be managed without copy/paste problems.

Created attachment 4261
proposed patch to run a hook

Attached:

Why would you pass a several nulls to the hook? What purpose does that serve?

Because (quote from comment #1): "It is designed such that the parameters passed to RevisionImportComplete hooks are
the same as for ArticleSaveComplete (except that some flags which are specific to manual editing will never appear). Thus, in many cases, existing extensions which use the ArticleSaveComplete hook can simply map RevisionImportComplete to the same function."

I can't think of many cases where the hook will be specifically needed when importing but not when saving pages, unless the purpose of the hook isd just to do extended logging of imports or similar things.

Mass compoment change: <some> -> Export/Import

mike.lifeguard+bugs wrote:

(In reply to comment #5)
[...]

I can't think of many cases where the hook will be specifically needed when
importing but not when saving pages, unless the purpose of the hook isd just to
do extended logging of imports or similar things.

Importing and saving the page are different - if there are conceivable cases where you want the import hook but you're not saving data (ie creating log entries but nothing else) then that should be possible, no?

(In reply to comment #7)

You're right, such a hook might also be useful for other purposes. Note that this is possible with the patch I suggested. In comment #1 I stated that you ''can'' map RevisionImportComplete and ArticleSaveComplete to the same function, but you are not ''forced'' to do so.

mike.lifeguard+bugs wrote:

Is this a dupe of bug 11539?

Basically yes, see comment #9 on bug 11539.

'NewRevisionFromEditComplete' was added a while back. This should inform text/revision tracking needs.

My DataTable extension (http://www.mediawiki.org/wiki/Extension:DataTable) now
uses the hook NewRevisionFromEditComplete
(http://www.mediawiki.org/wiki/Manual:Hooks/NewRevisionFromEditComplete), so
personally I don't have any further need for the hook suggested here.