Page MenuHomePhabricator

Consider codifying whether a given hook allows making primary db reads/writes
Open, Needs TriagePublic

Description

As part of the work for T88445: MediaWiki active/active datacenter investigation and work (tracking), it would be helpful if core and extension hooks provided documentation stating if the hook is invoked in a GET or POST (or possibly either) request context. That way, developers would have an easier time verifying if primary database connections are allowed, if writes are allowed, etc.

e.g. for a hook like:

/**
 * This is a hook handler interface, see docs/Hooks.md.
 * Use the hook name "LocalUserCreated" to register handlers implementing this interface.
 *
 * @stable to implement
 * @ingroup Hooks
 */
interface LocalUserCreatedHook {
	/**
	 * This hook is called when a local user has been created.
	 *
	 * @since 1.35
	 *
	 * @param User $user User object for the created user
	 * @param bool $autocreated Whether this was an auto-creation
	 * @return bool|void True or no return value to continue or false to abort
	 */
	public function onLocalUserCreated( $user, $autocreated );
}

we would modify it to something like:

/**
 * This is a hook handler interface, see docs/Hooks.md.
 * Use the hook name "LocalUserCreated" to register handlers implementing this interface.
 *
 * @stable to implement
 * @ingroup Hooks
 * @requestContext GET|POST
 *   - POST: Invoked on Special:CreateAccount or account creation via the API.
 *   - GET: Invoked on user autocreation when a user visits a wiki in the same wikifarm where the local account does not yet exist.
 */
interface LocalUserCreatedHook {
	/**
	 * This hook is called when a local user has been created.
	 *
	 * @since 1.35
	 *
	 * @param User $user User object for the created user
	 * @param bool $autocreated Whether this was an auto-creation
	 * @return bool|void True or no return value to continue or false to abort
	 */
	public function onLocalUserCreated( $user, $autocreated );
}

Event Timeline

Krinkle renamed this task from Document whether hooks are invoked in GET/POST request context to Consider codifying whether a given hook allows making primary db reads/writes.Oct 5 2021, 6:31 PM
Krinkle moved this task from Limbo to Watching on the Performance-Team (Radar) board.