I've now found the other threads about this, at https://moodle.org/mod/forum/discuss.php?d=310805 and https://moodle.org/mod/forum/discuss.php?d=270112, and can confirm that Bruno Manzoni's patch in the latter thread basically fixes the problem. It doesn't put in "[edit]" links against the <h3> - <h5> headings in the ToC or the wiki page, but that's something I can live without.
This gets the Atto editor working "correctly" with the wiki; TinyMCE users just have to remember that a Level 3 heading is the top level in a wiki page (a convention I'd adopted previously anyway - <h1> and <h2> are used in the main course page.
If I get time I'll investigate this further, but it's been years since I looked at the PHP internals of Moodle.