Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/auth/adapter/PhutilBitbucketAuthAdapter.php b/src/applications/auth/adapter/PhutilBitbucketAuthAdapter.php
index 1384548d5e..baf9d5407e 100644
--- a/src/applications/auth/adapter/PhutilBitbucketAuthAdapter.php
+++ b/src/applications/auth/adapter/PhutilBitbucketAuthAdapter.php
@@ -1,73 +1,73 @@
<?php
final class PhutilBitbucketAuthAdapter extends PhutilOAuth1AuthAdapter {
private $userInfo;
public function getAccountID() {
return idx($this->getUserInfo(), 'username');
}
public function getAccountName() {
return idx($this->getUserInfo(), 'display_name');
}
public function getAccountURI() {
$name = $this->getAccountID();
- if (strlen($name)) {
+ if (phutil_nonempty_string($name)) {
return 'https://bitbucket.org/'.$name;
}
return null;
}
public function getAccountImageURI() {
return idx($this->getUserInfo(), 'avatar');
}
public function getAccountRealName() {
$parts = array(
idx($this->getUserInfo(), 'first_name'),
idx($this->getUserInfo(), 'last_name'),
);
$parts = array_filter($parts);
return implode(' ', $parts);
}
public function getAdapterType() {
return 'bitbucket';
}
public function getAdapterDomain() {
return 'bitbucket.org';
}
protected function getRequestTokenURI() {
return 'https://bitbucket.org/api/1.0/oauth/request_token';
}
protected function getAuthorizeTokenURI() {
return 'https://bitbucket.org/api/1.0/oauth/authenticate';
}
protected function getValidateTokenURI() {
return 'https://bitbucket.org/api/1.0/oauth/access_token';
}
private function getUserInfo() {
if ($this->userInfo === null) {
// We don't need any of the data in the handshake, but do need to
// finish the process. This makes sure we've completed the handshake.
$this->getHandshakeData();
$uri = new PhutilURI('https://bitbucket.org/api/1.0/user');
$data = $this->newOAuth1Future($uri)
->setMethod('GET')
->resolveJSON();
$this->userInfo = idx($data, 'user', array());
}
return $this->userInfo;
}
}
diff --git a/src/applications/auth/adapter/PhutilGitHubAuthAdapter.php b/src/applications/auth/adapter/PhutilGitHubAuthAdapter.php
index a9d4c849d5..5d85a2ac21 100644
--- a/src/applications/auth/adapter/PhutilGitHubAuthAdapter.php
+++ b/src/applications/auth/adapter/PhutilGitHubAuthAdapter.php
@@ -1,76 +1,76 @@
<?php
/**
* Authentication adapter for Github OAuth2.
*/
final class PhutilGitHubAuthAdapter extends PhutilOAuthAuthAdapter {
public function getAdapterType() {
return 'github';
}
public function getAdapterDomain() {
return 'github.com';
}
public function getAccountID() {
return $this->getOAuthAccountData('id');
}
public function getAccountEmail() {
return $this->getOAuthAccountData('email');
}
public function getAccountName() {
return $this->getOAuthAccountData('login');
}
public function getAccountImageURI() {
return $this->getOAuthAccountData('avatar_url');
}
public function getAccountURI() {
$name = $this->getAccountName();
- if (strlen($name)) {
+ if (phutil_nonempty_string($name)) {
return 'https://github.com/'.$name;
}
return null;
}
public function getAccountRealName() {
return $this->getOAuthAccountData('name');
}
protected function getAuthenticateBaseURI() {
return 'https://github.com/login/oauth/authorize';
}
protected function getTokenBaseURI() {
return 'https://github.com/login/oauth/access_token';
}
protected function loadOAuthAccountData() {
$uri = new PhutilURI('https://api.github.com/user');
$future = new HTTPSFuture($uri);
// NOTE: GitHub requires a User-Agent string.
$future->addHeader('User-Agent', __CLASS__);
// See T13485. Circa early 2020, GitHub has deprecated use of the
// "access_token" URI parameter.
$token_header = sprintf('token %s', $this->getAccessToken());
$future->addHeader('Authorization', $token_header);
list($body) = $future->resolvex();
try {
return phutil_json_decode($body);
} catch (PhutilJSONParserException $ex) {
throw new PhutilProxyException(
pht('Expected valid JSON response from GitHub account data request.'),
$ex);
}
}
}
diff --git a/src/applications/auth/adapter/PhutilTwitterAuthAdapter.php b/src/applications/auth/adapter/PhutilTwitterAuthAdapter.php
index 6f738c75f6..02a1f59a67 100644
--- a/src/applications/auth/adapter/PhutilTwitterAuthAdapter.php
+++ b/src/applications/auth/adapter/PhutilTwitterAuthAdapter.php
@@ -1,75 +1,75 @@
<?php
/**
* Authentication adapter for Twitter OAuth1.
*/
final class PhutilTwitterAuthAdapter extends PhutilOAuth1AuthAdapter {
private $userInfo;
public function getAccountID() {
return idx($this->getHandshakeData(), 'user_id');
}
public function getAccountName() {
return idx($this->getHandshakeData(), 'screen_name');
}
public function getAccountURI() {
$name = $this->getAccountName();
- if (strlen($name)) {
+ if (phutil_nonempty_string($name)) {
return 'https://twitter.com/'.$name;
}
return null;
}
public function getAccountImageURI() {
$info = $this->getUserInfo();
return idx($info, 'profile_image_url');
}
public function getAccountRealName() {
$info = $this->getUserInfo();
return idx($info, 'name');
}
public function getAdapterType() {
return 'twitter';
}
public function getAdapterDomain() {
return 'twitter.com';
}
protected function getRequestTokenURI() {
return 'https://api.twitter.com/oauth/request_token';
}
protected function getAuthorizeTokenURI() {
return 'https://api.twitter.com/oauth/authorize';
}
protected function getValidateTokenURI() {
return 'https://api.twitter.com/oauth/access_token';
}
private function getUserInfo() {
if ($this->userInfo === null) {
$params = array(
'user_id' => $this->getAccountID(),
);
$uri = new PhutilURI(
'https://api.twitter.com/1.1/users/show.json',
$params);
$data = $this->newOAuth1Future($uri)
->setMethod('GET')
->resolveJSON();
$this->userInfo = $data;
}
return $this->userInfo;
}
}
diff --git a/src/applications/diffusion/query/lowlevel/DiffusionLowLevelCommitQuery.php b/src/applications/diffusion/query/lowlevel/DiffusionLowLevelCommitQuery.php
index 8b9233f128..0b5df04a41 100644
--- a/src/applications/diffusion/query/lowlevel/DiffusionLowLevelCommitQuery.php
+++ b/src/applications/diffusion/query/lowlevel/DiffusionLowLevelCommitQuery.php
@@ -1,223 +1,223 @@
<?php
/**
* Populate a @{class:DiffusionCommitRef} with information about a specific
* commit in a repository. This is a low-level query which talks directly to
* the underlying VCS.
*/
final class DiffusionLowLevelCommitQuery
extends DiffusionLowLevelQuery {
private $identifier;
public function withIdentifier($identifier) {
$this->identifier = $identifier;
return $this;
}
protected function executeQuery() {
if (!strlen($this->identifier)) {
throw new PhutilInvalidStateException('withIdentifier');
}
$type = $this->getRepository()->getVersionControlSystem();
switch ($type) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
$result = $this->loadGitCommitRef();
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
$result = $this->loadMercurialCommitRef();
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
$result = $this->loadSubversionCommitRef();
break;
default:
throw new Exception(pht('Unsupported repository type "%s"!', $type));
}
return $result;
}
private function loadGitCommitRef() {
$repository = $this->getRepository();
// See T5028. The "%B" (raw body) mode is not present in very old versions
// of Git. Use "%s" and "%b" ("subject" and "wrapped body") as an
// approximation.
$git_binary = PhutilBinaryAnalyzer::getForBinary('git');
$git_version = $git_binary->getBinaryVersion();
if (version_compare($git_version, '1.7.2', '>=')) {
$body_format = '%B';
$split_body = false;
} else {
$body_format = '%s%x00%b';
$split_body = true;
}
$argv = array();
$argv[] = '-n';
$argv[] = '1';
$argv[] = '--encoding=UTF-8';
$argv[] = sprintf(
'--format=%s',
implode(
'%x00',
array(
'%e',
'%cn',
'%ce',
'%an',
'%ae',
'%T',
'%at',
$body_format,
// The "git log" output includes a trailing newline. We want to
// faithfully capture only the exact text of the commit message,
// so include an explicit terminator: this makes sure the exact
// body text is surrounded by "\0" characters.
'~',
)));
// Even though we pass --encoding here, git doesn't always succeed, so
// we try a little harder, since git *does* tell us what the actual encoding
// is correctly (unless it doesn't; encoding is sometimes empty).
list($info) = $repository->execxLocalCommand(
'log -n 1 %Ls %s --',
$argv,
gitsprintf('%s', $this->identifier));
$parts = explode("\0", $info);
$encoding = array_shift($parts);
foreach ($parts as $key => $part) {
if ($encoding) {
$part = phutil_utf8_convert($part, 'UTF-8', $encoding);
}
$parts[$key] = phutil_utf8ize($part);
if (!strlen($parts[$key])) {
$parts[$key] = null;
}
}
$hashes = array(
id(new DiffusionCommitHash())
->setHashType(ArcanistDifferentialRevisionHash::HASH_GIT_COMMIT)
->setHashValue($this->identifier),
id(new DiffusionCommitHash())
->setHashType(ArcanistDifferentialRevisionHash::HASH_GIT_TREE)
->setHashValue($parts[4]),
);
$author_epoch = (int)$parts[5];
if (!$author_epoch) {
$author_epoch = null;
}
if ($split_body) {
// Here, the body is: "subject", "\0", "wrapped body". Stitch the
// pieces back together by putting a newline between them if both
// parts are nonempty.
$head = $parts[6];
$tail = $parts[7];
- if (strlen($head) && strlen($tail)) {
+ if (phutil_nonempty_string($head) && phutil_nonempty_string($tail)) {
$body = $head."\n\n".$tail;
- } else if (strlen($head)) {
+ } else if (phutil_nonempty_string($head)) {
$body = $head;
- } else if (strlen($tail)) {
+ } else if (phutil_nonempty_string($tail)) {
$body = $tail;
} else {
$body = '';
}
} else {
// Here, the body is the raw unwrapped body.
$body = $parts[6];
}
return id(new DiffusionCommitRef())
->setCommitterName($parts[0])
->setCommitterEmail($parts[1])
->setAuthorName($parts[2])
->setAuthorEmail($parts[3])
->setHashes($hashes)
->setAuthorEpoch($author_epoch)
->setMessage($body);
}
private function loadMercurialCommitRef() {
$repository = $this->getRepository();
list($stdout) = $repository->execxLocalCommand(
'log --template %s --rev %s',
'{author}\\n{desc}',
hgsprintf('%s', $this->identifier));
list($author, $message) = explode("\n", $stdout, 2);
$author = phutil_utf8ize($author);
$message = phutil_utf8ize($message);
list($author_name, $author_email) = $this->splitUserIdentifier($author);
$hashes = array(
id(new DiffusionCommitHash())
->setHashType(ArcanistDifferentialRevisionHash::HASH_MERCURIAL_COMMIT)
->setHashValue($this->identifier),
);
return id(new DiffusionCommitRef())
->setAuthorName($author_name)
->setAuthorEmail($author_email)
->setMessage($message)
->setHashes($hashes);
}
private function loadSubversionCommitRef() {
$repository = $this->getRepository();
list($xml) = $repository->execxRemoteCommand(
'log --xml --limit 1 %s',
$repository->getSubversionPathURI(null, $this->identifier));
// Subversion may send us back commit messages which won't parse because
// they have non UTF-8 garbage in them. Slam them into valid UTF-8.
$xml = phutil_utf8ize($xml);
$log = new SimpleXMLElement($xml);
$entry = $log->logentry[0];
$author = (string)$entry->author;
$message = (string)$entry->msg;
list($author_name, $author_email) = $this->splitUserIdentifier($author);
// No hashes in Subversion.
$hashes = array();
return id(new DiffusionCommitRef())
->setAuthorName($author_name)
->setAuthorEmail($author_email)
->setMessage($message)
->setHashes($hashes);
}
private function splitUserIdentifier($user) {
$email = new PhutilEmailAddress($user);
if ($email->getDisplayName() || $email->getDomainName()) {
$user_name = $email->getDisplayName();
$user_email = $email->getAddress();
} else {
$user_name = $email->getAddress();
$user_email = null;
}
return array($user_name, $user_email);
}
}
diff --git a/src/infrastructure/markup/rule/PhabricatorKeyboardRemarkupRule.php b/src/infrastructure/markup/rule/PhabricatorKeyboardRemarkupRule.php
index c5344a692c..a28735cfe9 100644
--- a/src/infrastructure/markup/rule/PhabricatorKeyboardRemarkupRule.php
+++ b/src/infrastructure/markup/rule/PhabricatorKeyboardRemarkupRule.php
@@ -1,273 +1,273 @@
<?php
final class PhabricatorKeyboardRemarkupRule extends PhutilRemarkupRule {
public function getPriority() {
return 200.0;
}
public function apply($text) {
return preg_replace_callback(
'@{key\b((?:[^}\\\\]+|\\\\.)*)}@m',
array($this, 'markupKeystrokes'),
$text);
}
public function markupKeystrokes(array $matches) {
if (!$this->isFlatText($matches[0])) {
return $matches[0];
}
$keys = explode(' ', $matches[1]);
foreach ($keys as $k => $v) {
$v = trim($v, " \n");
$v = preg_replace('/\\\\(.)/', '\\1', $v);
- if (!strlen($v)) {
+ if ($v === '') {
unset($keys[$k]);
continue;
}
$keys[$k] = $v;
}
$special = array(
array(
'name' => pht('Command'),
'symbol' => "\xE2\x8C\x98",
'aliases' => array(
'cmd',
'command',
),
),
array(
'name' => pht('Option'),
'symbol' => "\xE2\x8C\xA5",
'aliases' => array(
'opt',
'option',
),
),
array(
'name' => pht('Shift'),
'symbol' => "\xE2\x87\xA7",
'aliases' => array(
'shift',
),
),
array(
'name' => pht('Escape'),
'symbol' => "\xE2\x8E\x8B",
'aliases' => array(
'esc',
'escape',
),
),
array(
'name' => pht('Enter'),
'symbol' => "\xE2\x8F\x8E",
'aliases' => array(
'enter',
'return',
),
),
array(
'name' => pht('Control'),
'symbol' => "\xE2\x8C\x83",
'aliases' => array(
'ctrl',
'control',
),
),
array(
'name' => pht('Up'),
'symbol' => "\xE2\x86\x91",
'heavy' => "\xE2\xAC\x86",
'aliases' => array(
'up',
'arrow-up',
'up-arrow',
'north',
),
),
array(
'name' => pht('Tab'),
'symbol' => "\xE2\x87\xA5",
'aliases' => array(
'tab',
),
),
array(
'name' => pht('Right'),
'symbol' => "\xE2\x86\x92",
'heavy' => "\xE2\x9E\xA1",
'aliases' => array(
'right',
'right-arrow',
'arrow-right',
'east',
),
),
array(
'name' => pht('Left'),
'symbol' => "\xE2\x86\x90",
'heavy' => "\xE2\xAC\x85",
'aliases' => array(
'left',
'left-arrow',
'arrow-left',
'west',
),
),
array(
'name' => pht('Down'),
'symbol' => "\xE2\x86\x93",
'heavy' => "\xE2\xAC\x87",
'aliases' => array(
'down',
'down-arrow',
'arrow-down',
'south',
),
),
array(
'name' => pht('Up Right'),
'symbol' => "\xE2\x86\x97",
'heavy' => "\xE2\xAC\x88",
'aliases' => array(
'up-right',
'upright',
'up-right-arrow',
'upright-arrow',
'arrow-up-right',
'arrow-upright',
'northeast',
'north-east',
),
),
array(
'name' => pht('Down Right'),
'symbol' => "\xE2\x86\x98",
'heavy' => "\xE2\xAC\x8A",
'aliases' => array(
'down-right',
'downright',
'down-right-arrow',
'downright-arrow',
'arrow-down-right',
'arrow-downright',
'southeast',
'south-east',
),
),
array(
'name' => pht('Down Left'),
'symbol' => "\xE2\x86\x99",
'heavy' => "\xE2\xAC\x8B",
'aliases' => array(
'down-left',
'downleft',
'down-left-arrow',
'downleft-arrow',
'arrow-down-left',
'arrow-downleft',
'southwest',
'south-west',
),
),
array(
'name' => pht('Up Left'),
'symbol' => "\xE2\x86\x96",
'heavy' => "\xE2\xAC\x89",
'aliases' => array(
'up-left',
'upleft',
'up-left-arrow',
'upleft-arrow',
'arrow-up-left',
'arrow-upleft',
'northwest',
'north-west',
),
),
);
$map = array();
foreach ($special as $spec) {
foreach ($spec['aliases'] as $alias) {
$map[$alias] = $spec;
}
}
$is_text = $this->getEngine()->isTextMode();
$is_html_mail = $this->getEngine()->isHTMLMailMode();
if ($is_html_mail) {
$key_style = array(
'display: inline-block;',
'min-width: 1em;',
'padding: 4px 5px 5px;',
'font-weight: normal;',
'font-size: 0.8rem;',
'text-align: center;',
'text-decoration: none;',
'line-height: 0.6rem;',
'border-radius: 3px;',
'box-shadow: inset 0 -1px 0 rgba(71, 87, 120, 0.08);',
'-webkit-user-select: none;',
'user-select: none;',
'background: #f7f7f7;',
'border: 1px solid #C7CCD9;',
);
$key_style = implode(' ', $key_style);
$join_style = array(
'padding: 0 4px;',
'color: #92969D;',
);
$join_style = implode(' ', $join_style);
} else {
$key_style = null;
$join_style = null;
}
$parts = array();
foreach ($keys as $k => $v) {
$normal = phutil_utf8_strtolower($v);
if (isset($map[$normal])) {
$spec = $map[$normal];
} else {
$spec = array(
'name' => null,
'symbol' => $v,
);
}
if ($is_text) {
$parts[] = '['.$spec['symbol'].']';
} else {
$parts[] = phutil_tag(
'kbd',
array(
'title' => $spec['name'],
'style' => $key_style,
),
$spec['symbol']);
}
}
if ($is_text) {
$parts = implode(' + ', $parts);
} else {
$glue = phutil_tag(
'span',
array(
'class' => 'kbd-join',
'style' => $join_style,
),
'+');
$parts = phutil_implode_html($glue, $parts);
}
return $this->getEngine()->storeText($parts);
}
}

File Metadata

Mime Type
text/x-diff
Expires
Mon, Nov 25, 12:03 AM (1 d, 16 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1081
Default Alt Text
(20 KB)

Event Timeline