Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phriction/controller/PhrictionEditController.php
Show First 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | if ($id) { | ||||
$is_new = false; | $is_new = false; | ||||
} else { | } else { | ||||
$document = PhrictionDocument::initializeNewDocument($viewer, $slug); | $document = PhrictionDocument::initializeNewDocument($viewer, $slug); | ||||
$content = $document->getContent(); | $content = $document->getContent(); | ||||
$is_new = true; | $is_new = true; | ||||
} | } | ||||
} | } | ||||
if ($request->getBool('nodraft')) { | |||||
$draft = null; | |||||
$draft_key = null; | |||||
} else { | |||||
if ($document->getPHID()) { | |||||
$draft_key = $document->getPHID().':'.$content->getVersion(); | |||||
} else { | |||||
$draft_key = 'phriction:'.$content->getSlug(); | |||||
} | |||||
$draft = id(new PhabricatorDraft())->loadOneWhere( | |||||
'authorPHID = %s AND draftKey = %s', | |||||
$viewer->getPHID(), | |||||
$draft_key); | |||||
} | |||||
if ($draft && | |||||
strlen($draft->getDraft()) && | |||||
($draft->getDraft() != $content->getContent())) { | |||||
$content_text = $draft->getDraft(); | |||||
$discard = phutil_tag( | |||||
'a', | |||||
array( | |||||
'href' => $request->getRequestURI()->alter('nodraft', true), | |||||
), | |||||
pht('discard this draft')); | |||||
$draft_note = new PHUIInfoView(); | |||||
$draft_note->setSeverity(PHUIInfoView::SEVERITY_NOTICE); | |||||
$draft_note->setTitle(pht('Recovered Draft')); | |||||
$draft_note->appendChild( | |||||
pht('Showing a saved draft of your edits, you can %s.', $discard)); | |||||
} else { | |||||
$content_text = $content->getContent(); | |||||
$draft_note = null; | |||||
} | |||||
require_celerity_resource('phriction-document-css'); | require_celerity_resource('phriction-document-css'); | ||||
$e_title = true; | $e_title = true; | ||||
$e_content = true; | $e_content = true; | ||||
$validation_exception = null; | $validation_exception = null; | ||||
$notes = null; | $notes = null; | ||||
$title = $content->getTitle(); | $title = $content->getTitle(); | ||||
$overwrite = false; | $overwrite = false; | ||||
$v_cc = PhabricatorSubscribersQuery::loadSubscribersForPHID( | $v_cc = PhabricatorSubscribersQuery::loadSubscribersForPHID( | ||||
$document->getPHID()); | $document->getPHID()); | ||||
if ($is_new) { | if ($is_new) { | ||||
$v_projects = array(); | $v_projects = array(); | ||||
} else { | } else { | ||||
$v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs( | $v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs( | ||||
$document->getPHID(), | $document->getPHID(), | ||||
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); | PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); | ||||
$v_projects = array_reverse($v_projects); | $v_projects = array_reverse($v_projects); | ||||
} | } | ||||
$v_space = $document->getSpacePHID(); | $v_space = $document->getSpacePHID(); | ||||
$content_text = $content->getContent(); | |||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
$title = $request->getStr('title'); | $title = $request->getStr('title'); | ||||
$content_text = $request->getStr('content'); | $content_text = $request->getStr('content'); | ||||
$notes = $request->getStr('description'); | $notes = $request->getStr('description'); | ||||
$max_version = $request->getInt('contentVersion'); | $max_version = $request->getInt('contentVersion'); | ||||
$v_view = $request->getStr('viewPolicy'); | $v_view = $request->getStr('viewPolicy'); | ||||
$v_edit = $request->getStr('editPolicy'); | $v_edit = $request->getStr('editPolicy'); | ||||
Show All 34 Lines | if ($request->isFormPost()) { | ||||
->setContinueOnNoEffect(true) | ->setContinueOnNoEffect(true) | ||||
->setDescription($notes) | ->setDescription($notes) | ||||
->setProcessContentVersionError(!$request->getBool('overwrite')) | ->setProcessContentVersionError(!$request->getBool('overwrite')) | ||||
->setContentVersion($max_version); | ->setContentVersion($max_version); | ||||
try { | try { | ||||
$editor->applyTransactions($document, $xactions); | $editor->applyTransactions($document, $xactions); | ||||
if ($draft) { | |||||
$draft->delete(); | |||||
} | |||||
$uri = PhrictionDocument::getSlugURI($document->getSlug()); | $uri = PhrictionDocument::getSlugURI($document->getSlug()); | ||||
return id(new AphrontRedirectResponse())->setURI($uri); | return id(new AphrontRedirectResponse())->setURI($uri); | ||||
} catch (PhabricatorApplicationTransactionValidationException $ex) { | } catch (PhabricatorApplicationTransactionValidationException $ex) { | ||||
$validation_exception = $ex; | $validation_exception = $ex; | ||||
$e_title = nonempty( | $e_title = nonempty( | ||||
$ex->getShortMessage( | $ex->getShortMessage( | ||||
PhrictionDocumentTitleTransaction::TRANSACTIONTYPE), | PhrictionDocumentTitleTransaction::TRANSACTIONTYPE), | ||||
true); | true); | ||||
Show All 38 Lines | $policies = id(new PhabricatorPolicyQuery()) | ||||
->execute(); | ->execute(); | ||||
$view_capability = PhabricatorPolicyCapability::CAN_VIEW; | $view_capability = PhabricatorPolicyCapability::CAN_VIEW; | ||||
$edit_capability = PhabricatorPolicyCapability::CAN_EDIT; | $edit_capability = PhabricatorPolicyCapability::CAN_EDIT; | ||||
$form = id(new AphrontFormView()) | $form = id(new AphrontFormView()) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->addHiddenInput('slug', $document->getSlug()) | ->addHiddenInput('slug', $document->getSlug()) | ||||
->addHiddenInput('nodraft', $request->getBool('nodraft')) | |||||
->addHiddenInput('contentVersion', $max_version) | ->addHiddenInput('contentVersion', $max_version) | ||||
->addHiddenInput('overwrite', $overwrite) | ->addHiddenInput('overwrite', $overwrite) | ||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormTextControl()) | id(new AphrontFormTextControl()) | ||||
->setLabel(pht('Title')) | ->setLabel(pht('Title')) | ||||
->setValue($title) | ->setValue($title) | ||||
->setError($e_title) | ->setError($e_title) | ||||
->setName('title')) | ->setName('title')) | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | public function handleRequest(AphrontRequest $request) { | ||||
} else { | } else { | ||||
$crumbs->addTextCrumb(pht('Create')); | $crumbs->addTextCrumb(pht('Create')); | ||||
} | } | ||||
$crumbs->setBorder(true); | $crumbs->setBorder(true); | ||||
$view = id(new PHUITwoColumnView()) | $view = id(new PHUITwoColumnView()) | ||||
->setFooter( | ->setFooter( | ||||
array( | array( | ||||
$draft_note, | |||||
$form_box, | $form_box, | ||||
$preview, | $preview, | ||||
)); | )); | ||||
return $this->newPage() | return $this->newPage() | ||||
->setTitle($page_title) | ->setTitle($page_title) | ||||
->setCrumbs($crumbs) | ->setCrumbs($crumbs) | ||||
->appendChild($view); | ->appendChild($view); | ||||
} | } | ||||
} | } |