Pastebin
Summary: This is Paste. It needs some work, but epriestley recommended that I just commit something that works, and expand on that later. Specifically, it lacks the ability to view a raw paste right now, and to turn off line numbers, making it hard to copy/paste from for now. It works for showing other people code, however. Test Plan: Pasted stuff, and was able to view it, and see it in the list on /paste/. Put a file extension in the title, and saw that syntax highlighting worked as expected. Reviewers: epriestley CC: Differential Revision: 424
This commit is contained in:
@@ -22,6 +22,43 @@ class PhabricatorPasteCreateController extends PhabricatorPasteController {
|
||||
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
$paste = new PhabricatorPaste();
|
||||
|
||||
$error_view = null;
|
||||
$e_text = true;
|
||||
|
||||
if ($request->isFormPost()) {
|
||||
$errors = array();
|
||||
$title = $request->getStr('title');
|
||||
$text = $request->getStr('text');
|
||||
|
||||
if (!strlen($text)) {
|
||||
$e_text = 'Required';
|
||||
$errors[] = 'The paste may not be blank.';
|
||||
} else {
|
||||
$e_text = null;
|
||||
}
|
||||
|
||||
$paste->setTitle($title);
|
||||
|
||||
if (!$errors) {
|
||||
$paste_file = PhabricatorFile::newFromFileData(
|
||||
$text,
|
||||
array(
|
||||
'name' => $title,
|
||||
));
|
||||
$paste->setFilePHID($paste_file->getPHID());
|
||||
$paste->setAuthorPHID($user->getPHID());
|
||||
$paste->save();
|
||||
|
||||
return id(new AphrontRedirectResponse())
|
||||
->setURI('/P'.$paste->getID());
|
||||
} else {
|
||||
$error_view = new AphrontErrorView();
|
||||
$error_view->setErrors($errors);
|
||||
$error_view->setTitle('A problem has occurred!');
|
||||
}
|
||||
}
|
||||
|
||||
$form = new AphrontFormView();
|
||||
$form
|
||||
@@ -30,26 +67,31 @@ class PhabricatorPasteCreateController extends PhabricatorPasteController {
|
||||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
->setLabel('Title')
|
||||
->setValue($paste->getTitle())
|
||||
->setName('title'))
|
||||
->appendChild(
|
||||
id(new AphrontFormTextAreaControl())
|
||||
->setLabel('Text')
|
||||
->setError($e_text)
|
||||
->setName('text'))
|
||||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->addCancelButton('/paste/')
|
||||
->setValue('Create Paste'));
|
||||
|
||||
id(new AphrontFormSubmitControl())
|
||||
->addCancelButton('/paste/')
|
||||
->setValue('Create Paste'));
|
||||
|
||||
$panel = new AphrontPanelView();
|
||||
$panel->setWidth(AphrontPanelView::WIDTH_FULL);
|
||||
$panel->setHeader("Create a Paste");
|
||||
$panel->setWidth(AphrontPanelView::WIDTH_FORM);
|
||||
$panel->setHeader('Create a Paste');
|
||||
$panel->appendChild($form);
|
||||
|
||||
return $this->buildStandardPageResponse(
|
||||
$panel,
|
||||
array(
|
||||
$error_view,
|
||||
$panel,
|
||||
),
|
||||
array(
|
||||
'title' => 'Paste Creation',
|
||||
'tab' => 'create',
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user