Read only stdout in LinesOfALargeExecFuture

Summary:
We read all the output before throwing so stderr is empty.
I hit this issue in D5738.

Test Plan: Searched for invalid regexp in D5738.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5767
Add a convenience method for instantiating concrete subclasses of some abstract ancestor

Summary: This pattern occurs fairly often in Phabricator; add a helper method.

Test Plan: Used in D5756.

Reviewers: btrahan, vrana

Reviewed By: vrana

CC: aran

Differential Revision: https://secure.phabricator.com/D5757
Parse hosts more strictly in `PhutilURI`

Summary: See some discussion in D5726.

Test Plan: Added new, passing test.

Reviewers: wez, btrahan

Reviewed By: wez

CC: aran

Differential Revision: https://secure.phabricator.com/D5797
Allow named links inside simple tables in Remarkup

Summary:
Fixes T3064. Currently, the simple table syntax sees the `|` in the middle of a named link as a cell divider.

Special-case this since I don't have a clean way of fixing it otherwise, but it seems reasonable to fix it.

Test Plan:
Added a passing test.

{F41831}

Reviewers: vrana, btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3064

Differential Revision: https://secure.phabricator.com/D5798
Implement very basic PayPal API wrapper

Summary:
Ref T2787. The [[ https://github.com/paypal/merchant-sdk-php | official PayPal PHP SDK ]]:

  - ...is 27,000+ lines long!
  - ...is all generated code!
  - ...contains a non-ironic `PayPalAPIInterfaceServiceService` class as its primary interface!
  - ...uses SOAP!
  - ...is completely broken (literally missing most of the classes it needs to run)!

Instead, provide a minimal wrapper for the guts. The actual API is reasonable and there's a name-value pair flavor available.

I'm using this to implement the "Express Checkout" workflow in Phortune.

Test Plan: Made PayPal API calls using the test script.

Reviewers: btrahan, chad

Reviewed By: chad

CC: aran

Maniphest Tasks: T2787

Differential Revision: https://secure.phabricator.com/D5808
Remarkup: Allow Odd Line Breaks Before Blocks

Summary: If there are two or more consecutive line breaks (i.e. at least one empty line), the first non-empty line should be considered the first line of the block. Currently, that is not the case if there are an odd number of line breaks because the last empty line will be considered the first line of the block. This breaks things like HTML tables (which assumes the block starts with `<table>`), code blocks (which special cases the first line if it is `lang=something`), etc.

Test Plan: Ran unit tests successfully.

Reviewers: epriestley, vrana

Reviewed By: epriestley

CC: leebyron, aran, Korvin, keito

Differential Revision: https://secure.phabricator.com/D5814
Process Markdown-style headers in Remarkup

Summary:
Markdown supports a header style where headers are underlined with `=` or `-`. Support this in Remarkup as well.

I made this the text target rendering style too, since I think it looks a little nicer. Ref T2849.

Test Plan:
Added a bunch of unit tests.

{F42635}

Reviewers: btrahan, jevripio

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2849

Differential Revision: https://secure.phabricator.com/D5854
Parse most `[name](href)` Markdown-style links in Remarkup

Summary: Markdown has `[name](href)`-style links which we currently don't parse because they can occur naturally in discussions of source code (instead, we support Mediawiki-style links). Apply a few heuristics to reject likely accidental matches and support reasonable forms of this style. Ref T2849.

Test Plan: Added unit tests.

Reviewers: btrahan, jevripio

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2849

Differential Revision: https://secure.phabricator.com/D5857
Allow PhutilDeferredLog to fail more quietly

Summary:
We've hit a couple of issues with the exception PhutilDeferredLog throws when used in the Phabricator access log. In particular, it is thrown at an awkward time, when the request is already complete. It is also thrown from an awkward place in the stack, where we've already unwound everything and are calling `__destruct()`. It also isn't especially important.

Allow it to be degraded into a log message instead. The next diff will apply this degradation in Phabricator.

Test Plan: Unit tests; see next revision.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3144

Differential Revision: https://secure.phabricator.com/D5874
Allow comments in multi queries

Test Plan:
  print_r($conn->executeRawQueries(array(
    "SELECT 1 -- comment",
    "SELECT 2",
  )));

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5884
Re-execute multi-queries if some query fails

Summary:
If some query fails, all next queries are not accessible.

Also don't report correct queries not returning results as errors.

Test Plan:
  print_r(array_map('gettype', $conn->executeRawQueries(array(
    "SELECT 1",
    "DO",
    "DO SLEEP(5)",
  ))));
  // And other permutations.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5900
Put a sigil on remarkip-code-block in PhutilRemarkupEngineRemarkupCodeBlockRule

Summary: Also modified few test cases.

Test Plan: I made the necessary changes, differential is loading diffs as usual. Let me know if I have done it correctly.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin, AnhNhan

Maniphest Tasks: T3007

Differential Revision: https://secure.phabricator.com/D5888
Add missing parameter to strncasecmp()

Summary:
strncasecmp() takes 3 parameters, not 2. This worked in the general case because we usually do not set any headers, so we don't enter this comparison block. However, now that we set `User-Agent` from OAuth it is complaining in the logs.

  [13-May-2013 16:51:28] WARNING: [pool www] child 28977 said into stderr: "NOTICE: PHP message: [2013-05-13 16:51:28] ERROR 2: strncasecmp() expects exactly 3 parameters, 2 given at [/core/libphutil/src/future/http/HTTPSFuture.php:172]"
  [13-May-2013 16:51:28] WARNING: [pool www] child 28977 said into stderr: "NOTICE: PHP message:   #0 strncasecmp(User-Agent, Expect) called at [/core/libphutil/src/future/http/HTTPSFuture.php:172]"
  [13-May-2013 16:51:28] WARNING: [pool www] child 28977 said into stderr: "NOTICE: PHP message:   #1 HTTPSFuture::isReady() called at [/core/libphutil/src/future/Future.php:40]"
  [13-May-2013 16:51:28] WARNING: [pool www] child 28977 said into stderr: "NOTICE: PHP message:   #2 Future::resolve() called at [/core/libphutil/src/future/http/BaseHTTPFuture.php:231]"
  [13-May-2013 16:51:28] WARNING: [pool www] child 28977 said into stderr: "NOTICE: PHP message:   #3 BaseHTTPFuture::resolvex() called at [/core/phabricator/src/applications/auth/controller/PhabricatorOAuthLoginController.php:55]"
  [13-May-2013 16:51:28] WARNING: [pool www] child 28977 said into stderr: "NOTICE: PHP message:   #4 PhabricatorOAuthLoginController::processRequest() called at [/core/phabricator/webroot/index.php:84]"

Test Plan: Verified strncasecmp() behavior.

Reviewers: btrahan, chad

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D5917
Fix `[x]` in simple table markup

Summary:
This `*` should be a `+` since we want to match //something//.

Fixes `[x]` in a simple table, for any `x` which is not a link.

Test Plan: Added unit test, made it pass.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D5934
Move PhutilArray constructor one level up

Summary: PHP allows changing constructor signature so I see no reason why constructor shouldn't be directly in `PhutilArray`.

Test Plan: Unit tests.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5935
Fix calculation of spritesheet hashes to use relative paths

Summary:
When a user generates sprites, we hash all the inputs to figure out what we actually need to regenerate. Normally (i.e., on my machine), this works fine.

However, part of the hash is the absolute path of all the input images, so my machine hashes in `/Users/epriestley/phabricator/path/to/sprite.png`, and then @chad regens them and gets a hash of `/Users/notchad/phabricator/path/to/sprite.png` instead, or whatever. The hash comes out different so every manifest and sheet gets regenerated.

Instead, hash the //relative// path -- e.g., `path/to/sprite.png`. This keeps the path the same across machines and means that only sprites which have actually changed will regenerate.

See also next diff.

Test Plan:
  - Before this patch: generated sprites in `phabricator/`, then moved `phabricator/` to `phabricator2/` and regenerated. Incorrectly, all sprites were regenerated.  - After this patch: generated sprites in `phabricator/`, then moved `phabricator/` to `phabricator2/` and regenerated. Nothing was regenerated.

Reviewers: chad, btrahan

Reviewed By: chad

CC: aran

Differential Revision: https://secure.phabricator.com/D5964
Add Filesystem::binaryExists()

Summary:
We use `which x` in various places; provide a wrapper which we might some day make work on Windows.

The motivation for this is twofold:

  - I want to commandeer D5670, which will involve another `which`. `which` is yuck.
  - Users hit issues with `svn`, `git`, etc., fairly often. It would be good to do a check after hitting an error in PhabricatorRepository so we can raise a very specific error message about "you do not have git in your webserver path, here is how to fix that".

Test Plan: Ummm... will use in next diff?

Reviewers: btrahan, vrana

Reviewed By: vrana

CC: aran

Differential Revision: https://secure.phabricator.com/D5968
Improve behavior of named anchor links

Summary: Fixes T3220. We currently don't handle `[[ #anchor ]]` very well in remarkup.

Test Plan:
Unit tests.

{F43706}

Reviewers: btrahan, chad

Reviewed By: chad

CC: aran

Maniphest Tasks: T3220

Differential Revision: https://secure.phabricator.com/D5974
Implemented phutil_utf8_is_combining_character().

Summary: Implemented phutil_utf8_is_combining_character(), which returns true if an input character is a combining character.

Test Plan: Unit test: testUTF8IsCombiningCharacter().

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin, AnhNhan

Maniphest Tasks: T2379

Differential Revision: https://secure.phabricator.com/D5981
Implemented phutil_utf8_combined().

Summary: A function which splits a given UTF-8 string into an array of characters without splitting the combined characters.

Test Plan: Unit tests.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin, AnhNhan

Maniphest Tasks: T2379

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