Handle flipped tpl-ranges in findTopLevelNonOverlappingRanges

* Because of fostered of end-tags, a range's end and start tags
  might be flipped.  In such a scenario, two ranges A and B
  might have exactly identical ranges.

     A = {start: e1, end: e2}
     B = {start: e2, end: e1} where B is the flipped range.

  With these two ranges, it doesn't matter how we handle nesting.
  It is okay to consider A nested in B or the other other way
  round as long as we dont introduce a nesting loop.

  The logic in findTopLevelNonOverlappingRanges was missing a
  check to handle this scenario. When testing if B is nested
  in A, it wasn't checking if A was already nested in B.  Without
  this check, we will record that A is nested in B and B is nested
  in A which will introduce a loop in findToplevelEnclosingRange!

* Here is a reduced example extracted from Dogma_studio:

    <table>
    {{echo|<div>}}
    foo
    {{echo|</div>}}
    </table>

  Before this patch, this snippet sent the code into an infinite
  loop.  With this patch, the code terminates.  There is an
  unrelated error that this snippet exposes -- the fostering of
  the entire content in the table tags doesn't get encapsulated
  properly becausing of missing DSR information.  So, this snippet
  doesn't RT yet.  That will be addressed in a different commit.

  As expected, this content is fostered out in the PHP parser as
  well, but the PHP parser doesn't have to deal with RTing these
  buggy wikitext snippets exactly as they were.

* No change in parser test results.

* en:Dogma studio parses and isn't stuck in an infinite loop.

Change-Id: I32f643dbc6ae156726c490fbcf04fd86f44df82e