Make libphutil compatible with utf8mb4

Summary:
Ref T1191. Two changes here:

  - Try to use the `utf8mb4` character set. Fall back to `utf8` if it's not available. This may be slightly worse for old MySQL, but is far, far easier than trying to keeep a cache around somewhere with availability information.
  - Prepare to transition to `utf8mb4`. I'm just going to switch this over in the future. I considered trying to save the migration state in the environment somewhere, but it gets really, really messy because we have to inspect the migration state in order to build a connection object. There's also no advantage in the overwhelming majority of cases. We can do something more messy here eventually if it ends up being more complicated than I think.

Test Plan: Wrote comments full of emoji locally.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T1191

Differential Revision: https://secure.phabricator.com/D10604
Quiet utf8mb4 warnings when establish MySQL connections

Summary: Fixes T6228. Ref T1191. Some versions of things spew warnings on these calls; I can't reproduce it locally but @fabe reports this resolving it for him in T6228.

Test Plan: Still works fine locally, but no surprises there.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: fabe, epriestley

Maniphest Tasks: T1191, T6228

Differential Revision: https://secure.phabricator.com/D10623
Use normal human units, not "correct" SI units, when parsing MB/GB etc

Summary:
Technically, "KB" is "kilobyte" which is 1000 bytes, and "KiB" is "kibibyte" which is 1024 bytes. I implemented this function "correctly", but in practice we mostly use it to parse things from `php.ini`, `mysql.cnf`, etc., which all use units of 1024 intead of 1000. This ends up being really confusing because you write `128M` in a file (technicall meaning "128 mebibytes") and then a setup warning says `137M` (tehcnically meaning "137 megabytes").

Use the standard normal units that everyone and everything uses instead of the "correct" units. If we have some cause for the "real" SI units later we can mess with this stuff when we hit that.

Test Plan: Saw the setup check in D10630 actually report what I wrote in the file instead of a weird SI value.

Reviewers: btrahan, chad

Reviewed By: chad

Subscribers: epriestley

Differential Revision: https://secure.phabricator.com/D10631
Set autoload to false on CURLFile in HTTPSFuture

Summary: Fixes T6264, I assume this is correct after grepping through the codebase.

Test Plan: Reload in sandbox, eyeball text, not sure what else to do.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T6264

Differential Revision: https://secure.phabricator.com/D10650
Support arbitrary start numbers for ordered lists in remarkup

Summary: Fixes T6377.

Test Plan: Unit tests, mostly. Also checked a local install to see if this felt sensible.

Reviewers: Thirtyate, epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Maniphest Tasks: T6377

Differential Revision: https://secure.phabricator.com/D10742
Remove history support for console prompts on Windows

Summary: Fixes T6348.

Test Plan: Run `arc diff --nolint --nounit` and see the expected prompt, instead of just one word.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T6348

Differential Revision: https://secure.phabricator.com/D10743
Assume utf8mb4 support

Summary:
Ref T1191. This stops throwing an exception for non-BMP data when constructing queries.

  - For installs which have already adjusted, this allows emoji and other 4-byte characters to work.
  - For installs which have not adjusted yet but do have STRICT_ALL_TABLES set, MySQL will raise an error intead ("Incorrect string value...").
  - For installs which have not adjusted and also do not use STRICT_ALL_TABLES, this will silently truncate data. This is potentially a security risk. However, these installs are warned about the risk of leaving STRICT_ALL_TABLES disabled, there's no known way to exploit this issue, and they'll be auto-adjusted soon.

Test Plan: Ran locally and on secure.phabricator.com with this patch for a long time.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T1191

Differential Revision: https://secure.phabricator.com/D10798
Allow Conduit requests to be signed with a public/private keypair

Summary:
This allows callers (in the future, servers in a cluster or instances) to sign Conduit requests with an asymmetric keypair instead of a certificate or token.

Overall we could get away without this, but it seems worth doing for a few reasons:

  - By binding Device identity to SSH keys, we can also authorize them over (real) SSH easily, and not need separate conduit / SSH keys.
  - Asymmetric key cryptography is strong and well understood, and we never have to share or transmit private keys.
  - This is potentially useful to third parties for device identity, in a way that custom Conduit stuff wouldn't be.

Test Plan:
  - Added unit tests.
  - Will actually test once I mess with the other half of this.

Reviewers: hach-que, #blessed_reviewers, btrahan

Reviewed By: #blessed_reviewers, btrahan

Subscribers: epriestley, Korvin

Maniphest Tasks: T6240

Differential Revision: https://secure.phabricator.com/D10402
Process Remarkup in text and HTML email bodies appropriately

Summary: Ref T2617, adding inline styles to handle html email objects

Test Plan: Add code block to a Maniphest comment. Email should show pretty yellow background for code block.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Maniphest Tasks: T2617

Differential Revision: https://secure.phabricator.com/D10860
Disallow `[1]` from being interpreted as a marked checkbox in remarkup

Summary: Fixes T6640. `[1]` and similar are more likely footnotes than checkmarks.

Test Plan: {F241922}

Reviewers: btrahan, chad

Reviewed By: chad

Subscribers: epriestley

Maniphest Tasks: T6640

Differential Revision: https://secure.phabricator.com/D10913
Minor linter fix

Summary: Self-explanatory

Test Plan: `arc lint`

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Differential Revision: https://secure.phabricator.com/D10942
Support an explicit connection timeout parameter for database connections

Summary:
Ref T6238. On the instance management interface, I want to check if an instance's database is reachable by connecting to it.

If it isn't, we hang for 30-60 seconds (default connection timeout). Allow explicit specification of a timeout when establishing a connection instead.

This only does MySQLi, not MySQL. We don't need MySQL for now, although it would be nice to support it eventually (Ref T6710).

Test Plan:
  - Browsed around.
  - Used short timeouts to get instance database status in instance management.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T6238, T6710

Differential Revision: https://secure.phabricator.com/D10944
Allow ConduitClient to specify an explicit Host

Summary:
Ref T2783. To query a repository, we want to connect to a node which hosts it, but also connect using the correct instance hostname.

Allow `ConduitClient` to specify an explicit hostname.

Test Plan:
Used a script like this to verify that `setHost()` is impactful:

```
<?php

require_once 'scripts/__init_script__.php';

$response = id(new ConduitClient('http://127.0.0.1/'))
  ->setHost('local.phacility.com')
  ->callMethodSynchronous('conduit.ping', array());

var_dump($response);
```

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T2783

Differential Revision: https://secure.phabricator.com/D10960
Use more liberal whitespae detection for `%%%` and `---` remarkup rules

Summary: This relaxes detection of whitespace for literal blocks and horizontal lines. In particular, when these rules are quoted, they appear as, e.g., `> ---`, which currently does not show a quoted horizontal line.

Test Plan: Added and ran unit tests. Quoted literal and HR rules.

Reviewers: chad, btrahan

Reviewed By: btrahan

Subscribers: epriestley

Differential Revision: https://secure.phabricator.com/D10972
Preserve whitespace more faithfully when processing %%% remarkup blocks

Summary:
This improves the output for some edge cases with `%%%` blocks. Notably, blocks did not emit a block-level spacing tag, so this:

```
%%%a%%%
%%%b%%%
```

...rendered on a single line.

Test Plan:
Added unit tests.

{F249620}

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: chasemp, epriestley

Differential Revision: https://secure.phabricator.com/D10984
Support Conduit tokens in ConduitClient

Summary: Ref T5955. Allow ConduitClient to use simple token-based authentication.

Test Plan:
```
$ cat conduit.php
<?php

require_once 'scripts/__init_script__.php';

$args = new PhutilArgumentParser($argv);
$args->parseStandardArguments();

$result = id(new ConduitClient('http://local.phacility.com'))
  ->setConduitToken('api-6br7udiaydzjxorsr4ooggtzissh')
  ->callMethodSynchronous('user.whoami', array());

var_dump($result);
$ php -f conduit.php -- --trace
>>> [0] <conduit> user.whoami() <bytes = 117>
>>> [1] <http> http://local.phacility.com/api/user.whoami
<<< [1] <http> 216,804 us
<<< [0] <conduit> 217,307 us
array(6) {
  ["phid"]=>
  string(30) "PHID-USER-cvfydnwadpdj7vdon36z"
  ["userName"]=>
  string(5) "admin"
  ["realName"]=>
  string(4) "asdf"
  ["image"]=>
  string(85) "http://local.phacility.com/res/1410737307T/phabricator/3eb28cd9/rsrc/image/avatar.png"
  ["uri"]=>
  string(35) "http://local.phacility.com/p/admin/"
  ["roles"]=>
  array(4) {
    [0]=>
    string(5) "admin"
    [1]=>
    string(8) "verified"
    [2]=>
    string(8) "approved"
    [3]=>
    string(9) "activated"
  }
}
```

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T5955

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