Skip to content

Commit fed30df

Browse files
author
epriestley
committed
Split paste create/edit and list views
Summary: We have this hybrid "create / last few pastes" landing screen right now but I ~never use the list at the bottom and it makes the controller kind of complicated. I want to let you edit pastes too, and this generally simplifies things. Also makes the textarea monospaced and cleans up the fork logic a bit. Test Plan: Created, forked pastes. Viewed paste lists. Viewed pastes. Reviewers: vrana, btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T1690 Differential Revision: https://secure.phabricator.com/D3375
1 parent d9a133d commit fed30df

File tree

10 files changed

+194
-249
lines changed

10 files changed

+194
-249
lines changed

conf/default.conf.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,6 @@
11961196
'erb' => 'Embedded Ruby/ERB',
11971197
'erlang' => 'Erlang',
11981198
'html' => 'HTML',
1199-
'infer' => 'Infer from title (extension)',
12001199
'java' => 'Java',
12011200
'js' => 'Javascript',
12021201
'mysql' => 'MySQL',
@@ -1210,8 +1209,6 @@
12101209
'xml' => 'XML',
12111210
),
12121211

1213-
'pygments.dropdown-default' => 'infer',
1214-
12151212
// This is an override list of regular expressions which allows you to choose
12161213
// what language files are highlighted as. If your projects have certain rules
12171214
// about filenames or use unusual or ambiguous language extensions, you can

src/__phutil_library_map__.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,7 @@
892892
'PhabricatorPaste' => 'applications/paste/storage/PhabricatorPaste.php',
893893
'PhabricatorPasteController' => 'applications/paste/controller/PhabricatorPasteController.php',
894894
'PhabricatorPasteDAO' => 'applications/paste/storage/PhabricatorPasteDAO.php',
895+
'PhabricatorPasteEditController' => 'applications/paste/controller/PhabricatorPasteEditController.php',
895896
'PhabricatorPasteListController' => 'applications/paste/controller/PhabricatorPasteListController.php',
896897
'PhabricatorPasteQuery' => 'applications/paste/query/PhabricatorPasteQuery.php',
897898
'PhabricatorPasteViewController' => 'applications/paste/controller/PhabricatorPasteViewController.php',
@@ -1992,6 +1993,7 @@
19921993
),
19931994
'PhabricatorPasteController' => 'PhabricatorController',
19941995
'PhabricatorPasteDAO' => 'PhabricatorLiskDAO',
1996+
'PhabricatorPasteEditController' => 'PhabricatorPasteController',
19951997
'PhabricatorPasteListController' => 'PhabricatorPasteController',
19961998
'PhabricatorPasteQuery' => 'PhabricatorCursorPagedPolicyQuery',
19971999
'PhabricatorPasteViewController' => 'PhabricatorPasteController',

src/applications/paste/application/PhabricatorApplicationPaste.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function getRoutes() {
3434
return array(
3535
'/P(?P<id>\d+)' => 'PhabricatorPasteViewController',
3636
'/paste/' => array(
37-
'' => 'PhabricatorPasteListController',
37+
'' => 'PhabricatorPasteEditController',
3838
'filter/(?P<filter>\w+)/' => 'PhabricatorPasteListController',
3939
),
4040
);

src/applications/paste/controller/PhabricatorPasteController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function buildSideNavView(PhabricatorPaste $paste = null) {
2828
}
2929

3030
$nav->addLabel('Create');
31-
$nav->addFilter('create', 'New Paste');
31+
$nav->addFilter('edit', 'New Paste', $this->getApplicationURI());
3232

3333
$nav->addSpacer();
3434
$nav->addLabel('Pastes');
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2012 Facebook, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
final class PhabricatorPasteEditController extends PhabricatorPasteController {
20+
21+
public function processRequest() {
22+
$request = $this->getRequest();
23+
$user = $request->getUser();
24+
25+
$paste = new PhabricatorPaste();
26+
$title = 'Create Paste';
27+
28+
$parent_id = $request->getStr('parent');
29+
$parent = null;
30+
if ($parent_id) {
31+
// NOTE: If the Paste is forked from a paste which the user no longer
32+
// has permission to see, we still let them edit it.
33+
$parent = id(new PhabricatorPasteQuery())
34+
->setViewer($user)
35+
->withIDs(array($parent_id))
36+
->execute();
37+
$parent = head($parent);
38+
39+
if ($parent) {
40+
$paste->setParentPHID($parent->getPHID());
41+
}
42+
}
43+
44+
$text = null;
45+
$e_text = true;
46+
$errors = array();
47+
if ($request->isFormPost()) {
48+
$text = $request->getStr('text');
49+
if (!strlen($text)) {
50+
$e_text = 'Required';
51+
$errors[] = 'The paste may not be blank.';
52+
} else {
53+
$e_text = null;
54+
}
55+
56+
$paste->setTitle($request->getStr('title'));
57+
$paste->setLanguage($request->getStr('language'));
58+
59+
if (!$errors) {
60+
$paste_file = PhabricatorFile::newFromFileData(
61+
$text,
62+
array(
63+
'name' => $title,
64+
'mime-type' => 'text/plain; charset=utf-8',
65+
'authorPHID' => $user->getPHID(),
66+
));
67+
$paste->setFilePHID($paste_file->getPHID());
68+
$paste->setAuthorPHID($user->getPHID());
69+
$paste->save();
70+
71+
return id(new AphrontRedirectResponse())->setURI($paste->getURI());
72+
}
73+
} else {
74+
if ($parent) {
75+
$paste->setTitle('Fork of '.$parent->getFullName());
76+
$paste->setLanguage($parent->getLanguage());
77+
78+
$parent_file = id(new PhabricatorFile())->loadOneWhere(
79+
'phid = %s',
80+
$parent->getFilePHID());
81+
$text = $parent_file->loadFileData();
82+
}
83+
}
84+
85+
$error_view = null;
86+
if ($errors) {
87+
$error_view = id(new AphrontErrorView())
88+
->setTitle('A fatal omission!')
89+
->setErrors($errors);
90+
}
91+
92+
$form = new AphrontFormView();
93+
$form->setFlexible(true);
94+
95+
$langs = array(
96+
'' => '(Detect With Wizardly Powers)',
97+
) + PhabricatorEnv::getEnvConfig('pygments.dropdown-choices');
98+
99+
$submit = id(new AphrontFormSubmitControl())
100+
->setValue('Create Paste');
101+
102+
$form
103+
->setUser($user)
104+
->addHiddenInput('parent', $parent_id)
105+
->appendChild(
106+
id(new AphrontFormTextControl())
107+
->setLabel('Title')
108+
->setValue($paste->getTitle())
109+
->setName('title'))
110+
->appendChild(
111+
id(new AphrontFormSelectControl())
112+
->setLabel('Language')
113+
->setName('language')
114+
->setValue($paste->getLanguage())
115+
->setOptions($langs))
116+
->appendChild(
117+
id(new AphrontFormTextAreaControl())
118+
->setLabel('Text')
119+
->setError($e_text)
120+
->setValue($text)
121+
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
122+
->setCustomClass('PhabricatorMonospaced')
123+
->setName('text'))
124+
125+
/* TODO: Doesn't have any useful options yet.
126+
->appendChild(
127+
id(new AphrontFormPolicyControl())
128+
->setLabel('Visible To')
129+
->setUser($user)
130+
->setValue(
131+
$new_paste->getPolicy(PhabricatorPolicyCapability::CAN_VIEW))
132+
->setName('policy'))
133+
*/
134+
135+
->appendChild($submit);
136+
137+
$nav = $this->buildSideNavView();
138+
$nav->selectFilter('edit');
139+
$nav->appendChild(
140+
array(
141+
id(new PhabricatorHeaderView())->setHeader('Create Paste'),
142+
$error_view,
143+
$form,
144+
));
145+
146+
return $this->buildApplicationPage(
147+
$nav,
148+
array(
149+
'title' => $title,
150+
'device' => true,
151+
));
152+
}
153+
154+
}

0 commit comments

Comments
 (0)