@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
at upstream/main 59 lines 1.8 kB view raw
1<?php 2 3final class PhrictionNewController extends PhrictionController { 4 5 public function handleRequest(AphrontRequest $request) { 6 $viewer = $request->getViewer(); 7 $slug = PhabricatorSlug::normalize($request->getStr('slug')); 8 9 if ($request->isFormPost()) { 10 $document = id(new PhrictionDocumentQuery()) 11 ->setViewer($viewer) 12 ->withSlugs(array($slug)) 13 ->executeOne(); 14 $prompt = $request->getStr('prompt', 'no'); 15 $document_exists = $document && $document->getStatus() == 16 PhrictionDocumentStatus::STATUS_EXISTS; 17 18 if ($document_exists && $prompt == 'no') { 19 return $this->newDialog() 20 ->setSubmitURI('/phriction/new/') 21 ->setTitle(pht('Edit Existing Document?')) 22 ->setUser($viewer) 23 ->appendChild(pht( 24 'The document %s already exists. Do you want to edit it instead?', 25 phutil_tag('tt', array(), $slug))) 26 ->addHiddenInput('slug', $slug) 27 ->addHiddenInput('prompt', 'yes') 28 ->addCancelButton('/w/') 29 ->addSubmitButton(pht('Edit Document')); 30 } 31 32 $uri = '/phriction/edit/?slug='.$slug; 33 return id(new AphrontRedirectResponse()) 34 ->setURI($uri); 35 } 36 37 if ($slug == '/') { 38 $slug = ''; 39 } 40 41 $view = id(new PHUIFormLayoutView()) 42 ->appendChild(id(new AphrontFormTextControl()) 43 ->setLabel('/w/') 44 ->setValue($slug) 45 ->setName('slug')); 46 47 return $this->newDialog() 48 ->setTitle(pht('New Document')) 49 ->setSubmitURI('/phriction/new/') 50 ->appendChild(phutil_tag('p', 51 array(), 52 pht('Create a new document at'))) 53 ->appendChild($view) 54 ->addSubmitButton(pht('Create')) 55 ->addCancelButton('/w/'); 56 57 } 58 59}