Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/flag/controller/PhabricatorFlagEditController.php b/src/applications/flag/controller/PhabricatorFlagEditController.php
index 17adca8be9..e8f02dc951 100644
--- a/src/applications/flag/controller/PhabricatorFlagEditController.php
+++ b/src/applications/flag/controller/PhabricatorFlagEditController.php
@@ -1,88 +1,89 @@
<?php
final class PhabricatorFlagEditController extends PhabricatorFlagController {
private $phid;
public function willProcessRequest(array $data) {
$this->phid = $data['phid'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$phid = $this->phid;
$handle = PhabricatorObjectHandleData::loadOneHandle($phid, $user);
if (!$handle->isComplete()) {
return new Aphront404Response();
}
$flag = PhabricatorFlagQuery::loadUserFlag($user, $phid);
if (!$flag) {
$flag = new PhabricatorFlag();
$flag->setOwnerPHID($user->getPHID());
$flag->setType($handle->getType());
$flag->setObjectPHID($handle->getPHID());
$flag->setReasonPHID($user->getPHID());
}
if ($request->isDialogFormPost()) {
$flag->setColor($request->getInt('color'));
$flag->setNote($request->getStr('note'));
$flag->save();
return id(new AphrontReloadResponse())->setURI('/flag/');
}
$type_name = $handle->getTypeName();
$dialog = new AphrontDialogView();
$dialog->setUser($user);
$dialog->setTitle("Flag {$type_name}");
require_celerity_resource('phabricator-flag-css');
$form = new AphrontFormLayoutView();
$is_new = !$flag->getID();
if ($is_new) {
$form
- ->appendChild(
- "<p>You can flag this {$type_name} if you want to remember to look ".
- "at it later.</p><br />");
+ ->appendChild(hsprintf(
+ "<p>You can flag this %s if you want to remember to look ".
+ "at it later.</p><br />",
+ $type_name));
}
$radio = new AphrontFormRadioButtonControl();
foreach (PhabricatorFlagColor::getColorNameMap() as $color => $text) {
$class = 'phabricator-flag-radio phabricator-flag-color-'.$color;
$radio->addButton($color, $text, '', $class);
}
$form
->appendChild(
$radio
->setName('color')
->setLabel('Flag Color')
->setValue($flag->getColor()))
->appendChild(
id(new AphrontFormTextAreaControl())
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT)
->setName('note')
->setLabel('Note')
->setValue($flag->getNote()));
$dialog->appendChild($form);
$dialog->addCancelButton($handle->getURI());
$dialog->addSubmitButton(
$is_new ? "Flag {$type_name}" : 'Save');
return id(new AphrontDialogResponse())->setDialog($dialog);
}
}
diff --git a/src/applications/ponder/view/PonderAddCommentView.php b/src/applications/ponder/view/PonderAddCommentView.php
index f23f624df7..ba26fe961e 100644
--- a/src/applications/ponder/view/PonderAddCommentView.php
+++ b/src/applications/ponder/view/PonderAddCommentView.php
@@ -1,53 +1,53 @@
<?php
final class PonderAddCommentView extends AphrontView {
private $target;
private $actionURI;
private $questionID;
public function setTarget($target) {
$this->target = $target;
return $this;
}
public function setQuestionID($id) {
$this->questionID = $id;
return $this;
}
public function setActionURI($uri) {
$this->actionURI = $uri;
return $this;
}
public function render() {
require_celerity_resource('ponder-comment-table-css');
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
$questionID = $this->questionID;
$target = $this->target;
$form = new AphrontFormView();
$form
->setUser($this->user)
->setAction($this->actionURI)
->setWorkflow(true)
->addHiddenInput('target', $target)
->addHiddenInput('question_id', $questionID)
->appendChild(
id(new AphrontFormTextAreaControl())
->setName('content'))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue($is_serious ? 'Submit' : 'Editorialize'));
$view = id(new AphrontMoreView())
->setSome('')
- ->setMore(phutil_safe_html($form->render()))
+ ->setMore($form->render())
->setExpandText('Add Comment');
return $view->render();
}
}
diff --git a/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php b/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php
index 95938fa958..44b3a06d5d 100644
--- a/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php
+++ b/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php
@@ -1,457 +1,459 @@
<?php
/**
* @group slowvote
*/
final class PhabricatorSlowvotePollController
extends PhabricatorSlowvoteController {
private $id;
public function willProcessRequest(array $data) {
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$viewer_phid = $user->getPHID();
$poll = id(new PhabricatorSlowvotePoll())->load($this->id);
if (!$poll) {
return new Aphront404Response();
}
$options = id(new PhabricatorSlowvoteOption())->loadAllWhere(
'pollID = %d',
$poll->getID());
$choices = id(new PhabricatorSlowvoteChoice())->loadAllWhere(
'pollID = %d',
$poll->getID());
$comments = id(new PhabricatorSlowvoteComment())->loadAllWhere(
'pollID = %d',
$poll->getID());
$choices_by_option = mgroup($choices, 'getOptionID');
$comments_by_user = mpull($comments, null, 'getAuthorPHID');
$choices_by_user = mgroup($choices, 'getAuthorPHID');
$viewer_choices = idx($choices_by_user, $viewer_phid, array());
$viewer_comment = idx($comments_by_user, $viewer_phid, null);
$comment_text = null;
if ($viewer_comment) {
$comment_text = $viewer_comment->getCommentText();
}
if ($request->isFormPost()) {
$comment = idx($comments_by_user, $viewer_phid, null);
if ($comment) {
$comment->delete();
}
$comment_text = $request->getStr('comments');
if (strlen($comment_text)) {
id(new PhabricatorSlowvoteComment())
->setAuthorPHID($viewer_phid)
->setPollID($poll->getID())
->setCommentText($comment_text)
->save();
}
$votes = $request->getArr('vote');
switch ($poll->getMethod()) {
case PhabricatorSlowvotePoll::METHOD_PLURALITY:
// Enforce only one vote.
$votes = array_slice($votes, 0, 1);
break;
case PhabricatorSlowvotePoll::METHOD_APPROVAL:
// No filtering.
break;
default:
throw new Exception("Unknown poll method!");
}
foreach ($viewer_choices as $viewer_choice) {
$viewer_choice->delete();
}
foreach ($votes as $vote) {
id(new PhabricatorSlowvoteChoice())
->setAuthorPHID($viewer_phid)
->setPollID($poll->getID())
->setOptionID($vote)
->save();
}
return id(new AphrontRedirectResponse())->setURI('/V'.$poll->getID());
}
require_celerity_resource('phabricator-slowvote-css');
$phids = array_merge(
mpull($choices, 'getAuthorPHID'),
mpull($comments, 'getAuthorPHID'),
array(
$poll->getAuthorPHID(),
));
$query = new PhabricatorObjectHandleData($phids);
$handles = $query->loadHandles();
$objects = $query->loadObjects();
if ($poll->getShuffle()) {
shuffle($options);
}
$option_markup = array();
foreach ($options as $option) {
$option_markup[] = $this->renderPollOption(
$poll,
$viewer_choices,
$option);
}
$comments_by_option = array();
switch ($poll->getMethod()) {
case PhabricatorSlowvotePoll::METHOD_PLURALITY:
$choice_ids = array();
foreach ($choices_by_user as $user_phid => $user_choices) {
$choice_ids[$user_phid] = head($user_choices)->getOptionID();
}
foreach ($comments as $comment) {
$choice = idx($choice_ids, $comment->getAuthorPHID());
if ($choice) {
$comments_by_option[$choice][] = $comment;
}
}
break;
case PhabricatorSlowvotePoll::METHOD_APPROVAL:
// All comments are grouped in approval voting.
break;
default:
throw new Exception("Unknown poll method!");
}
$result_markup = $this->renderResultMarkup(
$poll,
$options,
$choices,
$comments,
$viewer_choices,
$choices_by_option,
$comments_by_option,
$handles,
$objects);
if ($viewer_choices) {
$instructions =
'Your vote has been recorded... but there is still ample time to '.
'rethink your position. Have you thoroughly considered all possible '.
'eventualities?';
} else {
$instructions =
'This is a weighty matter indeed. Consider your choices with the '.
'greatest of care.';
}
$form = id(new AphrontFormView())
->setUser($user)
->appendChild(hsprintf(
'<p class="aphront-form-instructions">%s</p>',
$instructions))
->appendChild(
id(new AphrontFormMarkupControl())
->setLabel('Vote')
->setValue($option_markup))
->appendChild(
id(new AphrontFormTextAreaControl())
->setLabel('Comments')
->setHeight(AphrontFormTextAreaControl::HEIGHT_SHORT)
->setName('comments')
->setValue($comment_text))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue('Cautiously Engage in Deliberations'));
$panel = new AphrontPanelView();
$panel->setHeader(phutil_escape_html($poll->getQuestion()));
$panel->setWidth(AphrontPanelView::WIDTH_WIDE);
$panel->appendChild($form);
$panel->appendChild('<br /><br />');
$panel->appendChild($result_markup);
return $this->buildStandardPageResponse(
$panel,
array(
'title' => 'V'.$poll->getID().' '.$poll->getQuestion(),
));
}
private function renderComments(array $comments, array $handles) {
assert_instances_of($comments, 'PhabricatorSlowvoteComment');
assert_instances_of($handles, 'PhabricatorObjectHandle');
$viewer = $this->getRequest()->getUser();
$engine = PhabricatorMarkupEngine::newSlowvoteMarkupEngine();
$comment_markup = array();
foreach ($comments as $comment) {
$handle = $handles[$comment->getAuthorPHID()];
$markup = phutil_safe_html(
$engine->markupText($comment->getCommentText()));
require_celerity_resource('phabricator-remarkup-css');
- $comment_markup[] =
+ $comment_markup[] = hsprintf(
'<tr>'.
'<th>'.
- $handle->renderLink().
- '<div class="phabricator-slowvote-datestamp">'.
- phabricator_datetime($comment->getDateCreated(), $viewer).
- '</div>'.
+ '%s'.
+ '<div class="phabricator-slowvote-datestamp">%s</div>'.
+ '</th>'.
'<td>'.
- '<div class="phabricator-remarkup">'.
- $markup.
- '</div>'.
+ '<div class="phabricator-remarkup">%s</div>'.
'</td>'.
- '</tr>';
+ '</tr>',
+ $handle->renderLink(),
+ phabricator_datetime($comment->getDateCreated(), $viewer),
+ $markup);
}
if ($comment_markup) {
$comment_markup = phutil_tag(
'table',
array(
'class' => 'phabricator-slowvote-comments',
),
- new PhutilSafeHTML(implode("\n", $comment_markup)));
+ $comment_markup);
} else {
$comment_markup = null;
}
return $comment_markup;
}
private function renderPollOption(
PhabricatorSlowvotePoll $poll,
array $viewer_choices,
PhabricatorSlowvoteOption $option) {
assert_instances_of($viewer_choices, 'PhabricatorSlowvoteChoice');
$id = $option->getID();
switch ($poll->getMethod()) {
case PhabricatorSlowvotePoll::METHOD_PLURALITY:
// Render a radio button.
$selected_option = head($viewer_choices);
if ($selected_option) {
$selected = $selected_option->getOptionID();
} else {
$selected = null;
}
if ($selected == $id) {
$checked = "checked";
} else {
$checked = null;
}
$input = phutil_tag(
'input',
array(
'type' => 'radio',
'name' => 'vote[]',
'value' => $id,
'checked' => $checked,
));
break;
case PhabricatorSlowvotePoll::METHOD_APPROVAL:
// Render a check box.
$checked = null;
foreach ($viewer_choices as $choice) {
if ($choice->getOptionID() == $id) {
$checked = 'checked';
break;
}
}
$input = phutil_tag(
'input',
array(
'type' => 'checkbox',
'name' => 'vote[]',
'checked' => $checked,
'value' => $id,
));
break;
default:
throw new Exception("Unknown poll method!");
}
if ($checked) {
$checked_class = 'phabricator-slowvote-checked';
} else {
$checked_class = null;
}
return phutil_tag(
'label',
array(
'class' => 'phabricator-slowvote-label '.$checked_class,
),
array($input, $option->getName()));
}
private function renderVoteCount(
PhabricatorSlowvotePoll $poll,
array $choices,
array $chosen) {
assert_instances_of($choices, 'PhabricatorSlowvoteChoice');
assert_instances_of($chosen, 'PhabricatorSlowvoteChoice');
switch ($poll->getMethod()) {
case PhabricatorSlowvotePoll::METHOD_PLURALITY:
$out_of_total = count($choices);
break;
case PhabricatorSlowvotePoll::METHOD_APPROVAL:
// Count unique respondents for approval votes.
$out_of_total = count(mpull($choices, null, 'getAuthorPHID'));
break;
default:
throw new Exception("Unknown poll method!");
}
return sprintf(
'%d / %d (%d%%)',
number_format(count($chosen)),
number_format($out_of_total),
$out_of_total
? round(100 * count($chosen) / $out_of_total)
: 0);
}
private function renderResultMarkup(
PhabricatorSlowvotePoll $poll,
array $options,
array $choices,
array $comments,
array $viewer_choices,
array $choices_by_option,
array $comments_by_option,
array $handles,
array $objects) {
assert_instances_of($options, 'PhabricatorSlowvoteOption');
assert_instances_of($choices, 'PhabricatorSlowvoteChoice');
assert_instances_of($comments, 'PhabricatorSlowvoteComment');
assert_instances_of($viewer_choices, 'PhabricatorSlowvoteChoice');
assert_instances_of($handles, 'PhabricatorObjectHandle');
assert_instances_of($objects, 'PhabricatorLiskDAO');
$viewer_phid = $this->getRequest()->getUser()->getPHID();
$can_see_responses = false;
$need_vote = false;
switch ($poll->getResponseVisibility()) {
case PhabricatorSlowvotePoll::RESPONSES_VISIBLE:
$can_see_responses = true;
break;
case PhabricatorSlowvotePoll::RESPONSES_VOTERS:
$can_see_responses = (bool)$viewer_choices;
$need_vote = true;
break;
case PhabricatorSlowvotePoll::RESPONSES_OWNER:
$can_see_responses = ($viewer_phid == $poll->getAuthorPHID());
break;
}
$result_markup = id(new AphrontFormLayoutView())
- ->appendChild('<h1>Ongoing Deliberation</h1>');
+ ->appendChild(phutil_tag('h1', array(), 'Ongoing Deliberation'));
if (!$can_see_responses) {
if ($need_vote) {
$reason = "You must vote to see the results.";
} else {
$reason = "The results are not public.";
}
$result_markup
- ->appendChild(
- '<p class="aphront-form-instructions"><em>'.$reason.'</em></p>');
+ ->appendChild(hsprintf(
+ '<p class="aphront-form-instructions"><em>%s</em></p>',
+ $reason));
return $result_markup;
}
foreach ($options as $option) {
$id = $option->getID();
$chosen = idx($choices_by_option, $id, array());
$users = array_select_keys($handles, mpull($chosen, 'getAuthorPHID'));
if ($users) {
$user_markup = array();
foreach ($users as $handle) {
$object = idx($objects, $handle->getPHID());
if (!$object) {
continue;
}
$profile_image = $handle->getImageURI();
$user_markup[] = phutil_tag(
'a',
array(
'href' => $handle->getURI(),
'class' => 'phabricator-slowvote-facepile',
),
phutil_tag(
'img',
array(
'src' => $profile_image,
)));
}
- $user_markup = implode('', $user_markup);
} else {
$user_markup = 'This option has failed to appeal to anyone.';
}
$comment_markup = $this->renderComments(
idx($comments_by_option, $id, array()),
$handles);
$vote_count = $this->renderVoteCount(
$poll,
$choices,
$chosen);
- $result_markup->appendChild(
+ $result_markup->appendChild(hsprintf(
'<div>'.
- '<div class="phabricator-slowvote-count">'.
- $vote_count.
- '</div>'.
- '<h1>'.phutil_escape_html($option->getName()).'</h1>'.
+ '<div class="phabricator-slowvote-count">%s</div>'.
+ '<h1>%s</h1>'.
'<hr class="phabricator-slowvote-hr" />'.
- $user_markup.
- '<div style="clear: both;">'.
+ '%s'.
+ '<div style="clear: both;" />'.
'<hr class="phabricator-slowvote-hr" />'.
- $comment_markup.
- '</div>');
+ '%s'.
+ '</div>',
+ $vote_count,
+ $option->getName(),
+ phutil_tag('div', array(), $user_markup),
+ $comment_markup));
}
if ($poll->getMethod() == PhabricatorSlowvotePoll::METHOD_APPROVAL &&
$comments) {
$comment_markup = $this->renderComments(
$comments,
$handles);
$result_markup->appendChild(
- '<h1>Motions Proposed for Consideration</h1>');
+ phutil_tag('h1', array(), 'Motions Proposed for Consideration'));
$result_markup->appendChild($comment_markup);
}
return $result_markup;
}
}
diff --git a/src/view/form/AphrontFormLayoutView.php b/src/view/form/AphrontFormLayoutView.php
index 5780353475..300c7370e0 100644
--- a/src/view/form/AphrontFormLayoutView.php
+++ b/src/view/form/AphrontFormLayoutView.php
@@ -1,43 +1,43 @@
<?php
/**
* This provides the layout of an AphrontFormView without actually providing
* the <form /> tag. Useful on its own for creating forms in other forms (like
* dialogs) or forms which aren't submittable.
*/
final class AphrontFormLayoutView extends AphrontView {
private $backgroundShading;
private $padded;
public function setBackgroundShading($shading) {
$this->backgroundShading = $shading;
return $this;
}
public function setPadded($padded) {
$this->padded = $padded;
return $this;
}
public function render() {
$classes = array('aphront-form-view');
if ($this->backgroundShading) {
$classes[] = 'aphront-form-view-shaded';
}
if ($this->padded) {
$classes[] = 'aphront-form-view-padded';
}
$classes = implode(' ', $classes);
- return phutil_render_tag(
+ return phutil_tag(
'div',
array(
'class' => $classes,
),
- $this->renderChildren());
+ $this->renderHTMLChildren());
}
}
diff --git a/src/view/form/AphrontFormView.php b/src/view/form/AphrontFormView.php
index 8b0041f00a..76342830b8 100644
--- a/src/view/form/AphrontFormView.php
+++ b/src/view/form/AphrontFormView.php
@@ -1,112 +1,112 @@
<?php
final class AphrontFormView extends AphrontView {
private $action;
private $method = 'POST';
private $header;
private $data = array();
private $encType;
private $workflow;
private $id;
private $flexible;
private $sigils = array();
public function setFlexible($flexible) {
$this->flexible = $flexible;
return $this;
}
public function setID($id) {
$this->id = $id;
return $this;
}
public function setAction($action) {
$this->action = $action;
return $this;
}
public function setMethod($method) {
$this->method = $method;
return $this;
}
public function setEncType($enc_type) {
$this->encType = $enc_type;
return $this;
}
public function addHiddenInput($key, $value) {
$this->data[$key] = $value;
return $this;
}
public function setWorkflow($workflow) {
$this->workflow = $workflow;
return $this;
}
public function addSigil($sigil) {
$this->sigils[] = $sigil;
return $this;
}
public function render() {
if ($this->flexible) {
require_celerity_resource('phabricator-form-view-css');
}
require_celerity_resource('aphront-form-view-css');
$layout = new AphrontFormLayoutView();
if (!$this->flexible) {
$layout
->setBackgroundShading(true)
->setPadded(true);
}
$layout
->appendChild($this->renderDataInputs())
- ->appendChild($this->renderChildren());
+ ->appendChild($this->renderHTMLChildren());
if (!$this->user) {
throw new Exception('You must pass the user to AphrontFormView.');
}
$sigils = $this->sigils;
if ($this->workflow) {
$sigils[] = 'workflow';
}
- return phabricator_render_form(
+ return phabricator_form(
$this->user,
array(
'class' => $this->flexible ? 'phabricator-form-view' : null,
'action' => $this->action,
'method' => $this->method,
'enctype' => $this->encType,
'sigil' => $sigils ? implode(' ', $sigils) : null,
'id' => $this->id,
),
$layout->render());
}
private function renderDataInputs() {
$inputs = array();
foreach ($this->data as $key => $value) {
if ($value === null) {
continue;
}
$inputs[] = phutil_tag(
'input',
array(
'type' => 'hidden',
'name' => $key,
'value' => $value,
));
}
- return implode("\n", $inputs);
+ return $inputs;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Sun, Nov 16, 12:28 AM (4 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
338568
Default Alt Text
(23 KB)

Event Timeline