Page MenuHomePhabricator

No easy way to suppress hard-deprecation warnings for hooks
Open, Needs TriagePublic

Description

The new Hooks system in T240307: Hook container with strong types and DI allows you to mark deprecated hooks, eg:

{
	"Hooks": {
		"UserLoginComplete" : {
			"handler": "*",
			"deprecated": true
		},
		"UserLoginComplete2" : {
			"handler": "*"
		}
	}
}

However, "acknowledging deprecation in this way causes the handler to not be called."

This causes problems for third-party code which doesn't have the resources to immediately patch their code to remove/replace usage of a deprecated hook. As soon as the hook is hard-deprecated in core, their CI breaks and becomes unusable until they replace usage of the deprecated hook, which may require engineering resources they don't immediately have.

There ought to be a way to acknowledge deprecation/suppress deprecation warnings *without* preventing the hook from being called.

You can probably use some version of MediaWikiTextCaseTrait::hideDeprecated / ::filterDeprecated, but the string to use is quite complicated (see HookContainer::callLegacyHook). It would be better if it were a simple boolean added to extension.json like deprecated: true; perhaps acknowledgeDeprecation: true or something like that.

Event Timeline

cscott renamed this task from No way to suppress hard-deprecation warnings for hooks to No easy way to suppress hard-deprecation warnings for hooks.May 27 2020, 4:43 PM

Change 599092 had a related patch set uploaded (by C. Scott Ananian; owner: C. Scott Ananian):
[mediawiki/core@master] WIP: Proof-of-concept of suppressing deprecation warnings from extensions

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

Proof of concept patches in https://gerrit.wikimedia.org/r/599092 (core) and https://gerrit.wikimedia.org/r/599093 (how it would be applied in an extension).

It's a little complicated by the need to migrate the extension to the new Hooks infrastructure; it would be ideal if this could work with the legacy hooks framework (since the whole goal here is to allow teams to defer migration work until resources are available), but I couldn't find any obvious way to add that extra flag to the legacy extension.json or $wgHooks syntax in https://www.mediawiki.org/wiki/Manual:Hooks . The standard syntax would pass any extra arguments to the function; you could probably tweak it to allow passing an associative array, but it doesn't really seem like we want to add new features to a syntax we're moving away from.