Fix a number of link-parsing and serialization issues.

Issues fixed:

* `[[Foo|[http://example.com]]]` is a valid link; the link content is the
literal string `[http://example.com]`; that is, it is not autolinked.
Add code to "delinkify" autolinks inside links, being especially careful
with autonumbered links.

* Properly encode `<>` when present as part of a title.  See the `Link
containing "#<" and "#>"` and `Link containing "<#" and ">#"` parser
test cases.  Note that we do not munge anchor strings; HTML5 allows
all non-space characters in ids (but see bug 57252).

* Split anchor from title correctly, even if there are multiple '#'
characters (bug 63430).  Added an additional parser test for this.

* Improve 'valid title' checking in `MWParserEnvironment#isValidLinkTarget`.
Decode %-escapes so that we can reliably detect bad characters, and ignore
any anchor section since the constraints we're testing apply only to title
characters.  Add a test for "% followed by 2 hexadecimal digits" which is
not allowed in a page title.

* Split off an `autourl` production from the general 'url' production
in the grammar, since the exact character classes recognized in
autolinks differ from the more permissive rules for external link
urls.  In particular single quote and open brace are allowed (bug
49688) and there is no `!(space / eolf)` restriction on `[.:,]` in
external link urls (bug 63947). Document where the characters classes
come from on the PHP side for easier auditing.

* Don't parse illegal entities using the `htmlentity` production.  This
improves our handling of raw ampersands in URLs, etc.

* Similarly to the `url` production tweaks above, improve the
`extlink_preprocessor_text` production to match PHP's `EXT_LINK_URL_CLASS`.
In particular we allow single quotes (see the `External link containing a
single quote. (bug 63947)` test case) and the pipe character (see the
`Images with the "|" character in the comment` test case).

* In WTS, escape urls which are percent-encoded but still not safe for
wikitext -- they are safe for HTML5 but contain characters not in
EXT_LINK_URL_CLASS and so are not yet safe for the PHP parser.  Use a
new `Util.entityEncodeAll` helper, since ordinary html entity encoding
is not guaranteed to escape HTML-safe-but-PHP-unsafe characters.  For
most cases this involved adding a call to `escapeExtLinkURL`, but modified
intrawiki links were previously not being escaped at all; add clauses to
mirror those already present for redirects and simple wiki links.

* In WTS, always entity-encode the contents of a `mw:Entity` span.
Previously, we only entity-encoded the contents if they were not HTML-safe,
which isn't an appropriate test for wikitext.

* Add `html/parsoid` sections to all parser tests using autonumbered links
to account for Parsoid's "empty content" representation of autonumbered links.

New blacklist entries:

* html2wt failures for `encoded ampersand` and `encoded equals` where the
encoding is unnecessarily used inside a URL.  We have no way of marking
<span typeof="mw:Entity"> *inside of an href attribute*.  I left these
as failures (inside of rewriting the test) since we could conceivably add
entity spans in some sort of data-parsoid attribute if we really wanted
clean round-trips here.  (This is not a new failure.)

* Same root cause for html2wt failure in `BUG 337: Escaped self-links
should be bold`: use of entities inside a URL.  In this case it's a
wikilink; we could add <span>s here.  (This is not a new failure.)

* New failure for `IPv6 urls`: we don't support the brackets in IPv6
URLs, and neither does the PHP parser (bug 21261).  In fact, this test
is disabled.  We only passed this test previously because we weren't
properly escaping the brackets in the URL, which are not PHP-safe.

* `Bug 2095: link with pipe and three closing brackets, version 2`:
we're properly parsing this one now, we're just adding `<nowiki>` tags
inside the link label.  Discussed this with subbu, it's likely a
WONTFIX, but in theory we could make our `<nowiki>`ification smarter
to handle this case.  We fail the html2html version as well, because
the `<nowiki>`s add `<span>`s.  (This is not a new failure.)

* `Link containing "#<" and "#>" % as a hex sequences`: we fail html2wt
and html2wt because we prefix the anchor with the current page title.
Not a bug, but perhaps should be fixed in the future.

* `Interwiki links that cannot be represented in wiki syntax` fails html2wt
because we convert underscores to spaces.

* `Parsing an URL`: fails html2wt, this test should probably be rewritten.

There are also a few selser failures.  Some of these are legitimate
issues caused by bug 64300: inserting text before an autolink breaks
the link.

I've also cleaned up the whitelist, rewriting tests where necessary to
add `html/parsoid` clauses and document proper Parsoid output.

Bug: 49688
Bug: 63430
Bug: 63947
Change-Id: If579bff310fd08653f55020c70167929423af5be