Page MenuHomePhabricator

Add hook to Linker::generateRollback()
Closed, ResolvedPublic

Description

Currently there is no hook that would allow extensions to modify the rollback links in MW's interface appearing in various places (history, RC, diffs etc.).

Motivation

It would be valuable if extensions could modify the default rollback link provided by MW. For example, the rollback method could be changed to AJAX-based, or more rollback methods could be added, such as reverting with a reason given.

Currently the only solution to a use case like this would be to modify HTML output, which would be very error-prone and ugly. Another solution would be to trigger a lot of JS on page load to modify the DOM, but that slows down page loading, creates additional flickering and does not work properly with features like enhanced RC.

We would use this hook to implement an extension that improves user experience in moderation (patrolling, reverting, etc.). See the relevant task here: https://gitlab.com/nonsensopedia/extensions/fancymoderation/-/issues/1

Hook description

LinkerGenerateRollbackLink is called in Linker::generateRollback static method after all important checks against the DB are done, but before any prettyfication of the link. This is to avoid code duplication in extensions and simplify hook implementation.

The extension can also return false to indicate no further processing of the link is needed. This may be useful if the extension wants full control over the link's appearance.

The hook passes these parameters:

  • $revision – the top revision to roll back.
  • $contextIContextSource provided by the caller.
  • $options – array of options passed to the method.
  • &$inner – modifiable HTML of the link.

Event Timeline

Change 595894 had a related patch set uploaded (by Ostrzyciel; owner: Ostrzyciel):
[mediawiki/core@master] Add hook to Linker::generateRollback()

https://gerrit.wikimedia.org/r/595894

Do you have a particular extension in mind that would use this hook?

Do you have a particular extension in mind that would use this hook?

Yes! :) With the help of two other guys from my wiki, we are writing FancyModeration (repo). It doesn't have a page on mediawiki.org yet (I should really do this), but it is being actively developed and tested on nonsa.pl.

Currently it has a few patrol-related features that improve user's experience with patrolling by allowing multiple changes to be patrolled at once, providing more patrol links, improving the responsiveness of them, etc. We decided to utilize as much PHP hooking as possible to reduce the load on users' browsers, so most of the magic is happening on the server.

We also want to do the same with rollback by providing pop-up windows allowing the user to specify a reason for the rollback and adding an option for a confirmation dialog that would prevent clumsy users from doing an accidental revert. We also think of making revert links on RecentChanges perform the revert through AJAX, without the need for the user to leave the page. There are quite a few possibilities :)

Change 595894 merged by jenkins-bot:
[mediawiki/core@master] Add hook to Linker::generateRollback()

https://gerrit.wikimedia.org/r/595894

Ostrzyciel updated the task description. (Show Details)