Page MenuHomePhabricator

AbuseFilter should provide a way to get WebRequest in custom variable hooks
Open, Needs TriagePublic

Description

See discussion in https://gerrit.wikimedia.org/r/c/mediawiki/extensions/OAuth/+/748784/, it would be good if hooks that want to add a variable depending on the current WebRequest state could access it without relying on global state.

See https://gerrit.wikimedia.org/r/c/mediawiki/extensions/WikimediaEvents/+/280468 (now removed) and https://gerrit.wikimedia.org/g/mediawiki/extensions/MobileApp/+/adf1dc44c4b3879fc516cb1b2c71077ddf95df1d/includes/MobileAppHooks.php#63 as examples that use $wgRequest directly.

Event Timeline

This is a bit problematic... AF itself does not have access to the global request when it fires the hook, and accessing the WebRequest in general is not easy (unless you have a ContextSource). Also, I'm not sure what the future of WebRequest is, and whether we should treat it as a value object or as a service (currently it's something hybrid). If it's the former, then MW core hooks should pass it; if the second, then it should not be passed by the hook, but injected into the hook handler.

Most of the hooks I've seen use it as more of a value object, just checking for some query parameter or header. I don't have a great solution either, just wanted to document this pattern is prevalent and would benefit from something better...