@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 PhrictionContent
4 extends PhrictionDAO
5 implements
6 PhabricatorPolicyInterface,
7 PhabricatorDestructibleInterface,
8 PhabricatorConduitResultInterface {
9
10 protected $documentPHID;
11 protected $version;
12 protected $authorPHID;
13
14 protected $title;
15 protected $slug;
16 protected $content;
17 protected $description;
18
19 protected $changeType;
20 protected $changeRef;
21
22 private $document = self::ATTACHABLE;
23
24 protected function getConfiguration() {
25 return array(
26 self::CONFIG_AUX_PHID => true,
27 self::CONFIG_COLUMN_SCHEMA => array(
28 'version' => 'uint32',
29 'title' => 'sort',
30 'slug' => 'text128',
31 'content' => 'text',
32 'changeType' => 'uint32',
33 'changeRef' => 'uint32?',
34 'description' => 'text',
35 ),
36 self::CONFIG_KEY_SCHEMA => array(
37 'key_version' => array(
38 'columns' => array('documentPHID', 'version'),
39 'unique' => true,
40 ),
41 'authorPHID' => array(
42 'columns' => array('authorPHID'),
43 ),
44 'slug' => array(
45 'columns' => array('slug'),
46 ),
47 ),
48 ) + parent::getConfiguration();
49 }
50
51 public function getPHIDType() {
52 return PhrictionContentPHIDType::TYPECONST;
53 }
54
55 public function newRemarkupView(PhabricatorUser $viewer) {
56 return id(new PHUIRemarkupView($viewer, $this->getContent()))
57 ->setContextObject($this)
58 ->setRemarkupOption(PHUIRemarkupView::OPTION_GENERATE_TOC, true)
59 ->setGenerateTableOfContents(true);
60 }
61
62 public function attachDocument(PhrictionDocument $document) {
63 $this->document = $document;
64 return $this;
65 }
66
67 public function getDocument() {
68 return $this->assertAttached($this->document);
69 }
70
71
72/* -( PhabricatorPolicyInterface )----------------------------------------- */
73
74
75 public function getCapabilities() {
76 return array(
77 PhabricatorPolicyCapability::CAN_VIEW,
78 );
79 }
80
81 public function getPolicy($capability) {
82 return PhabricatorPolicies::getMostOpenPolicy();
83 }
84
85 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
86 return false;
87 }
88
89
90/* -( PhabricatorExtendedPolicyInterface )--------------------------------- */
91
92
93 public function getExtendedPolicy($capability, PhabricatorUser $viewer) {
94 return array(
95 array($this->getDocument(), PhabricatorPolicyCapability::CAN_VIEW),
96 );
97 }
98
99
100/* -( PhabricatorDestructibleInterface )----------------------------------- */
101
102
103 public function destroyObjectPermanently(
104 PhabricatorDestructionEngine $engine) {
105 $this->delete();
106 }
107
108
109/* -( PhabricatorConduitResultInterface )---------------------------------- */
110
111
112 public function getFieldSpecificationsForConduit() {
113 return array(
114 id(new PhabricatorConduitSearchFieldSpecification())
115 ->setKey('documentPHID')
116 ->setType('phid')
117 ->setDescription(pht('Document this content is for.')),
118 id(new PhabricatorConduitSearchFieldSpecification())
119 ->setKey('version')
120 ->setType('int')
121 ->setDescription(pht('Content version.')),
122 );
123 }
124
125 public function getFieldValuesForConduit() {
126 return array(
127 'documentPHID' => $this->getDocument()->getPHID(),
128 'version' => (int)$this->getVersion(),
129 );
130 }
131
132 public function getConduitSearchAttachments() {
133 return array(
134 id(new PhrictionContentSearchEngineAttachment())
135 ->setAttachmentKey('content'),
136 );
137 }
138
139}