New API current_user_set()

The function sets the $g_cache_current_user_id global variable, and
clears the user preferences cache ($g_cache_current_user_pref) if
necessary.

Using this new API to set the current user as opposed to working with
$g_cache_current_user_id makes sure we always get the correct data from
get_user_pref().

Resolves an issue where the order (as well as the number) of bugnotes in
email notifications is based on the user who triggered the action,
instead of the email's recipient.

Fixes #17925 (porting 559ba4e43a2dc6c9f8fd6491f6279379734ac549)