Share tags2

Supersedes #11351.
Okay, I probably haven't fully grasped the injection pattern yet. You mean I need to get rid of the `if ($db === null)` check and make sure `$db` is always passed by the caller?