2012-11-10 00:08:37 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhrictionNewController extends PhrictionController {
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
2013-03-07 17:12:00 +01:00
|
|
|
$slug = PhabricatorSlug::normalize($request->getStr('slug'));
|
2012-11-10 00:08:37 +01:00
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
2014-05-19 21:41:12 +02:00
|
|
|
$document = id(new PhrictionDocumentQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withSlugs(array($slug))
|
|
|
|
->executeOne();
|
2013-03-13 15:39:46 +01:00
|
|
|
$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?',
|
2013-11-11 18:23:23 +01:00
|
|
|
phutil_tag('tt', array(), $slug)))
|
2013-03-13 15:39:46 +01:00
|
|
|
->addHiddenInput('slug', $slug)
|
|
|
|
->addHiddenInput('prompt', 'yes')
|
|
|
|
->addCancelButton('/w/')
|
|
|
|
->addSubmitButton(pht('Edit Document'));
|
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
2013-11-07 21:06:42 +01:00
|
|
|
} else if (PhrictionDocument::isProjectSlug($slug)) {
|
|
|
|
$project = id(new PhabricatorProjectQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withPhrictionSlugs(array(
|
|
|
|
PhrictionDocument::getProjectSlugIdentifier($slug)))
|
|
|
|
->executeOne();
|
|
|
|
if (!$project) {
|
2013-09-06 19:42:02 +02:00
|
|
|
$dialog = new AphrontDialogView();
|
|
|
|
$dialog->setSubmitURI('/w/')
|
|
|
|
->setTitle(pht('Oops!'))
|
|
|
|
->setUser($user)
|
|
|
|
->appendChild(pht(
|
|
|
|
'You cannot create wiki pages under "projects/",
|
|
|
|
because they are reserved as project pages.
|
|
|
|
Create a new project with this name first.'))
|
|
|
|
->addCancelButton('/w/', 'Okay');
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
2013-11-07 21:06:42 +01:00
|
|
|
}
|
2013-03-13 15:39:46 +01:00
|
|
|
}
|
2013-11-07 21:06:42 +01:00
|
|
|
|
|
|
|
$uri = '/phriction/edit/?slug='.$slug;
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI($uri);
|
2012-11-10 00:08:37 +01:00
|
|
|
}
|
|
|
|
|
2013-03-07 17:12:00 +01:00
|
|
|
if ($slug == '/') {
|
|
|
|
$slug = '';
|
|
|
|
}
|
|
|
|
|
2013-08-26 20:53:11 +02:00
|
|
|
$view = id(new PHUIFormLayoutView())
|
2012-11-10 00:08:37 +01:00
|
|
|
->appendChild(id(new AphrontFormTextControl())
|
|
|
|
->setLabel('/w/')
|
2013-03-07 17:12:00 +01:00
|
|
|
->setValue($slug)
|
2012-11-10 00:08:37 +01:00
|
|
|
->setName('slug'));
|
|
|
|
|
|
|
|
$dialog = id(new AphrontDialogView())
|
|
|
|
->setUser($user)
|
|
|
|
->setTitle(pht('New Document'))
|
2013-03-07 17:12:00 +01:00
|
|
|
->setSubmitURI('/phriction/new/')
|
2013-01-18 04:15:06 +01:00
|
|
|
->appendChild(phutil_tag('p',
|
2012-11-10 00:08:37 +01:00
|
|
|
array(),
|
2013-03-07 17:12:00 +01:00
|
|
|
pht('Create a new document at')))
|
2012-11-10 00:08:37 +01:00
|
|
|
->appendChild($view)
|
|
|
|
->addSubmitButton(pht('Create'))
|
2013-01-11 20:58:31 +01:00
|
|
|
->addCancelButton('/w/');
|
2012-11-10 00:08:37 +01:00
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|