move much of the Sidebar logic out into Foundation, since Wiki_template will need it too