Page MenuHomePhabricator

Provide an edit revision id within StopForumSpam logging, if available
Open, Needs TriagePublicFeature

Description

Per conversation during the monthly stewards call, it would be nice to provide an edit revision id with StopForumSpam's basic action logging, probably in this specific logging statement. This should only be relevant in report-only mode, as any non-read action should be blocked when StopForumSpam is set to enforce.

Event Timeline

Aklapper changed the subtype of this task from "Task" to "Feature Request".Nov 14 2022, 12:46 PM

Presumably this would need to use a different hook, one that is fired after the save is done (so there actually is a revision ID), then run probably the same checks again (or use a cached in process result)...

https://www.mediawiki.org/wiki/Manual:Hooks/PageSaveComplete or similar..

Thanks, @Reedy. So is there a best practice here? Is there a convenient way to conditionally control which hooks are subscribed based upon config? Or should both hooks be defined, with as much common logic abstracted out as a static function (or whatever) and then conditionally control the entire block within the hook? e.g.

public static function doCommonStuff( ... ) {
  ...
}

public function onHook1( ... ) {
  global $SFSReportOnly;
  if( $SFSReportOnly ) {
    static::doCommonStuff();
  }
}

public function onHook2( ... ) {
  if( ! $SFSReportOnly ) {
    static::doCommonStuff();
  }
}

https://www.mediawiki.org/wiki/Manual:Hooks

For extensions, if the hook function's behavior is conditioned on a setting in LocalSettings.php, the hook should be assigned and the function should terminate early if the condition was not met.

So basically, do what you suggest. Return early and don't block execution (returning true/false in some hooks does this for example; the return false; at the end of onGetUserPermissionsErrorsExpensive does this - preventing other hooks from running after it) of subsequent hook subscribers.

We might want to improve logging further so it documents something "before edit" and "on edit saved" or similar (to make searching easier, my wording there is terrible :P), and then we can include a revision ID where appropriate.

I would suggest moving most/all of the code into a common function where possible. Can make $revisionID or similar an optional parameter, and then just include it in the structured logging data when !== null or similar

Change 868501 had a related patch set uploaded (by SBassett; author: SBassett):

[mediawiki/extensions/StopForumSpam@master] Add support for revision ID logging in report-only mode

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