[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 abstract class DifferentialChangesetHTMLRenderer 4 extends DifferentialChangesetRenderer { 5 6 protected function renderChangeTypeHeader($force) { 7 $changeset = $this->getChangeset(); 8 9 $change = $changeset->getChangeType(); 10 $file = $changeset->getFileType(); 11 12 $messages = array(); 13 $none = hsprintf(''); 14 switch ($change) { 15 16 case DifferentialChangeType::TYPE_ADD: 17 switch ($file) { 18 case DifferentialChangeType::FILE_TEXT: 19 $messages[] = pht( 20 'This file was <strong>added</strong>.', 21 $none); 22 break; 23 case DifferentialChangeType::FILE_IMAGE: 24 $messages[] = pht( 25 'This image was <strong>added</strong>.', 26 $none); 27 break; 28 case DifferentialChangeType::FILE_DIRECTORY: 29 $messages[] = pht( 30 'This directory was <strong>added</strong>.', 31 $none); 32 break; 33 case DifferentialChangeType::FILE_BINARY: 34 $messages[] = pht( 35 'This binary file was <strong>added</strong>.', 36 $none); 37 break; 38 case DifferentialChangeType::FILE_SYMLINK: 39 $messages[] = pht( 40 'This symlink was <strong>added</strong>.', 41 $none); 42 break; 43 case DifferentialChangeType::FILE_SUBMODULE: 44 $messages[] = pht( 45 'This submodule was <strong>added</strong>.', 46 $none); 47 break; 48 } 49 break; 50 51 case DifferentialChangeType::TYPE_DELETE: 52 switch ($file) { 53 case DifferentialChangeType::FILE_TEXT: 54 $messages[] = pht( 55 'This file was <strong>deleted</strong>.', 56 $none); 57 break; 58 case DifferentialChangeType::FILE_IMAGE: 59 $messages[] = pht( 60 'This image was <strong>deleted</strong>.', 61 $none); 62 break; 63 case DifferentialChangeType::FILE_DIRECTORY: 64 $messages[] = pht( 65 'This directory was <strong>deleted</strong>.', 66 $none); 67 break; 68 case DifferentialChangeType::FILE_BINARY: 69 $messages[] = pht( 70 'This binary file was <strong>deleted</strong>.', 71 $none); 72 break; 73 case DifferentialChangeType::FILE_SYMLINK: 74 $messages[] = pht( 75 'This symlink was <strong>deleted</strong>.', 76 $none); 77 break; 78 case DifferentialChangeType::FILE_SUBMODULE: 79 $messages[] = pht( 80 'This submodule was <strong>deleted</strong>.', 81 $none); 82 break; 83 } 84 break; 85 86 case DifferentialChangeType::TYPE_MOVE_HERE: 87 $from = phutil_tag('strong', array(), $changeset->getOldFile()); 88 switch ($file) { 89 case DifferentialChangeType::FILE_TEXT: 90 $messages[] = pht('This file was moved from %s.', $from); 91 break; 92 case DifferentialChangeType::FILE_IMAGE: 93 $messages[] = pht('This image was moved from %s.', $from); 94 break; 95 case DifferentialChangeType::FILE_DIRECTORY: 96 $messages[] = pht('This directory was moved from %s.', $from); 97 break; 98 case DifferentialChangeType::FILE_BINARY: 99 $messages[] = pht('This binary file was moved from %s.', $from); 100 break; 101 case DifferentialChangeType::FILE_SYMLINK: 102 $messages[] = pht('This symlink was moved from %s.', $from); 103 break; 104 case DifferentialChangeType::FILE_SUBMODULE: 105 $messages[] = pht('This submodule was moved from %s.', $from); 106 break; 107 } 108 break; 109 110 case DifferentialChangeType::TYPE_COPY_HERE: 111 $from = phutil_tag('strong', array(), $changeset->getOldFile()); 112 switch ($file) { 113 case DifferentialChangeType::FILE_TEXT: 114 $messages[] = pht('This file was copied from %s.', $from); 115 break; 116 case DifferentialChangeType::FILE_IMAGE: 117 $messages[] = pht('This image was copied from %s.', $from); 118 break; 119 case DifferentialChangeType::FILE_DIRECTORY: 120 $messages[] = pht('This directory was copied from %s.', $from); 121 break; 122 case DifferentialChangeType::FILE_BINARY: 123 $messages[] = pht('This binary file was copied from %s.', $from); 124 break; 125 case DifferentialChangeType::FILE_SYMLINK: 126 $messages[] = pht('This symlink was copied from %s.', $from); 127 break; 128 case DifferentialChangeType::FILE_SUBMODULE: 129 $messages[] = pht('This submodule was copied from %s.', $from); 130 break; 131 } 132 break; 133 134 case DifferentialChangeType::TYPE_MOVE_AWAY: 135 $paths = phutil_tag( 136 'strong', 137 array(), 138 implode(', ', $changeset->getAwayPaths())); 139 switch ($file) { 140 case DifferentialChangeType::FILE_TEXT: 141 $messages[] = pht('This file was moved to %s.', $paths); 142 break; 143 case DifferentialChangeType::FILE_IMAGE: 144 $messages[] = pht('This image was moved to %s.', $paths); 145 break; 146 case DifferentialChangeType::FILE_DIRECTORY: 147 $messages[] = pht('This directory was moved to %s.', $paths); 148 break; 149 case DifferentialChangeType::FILE_BINARY: 150 $messages[] = pht('This binary file was moved to %s.', $paths); 151 break; 152 case DifferentialChangeType::FILE_SYMLINK: 153 $messages[] = pht('This symlink was moved to %s.', $paths); 154 break; 155 case DifferentialChangeType::FILE_SUBMODULE: 156 $messages[] = pht('This submodule was moved to %s.', $paths); 157 break; 158 } 159 break; 160 161 case DifferentialChangeType::TYPE_COPY_AWAY: 162 $paths = phutil_tag( 163 'strong', 164 array(), 165 implode(', ', $changeset->getAwayPaths())); 166 switch ($file) { 167 case DifferentialChangeType::FILE_TEXT: 168 $messages[] = pht('This file was copied to %s.', $paths); 169 break; 170 case DifferentialChangeType::FILE_IMAGE: 171 $messages[] = pht('This image was copied to %s.', $paths); 172 break; 173 case DifferentialChangeType::FILE_DIRECTORY: 174 $messages[] = pht('This directory was copied to %s.', $paths); 175 break; 176 case DifferentialChangeType::FILE_BINARY: 177 $messages[] = pht('This binary file was copied to %s.', $paths); 178 break; 179 case DifferentialChangeType::FILE_SYMLINK: 180 $messages[] = pht('This symlink was copied to %s.', $paths); 181 break; 182 case DifferentialChangeType::FILE_SUBMODULE: 183 $messages[] = pht('This submodule was copied to %s.', $paths); 184 break; 185 } 186 break; 187 188 case DifferentialChangeType::TYPE_MULTICOPY: 189 $paths = phutil_tag( 190 'strong', 191 array(), 192 implode(', ', $changeset->getAwayPaths())); 193 switch ($file) { 194 case DifferentialChangeType::FILE_TEXT: 195 $messages[] = pht( 196 'This file was deleted after being copied to %s.', 197 $paths); 198 break; 199 case DifferentialChangeType::FILE_IMAGE: 200 $messages[] = pht( 201 'This image was deleted after being copied to %s.', 202 $paths); 203 break; 204 case DifferentialChangeType::FILE_DIRECTORY: 205 $messages[] = pht( 206 'This directory was deleted after being copied to %s.', 207 $paths); 208 break; 209 case DifferentialChangeType::FILE_BINARY: 210 $messages[] = pht( 211 'This binary file was deleted after being copied to %s.', 212 $paths); 213 break; 214 case DifferentialChangeType::FILE_SYMLINK: 215 $messages[] = pht( 216 'This symlink was deleted after being copied to %s.', 217 $paths); 218 break; 219 case DifferentialChangeType::FILE_SUBMODULE: 220 $messages[] = pht( 221 'This submodule was deleted after being copied to %s.', 222 $paths); 223 break; 224 } 225 break; 226 227 default: 228 switch ($file) { 229 case DifferentialChangeType::FILE_TEXT: 230 // This is the default case, so we only render this header if 231 // forced to since it's not very useful. 232 if ($force) { 233 $messages[] = pht('This file was not modified.'); 234 } 235 break; 236 case DifferentialChangeType::FILE_IMAGE: 237 $messages[] = pht('This is an image.'); 238 break; 239 case DifferentialChangeType::FILE_DIRECTORY: 240 $messages[] = pht('This is a directory.'); 241 break; 242 case DifferentialChangeType::FILE_BINARY: 243 $messages[] = pht('This is a binary file.'); 244 break; 245 case DifferentialChangeType::FILE_SYMLINK: 246 $messages[] = pht('This is a symlink.'); 247 break; 248 case DifferentialChangeType::FILE_SUBMODULE: 249 $messages[] = pht('This is a submodule.'); 250 break; 251 } 252 break; 253 } 254 255 // If this is a text file with at least one hunk, we may have converted 256 // the text encoding. In this case, show a note. 257 $show_encoding = ($file == DifferentialChangeType::FILE_TEXT) && 258 ($changeset->getHunks()); 259 260 if ($show_encoding) { 261 $encoding = $this->getOriginalCharacterEncoding(); 262 if ($encoding != 'utf8') { 263 if ($encoding) { 264 $messages[] = pht( 265 'This file was converted from %s for display.', 266 phutil_tag('strong', array(), $encoding)); 267 } else { 268 $messages[] = pht( 269 'This file uses an unknown character encoding.'); 270 } 271 } 272 } 273 274 if (!$messages) { 275 return null; 276 } 277 278 foreach ($messages as $key => $message) { 279 $messages[$key] = phutil_tag('li', array(), $message); 280 } 281 282 return phutil_tag( 283 'ul', 284 array( 285 'class' => 'differential-meta-notice', 286 ), 287 $messages); 288 } 289 290 protected function renderPropertyChangeHeader() { 291 $changeset = $this->getChangeset(); 292 list($old, $new) = $this->getChangesetProperties($changeset); 293 294 // If we don't have any property changes, don't render this table. 295 if ($old === $new) { 296 return null; 297 } 298 299 $keys = array_keys($old + $new); 300 sort($keys); 301 302 $key_map = array( 303 'unix:filemode' => pht('File Mode'), 304 'file:dimensions' => pht('Image Dimensions'), 305 'file:mimetype' => pht('MIME Type'), 306 'file:size' => pht('File Size'), 307 ); 308 309 $rows = array(); 310 foreach ($keys as $key) { 311 $oval = idx($old, $key); 312 $nval = idx($new, $key); 313 if ($oval !== $nval) { 314 if ($oval === null) { 315 $oval = phutil_tag('em', array(), 'null'); 316 } else { 317 $oval = phutil_escape_html_newlines($oval); 318 } 319 320 if ($nval === null) { 321 $nval = phutil_tag('em', array(), 'null'); 322 } else { 323 $nval = phutil_escape_html_newlines($nval); 324 } 325 326 $readable_key = idx($key_map, $key, $key); 327 328 $row = array( 329 $readable_key, 330 $oval, 331 $nval, 332 ); 333 $rows[] = $row; 334 335 } 336 } 337 338 $classes = array('', 'oval', 'nval'); 339 $headers = array( 340 pht('Property'), 341 pht('Old Value'), 342 pht('New Value'), 343 ); 344 $table = id(new AphrontTableView($rows)) 345 ->setHeaders($headers) 346 ->setColumnClasses($classes); 347 return phutil_tag( 348 'div', 349 array( 350 'class' => 'differential-property-table', 351 ), 352 $table); 353 } 354 355 public function renderShield($message, $force = 'default') { 356 $end = count($this->getOldLines()); 357 $reference = $this->getRenderingReference(); 358 359 if ($force !== 'text' && 360 $force !== 'whitespace' && 361 $force !== 'none' && 362 $force !== 'default') { 363 throw new Exception("Invalid 'force' parameter '{$force}'!"); 364 } 365 366 $range = "0-{$end}"; 367 if ($force == 'text') { 368 // If we're forcing text, force the whole file to be rendered. 369 $range = "{$range}/0-{$end}"; 370 } 371 372 $meta = array( 373 'ref' => $reference, 374 'range' => $range, 375 ); 376 377 if ($force == 'whitespace') { 378 $meta['whitespace'] = DifferentialChangesetParser::WHITESPACE_SHOW_ALL; 379 } 380 381 $content = array(); 382 $content[] = $message; 383 if ($force !== 'none') { 384 $content[] = ' '; 385 $content[] = javelin_tag( 386 'a', 387 array( 388 'mustcapture' => true, 389 'sigil' => 'show-more', 390 'class' => 'complete', 391 'href' => '#', 392 'meta' => $meta, 393 ), 394 pht('Show File Contents')); 395 } 396 397 return $this->wrapChangeInTable( 398 javelin_tag( 399 'tr', 400 array( 401 'sigil' => 'context-target', 402 ), 403 phutil_tag( 404 'td', 405 array( 406 'class' => 'differential-shield', 407 'colspan' => 6, 408 ), 409 $content))); 410 } 411 412 abstract protected function renderColgroup(); 413 414 415 protected function wrapChangeInTable($content) { 416 if (!$content) { 417 return null; 418 } 419 420 return javelin_tag( 421 'table', 422 array( 423 'class' => 'differential-diff remarkup-code PhabricatorMonospaced', 424 'sigil' => 'differential-diff', 425 ), 426 array( 427 $this->renderColgroup(), 428 $content, 429 )); 430 } 431 432 protected function renderInlineComment( 433 PhabricatorInlineCommentInterface $comment, 434 $on_right = false) { 435 436 return $this->buildInlineComment($comment, $on_right)->render(); 437 } 438 439 protected function buildInlineComment( 440 PhabricatorInlineCommentInterface $comment, 441 $on_right = false) { 442 443 $user = $this->getUser(); 444 $edit = $user && 445 ($comment->getAuthorPHID() == $user->getPHID()) && 446 ($comment->isDraft()); 447 $allow_reply = (bool)$user; 448 449 return id(new DifferentialInlineCommentView()) 450 ->setInlineComment($comment) 451 ->setOnRight($on_right) 452 ->setHandles($this->getHandles()) 453 ->setMarkupEngine($this->getMarkupEngine()) 454 ->setEditable($edit) 455 ->setAllowReply($allow_reply); 456 } 457 458 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |