@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
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add a "document" style to PHUIRemarkupPreviewPanel and use it in Legalpad and Phriction

Summary: Ref T3671. Depends on D6674. Continues work in D6673, D6674 and extends it into Legalpad and Phriction. Then deletes a bunch of dead code.

Test Plan: Edited documents in Legalpad and Phriction, verified I got reasonable looking previews.

Reviewers: btrahan, Firehed

Reviewed By: btrahan

CC: aran, chad

Maniphest Tasks: T3671

Differential Revision: https://secure.phabricator.com/D6675

+86 -188
+2 -28
src/__celerity_resource_map__.php
··· 1765 1765 ), 1766 1766 'disk' => '/rsrc/js/core/behavior-konami.js', 1767 1767 ), 1768 - 'javelin-behavior-legalpad-document-preview' => 1769 - array( 1770 - 'uri' => '/res/d0ce5a8c/rsrc/js/application/legalpad/legalpad-document-preview.js', 1771 - 'type' => 'js', 1772 - 'requires' => 1773 - array( 1774 - 0 => 'javelin-behavior', 1775 - 1 => 'javelin-dom', 1776 - 2 => 'javelin-util', 1777 - 3 => 'phabricator-shaped-request', 1778 - ), 1779 - 'disk' => '/rsrc/js/application/legalpad/legalpad-document-preview.js', 1780 - ), 1781 1768 'javelin-behavior-lightbox-attachments' => 1782 1769 array( 1783 1770 'uri' => '/res/72b4d3a8/rsrc/js/core/behavior-lightbox-attachments.js', ··· 2254 2241 11 => 'phabricator-keyboard-shortcut', 2255 2242 ), 2256 2243 'disk' => '/rsrc/js/application/pholio/behavior-pholio-mock-view.js', 2257 - ), 2258 - 'javelin-behavior-phriction-document-preview' => 2259 - array( 2260 - 'uri' => '/res/e2fe02de/rsrc/js/application/phriction/phriction-document-preview.js', 2261 - 'type' => 'js', 2262 - 'requires' => 2263 - array( 2264 - 0 => 'javelin-behavior', 2265 - 1 => 'javelin-dom', 2266 - 2 => 'javelin-util', 2267 - 3 => 'phabricator-shaped-request', 2268 - ), 2269 - 'disk' => '/rsrc/js/application/phriction/phriction-document-preview.js', 2270 2244 ), 2271 2245 'javelin-behavior-ponder-votebox' => 2272 2246 array( ··· 3781 3755 ), 3782 3756 'phriction-document-css' => 3783 3757 array( 3784 - 'uri' => '/res/97a9ef40/rsrc/css/application/phriction/phriction-document-css.css', 3758 + 'uri' => '/res/754f6b37/rsrc/css/application/phriction/phriction-document-css.css', 3785 3759 'type' => 'css', 3786 3760 'requires' => 3787 3761 array( ··· 3853 3827 ), 3854 3828 'phui-remarkup-preview-css' => 3855 3829 array( 3856 - 'uri' => '/res/80d54c8c/rsrc/css/phui/phui-remarkup-preview.css', 3830 + 'uri' => '/res/6c886e63/rsrc/css/phui/phui-remarkup-preview.css', 3857 3831 'type' => 'css', 3858 3832 'requires' => 3859 3833 array(
-2
src/__phutil_library_map__.php
··· 647 647 'LegalpadDocumentEditController' => 'applications/legalpad/controller/LegalpadDocumentEditController.php', 648 648 'LegalpadDocumentEditor' => 'applications/legalpad/editor/LegalpadDocumentEditor.php', 649 649 'LegalpadDocumentListController' => 'applications/legalpad/controller/LegalpadDocumentListController.php', 650 - 'LegalpadDocumentPreviewController' => 'applications/legalpad/controller/LegalpadDocumentPreviewController.php', 651 650 'LegalpadDocumentQuery' => 'applications/legalpad/query/LegalpadDocumentQuery.php', 652 651 'LegalpadDocumentSearchEngine' => 'applications/legalpad/query/LegalpadDocumentSearchEngine.php', 653 652 'LegalpadDocumentSignController' => 'applications/legalpad/controller/LegalpadDocumentSignController.php', ··· 2657 2656 0 => 'LegalpadController', 2658 2657 1 => 'PhabricatorApplicationSearchResultsControllerInterface', 2659 2658 ), 2660 - 'LegalpadDocumentPreviewController' => 'LegalpadController', 2661 2659 'LegalpadDocumentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 2662 2660 'LegalpadDocumentSearchEngine' => 'PhabricatorApplicationSearchEngine', 2663 2661 'LegalpadDocumentSignController' => 'LegalpadController',
+1 -1
src/applications/legalpad/application/PhabricatorApplicationLegalpad.php
··· 49 49 'comment/(?P<id>\d+)/' => 'LegalpadDocumentCommentController', 50 50 'view/(?P<id>\d+)/' => 'LegalpadDocumentViewController', 51 51 'document/' => array( 52 - 'preview/' => 'LegalpadDocumentPreviewController'), 52 + 'preview/' => 'PhabricatorMarkupPreviewController'), 53 53 )); 54 54 } 55 55
+7 -22
src/applications/legalpad/controller/LegalpadDocumentEditController.php
··· 172 172 $crumbs->addCrumb( 173 173 id(new PhabricatorCrumbView())->setName($short)); 174 174 175 - $preview_header = id(new PhabricatorHeaderView()) 176 - ->setHeader(pht('Document Preview')); 177 - $preview_view = phutil_tag( 178 - 'div', 179 - array( 180 - 'id' => 'document-preview'), 181 - phutil_tag( 182 - 'div', 183 - array( 184 - 'class' => 'aphront-panel-preview-loading-text'), 185 - pht('Loading preview...'))); 186 - $preview_panel = id(new PHUIDocumentView()) 187 - ->appendChild($preview_header) 188 - ->appendChild($preview_view); 189 - Javelin::initBehavior( 190 - 'legalpad-document-preview', 191 - array( 192 - 'preview' => 'document-preview', 193 - 'title' => 'document-title', 194 - 'text' => 'document-text', 195 - 'uri' => $this->getApplicationURI('document/preview/'))); 175 + 176 + $preview = id(new PHUIRemarkupPreviewPanel()) 177 + ->setHeader(pht('Document Preview')) 178 + ->setPreviewURI($this->getApplicationURI('document/preview/')) 179 + ->setControlID('document-text') 180 + ->setSkin('document'); 196 181 197 182 return $this->buildApplicationPage( 198 183 array( 199 184 $crumbs, 200 185 $error_view, 201 186 $form, 202 - $preview_panel 187 + $preview 203 188 ), 204 189 array( 205 190 'title' => $title,
-26
src/applications/legalpad/controller/LegalpadDocumentPreviewController.php
··· 1 - <?php 2 - 3 - /** 4 - * @group legalpad 5 - */ 6 - final class LegalpadDocumentPreviewController 7 - extends LegalpadController { 8 - 9 - public function processRequest() { 10 - $request = $this->getRequest(); 11 - $user = $request->getUser(); 12 - $text = $request->getStr('text'); 13 - 14 - $body = id(new LegalpadDocumentBody()) 15 - ->setText($text); 16 - 17 - $content = PhabricatorMarkupEngine::renderOneObject( 18 - $body, 19 - LegalpadDocumentBody::MARKUP_FIELD_TEXT, 20 - $user); 21 - 22 - $content = hsprintf('<div class="phabricator-remarkup">%s</div>', $content); 23 - 24 - return id(new AphrontAjaxResponse())->setContent($content); 25 - } 26 - }
+1 -1
src/applications/phriction/application/PhabricatorApplicationPhriction.php
··· 52 52 'new/' => 'PhrictionNewController', 53 53 'move/(?:(?P<id>[1-9]\d*)/)?' => 'PhrictionMoveController', 54 54 55 - 'preview/' => 'PhrictionDocumentPreviewController', 55 + 'preview/' => 'PhabricatorMarkupPreviewController', 56 56 'diff/(?P<id>[1-9]\d*)/' => 'PhrictionDiffController', 57 57 ), 58 58 );
+6 -19
src/applications/phriction/controller/PhrictionEditController.php
··· 229 229 $header = id(new PhabricatorHeaderView()) 230 230 ->setHeader($panel_header); 231 231 232 - $preview_content = hsprintf( 233 - '<div class="phriction-document-preview-header plt pll">%s</div> 234 - <div id="document-preview"> 235 - <div class="aphront-panel-preview-loading-text">%s</div> 236 - </div>', 237 - pht('Document Preview'), 238 - pht('Loading preview...')); 239 - 240 - $preview_panel = id(new PHUIDocumentView()) 241 - ->appendChild($preview_content); 242 - 243 - Javelin::initBehavior( 244 - 'phriction-document-preview', 245 - array( 246 - 'preview' => 'document-preview', 247 - 'textarea' => 'document-textarea', 248 - 'uri' => '/phriction/preview/?draftkey='.$draft_key, 249 - )); 232 + $preview = id(new PHUIRemarkupPreviewPanel()) 233 + ->setHeader(pht('Document Preview')) 234 + ->setPreviewURI('/phriction/preview/') 235 + ->setControlID('document-textarea') 236 + ->setSkin('document'); 250 237 251 238 $crumbs = $this->buildApplicationCrumbs(); 252 239 if ($document->getID()) { ··· 269 256 $draft_note, 270 257 $error_view, 271 258 $form, 272 - $preview_panel, 259 + $preview, 273 260 ), 274 261 array( 275 262 'title' => pht('Edit Document'),
+1 -1
src/applications/ponder/storage/PonderAnswer.php
··· 100 100 } 101 101 102 102 public function newMarkupEngine($field) { 103 - return PhabricatorMarkupEngine::newPonderMarkupEngine(); 103 + return PhabricatorMarkupEngine::getEngine(); 104 104 } 105 105 106 106 public function didMarkupText(
+1 -1
src/applications/ponder/storage/PonderComment.php
··· 20 20 } 21 21 22 22 public function newMarkupEngine($field) { 23 - return PhabricatorMarkupEngine::newPonderMarkupEngine(); 23 + return PhabricatorMarkupEngine::getEngine(); 24 24 } 25 25 26 26 public function didMarkupText(
+1 -1
src/applications/ponder/storage/PonderQuestion.php
··· 146 146 } 147 147 148 148 public function newMarkupEngine($field) { 149 - return PhabricatorMarkupEngine::newPonderMarkupEngine(); 149 + return PhabricatorMarkupEngine::getEngine(); 150 150 } 151 151 152 152 public function didMarkupText(
-14
src/infrastructure/markup/PhabricatorMarkupEngine.php
··· 345 345 )); 346 346 } 347 347 348 - 349 - /** 350 - * @task engine 351 - */ 352 - public static function newSlowvoteMarkupEngine() { 353 - return self::newMarkupEngine(array( 354 - )); 355 - } 356 - 357 - 358 - public static function newPonderMarkupEngine(array $options = array()) { 359 - return self::newMarkupEngine($options); 360 - } 361 - 362 348 /** 363 349 * @task engine 364 350 */
+7 -1
src/infrastructure/markup/PhabricatorMarkupOneOff.php
··· 15 15 final class PhabricatorMarkupOneOff implements PhabricatorMarkupInterface { 16 16 17 17 private $content; 18 + private $preserveLinebreaks; 19 + 20 + public function setPreserveLinebreaks($preserve_linebreaks) { 21 + $this->preserveLinebreaks = $preserve_linebreaks; 22 + return $this; 23 + } 18 24 19 25 public function setContent($content) { 20 26 $this->content = $content; ··· 32 38 public function newMarkupEngine($field) { 33 39 return PhabricatorMarkupEngine::newMarkupEngine( 34 40 array( 35 - 'preserve-linebreaks' => false, 41 + 'preserve-linebreaks' => $this->preserveLinebreaks, 36 42 )); 37 43 } 38 44
+3 -1
src/infrastructure/markup/PhabricatorMarkupPreviewController.php
··· 10 10 $text = $request->getStr('text'); 11 11 12 12 $output = PhabricatorMarkupEngine::renderOneObject( 13 - id(new PhabricatorMarkupOneOff())->setContent($text), 13 + id(new PhabricatorMarkupOneOff()) 14 + ->setPreserveLinebreaks(true) 15 + ->setContent($text), 14 16 'default', 15 17 $viewer); 16 18
+35 -2
src/view/phui/PHUIRemarkupPreviewPanel.php
··· 9 9 private $loadingText; 10 10 private $controlID; 11 11 private $previewURI; 12 + private $skin = 'default'; 12 13 13 14 protected function canAppendChild() { 14 15 return false; ··· 34 35 return $this; 35 36 } 36 37 38 + public function setSkin($skin) { 39 + static $skins = array( 40 + 'default' => true, 41 + 'document' => true, 42 + ); 43 + 44 + if (empty($skins[$skin])) { 45 + $valid = implode(', ', array_keys($skins)); 46 + throw new Exception("Invalid skin '{$skin}'. Valid skins are: {$valid}."); 47 + } 48 + 49 + $this->skin = $skin; 50 + return $this; 51 + } 52 + 37 53 public function getTagName() { 38 54 return 'div'; 39 55 } 40 56 41 57 public function getTagAttributes() { 58 + $classes = array(); 59 + $classes[] = 'phui-remarkup-preview'; 60 + 61 + if ($this->skin) { 62 + $classes[] = 'phui-remarkup-preview-skin-'.$this->skin; 63 + } 64 + 42 65 return array( 43 - 'class' => 'phui-remarkup-preview', 66 + 'class' => $classes, 44 67 ); 45 68 } 46 69 ··· 88 111 ), 89 112 $loading); 90 113 91 - return array($header, $preview); 114 + $content = array($header, $preview); 115 + 116 + switch ($this->skin) { 117 + case 'document': 118 + $content = id(new PHUIDocumentView())->appendChild($content); 119 + break; 120 + default: 121 + break; 122 + } 123 + 124 + return $content; 92 125 } 93 126 94 127 }
-6
webroot/rsrc/css/application/phriction/phriction-document-css.css
··· 40 40 margin-bottom: 15px; 41 41 } 42 42 43 - .phriction-document-preview-header { 44 - color: #666666; 45 - margin-bottom: 1em; 46 - font-size: 11px; 47 - } 48 - 49 43 .phriction-document-history-diff { 50 44 padding: 0 2em 2em; 51 45 }
+21
webroot/rsrc/css/phui/phui-remarkup-preview.css
··· 14 14 padding: 12px; 15 15 } 16 16 17 + .phui-remarkup-preview-skin-document { 18 + background: transparent; 19 + border: none; 20 + } 21 + 22 + .phui-remarkup-preview-skin-document .phui-preview-header { 23 + padding: 8px; 24 + background: #f3f3f3; 25 + } 26 + 17 27 .device-phone .aphront-panel-preview { 18 28 display: none; 19 29 } ··· 21 31 .phui-preview-loading-text { 22 32 color: #666666; 23 33 } 34 + 35 + /** 36 + * TODO: Classes implementing PhabricatorMarkupInterface are of differing 37 + * mindsets about whether output should be wrapped in a `phabricator-remarkup` 38 + * <div /> or not. It should probably move to the Engine in all cases, but 39 + * until we do that get rid of the extra spacing generated by the inner div. 40 + */ 41 + .phui-remarkup-preview .phabricator-remarkup .phabricator-remarkup { 42 + padding: 0; 43 + margin: 0; 44 + }
-33
webroot/rsrc/js/application/legalpad/legalpad-document-preview.js
··· 1 - /** 2 - * @provides javelin-behavior-legalpad-document-preview 3 - * @requires javelin-behavior 4 - * javelin-dom 5 - * javelin-util 6 - * phabricator-shaped-request 7 - */ 8 - 9 - JX.behavior('legalpad-document-preview', function(config) { 10 - 11 - var preview = JX.$(config.preview); 12 - var title = JX.$(config.title); 13 - var text = JX.$(config.text); 14 - 15 - var callback = function(r) { 16 - JX.DOM.setContent(JX.$(config.preview), JX.$H(r)); 17 - }; 18 - 19 - var getdata = function() { 20 - return { 21 - title : title.value, 22 - text : text.value 23 - }; 24 - }; 25 - 26 - var request = new JX.PhabricatorShapedRequest(config.uri, callback, getdata); 27 - var trigger = JX.bind(request, request.trigger); 28 - 29 - JX.DOM.listen(title, 'keydown', null, trigger); 30 - JX.DOM.listen(text, 'keydown', null, trigger); 31 - request.start(); 32 - 33 - });
-29
webroot/rsrc/js/application/phriction/phriction-document-preview.js
··· 1 - /** 2 - * @provides javelin-behavior-phriction-document-preview 3 - * @requires javelin-behavior 4 - * javelin-dom 5 - * javelin-util 6 - * phabricator-shaped-request 7 - */ 8 - 9 - JX.behavior('phriction-document-preview', function(config) { 10 - 11 - var preview = JX.$(config.preview); 12 - var textarea = JX.$(config.textarea); 13 - 14 - var callback = function(r) { 15 - JX.DOM.setContent(JX.$(config.preview), JX.$H(r)); 16 - }; 17 - 18 - var getdata = function() { 19 - return { 20 - document : textarea.value 21 - }; 22 - }; 23 - 24 - var request = new JX.PhabricatorShapedRequest(config.uri, callback, getdata); 25 - var trigger = JX.bind(request, request.trigger); 26 - 27 - JX.DOM.listen(textarea, 'keydown', null, trigger); 28 - request.start(); 29 - });