IMO the way to go is XWIKI-21728
So that's what I did. It's a bit too dangerous for LTS branches, so I only did it in master (16.7.0).