Controller_History.class.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Controller for displaying file history
  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_History 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. return 'history.tpl';
  31. }
  32. /**
  33. * Gets the cache key for this controller
  34. *
  35. * @return string cache key
  36. */
  37. protected function GetCacheKey()
  38. {
  39. return (isset($this->params['hash']) ? $this->params['hash'] : '') . '|' . (isset($this->params['file']) ? sha1($this->params['file']) : '') . '|' . $this->params['page'];
  40. }
  41. /**
  42. * Gets the name of this controller's action
  43. *
  44. * @param boolean $local true if caller wants the localized action name
  45. * @return string action name
  46. */
  47. public function GetName($local = false)
  48. {
  49. if ($local && $this->resource) {
  50. return $this->resource->translate('history');
  51. }
  52. return 'history';
  53. }
  54. /**
  55. * Loads data for this template
  56. */
  57. protected function LoadData()
  58. {
  59. $co = $this->GetProject()->GetCommit($this->params['hash']);
  60. $this->tpl->assign('commit', $co);
  61. $tree = $co->GetTree();
  62. $this->tpl->assign('tree', $co->GetTree());
  63. $blobhash = $tree->PathToHash($this->params['file']);
  64. if (empty($blobhash))
  65. throw new GitPHP_FileNotFoundException($this->params['file']);
  66. $blob = $this->GetProject()->GetObjectManager()->GetBlob($blobhash);
  67. $blob->SetCommit($co);
  68. $blob->SetPath($this->params['file']);
  69. $this->tpl->assign('blob', $blob);
  70. $this->tpl->assign('page',$this->params['page']);
  71. $skip = $this->params['page'] * 100;
  72. $history = new GitPHP_FileHistory($this->GetProject(), $this->params['file'], $this->exe, $co, 101, $skip);
  73. if ($history->GetCount() > 100) {
  74. $this->tpl->assign('hasmorehistory', true);
  75. $history->SetLimit(100);
  76. }
  77. $this->tpl->assign('history', $history);
  78. }
  79. }