Page MenuHomePhorge

No OneTemporary

diff --git a/src/applications/macro/conduit/ConduitAPI_macro_query_Method.php b/src/applications/macro/conduit/ConduitAPI_macro_query_Method.php
index 5a35420dc6..f6477836cd 100644
--- a/src/applications/macro/conduit/ConduitAPI_macro_query_Method.php
+++ b/src/applications/macro/conduit/ConduitAPI_macro_query_Method.php
@@ -1,51 +1,41 @@
<?php
/**
* @group conduit
*/
final class ConduitAPI_macro_query_Method extends ConduitAPI_macro_Method {
public function getMethodDescription() {
return "Retrieve image macro information.";
}
public function defineParamTypes() {
return array(
);
}
public function defineReturnType() {
return 'list<dict>';
}
public function defineErrorTypes() {
return array(
);
}
protected function execute(ConduitAPIRequest $request) {
-
- $macros = id(new PhabricatorFileImageMacro())->loadAll();
-
- $files = array();
- if ($macros) {
- $files = id(new PhabricatorFile())->loadAllWhere(
- 'phid IN (%Ls)',
- mpull($macros, 'getFilePHID'));
- $files = mpull($files, null, 'getPHID');
- }
+ $macros = id(new PhabricatorMacroQuery())
+ ->setViewer($request->getUser())
+ ->execute();
$results = array();
foreach ($macros as $macro) {
- if (empty($files[$macro->getFilePHID()])) {
- continue;
- }
$results[$macro->getName()] = array(
- 'uri' => $files[$macro->getFilePHID()]->getBestURI(),
+ 'uri' => $macro->getFile()->getBestURI(),
);
}
return $results;
}
}
diff --git a/src/applications/macro/controller/PhabricatorMacroCommentController.php b/src/applications/macro/controller/PhabricatorMacroCommentController.php
index 81844dc529..bccc40c65c 100644
--- a/src/applications/macro/controller/PhabricatorMacroCommentController.php
+++ b/src/applications/macro/controller/PhabricatorMacroCommentController.php
@@ -1,72 +1,75 @@
<?php
final class PhabricatorMacroCommentController
extends PhabricatorMacroController {
private $id;
public function willProcessRequest(array $data) {
$this->id = idx($data, 'id');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
if (!$request->isFormPost()) {
return new Aphront400Response();
}
- $macro = id(new PhabricatorFileImageMacro())->load($this->id);
+ $macro = id(new PhabricatorMacroQuery())
+ ->setViewer($user)
+ ->withIDs(array($this->id))
+ ->executeOne();
if (!$macro) {
return new Aphront404Response();
}
$is_preview = $request->isPreviewRequest();
$draft = PhabricatorDraft::buildFromRequest($request);
$view_uri = $this->getApplicationURI('/view/'.$macro->getID().'/');
$xactions = array();
$xactions[] = id(new PhabricatorMacroTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
->attachComment(
id(new PhabricatorMacroTransactionComment())
->setContent($request->getStr('comment')));
$editor = id(new PhabricatorMacroEditor())
->setActor($user)
->setContinueOnNoEffect($request->isContinueRequest())
->setContentSource(
PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_WEB,
array(
'ip' => $request->getRemoteAddr(),
)))
->setIsPreview($is_preview);
try {
$xactions = $editor->applyTransactions($macro, $xactions);
} catch (PhabricatorApplicationTransactionNoEffectException $ex) {
return id(new PhabricatorApplicationTransactionNoEffectResponse())
->setCancelURI($view_uri)
->setException($ex);
}
if ($draft) {
$draft->replaceOrDelete();
}
if ($request->isAjax()) {
return id(new PhabricatorApplicationTransactionResponse())
->setViewer($user)
->setTransactions($xactions)
->setIsPreview($is_preview)
->setAnchorOffset($request->getStr('anchor'));
} else {
return id(new AphrontRedirectResponse())
->setURI($view_uri);
}
}
}
diff --git a/src/applications/macro/controller/PhabricatorMacroDisableController.php b/src/applications/macro/controller/PhabricatorMacroDisableController.php
index 2dbe854d0c..a0f386afe8 100644
--- a/src/applications/macro/controller/PhabricatorMacroDisableController.php
+++ b/src/applications/macro/controller/PhabricatorMacroDisableController.php
@@ -1,56 +1,64 @@
<?php
final class PhabricatorMacroDisableController
extends PhabricatorMacroController {
private $id;
public function willProcessRequest(array $data) {
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
- $macro = id(new PhabricatorFileImageMacro())->load($this->id);
+ $macro = id(new PhabricatorMacroQuery())
+ ->setViewer($user)
+ ->requireCapabilities(
+ array(
+ PhabricatorPolicyCapability::CAN_VIEW,
+ PhabricatorPolicyCapability::CAN_EDIT,
+ ))
+ ->withIDs(array($this->id))
+ ->executeOne();
if (!$macro) {
return new Aphront404Response();
}
$view_uri = $this->getApplicationURI('/view/'.$this->id.'/');
if ($request->isDialogFormPost() || $macro->getIsDisabled()) {
$xaction = id(new PhabricatorMacroTransaction())
->setTransactionType(PhabricatorMacroTransactionType::TYPE_DISABLED)
->setNewValue($macro->getIsDisabled() ? 0 : 1);
$editor = id(new PhabricatorMacroEditor())
->setActor($user)
->setContentSource(
PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_WEB,
array(
'ip' => $request->getRemoteAddr(),
)));
$xactions = $editor->applyTransactions($macro, array($xaction));
return id(new AphrontRedirectResponse())->setURI($view_uri);
}
$dialog = new AphrontDialogView();
$dialog
->setUser($request->getUser())
->setTitle(pht('Really disable macro?'))
->appendChild(phutil_tag('p', array(), pht(
'Really disable the much-beloved image macro %s? '.
'It will be sorely missed.',
$macro->getName())))
->setSubmitURI($this->getApplicationURI('/disable/'.$this->id.'/'))
->addSubmitButton(pht('Disable'))
->addCancelButton($view_uri);
return id(new AphrontDialogResponse())->setDialog($dialog);
}
}
diff --git a/src/applications/macro/controller/PhabricatorMacroEditController.php b/src/applications/macro/controller/PhabricatorMacroEditController.php
index 19779331bd..e225f43664 100644
--- a/src/applications/macro/controller/PhabricatorMacroEditController.php
+++ b/src/applications/macro/controller/PhabricatorMacroEditController.php
@@ -1,280 +1,287 @@
<?php
final class PhabricatorMacroEditController
extends PhabricatorMacroController {
private $id;
public function willProcessRequest(array $data) {
$this->id = idx($data, 'id');
}
public function processRequest() {
+ $request = $this->getRequest();
+ $user = $request->getUser();
+
if ($this->id) {
- $macro = id(new PhabricatorFileImageMacro())->load($this->id);
+ $macro = id(new PhabricatorMacroQuery())
+ ->setViewer($user)
+ ->requireCapabilities(
+ array(
+ PhabricatorPolicyCapability::CAN_VIEW,
+ PhabricatorPolicyCapability::CAN_EDIT,
+ ))
+ ->withIDs(array($this->id))
+ ->executeOne();
if (!$macro) {
return new Aphront404Response();
}
} else {
$macro = new PhabricatorFileImageMacro();
}
$errors = array();
$e_name = true;
$e_file = true;
$file = null;
$can_fetch = PhabricatorEnv::getEnvConfig('security.allow-outbound-http');
- $request = $this->getRequest();
- $user = $request->getUser();
if ($request->isFormPost()) {
$original = clone $macro;
$new_name = null;
if ($request->getBool('name_form') || !$macro->getID()) {
$new_name = $request->getStr('name');
$macro->setName($new_name);
if (!strlen($macro->getName())) {
$errors[] = pht('Macro name is required.');
$e_name = pht('Required');
} else if (!preg_match('/^[a-z0-9:_-]{3,}$/', $macro->getName())) {
$errors[] = pht(
'Macro must be at least three characters long and contain only '.
'lowercase letters, digits, hyphens, colons and underscores.');
$e_name = pht('Invalid');
} else {
$e_name = null;
}
}
$file = null;
if ($request->getFileExists('file')) {
$file = PhabricatorFile::newFromPHPUpload(
$_FILES['file'],
array(
'name' => $request->getStr('name'),
'authorPHID' => $user->getPHID(),
));
} else if ($request->getStr('url')) {
try {
$file = PhabricatorFile::newFromFileDownload(
$request->getStr('url'),
array(
'name' => $request->getStr('name'),
'authorPHID' => $user->getPHID(),
));
} catch (Exception $ex) {
$errors[] = pht('Could not fetch URL: %s', $ex->getMessage());
}
} else if ($request->getStr('phid')) {
$file = id(new PhabricatorFile())->loadOneWhere(
'phid = %s',
$request->getStr('phid'));
}
if ($file) {
if (!$file->isViewableInBrowser()) {
$errors[] = pht('You must upload an image.');
$e_file = pht('Invalid');
} else {
$macro->setFilePHID($file->getPHID());
+ $macro->attachFile($file);
$e_file = null;
}
}
if (!$macro->getID() && !$file) {
$errors[] = pht('You must upload an image to create a macro.');
$e_file = pht('Required');
}
if (!$errors) {
try {
$xactions = array();
if ($new_name !== null) {
$xactions[] = id(new PhabricatorMacroTransaction())
->setTransactionType(PhabricatorMacroTransactionType::TYPE_NAME)
->setNewValue($new_name);
}
if ($file) {
$xactions[] = id(new PhabricatorMacroTransaction())
->setTransactionType(PhabricatorMacroTransactionType::TYPE_FILE)
->setNewValue($file->getPHID());
}
$editor = id(new PhabricatorMacroEditor())
->setActor($user)
->setContinueOnNoEffect(true)
->setContentSource(
PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_WEB,
array(
'ip' => $request->getRemoteAddr(),
)));
$xactions = $editor->applyTransactions($original, $xactions);
$view_uri = $this->getApplicationURI('/view/'.$original->getID().'/');
return id(new AphrontRedirectResponse())->setURI($view_uri);
} catch (AphrontQueryDuplicateKeyException $ex) {
throw $ex;
$errors[] = pht('Macro name is not unique!');
$e_name = pht('Duplicate');
}
}
}
if ($errors) {
$error_view = new AphrontErrorView();
$error_view->setTitle(pht('Form Errors'));
$error_view->setErrors($errors);
} else {
$error_view = null;
}
-
$current_file = null;
if ($macro->getFilePHID()) {
- $current_file = id(new PhabricatorFile())->loadOneWhere(
- 'phid = %s',
- $macro->getFilePHID());
+ $current_file = $macro->getFile();
}
$form = new AphrontFormView();
$form->setFlexible(true);
$form->addHiddenInput('name_form', 1);
$form->setUser($request->getUser());
$form
->setEncType('multipart/form-data')
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Name'))
->setName('name')
->setValue($macro->getName())
->setCaption(
pht('This word or phrase will be replaced with the image.'))
->setError($e_name));
if (!$macro->getID()) {
if ($current_file) {
$current_file_view = id(new PhabricatorFileLinkView())
->setFilePHID($current_file->getPHID())
->setFileName($current_file->getName())
->setFileViewable(true)
->setFileViewURI($current_file->getBestURI())
->render();
$form->addHiddenInput('phid', $current_file->getPHID());
$form->appendChild(
id(new AphrontFormMarkupControl())
->setLabel(pht('Selected File'))
->setValue($current_file_view));
$other_label = pht('Change File');
} else {
$other_label = pht('File');
}
if ($can_fetch) {
$form->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('URL'))
->setName('url')
->setValue($request->getStr('url'))
->setError($e_file));
}
$form->appendChild(
id(new AphrontFormFileControl())
->setLabel($other_label)
->setName('file')
->setError($e_file));
}
$view_uri = $this->getApplicationURI('/view/'.$macro->getID().'/');
if ($macro->getID()) {
$cancel_uri = $view_uri;
} else {
$cancel_uri = $this->getApplicationURI();
}
$form
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Save Image Macro'))
->addCancelButton($cancel_uri));
$crumbs = $this->buildApplicationCrumbs();
if ($macro->getID()) {
$title = pht('Edit Image Macro');
$crumb = pht('Edit');
$crumbs->addCrumb(
id(new PhabricatorCrumbView())
->setHref($view_uri)
->setName(pht('Macro "%s"', $macro->getName())));
} else {
$title = pht('Create Image Macro');
$crumb = pht('Create');
}
$crumbs->addCrumb(
id(new PhabricatorCrumbView())
->setHref($request->getRequestURI())
->setName($crumb));
$header = id(new PhabricatorHeaderView())
->setHeader($title);
$upload = null;
if ($macro->getID()) {
$upload_header = id(new PhabricatorHeaderView())
->setHeader(pht('Upload New File'));
$upload_form = id(new AphrontFormView())
->setFlexible(true)
->setEncType('multipart/form-data')
->setUser($request->getUser());
if ($can_fetch) {
$upload_form
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('URL'))
->setName('url')
->setValue($request->getStr('url')));
}
$upload_form
->appendChild(
id(new AphrontFormFileControl())
->setLabel(pht('File'))
->setName('file'))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Upload File')));
$upload = array($upload_header, $upload_form);
}
return $this->buildApplicationPage(
array(
$crumbs,
$header,
$error_view,
$form,
$upload,
),
array(
'title' => $title,
));
}
}
diff --git a/src/applications/macro/controller/PhabricatorMacroListController.php b/src/applications/macro/controller/PhabricatorMacroListController.php
index ef3dd75d33..c127c929d9 100644
--- a/src/applications/macro/controller/PhabricatorMacroListController.php
+++ b/src/applications/macro/controller/PhabricatorMacroListController.php
@@ -1,162 +1,158 @@
<?php
final class PhabricatorMacroListController
extends PhabricatorMacroController {
private $filter;
public function willProcessRequest(array $data) {
$this->filter = idx($data, 'filter', 'active');
}
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
- $macro_table = new PhabricatorFileImageMacro();
- $file_table = new PhabricatorFile();
- $conn = $macro_table->establishConnection('r');
-
$pager = id(new AphrontCursorPagerView())
->readFromRequest($request);
$query = new PhabricatorMacroQuery();
$query->setViewer($viewer);
$filter = $request->getStr('name');
if (strlen($filter)) {
$query->withNameLike($filter);
}
$authors = $request->getArr('authors');
if ($authors) {
$query->withAuthorPHIDs($authors);
}
$has_search = $filter || $authors;
if ($this->filter == 'my') {
$query->withAuthorPHIDs(array($viewer->getPHID()));
// For pre-filling the tokenizer
$authors = array($viewer->getPHID());
}
if ($this->filter == 'active') {
$query->withStatus(PhabricatorMacroQuery::STATUS_ACTIVE);
}
$macros = $query->executeWithCursorPager($pager);
if ($has_search) {
$nodata = pht('There are no macros matching the filter.');
} else {
$nodata = pht('There are no image macros yet.');
}
if ($authors) {
$author_phids = array_fuse($authors);
} else {
$author_phids = array();
}
$files = mpull($macros, 'getFile');
if ($files) {
$author_phids += mpull($files, 'getAuthorPHID', 'getAuthorPHID');
}
$this->loadHandles($author_phids);
$author_handles = array_select_keys($this->getLoadedHandles(), $authors);
$filter_form = id(new AphrontFormView())
->setMethod('GET')
->setUser($request->getUser())
->appendChild(
id(new AphrontFormTextControl())
->setName('name')
->setLabel(pht('Name'))
->setValue($filter))
->appendChild(
id(new AphrontFormTokenizerControl())
->setName('authors')
->setLabel(pht('Authors'))
->setDatasource('/typeahead/common/users/')
->setValue(mpull($author_handles, 'getFullName')))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Filter Image Macros')));
$filter_view = new AphrontListFilterView();
$filter_view->appendChild($filter_form);
$nav = $this->buildSideNavView(
$for_app = false,
$has_search);
$nav->selectFilter($has_search ? 'search' : $this->filter);
$nav->appendChild($filter_view);
$pinboard = new PhabricatorPinboardView();
$pinboard->setNoDataString($nodata);
foreach ($macros as $macro) {
$file = $macro->getFile();
$item = new PhabricatorPinboardItemView();
if ($file) {
$item->setImageURI($file->getThumb280x210URI());
$item->setImageSize(280, 210);
if ($file->getAuthorPHID()) {
$author_handle = $this->getHandle($file->getAuthorPHID());
$item->appendChild(
pht('Created by %s', $author_handle->renderLink()));
}
$datetime = phabricator_date($file->getDateCreated(), $viewer);
$item->appendChild(
phutil_tag(
'div',
array(),
pht('Created on %s', $datetime)));
}
$item->setURI($this->getApplicationURI('/view/'.$macro->getID().'/'));
$item->setHeader($macro->getName());
$pinboard->addItem($item);
}
$nav->appendChild($pinboard);
if (!$has_search) {
$nav->appendChild($pager);
switch ($this->filter) {
case 'all':
$name = pht('All Macros');
break;
case 'my':
$name = pht('My Macros');
break;
case 'active':
$name = pht('Active Macros');
break;
default:
throw new Exception("Unknown filter $this->filter");
break;
}
} else {
$name = pht('Search');
}
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addCrumb(
id(new PhabricatorCrumbView())
->setName($name)
->setHref($request->getRequestURI()));
$nav->setCrumbs($crumbs);
return $this->buildApplicationPage(
$nav,
array(
'device' => true,
'title' => pht('Image Macros'),
'dust' => true,
));
}
}
diff --git a/src/applications/macro/controller/PhabricatorMacroMemeController.php b/src/applications/macro/controller/PhabricatorMacroMemeController.php
index aa412f0436..4446f48f93 100644
--- a/src/applications/macro/controller/PhabricatorMacroMemeController.php
+++ b/src/applications/macro/controller/PhabricatorMacroMemeController.php
@@ -1,45 +1,45 @@
<?php
final class PhabricatorMacroMemeController
extends PhabricatorMacroController {
public function processRequest() {
$request = $this->getRequest();
$macro_name = $request->getStr('macro');
$upper_text = $request->getStr('uppertext');
$lower_text = $request->getStr('lowertext');
$user = $request->getUser();
- $macro = id(new PhabricatorFileImageMacro())
- ->loadOneWhere('name=%s', $macro_name);
+ $macro = id(new PhabricatorMacroQuery())
+ ->setViewer($user)
+ ->withNames(array($macro_name))
+ ->executeOne();
if (!$macro) {
return new Aphront404Response();
}
- $file = id(new PhabricatorFile())->loadOneWhere(
- 'phid = %s',
- $macro->getFilePHID());
+ $file = $macro->getFile();
$upper_text = strtoupper($upper_text);
$lower_text = strtoupper($lower_text);
$mixed_text = md5($upper_text).":".md5($lower_text);
$hash = "meme".hash("sha256", $mixed_text);
$xform = id(new PhabricatorTransformedFile())
->loadOneWhere('originalphid=%s and transform=%s',
$file->getPHID(), $hash);
if ($xform) {
$memefile = id(new PhabricatorFile())->loadOneWhere(
'phid = %s', $xform->getTransformedPHID());
return id(new AphrontRedirectResponse())->setURI($memefile->getBestURI());
}
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
$transformers = (new PhabricatorImageTransformer());
$newfile = $transformers
->executeMemeTransform($file, $upper_text, $lower_text);
$xfile = new PhabricatorTransformedFile();
$xfile->setOriginalPHID($file->getPHID());
$xfile->setTransformedPHID($newfile->getPHID());
$xfile->setTransform($hash);
$xfile->save();
return id(new AphrontRedirectResponse())->setURI($newfile->getBestURI());
}
}
diff --git a/src/applications/macro/controller/PhabricatorMacroMemeDialogController.php b/src/applications/macro/controller/PhabricatorMacroMemeDialogController.php
index 9bb82f9926..970cee1a65 100644
--- a/src/applications/macro/controller/PhabricatorMacroMemeDialogController.php
+++ b/src/applications/macro/controller/PhabricatorMacroMemeDialogController.php
@@ -1,74 +1,75 @@
<?php
final class PhabricatorMacroMemeDialogController
extends PhabricatorMacroController {
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$name = $request->getStr('macro');
$above = $request->getStr('above');
$below = $request->getStr('below');
$e_macro = true;
$errors = array();
if ($request->isDialogFormPost()) {
if (!$name) {
$e_macro = pht('Required');
$errors[] = pht('Macro name is required.');
} else {
- $macro = id(new PhabricatorFileImageMacro())->loadOneWhere(
- 'name = %s',
- $name);
+ $macro = id(new PhabricatorMacroQuery())
+ ->setViewer($user)
+ ->withNames(array($name))
+ ->executeOne();
if (!$macro) {
$e_macro = pht('Invalid');
$errors[] = pht('No such macro.');
}
}
if (!$errors) {
$options = new PhutilSimpleOptions();
$data = array(
'src' => $name,
'above' => $above,
'below' => $below,
);
$string = $options->unparse($data, $escape = '}');
$result = array(
'text' => "{meme, {$string}}",
);
return id(new AphrontAjaxResponse())->setContent($result);
}
}
$view = id(new AphrontFormLayoutView())
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Macro'))
->setName('macro')
->setValue($name)
->setError($e_macro))
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Above'))
->setName('above')
->setValue($above))
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Below'))
->setName('below')
->setValue($below));
$dialog = id(new AphrontDialogView())
->setUser($user)
->setTitle(pht('Create Meme'))
->appendChild($view)
->addCancelButton('/')
->addSubmitButton(pht('rofllolo!!~'));
return id(new AphrontDialogResponse())->setDialog($dialog);
}
}
diff --git a/src/applications/macro/controller/PhabricatorMacroViewController.php b/src/applications/macro/controller/PhabricatorMacroViewController.php
index 61fef8ead9..4b9e9b569b 100644
--- a/src/applications/macro/controller/PhabricatorMacroViewController.php
+++ b/src/applications/macro/controller/PhabricatorMacroViewController.php
@@ -1,172 +1,173 @@
<?php
final class PhabricatorMacroViewController
extends PhabricatorMacroController {
private $id;
public function willProcessRequest(array $data) {
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
- $macro = id(new PhabricatorFileImageMacro())->load($this->id);
+ $macro = id(new PhabricatorMacroQuery())
+ ->setViewer($user)
+ ->withIDs(array($this->id))
+ ->executeOne();
if (!$macro) {
return new Aphront404Response();
}
- $file = id(new PhabricatorFile())->loadOneWhere(
- 'phid = %s',
- $macro->getFilePHID());
+ $file = $macro->getFile();
$title_short = pht('Macro "%s"', $macro->getName());
$title_long = pht('Image Macro "%s"', $macro->getName());
$subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID(
$macro->getPHID());
$this->loadHandles($subscribers);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addCrumb(
id(new PhabricatorCrumbView())
->setHref($this->getApplicationURI('/view/'.$macro->getID().'/'))
->setName($title_short));
$actions = $this->buildActionView($macro);
$properties = $this->buildPropertyView($macro, $file, $subscribers);
$xactions = id(new PhabricatorMacroTransactionQuery())
->setViewer($request->getUser())
->withObjectPHIDs(array($macro->getPHID()))
->execute();
$engine = id(new PhabricatorMarkupEngine())
->setViewer($user);
foreach ($xactions as $xaction) {
if ($xaction->getComment()) {
$engine->addObject(
$xaction->getComment(),
PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT);
}
}
$engine->process();
$timeline = id(new PhabricatorApplicationTransactionView())
->setUser($user)
->setTransactions($xactions)
->setMarkupEngine($engine);
$header = id(new PhabricatorHeaderView())
->setHeader($title_long);
if ($macro->getIsDisabled()) {
$header->addTag(
id(new PhabricatorTagView())
->setType(PhabricatorTagView::TYPE_STATE)
->setName(pht('Macro Disabled'))
->setBackgroundColor(PhabricatorTagView::COLOR_BLACK));
}
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
$add_comment_header = id(new PhabricatorHeaderView())
->setHeader(
$is_serious
? pht('Add Comment')
: pht('Grovel in Awe'));
$submit_button_name = $is_serious
? pht('Add Comment')
: pht('Lavish Praise');
$draft = PhabricatorDraft::newFromUserAndKey($user, $macro->getPHID());
$add_comment_form = id(new PhabricatorApplicationTransactionCommentView())
->setUser($user)
->setDraft($draft)
->setAction($this->getApplicationURI('/comment/'.$macro->getID().'/'))
->setSubmitButtonName($submit_button_name);
return $this->buildApplicationPage(
array(
$crumbs,
$header,
$actions,
$properties,
$timeline,
$add_comment_header,
$add_comment_form,
),
array(
'title' => $title_short,
));
}
private function buildActionView(PhabricatorFileImageMacro $macro) {
$view = new PhabricatorActionListView();
$view->setUser($this->getRequest()->getUser());
$view->setObject($macro);
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('Edit Macro'))
->setHref($this->getApplicationURI('/edit/'.$macro->getID().'/'))
->setIcon('edit'));
if ($macro->getIsDisabled()) {
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('Restore Macro'))
->setHref($this->getApplicationURI('/disable/'.$macro->getID().'/'))
->setWorkflow(true)
->setIcon('undo'));
} else {
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('Disable Macro'))
->setHref($this->getApplicationURI('/disable/'.$macro->getID().'/'))
->setWorkflow(true)
->setIcon('delete'));
}
return $view;
}
private function buildPropertyView(
PhabricatorFileImageMacro $macro,
PhabricatorFile $file = null,
array $subscribers) {
$view = new PhabricatorPropertyListView();
if ($subscribers) {
$sub_view = array();
foreach ($subscribers as $subscriber) {
$sub_view[] = $this->getHandle($subscriber)->renderLink();
}
$sub_view = phutil_implode_html(', ', $sub_view);
} else {
$sub_view = phutil_tag('em', array(), pht('None'));
}
$view->addProperty(
pht('Subscribers'),
$sub_view);
if ($file) {
$view->addImageContent(
phutil_tag(
'img',
array(
'src' => $file->getViewURI(),
'class' => 'phabricator-image-macro-hero',
)));
}
return $view;
}
}
diff --git a/src/applications/macro/query/PhabricatorMacroQuery.php b/src/applications/macro/query/PhabricatorMacroQuery.php
index 45d24afbd7..1599c783a1 100644
--- a/src/applications/macro/query/PhabricatorMacroQuery.php
+++ b/src/applications/macro/query/PhabricatorMacroQuery.php
@@ -1,143 +1,156 @@
<?php
/**
* @group phriction
*/
final class PhabricatorMacroQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $phids;
private $authors;
- private $name;
+ private $names;
+ private $nameLike;
private $status = 'status-any';
const STATUS_ANY = 'status-any';
const STATUS_ACTIVE = 'status-active';
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function withAuthorPHIDs(array $authors) {
$this->authors = $authors;
return $this;
}
public function withNameLike($name) {
- $this->name = $name;
+ $this->nameLike = $name;
+ return $this;
+ }
+
+ public function withNames(array $names) {
+ $this->names = $names;
return $this;
}
public function withStatus($status) {
$this->status = $status;
return $this;
}
protected function loadPage() {
$macro_table = new PhabricatorFileImageMacro();
$conn = $macro_table->establishConnection('r');
$rows = queryfx_all(
$conn,
'SELECT * FROM %T m %Q %Q %Q %Q',
$macro_table->getTableName(),
$this->buildJoinClause($conn),
$this->buildWhereClause($conn),
$this->buildOrderClause($conn),
$this->buildLimitClause($conn));
return $macro_table->loadAllFromArray($rows);
}
protected function buildJoinClause(AphrontDatabaseConnection $conn) {
$joins = array();
if ($this->authors) {
$file_table = new PhabricatorFile();
$joins[] = qsprintf(
$conn,
'JOIN %T f ON m.filePHID = f.phid',
$file_table->getTableName());
}
return implode(' ', $joins);
}
protected function buildWhereClause(AphrontDatabaseConnection $conn) {
$where = array();
if ($this->ids) {
$where[] = qsprintf(
$conn,
'm.id IN (%Ld)',
$this->ids);
}
if ($this->phids) {
$where[] = qsprintf(
$conn,
'm.phid IN (%Ld)',
$this->phids);
}
if ($this->authors) {
$where[] = qsprintf(
$conn,
'f.authorPHID IN (%Ls)',
$this->authors);
}
- if ($this->name) {
+ if ($this->nameLike) {
$where[] = qsprintf(
$conn,
'm.name LIKE %~',
- $this->name);
+ $this->nameLike);
+ }
+
+ if ($this->names) {
+ $where[] = qsprintf(
+ $conn,
+ 'm.name IN (%Ls)',
+ $this->names);
}
if ($this->status == self::STATUS_ACTIVE) {
$where[] = qsprintf(
$conn,
'm.isDisabled = 0');
}
$where[] = $this->buildPagingClause($conn);
return $this->formatWhereClause($where);
}
protected function willFilterPage(array $macros) {
if (!$macros) {
return array();
}
$file_phids = mpull($macros, 'getFilePHID');
$files = id(new PhabricatorFileQuery())
->setViewer($this->getViewer())
->withPHIDs($file_phids)
->execute();
$files = mpull($files, null, 'getPHID');
foreach ($macros as $key => $macro) {
$file = idx($files, $macro->getFilePHID());
if (!$file) {
unset($macros[$key]);
continue;
}
$macro->attachFile($file);
}
return $macros;
}
protected function getPagingColumn() {
return 'm.id';
}
}
diff --git a/src/applications/macro/remarkup/PhabricatorRemarkupRuleImageMacro.php b/src/applications/macro/remarkup/PhabricatorRemarkupRuleImageMacro.php
index 7ad83ebc58..48eefd12f7 100644
--- a/src/applications/macro/remarkup/PhabricatorRemarkupRuleImageMacro.php
+++ b/src/applications/macro/remarkup/PhabricatorRemarkupRuleImageMacro.php
@@ -1,63 +1,67 @@
<?php
/**
* @group markup
*/
final class PhabricatorRemarkupRuleImageMacro
extends PhutilRemarkupRule {
private $images;
public function apply($text) {
return preg_replace_callback(
'@^([a-zA-Z0-9:_\-]+)$@m',
array($this, 'markupImageMacro'),
$text);
}
public function markupImageMacro($matches) {
if ($this->images === null) {
$this->images = array();
- $rows = id(new PhabricatorFileImageMacro())->loadAllWhere(
- 'isDisabled = 0');
+
+ $viewer = $this->getEngine()->getConfig('viewer');
+ $rows = id(new PhabricatorMacroQuery())
+ ->setViewer($viewer)
+ ->withStatus(PhabricatorMacroQuery::STATUS_ACTIVE)
+ ->execute();
foreach ($rows as $row) {
$this->images[$row->getName()] = $row->getFilePHID();
}
}
$name = (string)$matches[1];
if (array_key_exists($name, $this->images)) {
$phid = $this->images[$name];
$file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $phid);
$style = null;
$src_uri = null;
if ($file) {
$src_uri = $file->getBestURI();
$file_data = $file->getMetadata();
$height = idx($file_data, PhabricatorFile::METADATA_IMAGE_HEIGHT);
$width = idx($file_data, PhabricatorFile::METADATA_IMAGE_WIDTH);
if ($height && $width) {
$style = sprintf(
'height: %dpx; width: %dpx;',
$height,
$width);
}
}
$img = phutil_tag(
'img',
array(
'src' => $src_uri,
'alt' => $matches[1],
'title' => $matches[1],
'style' => $style,
));
return $this->getEngine()->storeText($img);
} else {
return $matches[1];
}
}
}
diff --git a/src/applications/phid/handle/PhabricatorObjectHandleData.php b/src/applications/phid/handle/PhabricatorObjectHandleData.php
index db6bfd9e33..c08a9b25b9 100644
--- a/src/applications/phid/handle/PhabricatorObjectHandleData.php
+++ b/src/applications/phid/handle/PhabricatorObjectHandleData.php
@@ -1,678 +1,679 @@
<?php
final class PhabricatorObjectHandleData {
private $phids;
private $viewer;
public function __construct(array $phids) {
$this->phids = array_unique($phids);
}
public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer;
return $this;
}
public static function loadOneHandle($phid, PhabricatorUser $viewer) {
$query = new PhabricatorObjectHandleData(array($phid));
$query->setViewer($viewer);
$handles = $query->loadHandles();
return $handles[$phid];
}
public function loadObjects() {
$types = phid_group_by_type($this->phids);
$objects = array();
foreach ($types as $type => $phids) {
$objects += $this->loadObjectsOfType($type, $phids);
}
return $objects;
}
private function loadObjectsOfType($type, array $phids) {
if (!$this->viewer) {
throw new Exception(
"You must provide a viewer to load handles or objects.");
}
switch ($type) {
case PhabricatorPHIDConstants::PHID_TYPE_USER:
$user_dao = new PhabricatorUser();
$users = $user_dao->loadAllWhere(
'phid in (%Ls)',
$phids);
return mpull($users, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_CMIT:
$commits = id(new DiffusionCommitQuery())
->setViewer($this->viewer)
->withPHIDs($phids)
->execute();
return mpull($commits, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_TASK:
$task_dao = new ManiphestTask();
$tasks = $task_dao->loadAllWhere(
'phid IN (%Ls)',
$phids);
return mpull($tasks, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_CONF:
$config_dao = new PhabricatorConfigEntry();
$entries = $config_dao->loadAllWhere(
'phid IN (%Ls)',
$phids);
return mpull($entries, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_FILE:
$object = new PhabricatorFile();
$files = $object->loadAllWhere('phid IN (%Ls)', $phids);
return mpull($files, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_PROJ:
$projects = id(new PhabricatorProjectQuery())
->setViewer($this->viewer)
->withPHIDs($phids)
->execute();
return mpull($projects, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_REPO:
$object = new PhabricatorRepository();
$repositories = $object->loadAllWhere('phid in (%Ls)', $phids);
return mpull($repositories, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_OPKG:
$object = new PhabricatorOwnersPackage();
$packages = $object->loadAllWhere('phid in (%Ls)', $phids);
return mpull($packages, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_APRJ:
$project_dao = new PhabricatorRepositoryArcanistProject();
$projects = $project_dao->loadAllWhere(
'phid IN (%Ls)',
$phids);
return mpull($projects, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_MLST:
$object = new PhabricatorMetaMTAMailingList();
$lists = $object->loadAllWhere('phid IN (%Ls)', $phids);
return mpull($lists, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_DREV:
$revision_dao = new DifferentialRevision();
$revisions = $revision_dao->loadAllWhere(
'phid IN (%Ls)',
$phids);
return mpull($revisions, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_WIKI:
$document_dao = new PhrictionDocument();
$documents = $document_dao->loadAllWhere(
'phid IN (%Ls)',
$phids);
return mpull($documents, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_QUES:
$questions = id(new PonderQuestionQuery())
->setViewer($this->viewer)
->withPHIDs($phids)
->execute();
return mpull($questions, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_MOCK:
$mocks = id(new PholioMockQuery())
->setViewer($this->viewer)
->withPHIDs($phids)
->execute();
return mpull($mocks, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_XACT:
$subtypes = array();
foreach ($phids as $phid) {
$subtypes[phid_get_subtype($phid)][] = $phid;
}
$xactions = array();
foreach ($subtypes as $subtype => $subtype_phids) {
// TODO: Do this magically.
switch ($subtype) {
case PhabricatorPHIDConstants::PHID_TYPE_MOCK:
$results = id(new PholioTransactionQuery())
->setViewer($this->viewer)
->withPHIDs($subtype_phids)
->execute();
$xactions += mpull($results, null, 'getPHID');
break;
case PhabricatorPHIDConstants::PHID_TYPE_MCRO:
$results = id(new PhabricatorMacroTransactionQuery())
->setViewer($this->viewer)
->withPHIDs($subtype_phids)
->execute();
$xactions += mpull($results, null, 'getPHID');
break;
}
}
return mpull($xactions, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_MCRO:
- $macros = id(new PhabricatorFileImageMacro())->loadAllWhere(
- 'phid IN (%Ls)',
- $phids);
+ $macros = id(new PhabricatorMacroQuery())
+ ->setViewer($this->viewer)
+ ->withPHIDs($phids)
+ ->execute();
return mpull($macros, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_PSTE:
$pastes = id(new PhabricatorPasteQuery())
->withPHIDs($phids)
->setViewer($this->viewer)
->execute();
return mpull($pastes, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_BLOG:
$blogs = id(new PhameBlogQuery())
->withPHIDs($phids)
->setViewer($this->viewer)
->execute();
return mpull($blogs, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_POST:
$posts = id(new PhamePostQuery())
->withPHIDs($phids)
->setViewer($this->viewer)
->execute();
return mpull($posts, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_PVAR:
$vars = id(new PhluxVariableQuery())
->withPHIDs($phids)
->setViewer($this->viewer)
->execute();
return mpull($vars, null, 'getPHID');
}
}
public function loadHandles() {
$types = phid_group_by_type($this->phids);
$handles = array();
$external_loaders = PhabricatorEnv::getEnvConfig('phid.external-loaders');
foreach ($types as $type => $phids) {
$objects = $this->loadObjectsOfType($type, $phids);
switch ($type) {
case PhabricatorPHIDConstants::PHID_TYPE_MAGIC:
// Black magic!
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
switch ($phid) {
case ManiphestTaskOwner::OWNER_UP_FOR_GRABS:
$handle->setName('Up For Grabs');
$handle->setFullName('upforgrabs (Up For Grabs)');
$handle->setComplete(true);
break;
case ManiphestTaskOwner::PROJECT_NO_PROJECT:
$handle->setName('No Project');
$handle->setFullName('noproject (No Project)');
$handle->setComplete(true);
break;
default:
$handle->setName('Foul Magicks');
break;
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_USER:
$image_phids = mpull($objects, 'getProfileImagePHID');
$image_phids = array_unique(array_filter($image_phids));
$images = array();
if ($image_phids) {
$images = id(new PhabricatorFile())->loadAllWhere(
'phid IN (%Ls)',
$image_phids);
$images = mpull($images, 'getBestURI', 'getPHID');
}
$statuses = id(new PhabricatorUserStatus())->loadCurrentStatuses(
$phids);
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown User');
} else {
$user = $objects[$phid];
$handle->setName($user->getUsername());
$handle->setURI('/p/'.$user->getUsername().'/');
$handle->setFullName(
$user->getUsername().' ('.$user->getRealName().')');
$handle->setAlternateID($user->getID());
$handle->setComplete(true);
if (isset($statuses[$phid])) {
$handle->setStatus($statuses[$phid]->getTextStatus());
$handle->setTitle(
$statuses[$phid]->getTerseSummary($this->viewer));
}
$handle->setDisabled($user->getIsDisabled());
$img_uri = idx($images, $user->getProfileImagePHID());
if ($img_uri) {
$handle->setImageURI($img_uri);
} else {
$handle->setImageURI(
PhabricatorUser::getDefaultProfileImageURI());
}
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_MLST:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown Mailing List');
} else {
$list = $objects[$phid];
$handle->setName($list->getName());
$handle->setURI($list->getURI());
$handle->setFullName($list->getName());
$handle->setComplete(true);
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_DREV:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown Revision');
} else {
$rev = $objects[$phid];
$handle->setName($rev->getTitle());
$handle->setURI('/D'.$rev->getID());
$handle->setFullName('D'.$rev->getID().': '.$rev->getTitle());
$handle->setComplete(true);
$status = $rev->getStatus();
if (($status == ArcanistDifferentialRevisionStatus::CLOSED) ||
($status == ArcanistDifferentialRevisionStatus::ABANDONED)) {
$closed = PhabricatorObjectHandleStatus::STATUS_CLOSED;
$handle->setStatus($closed);
}
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_CMIT:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown Commit');
} else {
$repository = $objects[$phid]->getRepository();
$commit = $objects[$phid];
$callsign = $repository->getCallsign();
$commit_identifier = $commit->getCommitIdentifier();
$name = $repository->formatCommitName($commit_identifier);
$handle->setName($name);
$summary = $commit->getSummary();
if (strlen($summary)) {
$handle->setFullName($name.': '.$summary);
} else {
$handle->setFullName($name);
}
$handle->setURI('/r'.$callsign.$commit_identifier);
$handle->setTimestamp($commit->getEpoch());
$handle->setComplete(true);
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_TASK:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown Task');
} else {
$task = $objects[$phid];
$handle->setName($task->getTitle());
$handle->setURI('/T'.$task->getID());
$handle->setFullName('T'.$task->getID().': '.$task->getTitle());
$handle->setComplete(true);
$handle->setAlternateID($task->getID());
if ($task->getStatus() != ManiphestTaskStatus::STATUS_OPEN) {
$closed = PhabricatorObjectHandleStatus::STATUS_CLOSED;
$handle->setStatus($closed);
}
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_CONF:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown Config Entry');
} else {
$entry = $objects[$phid];
$handle->setName($entry->getKey());
$handle->setURI('/config/edit/'.$entry->getKey());
$handle->setFullName($entry->getKey());
$handle->setComplete(true);
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_FILE:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown File');
} else {
$file = $objects[$phid];
$handle->setName($file->getName());
$handle->setURI($file->getBestURI());
$handle->setComplete(true);
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_PROJ:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown Project');
} else {
$project = $objects[$phid];
$handle->setName($project->getName());
$handle->setURI('/project/view/'.$project->getID().'/');
$handle->setComplete(true);
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_REPO:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown Repository');
} else {
$repository = $objects[$phid];
$handle->setName($repository->getCallsign());
$handle->setFullName("r" . $repository->getCallsign() .
" (" . $repository->getName() . ")");
$handle->setURI('/diffusion/'.$repository->getCallsign().'/');
$handle->setComplete(true);
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_OPKG:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown Package');
} else {
$package = $objects[$phid];
$handle->setName($package->getName());
$handle->setURI('/owners/package/'.$package->getID().'/');
$handle->setComplete(true);
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_APRJ:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown Arcanist Project');
} else {
$project = $objects[$phid];
$handle->setName($project->getName());
$handle->setComplete(true);
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_WIKI:
$document_dao = new PhrictionDocument();
$content_dao = new PhrictionContent();
$conn = $document_dao->establishConnection('r');
$documents = queryfx_all(
$conn,
'SELECT * FROM %T document JOIN %T content
ON document.contentID = content.id
WHERE document.phid IN (%Ls)',
$document_dao->getTableName(),
$content_dao->getTableName(),
$phids);
$documents = ipull($documents, null, 'phid');
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($documents[$phid])) {
$handle->setName('Unknown Document');
} else {
$info = $documents[$phid];
$handle->setName($info['title']);
$handle->setURI(PhrictionDocument::getSlugURI($info['slug']));
$handle->setComplete(true);
if ($info['status'] != PhrictionDocumentStatus::STATUS_EXISTS) {
$closed = PhabricatorObjectHandleStatus::STATUS_CLOSED;
$handle->setStatus($closed);
}
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_QUES:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown Ponder Question');
} else {
$question = $objects[$phid];
$handle->setName(phutil_utf8_shorten($question->getTitle(), 60));
$handle->setURI(new PhutilURI('/Q' . $question->getID()));
$handle->setComplete(true);
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_PSTE:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown Paste');
} else {
$paste = $objects[$phid];
$handle->setName($paste->getTitle());
$handle->setFullName($paste->getFullName());
$handle->setURI('/P'.$paste->getID());
$handle->setComplete(true);
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_BLOG:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown Blog');
} else {
$blog = $objects[$phid];
$handle->setName($blog->getName());
$handle->setFullName($blog->getName());
$handle->setURI('/phame/blog/view/'.$blog->getID().'/');
$handle->setComplete(true);
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_POST:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown Post');
} else {
$post = $objects[$phid];
$handle->setName($post->getTitle());
$handle->setFullName($post->getTitle());
$handle->setURI('/phame/post/view/'.$post->getID().'/');
$handle->setComplete(true);
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_MOCK:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown Mock');
} else {
$mock = $objects[$phid];
$handle->setName($mock->getName());
$handle->setFullName('M'.$mock->getID().': '.$mock->getName());
$handle->setURI('/M'.$mock->getID());
$handle->setComplete(true);
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_MCRO:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown Macro');
} else {
$macro = $objects[$phid];
$handle->setName($macro->getName());
$handle->setFullName('Image Macro "'.$macro->getName().'"');
$handle->setURI('/macro/view/'.$macro->getID().'/');
$handle->setComplete(true);
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_PVAR:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown Variable');
} else {
$var = $objects[$phid];
$key = $var->getVariableKey();
$handle->setName($key);
$handle->setFullName('Phlux Variable "'.$key.'"');
$handle->setURI('/phlux/view/'.$key.'/');
$handle->setComplete(true);
}
$handles[$phid] = $handle;
}
break;
default:
$loader = null;
if (isset($external_loaders[$type])) {
$loader = $external_loaders[$type];
} else if (isset($external_loaders['*'])) {
$loader = $external_loaders['*'];
}
if ($loader) {
$object = newv($loader, array());
assert_instances_of(array($type => $object), 'ObjectHandleLoader');
$handles += $object->loadHandles($phids);
break;
}
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setType($type);
$handle->setPHID($phid);
$handle->setName('Unknown Object');
$handle->setFullName('An Unknown Object');
$handles[$phid] = $handle;
}
break;
}
}
return $handles;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Jan 19 2025, 23:23 (6 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1129862
Default Alt Text
(60 KB)

Event Timeline