getRequest(); $user = $request->getUser(); $paste = new PhabricatorPaste(); $error_view = null; $e_text = true; $paste_text = null; 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, 'mime-type' => 'text/plain; charset=utf-8', )); $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!'); } } else { $copy = $request->getInt('copy'); if ($copy) { $copy_paste = id(new PhabricatorPaste())->load($copy); if ($copy_paste) { $title = nonempty($copy_paste->getTitle(), 'P'.$copy_paste->getID()); $paste->setTitle('Copy of '.$title); $copy_file = id(new PhabricatorFile())->loadOneWhere( 'phid = %s', $copy_paste->getFilePHID()); $paste_text = $copy_file->loadFileData(); } } } $form = new AphrontFormView(); $form ->setUser($user) ->setAction($request->getRequestURI()->getPath()) ->appendChild( id(new AphrontFormTextControl()) ->setLabel('Title') ->setValue($paste->getTitle()) ->setName('title')) ->appendChild( id(new AphrontFormTextAreaControl()) ->setLabel('Text') ->setError($e_text) ->setValue($paste_text) ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL) ->setName('text')) ->appendChild( id(new AphrontFormSubmitControl()) ->addCancelButton('/paste/') ->setValue('Create Paste')); $panel = new AphrontPanelView(); $panel->setWidth(AphrontPanelView::WIDTH_FORM); $panel->setHeader('Create a Paste'); $panel->appendChild($form); return $this->buildStandardPageResponse( array( $error_view, $panel, ), array( 'title' => 'Paste Creation', 'tab' => 'create', )); } }