@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.

Add a Phriction hint when a draft exists, and fix some draft editing bugs

Summary:
Depends on D19662. Ref T13077. See PHI840.

- If you're looking at the published version of a document, but a draft version exists and you can edit it, add a hint/link.
- Fix an issue where the "draft" transaction would complain when you created a document since the initial content is empty and no "draft" transaction is adding any content.

Test Plan: Created new documents, viewed documents with current published versions and unpublished drafts.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13077

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

+87 -24
+29
src/applications/phriction/controller/PhrictionDocumentController.php
··· 186 186 ); 187 187 } else { 188 188 $content = $document->getContent(); 189 + 190 + if ($content->getVersion() < $document->getMaxVersion()) { 191 + $can_edit = PhabricatorPolicyFilter::hasCapability( 192 + $viewer, 193 + $document, 194 + PhabricatorPolicyCapability::CAN_EDIT); 195 + if ($can_edit) { 196 + $document_uri = new PhutilURI($document->getURI()); 197 + $draft_uri = $document_uri->alter('v', $document->getMaxVersion()); 198 + 199 + $draft_link = phutil_tag( 200 + 'a', 201 + array( 202 + 'href' => $draft_uri, 203 + ), 204 + pht('View Draft Version')); 205 + 206 + $draft_link = phutil_tag('strong', array(), $draft_link); 207 + 208 + $version_note = id(new PHUIInfoView()) 209 + ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) 210 + ->appendChild( 211 + array( 212 + pht('This document has unpublished draft changes.'), 213 + ' ', 214 + $draft_link, 215 + )); 216 + } 217 + } 189 218 } 190 219 191 220 $page_title = $content->getTitle();
+21 -11
src/applications/phriction/controller/PhrictionEditController.php
··· 98 98 $is_draft_mode = ($document->getContent()->getVersion() != $max_version); 99 99 100 100 if ($request->isFormPost()) { 101 - $save_as_draft = ($is_draft_mode || $request->getExists('draft')); 101 + if ($is_new) { 102 + $save_as_draft = false; 103 + } else { 104 + $save_as_draft = ($is_draft_mode || $request->getExists('draft')); 105 + } 102 106 103 107 $title = $request->getStr('title'); 104 108 $content_text = $request->getStr('content'); ··· 117 121 } 118 122 119 123 $xactions = array(); 124 + 120 125 $xactions[] = id(new PhrictionTransaction()) 121 126 ->setTransactionType(PhrictionDocumentTitleTransaction::TRANSACTIONTYPE) 122 127 ->setNewValue($title); ··· 275 280 ->addCancelButton($cancel_uri) 276 281 ->setValue(pht('Save Draft'))); 277 282 } else { 278 - $draft_button = id(new PHUIButtonView()) 279 - ->setTag('input') 280 - ->setName('draft') 281 - ->setText(pht('Save as Draft')) 282 - ->setColor(PHUIButtonView::GREEN); 283 + $submit = id(new AphrontFormSubmitControl()); 284 + 285 + if (!$is_new) { 286 + $draft_button = id(new PHUIButtonView()) 287 + ->setTag('input') 288 + ->setName('draft') 289 + ->setText(pht('Save as Draft')) 290 + ->setColor(PHUIButtonView::GREEN); 291 + $submit->addButton($draft_button); 292 + } 293 + 294 + $submit 295 + ->addCancelButton($cancel_uri) 296 + ->setValue($submit_button); 283 297 284 - $form->appendControl( 285 - id(new AphrontFormSubmitControl()) 286 - ->addButton($draft_button) 287 - ->addCancelButton($cancel_uri) 288 - ->setValue($submit_button)); 298 + $form->appendControl($submit); 289 299 } 290 300 291 301 $form_box = id(new PHUIObjectBoxView())
+16
src/applications/phriction/xaction/PhrictionDocumentContentTransaction.php
··· 13 13 $this->getEditor()->setShouldPublishContent($object, true); 14 14 } 15 15 16 + public function validateTransactions($object, array $xactions) { 17 + $errors = array(); 18 + 19 + // NOTE: This is slightly different from the draft validation. Here, 20 + // we're validating that: you can't edit away a document; and you can't 21 + // create an empty document. 22 + 23 + $content = $object->getContent()->getContent(); 24 + if ($this->isEmptyTextTransaction($content, $xactions)) { 25 + $errors[] = $this->newRequiredError( 26 + pht('Documents must have content.')); 27 + } 28 + 29 + return $errors; 30 + } 31 + 16 32 }
+21
src/applications/phriction/xaction/PhrictionDocumentDraftTransaction.php
··· 11 11 $this->getEditor()->setShouldPublishContent($object, false); 12 12 } 13 13 14 + public function validateTransactions($object, array $xactions) { 15 + $errors = array(); 16 + 17 + // NOTE: We're only validating that you can't edit a document down to 18 + // nothing in a draft transaction. Alone, this doesn't prevent you from 19 + // creating a document with no content. The content transaction has 20 + // validation for that. 21 + 22 + if (!$xactions) { 23 + return $errors; 24 + } 25 + 26 + $content = $object->getContent()->getContent(); 27 + if ($this->isEmptyTextTransaction($content, $xactions)) { 28 + $errors[] = $this->newRequiredError( 29 + pht('Documents must have content.')); 30 + } 31 + 32 + return $errors; 33 + } 34 + 14 35 }
-13
src/applications/phriction/xaction/PhrictionDocumentEditTransaction.php
··· 79 79 return $changes; 80 80 } 81 81 82 - public function validateTransactions($object, array $xactions) { 83 - $errors = array(); 84 - 85 - $content = $object->getContent()->getContent(); 86 - if ($this->isEmptyTextTransaction($content, $xactions)) { 87 - $errors[] = $this->newRequiredError( 88 - pht('Documents must have content.')); 89 - } 90 - 91 - return $errors; 92 - } 93 - 94 - 95 82 }