Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/aphront/applicationconfiguration/AphrontApplicationConfiguration.php b/src/aphront/applicationconfiguration/AphrontApplicationConfiguration.php
index aa69420a1f..4da7ea92f1 100644
--- a/src/aphront/applicationconfiguration/AphrontApplicationConfiguration.php
+++ b/src/aphront/applicationconfiguration/AphrontApplicationConfiguration.php
@@ -1,115 +1,116 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @group aphront
*/
abstract class AphrontApplicationConfiguration {
private $request;
private $host;
private $path;
private $console;
abstract public function getApplicationName();
abstract public function getURIMap();
abstract public function buildRequest();
abstract public function build404Controller();
abstract public function buildRedirectController($uri);
final public function setRequest(AphrontRequest $request) {
$this->request = $request;
return $this;
}
final public function getRequest() {
return $this->request;
}
final public function getConsole() {
return $this->console;
}
final public function setConsole($console) {
$this->console = $console;
+ return $this;
}
final public function buildController() {
$map = $this->getURIMap();
$mapper = new AphrontURIMapper($map);
$request = $this->getRequest();
$path = $request->getPath();
list($controller_class, $uri_data) = $mapper->mapPath($path);
if (!$controller_class) {
if (!preg_match('@/$@', $path)) {
// If we failed to match anything but don't have a trailing slash, try
// to add a trailing slash and issue a redirect if that resolves.
list($controller_class, $uri_data) = $mapper->mapPath($path.'/');
// NOTE: For POST, just 404 instead of redirecting, since the redirect
// will be a GET without parameters.
if ($controller_class && !$request->isHTTPPost()) {
$uri = $request->getRequestURI()->setPath($path.'/');
return $this->buildRedirectController($uri);
}
}
return $this->build404Controller();
}
PhutilSymbolLoader::loadClass($controller_class);
$controller = newv($controller_class, array($request));
return array($controller, $uri_data);
}
final public function setHost($host) {
$this->host = $host;
return $this;
}
final public function getHost() {
return $this->host;
}
final public function setPath($path) {
$this->path = $path;
return $this;
}
final public function getPath() {
return $this->path;
}
final public function willBuildRequest() {
}
/**
* Hook for synchronizing account information from OAuth workflows.
*
* @task hook
*/
public function willAuthenticateUserWithOAuth(
PhabricatorUser $user,
PhabricatorUserOAuthInfo $oauth_info,
PhabricatorOAuthProvider $provider) {
return;
}
}
diff --git a/src/aphront/request/AphrontRequest.php b/src/aphront/request/AphrontRequest.php
index d7f5fe8be5..22a6714b58 100644
--- a/src/aphront/request/AphrontRequest.php
+++ b/src/aphront/request/AphrontRequest.php
@@ -1,318 +1,320 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
*
* @task data Accessing Request Data
*
* @group aphront
*/
final class AphrontRequest {
const TYPE_AJAX = '__ajax__';
const TYPE_FORM = '__form__';
const TYPE_CONDUIT = '__conduit__';
private $host;
private $path;
private $requestData;
private $user;
private $env;
private $applicationConfiguration;
final public function __construct($host, $path) {
$this->host = $host;
$this->path = $path;
}
final public function setApplicationConfiguration(
$application_configuration) {
$this->applicationConfiguration = $application_configuration;
return $this;
}
final public function getApplicationConfiguration() {
return $this->applicationConfiguration;
}
final public function getPath() {
return $this->path;
}
final public function getHost() {
return $this->host;
}
/* -( Accessing Request Data )--------------------------------------------- */
/**
* @task data
*/
final public function setRequestData(array $request_data) {
$this->requestData = $request_data;
return $this;
}
/**
* @task data
*/
final public function getRequestData() {
return $this->requestData;
}
/**
* @task data
*/
final public function getInt($name, $default = null) {
if (isset($this->requestData[$name])) {
return (int)$this->requestData[$name];
} else {
return $default;
}
}
/**
* @task data
*/
final public function getBool($name, $default = null) {
if (isset($this->requestData[$name])) {
if ($this->requestData[$name] === 'true') {
return true;
} else if ($this->requestData[$name] === 'false') {
return false;
} else {
return (bool)$this->requestData[$name];
}
} else {
return $default;
}
}
/**
* @task data
*/
final public function getStr($name, $default = null) {
if (isset($this->requestData[$name])) {
$str = (string)$this->requestData[$name];
// Normalize newline craziness.
$str = str_replace(
array("\r\n", "\r"),
array("\n", "\n"),
$str);
return $str;
} else {
return $default;
}
}
/**
* @task data
*/
final public function getArr($name, $default = array()) {
if (isset($this->requestData[$name]) &&
is_array($this->requestData[$name])) {
return $this->requestData[$name];
} else {
return $default;
}
}
/**
* @task data
*/
final public function getStrList($name, $default = array()) {
if (!isset($this->requestData[$name])) {
return $default;
}
$list = $this->getStr($name);
$list = preg_split('/[,\n]/', $list);
$list = array_map('trim', $list);
$list = array_filter($list, 'strlen');
$list = array_values($list);
return $list;
}
/**
* @task data
*/
final public function getExists($name) {
return array_key_exists($name, $this->requestData);
}
final public function isHTTPPost() {
return ($_SERVER['REQUEST_METHOD'] == 'POST');
}
final public function isAjax() {
return $this->getExists(self::TYPE_AJAX);
}
final public function isConduit() {
return $this->getExists(self::TYPE_CONDUIT);
}
public static function getCSRFTokenName() {
return '__csrf__';
}
public static function getCSRFHeaderName() {
return 'X-Phabricator-Csrf';
}
final public function validateCSRF() {
$token_name = self::getCSRFTokenName();
$token = $this->getStr($token_name);
// No token in the request, check the HTTP header which is added for Ajax
// requests.
if (empty($token)) {
// PHP mangles HTTP headers by uppercasing them and replacing hyphens with
// underscores, then prepending 'HTTP_'.
$php_index = self::getCSRFHeaderName();
$php_index = strtoupper($php_index);
$php_index = str_replace('-', '_', $php_index);
$php_index = 'HTTP_'.$php_index;
$token = idx($_SERVER, $php_index);
}
$valid = $this->getUser()->validateCSRFToken($token);
if (!$valid) {
// Add some diagnostic details so we can figure out if some CSRF issues
// are JS problems or people accessing Ajax URIs directly with their
// browsers.
if ($token) {
$token_info = "with an invalid CSRF token";
} else {
$token_info = "without a CSRF token";
}
if ($this->isAjax()) {
$more_info = "(This was an Ajax request, {$token_info}.)";
} else {
$more_info = "(This was a web request, {$token_info}.)";
}
// This should only be able to happen if you load a form, pull your
// internet for 6 hours, and then reconnect and immediately submit,
// but give the user some indication of what happened since the workflow
// is incredibly confusing otherwise.
throw new AphrontCSRFException(
"The form you just submitted did not include a valid CSRF token. ".
"This token is a technical security measure which prevents a ".
"certain type of login hijacking attack. However, the token can ".
"become invalid if you leave a page open for more than six hours ".
"without a connection to the internet. To fix this problem: reload ".
"the page, and then resubmit it.\n\n".
$more_info);
}
return true;
}
final public function isFormPost() {
$post = $this->getExists(self::TYPE_FORM) &&
$this->isHTTPPost();
if (!$post) {
return false;
}
return $this->validateCSRF();
}
final public function getCookie($name, $default = null) {
return idx($_COOKIE, $name, $default);
}
final public function clearCookie($name) {
$this->setCookie($name, '', time() - (60 * 60 * 24 * 30));
}
final public function setCookie($name, $value, $expire = null) {
// Ensure cookies are only set on the configured domain.
$base_uri = PhabricatorEnv::getEnvConfig('phabricator.base-uri');
$base_uri = new PhutilURI($base_uri);
$base_domain = $base_uri->getDomain();
$base_protocol = $base_uri->getProtocol();
// The "Host" header may include a port number; if so, ignore it. We can't
// use PhutilURI since there's no URI scheme.
list($actual_host) = explode(':', $this->getHost(), 2);
if ($base_domain != $actual_host) {
throw new Exception(
"This install of Phabricator is configured as '{$base_domain}' but ".
"you are accessing it via '{$actual_host}'. Access Phabricator via ".
"the primary configured domain.");
}
if ($expire === null) {
$expire = time() + (60 * 60 * 24 * 365 * 5);
}
$is_secure = ($base_protocol == 'https');
setcookie(
$name,
$value,
$expire,
$path = '/',
$base_domain,
$is_secure,
$http_only = true);
+
+ return $this;
}
final public function setUser($user) {
$this->user = $user;
return $this;
}
final public function getUser() {
return $this->user;
}
final public function getRequestURI() {
$get = $_GET;
unset($get['__path__']);
$path = phutil_escape_uri($this->getPath());
return id(new PhutilURI($path))->setQueryParams($get);
}
final public function isDialogFormPost() {
return $this->isFormPost() && $this->getStr('__dialog__');
}
final public function getRemoteAddr() {
return $_SERVER['REMOTE_ADDR'];
}
}
diff --git a/src/applications/daemon/view/daemonlogevents/PhabricatorDaemonLogEventsView.php b/src/applications/daemon/view/daemonlogevents/PhabricatorDaemonLogEventsView.php
index aaebcbec0c..c33b5f746d 100644
--- a/src/applications/daemon/view/daemonlogevents/PhabricatorDaemonLogEventsView.php
+++ b/src/applications/daemon/view/daemonlogevents/PhabricatorDaemonLogEventsView.php
@@ -1,128 +1,130 @@
<?php
/*
- * Copyright 2011 Facebook, Inc.
+ * Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class PhabricatorDaemonLogEventsView extends AphrontView {
private $events;
private $combinedLog;
private $user;
public function setEvents(array $events) {
$this->events = $events;
+ return $this;
}
public function setCombinedLog($is_combined) {
$this->combinedLog = $is_combined;
+ return $this;
}
public function setUser(PhabricatorUser $user) {
$this->user = $user;
return $this;
}
public function render() {
$rows = array();
if (!$this->user) {
throw new Exception("Call setUser() before rendering!");
}
foreach ($this->events as $event) {
// Limit display log size. If a daemon gets stuck in an output loop this
// page can be like >100MB if we don't truncate stuff. Try to do cheap
// line-based truncation first, and fall back to expensive UTF-8 character
// truncation if that doesn't get things short enough.
$message = $event->getMessage();
$more_lines = null;
$more_chars = null;
$line_limit = 12;
if (substr_count($message, "\n") > $line_limit) {
$message = explode("\n", $message);
$more_lines = count($message) - $line_limit;
$message = array_slice($message, 0, $line_limit);
$message = implode("\n", $message);
}
$char_limit = 8192;
if (strlen($message) > $char_limit) {
$message = phutil_utf8v($message);
$more_chars = count($message) - $char_limit;
$message = array_slice($message, 0, $char_limit);
$message = implode('', $message);
}
$more = null;
if ($more_chars) {
$more = number_format($more_chars);
$more = "\n<... {$more} more characters ...>";
} else if ($more_lines) {
$more = number_format($more_lines);
$more = "\n<... {$more} more lines ...>";
}
$row = array(
phutil_escape_html($event->getLogType()),
phabricator_date($event->getEpoch(), $this->user),
phabricator_time($event->getEpoch(), $this->user),
str_replace("\n", '<br />', phutil_escape_html($message.$more)),
);
if ($this->combinedLog) {
array_unshift(
$row,
phutil_render_tag(
'a',
array(
'href' => '/daemon/log/'.$event->getLogID().'/',
),
phutil_escape_html('Daemon '.$event->getLogID())));
}
$rows[] = $row;
}
$classes = array(
'',
'',
'right',
'wide wrap',
);
$headers = array(
'Type',
'Date',
'Time',
'Message',
);
if ($this->combinedLog) {
array_unshift($classes, 'pri');
array_unshift($headers, 'Daemon');
}
$log_table = new AphrontTableView($rows);
$log_table->setHeaders($headers);
$log_table->setColumnClasses($classes);
return $log_table->render();
}
}
diff --git a/src/applications/daemon/view/daemonloglist/PhabricatorDaemonLogListView.php b/src/applications/daemon/view/daemonloglist/PhabricatorDaemonLogListView.php
index 3f9abb8cdd..02ae2b4557 100644
--- a/src/applications/daemon/view/daemonloglist/PhabricatorDaemonLogListView.php
+++ b/src/applications/daemon/view/daemonloglist/PhabricatorDaemonLogListView.php
@@ -1,117 +1,118 @@
<?php
/*
- * Copyright 2011 Facebook, Inc.
+ * Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class PhabricatorDaemonLogListView extends AphrontView {
private $daemonLogs;
private $user;
public function setDaemonLogs(array $daemon_logs) {
$this->daemonLogs = $daemon_logs;
+ return $this;
}
public function setUser(PhabricatorUser $user) {
$this->user = $user;
return $this;
}
public function render() {
$rows = array();
if (!$this->user) {
throw new Exception("Call setUser() before rendering!");
}
foreach ($this->daemonLogs as $log) {
$epoch = $log->getDateCreated();
if ($log->getHost() == php_uname('n')) {
$pid = $log->getPID();
$is_running = PhabricatorDaemonReference::isProcessRunning($pid);
if ($is_running) {
$running = phutil_render_tag(
'span',
array(
'style' => 'color: #00cc00',
'title' => 'Running',
),
'&bull;');
} else {
$running = phutil_render_tag(
'span',
array(
'style' => 'color: #cc0000',
'title' => 'Not running',
),
'&bull;');
}
} else {
$running = phutil_render_tag(
'span',
array(
'style' => 'color: #888888',
'title' => 'Not on this host',
),
'?');
}
$rows[] = array(
$running,
phutil_escape_html($log->getDaemon()),
phutil_escape_html($log->getHost()),
$log->getPID(),
phabricator_date($epoch, $this->user),
phabricator_time($epoch, $this->user),
phutil_render_tag(
'a',
array(
'href' => '/daemon/log/'.$log->getID().'/',
'class' => 'button small grey',
),
'View Log'),
);
}
$daemon_table = new AphrontTableView($rows);
$daemon_table->setHeaders(
array(
'',
'Daemon',
'Host',
'PID',
'Date',
'Time',
'View',
));
$daemon_table->setColumnClasses(
array(
'',
'wide wrap',
'',
'',
'',
'right',
'action',
));
return $daemon_table->render();
}
}
diff --git a/src/applications/differential/view/addcomment/DifferentialAddCommentView.php b/src/applications/differential/view/addcomment/DifferentialAddCommentView.php
index 5d8c57a581..97a425eda6 100644
--- a/src/applications/differential/view/addcomment/DifferentialAddCommentView.php
+++ b/src/applications/differential/view/addcomment/DifferentialAddCommentView.php
@@ -1,253 +1,255 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class DifferentialAddCommentView extends AphrontView {
private $revision;
private $actions;
private $actionURI;
private $user;
private $draft;
public function setRevision($revision) {
$this->revision = $revision;
return $this;
}
public function setActions(array $actions) {
$this->actions = $actions;
return $this;
}
public function setActionURI($uri) {
$this->actionURI = $uri;
+ return $this;
}
public function setUser(PhabricatorUser $user) {
$this->user = $user;
+ return $this;
}
public function setDraft($draft) {
$this->draft = $draft;
return $this;
}
private function generateWarningView(
$status,
array $titles,
$id,
$content) {
$warning = new AphrontErrorView();
$warning->setSeverity(AphrontErrorView::SEVERITY_ERROR);
$warning->setWidth(AphrontErrorView::WIDTH_WIDE);
$warning->setID($id);
$warning->appendChild($content);
$warning->setTitle(idx($titles, $status, 'Warning'));
return $warning;
}
public function render() {
require_celerity_resource('differential-revision-add-comment-css');
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
$revision = $this->revision;
$form = new AphrontFormView();
$form
->setWorkflow(true)
->setUser($this->user)
->setAction($this->actionURI)
->addHiddenInput('revision_id', $revision->getID())
->appendChild(
id(new AphrontFormSelectControl())
->setLabel('Action')
->setName('action')
->setID('comment-action')
->setOptions($this->actions))
->appendChild(
id(new AphrontFormTokenizerControl())
->setLabel('Add Reviewers')
->setName('reviewers')
->setControlID('add-reviewers')
->setControlStyle('display: none')
->setID('add-reviewers-tokenizer')
->setDisableBehavior(true))
->appendChild(
id(new AphrontFormTokenizerControl())
->setLabel('Add CCs')
->setName('ccs')
->setControlID('add-ccs')
->setControlStyle('display: none')
->setID('add-ccs-tokenizer')
->setDisableBehavior(true))
->appendChild(
id(new AphrontFormTextAreaControl())
->setName('comment')
->setID('comment-content')
->setLabel('Comment')
->setEnableDragAndDropFileUploads(true)
->setValue($this->draft)
->setCaption(phutil_render_tag(
'a',
array(
'href' => PhabricatorEnv::getDoclink(
'article/Remarkup_Reference.html'),
'tabindex' => '-1',
'target' => '_blank',
),
'Formatting Reference')))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue($is_serious ? 'Submit' : 'Clowncopterize'));
Javelin::initBehavior(
'differential-add-reviewers-and-ccs',
array(
'dynamic' => array(
'add-reviewers-tokenizer' => array(
'actions' => array('request_review' => 1, 'add_reviewers' => 1),
'src' => '/typeahead/common/users/',
'row' => 'add-reviewers',
'ondemand' => PhabricatorEnv::getEnvConfig('tokenizer.ondemand'),
'placeholder' => 'Type a user name...',
),
'add-ccs-tokenizer' => array(
'actions' => array('add_ccs' => 1),
'src' => '/typeahead/common/mailable/',
'row' => 'add-ccs',
'ondemand' => PhabricatorEnv::getEnvConfig('tokenizer.ondemand'),
'placeholder' => 'Type a user or mailing list...',
),
),
'select' => 'comment-action',
));
$diff = $revision->loadActiveDiff();
$lint_warning = null;
$unit_warning = null;
if ($diff->getLintStatus() >= DifferentialLintStatus::LINT_WARN) {
$titles =
array(
DifferentialLintStatus::LINT_WARN => 'Lint Warning',
DifferentialLintStatus::LINT_FAIL => 'Lint Failure',
DifferentialLintStatus::LINT_SKIP => 'Lint Skipped'
);
if ($diff->getLintStatus() == DifferentialLintStatus::LINT_SKIP) {
$content =
"<p>This diff was created without running lint. Make sure you are ".
"OK with that before you accept this diff.</p>";
} else {
$content =
"<p>This diff has Lint Problems. Make sure you are OK with them ".
"before you accept this diff.</p>";
}
$lint_warning = $this->generateWarningView(
$diff->getLintStatus(),
$titles,
'lint-warning',
$content);
}
if ($diff->getUnitStatus() >= DifferentialUnitStatus::UNIT_WARN) {
$titles =
array(
DifferentialUnitStatus::UNIT_WARN => 'Unit Tests Warning',
DifferentialUnitStatus::UNIT_FAIL => 'Unit Tests Failure',
DifferentialUnitStatus::UNIT_SKIP => 'Unit Tests Skipped',
DifferentialUnitStatus::UNIT_POSTPONED => 'Unit Tests Postponed'
);
if ($diff->getUnitStatus() == DifferentialUnitStatus::UNIT_POSTPONED) {
$content =
"<p>This diff has postponed unit tests. The results should be ".
"coming in soon. You should probably wait for them before accepting ".
"this diff.</p>";
} else if ($diff->getUnitStatus() == DifferentialUnitStatus::UNIT_SKIP) {
$content =
"<p>Unit tests were skipped when this diff was created. Make sure ".
"you are OK with that before you accept this diff.</p>";
} else {
$content =
"<p>This diff has Unit Test Problems. Make sure you are OK with ".
"them before you accept this diff.</p>";
}
$unit_warning = $this->generateWarningView(
$diff->getUnitStatus(),
$titles,
'unit-warning',
$content);
}
Javelin::initBehavior(
'differential-accept-with-errors',
array(
'select' => 'comment-action',
'lint_warning' => $lint_warning ? 'lint-warning' : null,
'unit_warning' => $unit_warning ? 'unit-warning' : null,
));
$rev_id = $revision->getID();
Javelin::initBehavior(
'differential-feedback-preview',
array(
'uri' => '/differential/comment/preview/'.$rev_id.'/',
'preview' => 'comment-preview',
'action' => 'comment-action',
'content' => 'comment-content',
'previewTokenizers' => array(
'reviewers' => 'add-reviewers-tokenizer',
'ccs' => 'add-ccs-tokenizer',
),
'inlineuri' => '/differential/comment/inline/preview/'.$rev_id.'/',
'inline' => 'inline-comment-preview',
));
$panel_view = new AphrontPanelView();
$panel_view->appendChild($form);
if ($lint_warning) {
$panel_view->appendChild($lint_warning);
}
if ($unit_warning) {
$panel_view->appendChild($unit_warning);
}
$panel_view->setHeader($is_serious ? 'Add Comment' : 'Leap Into Action');
$panel_view->addClass('aphront-panel-accent');
$panel_view->addClass('aphront-panel-flush');
return
'<div class="differential-add-comment-panel">'.
$panel_view->render().
'<div class="aphront-panel-preview aphront-panel-flush">'.
'<div id="comment-preview">'.
'<span class="aphront-panel-preview-loading-text">'.
'Loading comment preview...'.
'</span>'.
'</div>'.
'<div id="inline-comment-preview">'.
'</div>'.
'</div>'.
'</div>';
}
}
diff --git a/src/applications/differential/view/inlinecomment/DifferentialInlineCommentView.php b/src/applications/differential/view/inlinecomment/DifferentialInlineCommentView.php
index 930abcaa83..e420afa57d 100644
--- a/src/applications/differential/view/inlinecomment/DifferentialInlineCommentView.php
+++ b/src/applications/differential/view/inlinecomment/DifferentialInlineCommentView.php
@@ -1,264 +1,265 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class DifferentialInlineCommentView extends AphrontView {
private $inlineComment;
private $onRight;
private $buildScaffolding;
private $handles;
private $markupEngine;
private $editable;
private $preview;
public function setInlineComment(PhabricatorInlineCommentInterface $comment) {
$this->inlineComment = $comment;
return $this;
}
public function setOnRight($on_right) {
$this->onRight = $on_right;
return $this;
}
public function setBuildScaffolding($scaffold) {
$this->buildScaffolding = $scaffold;
return $this;
}
public function setHandles(array $handles) {
$this->handles = $handles;
return $this;
}
public function setMarkupEngine(PhutilMarkupEngine $engine) {
$this->markupEngine = $engine;
return $this;
}
public function setEditable($editable) {
$this->editable = $editable;
return $this;
}
public function setPreview($preview) {
$this->preview = $preview;
+ return $this;
}
public function render() {
$inline = $this->inlineComment;
$start = $inline->getLineNumber();
$length = $inline->getLineLength();
if ($length) {
$end = $start + $length;
$line = 'Lines '.number_format($start).'-'.number_format($end);
} else {
$line = 'Line '.number_format($start);
}
$metadata = array(
'id' => $inline->getID(),
'number' => $inline->getLineNumber(),
'length' => $inline->getLineLength(),
'on_right' => $this->onRight,
'original' => $inline->getContent(),
);
$sigil = 'differential-inline-comment';
$content = $inline->getContent();
$handles = $this->handles;
$links = array();
$is_synthetic = false;
if ($inline->getSyntheticAuthor()) {
$is_synthetic = true;
}
$is_draft = false;
if ($inline->isDraft() && !$is_synthetic) {
$links[] = 'Not Submitted Yet';
$is_draft = true;
}
if (!$this->preview) {
$links[] = javelin_render_tag(
'a',
array(
'href' => '#',
'mustcapture' => true,
'sigil' => 'differential-inline-prev',
),
'Previous');
$links[] = javelin_render_tag(
'a',
array(
'href' => '#',
'mustcapture' => true,
'sigil' => 'differential-inline-next',
),
'Next');
if (!$is_synthetic) {
// NOTE: No product reason why you can't reply to these, but the reply
// mechanism currently sends the inline comment ID to the server, not
// file/line information, and synthetic comments don't have an inline
// comment ID.
$links[] = javelin_render_tag(
'a',
array(
'href' => '#',
'mustcapture' => true,
'sigil' => 'differential-inline-reply',
),
'Reply');
}
}
$anchor_name = 'inline-'.$inline->getID();
if ($this->editable && !$this->preview) {
$links[] = javelin_render_tag(
'a',
array(
'href' => '#',
'mustcapture' => true,
'sigil' => 'differential-inline-edit',
),
'Edit');
$links[] = javelin_render_tag(
'a',
array(
'href' => '#',
'mustcapture' => true,
'sigil' => 'differential-inline-delete',
),
'Delete');
} else if ($this->preview) {
$links[] = javelin_render_tag(
'a',
array(
'meta' => array(
'anchor' => $anchor_name,
),
'sigil' => 'differential-inline-preview-jump',
),
'Not Visible');
}
if ($links) {
$links =
'<span class="differential-inline-comment-links">'.
implode(' &middot; ', $links).
'</span>';
} else {
$links = null;
}
$cache = $inline->getCache();
if (strlen($cache)) {
$content = $cache;
} else {
$content = $this->markupEngine->markupText($content);
if ($inline->getID()) {
$inline->setCache($content);
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
$inline->save();
unset($unguarded);
}
}
if ($this->preview) {
$anchor = null;
} else {
$anchor = phutil_render_tag(
'a',
array(
'name' => $anchor_name,
'id' => $anchor_name,
'class' => 'differential-inline-comment-anchor',
),
'');
}
$classes = array(
'differential-inline-comment',
);
if ($is_draft) {
$classes[] = 'differential-inline-comment-unsaved-draft';
}
if ($is_synthetic) {
$classes[] = 'differential-inline-comment-synthetic';
}
$classes = implode(' ', $classes);
if ($is_synthetic) {
$author = $inline->getSyntheticAuthor();
} else {
$author = $handles[$inline->getAuthorPHID()]->getName();
}
$markup = javelin_render_tag(
'div',
array(
'class' => $classes,
'sigil' => $sigil,
'meta' => $metadata,
),
'<div class="differential-inline-comment-head">'.
$anchor.
$links.
' <span class="differential-inline-comment-line">'.$line.'</span> '.
phutil_escape_html($author).
'</div>'.
'<div class="differential-inline-comment-content">'.
'<div class="phabricator-remarkup">'.
$content.
'</div>'.
'</div>');
return $this->scaffoldMarkup($markup);
}
private function scaffoldMarkup($markup) {
if (!$this->buildScaffolding) {
return $markup;
}
$left_markup = !$this->onRight ? $markup : '';
$right_markup = $this->onRight ? $markup : '';
return
'<table>'.
'<tr class="inline">'.
'<th></th>'.
'<td>'.$left_markup.'</td>'.
'<th></th>'.
'<td>'.$right_markup.'</td>'.
'</tr>'.
'</table>';
}
}
diff --git a/src/applications/diffusion/query/filecontent/base/DiffusionFileContentQuery.php b/src/applications/diffusion/query/filecontent/base/DiffusionFileContentQuery.php
index 17d7668237..6b291c348f 100644
--- a/src/applications/diffusion/query/filecontent/base/DiffusionFileContentQuery.php
+++ b/src/applications/diffusion/query/filecontent/base/DiffusionFileContentQuery.php
@@ -1,117 +1,118 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
abstract class DiffusionFileContentQuery extends DiffusionQuery {
private $needsBlame;
private $fileContent;
final public static function newFromDiffusionRequest(
DiffusionRequest $request) {
return parent::newQueryObject(__CLASS__, $request);
}
public function getSupportsBlameOnBlame() {
return false;
}
public function getPrevRev($rev) {
// TODO: support git once the 'parent' info of a commit is saved
// to the database.
throw new Exception("Unsupported VCS!");
}
final public function loadFileContent() {
$this->fileContent = $this->executeQuery();
}
final public function getRawData() {
return $this->fileContent->getCorpus();
}
final public function getBlameData() {
$raw_data = $this->getRawData();
$text_list = array();
$rev_list = array();
$blame_dict = array();
if (!$this->getNeedsBlame()) {
$text_list = explode("\n", rtrim($raw_data));
} else {
foreach (explode("\n", rtrim($raw_data)) as $k => $line) {
list($rev_id, $author, $text) = $this->tokenizeLine($line);
$text_list[$k] = $text;
$rev_list[$k] = $rev_id;
if (!isset($blame_dict[$rev_id]) &&
!isset($blame_dict[$rev_id]['author'] )) {
$blame_dict[$rev_id]['author'] = $author;
}
}
$repository = $this->getRequest()->getRepository();
$commits = id(new PhabricatorRepositoryCommit())->loadAllWhere(
'repositoryID = %d AND commitIdentifier IN (%Ls)', $repository->getID(),
array_unique($rev_list));
foreach ($commits as $commit) {
$blame_dict[$commit->getCommitIdentifier()]['epoch'] =
$commit->getEpoch();
}
$commits_data = array();
if ($commits) {
$commits_data = id(new PhabricatorRepositoryCommitData())->loadAllWhere(
'commitID IN (%Ls)',
mpull($commits, 'getID'));
}
$phids = array();
foreach ($commits_data as $data) {
$phids[] = $data->getCommitDetail('authorPHID');
}
$handles = id(new PhabricatorObjectHandleData(array_unique($phids)))
->loadHandles();
foreach ($commits_data as $data) {
if ($data->getCommitDetail('authorPHID')) {
$commit_identifier =
$commits[$data->getCommitID()]->getCommitIdentifier();
$blame_dict[$commit_identifier]['handle'] =
$handles[$data->getCommitDetail('authorPHID')];
}
}
}
return array($text_list, $rev_list, $blame_dict);
}
abstract protected function tokenizeLine($line);
public function setNeedsBlame($needs_blame) {
$this->needsBlame = $needs_blame;
+ return $this;
}
public function getNeedsBlame() {
return $this->needsBlame;
}
}
diff --git a/src/applications/diffusion/view/emptyresult/DiffusionEmptyResultView.php b/src/applications/diffusion/view/emptyresult/DiffusionEmptyResultView.php
index ce1023ef0f..a6a0144471 100644
--- a/src/applications/diffusion/view/emptyresult/DiffusionEmptyResultView.php
+++ b/src/applications/diffusion/view/emptyresult/DiffusionEmptyResultView.php
@@ -1,100 +1,102 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class DiffusionEmptyResultView extends DiffusionView {
private $browseQuery;
private $view;
public function setBrowseQuery($browse_query) {
$this->browseQuery = $browse_query;
+ return $this;
}
public function setView($view) {
$this->view = $view;
+ return $this;
}
public function render() {
$drequest = $this->getDiffusionRequest();
$commit = $drequest->getCommit();
$callsign = $drequest->getRepository()->getCallsign();
if ($commit) {
$commit = "r{$callsign}{$commit}";
} else {
$commit = 'HEAD';
}
switch ($this->browseQuery->getReasonForEmptyResultSet()) {
case DiffusionBrowseQuery::REASON_IS_NONEXISTENT:
$title = 'Path Does Not Exist';
// TODO: Under git, this error message should be more specific. It
// may exist on some other branch.
$body = "This path does not exist anywhere.";
$severity = AphrontErrorView::SEVERITY_ERROR;
break;
case DiffusionBrowseQuery::REASON_IS_EMPTY:
$title = 'Empty Directory';
$body = "This path was an empty directory at {$commit}.\n";
$severity = AphrontErrorView::SEVERITY_NOTICE;
break;
case DiffusionBrowseQuery::REASON_IS_DELETED:
$deleted = $this->browseQuery->getDeletedAtCommit();
$existed = $this->browseQuery->getExistedAtCommit();
$deleted = self::linkCommit($drequest->getRepository(), $deleted);
$browse = $this->linkBrowse(
$drequest->getPath(),
array(
'text' => 'existed',
'commit' => $existed,
'params' => array('view' => $this->view),
)
);
$existed = "r{$callsign}{$existed}";
$title = 'Path Was Deleted';
$body = "This path does not exist at {$commit}. It was deleted in ".
"{$deleted} and last {$browse} at {$existed}.";
$severity = AphrontErrorView::SEVERITY_WARNING;
break;
case DiffusionBrowseQuery::REASON_IS_UNTRACKED_PARENT:
$subdir = $drequest->getRepository()->getDetail('svn-subpath');
$title = 'Directory Not Tracked';
$body =
"This repository is configured to track only one subdirectory ".
"of the entire repository ('".phutil_escape_html($subdir)."'), ".
"but you aren't looking at something in that subdirectory, so no ".
"information is available.";
$severity = AphrontErrorView::SEVERITY_WARNING;
break;
default:
throw new Exception("Unknown failure reason!");
}
$error_view = new AphrontErrorView();
$error_view->setSeverity($severity);
$error_view->setTitle($title);
$error_view->appendChild('<p>'.$body.'</p>');
return $error_view->render();
}
}
diff --git a/src/applications/maniphest/auxiliaryfield/base/ManiphestAuxiliaryFieldSpecification.php b/src/applications/maniphest/auxiliaryfield/base/ManiphestAuxiliaryFieldSpecification.php
index 0da07f8ead..92a119b149 100644
--- a/src/applications/maniphest/auxiliaryfield/base/ManiphestAuxiliaryFieldSpecification.php
+++ b/src/applications/maniphest/auxiliaryfield/base/ManiphestAuxiliaryFieldSpecification.php
@@ -1,139 +1,143 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @group maniphest
*/
abstract class ManiphestAuxiliaryFieldSpecification {
const RENDER_TARGET_HTML = 'html';
const RENDER_TARGET_TEXT = 'text';
private $label;
private $auxiliaryKey;
private $caption;
private $value;
public function setLabel($val) {
$this->label = $val;
+ return $this;
}
public function getLabel() {
return $this->label;
}
public function setAuxiliaryKey($val) {
$this->auxiliaryKey = $val;
+ return $this;
}
public function getAuxiliaryKey() {
return $this->auxiliaryKey;
}
public function setCaption($val) {
$this->caption = $val;
+ return $this;
}
public function getCaption() {
return $this->caption;
}
public function setValue($val) {
$this->value = $val;
+ return $this;
}
public function getValue() {
return $this->value;
}
public function validate() {
return true;
}
public function isRequired() {
return false;
}
- public function setType($val)
- {
+ public function setType($val) {
$this->type = $val;
+ return $this;
}
public function getType() {
return $this->type;
}
public function renderControl() {
return null;
}
public function renderForDetailView() {
return phutil_escape_html($this->getValue());
}
/**
* Render a verb to appear in email titles when a transaction involving this
* field occurs. Specifically, Maniphest emails are formatted like this:
*
* [Maniphest] [Verb Here] TNNN: Task title here
* ^^^^^^^^^
*
* You should optionally return a title-case verb or short phrase like
* "Created", "Retitled", "Closed", "Resolved", "Commented On",
* "Lowered Priority", etc., which describes the transaction.
*
* @param ManiphestTransaction The transaction which needs description.
* @return string|null A short description of the transaction.
*/
public function renderTransactionEmailVerb(
ManiphestTransaction $transaction) {
return null;
}
/**
* Render a short description of the transaction, to appear above comments
* in the Maniphest transaction log. The string will be rendered after the
* acting user's name. Examples are:
*
* added a comment
* added alincoln to CC
* claimed this task
* created this task
* closed this task out of spite
*
* You should return a similar string, describing the transaction.
*
* Note the ##$target## parameter -- Maniphest needs to render transaction
* descriptions for different targets, like web and email. This method will
* be called with a ##ManiphestAuxiliaryFieldSpecification::RENDER_TARGET_*##
* constant describing the intended target.
*
* @param ManiphestTransaction The transaction which needs description.
* @param const Constant describing the rendering target (e.g., html or text).
* @return string|null Description of the transaction.
*/
public function renderTransactionDescription(
ManiphestTransaction $transaction,
$target) {
return 'updated a custom field';
}
}
diff --git a/src/applications/maniphest/auxiliaryfield/default/ManiphestAuxiliaryFieldDefaultSpecification.php b/src/applications/maniphest/auxiliaryfield/default/ManiphestAuxiliaryFieldDefaultSpecification.php
index 90db5fd9bf..658fd1f6d3 100644
--- a/src/applications/maniphest/auxiliaryfield/default/ManiphestAuxiliaryFieldDefaultSpecification.php
+++ b/src/applications/maniphest/auxiliaryfield/default/ManiphestAuxiliaryFieldDefaultSpecification.php
@@ -1,227 +1,227 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @group maniphest
*/
class ManiphestAuxiliaryFieldDefaultSpecification
extends ManiphestAuxiliaryFieldSpecification {
private $required;
private $fieldType;
private $selectOptions;
private $checkboxLabel;
private $checkboxValue;
private $error;
const TYPE_SELECT = 'select';
const TYPE_STRING = 'string';
const TYPE_INT = 'int';
const TYPE_BOOL = 'bool';
public function getFieldType() {
return $this->fieldType;
}
public function setFieldType($val) {
$this->fieldType = $val;
return $this;
}
public function getError() {
return $this->error;
}
public function setError($val) {
$this->error = $val;
return $this;
}
public function getSelectOptions() {
return $this->selectOptions;
}
public function setSelectOptions($array) {
$this->selectOptions = $array;
return $this;
}
public function setRequired($bool) {
$this->required = $bool;
return $this;
}
public function isRequired() {
return $this->required;
}
public function setCheckboxLabel($checkbox_label) {
$this->checkboxLabel = $checkbox_label;
return $this;
}
public function getCheckboxLabel() {
return $this->checkboxLabel;
}
public function setCheckboxValue($checkbox_value) {
$this->checkboxValue = $checkbox_value;
return $this;
}
public function getCheckboxValue() {
return $this->checkboxValue;
}
public function renderControl() {
$control = null;
$type = $this->getFieldType();
switch ($type) {
case self::TYPE_INT:
$control = new AphrontFormTextControl();
break;
case self::TYPE_STRING:
$control = new AphrontFormTextControl();
break;
case self::TYPE_SELECT:
$control = new AphrontFormSelectControl();
$control->setOptions($this->getSelectOptions());
break;
case self::TYPE_BOOL:
$control = new AphrontFormCheckboxControl();
break;
default:
$label = $this->getLabel();
throw new ManiphestAuxiliaryFieldTypeException(
"Field type '{$type}' is not a valid type (for field '{$label}').");
break;
}
if ($type == self::TYPE_BOOL) {
$control->addCheckbox(
'auxiliary['.$this->getAuxiliaryKey().']',
1,
$this->getCheckboxLabel(),
(bool)$this->getValue());
} else {
$control->setValue($this->getValue());
$control->setName('auxiliary['.$this->getAuxiliaryKey().']');
}
$control->setLabel($this->getLabel());
$control->setCaption($this->getCaption());
$control->setError($this->getError());
return $control;
}
public function setValueFromRequest($request) {
$aux_post_values = $request->getArr('auxiliary');
- $this->setValue(idx($aux_post_values, $this->getAuxiliaryKey(), ''));
+ return $this->setValue(idx($aux_post_values, $this->getAuxiliaryKey(), ''));
}
public function getValueForStorage() {
return $this->getValue();
}
public function setValueFromStorage($value) {
- $this->setValue($value);
+ return $this->setValue($value);
}
public function validate() {
switch ($this->getFieldType()) {
case self::TYPE_INT:
if (!is_numeric($this->getValue())) {
throw new ManiphestAuxiliaryFieldValidationException(
$this->getLabel().' must be an integer value.'
);
}
break;
case self::TYPE_BOOL:
return true;
case self::TYPE_STRING:
return true;
case self::TYPE_SELECT:
return true;
}
}
public function renderForDetailView() {
switch ($this->getFieldType()) {
case self::TYPE_BOOL:
if ($this->getValue()) {
return phutil_escape_html($this->getCheckboxValue());
} else {
return null;
}
case self::TYPE_SELECT:
$display = idx($this->getSelectOptions(), $this->getValue());
return phutil_escape_html($display);
}
return parent::renderForDetailView();
}
public function renderTransactionDescription(
ManiphestTransaction $transaction,
$target) {
$label = $this->getLabel();
$old = $transaction->getOldValue();
$new = $transaction->getNewValue();
switch ($this->getFieldType()) {
case self::TYPE_BOOL:
if ($new) {
$desc = "set field '{$label}' true";
} else {
$desc = "set field '{$label}' false";
}
break;
case self::TYPE_SELECT:
$old_display = idx($this->getSelectOptions(), $old);
$new_display = idx($this->getSelectOptions(), $new);
if ($old === null) {
$desc = "set field '{$label}' to '{$new_display}'";
} else {
$desc = "changed field '{$label}' ".
"from '{$old_display}' to '{$new_display}'";
}
break;
default:
if (!strlen($old)) {
if (!strlen($new)) {
return null;
}
$desc = "set field '{$label}' to '{$new}'";
} else {
$desc = "updated '{$label}' ".
"from '{$old}' to '{$new}'";
}
break;
}
if ($target == self::RENDER_TARGET_HTML) {
$desc = phutil_escape_html($desc);
}
return $desc;
}
}
diff --git a/src/applications/project/editor/project/PhabricatorProjectEditor.php b/src/applications/project/editor/project/PhabricatorProjectEditor.php
index ab6e92a9d0..00ee8478e8 100644
--- a/src/applications/project/editor/project/PhabricatorProjectEditor.php
+++ b/src/applications/project/editor/project/PhabricatorProjectEditor.php
@@ -1,236 +1,237 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class PhabricatorProjectEditor {
private $project;
private $user;
private $projectName;
private $addAffiliations;
private $remAffiliations;
public function __construct(PhabricatorProject $project) {
$this->project = $project;
}
public function setUser(PhabricatorUser $user) {
$this->user = $user;
return $this;
}
public function applyTransactions(array $transactions) {
if (!$this->user) {
throw new Exception('Call setUser() before save()!');
}
$user = $this->user;
$project = $this->project;
$is_new = !$project->getID();
if ($is_new) {
$project->setAuthorPHID($user->getPHID());
}
foreach ($transactions as $key => $xaction) {
$type = $xaction->getTransactionType();
$this->setTransactionOldValue($project, $xaction);
if (!$this->transactionHasEffect($xaction)) {
unset($transactions[$key]);
continue;
}
$this->applyTransactionEffect($project, $xaction);
}
if (!$transactions) {
return $this;
}
try {
$project->save();
foreach ($transactions as $xaction) {
$xaction->setAuthorPHID($user->getPHID());
$xaction->setProjectID($project->getID());
$xaction->save();
}
foreach ($this->remAffiliations as $affil) {
$affil->delete();
}
foreach ($this->addAffiliations as $affil) {
$affil->setProjectPHID($project->getPHID());
$affil->save();
}
foreach ($transactions as $xaction) {
$this->publishTransactionStory($project, $xaction);
}
} catch (AphrontQueryDuplicateKeyException $ex) {
// We already validated the slug, but might race. Try again to see if
// that's the issue. If it is, we'll throw a more specific exception. If
// not, throw the original exception.
$this->validateName($project);
throw $ex;
}
// TODO: If we rename a project, we should move its Phriction page. Do
// that once Phriction supports document moves.
return $this;
}
private function validateName(PhabricatorProject $project) {
$slug = $project->getPhrictionSlug();
$name = $project->getName();
if ($slug == '/') {
throw new PhabricatorProjectNameCollisionException(
"Project names must be unique and contain some letters or numbers.");
}
$id = $project->getID();
$collision = id(new PhabricatorProject())->loadOneWhere(
'(name = %s OR phrictionSlug = %s) AND id %Q %nd',
$name,
$slug,
$id ? '!=' : 'IS NOT',
$id ? $id : null);
if ($collision) {
$other_name = $collision->getName();
$other_id = $collision->getID();
throw new PhabricatorProjectNameCollisionException(
"Project names must be unique. The name '{$name}' is too similar to ".
"the name of another project, '{$other_name}' (Project ID: ".
"{$other_id}). Choose a unique name.");
}
}
private function setTransactionOldValue(
PhabricatorProject $project,
PhabricatorProjectTransaction $xaction) {
$type = $xaction->getTransactionType();
switch ($type) {
case PhabricatorProjectTransactionType::TYPE_NAME:
$xaction->setOldValue($project->getName());
break;
case PhabricatorProjectTransactionType::TYPE_STATUS:
$xaction->setOldValue($project->getStatus());
break;
case PhabricatorProjectTransactionType::TYPE_MEMBERS:
$affils = $project->loadAffiliations();
$project->attachAffiliations($affils);
$old_value = mpull($affils, 'getUserPHID');
$old_value = array_values($old_value);
$xaction->setOldValue($old_value);
$new_value = $xaction->getNewValue();
$new_value = array_filter($new_value);
$new_value = array_unique($new_value);
$new_value = array_values($new_value);
$xaction->setNewValue($new_value);
break;
default:
throw new Exception("Unknown transaction type '{$type}'!");
}
+ return $this;
}
private function applyTransactionEffect(
PhabricatorProject $project,
PhabricatorProjectTransaction $xaction) {
$type = $xaction->getTransactionType();
switch ($type) {
case PhabricatorProjectTransactionType::TYPE_NAME:
$project->setName($xaction->getNewValue());
$project->setPhrictionSlug($xaction->getNewValue());
$this->validateName($project);
break;
case PhabricatorProjectTransactionType::TYPE_STATUS:
$project->setStatus($xaction->getNewValue());
break;
case PhabricatorProjectTransactionType::TYPE_MEMBERS:
$old = array_fill_keys($xaction->getOldValue(), true);
$new = array_fill_keys($xaction->getNewValue(), true);
$add = array();
$rem = array();
foreach ($project->getAffiliations() as $affil) {
if (empty($new[$affil->getUserPHID()])) {
$rem[] = $affil;
}
}
foreach ($new as $phid => $ignored) {
if (empty($old[$phid])) {
$affil = new PhabricatorProjectAffiliation();
$affil->setRole('');
$affil->setUserPHID($phid);
$add[] = $affil;
}
}
$this->addAffiliations = $add;
$this->remAffiliations = $rem;
break;
default:
throw new Exception("Unknown transaction type '{$type}'!");
}
}
private function publishTransactionStory(
PhabricatorProject $project,
PhabricatorProjectTransaction $xaction) {
$related_phids = array(
$project->getPHID(),
$xaction->getAuthorPHID(),
);
id(new PhabricatorFeedStoryPublisher())
->setStoryType(PhabricatorFeedStoryTypeConstants::STORY_PROJECT)
->setStoryData(
array(
'projectPHID' => $project->getPHID(),
'transactionID' => $xaction->getID(),
'type' => $xaction->getTransactionType(),
'old' => $xaction->getOldValue(),
'new' => $xaction->getNewValue(),
))
->setStoryTime(time())
->setStoryAuthorPHID($xaction->getAuthorPHID())
->setRelatedPHIDs($related_phids)
->publish();
}
private function transactionHasEffect(
PhabricatorProjectTransaction $xaction) {
return ($xaction->getOldValue() !== $xaction->getNewValue());
}
}
diff --git a/src/infrastructure/celerity/graph/CelerityResourceGraph.php b/src/infrastructure/celerity/graph/CelerityResourceGraph.php
index 81b2dfbae8..9d6c8f6865 100644
--- a/src/infrastructure/celerity/graph/CelerityResourceGraph.php
+++ b/src/infrastructure/celerity/graph/CelerityResourceGraph.php
@@ -1,47 +1,48 @@
<?php
/*
- * Copyright 2011 Facebook, Inc.
+ * Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class CelerityResourceGraph extends AbstractDirectedGraph {
private $resourceGraph = array();
private $graphSet = false;
protected function loadEdges(array $nodes) {
if (!$this->graphSet) {
throw new Exception(
"Call setResourceGraph before loading the graph!"
);
}
$graph = $this->getResourceGraph();
$edges = array();
foreach ($nodes as $node) {
$edges[$node] = idx($graph, $node, array());
}
return $edges;
}
final public function setResourceGraph(array $graph) {
$this->resourceGraph = $graph;
$this->graphSet = true;
+ return $this;
}
private function getResourceGraph() {
return $this->resourceGraph;
}
}
diff --git a/src/infrastructure/celerity/map/CelerityResourceMap.php b/src/infrastructure/celerity/map/CelerityResourceMap.php
index 5d0ec732fc..5e79b883ca 100644
--- a/src/infrastructure/celerity/map/CelerityResourceMap.php
+++ b/src/infrastructure/celerity/map/CelerityResourceMap.php
@@ -1,134 +1,135 @@
<?php
/*
- * Copyright 2011 Facebook, Inc.
+ * Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Interface to the static resource map, which is a graph of available
* resources, resource dependencies, and packaging information. You generally do
* not need to invoke it directly; instead, you call higher-level Celerity APIs
* and it uses the resource map to satisfy your requests.
*
* @group celerity
*/
final class CelerityResourceMap {
private static $instance;
private $resourceMap;
private $packageMap;
private $reverseMap;
public static function getInstance() {
if (empty(self::$instance)) {
self::$instance = new CelerityResourceMap();
$root = phutil_get_library_root('phabricator');
$ok = include_once $root.'/__celerity_resource_map__.php';
if (!$ok) {
throw new Exception("Failed to load Celerity resource map!");
}
}
return self::$instance;
}
public function setResourceMap($resource_map) {
$this->resourceMap = $resource_map;
return $this;
}
public function resolveResources(array $symbols) {
$map = array();
foreach ($symbols as $symbol) {
if (!empty($map[$symbol])) {
continue;
}
$this->resolveResource($map, $symbol);
}
return $map;
}
private function resolveResource(array &$map, $symbol) {
if (empty($this->resourceMap[$symbol])) {
throw new Exception(
"Attempting to resolve unknown Celerity resource, '{$symbol}'.");
}
$info = $this->resourceMap[$symbol];
foreach ($info['requires'] as $requires) {
if (!empty($map[$requires])) {
continue;
}
$this->resolveResource($map, $requires);
}
$map[$symbol] = $info;
}
public function setPackageMap($package_map) {
$this->packageMap = $package_map;
+ return $this;
}
public function packageResources(array $resolved_map) {
$packaged = array();
$handled = array();
foreach ($resolved_map as $symbol => $info) {
if (isset($handled[$symbol])) {
continue;
}
if (empty($this->packageMap['reverse'][$symbol])) {
$packaged[$symbol] = $info;
} else {
$package = $this->packageMap['reverse'][$symbol];
$package_info = $this->packageMap['packages'][$package];
$packaged[$package_info['name']] = $package_info;
foreach ($package_info['symbols'] as $packaged_symbol) {
$handled[$packaged_symbol] = true;
}
}
}
return $packaged;
}
public function resolvePackage($package_hash) {
$package = idx($this->packageMap['packages'], $package_hash);
if (!$package) {
return null;
}
$paths = array();
foreach ($package['symbols'] as $symbol) {
$paths[] = $this->resourceMap[$symbol]['disk'];
}
return $paths;
}
public function lookupSymbolInformation($symbol) {
return idx($this->resourceMap, $symbol);
}
public function lookupFileInformation($path) {
if (empty($this->reverseMap)) {
$this->reverseMap = array();
foreach ($this->resourceMap as $symbol => $data) {
$data['provides'] = $symbol;
$this->reverseMap[$data['disk']] = $data;
}
}
return idx($this->reverseMap, $path);
}
}
diff --git a/src/view/layout/headsup/actionlist/AphrontHeadsupActionListView.php b/src/view/layout/headsup/actionlist/AphrontHeadsupActionListView.php
index 2eb411024e..618ddab704 100644
--- a/src/view/layout/headsup/actionlist/AphrontHeadsupActionListView.php
+++ b/src/view/layout/headsup/actionlist/AphrontHeadsupActionListView.php
@@ -1,43 +1,44 @@
<?php
/*
- * Copyright 2011 Facebook, Inc.
+ * Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class AphrontHeadsupActionListView extends AphrontView {
private $actions;
public function setActions(array $actions) {
$this->actions = $actions;
+ return $this;
}
public function render() {
require_celerity_resource('aphront-headsup-action-list-view-css');
$actions = array();
foreach ($this->actions as $action_view) {
$actions[] = $action_view->render();
}
$actions = implode("\n", $actions);
return
'<div class="aphront-headsup-action-list">'.
$actions.
'</div>';
}
}

File Metadata

Mime Type
text/x-diff
Expires
Sat, Sep 20, 3:59 AM (16 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
241410
Default Alt Text
(68 KB)

Event Timeline