1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-21 13:00:56 +01:00

Merge pull request #37 from CodeBlock/master

D672.
This commit is contained in:
Evan Priestley 2011-07-15 17:46:01 -07:00
commit 0bf6766089
5 changed files with 76 additions and 32 deletions

View file

@ -0,0 +1,3 @@
ALTER TABLE phabricator_pastebin.pastebin_paste
ADD COLUMN parentPHID VARCHAR(64) BINARY,
ADD KEY (parentPHID);

View file

@ -27,19 +27,16 @@ class PhabricatorPasteCreateController extends PhabricatorPasteController {
$error_view = null; $error_view = null;
$e_text = true; $e_text = true;
$fork = $request->getInt('fork');
$paste_text = null; $paste_text = null;
$paste_parent = null;
if ($request->isFormPost()) { if ($request->isFormPost()) {
$errors = array(); $errors = array();
$title = $request->getStr('title'); $title = $request->getStr('title');
$language = $request->getStr('language'); $paste_language = $request->getStr('language');
if ($language == 'infer') {
// If it's infer, store an empty string. Otherwise, store the
// language name. We do this so we can refer to 'infer' elsewhere
// in the code (such as default value) while retaining backwards
// compatibility with old posts with no language stored.
$language = '';
}
$text = $request->getStr('text'); $text = $request->getStr('text');
@ -50,10 +47,26 @@ class PhabricatorPasteCreateController extends PhabricatorPasteController {
$e_text = null; $e_text = null;
} }
$parent = id(new PhabricatorPaste())->loadOneWhere(
'phid = %s',
$request->getStr('parent'));
if ($parent) {
$paste->setParentPHID($parent->getPHID());
}
$paste->setTitle($title); $paste->setTitle($title);
$paste->setLanguage($language);
if (!$errors) { if (!$errors) {
if ($paste_language == 'infer') {
// If it's infer, store an empty string. Otherwise, store the
// language name. We do this so we can refer to 'infer' elsewhere
// in the code (such as default value) while retaining backwards
// compatibility with old posts with no language stored.
$paste_language = '';
}
$paste->setLanguage($paste_language);
$paste_file = PhabricatorFile::newFromFileData( $paste_file = PhabricatorFile::newFromFileData(
$text, $text,
array( array(
@ -73,31 +86,26 @@ class PhabricatorPasteCreateController extends PhabricatorPasteController {
$error_view->setTitle('A problem has occurred!'); $error_view->setTitle('A problem has occurred!');
} }
} else { } else {
$copy = $request->getInt('copy'); if ($fork) {
if ($copy) { $fork_paste = id(new PhabricatorPaste())->load($fork);
$copy_paste = id(new PhabricatorPaste())->load($copy); if ($fork_paste) {
if ($copy_paste) { $paste->setTitle('Fork of '.$fork_paste->getID().': '.
$title = nonempty($copy_paste->getTitle(), 'P'.$copy_paste->getID()); $fork_paste->getTitle());
$paste->setTitle('Copy of '.$title); $fork_file = id(new PhabricatorFile())->loadOneWhere(
$copy_file = id(new PhabricatorFile())->loadOneWhere(
'phid = %s', 'phid = %s',
$copy_paste->getFilePHID()); $fork_paste->getFilePHID());
$paste_text = $copy_file->loadFileData(); $paste_text = $fork_file->loadFileData();
$paste_language = nonempty($fork_paste->getLanguage(), 'infer');
$paste_parent = $fork_paste->getPHID();
} }
} else {
$paste_language = PhabricatorEnv::getEnvConfig(
'pygments.dropdown-default');
} }
} }
$form = new AphrontFormView(); $form = new AphrontFormView();
// If we're coming back from an error and the language was already defined,
// use that. Otherwise, ask the config for the default.
if ($paste->getLanguage()) {
$language_default = $paste->getLanguage();
} else {
$language_default = PhabricatorEnv::getEnvConfig(
'pygments.dropdown-default');
}
$available_languages = PhabricatorEnv::getEnvConfig( $available_languages = PhabricatorEnv::getEnvConfig(
'pygments.dropdown-choices'); 'pygments.dropdown-choices');
asort($available_languages); asort($available_languages);
@ -105,12 +113,13 @@ class PhabricatorPasteCreateController extends PhabricatorPasteController {
$language_select = id(new AphrontFormSelectControl()) $language_select = id(new AphrontFormSelectControl())
->setLabel('Language') ->setLabel('Language')
->setName('language') ->setName('language')
->setValue($language_default) ->setValue($paste_language)
->setOptions($available_languages); ->setOptions($available_languages);
$form $form
->setUser($user) ->setUser($user)
->setAction($request->getRequestURI()->getPath()) ->setAction($request->getRequestURI()->getPath())
->addHiddenInput('parent', $paste_parent)
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
->setLabel('Title') ->setLabel('Title')
@ -127,7 +136,7 @@ class PhabricatorPasteCreateController extends PhabricatorPasteController {
->appendChild( ->appendChild(
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->addCancelButton('/paste/') ->addCancelButton('/paste/')
->setValue('Create Paste')); ->setValue('Create Paste'));
$panel = new AphrontPanelView(); $panel = new AphrontPanelView();
$panel->setWidth(AphrontPanelView::WIDTH_FORM); $panel->setWidth(AphrontPanelView::WIDTH_FORM);

View file

@ -42,7 +42,6 @@ class PhabricatorPasteViewController extends PhabricatorPasteController {
} }
$corpus = $this->buildCorpus($paste, $file); $corpus = $this->buildCorpus($paste, $file);
$panel = new AphrontPanelView(); $panel = new AphrontPanelView();
if (strlen($paste->getTitle())) { if (strlen($paste->getTitle())) {
@ -58,10 +57,10 @@ class PhabricatorPasteViewController extends PhabricatorPasteController {
phutil_render_tag( phutil_render_tag(
'a', 'a',
array( array(
'href' => '/paste/?copy='.$paste->getID(), 'href' => '/paste/?fork='.$paste->getID(),
'class' => 'green button', 'class' => 'green button',
), ),
'Copy This')); 'Fork This'));
$raw_uri = PhabricatorFileURI::getViewURIForPHID($paste->getFilePHID()); $raw_uri = PhabricatorFileURI::getViewURIForPHID($paste->getFilePHID());
$panel->addButton( $panel->addButton(
@ -75,6 +74,37 @@ class PhabricatorPasteViewController extends PhabricatorPasteController {
$panel->appendChild($corpus); $panel->appendChild($corpus);
$forks_of_this_paste = id(new PhabricatorPaste())->loadAllWhere(
'parentPHID = %s',
$paste->getPHID());
if ($forks_of_this_paste) {
$forks = array();
foreach ($forks_of_this_paste as $fork) {
$forks[] = array(
$fork->getID(),
phutil_render_tag(
'a',
array(
'href' => '/P'.$fork->getID(),
),
phutil_escape_html($fork->getTitle())
)
);
}
$forks_table = new AphrontTableView($forks);
$forks_table->setHeaders(
array(
'Paste ID',
'Title',
)
);
$panel->setHeader("Forks of this Paste");
$panel->appendChild($forks_table);
}
return $this->buildStandardPageResponse( return $this->buildStandardPageResponse(
$panel, $panel,
array( array(

View file

@ -14,6 +14,7 @@ phutil_require_module('phabricator', 'applications/markup/syntax');
phutil_require_module('phabricator', 'applications/paste/controller/base'); phutil_require_module('phabricator', 'applications/paste/controller/base');
phutil_require_module('phabricator', 'applications/paste/storage/paste'); phutil_require_module('phabricator', 'applications/paste/storage/paste');
phutil_require_module('phabricator', 'infrastructure/celerity/api'); phutil_require_module('phabricator', 'infrastructure/celerity/api');
phutil_require_module('phabricator', 'view/control/table');
phutil_require_module('phabricator', 'view/layout/panel'); phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phutil', 'markup'); phutil_require_module('phutil', 'markup');

View file

@ -23,6 +23,7 @@ class PhabricatorPaste extends PhabricatorPasteDAO {
protected $authorPHID; protected $authorPHID;
protected $filePHID; protected $filePHID;
protected $language; protected $language;
protected $parentPHID;
public function getConfiguration() { public function getConfiguration() {
return array( return array(