Improve invalid workflow message.

Summary: Given an invalid workflow, show an error message which lists available commands.

Test Plan: Try specifying an invalid workflow.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin, AnhNhan

Maniphest Tasks: T3040

Differential Revision: https://secure.phabricator.com/D6129
Improve performance of phutil_utf8_shorten()

Summary:
This function is a little slower and more complex than necessary:

  - If the string to shorten has fewer bytes than the maximum length, it certainly has fewer characters, and we can skip all the expensive utf8 operations.
  - If the terminal is longer than the maximum length, just return it unmodified. Throwing is messy and excessively strict, and we need to do expensive utf8 operations early in the function to ensure we throw consistently.

Test Plan: This is well-covered by unit tests.

Reviewers: chad, btrahan

Reviewed By: chad

CC: aran

Differential Revision: https://secure.phabricator.com/D6182
Make phutil_tag() / phutil_escape_html() 10-15% faster

Summary:
These numbers are a bit rough, but they seem to make a difference. Total weight of my test page (Maniphest task list) dropped from ~194ms to ~170ms. Time spent in phutil_tag() dropped from 105-110ms to 90ms.

This also cleans up the call graph for xhprof a bit (e.g., removes 1,300 calls to array_map()). Generally, `foreach(...)` is faster than `array_map(...)` (at least for small inputs, and at least on Zend PHP) as we avoid paying for function call overhead.

Test Plan: Loaded various pages. There should be no functional changes.

Reviewers: btrahan, chad, vrana

Reviewed By: chad

CC: aran

Differential Revision: https://secure.phabricator.com/D6183
Provide an AuthProvider skeleton in libphutil

Summary: Ref T1536. One of the major issues with authentication today is the tight coupling between provider APIs (e.g., how you figure out a user's account ID) and Phabricator-specific configuration (like whether a specific provider is enabled or not). To remedy this, I'm splitting auth providers apart into libphutil -- they have the provider-specific code which knows the OAuth/LDAP/OpenID protocols. The configuration and policy code will layer on top of them intead of being part-and-parcel.

Test Plan: Static only; this code is not reachable.

Reviewers: btrahan, chad, rezanachmad

Reviewed By: chad

CC: aran

Maniphest Tasks: T1536

Differential Revision: https://secure.phabricator.com/D6155
Add diagnostics to LDAPAdapter

Summary: Ref T1536. Provides diagnostics support for LDAP.

Test Plan: Ran `bin/auth ldap`, see next diff.

Reviewers: mbishopim3, chad

Reviewed By: chad

CC: aran

Maniphest Tasks: T1536

Differential Revision: https://secure.phabricator.com/D6217
Restore/respect "require secure browsing" for Facebook (libphutil)

Summary: Ref T1536. Facebook use this OAuth option which impacts only Facebook, but since it's auth related we should probably grandfather it in. See next diff for the Phabricator part.

Test Plan: Configured / force triggered it, got told ot turn on secure browsign.

Reviewers: chad, btrahan

Reviewed By: chad

CC: aran

Maniphest Tasks: T1536

Differential Revision: https://secure.phabricator.com/D6223
Fix OAuth profile pictures for FB

Summary: Ref T1536. Older versions of this code had a multi-parameter accessor for the data, but this is essentially the only callsite any provider has for that so the new ones don't.

Test Plan: {F46833}

Reviewers: wez, chad

Reviewed By: chad

CC: aran

Maniphest Tasks: T1536

Differential Revision: https://secure.phabricator.com/D6233
Fix LDAP selection of DN after searching

Summary: Ref T1536. The "dn" property is unusual. Add code to find it.

Test Plan: Walked through this with @staticshock, who verified the fix.

Reviewers: staticshock, chad

Reviewed By: chad

CC: aran

Maniphest Tasks: T1536

Differential Revision: https://secure.phabricator.com/D6235
Expand LDAP auth API

Summary: Ref T1536. Support LDAP import somewhat better so I can nuke more code.

Test Plan: See next diff. Performed LDAP import.

Reviewers: btrahan, chad

Reviewed By: chad

CC: aran

Maniphest Tasks: T1536

Differential Revision: https://secure.phabricator.com/D6242
Add Asana and Amazon OAuth adapters

Summary:
Ref T1536. Ref T2852. These are pretty straightforward, except:

  - Amazon requires HTTPS, and won't let you make an app without an HTTPS callback URI.
  - Asana requires "Authorization:" instead of "?access_token" for authorization.

Test Plan: Created Amazon and Asana providers and used them to log in / register.

Reviewers: btrahan, chad

Reviewed By: chad

CC: aran

Maniphest Tasks: T1536, T2852

Differential Revision: https://secure.phabricator.com/D6248
Add a request parser.

Summary:
Parses the get and post array's. Cleans the keys up. PHP replaces certain characters one of these being a period ".", this is silly and we want to get it back.

Ref T3432

Test Plan:
Parse both request arrays and use phabricator generally.
Start submitting forms, including nested data (cc[0]=...).
Use custom fields with a period in the key.

Reviewers: epriestley

CC: aran, Korvin

Maniphest Tasks: T3432

Differential Revision: https://secure.phabricator.com/D6277
Be more liberal in reading LDAP configuration

Summary: Ref T1536. If we have `''` (empty string) instead of a strict null, we should still ignore it during lookup.

Test Plan: Configuration with searchAttibute but empty string usernameAttribute now works correctly.

Reviewers: btrahan, chad

Reviewed By: chad

CC: aran

Maniphest Tasks: T1536

Differential Revision: https://secure.phabricator.com/D6286
Add a PhutilAsanaFuture

Summary: Ref T2852. Provides future-based access to Asana's OAuth/HTTP API.

Test Plan: Logged in with Asana, effecting a "users/me" call.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2852

Differential Revision: https://secure.phabricator.com/D6272
Suport OAuth refresh tokens and token expiry

Summary: Ref T2852. Some providers, including Asana, issue short-lived OAuth tokens and separate long-lived refresh tokens which may be redeemed for new short-lived access tokens later. Provide initial support.

Test Plan: See next diff.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2852

Differential Revision: https://secure.phabricator.com/D6275
Implement an "invisibles" syntax highlighting language

Summary: Repalces a range of non printable characters with symbols

Test Plan: View some pastes with invisible highlighting

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T3322

Differential Revision: https://secure.phabricator.com/D6297
Submit AsanaFuture data with HTTPSFuture, not in the URI

Summary: Ref T2852. For POST/PUT, handing this data directly to the HTTPSFuture results in an encoding which the Asana side of things handles better (notably, decoding `+` as space), and is more reasonable in general.

Test Plan: Tasks don't show up in Asana as `"[Differential]+..."` after this change, and all the other API integrations continue to work properly.

Reviewers: btrahan, chad

Reviewed By: chad

CC: aran

Maniphest Tasks: T2852

Differential Revision: https://secure.phabricator.com/D6299
Support DELETE http method in libphutil

Summary: Ref T2852. Asana uses this for DELETEing stuff. This array was just to catch typos, I'm pretty sure (I think there was a `setMethod('PSOT')` somewhere once), and the method works correctly.

Test Plan: Deleted asana stuff via API.

Reviewers: btrahan, chad

Reviewed By: chad

CC: aran

Maniphest Tasks: T2852

Differential Revision: https://secure.phabricator.com/D6309
Add test cases which cover the trailing whitespace behavior of code blocks

Summary:
Code blocks should have all whitespace preserved identically, so that things like "lang=invisible" work as expected. Add test coverage around that.

Previously, the plain-text version of code blocks did not obey this rule. Make it obey the rule for consistency, and add/adjust test coverage.

Test Plan: Unit tests.

Reviewers: garoevans

Reviewed By: garoevans

CC: aran

Differential Revision: https://secure.phabricator.com/D6316
Fix doc comment
Rewrite block rules to calculate their own blocks

Summary:
Following a simple request... T3321

Fixes T3321

Test Plan: Unit tests... eventually

Reviewers: epriestley

CC: aran, Korvin

Maniphest Tasks: T3321

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