Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/paste/conduit/PasteCreateConduitAPIMethod.php
12241 views
1
<?php
2
3
final class PasteCreateConduitAPIMethod extends PasteConduitAPIMethod {
4
5
public function getAPIMethodName() {
6
return 'paste.create';
7
}
8
9
public function getMethodDescription() {
10
return pht('Create a new paste.');
11
}
12
13
public function getMethodStatus() {
14
return self::METHOD_STATUS_FROZEN;
15
}
16
17
public function getMethodStatusDescription() {
18
return pht(
19
'This method is frozen and will eventually be deprecated. New code '.
20
'should use "paste.edit" instead.');
21
}
22
23
protected function defineParamTypes() {
24
return array(
25
'content' => 'required string',
26
'title' => 'optional string',
27
'language' => 'optional string',
28
);
29
}
30
31
protected function defineReturnType() {
32
return 'nonempty dict';
33
}
34
35
protected function defineErrorTypes() {
36
return array(
37
'ERR-NO-PASTE' => pht('Paste may not be empty.'),
38
);
39
}
40
41
protected function execute(ConduitAPIRequest $request) {
42
$content = $request->getValue('content');
43
$title = $request->getValue('title');
44
$language = $request->getValue('language');
45
46
if ($content === null || !strlen($content)) {
47
throw new ConduitException('ERR-NO-PASTE');
48
}
49
50
$title = nonempty($title, pht('Masterwork From Distant Lands'));
51
$language = nonempty($language, '');
52
53
$viewer = $request->getUser();
54
55
$paste = PhabricatorPaste::initializeNewPaste($viewer);
56
57
$xactions = array();
58
59
$xactions[] = id(new PhabricatorPasteTransaction())
60
->setTransactionType(PhabricatorPasteContentTransaction::TRANSACTIONTYPE)
61
->setNewValue($content);
62
63
$xactions[] = id(new PhabricatorPasteTransaction())
64
->setTransactionType(PhabricatorPasteTitleTransaction::TRANSACTIONTYPE)
65
->setNewValue($title);
66
67
if (strlen($language)) {
68
$xactions[] = id(new PhabricatorPasteTransaction())
69
->setTransactionType(
70
PhabricatorPasteLanguageTransaction::TRANSACTIONTYPE)
71
->setNewValue($language);
72
}
73
74
$editor = id(new PhabricatorPasteEditor())
75
->setActor($viewer)
76
->setContinueOnNoEffect(true)
77
->setContentSource($request->newContentSource());
78
79
$xactions = $editor->applyTransactions($paste, $xactions);
80
81
$paste->attachRawContent($content);
82
return $this->buildPasteInfoDictionary($paste);
83
}
84
85
}
86
87