repo stringlengths 7 63 | file_url stringlengths 81 284 | file_path stringlengths 5 200 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:02:33 2026-01-05 05:24:06 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorChartFunction.php | src/applications/fact/chart/PhabricatorChartFunction.php | <?php
abstract class PhabricatorChartFunction
extends Phobject {
private $argumentParser;
private $functionLabel;
final public function getFunctionKey() {
return $this->getPhobjectClassConstant('FUNCTIONKEY', 32);
}
final public static function getAllFunctions() {
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setUniqueMethod('getFunctionKey')
->execute();
}
final public function setArguments(array $arguments) {
$parser = $this->getArgumentParser();
$parser->setRawArguments($arguments);
$specs = $this->newArguments();
if (!is_array($specs)) {
throw new Exception(
pht(
'Expected "newArguments()" in class "%s" to return a list of '.
'argument specifications, got %s.',
get_class($this),
phutil_describe_type($specs)));
}
assert_instances_of($specs, 'PhabricatorChartFunctionArgument');
foreach ($specs as $spec) {
$parser->addArgument($spec);
}
$parser->setHaveAllArguments(true);
$parser->parseArguments();
return $this;
}
public function setFunctionLabel(PhabricatorChartFunctionLabel $label) {
$this->functionLabel = $label;
return $this;
}
public function getFunctionLabel() {
if (!$this->functionLabel) {
$this->functionLabel = id(new PhabricatorChartFunctionLabel())
->setName(pht('Unlabeled Function'))
->setColor('rgba(255, 0, 0, 1)')
->setFillColor('rgba(255, 0, 0, 0.15)');
}
return $this->functionLabel;
}
final public function getKey() {
return $this->getFunctionLabel()->getKey();
}
final public static function newFromDictionary(array $map) {
PhutilTypeSpec::checkMap(
$map,
array(
'function' => 'string',
'arguments' => 'list<wild>',
));
$functions = self::getAllFunctions();
$function_name = $map['function'];
if (!isset($functions[$function_name])) {
throw new Exception(
pht(
'Attempting to build function "%s" from dictionary, but that '.
'function is unknown. Known functions are: %s.',
$function_name,
implode(', ', array_keys($functions))));
}
$function = id(clone $functions[$function_name])
->setArguments($map['arguments']);
return $function;
}
public function getSubfunctions() {
$result = array();
$result[] = $this;
foreach ($this->getFunctionArguments() as $argument) {
foreach ($argument->getSubfunctions() as $subfunction) {
$result[] = $subfunction;
}
}
return $result;
}
public function getFunctionArguments() {
$results = array();
$parser = $this->getArgumentParser();
foreach ($parser->getAllArguments() as $argument) {
if ($argument->getType() !== 'function') {
continue;
}
$name = $argument->getName();
$value = $this->getArgument($name);
if (!is_array($value)) {
$results[] = $value;
} else {
foreach ($value as $arg_value) {
$results[] = $arg_value;
}
}
}
return $results;
}
public function newDatapoints(PhabricatorChartDataQuery $query) {
$xv = $this->newInputValues($query);
if ($xv === null) {
$xv = $this->newDefaultInputValues($query);
}
$xv = $query->selectInputValues($xv);
$n = count($xv);
$yv = $this->evaluateFunction($xv);
$points = array();
for ($ii = 0; $ii < $n; $ii++) {
$y = $yv[$ii];
if ($y === null) {
continue;
}
$points[] = array(
'x' => $xv[$ii],
'y' => $y,
);
}
return $points;
}
abstract protected function newArguments();
final protected function newArgument() {
return new PhabricatorChartFunctionArgument();
}
final protected function getArgument($key) {
return $this->getArgumentParser()->getArgumentValue($key);
}
final protected function getArgumentParser() {
if (!$this->argumentParser) {
$parser = id(new PhabricatorChartFunctionArgumentParser())
->setFunction($this);
$this->argumentParser = $parser;
}
return $this->argumentParser;
}
abstract public function evaluateFunction(array $xv);
abstract public function getDataRefs(array $xv);
abstract public function loadRefs(array $refs);
public function getDomain() {
return null;
}
public function newInputValues(PhabricatorChartDataQuery $query) {
return null;
}
public function loadData() {
return;
}
protected function newDefaultInputValues(PhabricatorChartDataQuery $query) {
$x_min = $query->getMinimumValue();
$x_max = $query->getMaximumValue();
$limit = $query->getLimit();
return $this->newLinearSteps($x_min, $x_max, $limit);
}
protected function newLinearSteps($src, $dst, $count) {
$count = (int)$count;
$src = (int)$src;
$dst = (int)$dst;
if ($count === 0) {
throw new Exception(
pht('Can not generate zero linear steps between two values!'));
}
if ($src === $dst) {
return array($src);
}
if ($count === 1) {
return array($src);
}
$is_reversed = ($src > $dst);
if ($is_reversed) {
$min = (double)$dst;
$max = (double)$src;
} else {
$min = (double)$src;
$max = (double)$dst;
}
$step = (double)($max - $min) / (double)($count - 1);
$steps = array();
for ($cursor = $min; $cursor <= $max; $cursor += $step) {
$x = (int)round($cursor);
if (isset($steps[$x])) {
continue;
}
$steps[$x] = $x;
}
$steps = array_values($steps);
if ($is_reversed) {
$steps = array_reverse($steps);
}
return $steps;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorAccumulateChartFunction.php | src/applications/fact/chart/PhabricatorAccumulateChartFunction.php | <?php
final class PhabricatorAccumulateChartFunction
extends PhabricatorHigherOrderChartFunction {
const FUNCTIONKEY = 'accumulate';
protected function newArguments() {
return array(
$this->newArgument()
->setName('x')
->setType('function'),
);
}
public function evaluateFunction(array $xv) {
// First, we're going to accumulate the underlying function. Then
// we'll map the inputs through the accumulation.
$datasource = $this->getArgument('x');
// Use an unconstrained query to pull all the data from the underlying
// source. We need to accumulate data since the beginning of time to
// figure out the right Y-intercept -- otherwise, we'll always start at
// "0" wherever our domain begins.
$empty_query = new PhabricatorChartDataQuery();
$datasource_xv = $datasource->newInputValues($empty_query);
if (!$datasource_xv) {
// When the datasource has no datapoints, we can't evaluate the function
// anywhere.
return array_fill(0, count($xv), null);
}
$yv = $datasource->evaluateFunction($datasource_xv);
$map = array_combine($datasource_xv, $yv);
$accumulator = 0;
foreach ($map as $x => $y) {
$accumulator += $y;
$map[$x] = $accumulator;
}
// The value of "accumulate(x)" is the largest datapoint in the map which
// is no larger than "x".
$map_x = array_keys($map);
$idx = -1;
$max = count($map_x) - 1;
$yv = array();
$value = 0;
foreach ($xv as $x) {
// While the next "x" we need to evaluate the function at lies to the
// right of the next datapoint, move the current datapoint forward until
// we're at the rightmost datapoint which is not larger than "x".
while ($idx < $max) {
if ($map_x[$idx + 1] > $x) {
break;
}
$idx++;
$value = $map[$map_x[$idx]];
}
$yv[] = $value;
}
return $yv;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorChartDisplayData.php | src/applications/fact/chart/PhabricatorChartDisplayData.php | <?php
final class PhabricatorChartDisplayData
extends Phobject {
private $wireData;
private $range;
public function setWireData(array $wire_data) {
$this->wireData = $wire_data;
return $this;
}
public function getWireData() {
return $this->wireData;
}
public function setRange(PhabricatorChartInterval $range) {
$this->range = $range;
return $this;
}
public function getRange() {
return $this->range;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorHigherOrderChartFunction.php | src/applications/fact/chart/PhabricatorHigherOrderChartFunction.php | <?php
abstract class PhabricatorHigherOrderChartFunction
extends PhabricatorChartFunction {
public function getDomain() {
$domains = array();
foreach ($this->getFunctionArguments() as $function) {
$domains[] = $function->getDomain();
}
return PhabricatorChartInterval::newFromIntervalList($domains);
}
public function newInputValues(PhabricatorChartDataQuery $query) {
$map = array();
foreach ($this->getFunctionArguments() as $function) {
$xv = $function->newInputValues($query);
if ($xv !== null) {
foreach ($xv as $x) {
$map[$x] = true;
}
}
}
if (!$map) {
return null;
}
ksort($map);
return array_keys($map);
}
public function getDataRefs(array $xv) {
$refs = array();
foreach ($this->getFunctionArguments() as $function) {
$function_refs = $function->getDataRefs($xv);
$function_refs = array_select_keys($function_refs, $xv);
if (!$function_refs) {
continue;
}
foreach ($function_refs as $x => $ref_list) {
if (!isset($refs[$x])) {
$refs[$x] = array();
}
foreach ($ref_list as $ref) {
$refs[$x][] = $ref;
}
}
}
return $refs;
}
public function loadRefs(array $refs) {
$results = array();
foreach ($this->getFunctionArguments() as $function) {
$results += $function->loadRefs($refs);
}
return $results;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorShiftChartFunction.php | src/applications/fact/chart/PhabricatorShiftChartFunction.php | <?php
final class PhabricatorShiftChartFunction
extends PhabricatorPureChartFunction {
const FUNCTIONKEY = 'shift';
protected function newArguments() {
return array(
$this->newArgument()
->setName('shift')
->setType('number'),
);
}
public function evaluateFunction(array $xv) {
$shift = $this->getArgument('shift');
$yv = array();
foreach ($xv as $x) {
$yv[] = $x + $shift;
}
return $yv;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorCosChartFunction.php | src/applications/fact/chart/PhabricatorCosChartFunction.php | <?php
final class PhabricatorCosChartFunction
extends PhabricatorPureChartFunction {
const FUNCTIONKEY = 'cos';
protected function newArguments() {
return array();
}
public function evaluateFunction(array $xv) {
$yv = array();
foreach ($xv as $x) {
$yv[] = cos(deg2rad($x));
}
return $yv;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorConstantChartFunction.php | src/applications/fact/chart/PhabricatorConstantChartFunction.php | <?php
final class PhabricatorConstantChartFunction
extends PhabricatorPureChartFunction {
const FUNCTIONKEY = 'constant';
protected function newArguments() {
return array(
$this->newArgument()
->setName('n')
->setType('number'),
);
}
public function evaluateFunction(array $xv) {
$n = $this->getArgument('n');
$yv = array();
foreach ($xv as $x) {
$yv[] = $n;
}
return $yv;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/daemon/PhabricatorFactDaemon.php | src/applications/fact/daemon/PhabricatorFactDaemon.php | <?php
final class PhabricatorFactDaemon extends PhabricatorDaemon {
private $engines;
protected function run() {
$this->setEngines(PhabricatorFactEngine::loadAllEngines());
do {
PhabricatorCaches::destroyRequestCache();
$iterators = $this->getAllApplicationIterators();
foreach ($iterators as $iterator_name => $iterator) {
$this->processIteratorWithCursor($iterator_name, $iterator);
}
$sleep_duration = 60;
if ($this->shouldHibernate($sleep_duration)) {
break;
}
$this->sleep($sleep_duration);
} while (!$this->shouldExit());
}
public static function getAllApplicationIterators() {
$apps = PhabricatorApplication::getAllInstalledApplications();
$iterators = array();
foreach ($apps as $app) {
foreach ($app->getFactObjectsForAnalysis() as $object) {
$iterator = new PhabricatorFactUpdateIterator($object);
$iterators[get_class($object)] = $iterator;
}
}
return $iterators;
}
public function processIteratorWithCursor($iterator_name, $iterator) {
$this->log(pht("Processing cursor '%s'.", $iterator_name));
$cursor = id(new PhabricatorFactCursor())->loadOneWhere(
'name = %s',
$iterator_name);
if (!$cursor) {
$cursor = new PhabricatorFactCursor();
$cursor->setName($iterator_name);
$position = null;
} else {
$position = $cursor->getPosition();
}
if ($position) {
$iterator->setPosition($position);
}
$new_cursor_position = $this->processIterator($iterator);
if ($new_cursor_position) {
$cursor->setPosition($new_cursor_position);
$cursor->save();
}
}
public function setEngines(array $engines) {
assert_instances_of($engines, 'PhabricatorFactEngine');
$viewer = PhabricatorUser::getOmnipotentUser();
foreach ($engines as $engine) {
$engine->setViewer($viewer);
}
$this->engines = $engines;
return $this;
}
public function processIterator($iterator) {
$result = null;
$datapoints = array();
$count = 0;
foreach ($iterator as $key => $object) {
$phid = $object->getPHID();
$this->log(pht('Processing %s...', $phid));
$object_datapoints = $this->newDatapoints($object);
$count += count($object_datapoints);
$datapoints[$phid] = $object_datapoints;
if ($count > 1024) {
$this->updateDatapoints($datapoints);
$datapoints = array();
$count = 0;
}
$result = $key;
}
if ($count) {
$this->updateDatapoints($datapoints);
$datapoints = array();
$count = 0;
}
return $result;
}
private function newDatapoints(PhabricatorLiskDAO $object) {
$facts = array();
foreach ($this->engines as $engine) {
if (!$engine->supportsDatapointsForObject($object)) {
continue;
}
$facts[] = $engine->newDatapointsForObject($object);
}
return array_mergev($facts);
}
private function updateDatapoints(array $map) {
foreach ($map as $phid => $facts) {
assert_instances_of($facts, 'PhabricatorFactIntDatapoint');
}
$phids = array_keys($map);
if (!$phids) {
return;
}
$fact_keys = array();
$objects = array();
foreach ($map as $phid => $facts) {
foreach ($facts as $fact) {
$fact_keys[$fact->getKey()] = true;
$object_phid = $fact->getObjectPHID();
$objects[$object_phid] = $object_phid;
$dimension_phid = $fact->getDimensionPHID();
if ($dimension_phid !== null) {
$objects[$dimension_phid] = $dimension_phid;
}
}
}
$key_map = id(new PhabricatorFactKeyDimension())
->newDimensionMap(array_keys($fact_keys), true);
$object_map = id(new PhabricatorFactObjectDimension())
->newDimensionMap(array_keys($objects), true);
$table = new PhabricatorFactIntDatapoint();
$conn = $table->establishConnection('w');
$table_name = $table->getTableName();
$sql = array();
foreach ($map as $phid => $facts) {
foreach ($facts as $fact) {
$key_id = $key_map[$fact->getKey()];
$object_id = $object_map[$fact->getObjectPHID()];
$dimension_phid = $fact->getDimensionPHID();
if ($dimension_phid !== null) {
$dimension_id = $object_map[$dimension_phid];
} else {
$dimension_id = null;
}
$sql[] = qsprintf(
$conn,
'(%d, %d, %nd, %d, %d)',
$key_id,
$object_id,
$dimension_id,
$fact->getValue(),
$fact->getEpoch());
}
}
$rebuilt_ids = array_select_keys($object_map, $phids);
$table->openTransaction();
queryfx(
$conn,
'DELETE FROM %T WHERE objectID IN (%Ld)',
$table_name,
$rebuilt_ids);
if ($sql) {
foreach (PhabricatorLiskDAO::chunkSQL($sql) as $chunk) {
queryfx(
$conn,
'INSERT INTO %T
(keyID, objectID, dimensionID, value, epoch)
VALUES %LQ',
$table_name,
$chunk);
}
}
$table->saveTransaction();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/engine/PhabricatorDemoChartEngine.php | src/applications/fact/engine/PhabricatorDemoChartEngine.php | <?php
final class PhabricatorDemoChartEngine
extends PhabricatorChartEngine {
const CHARTENGINEKEY = 'facts.demo';
protected function newChart(PhabricatorFactChart $chart, array $map) {
$viewer = $this->getViewer();
$functions = array();
$function = $this->newFunction(
array('scale', 0.0001),
array('cos'),
array('scale', 128),
array('shift', 256));
$function->getFunctionLabel()
->setKey('cos-x')
->setName(pht('cos(x)'))
->setColor('rgba(0, 200, 0, 1)')
->setFillColor('rgba(0, 200, 0, 0.15)');
$functions[] = $function;
$function = $this->newFunction(
array('constant', 345));
$function->getFunctionLabel()
->setKey('constant-345')
->setName(pht('constant(345)'))
->setColor('rgba(0, 0, 200, 1)')
->setFillColor('rgba(0, 0, 200, 0.15)');
$functions[] = $function;
$datasets = array();
$datasets[] = id(new PhabricatorChartStackedAreaDataset())
->setFunctions($functions);
$chart->attachDatasets($datasets);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/engine/PhabricatorFactEngine.php | src/applications/fact/engine/PhabricatorFactEngine.php | <?php
abstract class PhabricatorFactEngine extends Phobject {
private $factMap;
private $viewer;
final public static function loadAllEngines() {
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->execute();
}
abstract public function newFacts();
abstract public function supportsDatapointsForObject(
PhabricatorLiskDAO $object);
abstract public function newDatapointsForObject(PhabricatorLiskDAO $object);
final protected function getFact($key) {
if ($this->factMap === null) {
$facts = $this->newFacts();
$facts = mpull($facts, null, 'getKey');
$this->factMap = $facts;
}
if (!isset($this->factMap[$key])) {
throw new Exception(
pht(
'Unknown fact ("%s") for engine "%s".',
$key,
get_class($this)));
}
return $this->factMap[$key];
}
public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer;
return $this;
}
public function getViewer() {
if (!$this->viewer) {
throw new PhutilInvalidStateException('setViewer');
}
return $this->viewer;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/engine/PhabricatorChartRenderingEngine.php | src/applications/fact/engine/PhabricatorChartRenderingEngine.php | <?php
final class PhabricatorChartRenderingEngine
extends Phobject {
private $viewer;
private $chart;
private $storedChart;
public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer;
return $this;
}
public function getViewer() {
return $this->viewer;
}
public function setChart(PhabricatorFactChart $chart) {
$this->chart = $chart;
return $this;
}
public function getChart() {
return $this->chart;
}
public function loadChart($chart_key) {
$chart = id(new PhabricatorFactChart())->loadOneWhere(
'chartKey = %s',
$chart_key);
if ($chart) {
$this->setChart($chart);
}
return $chart;
}
public static function getChartURI($chart_key) {
return id(new PhabricatorFactChart())
->setChartKey($chart_key)
->getURI();
}
public function getStoredChart() {
if (!$this->storedChart) {
$chart = $this->getChart();
$chart_key = $chart->getChartKey();
if (!$chart_key) {
$chart_key = $chart->newChartKey();
$stored_chart = id(new PhabricatorFactChart())->loadOneWhere(
'chartKey = %s',
$chart_key);
if ($stored_chart) {
$chart = $stored_chart;
} else {
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
try {
$chart->save();
} catch (AphrontDuplicateKeyQueryException $ex) {
$chart = id(new PhabricatorFactChart())->loadOneWhere(
'chartKey = %s',
$chart_key);
if (!$chart) {
throw new Exception(
pht(
'Failed to load chart with key "%s" after key collision. '.
'This should not be possible.',
$chart_key));
}
}
unset($unguarded);
}
$this->setChart($chart);
}
$this->storedChart = $chart;
}
return $this->storedChart;
}
public function newChartView() {
$chart = $this->getStoredChart();
$chart_key = $chart->getChartKey();
$chart_node_id = celerity_generate_unique_node_id();
$chart_view = phutil_tag(
'div',
array(
'id' => $chart_node_id,
'class' => 'chart-hardpoint',
));
$data_uri = urisprintf('/fact/chart/%s/draw/', $chart_key);
Javelin::initBehavior(
'line-chart',
array(
'chartNodeID' => $chart_node_id,
'dataURI' => (string)$data_uri,
));
return $chart_view;
}
public function newTabularView() {
$viewer = $this->getViewer();
$tabular_data = $this->newTabularData();
$ref_keys = array();
foreach ($tabular_data['datasets'] as $tabular_dataset) {
foreach ($tabular_dataset as $function) {
foreach ($function['data'] as $point) {
foreach ($point['refs'] as $ref) {
$ref_keys[$ref] = $ref;
}
}
}
}
$chart = $this->getStoredChart();
$ref_map = array();
foreach ($chart->getDatasets() as $dataset) {
foreach ($dataset->getFunctions() as $function) {
// If we aren't looking for anything else, bail out.
if (!$ref_keys) {
break 2;
}
$function_refs = $function->loadRefs($ref_keys);
$ref_map += $function_refs;
// Remove the ref keys that we found data for from the list of keys
// we are looking for. If any function gives us data for a given ref,
// that's satisfactory.
foreach ($function_refs as $ref_key => $ref_data) {
unset($ref_keys[$ref_key]);
}
}
}
$phids = array();
foreach ($ref_map as $ref => $ref_data) {
if (isset($ref_data['objectPHID'])) {
$phids[] = $ref_data['objectPHID'];
}
}
$handles = $viewer->loadHandles($phids);
$tabular_view = array();
foreach ($tabular_data['datasets'] as $tabular_data) {
foreach ($tabular_data as $function) {
$rows = array();
foreach ($function['data'] as $point) {
$ref_views = array();
$xv = date('Y-m-d h:i:s', $point['x']);
$yv = $point['y'];
$point_refs = array();
foreach ($point['refs'] as $ref) {
if (!isset($ref_map[$ref])) {
continue;
}
$point_refs[$ref] = $ref_map[$ref];
}
if (!$point_refs) {
$rows[] = array(
$xv,
$yv,
null,
null,
null,
);
} else {
foreach ($point_refs as $ref => $ref_data) {
$ref_value = $ref_data['value'];
$ref_link = $handles[$ref_data['objectPHID']]
->renderLink();
$view_uri = urisprintf(
'/fact/object/%s/',
$ref_data['objectPHID']);
$ref_button = id(new PHUIButtonView())
->setIcon('fa-table')
->setTag('a')
->setColor('grey')
->setHref($view_uri)
->setText(pht('View Data'));
$rows[] = array(
$xv,
$yv,
$ref_value,
$ref_link,
$ref_button,
);
$xv = null;
$yv = null;
}
}
}
$table = id(new AphrontTableView($rows))
->setHeaders(
array(
pht('X'),
pht('Y'),
pht('Raw'),
pht('Refs'),
null,
))
->setColumnClasses(
array(
'n',
'n',
'n',
'wide',
null,
));
$tabular_view[] = id(new PHUIObjectBoxView())
->setHeaderText(pht('Function'))
->setTable($table);
}
}
return $tabular_view;
}
public function newChartData() {
return $this->newWireData(false);
}
public function newTabularData() {
return $this->newWireData(true);
}
private function newWireData($is_tabular) {
$chart = $this->getStoredChart();
$chart_key = $chart->getChartKey();
$chart_engine = PhabricatorChartEngine::newFromChart($chart)
->setViewer($this->getViewer());
$chart_engine->buildChart($chart);
$datasets = $chart->getDatasets();
$functions = array();
foreach ($datasets as $dataset) {
foreach ($dataset->getFunctions() as $function) {
$functions[] = $function;
}
}
$subfunctions = array();
foreach ($functions as $function) {
foreach ($function->getSubfunctions() as $subfunction) {
$subfunctions[] = $subfunction;
}
}
foreach ($subfunctions as $subfunction) {
$subfunction->loadData();
}
$domain = $this->getDomain($functions);
$axis = id(new PhabricatorChartAxis())
->setMinimumValue($domain->getMin())
->setMaximumValue($domain->getMax());
$data_query = id(new PhabricatorChartDataQuery())
->setMinimumValue($domain->getMin())
->setMaximumValue($domain->getMax())
->setLimit(2000);
$wire_datasets = array();
$ranges = array();
foreach ($datasets as $dataset) {
if ($is_tabular) {
$display_data = $dataset->getTabularDisplayData($data_query);
} else {
$display_data = $dataset->getChartDisplayData($data_query);
}
$ranges[] = $display_data->getRange();
$wire_datasets[] = $display_data->getWireData();
}
$range = $this->getRange($ranges);
$chart_data = array(
'datasets' => $wire_datasets,
'xMin' => $domain->getMin(),
'xMax' => $domain->getMax(),
'yMin' => $range->getMin(),
'yMax' => $range->getMax(),
);
return $chart_data;
}
private function getDomain(array $functions) {
$domains = array();
foreach ($functions as $function) {
$domains[] = $function->getDomain();
}
$domain = PhabricatorChartInterval::newFromIntervalList($domains);
// If we don't have any domain data from the actual functions, pick a
// plausible domain automatically.
if ($domain->getMax() === null) {
$domain->setMax(PhabricatorTime::getNow());
}
if ($domain->getMin() === null) {
$domain->setMin($domain->getMax() - phutil_units('365 days in seconds'));
}
return $domain;
}
private function getRange(array $ranges) {
$range = PhabricatorChartInterval::newFromIntervalList($ranges);
// Start the Y axis at 0 unless the chart has negative values.
$min = $range->getMin();
if ($min === null || $min >= 0) {
$range->setMin(0);
}
// If there's no maximum value, just pick a plausible default.
$max = $range->getMax();
if ($max === null) {
$range->setMax($range->getMin() + 100);
}
return $range;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/engine/PhabricatorChartEngine.php | src/applications/fact/engine/PhabricatorChartEngine.php | <?php
abstract class PhabricatorChartEngine
extends Phobject {
private $viewer;
private $engineParameters = array();
const KEY_ENGINE = 'engineKey';
const KEY_PARAMETERS = 'engineParameters';
final public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer;
return $this;
}
final public function getViewer() {
return $this->viewer;
}
final protected function setEngineParameter($key, $value) {
$this->engineParameters[$key] = $value;
return $this;
}
final protected function getEngineParameter($key, $default = null) {
return idx($this->engineParameters, $key, $default);
}
final protected function getEngineParameters() {
return $this->engineParameters;
}
final public static function newFromChart(PhabricatorFactChart $chart) {
$engine_key = $chart->getChartParameter(self::KEY_ENGINE);
$engine_map = self::getAllChartEngines();
if (!isset($engine_map[$engine_key])) {
throw new Exception(
pht(
'Chart uses unknown engine key ("%s") and can not be rendered.',
$engine_key));
}
return clone id($engine_map[$engine_key]);
}
final public static function getAllChartEngines() {
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setUniqueMethod('getChartEngineKey')
->execute();
}
final public function getChartEngineKey() {
return $this->getPhobjectClassConstant('CHARTENGINEKEY', 32);
}
final public function buildChart(PhabricatorFactChart $chart) {
$map = $chart->getChartParameter(self::KEY_PARAMETERS, array());
return $this->newChart($chart, $map);
}
abstract protected function newChart(PhabricatorFactChart $chart, array $map);
final public function newStoredChart() {
$viewer = $this->getViewer();
$parameters = $this->getEngineParameters();
$chart = id(new PhabricatorFactChart())
->setChartParameter(self::KEY_ENGINE, $this->getChartEngineKey())
->setChartParameter(self::KEY_PARAMETERS, $this->getEngineParameters());
$rendering_engine = id(new PhabricatorChartRenderingEngine())
->setViewer($viewer)
->setChart($chart);
return $rendering_engine->getStoredChart();
}
final public function buildChartPanel() {
$chart = $this->newStoredChart();
$panel_type = id(new PhabricatorDashboardChartPanelType())
->getPanelTypeKey();
$chart_panel = id(new PhabricatorDashboardPanel())
->setPanelType($panel_type)
->setProperty('chartKey', $chart->getChartKey());
return $chart_panel;
}
final protected function newFunction($name /* , ... */) {
$argv = func_get_args();
return id(new PhabricatorComposeChartFunction())
->setArguments($argv);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/engine/PhabricatorTransactionFactEngine.php | src/applications/fact/engine/PhabricatorTransactionFactEngine.php | <?php
abstract class PhabricatorTransactionFactEngine
extends PhabricatorFactEngine {
public function newTransactionGroupsForObject(PhabricatorLiskDAO $object) {
$viewer = $this->getViewer();
$xaction_query = PhabricatorApplicationTransactionQuery::newQueryForObject(
$object);
$xactions = $xaction_query
->setViewer($viewer)
->withObjectPHIDs(array($object->getPHID()))
->execute();
$xactions = msortv($xactions, 'newChronologicalSortVector');
return $this->groupTransactions($xactions);
}
protected function groupTransactions(array $xactions) {
// These grouping rules are generally much looser than the display grouping
// rules. As long as the same user is editing the task and they don't leave
// it alone for a particularly long time, we'll group things together.
$breaks = array();
$touch_window = phutil_units('15 minutes in seconds');
$user_type = PhabricatorPeopleUserPHIDType::TYPECONST;
$last_actor = null;
$last_epoch = null;
foreach ($xactions as $key => $xaction) {
$this_actor = $xaction->getAuthorPHID();
if (phid_get_type($this_actor) != $user_type) {
$this_actor = null;
}
if ($this_actor && $last_actor && ($this_actor != $last_actor)) {
$breaks[$key] = true;
}
// If too much time passed between changes, group them separately.
$this_epoch = $xaction->getDateCreated();
if ($last_epoch) {
if (($this_epoch - $last_epoch) > $touch_window) {
$breaks[$key] = true;
}
}
// The clock gets reset every time the same real user touches the
// task, but does not reset if an automated actor touches things.
if (!$last_actor || ($this_actor == $last_actor)) {
$last_epoch = $this_epoch;
}
if ($this_actor && ($last_actor != $this_actor)) {
$last_actor = $this_actor;
$last_epoch = $this_epoch;
}
}
$groups = array();
$group = array();
foreach ($xactions as $key => $xaction) {
if (isset($breaks[$key])) {
if ($group) {
$groups[] = $group;
$group = array();
}
}
$group[] = $xaction;
}
if ($group) {
$groups[] = $group;
}
return $groups;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/engine/PhabricatorManiphestTaskFactEngine.php | src/applications/fact/engine/PhabricatorManiphestTaskFactEngine.php | <?php
final class PhabricatorManiphestTaskFactEngine
extends PhabricatorTransactionFactEngine {
public function newFacts() {
return array(
id(new PhabricatorCountFact())
->setKey('tasks.count.create'),
id(new PhabricatorCountFact())
->setKey('tasks.open-count.create'),
id(new PhabricatorCountFact())
->setKey('tasks.open-count.status'),
id(new PhabricatorCountFact())
->setKey('tasks.count.create.project'),
id(new PhabricatorCountFact())
->setKey('tasks.count.assign.project'),
id(new PhabricatorCountFact())
->setKey('tasks.open-count.create.project'),
id(new PhabricatorCountFact())
->setKey('tasks.open-count.status.project'),
id(new PhabricatorCountFact())
->setKey('tasks.open-count.assign.project'),
id(new PhabricatorCountFact())
->setKey('tasks.count.create.owner'),
id(new PhabricatorCountFact())
->setKey('tasks.count.assign.owner'),
id(new PhabricatorCountFact())
->setKey('tasks.open-count.create.owner'),
id(new PhabricatorCountFact())
->setKey('tasks.open-count.status.owner'),
id(new PhabricatorCountFact())
->setKey('tasks.open-count.assign.owner'),
id(new PhabricatorPointsFact())
->setKey('tasks.points.create'),
id(new PhabricatorPointsFact())
->setKey('tasks.points.score'),
id(new PhabricatorPointsFact())
->setKey('tasks.open-points.create'),
id(new PhabricatorPointsFact())
->setKey('tasks.open-points.status'),
id(new PhabricatorPointsFact())
->setKey('tasks.open-points.score'),
id(new PhabricatorPointsFact())
->setKey('tasks.points.create.project'),
id(new PhabricatorPointsFact())
->setKey('tasks.points.assign.project'),
id(new PhabricatorPointsFact())
->setKey('tasks.points.score.project'),
id(new PhabricatorPointsFact())
->setKey('tasks.open-points.create.project'),
id(new PhabricatorPointsFact())
->setKey('tasks.open-points.status.project'),
id(new PhabricatorPointsFact())
->setKey('tasks.open-points.score.project'),
id(new PhabricatorPointsFact())
->setKey('tasks.open-points.assign.project'),
id(new PhabricatorPointsFact())
->setKey('tasks.points.create.owner'),
id(new PhabricatorPointsFact())
->setKey('tasks.points.assign.owner'),
id(new PhabricatorPointsFact())
->setKey('tasks.points.score.owner'),
id(new PhabricatorPointsFact())
->setKey('tasks.open-points.create.owner'),
id(new PhabricatorPointsFact())
->setKey('tasks.open-points.status.owner'),
id(new PhabricatorPointsFact())
->setKey('tasks.open-points.score.owner'),
id(new PhabricatorPointsFact())
->setKey('tasks.open-points.assign.owner'),
);
}
public function supportsDatapointsForObject(PhabricatorLiskDAO $object) {
return ($object instanceof ManiphestTask);
}
public function newDatapointsForObject(PhabricatorLiskDAO $object) {
$xaction_groups = $this->newTransactionGroupsForObject($object);
$old_open = false;
$old_points = 0;
$old_owner = null;
$project_map = array();
$object_phid = $object->getPHID();
$is_create = true;
$specs = array();
$datapoints = array();
foreach ($xaction_groups as $xaction_group) {
$add_projects = array();
$rem_projects = array();
$new_open = $old_open;
$new_points = $old_points;
$new_owner = $old_owner;
if ($is_create) {
// Assume tasks start open.
// TODO: This might be a questionable assumption?
$new_open = true;
}
$group_epoch = last($xaction_group)->getDateCreated();
foreach ($xaction_group as $xaction) {
$old_value = $xaction->getOldValue();
$new_value = $xaction->getNewValue();
switch ($xaction->getTransactionType()) {
case ManiphestTaskStatusTransaction::TRANSACTIONTYPE:
$new_open = !ManiphestTaskStatus::isClosedStatus($new_value);
break;
case ManiphestTaskMergedIntoTransaction::TRANSACTIONTYPE:
// When a task is merged into another task, it is changed to a
// closed status without generating a separate status transaction.
$new_open = false;
break;
case ManiphestTaskPointsTransaction::TRANSACTIONTYPE:
$new_points = (int)$xaction->getNewValue();
break;
case ManiphestTaskOwnerTransaction::TRANSACTIONTYPE:
$new_owner = $xaction->getNewValue();
break;
case PhabricatorTransactions::TYPE_EDGE:
$edge_type = $xaction->getMetadataValue('edge:type');
switch ($edge_type) {
case PhabricatorProjectObjectHasProjectEdgeType::EDGECONST:
$record = PhabricatorEdgeChangeRecord::newFromTransaction(
$xaction);
$add_projects += array_fuse($record->getAddedPHIDs());
$rem_projects += array_fuse($record->getRemovedPHIDs());
break;
}
break;
}
}
// If a project was both added and removed, moot it.
$mix_projects = array_intersect_key($add_projects, $rem_projects);
$add_projects = array_diff_key($add_projects, $mix_projects);
$rem_projects = array_diff_key($rem_projects, $mix_projects);
$project_sets = array(
array(
'phids' => $rem_projects,
'scale' => -1,
),
array(
'phids' => $add_projects,
'scale' => 1,
),
);
if ($is_create) {
$action = 'create';
$action_points = $new_points;
$include_open = $new_open;
} else {
$action = 'assign';
$action_points = $old_points;
$include_open = $old_open;
}
foreach ($project_sets as $project_set) {
$scale = $project_set['scale'];
foreach ($project_set['phids'] as $project_phid) {
if ($include_open) {
$specs[] = array(
"tasks.open-count.{$action}.project",
1 * $scale,
$project_phid,
);
$specs[] = array(
"tasks.open-points.{$action}.project",
$action_points * $scale,
$project_phid,
);
}
$specs[] = array(
"tasks.count.{$action}.project",
1 * $scale,
$project_phid,
);
$specs[] = array(
"tasks.points.{$action}.project",
$action_points * $scale,
$project_phid,
);
if ($scale < 0) {
unset($project_map[$project_phid]);
} else {
$project_map[$project_phid] = $project_phid;
}
}
}
if ($new_owner !== $old_owner) {
$owner_sets = array(
array(
'phid' => $old_owner,
'scale' => -1,
),
array(
'phid' => $new_owner,
'scale' => 1,
),
);
foreach ($owner_sets as $owner_set) {
$owner_phid = $owner_set['phid'];
if ($owner_phid === null) {
continue;
}
$scale = $owner_set['scale'];
if ($old_open != $new_open) {
$specs[] = array(
"tasks.open-count.{$action}.owner",
1 * $scale,
$owner_phid,
);
$specs[] = array(
"tasks.open-points.{$action}.owner",
$action_points * $scale,
$owner_phid,
);
}
$specs[] = array(
"tasks.count.{$action}.owner",
1 * $scale,
$owner_phid,
);
if ($action_points) {
$specs[] = array(
"tasks.points.{$action}.owner",
$action_points * $scale,
$owner_phid,
);
}
}
}
if ($is_create) {
$specs[] = array(
'tasks.count.create',
1,
);
$specs[] = array(
'tasks.points.create',
$new_points,
);
if ($new_open) {
$specs[] = array(
'tasks.open-count.create',
1,
);
$specs[] = array(
'tasks.open-points.create',
$new_points,
);
}
} else if ($new_open !== $old_open) {
if ($new_open) {
$scale = 1;
} else {
$scale = -1;
}
$specs[] = array(
'tasks.open-count.status',
1 * $scale,
);
$specs[] = array(
'tasks.open-points.status',
$action_points * $scale,
);
if ($new_owner !== null) {
$specs[] = array(
'tasks.open-count.status.owner',
1 * $scale,
$new_owner,
);
$specs[] = array(
'tasks.open-points.status.owner',
$action_points * $scale,
$new_owner,
);
}
foreach ($project_map as $project_phid) {
$specs[] = array(
'tasks.open-count.status.project',
1 * $scale,
$project_phid,
);
$specs[] = array(
'tasks.open-points.status.project',
$action_points * $scale,
$project_phid,
);
}
}
// The "score" facts only apply to rescoring tasks which already
// exist, so we skip them if the task is being created.
if (($new_points !== $old_points) && !$is_create) {
$delta = ($new_points - $old_points);
$specs[] = array(
'tasks.points.score',
$delta,
);
foreach ($project_map as $project_phid) {
$specs[] = array(
'tasks.points.score.project',
$delta,
$project_phid,
);
if ($old_open && $new_open) {
$specs[] = array(
'tasks.open-points.score.project',
$delta,
$project_phid,
);
}
}
if ($new_owner !== null) {
$specs[] = array(
'tasks.points.score.owner',
$delta,
$new_owner,
);
if ($old_open && $new_open) {
$specs[] = array(
'tasks.open-points.score.owner',
$delta,
$new_owner,
);
}
}
if ($old_open && $new_open) {
$specs[] = array(
'tasks.open-points.score',
$delta,
);
}
}
$old_points = $new_points;
$old_open = $new_open;
$old_owner = $new_owner;
foreach ($specs as $spec) {
$spec_key = $spec[0];
$spec_value = $spec[1];
// Don't write any facts with a value of 0. The "count" facts never
// have a value of 0, and the "points" facts aren't meaningful if
// they have a value of 0.
if ($spec_value == 0) {
continue;
}
$datapoint = $this->getFact($spec_key)
->newDatapoint();
$datapoint
->setObjectPHID($object_phid)
->setValue($spec_value)
->setEpoch($group_epoch);
if (isset($spec[2])) {
$datapoint->setDimensionPHID($spec[2]);
}
$datapoints[] = $datapoint;
}
$specs = array();
$is_create = false;
}
return $datapoints;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/engine/__tests__/PhabricatorFactEngineTestCase.php | src/applications/fact/engine/__tests__/PhabricatorFactEngineTestCase.php | <?php
final class PhabricatorFactEngineTestCase extends PhabricatorTestCase {
public function testLoadAllEngines() {
PhabricatorFactEngine::loadAllEngines();
$this->assertTrue(true);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/controller/PhabricatorBadgesProfileController.php | src/applications/badges/controller/PhabricatorBadgesProfileController.php | <?php
abstract class PhabricatorBadgesProfileController
extends PhabricatorController {
private $badge;
public function setBadge(PhabricatorBadgesBadge $badge) {
$this->badge = $badge;
return $this;
}
public function getBadge() {
return $this->badge;
}
public function buildApplicationMenu() {
return $this->buildSideNavView()->getMenu();
}
protected function buildHeaderView() {
$viewer = $this->getViewer();
$badge = $this->getBadge();
$id = $badge->getID();
if ($badge->isArchived()) {
$status_icon = 'fa-ban';
$status_color = 'dark';
} else {
$status_icon = 'fa-check';
$status_color = 'bluegrey';
}
$status_name = idx(
PhabricatorBadgesBadge::getStatusNameMap(),
$badge->getStatus());
return id(new PHUIHeaderView())
->setHeader($badge->getName())
->setUser($viewer)
->setPolicyObject($badge)
->setStatus($status_icon, $status_color, $status_name)
->setHeaderIcon('fa-trophy');
}
protected function buildApplicationCrumbs() {
$badge = $this->getBadge();
$id = $badge->getID();
$badge_uri = $this->getApplicationURI("/view/{$id}/");
$crumbs = parent::buildApplicationCrumbs();
$crumbs->addTextCrumb($badge->getName(), $badge_uri);
$crumbs->setBorder(true);
return $crumbs;
}
protected function buildSideNavView($filter = null) {
$viewer = $this->getViewer();
$badge = $this->getBadge();
$id = $badge->getID();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$badge,
PhabricatorPolicyCapability::CAN_EDIT);
$nav = id(new AphrontSideNavFilterView())
->setBaseURI(new PhutilURI($this->getApplicationURI()));
$nav->addLabel(pht('Badge'));
$nav->addFilter(
'view',
pht('View Badge'),
$this->getApplicationURI("/view/{$id}/"),
'fa-trophy');
$nav->addFilter(
'recipients',
pht('View Recipients'),
$this->getApplicationURI("/recipients/{$id}/"),
'fa-group');
$nav->selectFilter($filter);
return $nav;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/controller/PhabricatorBadgesController.php | src/applications/badges/controller/PhabricatorBadgesController.php | <?php
abstract class PhabricatorBadgesController extends PhabricatorController {
public function buildApplicationMenu() {
return $this->newApplicationMenu()
->setSearchEngine(new PhabricatorBadgesSearchEngine());
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/controller/PhabricatorBadgesEditRecipientsController.php | src/applications/badges/controller/PhabricatorBadgesEditRecipientsController.php | <?php
final class PhabricatorBadgesEditRecipientsController
extends PhabricatorBadgesController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$xactions = array();
$badge = id(new PhabricatorBadgesQuery())
->setViewer($viewer)
->withIDs(array($id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_EDIT,
PhabricatorPolicyCapability::CAN_VIEW,
))
->executeOne();
if (!$badge) {
return new Aphront404Response();
}
$view_uri = $this->getApplicationURI('recipients/'.$badge->getID().'/');
if ($request->isFormPost()) {
$award_phids = array();
$add_recipients = $request->getArr('phids');
if ($add_recipients) {
foreach ($add_recipients as $phid) {
$award_phids[] = $phid;
}
}
$xactions[] = id(new PhabricatorBadgesTransaction())
->setTransactionType(
PhabricatorBadgesBadgeAwardTransaction::TRANSACTIONTYPE)
->setNewValue($award_phids);
$editor = id(new PhabricatorBadgesEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true)
->applyTransactions($badge, $xactions);
return id(new AphrontRedirectResponse())
->setURI($view_uri);
}
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$badge,
PhabricatorPolicyCapability::CAN_EDIT);
$form_box = null;
$title = pht('Add Recipient');
if ($can_edit) {
$header_name = pht('Edit Recipients');
$form = new AphrontFormView();
$form
->setUser($viewer)
->setFullWidth(true)
->appendControl(
id(new AphrontFormTokenizerControl())
->setName('phids')
->setLabel(pht('Recipients'))
->setDatasource(new PhabricatorPeopleDatasource()));
}
$dialog = id(new AphrontDialogView())
->setUser($viewer)
->setTitle(pht('Add Recipients'))
->appendForm($form)
->addCancelButton($view_uri)
->addSubmitButton(pht('Add Recipients'));
return $dialog;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/controller/PhabricatorBadgesCommentController.php | src/applications/badges/controller/PhabricatorBadgesCommentController.php | <?php
final class PhabricatorBadgesCommentController
extends PhabricatorBadgesController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
if (!$request->isFormPost()) {
return new Aphront400Response();
}
$badge = id(new PhabricatorBadgesQuery())
->setViewer($viewer)
->withIDs(array($id))
->executeOne();
if (!$badge) {
return new Aphront404Response();
}
$is_preview = $request->isPreviewRequest();
$draft = PhabricatorDraft::buildFromRequest($request);
$view_uri = $this->getApplicationURI('view/'.$badge->getID());
$xactions = array();
$xactions[] = id(new PhabricatorBadgesTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
->attachComment(
id(new PhabricatorBadgesTransactionComment())
->setContent($request->getStr('comment')));
$editor = id(new PhabricatorBadgesEditor())
->setActor($viewer)
->setContinueOnNoEffect($request->isContinueRequest())
->setContentSourceFromRequest($request)
->setIsPreview($is_preview);
try {
$xactions = $editor->applyTransactions($badge, $xactions);
} catch (PhabricatorApplicationTransactionNoEffectException $ex) {
return id(new PhabricatorApplicationTransactionNoEffectResponse())
->setCancelURI($view_uri)
->setException($ex);
}
if ($draft) {
$draft->replaceOrDelete();
}
if ($request->isAjax() && $is_preview) {
return id(new PhabricatorApplicationTransactionResponse())
->setObject($badge)
->setViewer($viewer)
->setTransactions($xactions)
->setIsPreview($is_preview);
} else {
return id(new AphrontRedirectResponse())
->setURI($view_uri);
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/controller/PhabricatorBadgesRecipientsController.php | src/applications/badges/controller/PhabricatorBadgesRecipientsController.php | <?php
final class PhabricatorBadgesRecipientsController
extends PhabricatorBadgesProfileController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$badge = id(new PhabricatorBadgesQuery())
->setViewer($viewer)
->withIDs(array($id))
->executeOne();
if (!$badge) {
return new Aphront404Response();
}
$this->setBadge($badge);
$awards = id(new PhabricatorBadgesAwardQuery())
->setViewer($viewer)
->withBadgePHIDs(array($badge->getPHID()))
->execute();
$recipient_phids = mpull($awards, 'getRecipientPHID');
$recipient_phids = array_reverse($recipient_phids);
$handles = $this->loadViewerHandles($recipient_phids);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Recipients'));
$crumbs->setBorder(true);
$title = $badge->getName();
$header = $this->buildHeaderView();
$recipient_list = id(new PhabricatorBadgesRecipientsListView())
->setBadge($badge)
->setAwards($awards)
->setHandles($handles)
->setUser($viewer);
$view = id(new PHUITwoColumnView())
->setHeader($header)
->setFooter(array(
$recipient_list,
));
$navigation = $this->buildSideNavView('recipients');
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->setPageObjectPHIDs(array($badge->getPHID()))
->setNavigation($navigation)
->appendChild($view);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/controller/PhabricatorBadgesListController.php | src/applications/badges/controller/PhabricatorBadgesListController.php | <?php
final class PhabricatorBadgesListController
extends PhabricatorBadgesController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
return id(new PhabricatorBadgesSearchEngine())
->setController($this)
->buildResponse();
}
protected function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
id(new PhabricatorBadgesEditEngine())
->setViewer($this->getViewer())
->addActionToCrumbs($crumbs);
return $crumbs;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/controller/PhabricatorBadgesArchiveController.php | src/applications/badges/controller/PhabricatorBadgesArchiveController.php | <?php
final class PhabricatorBadgesArchiveController
extends PhabricatorBadgesController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$badge = id(new PhabricatorBadgesQuery())
->setViewer($viewer)
->withIDs(array($id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$badge) {
return new Aphront404Response();
}
$view_uri = $this->getApplicationURI('view/'.$badge->getID().'/');
if ($request->isFormPost()) {
if ($badge->isArchived()) {
$new_status = PhabricatorBadgesBadge::STATUS_ACTIVE;
} else {
$new_status = PhabricatorBadgesBadge::STATUS_ARCHIVED;
}
$xactions = array();
$xactions[] = id(new PhabricatorBadgesTransaction())
->setTransactionType(
PhabricatorBadgesBadgeStatusTransaction::TRANSACTIONTYPE)
->setNewValue($new_status);
id(new PhabricatorBadgesEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true)
->applyTransactions($badge, $xactions);
return id(new AphrontRedirectResponse())->setURI($view_uri);
}
if ($badge->isArchived()) {
$title = pht('Activate Badge');
$body = pht('This badge will be re-commissioned into service.');
$button = pht('Activate Badge');
} else {
$title = pht('Archive Badge');
$body = pht(
'This dedicated badge, once a distinguish icon of this install, '.
'shall be immediately retired from service, but will never far from '.
'our hearts. Godspeed.');
$button = pht('Archive Badge');
}
return $this->newDialog()
->setTitle($title)
->appendChild($body)
->addCancelButton($view_uri)
->addSubmitButton($button);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/controller/PhabricatorBadgesAwardController.php | src/applications/badges/controller/PhabricatorBadgesAwardController.php | <?php
final class PhabricatorBadgesAwardController
extends PhabricatorBadgesController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$user = id(new PhabricatorPeopleQuery())
->setViewer($viewer)
->withIDs(array($id))
->executeOne();
if (!$user) {
return new Aphront404Response();
}
$view_uri = '/people/badges/'.$user->getID().'/';
if ($request->isFormPost()) {
$badge_phids = $request->getArr('badgePHIDs');
$badges = id(new PhabricatorBadgesQuery())
->setViewer($viewer)
->withPHIDs($badge_phids)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_EDIT,
PhabricatorPolicyCapability::CAN_VIEW,
))
->execute();
if (!$badges) {
return new Aphront404Response();
}
$award_phids = array($user->getPHID());
foreach ($badges as $badge) {
$xactions = array();
$xactions[] = id(new PhabricatorBadgesTransaction())
->setTransactionType(
PhabricatorBadgesBadgeAwardTransaction::TRANSACTIONTYPE)
->setNewValue($award_phids);
$editor = id(new PhabricatorBadgesEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true)
->applyTransactions($badge, $xactions);
}
return id(new AphrontRedirectResponse())
->setURI($view_uri);
}
$form = id(new AphrontFormView())
->setUser($viewer)
->appendControl(
id(new AphrontFormTokenizerControl())
->setLabel(pht('Badge'))
->setName('badgePHIDs')
->setDatasource(
id(new PhabricatorBadgesDatasource())
->setParameters(
array(
'recipientPHID' => $user->getPHID(),
))));
$dialog = $this->newDialog()
->setTitle(pht('Award Badge'))
->appendForm($form)
->addCancelButton($view_uri)
->addSubmitButton(pht('Award'));
return $dialog;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/controller/PhabricatorBadgesEditController.php | src/applications/badges/controller/PhabricatorBadgesEditController.php | <?php
final class PhabricatorBadgesEditController extends
PhabricatorBadgesController {
public function handleRequest(AphrontRequest $request) {
return id(new PhabricatorBadgesEditEngine())
->setController($this)
->buildResponse();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/controller/PhabricatorBadgesViewController.php | src/applications/badges/controller/PhabricatorBadgesViewController.php | <?php
final class PhabricatorBadgesViewController
extends PhabricatorBadgesProfileController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$badge = id(new PhabricatorBadgesQuery())
->setViewer($viewer)
->withIDs(array($id))
->executeOne();
if (!$badge) {
return new Aphront404Response();
}
$this->setBadge($badge);
$crumbs = $this->buildApplicationCrumbs();
$title = $badge->getName();
$header = $this->buildHeaderView();
$curtain = $this->buildCurtain($badge);
$details = $this->buildDetailsView($badge);
$timeline = $this->buildTransactionTimeline(
$badge,
new PhabricatorBadgesTransactionQuery());
$comment_view = id(new PhabricatorBadgesEditEngine())
->setViewer($viewer)
->buildEditEngineCommentView($badge);
$view = id(new PHUITwoColumnView())
->setHeader($header)
->setCurtain($curtain)
->setMainColumn(array(
$timeline,
$comment_view,
))
->addPropertySection(pht('Description'), $details);
$navigation = $this->buildSideNavView('view');
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->setPageObjectPHIDs(array($badge->getPHID()))
->setNavigation($navigation)
->appendChild($view);
}
private function buildDetailsView(
PhabricatorBadgesBadge $badge) {
$viewer = $this->getViewer();
$view = id(new PHUIPropertyListView())
->setUser($viewer);
$description = $badge->getDescription();
if (strlen($description)) {
$view->addTextContent(
new PHUIRemarkupView($viewer, $description));
}
$badge = id(new PHUIBadgeView())
->setIcon($badge->getIcon())
->setHeader($badge->getName())
->setSubhead($badge->getFlavor())
->setQuality($badge->getQuality());
$view->addTextContent($badge);
return $view;
}
private function buildCurtain(PhabricatorBadgesBadge $badge) {
$viewer = $this->getViewer();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$badge,
PhabricatorPolicyCapability::CAN_EDIT);
$id = $badge->getID();
$edit_uri = $this->getApplicationURI("/edit/{$id}/");
$archive_uri = $this->getApplicationURI("/archive/{$id}/");
$curtain = $this->newCurtainView($badge);
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('Edit Badge'))
->setIcon('fa-pencil')
->setDisabled(!$can_edit)
->setHref($edit_uri));
if ($badge->isArchived()) {
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('Activate Badge'))
->setIcon('fa-check')
->setDisabled(!$can_edit)
->setWorkflow($can_edit)
->setHref($archive_uri));
} else {
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('Archive Badge'))
->setIcon('fa-ban')
->setDisabled(!$can_edit)
->setWorkflow($can_edit)
->setHref($archive_uri));
}
return $curtain;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/controller/PhabricatorBadgesRemoveRecipientsController.php | src/applications/badges/controller/PhabricatorBadgesRemoveRecipientsController.php | <?php
final class PhabricatorBadgesRemoveRecipientsController
extends PhabricatorBadgesController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$badge = id(new PhabricatorBadgesQuery())
->setViewer($viewer)
->withIDs(array($id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$badge) {
return new Aphront404Response();
}
$remove_phid = $request->getStr('phid');
$view_uri = $this->getApplicationURI('recipients/'.$badge->getID().'/');
if ($request->isFormPost()) {
$xactions = array();
$xactions[] = id(new PhabricatorBadgesTransaction())
->setTransactionType(
PhabricatorBadgesBadgeRevokeTransaction::TRANSACTIONTYPE)
->setNewValue(array($remove_phid));
$editor = id(new PhabricatorBadgesEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true)
->applyTransactions($badge, $xactions);
return id(new AphrontRedirectResponse())
->setURI($view_uri);
}
$handle = id(new PhabricatorHandleQuery())
->setViewer($viewer)
->withPHIDs(array($remove_phid))
->executeOne();
$dialog = id(new AphrontDialogView())
->setUser($viewer)
->setTitle(pht('Really Revoke Badge?'))
->appendParagraph(
pht(
'Really revoke the badge "%s" from %s?',
phutil_tag('strong', array(), $badge->getName()),
phutil_tag('strong', array(), $handle->getName())))
->addCancelButton($view_uri)
->addSubmitButton(pht('Revoke Badge'));
return $dialog;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/storage/PhabricatorBadgesDAO.php | src/applications/badges/storage/PhabricatorBadgesDAO.php | <?php
abstract class PhabricatorBadgesDAO extends PhabricatorLiskDAO {
public function getApplicationName() {
return 'badges';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/storage/PhabricatorBadgesBadgeNameNgrams.php | src/applications/badges/storage/PhabricatorBadgesBadgeNameNgrams.php | <?php
final class PhabricatorBadgesBadgeNameNgrams
extends PhabricatorSearchNgrams {
public function getNgramKey() {
return 'badgename';
}
public function getColumnName() {
return 'name';
}
public function getApplicationName() {
return 'badges';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/storage/PhabricatorBadgesTransaction.php | src/applications/badges/storage/PhabricatorBadgesTransaction.php | <?php
final class PhabricatorBadgesTransaction
extends PhabricatorModularTransaction {
const MAILTAG_DETAILS = 'badges:details';
const MAILTAG_COMMENT = 'badges:comment';
const MAILTAG_OTHER = 'badges:other';
public function getApplicationName() {
return 'badges';
}
public function getApplicationTransactionType() {
return PhabricatorBadgesPHIDType::TYPECONST;
}
public function getApplicationTransactionCommentObject() {
return new PhabricatorBadgesTransactionComment();
}
public function getBaseTransactionClass() {
return 'PhabricatorBadgesBadgeTransactionType';
}
public function getMailTags() {
$tags = parent::getMailTags();
switch ($this->getTransactionType()) {
case PhabricatorTransactions::TYPE_COMMENT:
$tags[] = self::MAILTAG_COMMENT;
break;
case PhabricatorBadgesBadgeNameTransaction::TRANSACTIONTYPE:
case PhabricatorBadgesBadgeDescriptionTransaction::TRANSACTIONTYPE:
case PhabricatorBadgesBadgeFlavorTransaction::TRANSACTIONTYPE:
case PhabricatorBadgesBadgeIconTransaction::TRANSACTIONTYPE:
case PhabricatorBadgesBadgeStatusTransaction::TRANSACTIONTYPE:
case PhabricatorBadgesBadgeQualityTransaction::TRANSACTIONTYPE:
$tags[] = self::MAILTAG_DETAILS;
break;
case PhabricatorBadgesBadgeAwardTransaction::TRANSACTIONTYPE:
case PhabricatorBadgesBadgeRevokeTransaction::TRANSACTIONTYPE:
default:
$tags[] = self::MAILTAG_OTHER;
break;
}
return $tags;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/storage/PhabricatorBadgesTransactionComment.php | src/applications/badges/storage/PhabricatorBadgesTransactionComment.php | <?php
final class PhabricatorBadgesTransactionComment
extends PhabricatorApplicationTransactionComment {
public function getApplicationTransactionObject() {
return new PhabricatorBadgesTransaction();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/storage/PhabricatorBadgesBadge.php | src/applications/badges/storage/PhabricatorBadgesBadge.php | <?php
final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
implements
PhabricatorPolicyInterface,
PhabricatorApplicationTransactionInterface,
PhabricatorSubscribableInterface,
PhabricatorFlaggableInterface,
PhabricatorDestructibleInterface,
PhabricatorConduitResultInterface,
PhabricatorNgramsInterface {
protected $name;
protected $flavor;
protected $description;
protected $icon;
protected $quality;
protected $mailKey;
protected $editPolicy;
protected $status;
protected $creatorPHID;
const STATUS_ACTIVE = 'open';
const STATUS_ARCHIVED = 'closed';
const DEFAULT_ICON = 'fa-star';
public static function getStatusNameMap() {
return array(
self::STATUS_ACTIVE => pht('Active'),
self::STATUS_ARCHIVED => pht('Archived'),
);
}
public static function initializeNewBadge(PhabricatorUser $actor) {
$app = id(new PhabricatorApplicationQuery())
->setViewer($actor)
->withClasses(array('PhabricatorBadgesApplication'))
->executeOne();
$view_policy = PhabricatorPolicies::getMostOpenPolicy();
$edit_policy =
$app->getPolicy(PhabricatorBadgesDefaultEditCapability::CAPABILITY);
return id(new PhabricatorBadgesBadge())
->setIcon(self::DEFAULT_ICON)
->setQuality(PhabricatorBadgesQuality::DEFAULT_QUALITY)
->setCreatorPHID($actor->getPHID())
->setEditPolicy($edit_policy)
->setFlavor('')
->setDescription('')
->setStatus(self::STATUS_ACTIVE);
}
protected function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_COLUMN_SCHEMA => array(
'name' => 'sort255',
'flavor' => 'text255',
'description' => 'text',
'icon' => 'text255',
'quality' => 'uint32',
'status' => 'text32',
'mailKey' => 'bytes20',
),
self::CONFIG_KEY_SCHEMA => array(
'key_creator' => array(
'columns' => array('creatorPHID', 'dateModified'),
),
),
) + parent::getConfiguration();
}
public function generatePHID() {
return
PhabricatorPHID::generateNewPHID(PhabricatorBadgesPHIDType::TYPECONST);
}
public function isArchived() {
return ($this->getStatus() == self::STATUS_ARCHIVED);
}
public function getViewURI() {
return '/badges/view/'.$this->getID().'/';
}
public function save() {
if (!$this->getMailKey()) {
$this->setMailKey(Filesystem::readRandomCharacters(20));
}
return parent::save();
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
);
}
public function getPolicy($capability) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
return PhabricatorPolicies::getMostOpenPolicy();
case PhabricatorPolicyCapability::CAN_EDIT:
return $this->getEditPolicy();
}
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return false;
}
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
public function getApplicationTransactionEditor() {
return new PhabricatorBadgesEditor();
}
public function getApplicationTransactionTemplate() {
return new PhabricatorBadgesTransaction();
}
/* -( PhabricatorSubscribableInterface )----------------------------------- */
public function isAutomaticallySubscribed($phid) {
return false;
}
/* -( PhabricatorDestructibleInterface )----------------------------------- */
public function destroyObjectPermanently(
PhabricatorDestructionEngine $engine) {
$awards = id(new PhabricatorBadgesAwardQuery())
->setViewer($engine->getViewer())
->withBadgePHIDs(array($this->getPHID()))
->execute();
foreach ($awards as $award) {
$engine->destroyObject($award);
}
$this->openTransaction();
$this->delete();
$this->saveTransaction();
}
/* -( PhabricatorConduitResultInterface )---------------------------------- */
public function getFieldSpecificationsForConduit() {
return array(
id(new PhabricatorConduitSearchFieldSpecification())
->setKey('name')
->setType('string')
->setDescription(pht('The name of the badge.')),
id(new PhabricatorConduitSearchFieldSpecification())
->setKey('creatorPHID')
->setType('phid')
->setDescription(pht('User PHID of the creator.')),
id(new PhabricatorConduitSearchFieldSpecification())
->setKey('status')
->setType('string')
->setDescription(pht('Active or archived status of the badge.')),
);
}
public function getFieldValuesForConduit() {
return array(
'name' => $this->getName(),
'creatorPHID' => $this->getCreatorPHID(),
'status' => $this->getStatus(),
);
}
public function getConduitSearchAttachments() {
return array();
}
/* -( PhabricatorNgramInterface )------------------------------------------ */
public function newNgrams() {
return array(
id(new PhabricatorBadgesBadgeNameNgrams())
->setValue($this->getName()),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/storage/PhabricatorBadgesSchemaSpec.php | src/applications/badges/storage/PhabricatorBadgesSchemaSpec.php | <?php
final class PhabricatorBadgesSchemaSpec
extends PhabricatorConfigSchemaSpec {
public function buildSchemata() {
$this->buildEdgeSchemata(new PhabricatorBadgesBadge());
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/storage/PhabricatorBadgesAward.php | src/applications/badges/storage/PhabricatorBadgesAward.php | <?php
final class PhabricatorBadgesAward extends PhabricatorBadgesDAO
implements
PhabricatorDestructibleInterface,
PhabricatorPolicyInterface {
protected $badgePHID;
protected $recipientPHID;
protected $awarderPHID;
private $badge = self::ATTACHABLE;
public static function initializeNewBadgesAward(
PhabricatorUser $actor,
PhabricatorBadgesBadge $badge,
$recipient_phid) {
return id(new self())
->setRecipientPHID($recipient_phid)
->setBadgePHID($badge->getPHID())
->setAwarderPHID($actor->getPHID())
->attachBadge($badge);
}
protected function getConfiguration() {
return array(
self::CONFIG_KEY_SCHEMA => array(
'key_badge' => array(
'columns' => array('badgePHID', 'recipientPHID'),
'unique' => true,
),
'key_recipient' => array(
'columns' => array('recipientPHID'),
),
),
) + parent::getConfiguration();
}
public function attachBadge(PhabricatorBadgesBadge $badge) {
$this->badge = $badge;
return $this;
}
public function getBadge() {
return $this->assertAttached($this->badge);
}
/* -( PhabricatorDestructibleInterface )----------------------------------- */
public function destroyObjectPermanently(
PhabricatorDestructionEngine $engine) {
$this->openTransaction();
$this->delete();
$this->saveTransaction();
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
);
}
public function getPolicy($capability) {
return $this->getBadge()->getPolicy($capability);
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return false;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/icon/PhabricatorBadgesIconSet.php | src/applications/badges/icon/PhabricatorBadgesIconSet.php | <?php
final class PhabricatorBadgesIconSet
extends PhabricatorIconSet {
const ICONSETKEY = 'badges';
public function getSelectIconTitleText() {
return pht('Choose Badge Icon');
}
protected function newIcons() {
$map = array(
'fa-star' => pht('Superstar'),
'fa-user' => pht('Average Person'),
'fa-bug' => pht('Ladybug'),
'fa-users' => pht('Triplets'),
'fa-book' => pht('Nominomicon'),
'fa-rocket' => pht('Escape Route'),
'fa-life-ring' => pht('Foam Circle'),
'fa-birthday-cake' => pht('Cake Day'),
'fa-camera-retro' => pht('Leica Enthusiast'),
'fa-beer' => pht('Liquid Lunch'),
'fa-gift' => pht('Free Stuff'),
'fa-eye' => pht('Eye See You'),
'fa-heart' => pht('Love is Love'),
'fa-trophy' => pht('Winner at Things'),
'fa-umbrella' => pht('Rain Defender'),
'fa-graduation-cap' => pht('In Debt'),
'fa-empire' => pht('The Empire'),
'fa-first-order' => pht('First Order'),
'fa-rebel' => pht('Rebel'),
'fa-space-shuttle' => pht('Star Ship'),
'fa-anchor' => pht('Anchors Away'),
'fa-code' => pht('Coder'),
'fa-briefcase' => pht('Serious Business'),
'fa-globe' => pht('International'),
'fa-desktop' => pht('Glowing Rectangle'),
);
$icons = array();
foreach ($map as $key => $label) {
$icons[] = id(new PhabricatorIconSetIcon())
->setKey($key)
->setLabel($label);
}
return $icons;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/query/PhabricatorBadgesAwardQuery.php | src/applications/badges/query/PhabricatorBadgesAwardQuery.php | <?php
final class PhabricatorBadgesAwardQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $badgePHIDs;
private $recipientPHIDs;
private $awarderPHIDs;
private $badgeStatuses = null;
protected function willFilterPage(array $awards) {
$badge_phids = array();
foreach ($awards as $key => $award) {
$badge_phids[] = $award->getBadgePHID();
}
$badges = id(new PhabricatorBadgesQuery())
->setViewer($this->getViewer())
->withPHIDs($badge_phids)
->execute();
$badges = mpull($badges, null, 'getPHID');
foreach ($awards as $key => $award) {
$award_badge = idx($badges, $award->getBadgePHID());
if (!$award_badge) {
unset($awards[$key]);
$this->didRejectResult($award);
continue;
}
$award->attachBadge($award_badge);
}
return $awards;
}
public function withBadgePHIDs(array $phids) {
$this->badgePHIDs = $phids;
return $this;
}
public function withRecipientPHIDs(array $phids) {
$this->recipientPHIDs = $phids;
return $this;
}
public function withAwarderPHIDs(array $phids) {
$this->awarderPHIDs = $phids;
return $this;
}
public function withBadgeStatuses(array $statuses) {
$this->badgeStatuses = $statuses;
return $this;
}
private function shouldJoinBadge() {
return (bool)$this->badgeStatuses;
}
public function newResultObject() {
return new PhabricatorBadgesAward();
}
protected function getPrimaryTableAlias() {
return 'badges_award';
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->badgePHIDs !== null) {
$where[] = qsprintf(
$conn,
'badges_award.badgePHID IN (%Ls)',
$this->badgePHIDs);
}
if ($this->recipientPHIDs !== null) {
$where[] = qsprintf(
$conn,
'badges_award.recipientPHID IN (%Ls)',
$this->recipientPHIDs);
}
if ($this->awarderPHIDs !== null) {
$where[] = qsprintf(
$conn,
'badges_award.awarderPHID IN (%Ls)',
$this->awarderPHIDs);
}
if ($this->badgeStatuses !== null) {
$where[] = qsprintf(
$conn,
'badges_badge.status IN (%Ls)',
$this->badgeStatuses);
}
return $where;
}
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
$join = parent::buildJoinClauseParts($conn);
$badges = new PhabricatorBadgesBadge();
if ($this->shouldJoinBadge()) {
$join[] = qsprintf(
$conn,
'JOIN %T badges_badge ON badges_award.badgePHID = badges_badge.phid',
$badges->getTableName());
}
return $join;
}
public function getQueryApplicationClass() {
return 'PhabricatorBadgesApplication';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/query/PhabricatorBadgesSearchEngine.php | src/applications/badges/query/PhabricatorBadgesSearchEngine.php | <?php
final class PhabricatorBadgesSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Badges');
}
public function getApplicationClassName() {
return 'PhabricatorBadgesApplication';
}
public function newQuery() {
return new PhabricatorBadgesQuery();
}
protected function buildCustomSearchFields() {
return array(
id(new PhabricatorSearchTextField())
->setLabel(pht('Name Contains'))
->setKey('name')
->setDescription(pht('Search for badges by name substring.')),
id(new PhabricatorSearchCheckboxesField())
->setKey('qualities')
->setLabel(pht('Quality'))
->setEnableForConduit(false)
->setOptions(PhabricatorBadgesQuality::getDropdownQualityMap()),
id(new PhabricatorSearchCheckboxesField())
->setKey('statuses')
->setLabel(pht('Status'))
->setOptions(
id(new PhabricatorBadgesBadge())
->getStatusNameMap()),
);
}
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
if ($map['statuses']) {
$query->withStatuses($map['statuses']);
}
if ($map['qualities']) {
$query->withQualities($map['qualities']);
}
if ($map['name'] !== null) {
$query->withNameNgrams($map['name']);
}
return $query;
}
protected function getURI($path) {
return '/badges/'.$path;
}
protected function getBuiltinQueryNames() {
$names = array();
$names['open'] = pht('Active Badges');
$names['all'] = pht('All Badges');
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'all':
return $query;
case 'open':
return $query->setParameter(
'statuses',
array(
PhabricatorBadgesBadge::STATUS_ACTIVE,
));
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function getRequiredHandlePHIDsForResultList(
array $badges,
PhabricatorSavedQuery $query) {
$phids = array();
return $phids;
}
protected function renderResultList(
array $badges,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($badges, 'PhabricatorBadgesBadge');
$viewer = $this->requireViewer();
$list = id(new PHUIObjectItemListView());
foreach ($badges as $badge) {
$quality_name = PhabricatorBadgesQuality::getQualityName(
$badge->getQuality());
$mini_badge = id(new PHUIBadgeMiniView())
->setHeader($badge->getName())
->setIcon($badge->getIcon())
->setQuality($badge->getQuality());
$item = id(new PHUIObjectItemView())
->setHeader($badge->getName())
->setBadge($mini_badge)
->setHref('/badges/view/'.$badge->getID().'/')
->addAttribute($quality_name)
->addAttribute($badge->getFlavor());
if ($badge->isArchived()) {
$item->setDisabled(true);
$item->addIcon('fa-ban', pht('Archived'));
}
$list->addItem($item);
}
$result = new PhabricatorApplicationSearchResultView();
$result->setObjectList($list);
$result->setNoDataString(pht('No badges found.'));
return $result;
}
protected function getNewUserBody() {
$create_button = id(new PHUIButtonView())
->setTag('a')
->setText(pht('Create a Badge'))
->setHref('/badges/create/')
->setColor(PHUIButtonView::GREEN);
$icon = $this->getApplication()->getIcon();
$app_name = $this->getApplication()->getName();
$view = id(new PHUIBigInfoView())
->setIcon($icon)
->setTitle(pht('Welcome to %s', $app_name))
->setDescription(
pht('Badges let you award and distinguish special users '.
'throughout your install.'))
->addAction($create_button);
return $view;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/query/PhabricatorBadgesQuery.php | src/applications/badges/query/PhabricatorBadgesQuery.php | <?php
final class PhabricatorBadgesQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $phids;
private $qualities;
private $statuses;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function withQualities(array $qualities) {
$this->qualities = $qualities;
return $this;
}
public function withStatuses(array $statuses) {
$this->statuses = $statuses;
return $this;
}
public function withNameNgrams($ngrams) {
return $this->withNgramsConstraint(
id(new PhabricatorBadgesBadgeNameNgrams()),
$ngrams);
}
protected function getPrimaryTableAlias() {
return 'badges';
}
public function newResultObject() {
return new PhabricatorBadgesBadge();
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) {
$where[] = qsprintf(
$conn,
'badges.id IN (%Ld)',
$this->ids);
}
if ($this->phids !== null) {
$where[] = qsprintf(
$conn,
'badges.phid IN (%Ls)',
$this->phids);
}
if ($this->qualities !== null) {
$where[] = qsprintf(
$conn,
'badges.quality IN (%Ls)',
$this->qualities);
}
if ($this->statuses !== null) {
$where[] = qsprintf(
$conn,
'badges.status IN (%Ls)',
$this->statuses);
}
return $where;
}
public function getQueryApplicationClass() {
return 'PhabricatorBadgesApplication';
}
public function getBuiltinOrders() {
return array(
'quality' => array(
'vector' => array('quality', 'id'),
'name' => pht('Rarity (Rarest First)'),
),
'shoddiness' => array(
'vector' => array('-quality', '-id'),
'name' => pht('Rarity (Most Common First)'),
),
) + parent::getBuiltinOrders();
}
public function getOrderableColumns() {
return array(
'quality' => array(
'table' => $this->getPrimaryTableAlias(),
'column' => 'quality',
'reverse' => true,
'type' => 'int',
),
) + parent::getOrderableColumns();
}
protected function newPagingMapFromPartialObject($object) {
return array(
'id' => (int)$object->getID(),
'quality' => $object->getQuality(),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/query/PhabricatorBadgesTransactionQuery.php | src/applications/badges/query/PhabricatorBadgesTransactionQuery.php | <?php
final class PhabricatorBadgesTransactionQuery
extends PhabricatorApplicationTransactionQuery {
public function getTemplateApplicationTransaction() {
return new PhabricatorBadgesTransaction();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/mail/PhabricatorBadgesMailReceiver.php | src/applications/badges/mail/PhabricatorBadgesMailReceiver.php | <?php
final class PhabricatorBadgesMailReceiver
extends PhabricatorObjectMailReceiver {
public function isEnabled() {
return PhabricatorApplication::isClassInstalled(
'PhabricatorBadgesApplication');
}
protected function getObjectPattern() {
return 'BDGE[1-9]\d*';
}
protected function loadObject($pattern, PhabricatorUser $viewer) {
$id = (int)substr($pattern, 4);
return id(new PhabricatorBadgesQuery())
->setViewer($viewer)
->withIDs(array($id))
->executeOne();
}
protected function getTransactionReplyHandler() {
return new PhabricatorBadgesReplyHandler();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/mail/PhabricatorBadgesReplyHandler.php | src/applications/badges/mail/PhabricatorBadgesReplyHandler.php | <?php
final class PhabricatorBadgesReplyHandler
extends PhabricatorApplicationTransactionReplyHandler {
public function validateMailReceiver($mail_receiver) {
if (!($mail_receiver instanceof PhabricatorBadgesBadge)) {
throw new Exception(pht('Mail receiver is not a %s!', 'Badges'));
}
}
public function getObjectPrefix() {
return 'BDGE';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/editor/PhabricatorBadgesEditor.php | src/applications/badges/editor/PhabricatorBadgesEditor.php | <?php
final class PhabricatorBadgesEditor
extends PhabricatorApplicationTransactionEditor {
public function getEditorApplicationClass() {
return 'PhabricatorBadgesApplication';
}
public function getEditorObjectsDescription() {
return pht('Badges');
}
public function getCreateObjectTitle($author, $object) {
return pht('%s created this badge.', $author);
}
public function getCreateObjectTitleForFeed($author, $object) {
return pht('%s created %s.', $author, $object);
}
protected function supportsSearch() {
return true;
}
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
$types[] = PhabricatorTransactions::TYPE_COMMENT;
$types[] = PhabricatorTransactions::TYPE_EDGE;
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
return $types;
}
protected function shouldSendMail(
PhabricatorLiskDAO $object,
array $xactions) {
return true;
}
public function getMailTagsMap() {
return array(
PhabricatorBadgesTransaction::MAILTAG_DETAILS =>
pht('Someone changes the badge\'s details.'),
PhabricatorBadgesTransaction::MAILTAG_COMMENT =>
pht('Someone comments on a badge.'),
PhabricatorBadgesTransaction::MAILTAG_OTHER =>
pht('Other badge activity not listed above occurs.'),
);
}
protected function shouldPublishFeedStory(
PhabricatorLiskDAO $object,
array $xactions) {
return true;
}
protected function expandTransactions(
PhabricatorLiskDAO $object,
array $xactions) {
$actor = $this->getActor();
$actor_phid = $actor->getPHID();
$results = parent::expandTransactions($object, $xactions);
// Automatically subscribe the author when they create a badge.
if ($this->getIsNewObject()) {
if ($actor_phid) {
$results[] = id(new PhabricatorBadgesTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)
->setNewValue(
array(
'+' => array($actor_phid => $actor_phid),
));
}
}
return $results;
}
protected function buildReplyHandler(PhabricatorLiskDAO $object) {
return id(new PhabricatorBadgesReplyHandler())
->setMailReceiver($object);
}
protected function buildMailTemplate(PhabricatorLiskDAO $object) {
$name = $object->getName();
$id = $object->getID();
$subject = pht('Badge %d: %s', $id, $name);
return id(new PhabricatorMetaMTAMail())
->setSubject($subject);
}
protected function getMailTo(PhabricatorLiskDAO $object) {
return array(
$object->getCreatorPHID(),
$this->requireActor()->getPHID(),
);
}
protected function buildMailBody(
PhabricatorLiskDAO $object,
array $xactions) {
$body = parent::buildMailBody($object, $xactions);
$body->addLinkSection(
pht('BADGE DETAIL'),
PhabricatorEnv::getProductionURI('/badges/view/'.$object->getID().'/'));
return $body;
}
protected function getMailSubjectPrefix() {
return pht('[Badge]');
}
protected function applyFinalEffects(
PhabricatorLiskDAO $object,
array $xactions) {
$badge_phid = $object->getPHID();
$user_phids = array();
$clear_everything = false;
foreach ($xactions as $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorBadgesBadgeAwardTransaction::TRANSACTIONTYPE:
case PhabricatorBadgesBadgeRevokeTransaction::TRANSACTIONTYPE:
foreach ($xaction->getNewValue() as $user_phid) {
$user_phids[] = $user_phid;
}
break;
default:
$clear_everything = true;
break;
}
}
if ($clear_everything) {
$awards = id(new PhabricatorBadgesAwardQuery())
->setViewer($this->getActor())
->withBadgePHIDs(array($badge_phid))
->execute();
foreach ($awards as $award) {
$user_phids[] = $award->getRecipientPHID();
}
}
if ($user_phids) {
PhabricatorUserCache::clearCaches(
PhabricatorUserBadgesCacheType::KEY_BADGES,
$user_phids);
}
return $xactions;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/editor/PhabricatorBadgesEditEngine.php | src/applications/badges/editor/PhabricatorBadgesEditEngine.php | <?php
final class PhabricatorBadgesEditEngine
extends PhabricatorEditEngine {
const ENGINECONST = 'badges.badge';
public function getEngineName() {
return pht('Badges');
}
public function getEngineApplicationClass() {
return 'PhabricatorBadgesApplication';
}
public function getSummaryHeader() {
return pht('Configure Badges Forms');
}
public function getSummaryText() {
return pht('Configure creation and editing forms in Badges.');
}
public function isEngineConfigurable() {
return false;
}
protected function newEditableObject() {
return PhabricatorBadgesBadge::initializeNewBadge($this->getViewer());
}
protected function newObjectQuery() {
return new PhabricatorBadgesQuery();
}
protected function getObjectCreateTitleText($object) {
return pht('Create New Badge');
}
protected function getObjectEditTitleText($object) {
return pht('Edit Badge: %s', $object->getName());
}
protected function getObjectEditShortText($object) {
return $object->getName();
}
protected function getObjectCreateShortText() {
return pht('Create Badge');
}
protected function getObjectName() {
return pht('Badge');
}
protected function getObjectCreateCancelURI($object) {
return $this->getApplication()->getApplicationURI('/');
}
protected function getEditorURI() {
return $this->getApplication()->getApplicationURI('edit/');
}
protected function getCommentViewHeaderText($object) {
return pht('Render Honors');
}
protected function getCommentViewButtonText($object) {
return pht('Salute');
}
protected function getObjectViewURI($object) {
return $object->getViewURI();
}
protected function getCreateNewObjectPolicy() {
return $this->getApplication()->getPolicy(
PhabricatorBadgesCreateCapability::CAPABILITY);
}
protected function buildCustomEditFields($object) {
return array(
id(new PhabricatorTextEditField())
->setKey('name')
->setLabel(pht('Name'))
->setDescription(pht('Badge name.'))
->setConduitTypeDescription(pht('New badge name.'))
->setTransactionType(
PhabricatorBadgesBadgeNameTransaction::TRANSACTIONTYPE)
->setValue($object->getName())
->setIsRequired(true),
id(new PhabricatorTextEditField())
->setKey('flavor')
->setLabel(pht('Flavor Text'))
->setDescription(pht('Short description of the badge.'))
->setConduitTypeDescription(pht('New badge flavor.'))
->setValue($object->getFlavor())
->setTransactionType(
PhabricatorBadgesBadgeFlavorTransaction::TRANSACTIONTYPE),
id(new PhabricatorIconSetEditField())
->setKey('icon')
->setLabel(pht('Icon'))
->setIconSet(new PhabricatorBadgesIconSet())
->setTransactionType(
PhabricatorBadgesBadgeIconTransaction::TRANSACTIONTYPE)
->setConduitDescription(pht('Change the badge icon.'))
->setConduitTypeDescription(pht('New badge icon.'))
->setValue($object->getIcon()),
id(new PhabricatorSelectEditField())
->setKey('quality')
->setLabel(pht('Quality'))
->setDescription(pht('Color and rarity of the badge.'))
->setConduitTypeDescription(pht('New badge quality.'))
->setValue($object->getQuality())
->setTransactionType(
PhabricatorBadgesBadgeQualityTransaction::TRANSACTIONTYPE)
->setOptions(PhabricatorBadgesQuality::getDropdownQualityMap()),
id(new PhabricatorRemarkupEditField())
->setKey('description')
->setLabel(pht('Description'))
->setDescription(pht('Badge long description.'))
->setConduitTypeDescription(pht('New badge description.'))
->setTransactionType(
PhabricatorBadgesBadgeDescriptionTransaction::TRANSACTIONTYPE)
->setValue($object->getDescription()),
id(new PhabricatorUsersEditField())
->setKey('award')
->setIsFormField(false)
->setDescription(pht('New badge award recipients.'))
->setConduitTypeDescription(pht('New badge award recipients.'))
->setTransactionType(
PhabricatorBadgesBadgeAwardTransaction::TRANSACTIONTYPE)
->setLabel(pht('Award Recipients')),
id(new PhabricatorUsersEditField())
->setKey('revoke')
->setIsFormField(false)
->setDescription(pht('Revoke badge award recipients.'))
->setConduitTypeDescription(pht('Revoke badge award recipients.'))
->setTransactionType(
PhabricatorBadgesBadgeRevokeTransaction::TRANSACTIONTYPE)
->setLabel(pht('Revoke Recipients')),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/xaction/PhabricatorBadgesBadgeDescriptionTransaction.php | src/applications/badges/xaction/PhabricatorBadgesBadgeDescriptionTransaction.php | <?php
final class PhabricatorBadgesBadgeDescriptionTransaction
extends PhabricatorBadgesBadgeTransactionType {
const TRANSACTIONTYPE = 'badge.description';
public function generateOldValue($object) {
return $object->getDescription();
}
public function applyInternalEffects($object, $value) {
$object->setDescription($value);
}
public function getTitle() {
return pht(
'%s updated the badge description.',
$this->renderAuthor());
}
public function getTitleForFeed() {
return pht(
'%s updated the badge description for %s.',
$this->renderAuthor(),
$this->renderObject());
}
public function hasChangeDetailView() {
return true;
}
public function getMailDiffSectionHeader() {
return pht('CHANGES TO BADGE DESCRIPTION');
}
public function newChangeDetailView() {
$viewer = $this->getViewer();
return id(new PhabricatorApplicationTransactionTextDiffDetailView())
->setViewer($viewer)
->setOldText($this->getOldValue())
->setNewText($this->getNewValue());
}
public function newRemarkupChanges() {
$changes = array();
$changes[] = $this->newRemarkupChange()
->setOldValue($this->getOldValue())
->setNewValue($this->getNewValue());
return $changes;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/xaction/PhabricatorBadgesBadgeFlavorTransaction.php | src/applications/badges/xaction/PhabricatorBadgesBadgeFlavorTransaction.php | <?php
final class PhabricatorBadgesBadgeFlavorTransaction
extends PhabricatorBadgesBadgeTransactionType {
const TRANSACTIONTYPE = 'badge.flavor';
public function generateOldValue($object) {
return $object->getFlavor();
}
public function applyInternalEffects($object, $value) {
$object->setFlavor($value);
}
public function getTitle() {
return pht(
'%s updated the flavor from %s to %s.',
$this->renderAuthor(),
$this->renderOldValue(),
$this->renderNewValue());
}
public function getTitleForFeed() {
return pht(
'%s updated %s flavor text from %s to %s.',
$this->renderAuthor(),
$this->renderObject(),
$this->renderOldValue(),
$this->renderNewValue());
}
public function validateTransactions($object, array $xactions) {
$errors = array();
$max_length = $object->getColumnMaximumByteLength('flavor');
foreach ($xactions as $xaction) {
$new_value = $xaction->getNewValue();
$new_length = strlen($new_value);
if ($new_length > $max_length) {
$errors[] = $this->newRequiredError(
pht('The flavor text can be no longer than %s characters.',
new PhutilNumber($max_length)));
}
}
return $errors;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/xaction/PhabricatorBadgesBadgeQualityTransaction.php | src/applications/badges/xaction/PhabricatorBadgesBadgeQualityTransaction.php | <?php
final class PhabricatorBadgesBadgeQualityTransaction
extends PhabricatorBadgesBadgeTransactionType {
const TRANSACTIONTYPE = 'badge.quality';
public function generateOldValue($object) {
return $object->getQuality();
}
public function applyInternalEffects($object, $value) {
$object->setQuality($value);
}
public function shouldHide() {
if ($this->isCreateTransaction()) {
return true;
}
return false;
}
public function getTitle() {
$old = $this->getQualityLabel($this->getOldValue());
$new = $this->getQualityLabel($this->getNewValue());
return pht(
'%s updated the quality from %s to %s.',
$this->renderAuthor(),
$old,
$new);
}
public function getTitleForFeed() {
$old = $this->getQualityLabel($this->getOldValue());
$new = $this->getQualityLabel($this->getNewValue());
return pht(
'%s updated the quality of %s from %s to %s.',
$this->renderAuthor(),
$this->renderObject(),
$old,
$new);
}
public function validateTransactions($object, array $xactions) {
$errors = array();
if ($this->isEmptyTextTransaction($object->getQuality(), $xactions)) {
$errors[] = $this->newRequiredError(
pht('Badge quality must be set.'));
}
$map = PhabricatorBadgesQuality::getQualityMap();
if (!$map[$object->getQuality()]) {
$errors[] = $this->newRequiredError(
pht('Badge quality is not valid.'));
}
return $errors;
}
private function getQualityLabel($quality) {
$map = PhabricatorBadgesQuality::getQualityMap();
$name = $map[$quality]['name'];
return $this->renderValue($name);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/xaction/PhabricatorBadgesBadgeAwardTransaction.php | src/applications/badges/xaction/PhabricatorBadgesBadgeAwardTransaction.php | <?php
final class PhabricatorBadgesBadgeAwardTransaction
extends PhabricatorBadgesBadgeTransactionType {
const TRANSACTIONTYPE = 'badge.award';
public function generateOldValue($object) {
return null;
}
public function applyExternalEffects($object, $value) {
foreach ($value as $phid) {
$award = PhabricatorBadgesAward::initializeNewBadgesAward(
$this->getActor(),
$object,
$phid);
$award->save();
}
return;
}
public function getTitle() {
$new = $this->getNewValue();
if (!is_array($new)) {
$new = array();
}
$handles = $this->renderHandleList($new);
return pht(
'%s awarded this badge to %s recipient(s): %s.',
$this->renderAuthor(),
new PhutilNumber(count($new)),
$handles);
}
public function getTitleForFeed() {
$new = $this->getNewValue();
if (!is_array($new)) {
$new = array();
}
$handles = $this->renderHandleList($new);
return pht(
'%s awarded %s to %s recipient(s): %s.',
$this->renderAuthor(),
$this->renderObject(),
new PhutilNumber(count($new)),
$handles);
}
public function getIcon() {
return 'fa-user-plus';
}
public function validateTransactions($object, array $xactions) {
$errors = array();
foreach ($xactions as $xaction) {
$user_phids = $xaction->getNewValue();
if (!$user_phids) {
$errors[] = $this->newRequiredError(
pht('Recipient is required.'));
continue;
}
foreach ($user_phids as $user_phid) {
// Check if a valid user
$user = id(new PhabricatorPeopleQuery())
->setViewer($this->getActor())
->withPHIDs(array($user_phid))
->executeOne();
if (!$user) {
$errors[] = $this->newInvalidError(
pht(
'Recipient PHID "%s" is not a valid user PHID.',
$user_phid));
continue;
}
// Check if already awarded
$award = id(new PhabricatorBadgesAwardQuery())
->setViewer($this->getActor())
->withRecipientPHIDs(array($user_phid))
->withBadgePHIDs(array($object->getPHID()))
->executeOne();
if ($award) {
$errors[] = $this->newInvalidError(
pht(
'%s has already been awarded this badge.',
$user->getUsername()));
}
}
}
return $errors;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/xaction/PhabricatorBadgesBadgeIconTransaction.php | src/applications/badges/xaction/PhabricatorBadgesBadgeIconTransaction.php | <?php
final class PhabricatorBadgesBadgeIconTransaction
extends PhabricatorBadgesBadgeTransactionType {
const TRANSACTIONTYPE = 'badge.icon';
public function generateOldValue($object) {
return $object->getIcon();
}
public function applyInternalEffects($object, $value) {
$object->setIcon($value);
}
public function shouldHide() {
if ($this->isCreateTransaction()) {
return true;
}
return false;
}
public function getTitle() {
$old = $this->getIconLabel($this->getOldValue());
$new = $this->getIconLabel($this->getNewValue());
return pht(
'%s changed the badge icon from %s to %s.',
$this->renderAuthor(),
$this->renderValue($old),
$this->renderValue($new));
}
public function getTitleForFeed() {
$old = $this->getIconLabel($this->getOldValue());
$new = $this->getIconLabel($this->getNewValue());
return pht(
'%s changed the badge icon for %s from %s to %s.',
$this->renderAuthor(),
$this->renderObject(),
$this->renderValue($old),
$this->renderValue($new));
}
private function getIconLabel($icon) {
$set = new PhabricatorBadgesIconSet();
return $set->getIconLabel($icon);
}
public function getIcon() {
return $this->getNewValue();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/xaction/PhabricatorBadgesBadgeStatusTransaction.php | src/applications/badges/xaction/PhabricatorBadgesBadgeStatusTransaction.php | <?php
final class PhabricatorBadgesBadgeStatusTransaction
extends PhabricatorBadgesBadgeTransactionType {
const TRANSACTIONTYPE = 'badges.status';
public function generateOldValue($object) {
return $object->getStatus();
}
public function applyInternalEffects($object, $value) {
$object->setStatus($value);
}
public function getTitle() {
if ($this->getNewValue() == PhabricatorBadgesBadge::STATUS_ARCHIVED) {
return pht(
'%s disabled this badge.',
$this->renderAuthor());
} else {
return pht(
'%s enabled this badge.',
$this->renderAuthor());
}
}
public function getTitleForFeed() {
if ($this->getNewValue() == PhabricatorBadgesBadge::STATUS_ARCHIVED) {
return pht(
'%s disabled the badge %s.',
$this->renderAuthor(),
$this->renderObject());
} else {
return pht(
'%s enabled the badge %s.',
$this->renderAuthor(),
$this->renderObject());
}
}
public function getIcon() {
if ($this->getNewValue() == PhabricatorBadgesBadge::STATUS_ARCHIVED) {
return 'fa-ban';
} else {
return 'fa-check';
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/xaction/PhabricatorBadgesBadgeTransactionType.php | src/applications/badges/xaction/PhabricatorBadgesBadgeTransactionType.php | <?php
abstract class PhabricatorBadgesBadgeTransactionType
extends PhabricatorModularTransactionType {}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/xaction/PhabricatorBadgesBadgeRevokeTransaction.php | src/applications/badges/xaction/PhabricatorBadgesBadgeRevokeTransaction.php | <?php
final class PhabricatorBadgesBadgeRevokeTransaction
extends PhabricatorBadgesBadgeTransactionType {
const TRANSACTIONTYPE = 'badge.revoke';
public function generateOldValue($object) {
return null;
}
public function applyExternalEffects($object, $value) {
$awards = id(new PhabricatorBadgesAwardQuery())
->setViewer($this->getActor())
->withRecipientPHIDs($value)
->withBadgePHIDs(array($object->getPHID()))
->execute();
$awards = mpull($awards, null, 'getRecipientPHID');
foreach ($value as $phid) {
$awards[$phid]->delete();
}
return;
}
public function getTitle() {
$new = $this->getNewValue();
if (!is_array($new)) {
$new = array();
}
$handles = $this->renderHandleList($new);
return pht(
'%s revoked this badge from %s recipient(s): %s.',
$this->renderAuthor(),
new PhutilNumber(count($new)),
$handles);
}
public function getTitleForFeed() {
$new = $this->getNewValue();
if (!is_array($new)) {
$new = array();
}
$handles = $this->renderHandleList($new);
return pht(
'%s revoked %s from %s recipient(s): %s.',
$this->renderAuthor(),
$this->renderObject(),
new PhutilNumber(count($new)),
$handles);
}
public function getIcon() {
return 'fa-user-times';
}
public function validateTransactions($object, array $xactions) {
$errors = array();
foreach ($xactions as $xaction) {
$award_phids = $xaction->getNewValue();
if (!$award_phids) {
$errors[] = $this->newRequiredError(
pht('Recipient is required.'));
continue;
}
foreach ($award_phids as $award_phid) {
$award = id(new PhabricatorBadgesAwardQuery())
->setViewer($this->getActor())
->withRecipientPHIDs(array($award_phid))
->withBadgePHIDs(array($object->getPHID()))
->executeOne();
if (!$award) {
$errors[] = $this->newInvalidError(
pht(
'Recipient PHID "%s" has not been awarded.',
$award_phid));
}
}
}
return $errors;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/xaction/PhabricatorBadgesBadgeNameTransaction.php | src/applications/badges/xaction/PhabricatorBadgesBadgeNameTransaction.php | <?php
final class PhabricatorBadgesBadgeNameTransaction
extends PhabricatorBadgesBadgeTransactionType {
const TRANSACTIONTYPE = 'badge.name';
public function generateOldValue($object) {
return $object->getName();
}
public function applyInternalEffects($object, $value) {
$object->setName($value);
}
public function getTitle() {
return pht(
'%s renamed this badge from %s to %s.',
$this->renderAuthor(),
$this->renderOldValue(),
$this->renderNewValue());
}
public function getTitleForFeed() {
return pht(
'%s renamed %s badge %s to %s.',
$this->renderAuthor(),
$this->renderObject(),
$this->renderOldValue(),
$this->renderNewValue());
}
public function validateTransactions($object, array $xactions) {
$errors = array();
if ($this->isEmptyTextTransaction($object->getName(), $xactions)) {
$errors[] = $this->newRequiredError(
pht('Badges must have a name.'));
}
$max_length = $object->getColumnMaximumByteLength('name');
foreach ($xactions as $xaction) {
$new_value = $xaction->getNewValue();
$new_length = strlen($new_value);
if ($new_length > $max_length) {
$errors[] = $this->newInvalidError(
pht('The name can be no longer than %s characters.',
new PhutilNumber($max_length)));
}
}
return $errors;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/application/PhabricatorBadgesApplication.php | src/applications/badges/application/PhabricatorBadgesApplication.php | <?php
final class PhabricatorBadgesApplication extends PhabricatorApplication {
public function getName() {
return pht('Badges');
}
public function getBaseURI() {
return '/badges/';
}
public function getShortDescription() {
return pht('Achievements and Notoriety');
}
public function getIcon() {
return 'fa-trophy';
}
public function getFlavorText() {
return pht('Build self esteem through gamification.');
}
public function getApplicationGroup() {
return self::GROUP_UTILITIES;
}
public function getRoutes() {
return array(
'/badges/' => array(
'(?:query/(?P<queryKey>[^/]+)/)?'
=> 'PhabricatorBadgesListController',
'award/(?:(?P<id>\d+)/)?'
=> 'PhabricatorBadgesAwardController',
'create/'
=> 'PhabricatorBadgesEditController',
'comment/(?P<id>[1-9]\d*)/'
=> 'PhabricatorBadgesCommentController',
$this->getEditRoutePattern('edit/')
=> 'PhabricatorBadgesEditController',
'archive/(?:(?P<id>\d+)/)?'
=> 'PhabricatorBadgesArchiveController',
'view/(?:(?P<id>\d+)/)?'
=> 'PhabricatorBadgesViewController',
'recipients/' => array(
'(?P<id>[1-9]\d*)/'
=> 'PhabricatorBadgesRecipientsController',
'(?P<id>[1-9]\d*)/add/'
=> 'PhabricatorBadgesEditRecipientsController',
'(?P<id>[1-9]\d*)/remove/'
=> 'PhabricatorBadgesRemoveRecipientsController',
),
),
);
}
protected function getCustomCapabilities() {
return array(
PhabricatorBadgesCreateCapability::CAPABILITY => array(
'default' => PhabricatorPolicies::POLICY_ADMIN,
'caption' => pht('Default create policy for badges.'),
),
PhabricatorBadgesDefaultEditCapability::CAPABILITY => array(
'default' => PhabricatorPolicies::POLICY_ADMIN,
'caption' => pht('Default edit policy for badges.'),
'template' => PhabricatorBadgesPHIDType::TYPECONST,
),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/lipsum/PhabricatorBadgesLootContextFreeGrammar.php | src/applications/badges/lipsum/PhabricatorBadgesLootContextFreeGrammar.php | <?php
final class PhabricatorBadgesLootContextFreeGrammar
extends PhutilContextFreeGrammar {
protected function getRules() {
return array(
'start' => array(
'[jewelry]',
),
'jewelry' => array(
'Ring [jewelry-suffix]',
'Ring [jewelry-suffix]',
'[jewelry-prefix] Ring',
'[jewelry-prefix] Ring',
'Amulet [jewelry-suffix]',
'Amulet [jewelry-suffix]',
'[jewelry-prefix] Amulet',
'[jewelry-prefix] Amulet',
'[jewelry-prefix] Ring [jewelry-suffix]',
'[jewelry-prefix] Amulet [jewelry-suffix]',
'[unique-jewelry]',
),
'jewelry-prefix' => array(
'[mana-prefix]',
),
'jewelry-suffix' => array(
'[dexterity-suffix]',
'[dexterity-suffix-jewelry]',
),
'mana-prefix' => array(
'Hyena\'s (-<11-25> Mana)',
'Frog\'s (-<1-10> Mana)',
'Spider\'s (+<10-15> Mana)',
'Raven\'s (+<15-20> Mana)',
'Snake\'s (+<21-30> Mana)',
'Serpent\'s (+<31-40> Mana)',
'Drake\'s (+<41-50> Mana)',
'Dragon\'s (+<51-60> Mana)',
),
'dexterity-suffix' => array(
'of Paralysis (-<6-10> Dexterity)',
'of Atrophy (-<1-5> Dexterity)',
'of Dexterity (+<1-5> Dexterity)',
'of Skill (+<6-10> Dexterity)',
'of Accuracy (+<11-15> Dexterity)',
'of Precision (+<16-20> Dexterity)',
),
'dexterity-suffix-jewelry' => array(
'[dexterity-suffix]',
'[dexterity-suffix]',
'[dexterity-suffix]',
'[dexterity-suffix]',
'[dexterity-suffix]',
'[dexterity-suffix]',
'[dexterity-suffix]',
'[dexterity-suffix]',
'[dexterity-suffix]',
'of Perfection (+<21-30> Dexterity)',
),
'unique-jewelry' => array(
'[jewelry]',
'[jewelry]',
'[jewelry]',
'[jewelry]',
'[jewelry]',
'[jewelry]',
'[jewelry]',
'[jewelry]',
'[unique-ring]',
'[unique-amulet]',
),
'unique-ring' => array(
'The Bleeder',
'The Bramble',
'Constricting Ring',
'Empyrean Band',
'Ring of Engagement',
'Ring of Regha',
),
'unique-amulet' => array(
'Optic Amulet',
),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/lipsum/PhabricatorBadgesBadgeTestDataGenerator.php | src/applications/badges/lipsum/PhabricatorBadgesBadgeTestDataGenerator.php | <?php
final class PhabricatorBadgesBadgeTestDataGenerator
extends PhabricatorTestDataGenerator {
const GENERATORKEY = 'badges';
public function getGeneratorName() {
return pht('Badges');
}
public function generateObject() {
$author = $this->loadRandomUser();
list($name, $description, $quality, $icon) = $this->newLoot();
$xactions = array();
$xactions[] = array(
'type' => 'name',
'value' => $name,
);
$xactions[] = array(
'type' => 'description',
'value' => $description,
);
$xactions[] = array(
'type' => 'quality',
'value' => (string)$quality,
);
$xactions[] = array(
'type' => 'icon',
'value' => $icon,
);
$params = array(
'transactions' => $xactions,
);
$result = id(new ConduitCall('badge.edit', $params))
->setUser($author)
->execute();
return $result['object']['phid'];
}
private function newLoot() {
$drop = id(new PhabricatorBadgesLootContextFreeGrammar())
->generate();
$drop = preg_replace_callback(
'/<(\d+)-(\d+)>/',
array($this, 'rollDropValue'),
$drop);
$effect_pattern = '/\s*\(([^)]+)\)/';
$matches = null;
if (preg_match_all($effect_pattern, $drop, $matches)) {
$description = $matches[1];
$description = implode("\n", $description);
} else {
$description = '';
}
$drop = preg_replace($effect_pattern, '', $drop);
$quality_map = PhabricatorBadgesQuality::getQualityMap();
shuffle($quality_map);
$quality = head($quality_map);
$rarity = $quality['rarity'];
$icon_map = id(new PhabricatorBadgesIconSet())->getIcons();
shuffle($icon_map);
$icon_map = head($icon_map);
$icon = $icon_map->getKey();
return array($drop, $description, $rarity, $icon);
}
public function rollDropValue($matches) {
$min = (int)$matches[1];
$max = (int)$matches[2];
return mt_rand($min, $max);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/lipsum/PhabricatorBadgesAwardTestDataGenerator.php | src/applications/badges/lipsum/PhabricatorBadgesAwardTestDataGenerator.php | <?php
final class PhabricatorBadgesAwardTestDataGenerator
extends PhabricatorTestDataGenerator {
const GENERATORKEY = 'badges.award';
public function getGeneratorName() {
return pht('Badges Award');
}
public function generateObject() {
$author = $this->loadRandomUser();
$recipient = $this->loadRandomUser();
$badge_phid = $this->loadRandomPHID(new PhabricatorBadgesBadge());
$xactions = array();
$xactions[] = array(
'type' => 'award',
'value' => array($recipient->getPHID()),
);
$params = array(
'transactions' => $xactions,
'objectIdentifier' => $badge_phid,
);
$result = id(new ConduitCall('badge.edit', $params))
->setUser($author)
->execute();
return $result['object']['phid'];
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/view/PhabricatorBadgesRecipientsListView.php | src/applications/badges/view/PhabricatorBadgesRecipientsListView.php | <?php
final class PhabricatorBadgesRecipientsListView extends AphrontView {
private $badge;
private $awards;
private $handles;
public function setBadge(PhabricatorBadgesBadge $badge) {
$this->badge = $badge;
return $this;
}
public function setAwards(array $awards) {
$this->awards = $awards;
return $this;
}
public function setHandles(array $handles) {
$this->handles = $handles;
return $this;
}
public function render() {
$viewer = $this->getViewer();
$badge = $this->badge;
$handles = $this->handles;
$awards = mpull($this->awards, null, 'getRecipientPHID');
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$badge,
PhabricatorPolicyCapability::CAN_EDIT);
$award_button = id(new PHUIButtonView())
->setTag('a')
->setIcon('fa-plus')
->setText(pht('Add Recipients'))
->setWorkflow(true)
->setDisabled(!$can_edit)
->setHref('/badges/recipients/'.$badge->getID().'/add/');
$header = id(new PHUIHeaderView())
->setHeader(pht('Recipients'))
->addActionLink($award_button);
$list = id(new PHUIObjectItemListView())
->setNoDataString(pht('This badge does not have any recipients.'))
->setFlush(true);
foreach ($handles as $handle) {
$remove_uri = '/badges/recipients/'.
$badge->getID().'/remove/?phid='.$handle->getPHID();
$award = $awards[$handle->getPHID()];
$awarder_handle = $viewer->renderHandle($award->getAwarderPHID());
$award_date = phabricator_date($award->getDateCreated(), $viewer);
$awarder_info = pht(
'Awarded by %s on %s',
$awarder_handle->render(),
$award_date);
$item = id(new PHUIObjectItemView())
->setHeader($handle->getFullName())
->setSubhead($awarder_info)
->setHref($handle->getURI())
->setImageURI($handle->getImageURI());
if ($can_edit) {
$item->addAction(
id(new PHUIListItemView())
->setIcon('fa-times')
->setName(pht('Remove'))
->setHref($remove_uri)
->setWorkflow(true));
}
$list->addItem($item);
}
$box = id(new PHUIObjectBoxView())
->setHeader($header)
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
->setObjectList($list);
return $box;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/phid/PhabricatorBadgesPHIDType.php | src/applications/badges/phid/PhabricatorBadgesPHIDType.php | <?php
final class PhabricatorBadgesPHIDType extends PhabricatorPHIDType {
const TYPECONST = 'BDGE';
public function getTypeName() {
return pht('Badge');
}
public function newObject() {
return new PhabricatorBadgesBadge();
}
public function getPHIDTypeApplicationClass() {
return 'PhabricatorBadgesApplication';
}
protected function buildQueryForObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new PhabricatorBadgesQuery())
->withPHIDs($phids);
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
foreach ($handles as $phid => $handle) {
$badge = $objects[$phid];
$id = $badge->getID();
$name = $badge->getName();
if ($badge->isArchived()) {
$handle->setStatus(PhabricatorObjectHandle::STATUS_CLOSED);
}
$handle->setName($name);
$handle->setURI("/badges/view/{$id}/");
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/conduit/PhabricatorBadgesEditConduitAPIMethod.php | src/applications/badges/conduit/PhabricatorBadgesEditConduitAPIMethod.php | <?php
final class PhabricatorBadgesEditConduitAPIMethod
extends PhabricatorEditEngineAPIMethod {
public function getAPIMethodName() {
return 'badge.edit';
}
public function newEditEngine() {
return new PhabricatorBadgesEditEngine();
}
public function getMethodSummary() {
return pht(
'Apply transactions to create a new badge or edit an existing one.');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/conduit/PhabricatorBadgesSearchConduitAPIMethod.php | src/applications/badges/conduit/PhabricatorBadgesSearchConduitAPIMethod.php | <?php
final class PhabricatorBadgesSearchConduitAPIMethod
extends PhabricatorSearchEngineAPIMethod {
public function getAPIMethodName() {
return 'badge.search';
}
public function newSearchEngine() {
return new PhabricatorBadgesSearchEngine();
}
public function getMethodSummary() {
return pht('Read information about badges.');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/typeahead/PhabricatorBadgesDatasource.php | src/applications/badges/typeahead/PhabricatorBadgesDatasource.php | <?php
final class PhabricatorBadgesDatasource
extends PhabricatorTypeaheadDatasource {
public function getBrowseTitle() {
return pht('Browse Badges');
}
public function getPlaceholderText() {
return pht('Type a badge name...');
}
public function getDatasourceApplicationClass() {
return 'PhabricatorBadgesApplication';
}
public function loadResults() {
$viewer = $this->getViewer();
$raw_query = $this->getRawQuery();
$params = $this->getParameters();
$recipient_phid = $params['recipientPHID'];
$badges = id(new PhabricatorBadgesQuery())
->setViewer($viewer)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->execute();
$awards = id(new PhabricatorBadgesAwardQuery())
->setViewer($viewer)
->withAwarderPHIDs(array($viewer->getPHID()))
->withRecipientPHIDs(array($recipient_phid))
->execute();
$awards = mpull($awards, null, 'getBadgePHID');
$results = array();
foreach ($badges as $badge) {
$closed = null;
$badge_awards = idx($awards, $badge->getPHID(), null);
if ($badge_awards) {
$closed = pht('Already awarded');
}
$status = $badge->getStatus();
if ($status === PhabricatorBadgesBadge::STATUS_ARCHIVED) {
$closed = pht('Archived');
}
$results[] = id(new PhabricatorTypeaheadResult())
->setName($badge->getName())
->setIcon($badge->getIcon())
->setColor(
PhabricatorBadgesQuality::getQualityColor($badge->getQuality()))
->setClosed($closed)
->setPHID($badge->getPHID());
}
$results = $this->filterResultsAgainstTokens($results);
return $results;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/capability/PhabricatorBadgesDefaultEditCapability.php | src/applications/badges/capability/PhabricatorBadgesDefaultEditCapability.php | <?php
final class PhabricatorBadgesDefaultEditCapability
extends PhabricatorPolicyCapability {
const CAPABILITY = 'badges.default.edit';
public function getCapabilityName() {
return pht('Default Edit Badges');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/capability/PhabricatorBadgesCreateCapability.php | src/applications/badges/capability/PhabricatorBadgesCreateCapability.php | <?php
final class PhabricatorBadgesCreateCapability
extends PhabricatorPolicyCapability {
const CAPABILITY = 'badges.default.create';
public function getCapabilityName() {
return pht('Can Create Badges');
}
public function describeCapabilityRejection() {
return pht('You do not have permission to create badges.');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/badges/constants/PhabricatorBadgesQuality.php | src/applications/badges/constants/PhabricatorBadgesQuality.php | <?php
final class PhabricatorBadgesQuality
extends Phobject {
const POOR = 140;
const COMMON = 120;
const UNCOMMON = 100;
const RARE = 80;
const EPIC = 60;
const LEGENDARY = 40;
const HEIRLOOM = 20;
const DEFAULT_QUALITY = 140;
public static function getQualityName($quality) {
$map = self::getQualityDictionary($quality);
$default = pht('Unknown Quality ("%s")', $quality);
return idx($map, 'name', $default);
}
public static function getQualityColor($quality) {
$map = self::getQualityDictionary($quality);
$default = 'grey';
return idx($map, 'color', $default);
}
private static function getQualityDictionary($quality) {
$map = self::getQualityMap();
$default = array();
return idx($map, $quality, $default);
}
public static function getQualityMap() {
return array(
self::POOR => array(
'rarity' => 140,
'name' => pht('Poor'),
'color' => 'grey',
),
self::COMMON => array(
'rarity' => 120,
'name' => pht('Common'),
'color' => 'white',
),
self::UNCOMMON => array(
'rarity' => 100,
'name' => pht('Uncommon'),
'color' => 'green',
),
self::RARE => array(
'rarity' => 80,
'name' => pht('Rare'),
'color' => 'blue',
),
self::EPIC => array(
'rarity' => 60,
'name' => pht('Epic'),
'color' => 'indigo',
),
self::LEGENDARY => array(
'rarity' => 40,
'name' => pht('Legendary'),
'color' => 'orange',
),
self::HEIRLOOM => array(
'rarity' => 20,
'name' => pht('Heirloom'),
'color' => 'yellow',
),
);
}
public static function getDropdownQualityMap() {
$map = self::getQualityMap();
return ipull($map, 'name');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/controller/PassphraseCredentialDestroyController.php | src/applications/passphrase/controller/PassphraseCredentialDestroyController.php | <?php
final class PassphraseCredentialDestroyController
extends PassphraseController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$credential = id(new PassphraseCredentialQuery())
->setViewer($viewer)
->withIDs(array($id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$credential) {
return new Aphront404Response();
}
$type = PassphraseCredentialType::getTypeByConstant(
$credential->getCredentialType());
if (!$type) {
throw new Exception(pht('Credential has invalid type "%s"!', $type));
}
$view_uri = '/K'.$credential->getID();
if ($request->isFormPost()) {
$xactions = array();
$xactions[] = id(new PassphraseCredentialTransaction())
->setTransactionType(
PassphraseCredentialDestroyTransaction::TRANSACTIONTYPE)
->setNewValue(1);
$editor = id(new PassphraseCredentialTransactionEditor())
->setActor($viewer)
->setContinueOnMissingFields(true)
->setContentSourceFromRequest($request)
->applyTransactions($credential, $xactions);
return id(new AphrontRedirectResponse())->setURI($view_uri);
}
return $this->newDialog()
->setUser($viewer)
->setTitle(pht('Really destroy credential?'))
->appendChild(
pht(
'This credential will be deactivated and the secret will be '.
'unrecoverably destroyed. Anything relying on this credential '.
'will cease to function. This operation can not be undone.'))
->addSubmitButton(pht('Destroy Credential'))
->addCancelButton($view_uri);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/controller/PassphraseCredentialCreateController.php | src/applications/passphrase/controller/PassphraseCredentialCreateController.php | <?php
final class PassphraseCredentialCreateController extends PassphraseController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$types = PassphraseCredentialType::getAllCreateableTypes();
$types = mpull($types, null, 'getCredentialType');
$types = msort($types, 'getCredentialTypeName');
$errors = array();
$e_type = null;
if ($request->isFormPost()) {
$type = $request->getStr('type');
if (empty($types[$type])) {
$errors[] = pht('You must choose a credential type.');
$e_type = pht('Required');
}
if (!$errors) {
$uri = $this->getApplicationURI('edit/?type='.$type);
return id(new AphrontRedirectResponse())->setURI($uri);
}
}
$types_control = id(new AphrontFormRadioButtonControl())
->setName('type')
->setLabel(pht('Credential Type'))
->setError($e_type);
foreach ($types as $type) {
$types_control->addButton(
$type->getCredentialType(),
$type->getCredentialTypeName(),
$type->getCredentialTypeDescription());
}
$form = id(new AphrontFormView())
->setUser($viewer)
->appendChild($types_control)
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Continue'))
->addCancelButton($this->getApplicationURI()));
$title = pht('New Credential');
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Create'));
$crumbs->setBorder(true);
$box = id(new PHUIObjectBoxView())
->setHeaderText($title)
->setFormErrors($errors)
->setBackground(PHUIObjectBoxView::WHITE_CONFIG)
->setForm($form);
$view = id(new PHUITwoColumnView())
->setFooter($box);
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->appendChild($view);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/controller/PassphraseCredentialConduitController.php | src/applications/passphrase/controller/PassphraseCredentialConduitController.php | <?php
final class PassphraseCredentialConduitController
extends PassphraseController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$credential = id(new PassphraseCredentialQuery())
->setViewer($viewer)
->withIDs(array($id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$credential) {
return new Aphront404Response();
}
$view_uri = '/K'.$credential->getID();
$token = id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession(
$viewer,
$request,
$view_uri);
$type = PassphraseCredentialType::getTypeByConstant(
$credential->getCredentialType());
if (!$type) {
throw new Exception(pht('Credential has invalid type "%s"!', $type));
}
$is_locked = $credential->getIsLocked();
if ($is_locked) {
return $this->newDialog()
->setUser($viewer)
->setTitle(pht('Credential Locked'))
->appendChild(
pht(
'This credential can not be made available via Conduit because '.
'it is locked.'))
->addCancelButton($view_uri);
}
if ($request->isFormPost()) {
$xactions = array();
$xactions[] = id(new PassphraseCredentialTransaction())
->setTransactionType(
PassphraseCredentialConduitTransaction::TRANSACTIONTYPE)
->setNewValue(!$credential->getAllowConduit());
$editor = id(new PassphraseCredentialTransactionEditor())
->setActor($viewer)
->setContinueOnMissingFields(true)
->setContentSourceFromRequest($request)
->applyTransactions($credential, $xactions);
return id(new AphrontRedirectResponse())->setURI($view_uri);
}
if ($credential->getAllowConduit()) {
return $this->newDialog()
->setTitle(pht('Prevent Conduit access?'))
->appendChild(
pht(
'This credential and its secret will no longer be able '.
'to be retrieved using the `%s` method in Conduit.',
'passphrase.query'))
->addSubmitButton(pht('Prevent Conduit Access'))
->addCancelButton($view_uri);
} else {
return $this->newDialog()
->setTitle(pht('Allow Conduit access?'))
->appendChild(
pht(
'This credential will be able to be retrieved via the Conduit '.
'API by users who have access to this credential. You should '.
'only enable this for credentials which need to be accessed '.
'programmatically (such as from build agents).'))
->addSubmitButton(pht('Allow Conduit Access'))
->addCancelButton($view_uri);
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/controller/PassphraseCredentialLockController.php | src/applications/passphrase/controller/PassphraseCredentialLockController.php | <?php
final class PassphraseCredentialLockController
extends PassphraseController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$credential = id(new PassphraseCredentialQuery())
->setViewer($viewer)
->withIDs(array($id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$credential) {
return new Aphront404Response();
}
$type = PassphraseCredentialType::getTypeByConstant(
$credential->getCredentialType());
if (!$type) {
throw new Exception(pht('Credential has invalid type "%s"!', $type));
}
$view_uri = '/K'.$credential->getID();
if ($credential->getIsLocked()) {
return $this->newDialog()
->setTitle(pht('Credential Already Locked'))
->appendChild(
pht('This credential is already locked.'))
->addCancelButton($view_uri, pht('Close'));
}
if ($request->isFormPost()) {
$xactions = array();
$xactions[] = id(new PassphraseCredentialTransaction())
->setTransactionType(
PassphraseCredentialConduitTransaction::TRANSACTIONTYPE)
->setNewValue(0);
$xactions[] = id(new PassphraseCredentialTransaction())
->setTransactionType(
PassphraseCredentialLockTransaction::TRANSACTIONTYPE)
->setNewValue(1);
$editor = id(new PassphraseCredentialTransactionEditor())
->setActor($viewer)
->setContinueOnMissingFields(true)
->setContinueOnNoEffect(true)
->setContentSourceFromRequest($request)
->applyTransactions($credential, $xactions);
return id(new AphrontRedirectResponse())->setURI($view_uri);
}
return $this->newDialog()
->setTitle(pht('Lock Credential'))
->appendChild(
pht(
'This credential will be locked and the secret will be hidden '.
'forever. If Conduit access is enabled, it will be revoked. '.
'Anything relying on this credential will still function. This '.
'operation can not be undone.'))
->addSubmitButton(pht('Lock Credential'))
->addCancelButton($view_uri);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/controller/PassphraseController.php | src/applications/passphrase/controller/PassphraseController.php | <?php
abstract class PassphraseController extends PhabricatorController {
public function buildSideNavView($for_app = false) {
$user = $this->getRequest()->getUser();
$nav = new AphrontSideNavFilterView();
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
if ($for_app) {
$nav->addFilter('create', pht('Create Credential'));
}
id(new PassphraseCredentialSearchEngine())
->setViewer($user)
->addNavigationItems($nav->getMenu());
$nav->selectFilter(null);
return $nav;
}
public function buildApplicationMenu() {
return $this->buildSideNavView(true)->getMenu();
}
protected function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
$crumbs->addAction(
id(new PHUIListItemView())
->setName(pht('Create Credential'))
->setHref($this->getApplicationURI('create/'))
->setIcon('fa-plus-square'));
return $crumbs;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/controller/PassphraseCredentialListController.php | src/applications/passphrase/controller/PassphraseCredentialListController.php | <?php
final class PassphraseCredentialListController extends PassphraseController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$querykey = $request->getURIData('queryKey');
$controller = id(new PhabricatorApplicationSearchController())
->setQueryKey($querykey)
->setSearchEngine(new PassphraseCredentialSearchEngine())
->setNavigation($this->buildSideNavView());
return $this->delegateToController($controller);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/controller/PassphraseCredentialEditController.php | src/applications/passphrase/controller/PassphraseCredentialEditController.php | <?php
final class PassphraseCredentialEditController extends PassphraseController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
if ($id) {
$credential = id(new PassphraseCredentialQuery())
->setViewer($viewer)
->withIDs(array($id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$credential) {
return new Aphront404Response();
}
$type = $this->getCredentialType($credential->getCredentialType());
$type_const = $type->getCredentialType();
$is_new = false;
} else {
$type_const = $request->getStr('type');
$type = $this->getCredentialType($type_const);
if (!$type->isCreateable()) {
throw new Exception(
pht(
'Credential has noncreateable type "%s"!',
$type_const));
}
$credential = PassphraseCredential::initializeNewCredential($viewer)
->setCredentialType($type->getCredentialType())
->setProvidesType($type->getProvidesType())
->attachImplementation($type);
$is_new = true;
// Prefill username if provided.
$credential->setUsername((string)$request->getStr('username'));
if (!$request->getStr('isInitialized')) {
$type->didInitializeNewCredential($viewer, $credential);
}
}
$errors = array();
$v_name = $credential->getName();
$e_name = true;
$v_desc = $credential->getDescription();
$v_space = $credential->getSpacePHID();
$v_username = $credential->getUsername();
$e_username = true;
$v_is_locked = false;
$bullet = "\xE2\x80\xA2";
$v_secret = $credential->getSecretID() ? str_repeat($bullet, 32) : null;
if ($is_new && ($v_secret === null)) {
// If we're creating a new credential, the credential type may have
// populated the secret for us (for example, generated an SSH key). In
// this case,
try {
$v_secret = $credential->getSecret()->openEnvelope();
} catch (Exception $ex) {
// Ignore this.
}
}
$validation_exception = null;
$errors = array();
$e_password = null;
$e_secret = null;
if ($request->isFormPost()) {
$v_name = $request->getStr('name');
$v_desc = $request->getStr('description');
$v_username = $request->getStr('username');
$v_view_policy = $request->getStr('viewPolicy');
$v_edit_policy = $request->getStr('editPolicy');
$v_is_locked = $request->getStr('lock');
$v_secret = $request->getStr('secret');
$v_space = $request->getStr('spacePHID');
$v_password = $request->getStr('password');
$v_decrypt = $v_secret;
$env_secret = new PhutilOpaqueEnvelope($v_secret);
$env_password = new PhutilOpaqueEnvelope($v_password);
$has_secret = !preg_match('/^('.$bullet.')+$/', trim($v_decrypt));
// Validate and repair SSH private keys, and apply passwords if they
// are provided. See T13454 for discussion.
// This should eventually be refactored to be modular rather than a
// hard-coded set of behaviors here in the Controller, but this is
// likely a fairly extensive change.
$is_ssh = ($type instanceof PassphraseSSHPrivateKeyTextCredentialType);
if ($is_ssh && $has_secret) {
$old_object = PhabricatorAuthSSHPrivateKey::newFromRawKey($env_secret);
if (strlen($v_password)) {
$old_object->setPassphrase($env_password);
}
try {
$new_object = $old_object->newBarePrivateKey();
$v_decrypt = $new_object->getKeyBody()->openEnvelope();
} catch (PhabricatorAuthSSHPrivateKeyException $ex) {
$errors[] = $ex->getMessage();
if ($ex->isFormatException()) {
$e_secret = pht('Invalid');
}
if ($ex->isPassphraseException()) {
$e_password = pht('Invalid');
}
}
}
if (!$errors) {
$type_name =
PassphraseCredentialNameTransaction::TRANSACTIONTYPE;
$type_desc =
PassphraseCredentialDescriptionTransaction::TRANSACTIONTYPE;
$type_username =
PassphraseCredentialUsernameTransaction::TRANSACTIONTYPE;
$type_destroy =
PassphraseCredentialDestroyTransaction::TRANSACTIONTYPE;
$type_secret_id =
PassphraseCredentialSecretIDTransaction::TRANSACTIONTYPE;
$type_is_locked =
PassphraseCredentialLockTransaction::TRANSACTIONTYPE;
$type_view_policy = PhabricatorTransactions::TYPE_VIEW_POLICY;
$type_edit_policy = PhabricatorTransactions::TYPE_EDIT_POLICY;
$type_space = PhabricatorTransactions::TYPE_SPACE;
$xactions = array();
$xactions[] = id(new PassphraseCredentialTransaction())
->setTransactionType($type_name)
->setNewValue($v_name);
$xactions[] = id(new PassphraseCredentialTransaction())
->setTransactionType($type_desc)
->setNewValue($v_desc);
$xactions[] = id(new PassphraseCredentialTransaction())
->setTransactionType($type_view_policy)
->setNewValue($v_view_policy);
$xactions[] = id(new PassphraseCredentialTransaction())
->setTransactionType($type_edit_policy)
->setNewValue($v_edit_policy);
$xactions[] = id(new PassphraseCredentialTransaction())
->setTransactionType($type_space)
->setNewValue($v_space);
// Open a transaction in case we're writing a new secret; this limits
// the amount of code which handles secret plaintexts.
$credential->openTransaction();
if (!$credential->getIsLocked()) {
if ($type->shouldRequireUsername()) {
$xactions[] = id(new PassphraseCredentialTransaction())
->setTransactionType($type_username)
->setNewValue($v_username);
}
// If some value other than a sequence of bullets was provided for
// the credential, update it. In particular, note that we are
// explicitly allowing empty secrets: one use case is HTTP auth where
// the username is a secret token which covers both identity and
// authentication.
if ($has_secret) {
// If the credential was previously destroyed, restore it when it is
// edited if a secret is provided.
$xactions[] = id(new PassphraseCredentialTransaction())
->setTransactionType($type_destroy)
->setNewValue(0);
$new_secret = id(new PassphraseSecret())
->setSecretData($v_decrypt)
->save();
$xactions[] = id(new PassphraseCredentialTransaction())
->setTransactionType($type_secret_id)
->setNewValue($new_secret->getID());
}
$xactions[] = id(new PassphraseCredentialTransaction())
->setTransactionType($type_is_locked)
->setNewValue($v_is_locked);
}
try {
$editor = id(new PassphraseCredentialTransactionEditor())
->setActor($viewer)
->setContinueOnNoEffect(true)
->setContentSourceFromRequest($request)
->applyTransactions($credential, $xactions);
$credential->saveTransaction();
if ($request->isAjax()) {
return id(new AphrontAjaxResponse())->setContent(
array(
'phid' => $credential->getPHID(),
'name' => 'K'.$credential->getID().' '.$credential->getName(),
));
} else {
return id(new AphrontRedirectResponse())
->setURI('/K'.$credential->getID());
}
} catch (PhabricatorApplicationTransactionValidationException $ex) {
$credential->killTransaction();
$validation_exception = $ex;
$e_name = $ex->getShortMessage($type_name);
$e_username = $ex->getShortMessage($type_username);
$credential->setViewPolicy($v_view_policy);
$credential->setEditPolicy($v_edit_policy);
}
}
}
$policies = id(new PhabricatorPolicyQuery())
->setViewer($viewer)
->setObject($credential)
->execute();
$secret_control = $type->newSecretControl();
$credential_is_locked = $credential->getIsLocked();
$form = id(new AphrontFormView())
->setUser($viewer)
->addHiddenInput('isInitialized', true)
->addHiddenInput('type', $type_const)
->appendChild(
id(new AphrontFormTextControl())
->setName('name')
->setLabel(pht('Name'))
->setValue($v_name)
->setError($e_name))
->appendChild(
id(new PhabricatorRemarkupControl())
->setUser($viewer)
->setName('description')
->setLabel(pht('Description'))
->setValue($v_desc))
->appendChild(
id(new AphrontFormDividerControl()))
->appendControl(
id(new AphrontFormPolicyControl())
->setName('viewPolicy')
->setPolicyObject($credential)
->setSpacePHID($v_space)
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
->setPolicies($policies))
->appendControl(
id(new AphrontFormPolicyControl())
->setName('editPolicy')
->setPolicyObject($credential)
->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
->setPolicies($policies))
->appendChild(
id(new AphrontFormDividerControl()));
if ($credential_is_locked) {
$form->appendRemarkupInstructions(
pht('This credential is permanently locked and can not be edited.'));
}
if ($type->shouldRequireUsername()) {
$form->appendChild(
id(new AphrontFormTextControl())
->setName('username')
->setLabel(pht('Login/Username'))
->setValue($v_username)
->setDisabled($credential_is_locked)
->setError($e_username));
}
$form->appendChild(
$secret_control
->setName('secret')
->setLabel($type->getSecretLabel())
->setDisabled($credential_is_locked)
->setValue($v_secret)
->setError($e_secret));
if ($type->shouldShowPasswordField()) {
$form->appendChild(
id(new AphrontFormPasswordControl())
->setDisableAutocomplete(true)
->setName('password')
->setLabel($type->getPasswordLabel())
->setDisabled($credential_is_locked)
->setError($e_password));
}
if ($is_new) {
$form->appendChild(
id(new AphrontFormCheckboxControl())
->addCheckbox(
'lock',
1,
array(
phutil_tag('strong', array(), pht('Lock Permanently:')),
' ',
pht('Prevent the secret from being revealed or changed.'),
),
$v_is_locked)
->setDisabled($credential_is_locked));
}
$crumbs = $this->buildApplicationCrumbs();
$crumbs->setBorder(true);
if ($is_new) {
$title = pht('New Credential: %s', $type->getCredentialTypeName());
$crumbs->addTextCrumb(pht('Create'));
$cancel_uri = $this->getApplicationURI();
} else {
$title = pht('Edit Credential: %s', $credential->getName());
$crumbs->addTextCrumb(
'K'.$credential->getID(),
'/K'.$credential->getID());
$crumbs->addTextCrumb(pht('Edit'));
$cancel_uri = '/K'.$credential->getID();
}
if ($request->isAjax()) {
if ($errors) {
$errors = id(new PHUIInfoView())->setErrors($errors);
}
return $this->newDialog()
->setWidth(AphrontDialogView::WIDTH_FORM)
->setTitle($title)
->appendChild($errors)
->appendChild($form->buildLayoutView())
->addSubmitButton(pht('Create Credential'))
->addCancelButton($cancel_uri);
}
$form->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Save'))
->addCancelButton($cancel_uri));
$box = id(new PHUIObjectBoxView())
->setHeaderText($title)
->setFormErrors($errors)
->setValidationException($validation_exception)
->setBackground(PHUIObjectBoxView::WHITE_CONFIG)
->setForm($form);
$view = id(new PHUITwoColumnView())
->setFooter(array(
$box,
));
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->appendChild($view);
}
private function getCredentialType($type_const) {
$type = PassphraseCredentialType::getTypeByConstant($type_const);
if (!$type) {
throw new Exception(
pht('Credential has invalid type "%s"!', $type_const));
}
return $type;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/controller/PassphraseCredentialViewController.php | src/applications/passphrase/controller/PassphraseCredentialViewController.php | <?php
final class PassphraseCredentialViewController extends PassphraseController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$credential = id(new PassphraseCredentialQuery())
->setViewer($viewer)
->withIDs(array($id))
->executeOne();
if (!$credential) {
return new Aphront404Response();
}
$type = $credential->getImplementation();
$timeline = $this->buildTransactionTimeline(
$credential,
new PassphraseCredentialTransactionQuery());
$timeline->setShouldTerminate(true);
$title = pht('%s %s', $credential->getMonogram(), $credential->getName());
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($credential->getMonogram());
$crumbs->setBorder(true);
$header = $this->buildHeaderView($credential);
$curtain = $this->buildCurtain($credential, $type);
$subheader = $this->buildSubheaderView($credential);
$content = $this->buildPropertySectionView($credential, $type);
$view = id(new PHUITwoColumnView())
->setHeader($header)
->setSubheader($subheader)
->setCurtain($curtain)
->setMainColumn($timeline)
->addPropertySection(pht('Properties'), $content);
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->appendChild($view);
}
private function buildHeaderView(PassphraseCredential $credential) {
$viewer = $this->getRequest()->getUser();
$header = id(new PHUIHeaderView())
->setUser($viewer)
->setHeader($credential->getName())
->setPolicyObject($credential)
->setHeaderIcon('fa-user-secret');
if ($credential->getIsDestroyed()) {
$header->setStatus('fa-ban', 'red', pht('Destroyed'));
}
return $header;
}
private function buildSubheaderView(
PassphraseCredential $credential) {
$viewer = $this->getViewer();
$author = $viewer->renderHandle($credential->getAuthorPHID())->render();
$date = phabricator_datetime($credential->getDateCreated(), $viewer);
$author = phutil_tag('strong', array(), $author);
$person = id(new PhabricatorPeopleQuery())
->setViewer($viewer)
->withPHIDs(array($credential->getAuthorPHID()))
->needProfileImage(true)
->executeOne();
if (!$person) {
return null;
}
$image_uri = $person->getProfileImageURI();
$image_href = '/p/'.$credential->getUsername();
$content = pht('Created by %s on %s.', $author, $date);
return id(new PHUIHeadThingView())
->setImage($image_uri)
->setImageHref($image_href)
->setContent($content);
}
private function buildCurtain(
PassphraseCredential $credential,
PassphraseCredentialType $type) {
$viewer = $this->getViewer();
$id = $credential->getID();
$is_locked = $credential->getIsLocked();
if ($is_locked) {
$credential_lock_text = pht('Locked Permanently');
$credential_lock_icon = 'fa-lock';
} else {
$credential_lock_text = pht('Lock Permanently');
$credential_lock_icon = 'fa-unlock';
}
$allow_conduit = $credential->getAllowConduit();
if ($allow_conduit) {
$credential_conduit_text = pht('Prevent Conduit Access');
$credential_conduit_icon = 'fa-ban';
} else {
$credential_conduit_text = pht('Allow Conduit Access');
$credential_conduit_icon = 'fa-wrench';
}
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$credential,
PhabricatorPolicyCapability::CAN_EDIT);
$can_conduit = ($can_edit && !$is_locked);
$curtain = $this->newCurtainView($credential);
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('Edit Credential'))
->setIcon('fa-pencil')
->setHref($this->getApplicationURI("edit/{$id}/"))
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
if (!$credential->getIsDestroyed()) {
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('Destroy Credential'))
->setIcon('fa-times')
->setHref($this->getApplicationURI("destroy/{$id}/"))
->setDisabled(!$can_edit)
->setWorkflow(true));
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('Show Secret'))
->setIcon('fa-eye')
->setHref($this->getApplicationURI("reveal/{$id}/"))
->setDisabled(!$can_edit || $is_locked)
->setWorkflow(true));
if ($type->hasPublicKey()) {
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('Show Public Key'))
->setIcon('fa-download')
->setHref($this->getApplicationURI("public/{$id}/"))
->setWorkflow(true));
}
$curtain->addAction(
id(new PhabricatorActionView())
->setName($credential_conduit_text)
->setIcon($credential_conduit_icon)
->setHref($this->getApplicationURI("conduit/{$id}/"))
->setDisabled(!$can_conduit)
->setWorkflow(true));
$curtain->addAction(
id(new PhabricatorActionView())
->setName($credential_lock_text)
->setIcon($credential_lock_icon)
->setHref($this->getApplicationURI("lock/{$id}/"))
->setDisabled(!$can_edit || $is_locked)
->setWorkflow(true));
}
return $curtain;
}
private function buildPropertySectionView(
PassphraseCredential $credential,
PassphraseCredentialType $type) {
$viewer = $this->getRequest()->getUser();
$properties = id(new PHUIPropertyListView())
->setUser($viewer);
$properties->addProperty(
pht('Credential Type'),
$type->getCredentialTypeName());
if ($type->shouldRequireUsername()) {
$properties->addProperty(
pht('Username'),
$credential->getUsername());
}
$description = $credential->getDescription();
if (strlen($description)) {
$properties->addSectionHeader(
pht('Description'),
PHUIPropertyListView::ICON_SUMMARY);
$properties->addTextContent(
new PHUIRemarkupView($viewer, $description));
}
return $properties;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/controller/PassphraseCredentialRevealController.php | src/applications/passphrase/controller/PassphraseCredentialRevealController.php | <?php
final class PassphraseCredentialRevealController
extends PassphraseController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$credential = id(new PassphraseCredentialQuery())
->setViewer($viewer)
->withIDs(array($id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->needSecrets(true)
->executeOne();
if (!$credential) {
return new Aphront404Response();
}
$view_uri = $credential->getURI();
$is_locked = $credential->getIsLocked();
if ($is_locked) {
return $this->newDialog()
->setUser($viewer)
->setTitle(pht('Credential is locked'))
->appendChild(
pht(
'This credential can not be shown, because it is locked.'))
->addCancelButton($view_uri);
}
if ($request->isFormOrHisecPost()) {
$secret = $credential->getSecret();
if (!$secret) {
$body = pht('This credential has no associated secret.');
} else if (!strlen($secret->openEnvelope())) {
$body = pht('This credential has an empty secret.');
} else {
$body = id(new PHUIFormLayoutView())
->appendChild(
id(new AphrontFormTextAreaControl())
->setLabel(pht('Plaintext'))
->setReadOnly(true)
->setCustomClass('PhabricatorMonospaced')
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
->setValue($secret->openEnvelope()));
}
// NOTE: Disable workflow on the cancel button to reload the page so
// the viewer can see that their view was logged.
$dialog = id(new AphrontDialogView())
->setUser($viewer)
->setWidth(AphrontDialogView::WIDTH_FORM)
->setTitle(pht('Credential Secret (%s)', $credential->getMonogram()))
->appendChild($body)
->setDisableWorkflowOnCancel(true)
->addCancelButton($view_uri, pht('Done'));
$type_secret = PassphraseCredentialLookedAtTransaction::TRANSACTIONTYPE;
$xactions = array(
id(new PassphraseCredentialTransaction())
->setTransactionType($type_secret)
->setNewValue(true),
);
$editor = id(new PassphraseCredentialTransactionEditor())
->setActor($viewer)
->setCancelURI($view_uri)
->setContinueOnNoEffect(true)
->setContentSourceFromRequest($request)
->applyTransactions($credential, $xactions);
return id(new AphrontDialogResponse())->setDialog($dialog);
}
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
if ($is_serious) {
$body = pht(
'The secret associated with this credential will be shown in plain '.
'text on your screen.');
} else {
$body = pht(
'The secret associated with this credential will be shown in plain '.
'text on your screen. Before continuing, wrap your arms around '.
'your monitor to create a human shield, keeping it safe from '.
'prying eyes. Protect company secrets!');
}
return $this->newDialog()
->setUser($viewer)
->setTitle(pht('Really show secret?'))
->appendChild($body)
->addSubmitButton(pht('Show Secret'))
->addCancelButton($view_uri);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/controller/PassphraseCredentialPublicController.php | src/applications/passphrase/controller/PassphraseCredentialPublicController.php | <?php
final class PassphraseCredentialPublicController
extends PassphraseController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$credential = id(new PassphraseCredentialQuery())
->setViewer($viewer)
->withIDs(array($id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
))
->executeOne();
if (!$credential) {
return new Aphront404Response();
}
$type = PassphraseCredentialType::getTypeByConstant(
$credential->getCredentialType());
if (!$type) {
throw new Exception(pht('Credential has invalid type "%s"!', $type));
}
if (!$type->hasPublicKey()) {
throw new Exception(pht('Credential has no public key!'));
}
$view_uri = '/'.$credential->getMonogram();
$public_key = $type->getPublicKey($viewer, $credential);
$body = id(new PHUIFormLayoutView())
->appendChild(
id(new AphrontFormTextAreaControl())
->setLabel(pht('Public Key'))
->setReadOnly(true)
->setValue($public_key));
return $this->newDialog()
->setWidth(AphrontDialogView::WIDTH_FORM)
->setTitle(pht('Public Key (%s)', $credential->getMonogram()))
->appendChild($body)
->addCancelButton($view_uri, pht('Done'));
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/storage/PassphraseCredentialTransaction.php | src/applications/passphrase/storage/PassphraseCredentialTransaction.php | <?php
final class PassphraseCredentialTransaction
extends PhabricatorModularTransaction {
public function getApplicationName() {
return 'passphrase';
}
public function getApplicationTransactionType() {
return PassphraseCredentialPHIDType::TYPECONST;
}
public function getBaseTransactionClass() {
return 'PassphraseCredentialTransactionType';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/storage/PassphraseDAO.php | src/applications/passphrase/storage/PassphraseDAO.php | <?php
abstract class PassphraseDAO extends PhabricatorLiskDAO {
public function getApplicationName() {
return 'passphrase';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/storage/PassphraseSchemaSpec.php | src/applications/passphrase/storage/PassphraseSchemaSpec.php | <?php
final class PassphraseSchemaSpec
extends PhabricatorConfigSchemaSpec {
public function buildSchemata() {
$this->buildEdgeSchemata(new PassphraseCredential());
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/storage/PassphraseSecret.php | src/applications/passphrase/storage/PassphraseSecret.php | <?php
final class PassphraseSecret extends PassphraseDAO {
protected $secretData;
protected function getConfiguration() {
return array(
self::CONFIG_TIMESTAMPS => false,
self::CONFIG_BINARY => array(
'secretData' => true,
),
) + parent::getConfiguration();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/storage/PassphraseCredential.php | src/applications/passphrase/storage/PassphraseCredential.php | <?php
final class PassphraseCredential extends PassphraseDAO
implements
PhabricatorApplicationTransactionInterface,
PhabricatorPolicyInterface,
PhabricatorFlaggableInterface,
PhabricatorSubscribableInterface,
PhabricatorDestructibleInterface,
PhabricatorSpacesInterface,
PhabricatorFulltextInterface,
PhabricatorFerretInterface {
protected $name;
protected $credentialType;
protected $providesType;
protected $viewPolicy;
protected $editPolicy;
protected $description;
protected $username;
protected $secretID;
protected $isDestroyed;
protected $isLocked = 0;
protected $allowConduit = 0;
protected $authorPHID;
protected $spacePHID;
private $secret = self::ATTACHABLE;
private $implementation = self::ATTACHABLE;
public static function initializeNewCredential(PhabricatorUser $actor) {
$app = id(new PhabricatorApplicationQuery())
->setViewer($actor)
->withClasses(array('PhabricatorPassphraseApplication'))
->executeOne();
$view_policy = $app->getPolicy(PassphraseDefaultViewCapability::CAPABILITY);
$edit_policy = $app->getPolicy(PassphraseDefaultEditCapability::CAPABILITY);
return id(new PassphraseCredential())
->setName('')
->setUsername('')
->setDescription('')
->setIsDestroyed(0)
->setAuthorPHID($actor->getPHID())
->setViewPolicy($view_policy)
->setEditPolicy($edit_policy)
->setSpacePHID($actor->getDefaultSpacePHID());
}
public function getMonogram() {
return 'K'.$this->getID();
}
public function getURI() {
return '/'.$this->getMonogram();
}
protected function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_COLUMN_SCHEMA => array(
'name' => 'text255',
'credentialType' => 'text64',
'providesType' => 'text64',
'description' => 'text',
'username' => 'text255',
'secretID' => 'id?',
'isDestroyed' => 'bool',
'isLocked' => 'bool',
'allowConduit' => 'bool',
),
self::CONFIG_KEY_SCHEMA => array(
'key_secret' => array(
'columns' => array('secretID'),
'unique' => true,
),
'key_type' => array(
'columns' => array('credentialType'),
),
'key_provides' => array(
'columns' => array('providesType'),
),
),
) + parent::getConfiguration();
}
public function generatePHID() {
return PhabricatorPHID::generateNewPHID(
PassphraseCredentialPHIDType::TYPECONST);
}
public function attachSecret(PhutilOpaqueEnvelope $secret = null) {
$this->secret = $secret;
return $this;
}
public function getSecret() {
return $this->assertAttached($this->secret);
}
public function getCredentialTypeImplementation() {
$type = $this->getCredentialType();
return PassphraseCredentialType::getTypeByConstant($type);
}
public function attachImplementation(PassphraseCredentialType $impl) {
$this->implementation = $impl;
return $this;
}
public function getImplementation() {
return $this->assertAttached($this->implementation);
}
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
public function getApplicationTransactionEditor() {
return new PassphraseCredentialTransactionEditor();
}
public function getApplicationTransactionTemplate() {
return new PassphraseCredentialTransaction();
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
);
}
public function getPolicy($capability) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
return $this->getViewPolicy();
case PhabricatorPolicyCapability::CAN_EDIT:
return $this->getEditPolicy();
}
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return false;
}
/* -( PhabricatorSubscribableInterface )----------------------------------- */
public function isAutomaticallySubscribed($phid) {
return false;
}
/* -( PhabricatorDestructibleInterface )----------------------------------- */
public function destroyObjectPermanently(
PhabricatorDestructionEngine $engine) {
$this->openTransaction();
$secrets = id(new PassphraseSecret())->loadAllWhere(
'id = %d',
$this->getSecretID());
foreach ($secrets as $secret) {
$secret->delete();
}
$this->delete();
$this->saveTransaction();
}
/* -( PhabricatorSpacesInterface )----------------------------------------- */
public function getSpacePHID() {
return $this->spacePHID;
}
/* -( PhabricatorFulltextInterface )--------------------------------------- */
public function newFulltextEngine() {
return new PassphraseCredentialFulltextEngine();
}
/* -( PhabricatorFerretInterface )----------------------------------------- */
public function newFerretEngine() {
return new PassphraseCredentialFerretEngine();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/query/PassphraseCredentialTransactionQuery.php | src/applications/passphrase/query/PassphraseCredentialTransactionQuery.php | <?php
final class PassphraseCredentialTransactionQuery
extends PhabricatorApplicationTransactionQuery {
public function getTemplateApplicationTransaction() {
return new PassphraseCredentialTransaction();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/query/PassphraseCredentialSearchEngine.php | src/applications/passphrase/query/PassphraseCredentialSearchEngine.php | <?php
final class PassphraseCredentialSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Passphrase Credentials');
}
public function getApplicationClassName() {
return 'PhabricatorPassphraseApplication';
}
public function newQuery() {
return new PassphraseCredentialQuery();
}
protected function buildCustomSearchFields() {
return array(
id(new PhabricatorSearchThreeStateField())
->setLabel(pht('Status'))
->setKey('isDestroyed')
->setOptions(
pht('Show All'),
pht('Show Only Destroyed Credentials'),
pht('Show Only Active Credentials')),
id(new PhabricatorSearchTextField())
->setLabel(pht('Name Contains'))
->setKey('name'),
);
}
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
if ($map['isDestroyed'] !== null) {
$query->withIsDestroyed($map['isDestroyed']);
}
if (strlen($map['name'])) {
$query->withNameContains($map['name']);
}
return $query;
}
protected function getURI($path) {
return '/passphrase/'.$path;
}
protected function getBuiltinQueryNames() {
return array(
'active' => pht('Active Credentials'),
'all' => pht('All Credentials'),
);
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'all':
return $query;
case 'active':
return $query->setParameter('isDestroyed', false);
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function renderResultList(
array $credentials,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($credentials, 'PassphraseCredential');
$viewer = $this->requireViewer();
$list = new PHUIObjectItemListView();
$list->setUser($viewer);
foreach ($credentials as $credential) {
$item = id(new PHUIObjectItemView())
->setObjectName('K'.$credential->getID())
->setHeader($credential->getName())
->setHref('/K'.$credential->getID())
->setObject($credential);
$item->addAttribute(
pht('Login: %s', $credential->getUsername()));
if ($credential->getIsDestroyed()) {
$item->addIcon('fa-ban', pht('Destroyed'));
$item->setDisabled(true);
}
$type = PassphraseCredentialType::getTypeByConstant(
$credential->getCredentialType());
if ($type) {
$item->addIcon('fa-wrench', $type->getCredentialTypeName());
}
$list->addItem($item);
}
$result = new PhabricatorApplicationSearchResultView();
$result->setObjectList($list);
$result->setNoDataString(pht('No credentials found.'));
return $result;
}
protected function getNewUserBody() {
$create_button = id(new PHUIButtonView())
->setTag('a')
->setText(pht('Create a Credential'))
->setHref('/passphrase/create/')
->setColor(PHUIButtonView::GREEN);
$icon = $this->getApplication()->getIcon();
$app_name = $this->getApplication()->getName();
$view = id(new PHUIBigInfoView())
->setIcon($icon)
->setTitle(pht('Welcome to %s', $app_name))
->setDescription(
pht('Credential management and general storage of shared secrets.'))
->addAction($create_button);
return $view;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/query/PassphraseCredentialQuery.php | src/applications/passphrase/query/PassphraseCredentialQuery.php | <?php
final class PassphraseCredentialQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $phids;
private $credentialTypes;
private $providesTypes;
private $isDestroyed;
private $allowConduit;
private $nameContains;
private $needSecrets;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function withCredentialTypes(array $credential_types) {
$this->credentialTypes = $credential_types;
return $this;
}
public function withProvidesTypes(array $provides_types) {
$this->providesTypes = $provides_types;
return $this;
}
public function withIsDestroyed($destroyed) {
$this->isDestroyed = $destroyed;
return $this;
}
public function withAllowConduit($allow_conduit) {
$this->allowConduit = $allow_conduit;
return $this;
}
public function withNameContains($name_contains) {
$this->nameContains = $name_contains;
return $this;
}
public function needSecrets($need_secrets) {
$this->needSecrets = $need_secrets;
return $this;
}
public function newResultObject() {
return new PassphraseCredential();
}
protected function willFilterPage(array $page) {
if ($this->needSecrets) {
$secret_ids = mpull($page, 'getSecretID');
$secret_ids = array_filter($secret_ids);
$secrets = array();
if ($secret_ids) {
$secret_objects = id(new PassphraseSecret())->loadAllWhere(
'id IN (%Ld)',
$secret_ids);
foreach ($secret_objects as $secret) {
$secret_data = $secret->getSecretData();
$secrets[$secret->getID()] = new PhutilOpaqueEnvelope($secret_data);
}
}
foreach ($page as $key => $credential) {
$secret_id = $credential->getSecretID();
if (!$secret_id) {
$credential->attachSecret(null);
} else if (isset($secrets[$secret_id])) {
$credential->attachSecret($secrets[$secret_id]);
} else {
unset($page[$key]);
}
}
}
foreach ($page as $key => $credential) {
$type = PassphraseCredentialType::getTypeByConstant(
$credential->getCredentialType());
if (!$type) {
unset($page[$key]);
continue;
}
$credential->attachImplementation(clone $type);
}
return $page;
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) {
$where[] = qsprintf(
$conn,
'c.id IN (%Ld)',
$this->ids);
}
if ($this->phids !== null) {
$where[] = qsprintf(
$conn,
'c.phid IN (%Ls)',
$this->phids);
}
if ($this->credentialTypes !== null) {
$where[] = qsprintf(
$conn,
'c.credentialType in (%Ls)',
$this->credentialTypes);
}
if ($this->providesTypes !== null) {
$where[] = qsprintf(
$conn,
'c.providesType IN (%Ls)',
$this->providesTypes);
}
if ($this->isDestroyed !== null) {
$where[] = qsprintf(
$conn,
'c.isDestroyed = %d',
(int)$this->isDestroyed);
}
if ($this->allowConduit !== null) {
$where[] = qsprintf(
$conn,
'c.allowConduit = %d',
(int)$this->allowConduit);
}
if (phutil_nonempty_string($this->nameContains)) {
$where[] = qsprintf(
$conn,
'LOWER(c.name) LIKE %~',
phutil_utf8_strtolower($this->nameContains));
}
return $where;
}
public function getQueryApplicationClass() {
return 'PhabricatorPassphraseApplication';
}
protected function getPrimaryTableAlias() {
return 'c';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/editor/PassphraseCredentialTransactionEditor.php | src/applications/passphrase/editor/PassphraseCredentialTransactionEditor.php | <?php
final class PassphraseCredentialTransactionEditor
extends PhabricatorApplicationTransactionEditor {
public function getEditorApplicationClass() {
return 'PhabricatorPassphraseApplication';
}
public function getEditorObjectsDescription() {
return pht('Passphrase Credentials');
}
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
return $types;
}
public function getCreateObjectTitle($author, $object) {
return pht('%s created this credential.', $author);
}
public function getCreateObjectTitleForFeed($author, $object) {
return pht('%s created %s.', $author, $object);
}
protected function supportsSearch() {
return true;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/xaction/PassphraseCredentialSecretIDTransaction.php | src/applications/passphrase/xaction/PassphraseCredentialSecretIDTransaction.php | <?php
final class PassphraseCredentialSecretIDTransaction
extends PassphraseCredentialTransactionType {
const TRANSACTIONTYPE = 'passphrase:secretID';
public function generateOldValue($object) {
return $object->getSecretID();
}
public function applyInternalEffects($object, $value) {
$old_id = $object->getSecretID();
if ($old_id) {
$this->destroySecret($old_id);
}
$object->setSecretID($value);
}
public function getTitle() {
$old = $this->getOldValue();
if (!$old) {
return pht(
'%s attached a new secret to this credential.',
$this->renderAuthor());
} else {
return pht(
'%s updated the secret for this credential.',
$this->renderAuthor());
}
}
public function getTitleForFeed() {
$old = $this->getOldValue();
if ($old === null) {
return pht(
'%s attached a new secret to %s.',
$this->renderAuthor(),
$this->renderObject());
} else {
return pht(
'%s updated the secret for %s.',
$this->renderAuthor(),
$this->renderObject());
}
}
public function getIcon() {
return 'fa-key';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/xaction/PassphraseCredentialDescriptionTransaction.php | src/applications/passphrase/xaction/PassphraseCredentialDescriptionTransaction.php | <?php
final class PassphraseCredentialDescriptionTransaction
extends PassphraseCredentialTransactionType {
const TRANSACTIONTYPE = 'passphrase:description';
public function generateOldValue($object) {
return $object->getDescription();
}
public function applyInternalEffects($object, $value) {
$object->setDescription($value);
}
public function shouldHide() {
$old = $this->getOldValue();
if (!strlen($old)) {
return true;
}
return false;
}
public function getTitle() {
return pht(
'%s updated the description for this credential.',
$this->renderAuthor());
}
public function getTitleForFeed() {
return pht(
'%s updated the description for credential %s.',
$this->renderAuthor(),
$this->renderObject());
}
public function hasChangeDetailView() {
return true;
}
public function getMailDiffSectionHeader() {
return pht('CHANGES TO CREDENTIAL DESCRIPTION');
}
public function newChangeDetailView() {
$viewer = $this->getViewer();
return id(new PhabricatorApplicationTransactionTextDiffDetailView())
->setViewer($viewer)
->setOldText($this->getOldValue())
->setNewText($this->getNewValue());
}
public function newRemarkupChanges() {
$changes = array();
$changes[] = $this->newRemarkupChange()
->setOldValue($this->getOldValue())
->setNewValue($this->getNewValue());
return $changes;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/xaction/PassphraseCredentialLookedAtTransaction.php | src/applications/passphrase/xaction/PassphraseCredentialLookedAtTransaction.php | <?php
final class PassphraseCredentialLookedAtTransaction
extends PassphraseCredentialTransactionType {
const TRANSACTIONTYPE = 'passphrase:lookedAtSecret';
public function generateOldValue($object) {
return null;
}
public function getTitle() {
return pht(
'%s examined the secret plaintext for this credential.',
$this->renderAuthor());
}
public function getTitleForFeed() {
return pht(
'%s examined the secret plaintext for credential %s.',
$this->renderAuthor(),
$this->renderObject());
}
public function getIcon() {
return 'fa-eye';
}
public function getColor() {
return 'blue';
}
public function shouldTryMFA(
$object,
PhabricatorApplicationTransaction $xaction) {
return true;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/xaction/PassphraseCredentialUsernameTransaction.php | src/applications/passphrase/xaction/PassphraseCredentialUsernameTransaction.php | <?php
final class PassphraseCredentialUsernameTransaction
extends PassphraseCredentialTransactionType {
const TRANSACTIONTYPE = 'passphrase:username';
public function generateOldValue($object) {
return $object->getUsername();
}
public function applyInternalEffects($object, $value) {
$object->setUsername($value);
}
public function getTitle() {
return pht(
'%s set the username for this credential to %s.',
$this->renderAuthor(),
$this->renderNewValue());
}
public function getTitleForFeed() {
return pht(
'%s set the username for credential %s to %s.',
$this->renderAuthor(),
$this->renderObject(),
$this->renderNewValue());
}
public function validateTransactions($object, array $xactions) {
$errors = array();
$credential_type = $object->getImplementation();
if ($credential_type->shouldRequireUsername()) {
if ($this->isEmptyTextTransaction($object->getUsername(), $xactions)) {
$errors[] = $this->newRequiredError(
pht('This credential must have a username.'));
}
}
$max_length = $object->getColumnMaximumByteLength('username');
foreach ($xactions as $xaction) {
$new_value = $xaction->getNewValue();
$new_length = strlen($new_value);
if ($new_length > $max_length) {
$errors[] = $this->newInvalidError(
pht('The username can be no longer than %s characters.',
new PhutilNumber($max_length)));
}
}
return $errors;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/xaction/PassphraseCredentialNameTransaction.php | src/applications/passphrase/xaction/PassphraseCredentialNameTransaction.php | <?php
final class PassphraseCredentialNameTransaction
extends PassphraseCredentialTransactionType {
const TRANSACTIONTYPE = 'passphrase:name';
public function generateOldValue($object) {
return $object->getName();
}
public function applyInternalEffects($object, $value) {
$object->setName($value);
}
public function getTitle() {
$old = $this->getOldValue();
if (!strlen($old)) {
return pht(
'%s created this credential.',
$this->renderAuthor());
} else {
return pht(
'%s renamed this credential from %s to %s.',
$this->renderAuthor(),
$this->renderOldValue(),
$this->renderNewValue());
}
}
public function getTitleForFeed() {
$old = $this->getOldValue();
if (!strlen($old)) {
return pht(
'%s created %s.',
$this->renderAuthor(),
$this->renderObject());
} else {
return pht(
'%s renamed %s credential %s to %s.',
$this->renderAuthor(),
$this->renderObject(),
$this->renderOldValue(),
$this->renderNewValue());
}
}
public function validateTransactions($object, array $xactions) {
$errors = array();
if ($this->isEmptyTextTransaction($object->getName(), $xactions)) {
$errors[] = $this->newRequiredError(
pht('Credentials must have a name.'));
}
$max_length = $object->getColumnMaximumByteLength('name');
foreach ($xactions as $xaction) {
$new_value = $xaction->getNewValue();
$new_length = strlen($new_value);
if ($new_length > $max_length) {
$errors[] = $this->newInvalidError(
pht('The name can be no longer than %s characters.',
new PhutilNumber($max_length)));
}
}
return $errors;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/xaction/PassphraseCredentialConduitTransaction.php | src/applications/passphrase/xaction/PassphraseCredentialConduitTransaction.php | <?php
final class PassphraseCredentialConduitTransaction
extends PassphraseCredentialTransactionType {
const TRANSACTIONTYPE = 'passphrase:conduit';
public function generateOldValue($object) {
return $object->getAllowConduit();
}
public function applyInternalEffects($object, $value) {
$object->setAllowConduit((int)$value);
}
public function getTitle() {
$new = $this->getNewValue();
if ($new) {
return pht(
'%s allowed Conduit API access to this credential.',
$this->renderAuthor());
} else {
return pht(
'%s disallowed Conduit API access to this credential.',
$this->renderAuthor());
}
}
public function getTitleForFeed() {
$new = $this->getNewValue();
if ($new) {
return pht(
'%s allowed Conduit API access to credential %s.',
$this->renderAuthor(),
$this->renderObject());
} else {
return pht(
'%s disallowed Conduit API access to credential %s.',
$this->renderAuthor(),
$this->renderObject());
}
}
public function getIcon() {
$new = $this->getNewValue();
if ($new) {
return 'fa-tty';
} else {
return 'fa-ban';
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/xaction/PassphraseCredentialTransactionType.php | src/applications/passphrase/xaction/PassphraseCredentialTransactionType.php | <?php
abstract class PassphraseCredentialTransactionType
extends PhabricatorModularTransactionType {
public function destroySecret($secret_id) {
$table = new PassphraseSecret();
queryfx(
$table->establishConnection('w'),
'DELETE FROM %T WHERE id = %d',
$table->getTableName(),
$secret_id);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/xaction/PassphraseCredentialDestroyTransaction.php | src/applications/passphrase/xaction/PassphraseCredentialDestroyTransaction.php | <?php
final class PassphraseCredentialDestroyTransaction
extends PassphraseCredentialTransactionType {
const TRANSACTIONTYPE = 'passphrase:destroy';
public function generateOldValue($object) {
return $object->getIsDestroyed();
}
public function applyInternalEffects($object, $value) {
$is_destroyed = $value;
$object->setIsDestroyed($is_destroyed);
if ($is_destroyed) {
$secret_id = $object->getSecretID();
if ($secret_id) {
$this->destroySecret($secret_id);
$object->setSecretID(null);
}
}
}
public function shouldHide() {
$new = $this->getNewValue();
if (!$new) {
return true;
}
}
public function getTitle() {
return pht(
'%s destroyed the secret for this credential.',
$this->renderAuthor());
}
public function getTitleForFeed() {
return pht(
'%s destroyed the secret for credential %s.',
$this->renderAuthor(),
$this->renderObject());
}
public function getIcon() {
return 'fa-ban';
}
public function getColor() {
return 'red';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/xaction/PassphraseCredentialLockTransaction.php | src/applications/passphrase/xaction/PassphraseCredentialLockTransaction.php | <?php
final class PassphraseCredentialLockTransaction
extends PassphraseCredentialTransactionType {
const TRANSACTIONTYPE = 'passphrase:lock';
public function generateOldValue($object) {
return $object->getIsLocked();
}
public function applyInternalEffects($object, $value) {
$object->setIsLocked((int)$value);
}
public function shouldHide() {
$new = $this->getNewValue();
if ($new === null) {
return true;
}
return false;
}
public function getTitle() {
return pht(
'%s locked this credential.',
$this->renderAuthor());
}
public function getTitleForFeed() {
return pht(
'%s locked credential %s.',
$this->renderAuthor(),
$this->renderObject());
}
public function getIcon() {
return 'fa-lock';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/application/PhabricatorPassphraseApplication.php | src/applications/passphrase/application/PhabricatorPassphraseApplication.php | <?php
final class PhabricatorPassphraseApplication extends PhabricatorApplication {
public function getName() {
return pht('Passphrase');
}
public function getBaseURI() {
return '/passphrase/';
}
public function getShortDescription() {
return pht('Credential Store');
}
public function getIcon() {
return 'fa-user-secret';
}
public function getTitleGlyph() {
return "\xE2\x97\x88";
}
public function getFlavorText() {
return pht('Put your secrets in a lockbox.');
}
public function getApplicationGroup() {
return self::GROUP_UTILITIES;
}
public function canUninstall() {
return false;
}
public function getRoutes() {
return array(
'/K(?P<id>\d+)' => 'PassphraseCredentialViewController',
'/passphrase/' => array(
'(?:query/(?P<queryKey>[^/]+)/)?'
=> 'PassphraseCredentialListController',
'create/' => 'PassphraseCredentialCreateController',
'edit/(?:(?P<id>\d+)/)?' => 'PassphraseCredentialEditController',
'destroy/(?P<id>\d+)/' => 'PassphraseCredentialDestroyController',
'reveal/(?P<id>\d+)/' => 'PassphraseCredentialRevealController',
'public/(?P<id>\d+)/' => 'PassphraseCredentialPublicController',
'lock/(?P<id>\d+)/' => 'PassphraseCredentialLockController',
'conduit/(?P<id>\d+)/' => 'PassphraseCredentialConduitController',
),
);
}
public function getRemarkupRules() {
return array(
new PassphraseRemarkupRule(),
);
}
public function getApplicationSearchDocumentTypes() {
return array(
PassphraseCredentialPHIDType::TYPECONST,
);
}
protected function getCustomCapabilities() {
$policy_key = id(new PassphraseCredentialAuthorPolicyRule())
->getObjectPolicyFullKey();
return array(
PassphraseDefaultViewCapability::CAPABILITY => array(
'caption' => pht('Default view policy for newly created credentials.'),
'template' => PassphraseCredentialPHIDType::TYPECONST,
'capability' => PhabricatorPolicyCapability::CAN_VIEW,
'default' => $policy_key,
),
PassphraseDefaultEditCapability::CAPABILITY => array(
'caption' => pht('Default edit policy for newly created credentials.'),
'template' => PassphraseCredentialPHIDType::TYPECONST,
'capability' => PhabricatorPolicyCapability::CAN_EDIT,
'default' => $policy_key,
),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/credentialtype/PassphraseSSHPrivateKeyTextCredentialType.php | src/applications/passphrase/credentialtype/PassphraseSSHPrivateKeyTextCredentialType.php | <?php
final class PassphraseSSHPrivateKeyTextCredentialType
extends PassphraseSSHPrivateKeyCredentialType {
const CREDENTIAL_TYPE = 'ssh-key-text';
public function getCredentialType() {
return self::CREDENTIAL_TYPE;
}
public function getCredentialTypeName() {
return pht('SSH Private Key');
}
public function getCredentialTypeDescription() {
return pht('Store the plaintext of an SSH private key.');
}
public function getSecretLabel() {
return pht('Private Key');
}
public function shouldShowPasswordField() {
return true;
}
public function getPasswordLabel() {
return pht('Password for Key');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/credentialtype/PassphraseSSHPrivateKeyCredentialType.php | src/applications/passphrase/credentialtype/PassphraseSSHPrivateKeyCredentialType.php | <?php
abstract class PassphraseSSHPrivateKeyCredentialType
extends PassphraseCredentialType {
const PROVIDES_TYPE = 'provides/ssh-key-file';
final public function getProvidesType() {
return self::PROVIDES_TYPE;
}
public function hasPublicKey() {
return true;
}
public function getPublicKey(
PhabricatorUser $viewer,
PassphraseCredential $credential) {
$key = PassphraseSSHKey::loadFromPHID($credential->getPHID(), $viewer);
$file = $key->getKeyfileEnvelope();
list($stdout) = execx('ssh-keygen -y -f %P', $file);
return $stdout;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/credentialtype/PassphraseSSHGeneratedKeyCredentialType.php | src/applications/passphrase/credentialtype/PassphraseSSHGeneratedKeyCredentialType.php | <?php
final class PassphraseSSHGeneratedKeyCredentialType
extends PassphraseSSHPrivateKeyCredentialType {
const CREDENTIAL_TYPE = 'ssh-generated-key';
public function getCredentialType() {
return self::CREDENTIAL_TYPE;
}
public function getCredentialTypeName() {
return pht('SSH Private Key (Generated)');
}
public function getCredentialTypeDescription() {
return pht('Generate an SSH keypair.');
}
public function getSecretLabel() {
return pht('Generated Key');
}
public function didInitializeNewCredential(
PhabricatorUser $actor,
PassphraseCredential $credential) {
$pair = PhabricatorSSHKeyGenerator::generateKeypair();
list($public_key, $private_key) = $pair;
$credential->attachSecret(new PhutilOpaqueEnvelope($private_key));
return $credential;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/credentialtype/PassphraseCredentialType.php | src/applications/passphrase/credentialtype/PassphraseCredentialType.php | <?php
/**
* @task password Managing Encryption Passwords
*/
abstract class PassphraseCredentialType extends Phobject {
abstract public function getCredentialType();
abstract public function getProvidesType();
abstract public function getCredentialTypeName();
abstract public function getCredentialTypeDescription();
abstract public function getSecretLabel();
public function newSecretControl() {
return new AphrontFormTextAreaControl();
}
public static function getAllTypes() {
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setUniqueMethod('getCredentialType')
->execute();
}
public static function getAllCreateableTypes() {
$types = self::getAllTypes();
foreach ($types as $key => $type) {
if (!$type->isCreateable()) {
unset($types[$key]);
}
}
return $types;
}
public static function getAllProvidesTypes() {
$types = array();
foreach (self::getAllTypes() as $type) {
$types[] = $type->getProvidesType();
}
return array_unique($types);
}
public static function getTypeByConstant($constant) {
$all = self::getAllTypes();
$all = mpull($all, null, 'getCredentialType');
return idx($all, $constant);
}
/**
* Can users create new credentials of this type?
*
* @return bool True if new credentials of this type can be created.
*/
public function isCreateable() {
return true;
}
public function didInitializeNewCredential(
PhabricatorUser $actor,
PassphraseCredential $credential) {
return $credential;
}
public function hasPublicKey() {
return false;
}
public function getPublicKey(
PhabricatorUser $viewer,
PassphraseCredential $credential) {
return null;
}
/* -( Passwords )---------------------------------------------------------- */
/**
* Return true to show an additional "Password" field. This is used by
* SSH credentials to strip passwords off private keys.
*
* @return bool True if a password field should be shown to the user.
*
* @task password
*/
public function shouldShowPasswordField() {
return false;
}
/**
* Return the label for the password field, if one is shown.
*
* @return string Human-readable field label.
*
* @task password
*/
public function getPasswordLabel() {
return pht('Password');
}
public function shouldRequireUsername() {
return true;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/credentialtype/PassphraseTokenCredentialType.php | src/applications/passphrase/credentialtype/PassphraseTokenCredentialType.php | <?php
final class PassphraseTokenCredentialType
extends PassphraseCredentialType {
const CREDENTIAL_TYPE = 'token';
const PROVIDES_TYPE = 'provides/token';
public function getCredentialType() {
return self::CREDENTIAL_TYPE;
}
public function getProvidesType() {
return self::PROVIDES_TYPE;
}
public function getCredentialTypeName() {
return pht('Token');
}
public function getCredentialTypeDescription() {
return pht('Store an API token.');
}
public function getSecretLabel() {
return pht('Token');
}
public function newSecretControl() {
return id(new AphrontFormTextControl());
}
public function shouldRequireUsername() {
return false;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/credentialtype/PassphrasePasswordCredentialType.php | src/applications/passphrase/credentialtype/PassphrasePasswordCredentialType.php | <?php
final class PassphrasePasswordCredentialType
extends PassphraseCredentialType {
const CREDENTIAL_TYPE = 'password';
const PROVIDES_TYPE = 'provides/password';
public function getCredentialType() {
return self::CREDENTIAL_TYPE;
}
public function getProvidesType() {
return self::PROVIDES_TYPE;
}
public function getCredentialTypeName() {
return pht('Password');
}
public function getCredentialTypeDescription() {
return pht('Store a plaintext password.');
}
public function getSecretLabel() {
return pht('Password');
}
public function newSecretControl() {
return id(new AphrontFormPasswordControl())
->setDisableAutocomplete(true);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/credentialtype/PassphraseSSHPrivateKeyFileCredentialType.php | src/applications/passphrase/credentialtype/PassphraseSSHPrivateKeyFileCredentialType.php | <?php
final class PassphraseSSHPrivateKeyFileCredentialType
extends PassphraseSSHPrivateKeyCredentialType {
const CREDENTIAL_TYPE = 'ssh-key-file';
public function getCredentialType() {
return self::CREDENTIAL_TYPE;
}
public function getCredentialTypeName() {
return pht('SSH Private Key File');
}
public function getCredentialTypeDescription() {
return pht('Store the path on disk to an SSH private key.');
}
public function getSecretLabel() {
return pht('Path On Disk');
}
public function newSecretControl() {
return new AphrontFormTextControl();
}
public function isCreateable() {
// This credential type exists to support historic repository configuration.
// We don't support creating new credentials with this type, since it does
// not scale and managing passwords is much more difficult than if we have
// the key text.
return false;
}
public function hasPublicKey() {
// These have public keys, but they'd be cumbersome to extract.
return true;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/credentialtype/PassphraseNoteCredentialType.php | src/applications/passphrase/credentialtype/PassphraseNoteCredentialType.php | <?php
final class PassphraseNoteCredentialType
extends PassphraseCredentialType {
const CREDENTIAL_TYPE = 'note';
const PROVIDES_TYPE = 'provides/note';
public function getCredentialType() {
return self::CREDENTIAL_TYPE;
}
public function getProvidesType() {
return self::PROVIDES_TYPE;
}
public function getCredentialTypeName() {
return pht('Note');
}
public function getCredentialTypeDescription() {
return pht('Store a plaintext note.');
}
public function getSecretLabel() {
return pht('Note');
}
public function newSecretControl() {
return id(new AphrontFormTextAreaControl());
}
public function shouldRequireUsername() {
return false;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.