~ubuntu-branches/ubuntu/wily/phabricator/wily

1 by Richard Sellam
Import upstream version 0~git20141023
1
<?php
2
3
final class DifferentialInlineComment
4
  implements PhabricatorInlineCommentInterface {
5
6
  private $proxy;
7
  private $syntheticAuthor;
0.15.2 by Richard Sellam
Import upstream version 0~git20150428
8
  private $isGhost;
1 by Richard Sellam
Import upstream version 0~git20141023
9
10
  public function __construct() {
11
    $this->proxy = new DifferentialTransactionComment();
12
  }
13
14
  public function __clone() {
15
    $this->proxy = clone $this->proxy;
16
  }
17
18
  public function getTransactionCommentForSave() {
19
    $content_source = PhabricatorContentSource::newForSource(
20
      PhabricatorContentSource::SOURCE_LEGACY,
21
      array());
22
23
    $this->proxy
24
      ->setViewPolicy('public')
25
      ->setEditPolicy($this->getAuthorPHID())
26
      ->setContentSource($content_source)
0.15.4 by Richard Sellam
Import upstream version 0~git20150613
27
      ->attachIsHidden(false)
1 by Richard Sellam
Import upstream version 0~git20141023
28
      ->setCommentVersion(1);
29
30
    return $this->proxy;
31
  }
32
33
  public function openTransaction() {
34
    $this->proxy->openTransaction();
35
  }
36
37
  public function saveTransaction() {
38
    $this->proxy->saveTransaction();
39
  }
40
41
  public function save() {
42
    $this->getTransactionCommentForSave()->save();
43
44
    return $this;
45
  }
46
47
  public function delete() {
48
    $this->proxy->delete();
49
50
    return $this;
51
  }
52
0.15.4 by Richard Sellam
Import upstream version 0~git20150613
53
  public function supportsHiding() {
54
    if ($this->getSyntheticAuthor()) {
55
      return false;
56
    }
57
    return true;
58
  }
59
60
  public function isHidden() {
61
    if (!$this->supportsHiding()) {
62
      return false;
63
    }
64
    return $this->proxy->getIsHidden();
65
  }
66
1 by Richard Sellam
Import upstream version 0~git20141023
67
  public function getID() {
68
    return $this->proxy->getID();
69
  }
70
71
  public function getPHID() {
72
    return $this->proxy->getPHID();
73
  }
74
75
  public static function newFromModernComment(
76
    DifferentialTransactionComment $comment) {
77
78
    $obj = new DifferentialInlineComment();
79
    $obj->proxy = $comment;
80
81
    return $obj;
82
  }
83
84
  public function setSyntheticAuthor($synthetic_author) {
85
    $this->syntheticAuthor = $synthetic_author;
86
    return $this;
87
  }
88
89
  public function getSyntheticAuthor() {
90
    return $this->syntheticAuthor;
91
  }
92
93
  public function isCompatible(PhabricatorInlineCommentInterface $comment) {
94
    return
95
      ($this->getAuthorPHID() === $comment->getAuthorPHID()) &&
96
      ($this->getSyntheticAuthor() === $comment->getSyntheticAuthor()) &&
97
      ($this->getContent() === $comment->getContent());
98
  }
99
100
  public function setContent($content) {
101
    $this->proxy->setContent($content);
102
    return $this;
103
  }
104
105
  public function getContent() {
106
    return $this->proxy->getContent();
107
  }
108
109
  public function isDraft() {
110
    return !$this->proxy->getTransactionPHID();
111
  }
112
113
  public function setChangesetID($id) {
114
    $this->proxy->setChangesetID($id);
115
    return $this;
116
  }
117
118
  public function getChangesetID() {
119
    return $this->proxy->getChangesetID();
120
  }
121
122
  public function setIsNewFile($is_new) {
123
    $this->proxy->setIsNewFile($is_new);
124
    return $this;
125
  }
126
127
  public function getIsNewFile() {
128
    return $this->proxy->getIsNewFile();
129
  }
130
131
  public function setLineNumber($number) {
132
    $this->proxy->setLineNumber($number);
133
    return $this;
134
  }
135
136
  public function getLineNumber() {
137
    return $this->proxy->getLineNumber();
138
  }
139
140
  public function setLineLength($length) {
141
    $this->proxy->setLineLength($length);
142
    return $this;
143
  }
144
145
  public function getLineLength() {
146
    return $this->proxy->getLineLength();
147
  }
148
149
  public function setCache($cache) {
150
    return $this;
151
  }
152
153
  public function getCache() {
154
    return null;
155
  }
156
157
  public function setAuthorPHID($phid) {
158
    $this->proxy->setAuthorPHID($phid);
159
    return $this;
160
  }
161
162
  public function getAuthorPHID() {
163
    return $this->proxy->getAuthorPHID();
164
  }
165
166
  public function setRevision(DifferentialRevision $revision) {
167
    $this->proxy->setRevisionPHID($revision->getPHID());
168
    return $this;
169
  }
170
171
  public function getRevisionPHID() {
172
    return $this->proxy->getRevisionPHID();
173
  }
174
175
  // Although these are purely transitional, they're also *extra* dumb.
176
177
  public function setRevisionID($revision_id) {
178
    $revision = id(new DifferentialRevision())->load($revision_id);
179
    return $this->setRevision($revision);
180
  }
181
182
  public function getRevisionID() {
183
    $phid = $this->proxy->getRevisionPHID();
184
    if (!$phid) {
185
      return null;
186
    }
187
188
    $revision = id(new DifferentialRevision())->loadOneWhere(
189
      'phid = %s',
190
      $phid);
191
    if (!$revision) {
192
      return null;
193
    }
194
    return $revision->getID();
195
  }
196
197
  // When setting a comment ID, we also generate a phantom transaction PHID for
198
  // the future transaction.
199
200
  public function setCommentID($id) {
201
    $this->proxy->setTransactionPHID(
202
      PhabricatorPHID::generateNewPHID(
203
        PhabricatorApplicationTransactionTransactionPHIDType::TYPECONST,
204
        DifferentialRevisionPHIDType::TYPECONST));
205
    return $this;
206
  }
207
0.15.2 by Richard Sellam
Import upstream version 0~git20150428
208
  public function setReplyToCommentPHID($phid) {
209
    $this->proxy->setReplyToCommentPHID($phid);
210
    return $this;
211
  }
212
213
  public function getReplyToCommentPHID() {
214
    return $this->proxy->getReplyToCommentPHID();
215
  }
216
217
  public function setHasReplies($has_replies) {
218
    $this->proxy->setHasReplies($has_replies);
219
    return $this;
220
  }
221
222
  public function getHasReplies() {
223
    return $this->proxy->getHasReplies();
224
  }
225
226
  public function setIsDeleted($is_deleted) {
227
    $this->proxy->setIsDeleted($is_deleted);
228
    return $this;
229
  }
230
231
  public function getIsDeleted() {
232
    return $this->proxy->getIsDeleted();
233
  }
234
235
  public function setFixedState($state) {
236
    $this->proxy->setFixedState($state);
237
    return $this;
238
  }
239
240
  public function getFixedState() {
241
    return $this->proxy->getFixedState();
242
  }
243
244
  public function setIsGhost($is_ghost) {
245
    $this->isGhost = $is_ghost;
246
    return $this;
247
  }
248
249
  public function getIsGhost() {
250
    return $this->isGhost;
251
  }
252
253
  public function makeEphemeral() {
254
    $this->proxy->makeEphemeral();
255
    return $this;
256
  }
257
258
1 by Richard Sellam
Import upstream version 0~git20141023
259
/* -(  PhabricatorMarkupInterface Implementation  )-------------------------- */
260
261
262
  public function getMarkupFieldKey($field) {
263
    // We can't use ID because synthetic comments don't have it.
264
    return 'DI:'.PhabricatorHash::digest($this->getContent());
265
  }
266
267
  public function newMarkupEngine($field) {
268
    return PhabricatorMarkupEngine::newDifferentialMarkupEngine();
269
  }
270
271
  public function getMarkupText($field) {
272
    return $this->getContent();
273
  }
274
275
  public function didMarkupText($field, $output, PhutilMarkupEngine $engine) {
276
    return $output;
277
  }
278
279
  public function shouldUseMarkupCache($field) {
280
    // Only cache submitted comments.
281
    return ($this->getID() && !$this->isDraft());
282
  }
283
284
}