(cherry picked from commit a802508f88e546bf18990559e44bf27a09c869ee)
Co-authored-by: silverwind <me@silverwind.io> (cherry picked from commit be112c1fc30f87a248b30f48e891d1c8c18e8280) Conflicts: routers/web/web.go trivial conflict because of https://codeberg.org/forgejo/forgejo/pulls/1533
just a step towards #25655 and some related refactoring
Replace #20480 Replace #18448 Close #16414