2012-11-10 00:08:37 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group phriction
|
|
|
|
*/
|
|
|
|
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()) {
|
2013-03-13 15:39:46 +01:00
|
|
|
$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('<tt>%s</tt>', $slug)))
|
|
|
|
->addHiddenInput('slug', $slug)
|
|
|
|
->addHiddenInput('prompt', 'yes')
|
|
|
|
->addCancelButton('/w/')
|
|
|
|
->addSubmitButton(pht('Edit Document'));
|
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
2013-09-06 19:42:02 +02:00
|
|
|
} elseif (substr($slug, 0, 9) == 'projects/') {
|
|
|
|
$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-03-13 15:39:46 +01:00
|
|
|
} else {
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|