Fix dynamic string usage as safe input

Test Plan:
  $ arc lint

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4798
Allow specifying precission in PhutilNumber

Test Plan: New test case.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4818
Use cURL multi interface in HTTPSFuture

Summary:
This violates the contract of `isReady()` which shouldn't block.
My implementation waits for any available handle.
The reason is that cURL doesn't expose the file descriptors for select: http://svn.php.net/viewvc/php/php-src/tags/php_5_4_0/ext/curl/multi.c?view=markup#l193
This will cause waiting for HTTPS future even if non-HTTPS future is already available.
I think that it is not a big deal.

Other solution is to rewrite `FutureIterator` to call Future-specific waiters instead of `Future::waitForSockets()`.

Other solution is to remove `curl_multi_select()` and always busy wait.

Test Plan:
  $futures = array();
  for ($i=0; $i < 5; $i++) {
    $futures[] = new HTTPSFuture('http://www.vrana.cz/sleep.php');
  }

  foreach (Futures($futures) as $future) {
    list(, $content) = $future->resolve();
    echo "$content\n";
  }

Please suggest me how to benchmark it (some Arcanist command?).

Reviewers: vrana, btrahan

Reviewed By: btrahan

CC: aran, Korvin, edward

Maniphest Tasks: T1683

Differential Revision: https://secure.phabricator.com/D2471
Fix Filesystem::executeRemovePath

Summary:
Filesystem::remove() (implemented by executeRemovePath()) was broken for
symlinks to directories because is_dir returns true for symlinks to directories
in php.

Test Plan:
Tested in hphpd that is_dir() returns true for symlinks to directories, and that
unlink() instead of rmdir() will remove them (rmdir() won't remove them).
I haven't tested this code specifically.

Reviewers: epriestley, vrana

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4861
Disable cURL protocols other than HTTP and HTTPS

Summary:
See here for lols:

http://blog.volema.com/curl-rce.html

Although I'm not terribly worried about someone actually building a payload for this and mounting an attack, the underlying behavior is very silly. Shut this class of things down so that we never have to debug `arc` raising FTP errors, if nothing else.

Test Plan: Ran `arc` network commands.

Reviewers: btrahan, vrana, indiefan

Reviewed By: indiefan

CC: indiefan, aran

Differential Revision: https://secure.phabricator.com/D4864
Highlight using XHPAST in parallel

Summary:
We usually try to highlight two files at once in Differential:
https://secure.phabricator.com/diffusion/P/browse/master/src/applications/differential/parser/DifferentialChangesetParser.php;3706ec4879a1250c$602-603

Test Plan:
  $highlighter = new PhutilXHPASTSyntaxHighlighter();
  $futures = array(
    $highlighter->getHighlightFuture(file_get_contents('../src/__phutil_library_map__.php')),
    $highlighter->getHighlightFuture(file_get_contents('../src/__phutil_library_map__.php')),
  );

  Futures($futures)->resolveAll();

Saw drop from 0.424 s to 0.380 s.

Also:

  <?php
  $highlighter = new PhutilXHPASTSyntaxHighlighter();
  $futures = array(
    $highlighter->getHighlightFuture('echo "a";'),
    $highlighter->getHighlightFuture('echo "b";'),
    $highlighter->getHighlightFuture('syntax error'),
    $highlighter->getHighlightFuture('<?php'),
    $highlighter->getHighlightFuture('<?php syntax error'),
  );

  foreach (Futures($futures) as $future) {
    echo $future->resolve()."\n\n\n";
  }

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4874
Move Pygments handling from Phabricator

Summary: Moved from D4875.

Test Plan: None.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4876
Return safe HTML from syntax highlighters

Summary: I wonder what the perf impact of this is.

Test Plan: None yet.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4873
Don't merge consecuitive list blocks

Summary: We've merged them from the initial commit, but it doesn't make much sense to do so. It makes less sense after the introduction of numeric lists.

Test Plan: Unit test.

Reviewers: brennantaylor

Reviewed By: brennantaylor

CC: aran

Differential Revision: https://secure.phabricator.com/D4912
Allow nested arrays in tag rendering

Summary: There's at least one of these in `phutil_tag()`, and tracking them down is a huge pain, and we've made a fair number of affordances for them elsewhere which can be simplified if we just allow them to work properly.

Test Plan: Unit tests. Diff rendering in `phutil_tag` no longer raises warnings over `hsprintf('...%s...', array())`.

Reviewers: vrana

Reviewed By: vrana

CC: aran

Differential Revision: https://secure.phabricator.com/D4940
Fix issue with highlighting multi-line tokens in libphutil

Summary: Broken by D4873, which accidentally discarded newlines.

Test Plan: Added unit test; made it pass.

Reviewers: vrana

Reviewed By: vrana

CC: aran

Differential Revision: https://secure.phabricator.com/D4941
Kill phutil_render_tag()

Test Plan:
  $ arc unit

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4944
Convert Remarkup to safe HTML

Summary: This could be slow but we cache where it matters.

Test Plan:
We have quite good unit tests.
Didn't test this in Phabricator yet (neither in //master// nor //phutil_tag//).

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T2432

Differential Revision: https://secure.phabricator.com/D4918
Provide optional detailed help from workflows

Summary: Acts like "synopsis" but is shown only on detailed help. If you don't want synopsii (sp?), you could just call setHelp() instead of setSynopsis(). Seem reasonable?

Test Plan: Faked some help, ran `x help`, `x help y`.

Reviewers: davidreuss

Reviewed By: davidreuss

CC: aran

Differential Revision: https://secure.phabricator.com/D4950
When there is only one translation variant, always select it

Summary:
Some translation parameters (like HTML strings) don't have variants.

Some languages don't have variants for certain parameters (like English for the sex of a person).

In these cases, don't require translations to provide variants.

Test Plan: Added and ran unit test.

Reviewers: chad, vrana

Reviewed By: chad

CC: aran

Differential Revision: https://secure.phabricator.com/D4985
Fix lock tests under Ubuntu/dash

Summary:
On Ubuntu, the default `sh` is `dash`, which (unlike bash) remains around in the process tree when you run shell commands (see the dozen similar bugs this has caused).

During these tests, we spawn and then kill subprocesses fairly aggressively. With `dash`, the subshell eats the SIGKILL and the grandchild process is left hanging around, holding the lock.

Instead, use `exec` to vanish the intermediate shell process so we can SIGKILL the lock holder directly.

Fixes T2560.

Test Plan:
```
ubuntu@ip-10-170-222-96:/core/libphutil$ uname -a
Linux ip-10-170-222-96 3.0.0-16-virtual #29-Ubuntu SMP Tue Feb 14 13:27:41 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
ubuntu@ip-10-170-222-96:/core/libphutil$ ../arcanist/bin/arc unit src/filesystem/__tests__/PhutilFileLockTestCase.php
   PASS   <1ms★  testLogWriteFailure
   PASS  120ms   testManyWriters
   PASS    5ms★  testLogging
   PASS  146ms   testLockHolding
   PASS    2ms★  testIsLocked
   PASS   <1ms★  testExcessiveUnlock
   PASS  147ms   testUnlockAll
   PASS   <1ms★  testRelock
   PASS   90ms   testLockTesting
   PASS  119ms   testInProcessLocking
   PASS  106ms   testInProcessHolding
```

Reviewers: Afaque_Hussain, chad

Reviewed By: chad

CC: aran

Maniphest Tasks: T2560

Differential Revision: https://secure.phabricator.com/D5008
Apply lint rules to libphutil

Summary: See D5002. Same for libphutil.

Test Plan: `arc unit --everything`

Reviewers: chad

Reviewed By: chad

CC: aran

Differential Revision: https://secure.phabricator.com/D5004
Asserting that data to be written is string like

Summary: Asserting that data to be written is string like.

Test Plan: Passing non string like data to the Filesystem::writefile() function to see if the appropriate error message is displayed

Reviewers: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4995
Refactor MD5 code. Add unit test for FileFinder.

Summary: FileFinder::find() now uses PHP's md5_file() for all MD5 calculations and now has associated unit tests.

Test Plan: Ensure the unit tests pass.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5013
Do not calculate checksums of directories.

Summary: Add a condition to avoid calculating the checksum of a directory and add corresponding unit tests.

Test Plan: Ensure unit tests pass.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

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