(Bug 50144) Fixes for escaping of harmful wikitext in template args

* The old code was trying to be too smart but was buggy.

* Fixed a bug in the tokenizer that set tsr on span:NoWiki for
  broken tpl transclusion calls (stray {{, }} and such). This
  span broke the assumption made in DSR computation that tsrs
  for Nowiki nodes dont span the entire range.

  This bug fix is also required to get tpl arg escaping working.

* No change in parser test results.

* Tested on the following snippets (test commands first and output
  below that)
-------------------------------
echo "{{echo|foo}}" | node parse | sed 's/foo/[[ [[ }} {{ bar }} | baz]]/g;' | node parse --html2wt
echo "{{echo|foo}}" | node parse | sed 's/foo/[[ [[ {{ bar }} | baz]]/g;' | node parse --html2wt
echo "{{echo|foo}}" | node parse | sed 's/foo/[[ {{ bar }} | baz]]/g;' | node parse --html2wt
echo "{{echo|foo}}" | node parse | sed 's/"foo"/"
a}}"/g;' | node parse --html2wt
echo "{{echo|foo}}" | node parse | sed 's/"foo"/"{{a<\/s>"/g;' | node parse --html2wt
echo "{{echo|foo}}" | node parse | sed 's/"foo"/"{{a}}<\/s>"/g;' | node parse --html2wt
echo "{{echo|foo}}" | node parse | sed 's/"foo"/"
{{a}}"/g;' | node parse --html2wt
echo "{{echo|http://foo.com/ab}}" | node parse | sed 's/ab/a|b/g;' | node parse --html2wt
echo "{{echo|[http://foo.com/ab ab]}}" | node parse | sed 's/ab/a|b/g;' | node parse --html2wt
-------------------------------
{{echo|<nowiki>[[ [[ </nowiki><nowiki>}}</nowiki> {{ bar }}<nowiki> | baz]]</nowiki>}}
{{echo|<nowiki>[[ </nowiki>[[ {{ bar }} | baz]]}}
{{echo|[[ {{ bar }} | baz]]}}
{{echo|
a<nowiki>}}</nowiki>}}
{{echo|<nowiki>{{</nowiki>a
}}
{{echo|{{a}}
}}
{{echo|
{{a}}}}
{{echo|http://foo.com/a&#124;b}}
{{echo|[http://foo.com/a&#124;b a&#124;b]}}
-------------------------------

Change-Id: I4ed3dea80a1df5acfe038cce5e21a646d5f4194a
Merge "(Bug 50144) Fixes for escaping of harmful wikitext in template args"