@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

Replace some hsprintf() with phutil_tag() and phutil_tag_div() Depends on D7545.

Test Plan: This is one of the rare moments where unit tests for views would be useful.

Reviewers: epriestley

Reviewed By: epriestley

CC: Korvin, epriestley, aran

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

+151 -201
+8 -6
src/aphront/response/AphrontRedirectResponse.php
··· 42 42 $error->setSeverity(AphrontErrorView::SEVERITY_NOTICE); 43 43 $error->setTitle('Stopped on Redirect'); 44 44 45 + $error->appendChild(phutil_tag('p', array(), pht( 46 + 'You were stopped here because %s is set in your configuration.', 47 + phutil_tag('tt', array(), 'debug.stop-on-redirect')))); 48 + 45 49 $link = phutil_tag( 46 50 'a', 47 51 array( 48 52 'href' => $this->getURI(), 49 53 ), 50 - 'Continue to: '.$this->getURI()); 54 + $this->getURI()); 51 55 52 - $error->appendChild(hsprintf( 53 - '<p>You were stopped here because <tt>debug.stop-on-redirect</tt> '. 54 - 'is set in your configuration.</p>'. 55 - '<p>%s</p>', 56 - $link)); 56 + $error->appendChild(phutil_tag('p', array(), pht( 57 + 'Continue to: %s', 58 + $link))); 57 59 58 60 $view->appendChild($error); 59 61
+5 -4
src/infrastructure/celerity/CelerityStaticResourceResponse.php
··· 196 196 if (strpos($data, '<!') !== false) { 197 197 throw new Exception('Literal <! is not allowed inside inline script.'); 198 198 } 199 - return hsprintf( 200 - // We don't use <![CDATA[ ]]> because it is ignored by HTML parsers. We 201 - // would need to send the document with XHTML content type. 202 - '<script type="text/javascript">%s</script>', 199 + // We don't use <![CDATA[ ]]> because it is ignored by HTML parsers. We 200 + // would need to send the document with XHTML content type. 201 + return phutil_tag( 202 + 'script', 203 + array('type' => 'text/javascript'), 203 204 phutil_safe_html($data)); 204 205 } 205 206
+2 -1
src/infrastructure/diff/PhabricatorInlineCommentController.php
··· 71 71 $dialog->setTitle('Really delete this comment?'); 72 72 $dialog->addHiddenInput('id', $this->getCommentID()); 73 73 $dialog->addHiddenInput('op', 'delete'); 74 - $dialog->appendChild(hsprintf('<p>Delete this inline comment?</p>')); 74 + $dialog->appendChild( 75 + phutil_tag('p', array(), pht('Delete this inline comment?'))); 75 76 76 77 $dialog->addCancelButton('#'); 77 78 $dialog->addSubmitButton('Delete');
+20 -26
src/infrastructure/diff/view/PhabricatorInlineSummaryView.php
··· 19 19 } 20 20 21 21 private function renderHeader() { 22 - return phutil_tag( 23 - 'div', 24 - array( 25 - 'class' => 'phabricator-inline-summary', 26 - ), 27 - 'Inline Comments'); 22 + return phutil_tag_div('phabricator-inline-summary', pht('Inline Comments')); 28 23 } 29 24 30 25 private function renderTable() { ··· 39 34 } 40 35 } 41 36 42 - $rows[] = hsprintf('<tr><th colspan="3">%s</th></tr>', $group); 37 + $rows[] = phutil_tag( 38 + 'tr', 39 + array(), 40 + phutil_tag('th', array('colspan' => 3), $group)); 43 41 44 42 foreach ($items as $item) { 45 43 ··· 80 78 $where = idx($item, 'where'); 81 79 82 80 $colspan = ($has_where ? null : 2); 83 - $rows[] = hsprintf( 84 - '<tr>'. 85 - '<td class="inline-line-number">%s</td>'. 86 - '%s'. 87 - '%s'. 88 - '</tr>', 89 - $lines, 90 - ($has_where 91 - ? hsprintf('<td class="inline-which-diff">%s</td>', $where) 92 - : null), 93 - phutil_tag( 94 - 'td', 95 - array( 96 - 'class' => 'inline-summary-content', 97 - 'colspan' => $colspan, 98 - ), 99 - hsprintf( 100 - '<div class="phabricator-remarkup">%s</div>', 101 - $item['content']))); 81 + $rows[] = phutil_tag( 82 + 'tr', 83 + array(), 84 + array( 85 + phutil_tag('td', array('class' => 'inline-line-number'), $lines), 86 + ($has_where 87 + ? phutil_tag('td', array('class' => 'inline-which-diff'), $where) 88 + : null), 89 + phutil_tag( 90 + 'td', 91 + array( 92 + 'class' => 'inline-summary-content', 93 + 'colspan' => $colspan, 94 + ), 95 + phutil_tag_div('phabricator-remarkup', $item['content'])))); 102 96 } 103 97 } 104 98
+2 -2
src/infrastructure/markup/rule/PhabricatorRemarkupRuleYoutube.php
··· 30 30 } 31 31 32 32 $youtube_src = 'https://www.youtube.com/embed/'.$v; 33 - $iframe = hsprintf( 34 - '<div class="embedded-youtube-video">%s</div>', 33 + $iframe = phutil_tag_div( 34 + 'embedded-youtube-video', 35 35 phutil_tag( 36 36 'iframe', 37 37 array(
+8 -5
src/view/control/AphrontTableView.php
··· 272 272 } 273 273 } else { 274 274 $colspan = max(count(array_filter($visibility)), 1); 275 - $table[] = hsprintf( 276 - '<tr class="no-data"><td colspan="%s">%s</td></tr>', 277 - $colspan, 278 - coalesce($this->noDataString, pht('No data available.'))); 275 + $table[] = phutil_tag( 276 + 'tr', 277 + array('class' => 'no-data'), 278 + phutil_tag( 279 + 'td', 280 + array('colspan' => $colspan), 281 + coalesce($this->noDataString, pht('No data available.')))); 279 282 } 280 283 281 284 $table_class = 'aphront-table-view'; ··· 287 290 } 288 291 289 292 $html = phutil_tag('table', array('class' => $table_class), $table); 290 - return hsprintf('<div class="aphront-table-wrap">%s</div>', $html); 293 + return phutil_tag_div('aphront-table-wrap', $html); 291 294 } 292 295 293 296 public static function renderSingleDisplayLine($line) {
+22 -27
src/view/control/PhabricatorObjectSelectorDialog.php
··· 117 117 'action' => $this->submitURI, 118 118 'id' => $search_id, 119 119 ), 120 - hsprintf( 121 - '<table class="phabricator-object-selector-search"> 122 - <tr> 123 - <td class="phabricator-object-selector-search-filter">%s</td> 124 - <td class="phabricator-object-selector-search-text">%s</td> 125 - </tr> 126 - </table>', 127 - phutil_tag( 128 - 'select', 129 - array('id' => $filter_id), 130 - $options), 131 - phutil_tag( 132 - 'input', 133 - array( 134 - 'id' => $query_id, 135 - 'type' => 'text')))); 120 + phutil_tag( 121 + 'table', 122 + array('class' => 'phabricator-object-selector-search'), 123 + phutil_tag('tr', array(), array( 124 + phutil_tag( 125 + 'td', 126 + array('class' => 'phabricator-object-selector-search-filter'), 127 + phutil_tag('select', array('id' => $filter_id), $options)), 128 + phutil_tag( 129 + 'td', 130 + array('class' => 'phabricator-object-selector-search-text'), 131 + phutil_tag('input', array('id' => $query_id, 'type' => 'text'))), 132 + )))); 136 133 137 134 $result_box = phutil_tag( 138 135 'div', ··· 142 139 ), 143 140 ''); 144 141 145 - $attached_box = hsprintf( 146 - '<div class="phabricator-object-selector-current">'. 147 - '<div class="phabricator-object-selector-currently-attached">'. 148 - '<div class="phabricator-object-selector-header">%s</div>'. 149 - '<div id="%s"></div>'. 150 - '%s'. 151 - '</div>'. 152 - '</div>', 153 - $this->header, 154 - $current_id, 155 - $instructions); 142 + $attached_box = phutil_tag_div( 143 + 'phabricator-object-selector-current', 144 + phutil_tag_div( 145 + 'phabricator-object-selector-currently-attached', 146 + array( 147 + phutil_tag_div('phabricator-object-selector-header', $this->header), 148 + phutil_tag('div', array('id' => $current_id)), 149 + $instructions, 150 + ))); 156 151 157 152 $dialog = new AphrontDialogView(); 158 153 $dialog
+4 -4
src/view/form/control/AphrontFormCheckboxControl.php
··· 38 38 'for' => $id, 39 39 ), 40 40 $box['label']); 41 - $rows[] = hsprintf( 42 - '<tr><td>%s</td><th>%s</th></tr>', 43 - $checkbox, 44 - $label); 41 + $rows[] = phutil_tag('tr', array(), array( 42 + phutil_tag('td', array(), $checkbox), 43 + phutil_tag('th', array(), $label) 44 + )); 45 45 } 46 46 return phutil_tag( 47 47 'table',
+7 -7
src/view/form/control/AphrontFormRadioButtonControl.php
··· 51 51 $button['label']); 52 52 53 53 if ($button['caption']) { 54 - $label = hsprintf( 55 - '%s<div class="aphront-form-radio-caption">%s</div>', 54 + $label = array( 56 55 $label, 57 - $button['caption']); 56 + phutil_tag_div('aphront-form-radio-caption', $button['caption']), 57 + ); 58 58 } 59 - $rows[] = hsprintf( 60 - '<tr><td>%s</td><th>%s</th></tr>', 61 - $radio, 62 - $label); 59 + $rows[] = phutil_tag('tr', array(), array( 60 + phutil_tag('td', array(), $radio), 61 + phutil_tag('th', array(), $label), 62 + )); 63 63 } 64 64 65 65 return phutil_tag(
+9 -10
src/view/layout/AphrontContextBarView.php
··· 15 15 16 16 require_celerity_resource('aphront-contextbar-view-css'); 17 17 18 - return hsprintf( 19 - '<div class="aphront-contextbar-view">'. 20 - '<div class="aphront-contextbar-core">'. 21 - '<div class="aphront-contextbar-buttons">%s</div>'. 22 - '<div class="aphront-contextbar-content">%s</div>'. 23 - '</div>'. 24 - '<div style="clear: both;"></div>'. 25 - '</div>', 26 - $view->render(), 27 - $this->renderChildren()); 18 + return phutil_tag_div( 19 + 'aphront-contextbar-view', 20 + array( 21 + phutil_tag_div('aphront-contextbar-core', array( 22 + phutil_tag_div('aphront-contextbar-buttons', $view->render()), 23 + phutil_tag_div('aphront-contextbar-content', $this->renderChildren()), 24 + )), 25 + phutil_tag('div', array('style' => 'clear: both;')), 26 + )); 28 27 } 29 28 30 29 }
+6 -11
src/view/layout/AphrontPanelView.php
··· 69 69 } 70 70 71 71 if ($this->caption !== null) { 72 - $caption = phutil_tag( 73 - 'div', 74 - array('class' => 'aphront-panel-view-caption'), 75 - $this->caption); 72 + $caption = phutil_tag_div('aphront-panel-view-caption', $this->caption); 76 73 } else { 77 74 $caption = null; 78 75 } 79 76 80 77 $buttons = null; 81 78 if ($this->buttons) { 82 - $buttons = hsprintf( 83 - '<div class="aphront-panel-view-buttons">%s</div>', 79 + $buttons = phutil_tag_div( 80 + 'aphront-panel-view-buttons', 84 81 phutil_implode_html(" ", $this->buttons)); 85 82 } 86 - $header_elements = hsprintf( 87 - '<div class="aphront-panel-header">%s%s%s</div>', 88 - $buttons, 89 - $header, 90 - $caption); 83 + $header_elements = phutil_tag_div( 84 + 'aphront-panel-header', 85 + array($buttons, $header, $caption)); 91 86 92 87 $table = phutil_implode_html('', $this->renderChildren()); 93 88
+2 -5
src/view/layout/PhabricatorSourceCodeView.php
··· 116 116 $classes[] = 'remarkup-code'; 117 117 $classes[] = 'PhabricatorMonospaced'; 118 118 119 - return phutil_tag( 120 - 'div', 121 - array( 122 - 'class' => 'phabricator-source-code-container', 123 - ), 119 + return phutil_tag_div( 120 + 'phabricator-source-code-container', 124 121 javelin_tag( 125 122 'table', 126 123 array(
+12 -14
src/view/layout/PhabricatorTransactionView.php
··· 62 62 63 63 $transaction_id = $this->anchorName ? 'anchor-'.$this->anchorName : null; 64 64 65 + $header = phutil_tag_div( 66 + 'phabricator-transaction-header', 67 + array($info, $actions)); 68 + 65 69 return phutil_tag( 66 70 'div', 67 71 array( ··· 69 73 'id' => $transaction_id, 70 74 'style' => $style, 71 75 ), 72 - hsprintf( 73 - '<div class="phabricator-transaction-detail %s">'. 74 - '<div class="phabricator-transaction-header">%s%s</div>'. 75 - '%s'. 76 - '</div>', 77 - $classes, 78 - $info, 79 - $actions, 80 - $content)); 76 + phutil_tag_div( 77 + 'phabricator-transaction-detail '.$classes, 78 + array($header, $content))); 81 79 82 80 } 83 81 ··· 118 116 119 117 $info = phutil_implode_html(" \xC2\xB7 ", $info); 120 118 121 - return hsprintf( 122 - '<span class="phabricator-transaction-info">%s</span>', 119 + return phutil_tag( 120 + 'span', 121 + array('class' => 'phabricator-transaction-info'), 123 122 $info); 124 123 } 125 124 ··· 139 138 if (!$this->hasChildren()) { 140 139 return null; 141 140 } 142 - return phutil_tag( 143 - 'div', 144 - array('class' => 'phabricator-transaction-content'), 141 + return phutil_tag_div( 142 + 'phabricator-transaction-content', 145 143 $this->renderChildren()); 146 144 } 147 145
+8 -8
src/view/page/AphrontRequestFailureView.php
··· 13 13 final public function render() { 14 14 require_celerity_resource('aphront-request-failure-view-css'); 15 15 16 - return hsprintf( 17 - '<div class="aphront-request-failure-view">'. 18 - '<div class="aphront-request-failure-head">'. 19 - '<h1>%s</h1>'. 20 - '</div>'. 21 - '<div class="aphront-request-failure-body">%s</div>'. 22 - '</div>', 23 - $this->header, 16 + $head = phutil_tag_div( 17 + 'aphront-request-failure-head', 18 + phutil_tag('h1', array(), $this->header)); 19 + 20 + $body = phutil_tag_div( 21 + 'aphront-request-failure-body', 24 22 $this->renderChildren()); 23 + 24 + return phutil_tag_div('aphront-request-failure-view', array($head, $body)); 25 25 } 26 26 27 27 }
+14 -20
src/view/page/PhabricatorStandardPageView.php
··· 298 298 $developer_warning = null; 299 299 if (PhabricatorEnv::getEnvConfig('phabricator.developer-mode') && 300 300 DarkConsoleErrorLogPluginAPI::getErrors()) { 301 - $developer_warning = phutil_tag( 302 - 'div', 303 - array( 304 - 'class' => 'aphront-developer-error-callout', 305 - ), 301 + $developer_warning = phutil_tag_div( 302 + 'aphront-developer-error-callout', 306 303 pht( 307 304 'This page raised PHP errors. Find them in DarkConsole '. 308 305 'or the error log.')); ··· 313 310 if ($user && $user->getIsAdmin()) { 314 311 $open = PhabricatorSetupCheck::getOpenSetupIssueCount(); 315 312 if ($open) { 316 - $setup_warning = phutil_tag( 317 - 'div', 318 - array( 319 - 'class' => 'setup-warning-callout', 320 - ), 313 + $setup_warning = phutil_tag_div( 314 + 'setup-warning-callout', 321 315 phutil_tag( 322 316 'a', 323 317 array( ··· 334 328 'id' => 'base-page', 335 329 'class' => 'phabricator-standard-page', 336 330 ), 337 - hsprintf( 338 - '%s%s%s'. 339 - '<div class="phabricator-standard-page-body">'. 340 - '%s%s<div style="clear: both;"></div>'. 341 - '</div>', 342 - $developer_warning, 343 - $setup_warning, 344 - $header_chrome, 345 - ($console ? hsprintf('<darkconsole />') : null), 346 - parent::getBody())); 331 + array( 332 + $developer_warning, 333 + $setup_warning, 334 + $header_chrome, 335 + phutil_tag_div('phabricator-standard-page-body', array( 336 + ($console ? hsprintf('<darkconsole />') : null), 337 + parent::getBody(), 338 + phutil_tag('div', array('style' => 'clear: both;')), 339 + )), 340 + )); 347 341 } 348 342 349 343 protected function getTail() {
+4 -5
src/view/page/menu/PhabricatorMainMenuSearchView.php
··· 66 66 'action' => '/search/', 67 67 'method' => 'POST', 68 68 ), 69 - hsprintf( 70 - '<div class="phabricator-main-menu-search-container">'. 71 - '%s<button>Search</button>%s%s'. 72 - '</div>', 69 + phutil_tag_div('phabricator-main-menu-search-container', array( 73 70 $input, 71 + phutil_tag('button', array(), pht('Search')), 74 72 $scope_input, 75 - $target)); 73 + $target, 74 + ))); 76 75 77 76 return $form; 78 77 }
+3 -6
src/view/widget/bars/AphrontProgressBarView.php
··· 38 38 39 39 $color = $this->getColor(); 40 40 41 - return phutil_tag( 42 - 'div', 43 - array( 44 - 'class' => "aphront-bar progress color-{$color}", 45 - ), 41 + return phutil_tag_div( 42 + "aphront-bar progress color-{$color}", 46 43 array( 47 44 phutil_tag( 48 45 'div', 49 46 array('title' => $this->alt), 50 47 phutil_tag( 51 48 'div', 52 - array('style' => hsprintf("width: %dpx;", $width)), 49 + array('style' => "width: {$width}px;"), 53 50 '')), 54 51 phutil_tag( 55 52 'span',
+15 -40
src/view/widget/hovercard/PhabricatorHovercardView.php
··· 92 92 $body_title = $handle->getFullName(); 93 93 } 94 94 95 - $body[] = phutil_tag( 96 - 'div', 97 - array( 98 - 'class' => 'phabricator-hovercard-body-header' 99 - ), 100 - $body_title); 95 + $body[] = phutil_tag_div('phabricator-hovercard-body-header', $body_title); 101 96 102 97 foreach ($this->fields as $field) { 103 - $item = hsprintf('<strong>%s:</strong> <span>%s</span>', 104 - $field['label'], $field['value']); 105 - $body[] = phutil_tag( 106 - 'div', 107 - array( 108 - 'class' => 'phabricator-hovercard-body-item' 109 - ), 110 - $item); 98 + $item = array( 99 + phutil_tag('strong', array(), $field['label']), 100 + ' ', 101 + phutil_tag('span', array(), $field['value']), 102 + ); 103 + $body[] = phutil_tag_div('phabricator-hovercard-body-item', $item); 111 104 } 112 105 113 106 if ($handle->getImageURI()) { ··· 147 140 148 141 $tail = null; 149 142 if ($buttons) { 150 - $tail = phutil_tag('div', 151 - array('class' => 'phabricator-hovercard-tail'), 152 - $buttons); 143 + $tail = phutil_tag_div('phabricator-hovercard-tail', $buttons); 153 144 } 154 145 155 146 // Assemble container 156 147 // TODO: Add color support 157 - $content = hsprintf( 158 - '%s%s%s', 159 - phutil_tag('div', 160 - array( 161 - 'class' => 'phabricator-hovercard-head' 162 - ), 163 - $header), 164 - phutil_tag('div', 165 - array( 166 - 'class' => 'phabricator-hovercard-body' 167 - ), 168 - $body), 169 - $tail); 170 - 171 - $hovercard = phutil_tag("div", 148 + $hovercard = phutil_tag_div( 149 + 'phabricator-hovercard-container', 172 150 array( 173 - "class" => "phabricator-hovercard-container", 174 - ), 175 - $content); 151 + phutil_tag_div('phabricator-hovercard-head', $header), 152 + phutil_tag_div('phabricator-hovercard-body', $body), 153 + $tail, 154 + )); 176 155 177 156 // Wrap for thick border 178 157 // and later the tip at the bottom 179 - return phutil_tag('div', 180 - array( 181 - 'class' => 'phabricator-hovercard-wrapper', 182 - ), 183 - $hovercard); 158 + return phutil_tag_div('phabricator-hovercard-wrapper', $hovercard); 184 159 } 185 160 186 161 }