Page MenuHomePhabricator

Grand Hook Revamp
Open, Needs TriagePublic

Description

Over the past years, there have been several pushes to improve the way MediaWiki exposes hooks to extensions. The three main aspects are:

  1. Use proper interfaces instead of callbacks, and enable the use of dependency injection in hook handlers: T240307: Hook container with strong types and DI
  2. Make all hooks either an "action" hook (potentially async, serializable params) or a "filter" hook (no sideeffects): T212482: RFC: Evolve hook system to support "filters" and "actions" only
  3. Reduce the surface we expose to extensions, by passing only simple objects (ideally, only "data") to hooks. This matches nicely the desire to no longer bind to "monster objects" (such as User, Title, WikiPage, Language, etc) and define narrow interfaces and value objects to be used instead.

Instead of addressing these concerns separately, it seems useful to address them together. It's a disruptive change, and we should minimize the cost (time, effort) it imposes on extension maintainers. The process could go something like this:

  1. Pick two or three extensions. Analyze which hooks it uses, and how. Also look at how the same hooks are used by other extensions.
  2. Modernize the hooks used by the extensions. For each hook, create replacements that conform to the action/filter principles and only expose "data". Note that in some cases, new abstractions (service objects, value objects) may need to be created to allow for the hook interface to be "clean".
  3. Change the extensions to use the new hooks. At the same time, change it to use the new hook handler system.
  4. Repeat until all relevant hooks and extensions have been updated.

Rough estimate of effort: A first round could be done by two to three engineers in four to six weeks, depending on the extensions and hooks chosen. When doing this the first time, we may hit snags and find that we need to step back and spend time creating some extra abstractions (classes, interfaces) for use by the hooks. The more often we do this, the better the chance that we already have all necessary abstractions. The current drive to break up classes like Title and User is providing a good foundation to reduce the need to spend time on creating new classes and interfaces that can be used in hooks.

After the initial test run, we should have a good idea of how long it would take to do the same thing for all hooks and extensions. As a preliminary rough estimate, will take two people about six month of focused work, plus another quarter of wrapping up the long tail "on the side". This can be scaled out to some degree by assigning different sets of extensions and hooks to different sub-teams, but coordination is needed because the sets of hooks used by sets of extensions overlap. Perhaps six people could get it done in a quarter - but only if most of the people involved have done this kind of work before. Otherwise, it'll take an extra month to ramp up.

Related tasks:

Event Timeline

Hey there. This task is proposed as a blocker to MediaWiki 1.37, which will be cut in less than three weeks' time. Please consider whether this will make that deadline, and if not, move it to block the MediaWiki 1.38 release (MW-1.38-release) or remove as a blocker entirely.