Controller_Commitdiff.class.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * Controller for displaying a commitdiff
  4. *
  5. * @author Christopher Han <xiphux@gmail.com>
  6. * @copyright Copyright (c) 2010 Christopher Han
  7. * @package GitPHP
  8. * @subpackage Controller
  9. */
  10. class GitPHP_Controller_Commitdiff extends GitPHP_Controller_DiffBase
  11. {
  12. /**
  13. * Gets the template for this controller
  14. *
  15. * @return string template filename
  16. */
  17. protected function GetTemplate()
  18. {
  19. if ($this->Plain()) {
  20. return 'commitdiffplain.tpl';
  21. }
  22. return 'commitdiff.tpl';
  23. }
  24. /**
  25. * Gets the cache key for this controller
  26. *
  27. * @return string cache key
  28. */
  29. protected function GetCacheKey()
  30. {
  31. $key = (isset($this->params['hash']) ? $this->params['hash'] : '')
  32. . '|' . (isset($this->params['hashparent']) ? $this->params['hashparent'] : '')
  33. . '|' . (isset($this->params['sidebyside']) && ($this->params['sidebyside'] === true) ? '1' : '');
  34. return $key;
  35. }
  36. /**
  37. * Gets the name of this controller's action
  38. *
  39. * @param boolean $local true if caller wants the localized action name
  40. * @return string action name
  41. */
  42. public function GetName($local = false)
  43. {
  44. if ($local && $this->resource) {
  45. return $this->resource->translate('commitdiff');
  46. }
  47. return 'commitdiff';
  48. }
  49. /**
  50. * Loads headers for this template
  51. */
  52. protected function LoadHeaders()
  53. {
  54. parent::LoadHeaders();
  55. if ($this->Plain()) {
  56. $this->headers[] = 'Content-disposition: inline; filename="git-' . $this->params['hash'] . '.patch"';
  57. $this->preserveWhitespace = true;
  58. }
  59. }
  60. /**
  61. * Loads data for this template
  62. */
  63. protected function LoadData()
  64. {
  65. $co = $this->GetProject()->GetCommit($this->params['hash']);
  66. $this->tpl->assign('commit', $co);
  67. if (isset($this->params['hashparent'])) {
  68. $this->tpl->assign("hashparent", $this->params['hashparent']);
  69. }
  70. if (isset($this->params['sidebyside']) && ($this->params['sidebyside'] === true)) {
  71. $this->tpl->assign('sidebyside', true);
  72. }
  73. $treediff = new GitPHP_TreeDiff($this->GetProject(), $this->exe, $this->params['hash'], (isset($this->params['hashparent']) ? $this->params['hashparent'] : ''));
  74. $this->tpl->assign('treediff', $treediff);
  75. }
  76. }