Controller_Log.class.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * Controller for displaying a log
  4. *
  5. * @author Christopher Han
  6. * @copyright Copyright (c) 2010 Christopher Han
  7. * @package GitPHP
  8. * @subpackage Controller
  9. */
  10. class GitPHP_Controller_Log extends GitPHP_ControllerBase
  11. {
  12. /**
  13. * Initialize controller
  14. */
  15. public function Initialize()
  16. {
  17. parent::Initialize();
  18. if (empty($this->params['hash']))
  19. $this->params['hash'] = 'HEAD';
  20. if (empty($this->params['page']))
  21. $this->params['page'] = 0;
  22. }
  23. /**
  24. * Gets the template for this controller
  25. *
  26. * @return string template filename
  27. */
  28. protected function GetTemplate()
  29. {
  30. if (isset($this->params['short']) && ($this->params['short'] === true)) {
  31. return 'shortlog.tpl';
  32. }
  33. return 'log.tpl';
  34. }
  35. /**
  36. * Gets the cache key for this controller
  37. *
  38. * @return string cache key
  39. */
  40. protected function GetCacheKey()
  41. {
  42. return $this->params['hash'] . '|' . $this->params['page'] . '|' . (isset($this->params['mark']) ? $this->params['mark'] : '');
  43. }
  44. /**
  45. * Gets the name of this controller's action
  46. *
  47. * @param boolean $local true if caller wants the localized action name
  48. * @return string action name
  49. */
  50. public function GetName($local = false)
  51. {
  52. if (isset($this->params['short']) && ($this->params['short'] === true)) {
  53. if ($local && $this->resource) {
  54. return $this->resource->translate('shortlog');
  55. }
  56. return 'shortlog';
  57. }
  58. if ($local && $this->resource) {
  59. return $this->resource->translate('log');
  60. }
  61. return 'log';
  62. }
  63. /**
  64. * Loads data for this template
  65. */
  66. protected function LoadData()
  67. {
  68. $commit = $this->GetProject()->GetCommit($this->params['hash']);
  69. $this->tpl->assign('commit', $commit);
  70. $this->tpl->assign('head', $this->GetProject()->GetHeadCommit());
  71. $this->tpl->assign('page',$this->params['page']);
  72. //$compat = $this->GetProject()->GetCompat();
  73. $skip = $this->params['page'] * 100;
  74. $strategy = null;
  75. //if ($compat || ($skip > $this->config->GetValue('largeskip'))) {
  76. $strategy = new GitPHP_LogLoad_Git($this->exe);
  77. //} else {
  78. // $strategy = new GitPHP_LogLoad_Raw();
  79. //}
  80. $revlist = new GitPHP_Log($this->GetProject(), $commit, $strategy, 101, $skip);
  81. if ($revlist->GetCount() > 100) {
  82. $this->tpl->assign('hasmorerevs', true);
  83. $revlist->SetLimit(100);
  84. }
  85. $this->tpl->assign('revlist', $revlist);
  86. if (isset($this->params['mark'])) {
  87. $this->tpl->assign('mark', $this->GetProject()->GetCommit($this->params['mark']));
  88. }
  89. }
  90. }