@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Give PhameBlog an EditEngine

Summary: This seems to work, but I couldn't figure out how to pass over a Caption for a text field.

Test Plan: New blog, Edit blog.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D14770

+96 -190
+2
src/__phutil_library_map__.php
··· 3352 3352 'PhameBlogController' => 'applications/phame/controller/blog/PhameBlogController.php', 3353 3353 'PhameBlogCreateCapability' => 'applications/phame/capability/PhameBlogCreateCapability.php', 3354 3354 'PhameBlogEditController' => 'applications/phame/controller/blog/PhameBlogEditController.php', 3355 + 'PhameBlogEditEngine' => 'applications/phame/editor/PhameBlogEditEngine.php', 3355 3356 'PhameBlogEditor' => 'applications/phame/editor/PhameBlogEditor.php', 3356 3357 'PhameBlogFeedController' => 'applications/phame/controller/blog/PhameBlogFeedController.php', 3357 3358 'PhameBlogListController' => 'applications/phame/controller/blog/PhameBlogListController.php', ··· 7735 7736 'PhameBlogController' => 'PhameController', 7736 7737 'PhameBlogCreateCapability' => 'PhabricatorPolicyCapability', 7737 7738 'PhameBlogEditController' => 'PhameBlogController', 7739 + 'PhameBlogEditEngine' => 'PhabricatorEditEngine', 7738 7740 'PhameBlogEditor' => 'PhabricatorApplicationTransactionEditor', 7739 7741 'PhameBlogFeedController' => 'PhameBlogController', 7740 7742 'PhameBlogListController' => 'PhameBlogController',
+5 -190
src/applications/phame/controller/blog/PhameBlogEditController.php
··· 1 1 <?php 2 2 3 - final class PhameBlogEditController 4 - extends PhameBlogController { 3 + final class PhameBlogEditController extends PhameBlogController { 5 4 6 5 public function handleRequest(AphrontRequest $request) { 7 - $viewer = $request->getViewer(); 8 - $id = $request->getURIData('id'); 9 - 10 - if ($id) { 11 - $blog = id(new PhameBlogQuery()) 12 - ->setViewer($viewer) 13 - ->withIDs(array($id)) 14 - ->requireCapabilities( 15 - array( 16 - PhabricatorPolicyCapability::CAN_EDIT, 17 - )) 18 - ->executeOne(); 19 - if (!$blog) { 20 - return new Aphront404Response(); 21 - } 22 - 23 - $submit_button = pht('Save Changes'); 24 - $page_title = pht('Edit Blog'); 25 - $cancel_uri = $this->getApplicationURI('blog/view/'.$blog->getID().'/'); 26 - 27 - $v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs( 28 - $blog->getPHID(), 29 - PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); 30 - $v_projects = array_reverse($v_projects); 31 - $v_cc = PhabricatorSubscribersQuery::loadSubscribersForPHID( 32 - $blog->getPHID()); 33 - 34 - } else { 35 - $this->requireApplicationCapability( 36 - PhameBlogCreateCapability::CAPABILITY); 37 - 38 - $blog = PhameBlog::initializeNewBlog($viewer); 39 - 40 - $submit_button = pht('Create Blog'); 41 - $page_title = pht('Create Blog'); 42 - $cancel_uri = $this->getApplicationURI(); 43 - $v_projects = array(); 44 - $v_cc = array(); 45 - } 46 - $name = $blog->getName(); 47 - $description = $blog->getDescription(); 48 - $custom_domain = $blog->getDomain(); 49 - $can_view = $blog->getViewPolicy(); 50 - $can_edit = $blog->getEditPolicy(); 51 - 52 - $e_name = true; 53 - $e_custom_domain = null; 54 - $e_view_policy = null; 55 - $validation_exception = null; 56 - if ($request->isFormPost()) { 57 - $name = $request->getStr('name'); 58 - $description = $request->getStr('description'); 59 - $custom_domain = nonempty($request->getStr('custom_domain'), null); 60 - $can_view = $request->getStr('can_view'); 61 - $can_edit = $request->getStr('can_edit'); 62 - $v_projects = $request->getArr('projects'); 63 - $v_cc = $request->getArr('cc'); 6 + return id(new PhameBlogEditEngine()) 7 + ->setController($this) 8 + ->buildResponse(); 9 + } 64 10 65 - $xactions = array( 66 - id(new PhameBlogTransaction()) 67 - ->setTransactionType(PhameBlogTransaction::TYPE_NAME) 68 - ->setNewValue($name), 69 - id(new PhameBlogTransaction()) 70 - ->setTransactionType(PhameBlogTransaction::TYPE_DESCRIPTION) 71 - ->setNewValue($description), 72 - id(new PhameBlogTransaction()) 73 - ->setTransactionType(PhameBlogTransaction::TYPE_DOMAIN) 74 - ->setNewValue($custom_domain), 75 - id(new PhameBlogTransaction()) 76 - ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY) 77 - ->setNewValue($can_view), 78 - id(new PhameBlogTransaction()) 79 - ->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY) 80 - ->setNewValue($can_edit), 81 - id(new PhameBlogTransaction()) 82 - ->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS) 83 - ->setNewValue(array('=' => $v_cc)), 84 - ); 85 - 86 - $proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; 87 - $xactions[] = id(new PhameBlogTransaction()) 88 - ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) 89 - ->setMetadataValue('edge:type', $proj_edge_type) 90 - ->setNewValue(array('=' => array_fuse($v_projects))); 91 - 92 - $editor = id(new PhameBlogEditor()) 93 - ->setActor($viewer) 94 - ->setContentSourceFromRequest($request) 95 - ->setContinueOnNoEffect(true); 96 - 97 - try { 98 - $editor->applyTransactions($blog, $xactions); 99 - return id(new AphrontRedirectResponse()) 100 - ->setURI($this->getApplicationURI('blog/view/'.$blog->getID().'/')); 101 - } catch (PhabricatorApplicationTransactionValidationException $ex) { 102 - $validation_exception = $ex; 103 - 104 - $e_name = $validation_exception->getShortMessage( 105 - PhameBlogTransaction::TYPE_NAME); 106 - $e_custom_domain = $validation_exception->getShortMessage( 107 - PhameBlogTransaction::TYPE_DOMAIN); 108 - $e_view_policy = $validation_exception->getShortMessage( 109 - PhabricatorTransactions::TYPE_VIEW_POLICY); 110 - } 111 - } 112 - 113 - $policies = id(new PhabricatorPolicyQuery()) 114 - ->setViewer($viewer) 115 - ->setObject($blog) 116 - ->execute(); 117 - 118 - $form = id(new AphrontFormView()) 119 - ->setUser($viewer) 120 - ->appendChild( 121 - id(new AphrontFormTextControl()) 122 - ->setLabel(pht('Name')) 123 - ->setName('name') 124 - ->setValue($name) 125 - ->setID('blog-name') 126 - ->setError($e_name)) 127 - ->appendChild( 128 - id(new PhabricatorRemarkupControl()) 129 - ->setUser($viewer) 130 - ->setLabel(pht('Description')) 131 - ->setName('description') 132 - ->setValue($description) 133 - ->setID('blog-description') 134 - ->setUser($viewer) 135 - ->setDisableMacros(true)) 136 - ->appendControl( 137 - id(new AphrontFormTokenizerControl()) 138 - ->setLabel(pht('Subscribers')) 139 - ->setName('cc') 140 - ->setValue($v_cc) 141 - ->setUser($viewer) 142 - ->setDatasource(new PhabricatorMetaMTAMailableDatasource())) 143 - ->appendChild( 144 - id(new AphrontFormPolicyControl()) 145 - ->setUser($viewer) 146 - ->setCapability(PhabricatorPolicyCapability::CAN_VIEW) 147 - ->setPolicyObject($blog) 148 - ->setPolicies($policies) 149 - ->setError($e_view_policy) 150 - ->setValue($can_view) 151 - ->setName('can_view')) 152 - ->appendChild( 153 - id(new AphrontFormPolicyControl()) 154 - ->setUser($viewer) 155 - ->setCapability(PhabricatorPolicyCapability::CAN_EDIT) 156 - ->setPolicyObject($blog) 157 - ->setPolicies($policies) 158 - ->setValue($can_edit) 159 - ->setName('can_edit')) 160 - ->appendControl( 161 - id(new AphrontFormTokenizerControl()) 162 - ->setLabel(pht('Projects')) 163 - ->setName('projects') 164 - ->setValue($v_projects) 165 - ->setDatasource(new PhabricatorProjectDatasource())) 166 - ->appendChild( 167 - id(new AphrontFormTextControl()) 168 - ->setLabel(pht('Custom Domain')) 169 - ->setName('custom_domain') 170 - ->setValue($custom_domain) 171 - ->setCaption( 172 - pht('Must include at least one dot (.), e.g. %s', 'blog.example.com')) 173 - ->setError($e_custom_domain)) 174 - ->appendChild( 175 - id(new AphrontFormSubmitControl()) 176 - ->addCancelButton($cancel_uri) 177 - ->setValue($submit_button)); 178 - 179 - $form_box = id(new PHUIObjectBoxView()) 180 - ->setHeaderText($page_title) 181 - ->setValidationException($validation_exception) 182 - ->setForm($form); 183 - 184 - $crumbs = $this->buildApplicationCrumbs(); 185 - $crumbs->addTextCrumb(pht('Blogs'), $this->getApplicationURI('blog/')); 186 - $crumbs->addTextCrumb($page_title, $this->getApplicationURI('blog/new')); 187 - 188 - return $this->newPage() 189 - ->setTitle($page_title) 190 - ->setCrumbs($crumbs) 191 - ->appendChild( 192 - array( 193 - $form_box, 194 - )); 195 - } 196 11 }
+85
src/applications/phame/editor/PhameBlogEditEngine.php
··· 1 + <?php 2 + 3 + final class PhameBlogEditEngine 4 + extends PhabricatorEditEngine { 5 + 6 + const ENGINECONST = 'phame.blog'; 7 + 8 + public function getEngineName() { 9 + return pht('Blogs'); 10 + } 11 + 12 + public function getEngineApplicationClass() { 13 + return 'PhabricatorPhameApplication'; 14 + } 15 + 16 + protected function newEditableObject() { 17 + return PhameBlog::initializeNewBlog($this->getViewer()); 18 + } 19 + 20 + protected function newObjectQuery() { 21 + return id(new PhameBlogQuery()) 22 + ->needProfileImage(true); 23 + } 24 + 25 + protected function getObjectCreateTitleText($object) { 26 + return pht('Create New Blog'); 27 + } 28 + 29 + protected function getObjectEditTitleText($object) { 30 + return pht('Edit %s', $object->getName()); 31 + } 32 + 33 + protected function getObjectEditShortText($object) { 34 + return $object->getName(); 35 + } 36 + 37 + protected function getObjectCreateShortText() { 38 + return pht('Create Blog'); 39 + } 40 + 41 + protected function getObjectViewURI($object) { 42 + return $object->getManageURI(); 43 + } 44 + 45 + protected function buildCustomEditFields($object) { 46 + 47 + return array( 48 + id(new PhabricatorTextEditField()) 49 + ->setKey('name') 50 + ->setLabel(pht('Name')) 51 + ->setDescription(pht('Blog name.')) 52 + ->setConduitDescription(pht('Retitle the blog.')) 53 + ->setConduitTypeDescription(pht('New blog title.')) 54 + ->setTransactionType(PhameBlogTransaction::TYPE_NAME) 55 + ->setValue($object->getName()), 56 + id(new PhabricatorRemarkupEditField()) 57 + ->setKey('description') 58 + ->setLabel(pht('Description')) 59 + ->setDescription(pht('Blog description.')) 60 + ->setConduitDescription(pht('Change the blog description.')) 61 + ->setConduitTypeDescription(pht('New blog description.')) 62 + ->setTransactionType(PhameBlogTransaction::TYPE_DESCRIPTION) 63 + ->setValue($object->getDescription()), 64 + id(new PhabricatorTextEditField()) 65 + ->setKey('domain') 66 + ->setLabel(pht('Custom Domain')) 67 + ->setDescription(pht('Blog domain name.')) 68 + ->setConduitDescription(pht('Change the blog domain.')) 69 + ->setConduitTypeDescription(pht('New blog domain.')) 70 + ->setValue($object->getDomain()) 71 + ->setTransactionType(PhameBlogTransaction::TYPE_DOMAIN), 72 + id(new PhabricatorSelectEditField()) 73 + ->setKey('status') 74 + ->setLabel(pht('Status')) 75 + ->setTransactionType(PhameBlogTransaction::TYPE_STATUS) 76 + ->setIsConduitOnly(true) 77 + ->setOptions(PhameBlog::getStatusNameMap()) 78 + ->setDescription(pht('Active or archived status.')) 79 + ->setConduitDescription(pht('Active or archive the blog.')) 80 + ->setConduitTypeDescription(pht('New blog status constant.')) 81 + ->setValue($object->getStatus()), 82 + ); 83 + } 84 + 85 + }
+4
src/applications/phame/storage/PhameBlog.php
··· 193 193 return '/phame/blog/view/'.$this->getID().'/'; 194 194 } 195 195 196 + public function getManageURI() { 197 + return '/phame/blog/manage/'.$this->getID().'/'; 198 + } 199 + 196 200 public function getProfileImageURI() { 197 201 return $this->getProfileImageFile()->getBestURI(); 198 202 }