@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final 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_DEPRECATED;
15 }
16
17 public function getMethodStatusDescription() {
18 return pht(
19 'This method has been deprecated since %s in favor of %s.',
20 '10/2025',
21 'paste.edit');
22 }
23
24 protected function defineParamTypes() {
25 return array(
26 'content' => 'required string',
27 'title' => 'optional string',
28 'language' => 'optional string',
29 );
30 }
31
32 protected function defineReturnType() {
33 return 'nonempty dict';
34 }
35
36 protected function defineErrorTypes() {
37 return array(
38 'ERR-NO-PASTE' => pht('Paste may not be empty.'),
39 );
40 }
41
42 protected function execute(ConduitAPIRequest $request) {
43 $content = $request->getValue('content');
44 $title = $request->getValue('title');
45 $language = $request->getValue('language');
46
47 if (!phutil_nonempty_string($content)) {
48 throw new ConduitException('ERR-NO-PASTE');
49 }
50
51 $title = nonempty($title, pht('Masterwork From Distant Lands'));
52 $language = nonempty($language, '');
53
54 $viewer = $request->getUser();
55
56 $paste = PhabricatorPaste::initializeNewPaste($viewer);
57
58 $xactions = array();
59
60 $xactions[] = id(new PhabricatorPasteTransaction())
61 ->setTransactionType(PhabricatorPasteContentTransaction::TRANSACTIONTYPE)
62 ->setNewValue($content);
63
64 $xactions[] = id(new PhabricatorPasteTransaction())
65 ->setTransactionType(PhabricatorPasteTitleTransaction::TRANSACTIONTYPE)
66 ->setNewValue($title);
67
68 if (strlen($language)) {
69 $xactions[] = id(new PhabricatorPasteTransaction())
70 ->setTransactionType(
71 PhabricatorPasteLanguageTransaction::TRANSACTIONTYPE)
72 ->setNewValue($language);
73 }
74
75 $editor = id(new PhabricatorPasteEditor())
76 ->setActor($viewer)
77 ->setContinueOnNoEffect(true)
78 ->setContentSource($request->newContentSource());
79
80 $xactions = $editor->applyTransactions($paste, $xactions);
81
82 $paste->attachRawContent($content);
83 return $this->buildPasteInfoDictionary($paste);
84 }
85
86}