More accurate detection of auto-inserted end-tags.

* Consider this test case (extracted from
   en/Bolton Wanderers F.C. season 2008-09)
---------------------
{{Fb_kit_header |su=[[Reebok]] |sp=[[Reebok]]}}
{| style="border: 0px;"
|foo
|}
---------------------

  Fb_kit_header opens a table which is not closed before
  a new table is opened.  So, the tree builder auto-closes the
  open table.  Since this table was opened in a template, the
  previous code didn't run builder-inserted-tag-detection on
  the table tag even though the end tag was closed outside the
  template.  This then threw DSR algorithm for a loop which
  assumed that the table came from the top-level and caused
  an off-by-2 error ("|}") which the affected RT-ing.

* This patch figures out when an end-tag comes from top-level
  content (even if the open-tag comes from a template) and
  runs builder-inserted-tag-detection on the end-tag which
  fixes RTing of this snippet (and the page from which this
  snippet was extracted).

* No change in parser tests (TODO: add new parser tests).

Change-Id: I853b2fd3ebdbf593540ef809f9176d2a7f0fb8b1