Reworked detection of nested and overlapping tpl-ranges.

* In an attempt to be efficient (mainly because of lack of hash
  code on DOM nodes), the old code relied on some brittle assumptions
  about what tpl ranges needed to be checked to detect tpl nesting
  and overlapping.  It relied on sorting of tpl-ranges and comparing
  adjacent pairs for both nesting and overlap.  However, citation
  templates get moved around from their original wikitext source
  position to elsewhere in the DOM which breaks this assumption
  about nesting -- and we dont have a reliable way to sort the
  tpl ranges on tpl-id or tsr-0 values.

* The new code instead effectively compares all ranges against all
  other to see if any is nested inside another.  However, it tries
  to this efficiently (than do a n^2 set of checks each of which
  itself is inefficient if done naively).  The code assigns
  dom-ranges to every node (but only sufficient to do this for the
  top-level nodes of the range).  This is linear-time.  For every
  template, it then walks up to the root to find a node that has
  tpl-ranges assigned to it.  If found, it signals a nesting
  intersection (with some addtl. checks needed to prevent false
  self-nesting hits -- see code for details).

* No change in parser tests.

* Tested following pages:
  - en:Allegations_of_tourist_apartheid_in_Cuba fixed in efe2f968.
  - en:Elvis_68_comeback_special -- regression caused by efe2f968.
  - en:SS_Oxfordshire -- from old commit
  - en:Almirante_Latorre-class_battleship -- from old commit

Change-Id: I5724ad16614d09c68e0abfafbc7ed677874eba12