Allow caller to set a "preferred" editor for PhutilInteractiveEditor

Summary: The main use case for this is supporting an 'editor' configuration in arc. A fair number of users are unfamiliar with EDITOR or with environmental variables in general, and setting them on Windows is a particular pain. Instead, allow arc to have an editor config so we can simplify instructions for "how to set up editors".

Test Plan: Added arc support for this, called `arc set-config editor 'mate -w'`, ran 'arc diff', got textmate instead of nano.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1309

Differential Revision: https://secure.phabricator.com/D2955
Fix some Windows EDITOR issues

Summary:
See D2955, D2956. Fix some more issues:

  - We're escaping in a way that makes it easier to specify EDITOR but prevents you from specifying flags.
  - Catch complete proc_open() failures and fail less mysteriously.
  - Don't use +line on Windows since it doesn't work with most editors.

Test Plan: Created this diff on Windows.

Reviewers: btrahan, jungejason

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1309

Differential Revision: https://secure.phabricator.com/D2957
Add an "OpaqueEnvelope" for passing passwords around

Summary: See T1526. To prevent passwords from appearing in logs and traces, provide an object which can wrap them up.

Test Plan: Ran unit tests.

Reviewers: vrana, btrahan

Reviewed By: vrana

CC: aran

Maniphest Tasks: T1526

Differential Revision: https://secure.phabricator.com/D2991
Minor, explain secret splitting in opaque envelope test case.

Auditors: vrana
Add ldap_sprintf() for LDAP escaping

Summary: We have some minor issues with LDAP escaping now. I think they're not security problems (they will only cause us to reject valid inputs) but add an xsprintf()-family function to fix them.

Test Plan: Did LDAP login with names like ",", got the expected errors ("bad username") instead of suspicious errors ("invalid syntax").

Reviewers: vrana, btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D2994
Fix various TempFile issues

Summary:
This class is a mess, I think it hasn't been touched since it came out of FB.

  - $dir parameter to constructor does nothing.
  - preserve() does nothing.
  - Fix documentation.
  - Use more Filesystem.

Test Plan: Used setPreserveFile() in a future diff.

Reviewers: btrahan, vrana

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D2996
Add PhutilGitURI for parsing scp-style Git URIs

Summary:
See T1529.

We currently convert "scp-style" URIs into normal URIs in Phabricator:

  git@host:path -> ssh://git@host/path

This isn't correct; paths in the scp-style URIs are resolved relatively, while paths in the normal-style URIs are resolved absolutely.

Since we can't do this transformation any more, add a real parser so we can replace the transformation code in Phabricator with something sensible.

Test Plan: Unit test coverage.

Reviewers: btrahan, vrana

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1529

Differential Revision: https://secure.phabricator.com/D3033
Remove "remote_hooks_installed" from libphutil/.arcconfig

Summary: See D967.

Test Plan: Looked.

Reviewers: vrana

Reviewed By: vrana

CC: aran

Differential Revision: https://secure.phabricator.com/D3049
Move AphrontWriteGuard to libphutil

Summary: Toward a queryfx() in libphutil and general separation of Aphront from Phabricator.

Test Plan: Loaded some pages which use write guard.

Reviewers: btrahan, vrana

Reviewed By: vrana

CC: aran

Maniphest Tasks: T1283

Differential Revision: https://secure.phabricator.com/D3051
Move AphrontConnection to libphutil

Summary: Move AphrontConnection and related classes to libphutil so we can move queryfx() here.

Test Plan: lint / loaded pages.

Reviewers: vrana, btrahan

Reviewed By: vrana

CC: aran

Maniphest Tasks: T1283

Differential Revision: https://secure.phabricator.com/D3055
Move querfyx() to libphutil

Summary: See recent diffs.

Test Plan: Loaded site.

Reviewers: vrana, btrahan

Reviewed By: vrana

CC: aran

Maniphest Tasks: T1283

Differential Revision: https://secure.phabricator.com/D3057
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