Gallery backports

Backport of various gallery improvements to stable5.

About half of them weren't clean cherry-picks, please test.

cc @DeepDiver1975 @butonic