Fix xhpast Makefile for parallel builds

See: https://github.com/facebook/libphutil/issues/29
Allow PhutilTypeSpec to validate regular expressions

Summary: Adds a `regex` type to PhutilTypeSpec.

Test Plan: Unit tests; triggered the exception manually and read it to make sure it made sense.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D6855
Expand libphutil support for Twitter as an auth provider

Summary:
Ref T3687. Companion to the next diff, which adds the Phabricator half of this. Twitter is an easier OAuth1 proivder to implement and get a sanity check from, on the road to JIRA. Broadly:

  - Consumer secrets are now wrapped in a `PhutilOpaqueEnvelope` for consistency with OAuth2.
  - Twitter provider now returns full account info (username, profile image, etc), by making a call to the Twitter API.

Test Plan:
Registered using Twitter, got a registration form filled with information:

{F57054}

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3687

Differential Revision: https://secure.phabricator.com/D6864
Enhance support for JIRA as an authentication adapter

Summary: Ref T3687. Actually pull account info in JIRA and expose it via the standard API.

Test Plan: See next revision.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3687

Differential Revision: https://secure.phabricator.com/D6867
Add `PhutilAuthUserAbortedException` to libphutil

Summary:
Ref T3687. When users hit "Deny" or "Cancel" on web-based auth workflows, provide a way for adapters to indicate this.

With the next diff, this improves the UX of cancelling (a bare exception becomes a dialog).

Test Plan: Cancelled out of JIRA oauth workflow, got nice dialog (after next change).

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3687

Differential Revision: https://secure.phabricator.com/D6872
Allow JIRA auth adapter to export a "JIRA Future"

Summary: Ref T3687. Cleans up the API a bit so we can make JIRA calls more easily.

Test Plan: See next revision. Logged in and out with JIRA.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3687

Differential Revision: https://secure.phabricator.com/D6877
Fix literal block

Summary:
Also try to consolidate lines parser code for literal and code
blocks by adding an intermediate ##PhutilRemarkupEngineMultiLineEnclosedBlockRule##
class.

Test Plan: Tested literal and code blocks in sandbox.

Reviewers: epriestley

Reviewed By: epriestley

CC: ldbrandy, Korvin, aran, wez

Differential Revision: https://secure.phabricator.com/D6848
Provide explicit remarkup block priorities

Summary:
D6848 fixed some issues with the `%%%` literal block syntax, but this had a side effect of breaking list syntax //if// the blocks were added in a different order than libphutil adds them. It also created an order-dependent issue with the space-only rules in the code block.

To fix this:

  - Add explicit block priorities so the order they're declared in doesn't matter. We did this for inline rules some time ago, and it seems to work well.
  - Explicitly break the input order of blocks to force the priority rules to take effect during unit tests.
  - Split the code and literal blocks apart again, so the space-only logic doesn't run in the literal block. The complexity to keep them inheriting a common parent while separating this logic out didn't seem worthwhile.

Test Plan: The unit tests from D6848 still pass.

Reviewers: andrewjcg, btrahan, chad

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D6889
Add an option to HTTPSFuture to ignore Location headers

Summary: Sometimes it can be handy to get the request directly rather than following a redirect, such as a badly-implemented 404 page or a broken webserver sending data alongside a Location header.

Test Plan: Use HTTPSFuture to download data from one of said broken servers.

Reviewers: epriestley

Reviewed By: epriestley

CC: Korvin, aran

Differential Revision: https://secure.phabricator.com/D6897
Encode/sign JIRA POST requests like JIRA expects

Summary: Ref T3687. Currently we use generic OAuth1 rules here, but JIRA expects bodies to be JSON encoded and not included as part of the signature. Left a comment about this in case we need some other behavior in general, but this is probably the simplest thing that could possibly work for now.

Test Plan: Performed API POST requests to JIRA, got action on the other side.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3687

Differential Revision: https://secure.phabricator.com/D6891
Configure allowable status codes for HTTPFuture and HTTPSFuture

Summary: Expose new setExpectStatus() method on BaseHTTPFuture. If set, any status code not in the array will trigger an error state in HTTPFutureResponseStatusHTTP.

Test Plan: Used HTTPSFuture with resolvex() and tested against various status codes.

Reviewers: epriestley

Reviewed By: epriestley

CC: Korvin, aran

Differential Revision: https://secure.phabricator.com/D6899
Allow int to trigger ordered list remarkup

Summary:
A line starting with `1.`, `1/` or `1)` can trigger the start of an ordered list.

Once in the list `[0-9]+[./)]` will continue matching the new syntax.

Test Plan: Unit test

Reviewers: epriestley

Reviewed By: epriestley

CC: Korvin, aran

Maniphest Tasks: T3797

Differential Revision: https://secure.phabricator.com/D6994
Parse markup for external interpreter

Summary:
This should pick on any interpreters extending `PhutilRemarkupBlockInterpreter` after matching a specific syntax, see task.

Fixes T3602

Test Plan: unit test

Reviewers: epriestley

Reviewed By: epriestley

CC: Korvin, aran

Maniphest Tasks: T3602

Differential Revision: https://secure.phabricator.com/D7012
Implement Bugtraq as a standalone parse step

Summary:
Ref T3840. I wasn't able to figure the bug in this logic out initially and it doesn't //really// belong on PhabricatorRepository. Separate it out and write tests for it.

The current logic lives here:

https://secure.phabricator.com/diffusion/P/browse/master/src/applications/repository/storage/PhabricatorRepository.php;d3de57716a4fc528$695-744

The bug was that the logic basically does this:

  foreach (capturing match) {
    foreach (array_reverse(selection match)) {
      substr_replace(...);
    }
  }

So we do the selection matches in reverse order (which avoids disrupting the offset), but the capturing matches in forward order. So if you have text like this:

  Issues: 123
  Issues: 345

...everything will end up garbled. Instead, collect all replacements and then do them all in reverse order.

The next diff will replace the logic in Phabricator with a call to this logic.

Test Plan: Unit tests.

Reviewers: btrahan, vrana

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3840

Differential Revision: https://secure.phabricator.com/D7021
Allow blindly trusted HTTPS domains to be globally configured in libphutil

Summary:
Last in a long chain of user requests. Lots of users use self-signed or otherwise goofy HTTPS certificates and don't have the expertise to configure a CA bundle. Let them just say "trust this domain implicitly, no matter what" in configuration.

The next diff will add an arc config option for this.

Test Plan: Added some `die()`, verified that the option in the next diff sends us down the right path.

Reviewers: btrahan

Reviewed By: btrahan

CC: hlau, aran

Differential Revision: https://secure.phabricator.com/D7130
Add PhutilLunarPhase, for computing phases of the moon

Summary:
Ref T603. This seems good enough to produce the same answer as asking a layperson "does the moon look full?".

(Enables implementation of phase-of-the-moon policy controls.)

Test Plan: Unit tests.

Reviewers: btrahan, chad

Reviewed By: chad

CC: aran

Maniphest Tasks: T603

Differential Revision: https://secure.phabricator.com/D7216
Remove spurious +x

Summary: `make` works fine without this unnecessary +x on the makefile.
Fix two issues with Filesystem::writeUniqueFile

Summary:
  - `fclose()` error code was not checked.
  - Writing 0 bytes would be treated as an error.

Test Plan: Unit test.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran, glen

Differential Revision: https://secure.phabricator.com/D7262
Add an auth adapter for Mozilla Persona

Summary: Ref T3958. Adds the adapter for Persona.

Test Plan: See next revision.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3958

Differential Revision: https://secure.phabricator.com/D7312
Fix a lexer issue with SimpleOptions and backslashes in unterminated quotes

Summary: The SimpleOptions lexer has an error when parsing a line like `a="\`, where the lexer can't accept the backslash inside the unterminated quotes.

Test Plan: Added failing unit tests; they now pass.

Reviewers: btrahan, SEJeff

Reviewed By: SEJeff

CC: SEJeff, aran

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