@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
3/**
4 * DEPRECATED. Use @{class:PHUIRemarkupView}.
5 */
6final class PhabricatorMarkupOneOff
7 extends Phobject
8 implements PhabricatorMarkupInterface {
9
10 private $content;
11 private $preserveLinebreaks;
12 private $engineRuleset;
13 private $engine;
14 private $disableCache;
15 private $contentCacheFragment;
16
17 private $generateTableOfContents;
18 private $tableOfContents;
19
20 public function setEngineRuleset($engine_ruleset) {
21 $this->engineRuleset = $engine_ruleset;
22 return $this;
23 }
24
25 public function getEngineRuleset() {
26 return $this->engineRuleset;
27 }
28
29 public function setPreserveLinebreaks($preserve_linebreaks) {
30 $this->preserveLinebreaks = $preserve_linebreaks;
31 return $this;
32 }
33
34 public function setContent($content) {
35 $this->content = $content;
36 return $this;
37 }
38
39 public function getContent() {
40 return $this->content;
41 }
42
43 public function setEngine(PhutilMarkupEngine $engine) {
44 $this->engine = $engine;
45 return $this;
46 }
47
48 public function getEngine() {
49 return $this->engine;
50 }
51
52 public function setDisableCache($disable_cache) {
53 $this->disableCache = $disable_cache;
54 return $this;
55 }
56
57 public function getDisableCache() {
58 return $this->disableCache;
59 }
60
61 public function setGenerateTableOfContents($generate) {
62 $this->generateTableOfContents = $generate;
63 return $this;
64 }
65
66 public function getGenerateTableOfContents() {
67 return $this->generateTableOfContents;
68 }
69
70 public function getTableOfContents() {
71 return $this->tableOfContents;
72 }
73
74 public function setContentCacheFragment($fragment) {
75 $this->contentCacheFragment = $fragment;
76 return $this;
77 }
78
79 public function getContentCacheFragment() {
80 return $this->contentCacheFragment;
81 }
82
83 public function getMarkupFieldKey($field) {
84 $fragment = $this->getContentCacheFragment();
85 if ($fragment !== null) {
86 return $fragment;
87 }
88
89 return PhabricatorHash::digestForIndex($this->getContent()).':oneoff';
90 }
91
92 public function newMarkupEngine($field) {
93 if ($this->engine) {
94 return $this->engine;
95 }
96
97 if ($this->engineRuleset) {
98 return PhabricatorMarkupEngine::getEngine($this->engineRuleset);
99 } else if ($this->preserveLinebreaks) {
100 return PhabricatorMarkupEngine::getEngine();
101 } else {
102 return PhabricatorMarkupEngine::getEngine('nolinebreaks');
103 }
104 }
105
106 public function getMarkupText($field) {
107 return $this->getContent();
108 }
109
110 public function didMarkupText(
111 $field,
112 $output,
113 PhutilMarkupEngine $engine) {
114
115 if ($this->getGenerateTableOfContents()) {
116 $toc = PhutilRemarkupHeaderBlockRule::renderTableOfContents($engine);
117 $this->tableOfContents = $toc;
118 }
119
120 require_celerity_resource('phabricator-remarkup-css');
121
122 return phutil_tag(
123 'div',
124 array(
125 'class' => 'phabricator-remarkup',
126 ),
127 $output);
128 }
129
130 public function shouldUseMarkupCache($field) {
131 if ($this->getDisableCache()) {
132 return false;
133 }
134
135 return true;
136 }
137
138}