From 4b6c81a23c4ec094bd7c798ab44e3c9d4e1502a9 Mon Sep 17 00:00:00 2001 From: Anh Nhan Nguyen Date: Wed, 13 Mar 2013 07:39:46 -0700 Subject: [PATCH] adding a warning upon 'creating' a new document on an existing page Summary: don't remember what I changed except for add that intermediate dialog Test Plan: {F35155} Ugly, ain't it? you can edit instead, or admit that it was a mistake to take on Phriction's existing documents Reviewers: epriestley, chad, btrahan Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2686 Differential Revision: https://secure.phabricator.com/D5295 --- .../controller/PhrictionNewController.php | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/applications/phriction/controller/PhrictionNewController.php b/src/applications/phriction/controller/PhrictionNewController.php index 934b41375b..1d9a3b5b82 100644 --- a/src/applications/phriction/controller/PhrictionNewController.php +++ b/src/applications/phriction/controller/PhrictionNewController.php @@ -12,9 +12,32 @@ final class PhrictionNewController extends PhrictionController { $slug = PhabricatorSlug::normalize($request->getStr('slug')); if ($request->isFormPost()) { - $uri = '/phriction/edit/?slug='.$slug; - return id(new AphrontRedirectResponse()) - ->setURI($uri); + $document = id(new PhrictionDocument())->loadOneWhere( + 'slug = %s', + $slug); + $prompt = $request->getStr('prompt', 'no'); + $document_exists = $document && $document->getStatus() == + PhrictionDocumentStatus::STATUS_EXISTS; + + if ($document_exists && $prompt == 'no') { + $dialog = new AphrontDialogView(); + $dialog->setSubmitURI('/phriction/new/') + ->setTitle(pht('Edit Existing Document?')) + ->setUser($user) + ->appendChild(pht( + 'The document %s already exists. Do you want to edit it instead?', + hsprintf('%s', $slug))) + ->addHiddenInput('slug', $slug) + ->addHiddenInput('prompt', 'yes') + ->addCancelButton('/w/') + ->addSubmitButton(pht('Edit Document')); + + return id(new AphrontDialogResponse())->setDialog($dialog); + } else { + $uri = '/phriction/edit/?slug='.$slug; + return id(new AphrontRedirectResponse()) + ->setURI($uri); + } } if ($slug == '/') {