Add final newline to Remarkup tests

Test Plan:
  $ arc unit

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3885
Fix undefined index in console syntax highlighter
Allow filtering iterator results

Summary: See D3940 for usage.

Test Plan: New test.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3944
Allow chunking iterator results

Summary:
I'll use it in `save_lint.php`.
It could also return iterators but this is fine for me.

Test Plan: New test.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3945
Statically link xhpast.exe

Summary:
Some users reported that this virus doesn't always work.
Re-compiled by adding `-static` to `xhpast` in `Makefile`.

Test Plan:
Renamed MinGW directory which previously triggered the problem. Then:

  $ xhpast.exe < xhpast_parse.php
  {"tree":[9000, 0, 291, [...]]}

Reviewers: epriestley, btrahan

Reviewed By: btrahan

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3950
Add PhutilKeyValueCache and some implementations

Summary:
This is basically a slightly-more-abstract version of Facebook's cache stack, without any of the cachekey callbacks (in SocialBB, I implemented something similar above this).

  - `PhutilKeyValueCache` defines an abstract key-value cache interface with get/set/delete operations.
  - `PhutilKeyValueCacheStack` allows you to compose several caches so they behave like a single cache with readthrough semantics (like request -> APC -> Memcache at Facebook).

Then there are cache implementations:

  - `PhutilKeyValueCacheAPC` implements an APC-based cache.
  - `PhutilKeyValueCacheMemcache` implements a memcache-backed cache.
  - `PhutilKeyValueCacheInRequest` is like Facebook's $GLOBALS['CACHE'] (i.e., kind of a bad idea).
  - `PhutilKeyValueCacheOnDisk` implements a disk-based cache. With clever use of `getmypid()` / `posix_getppid()` and such we can reasonably fake something like APC for non-APC installs.

Test Plan: Ran unit tests. This is a slightly modified version of code that worked correctly in SocialBB.

Reviewers: btrahan, vrana

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2062

Differential Revision: https://secure.phabricator.com/D3974
Print request size when debugging Conduit calls

Summary:
See https://github.com/facebook/phabricator/issues/233

This is hopefully of general use when debugging the various crazy request size bugs we hit.

Test Plan: Ran `arc diff --trace`, saw request sizes.

Reviewers: btrahan, vrana

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D3980
Clean up Key-Value Cache diff

Summary:
Feedback from D3974.

  - Make $profiler private and provide getProfiler().
  - Document `PhutilKeyValueCache`.
  - Document `$ttl`.
  - Move `$ttl` from `getKey()` signature to `setNextTTL($ttl)` on `PhutilKeyValueCacheStack`.
  - Make return values for kvimpl methods more consistent.
  - Fix `apc_clear_cache()` -> `apc_clear_cache('user')`.
  - Test for invalid memcache TTL.
  - Document memcache server specification.
  - Use `PhutilFileLock` to control access to the cachefile in `PhutilKeyValueCacheOnDisk`.
  - Write the new disk cache to the same place as the old disk cache. The write is now protected by a lock.
  - Document `PhutilKeyValueCacheStack->setCaches()`.
  - Remove redundant method definitions in `PhutilKeyValueCacheStack`.
  - Unrelated, update documentation of PhutilFileLock.

Test Plan: Ran unit tests. Ran slow TTL unit tests.

Reviewers: vrana, btrahan

Reviewed By: vrana

CC: aran

Maniphest Tasks: T2062

Differential Revision: https://secure.phabricator.com/D3978
Mark memcache_pconnect as an external function for static analysis

Summary:
If you don't have the memcache extension installed, this function won't exist.

We have only one callsite from the extension and are unlikely (probably?) to accumulate more, so just external it rather than whitelisting the whole extension in arc.

Test Plan: idk shrugz~

Reviewers: btrahan, vrana

Reviewed By: vrana

CC: aran

Differential Revision: https://secure.phabricator.com/D3989
Allow formatting numbers in translations

Summary: This is actually not that simple - some languages group hundreds instead of thousands, some group also decimals.

Test Plan: New unit test, next diff.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T1139

Differential Revision: https://secure.phabricator.com/D3960
Fix some libphutil lint warnings

Summary:
This is most of the trivial ones.

  - Fix some whitespace stuff.
  - Fix some very old unconventional test names.

Test Plan: Lint.

Reviewers: vrana

Reviewed By: vrana

CC: aran

Differential Revision: https://secure.phabricator.com/D4017
Give SSL a better fallback path in HTTPSFuture.

Summary:
This patch provides a better fallback path for SSL certificates in libphutil.
The path now works like this:
- See if a certificate has been set externally (e.g. by arcanist -- I'll get to
  this in a minute).
- See if a custom.pem exists. This provides another "local" option before we ask
  the system for a global option.
- Ask php if curl.cainfo is set, and use that.
- Lastly, fall back to default.pem, which ships with libphutil.

As for setting the certificate externally -- I'd like to (next) patch Arcanist
to accept an "ssl_cert" key in .arcrc, for specific hosts, and use it if it
exists. The ssl cert there will be the full certificate. It prevents the user
from having to maintain bundles of certs themselves. It also allows for saner
fallback -- e.g. if I use arc for both secure.phabricator.com and my own
instance with a custom cert -- previously Phabricator would try to use
`custom.pem` for both. This patch provides a //way// to fix that issue, and a
patch to Arcanist will provide the actual fix.

Test Plan:
Lots of stuff. :)

- Threw a custom.pem in `libphutil/resources/ssl`, and it tried to use it.
- Added a `curl.cainfo` and saw that it wasn't used (custom.pem takes
  precedence).
- Moved the custom.pem out of the way, and saw that `curl.cainfo` was now used.
- Removed `curl.cainfo` and saw it fall back to default.pem.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3953
Add ppull method to utils.

Create ppull method in utils.php. This method is identical to mpull
except that it accesses object properties instead of object methods.
Generate squareish sprite sheets

Summary: Generate less-cumbersome sheets that are mostly square.

Test Plan: {F24969}

Reviewers: chad

Reviewed By: chad

CC: aran

Maniphest Tasks: T2013

Differential Revision: https://secure.phabricator.com/D4024
Support 2x sheets in sprite tool

Summary: Add support for retina derpsplays

Test Plan:
1x:

{F24971}

2x:

{F24972}

Reviewers: chad

Reviewed By: chad

CC: aran

Maniphest Tasks: T2013

Differential Revision: https://secure.phabricator.com/D4025
Update src/markup/engine/remarkup/blockrule/PhutilRemarkupEngineRemarkupHeaderBlockRule.php

https://secure.phabricator.com/D4043 -- ghetto style.
Add dirty detection and fix a bug in SpriteSheet

Summary:
  - I had some W vs H mixed up, fix that.
  - Allow sheets to detect when they need to be regenerated (any source file, rule, dimension, or position has changed) so we don't need to do extra work.

Test Plan: Generated sheets with non-square icons without hitting layout bugs. Ran sprite generation and saw only dirty sheets be picked up for regen.

Reviewers: chad

Reviewed By: chad

CC: aran

Differential Revision: https://secure.phabricator.com/D4031
Display URI in HTTP profiler

Test Plan:
  $ echo '{}' | arc call-conduit 'user.whoami' --trace

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4040
Add a case-sensitive mode to PhutilSimpleOptions

Summary: This is for fixing the strtolower() nonsense in Drydock.

Test Plan: Ran unit tests, grepped for PhutilSimpleOptions

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2015

Differential Revision: https://secure.phabricator.com/D4047
Revert SSL version back to automatic detection

Summary:
See discussion in T2132. In D3767 I forced this to "3" to fix some problems users had reported [[https://github.com/facebook/libphutil/issues/17 | here]]. However, users are now reporting problems with it being set to 3. After some more digging, I think the "3" camp is in the wrong, and possibly affected by an issue in libssl:

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=666051
http://rt.openssl.org/Ticket/Display.html?id=2771&user=guest&pass=guest

In particular, the value of "1" for this field means TLSv1, which, unintuitively, is a **newer** protocol than a "3" value for this field to indicate SSLv3.

So, revert D3767 -- I'll push back on the v3 crowd. I can't reproduce any of this, but I have `OpenSSL 0.9.8r 8 Feb 2011` and am not thrilled about spending all day building libssl versions until we get a more useful report.

Also improve the HTTP/S future test script slightly.

Test Plan: :(

Reviewers: vrana, btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2132

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