Split PhutilFileLock into PhutilLock and PhutilFileLock

Summary: I think I have a reasonable way to do global locks, which are better for the intended use case, but they can share some code with the file locks.

Test Plan: Ran unit tests.

Reviewers: nh, jungejason, vrana

Reviewed By: vrana

CC: aran

Maniphest Tasks: T1400

Differential Revision: https://secure.phabricator.com/D2862
Remove 'Module' from docs caption

Test Plan: None.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D2869
Allow specifying custom syntax highlighter in Remarkup

Test Plan: Specified it and verified that it has been used by calling `phlog()`.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D2873
Minor, add a test script for phutil_console_prompt().
Fix phutil_console_prompt() under Ubuntu

Summary:
In Ubuntu, `sh` is `dash`. It doesn't support `read -e`, but when we run `echo $BASH 2>/dev/null` it returns "\n", which is true, so we try to run `read -e` anyway.

Instead, do an explicit test for the availability of bash, and use it if it's available.

Test Plan: Ran `scripts/test/prompt.php --history /tmp/h` on Ubuntu and got readline instead of an exception about `read -e` being illegal.

Reviewers: vrana

Reviewed By: vrana

CC: aran

Maniphest Tasks: T1302

Differential Revision: https://secure.phabricator.com/D2879
Add <table> syntax to Remarkup

Summary:
Adds basic table syntax. I went with just HTML table syntax since it's straightforward and familiar and all the other syntaxes (in mediawiki, trac, etc) seem awful.

It's safe to do this since we parse the talbe markup itself very strictly, and don't actually use the tags the user types.

Test Plan: {F13683}

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D2902
Simpler version of D2910

Summary: Simpler? Yes? Also utf8-aware! Tests from D2910 pass.

Test Plan: Unit tests.

Reviewers: nh

Reviewed By: nh

CC: aran

Differential Revision: https://secure.phabricator.com/D2914
Add a JSONProtocolChannel to libphutil

Summary: This lets us build a test client for Aphlict from the CLI, to make it a little easier to debug stuff.

Test Plan: Ran unit tests. Built an Aphlict CLI client.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D2926
Show event dispatch in the ServiceProfiler

Summary: This makes scripts much easier to debug with --trace, in particular. Also fix the old 'flock' name (now 'lock').

Test Plan: Ran `emit_test_event.php --trace`.

Reviewers: btrahan, jungejason

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1092

Differential Revision: https://secure.phabricator.com/D2918
Allow PhutilLocks to block

Summary: There are a couple of operations where I want to use locks now that we have a primitive, but when they're on web workflows we should block and wait for the lock. Allow locks to block.

Test Plan: Ran unit tests, "lock.php" with --wait, verified CPU usage for blocking processes is negligible, verified blocking processes acquire locks when they're released.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D2924
Return $this from lock() and unlock()

Summary: This simplifies establishing multiple locks since you don't need to use temp vars.

Test Plan: Trivial / unit tests.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1162

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