mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-25 08:12:40 +01:00
9084f1fe8c
Summary: we were just checking if projects/ was in the URI before barfing. Use some more fun utility functions such that we only complain if there is no project. Fixes T4071. Test Plan: made a subpage under a project - success! tried to make a project wiki page where there was no project - successful failure! tried to make a project wiki sub page where there was no project - successful failure! Reviewers: epriestley, chad Reviewed By: epriestley CC: Korvin, epriestley, aran Maniphest Tasks: T4071 Differential Revision: https://secure.phabricator.com/D7527
85 lines
2.7 KiB
PHP
85 lines
2.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group phriction
|
|
*/
|
|
final class PhrictionNewController extends PhrictionController {
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
$user = $request->getUser();
|
|
$slug = PhabricatorSlug::normalize($request->getStr('slug'));
|
|
|
|
if ($request->isFormPost()) {
|
|
$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);
|
|
} else if (PhrictionDocument::isProjectSlug($slug)) {
|
|
$project = id(new PhabricatorProjectQuery())
|
|
->setViewer($user)
|
|
->withPhrictionSlugs(array(
|
|
PhrictionDocument::getProjectSlugIdentifier($slug)))
|
|
->executeOne();
|
|
if (!$project) {
|
|
$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);
|
|
}
|
|
}
|
|
|
|
$uri = '/phriction/edit/?slug='.$slug;
|
|
return id(new AphrontRedirectResponse())
|
|
->setURI($uri);
|
|
}
|
|
|
|
if ($slug == '/') {
|
|
$slug = '';
|
|
}
|
|
|
|
$view = id(new PHUIFormLayoutView())
|
|
->appendChild(id(new AphrontFormTextControl())
|
|
->setLabel('/w/')
|
|
->setValue($slug)
|
|
->setName('slug'));
|
|
|
|
$dialog = id(new AphrontDialogView())
|
|
->setUser($user)
|
|
->setTitle(pht('New Document'))
|
|
->setSubmitURI('/phriction/new/')
|
|
->appendChild(phutil_tag('p',
|
|
array(),
|
|
pht('Create a new document at')))
|
|
->appendChild($view)
|
|
->addSubmitButton(pht('Create'))
|
|
->addCancelButton('/w/');
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
}
|
|
|
|
}
|