Fix an issue where closed connections are retained in a zombie state by PHP

Summary:
Argh, this took me like 4 hours to figure out.

After D3035, daemons on secure.phabricator.com are dying after a while with "too many open files". These aren't live MySQL connections (`SHOW FULL PROCESSLIST` shows nothing) but fds that haven't been completely disposed of (TCP connections in CLOSE_WAIT or unix sockets not doing much of anything). This repro'd on OSX and Ubuntu across many different versions of PHP, which I spent hours building since I'm dumb and made a mistake early on which led me to believe that I wasn't seeing it on OSX.

In fact, these connections don't close because we're still holding a reference to the result set (if we've executed any queries on the connection). Throw the result set away when we close a connection.

I missed this in D3035 originally because I inspected `SHOW FULL PROCESSLIST` but didn't consider to inspect `lsof`.

Test Plan: Built a script that does 300 connects, SELECT 1, and then does "lsof | grep getmypid() | wc -l". With the assignment commented out, it reports ~300 file descriptors. With the assignment there, it reports ~0 file descriptors.

Reviewers: btrahan, vrana, nh, dschleimer

Reviewed By: dschleimer

CC: aran

Maniphest Tasks: T1470

Differential Revision: https://secure.phabricator.com/D3071
Move qsprintf() test cases back to phabricator

Summary: We could add stub tests based on an Isolated connection, but Lisk has no clue how to get a real connection in order for mysql_real_escape_string() to work so these tests need to go back to Phabricator.

Test Plan: Liberate / Lint.

Reviewers: nh, btrahan, vrana

Reviewed By: nh

CC: aran

Maniphest Tasks: T1283

Differential Revision: https://secure.phabricator.com/D3073
Add PhutilBufferedIterator

Summary: I'm planning to build object iterators for the ETL pipeline, but we can share most of the code between them and LiskMigrationIterator by creating a primitive.

Test Plan: Unit tests.

Reviewers: vrana, btrahan

Reviewed By: vrana

CC: aran

Maniphest Tasks: T1562

Differential Revision: https://secure.phabricator.com/D3075
Highlight LESS and SCSS as CSS, because it's better than nothing.

Summary:
LESS and SCSS are two stylesheet languages similar in syntax to CSS.
Pygments doesn't directly support them, but I don't think it's unreasonable to
highlight them as CSS by default. They're close enough to CSS that it doesn't
look terrible, and I think they're becoming used enough that it makes sense
to do this by default.

Test Plan:
Viewed a .less, and .scss file under the CSS parser to see if they looked
reasonable.

See P473 (scss) and P474 (less) for samples of them highlighted with css.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3086
Merge pull request #13 from CodeBlock/master

D3086
Fix warning when selecting descendants of a class with no descendants

Summary: If you try to select the descendants of a class that has no children, we currently raise a warning. Handle this condition properly.

Test Plan: Selected descendants of a childless class.

Reviewers: vrana, btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D3097
Send daemon heartbeat, exit status

Summary:
Send a heartbeat via conduit (if possible) for daemons, and when they exit
cleanly, set the status to exited. This is the libphutil part of D3126.

Test Plan: See test plan for D3126.

Reviewers: epriestley, vrana

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3127
Fix an XSS hole in Remarkup link handling, see T1601

Auditors: nh
Document %Ls in `csprintf()`

Test Plan: Read.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3156
Fix an issue where messages may not be processed by PhutilConsoleServer after the client exits

Summary:
When we call update(), it may move messages into the read() buffer but we won't process them right now. Process messages after update().

Also improve the correctness of the flush() implementation.

See D2841.

Test Plan: Ran test script with 4-second linter child, got 4 messages on stdout.

Reviewers: vrana

Reviewed By: vrana

CC: aran

Differential Revision: https://secure.phabricator.com/D3152
Don't use stream_socket_shutdown() in socket channel

Summary: I'm not sure if `fclose()` does everything we need in Zend PHP but this solves all my troubles.

Test Plan:
  $ ./lint_mock.php # with 4 both with and without questions

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3157
Fix an issue where PHP_EOL_COMMENT tokens were discarded on EOF

Summary:
There was no token production rule from state <PHP_EOL_COMMENT> on <<EOF>>.

NOTE: I didn't bump the xhpast version since this is such a minor edge case that it didn't seem worth the trouble.

Test Plan: Unit test now passes with a clean xhpast build.

Reviewers: nh

Reviewed By: nh

CC: aran

Maniphest Tasks: T1599

Differential Revision: https://secure.phabricator.com/D3154
Provide a function for validating translations

Summary:
Based on discussion at T1139#32, we will not provide context to translators.
Thus we should limit the translations to have the same special characters.

This disallows some originals: e.g. 'print <filename>' in text context - one should use 'print <%s>' with `pht('filename')`.
And some translations: e.g. 'me & you' translated as 'me and you'.

We should call this from linter but I don't know how.
We can easily call it from `addTranslations()` in runtime but I'm not sure it's worth the overhead.

Test Plan: New test.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T1139

Differential Revision: https://secure.phabricator.com/D3164
Provide prompt for console server

Test Plan: Used it in `arc diff`.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3167
Split Remarkup rule for document link from hyperlink

Summary:
We have other rules dealing with hyperlinks (`PhabricatorRemarkupRuleProxyImage`) which collides with one rule for hyperlink:

- If we apply proxy image first then it creates `[[ storedText ]]` which builds an invalid link.
- If we apply hyperlink first then there's nothing left for proxy image.

Test Plan: `[[ http://example.com/a.png | a ]]`

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3191
Add API for getting ANSI status
Allow redirecting output in console

Summary: This will allow us using plain `echo`, `passthru()` and such with console clients.

Test Plan: Called it from console client together with echo.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3208
Add context support to PHP highlighter

Summary:
 - Detect x::y, and mark y as an attribute with context x.
 - Export found contexts as a data attribute.

Test Plan: Load Diffusion. Examine DOM and click on things.

Reviewers: epriestley

Reviewed By: epriestley

CC: nh, aran, Korvin

Maniphest Tasks: T1602

Differential Revision: https://secure.phabricator.com/D3214
Make XHPASTSyntaxHighlighter more robust

Summary:
 - Also store symbol name as a DOM attribute, to allow cases where the
   symbol name isn't simply the text content of the `<span>`.
 - Check for interesting symbols first, to allow cases where the symbol
   doesn't have type T_STRING.

These changes support new features internal to Facebook, though they
also seem worthwhile in their own right.

Test Plan: Browse Diffusion. Examine DOM.

Reviewers: epriestley

Reviewed By: epriestley

CC: nh, aran, Korvin

Maniphest Tasks: T1602

Differential Revision: https://secure.phabricator.com/D3226
Support self::$foo case

Summary: See T1602#15.

Test Plan: Browse Diffusion. Click on things.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T1602

Differential Revision: https://secure.phabricator.com/D3237