Improvement to detection of nested template ranges.

* Existing code for detecting nested templates stopped after
  finding the first container rather than finding the outermost
  container.

* The simple change in this patch fixes contrived examples that
  come about from fostering.
------------
{|
{{echo|<div>}}
foo
{{echo|</div>}}
|}
------------

  In this example, 3 template ranges are detected, all of which
  are identical (fostered content + table). Nesting detection wasn't
  picking up the outermost (in terms of wikitext source range)
  template which resulted in a missing data-mw and resulting
  screwup in RT-ing.

* Unrelated: minor tweaks to several comments.

* Fixes a selser failure from a8374b63294ae31d494e5dd65cebc31a1392694b

Change-Id: I190e6c6081ecc79fea2bb4304a9cd41c14221158