From 67aea6d89ec47c1fb328666ce5b2e7951d5631ec Mon Sep 17 00:00:00 2001 From: wangyidong Date: Wed, 16 Dec 2020 17:12:32 +0800 Subject: [PATCH] * finish task #8653. --- config/filter.php | 5 +-- module/git/control.php | 4 +-- module/repo/control.php | 42 ++++++++++++++--------- module/repo/model.php | 22 ++++++++++-- module/repo/view/ajaxsidecommits.html.php | 8 ++--- module/repo/view/blame.html.php | 4 +-- module/repo/view/browse.html.php | 6 ++-- module/repo/view/diff.html.php | 4 +-- module/repo/view/log.html.php | 8 ++--- module/repo/view/revision.html.php | 2 +- module/repo/view/view.html.php | 14 ++++---- module/svn/control.php | 4 +-- 12 files changed, 75 insertions(+), 48 deletions(-) diff --git a/config/filter.php b/config/filter.php index 3d8309c5c2..5d7c737cf4 100644 --- a/config/filter.php +++ b/config/filter.php @@ -256,8 +256,9 @@ $filter->repo->default = new stdclass(); $filter->repo->diff = new stdclass(); $filter->repo->view = new stdclass(); -$filter->repo->default->get['path'] = 'reg::base64'; -$filter->repo->default->get['entry'] = 'reg::base64'; +$filter->repo->default->get['repoPath'] = 'reg::base64'; +$filter->repo->default->get['path'] = 'reg::base64'; +$filter->repo->default->get['entry'] = 'reg::base64'; $filter->repo->default->cookie['repoBranch'] = 'reg::any'; $filter->repo->diff->cookie['arrange'] = 'reg::word'; diff --git a/module/git/control.php b/module/git/control.php index c50af7f63b..5f9f64b012 100644 --- a/module/git/control.php +++ b/module/git/control.php @@ -44,7 +44,7 @@ class git extends control { $entry = $this->repo->encodePath(str_replace($repo->path, '', $path)); $oldRevision = "$revision^"; - $this->locate($this->repo->createLink('diff', "repoID=$repo->id&entry=&oldRevision=$oldRevision&revision=$revision", "entry=$entry", 'html', 'true')); + $this->locate($this->repo->createLink('diff', "repoID=$repo->id&entry=$entry&oldRevision=$oldRevision&revision=$revision", 'html', 'true')); } } } @@ -77,7 +77,7 @@ class git extends control if(strpos($path, $repo->path) === 0) { $entry = $this->repo->encodePath(str_replace($repo->path, '', $path)); - $this->locate($this->repo->createLink('view', "repoID=$repo->id&entry=&revision=$revision", "entry=$entry", 'html', true)); + $this->locate($this->repo->createLink('view', "repoID=$repo->id&entry=$entry&revision=$revision", 'html', true)); } } } diff --git a/module/repo/control.php b/module/repo/control.php index 18ed6256eb..5f1c53f907 100644 --- a/module/repo/control.php +++ b/module/repo/control.php @@ -174,11 +174,19 @@ class repo extends control */ public function view($repoID, $entry, $revision = 'HEAD', $showBug = 'false', $encoding = '') { - if($this->get->entry) $entry = $this->get->entry; + if($this->get->repoPath) $entry = $this->get->repoPath; $this->repo->setMenu($this->repos, $repoID); $this->repo->setBackSession('view', $withOtherModule = true); if($repoID == 0) $repoID = $this->session->repoID; + if($_POST) + { + $oldRevision = isset($this->post->revision[1]) ? $this->post->revision[1] : ''; + $newRevision = isset($this->post->revision[0]) ? $this->post->revision[0] : ''; + + $this->locate($this->repo->createLink('diff', "repoID=$repoID&entry=$entry&oldrevision=$oldRevision&newRevision=$newRevision")); + } + $file = $entry; $repo = $this->repo->getRepoByID($repoID); $entry = $this->repo->decodePath($entry); @@ -186,7 +194,7 @@ class repo extends control $this->scm->setEngine($repo); $info = $this->scm->info($entry, $revision); $path = $entry ? $info->path : ''; - if($info->kind == 'dir') $this->locate($this->repo->createLink('browse', "repoID=$repoID&path=&revision=$revision", "path=" . $this->repo->encodePath($path))); + if($info->kind == 'dir') $this->locate($this->repo->createLink('browse', "repoID=$repoID&path=" . $this->repo->encodePath($path) . "&revision=$revision")); $content = $this->scm->cat($entry, $revision); $entry = urldecode($entry); $pathInfo = pathinfo($entry); @@ -265,7 +273,7 @@ class repo extends control public function browse($repoID = 0, $path = '', $revision = 'HEAD', $refresh = 0) { /* Get path and refresh. */ - if($this->get->path) $path = $this->get->path; + if($this->get->repoPath) $path = $this->get->repoPath; if(empty($refresh) and $this->cookie->repoRefresh) $refresh = $this->cookie->repoRefresh; /* Set menu and session. */ @@ -291,7 +299,7 @@ class repo extends control $oldRevision = isset($this->post->revision[1]) ? $this->post->revision[1] : ''; $newRevision = isset($this->post->revision[0]) ? $this->post->revision[0] : ''; - $this->locate($this->repo->createLink('diff', "repoID=$repoID&entry=&oldrevision=$oldRevision&newRevision=$newRevision", "path=" . $this->repo->encodePath($path))); + $this->locate($this->repo->createLink('diff', "repoID=$repoID&entry=" . $this->repo->encodePath($path) . "&oldrevision=$oldRevision&newRevision=$newRevision")); } /* Cache infos. */ @@ -381,7 +389,7 @@ class repo extends control */ public function log($repoID = 0, $entry = '', $revision = 'HEAD', $type = 'dir', $recTotal = 0, $recPerPage = 50, $pageID = 1) { - if($this->get->entry) $entry = $this->get->entry; + if($this->get->repoPath) $entry = $this->get->repoPath; $this->repo->setMenu($this->repos, $repoID); $this->repo->setBackSession('log', $withOtherModule = true); if($repoID == 0) $repoID = $this->session->repoID; @@ -398,7 +406,7 @@ class repo extends control $oldRevision = isset($this->post->revision[1]) ? $this->post->revision[1] : ''; $newRevision = isset($this->post->revision[0]) ? $this->post->revision[0] : ''; - $this->locate($this->repo->createLink('diff', "repoID=$repoID&entry=&oldrevision=$oldRevision&newRevision=$newRevision", "entry=" . $this->repo->encodePath($path))); + $this->locate($this->repo->createLink('diff', "repoID=$repoID&entry=" . $this->repo->encodePath($path) . "&oldrevision=$oldRevision&newRevision=$newRevision")); } $this->scm->setEngine($repo); @@ -426,7 +434,7 @@ class repo extends control * * @param int $repoID * @param int $revision - * @param string $path + * @param string $root * @param string $type * * @access public @@ -434,6 +442,8 @@ class repo extends control */ public function revision($repoID, $revision, $root = '', $type = 'dir') { + if($this->get->repoPath) $root = $this->get->repoPath; + $this->repo->setMenu($this->repos, $repoID); $this->repo->setBackSession(); if($repoID == 0) $repoID = $this->session->repoID; @@ -475,13 +485,13 @@ class repo extends control $encodePath = $this->repo->encodePath($path); if($change['kind'] == '' or $change['kind'] == 'file') { - $change['view'] = $viewPriv ? html::a($this->repo->createLink('view', "repoID=$repoID&entry=&revision=$revision", "entry=$encodePath"), $this->lang->repo->viewA) : ''; - if($change['action'] == 'M') $change['diff'] = $diffPriv ? html::a($this->repo->createLink('diff', "repoID=$repoID&entry=&oldRevision=$oldRevision&newRevision=$revision", "entry=$encodePath"), $this->lang->repo->diffAB) : ''; + $change['view'] = $viewPriv ? html::a($this->repo->createLink('view', "repoID=$repoID&entry=$encodePath&revision=$revision"), $this->lang->repo->viewA) : ''; + if($change['action'] == 'M') $change['diff'] = $diffPriv ? html::a($this->repo->createLink('diff', "repoID=$repoID&entry=$encodePath&oldRevision=$oldRevision&newRevision=$revision"), $this->lang->repo->diffAB) : ''; } else { - $change['view'] = $viewPriv ? html::a($this->repo->createLink('browse', "repoID=$repoID&path=&revision=$revision", "path=$encodePath"), $this->lang->repo->browse) : ''; - if($change['action'] == 'M') $change['diff'] = $diffPriv ? html::a($this->repo->createLink('diff', "repoID=$repoID&entry=&oldRevision=$oldRevision&newRevision=$revision", "entry=$encodePath"), $this->lang->repo->diffAB) : ''; + $change['view'] = $viewPriv ? html::a($this->repo->createLink('browse', "repoID=$repoID&path=$encodePath&revision=$revision"), $this->lang->repo->browse) : ''; + if($change['action'] == 'M') $change['diff'] = $diffPriv ? html::a($this->repo->createLink('diff', "repoID=$repoID&entry=$encodePath&oldRevision=$oldRevision&newRevision=$revision"), $this->lang->repo->diffAB) : ''; } $changes[$path] = $change; } @@ -527,7 +537,7 @@ class repo extends control */ public function blame($repoID, $entry, $revision = 'HEAD', $encoding = '') { - if($this->get->entry) $entry = $this->get->entry; + if($this->get->repoPath) $entry = $this->get->repoPath; $this->repo->setMenu($this->repos, $repoID); if($repoID == 0) $repoID = $this->session->repoID; $repo = $this->repo->getRepoByID($repoID); @@ -574,7 +584,7 @@ class repo extends control */ public function diff($repoID, $entry = '', $oldRevision = '0', $newRevision = 'HEAD', $showBug = 'false', $encoding = '') { - if($this->get->entry) $entry = $this->get->entry; + if($this->get->repoPath) $entry = $this->get->repoPath; $this->repo->setMenu($this->repos, $repoID); if($repoID == 0) $repoID = $this->session->repoID; $file = $entry; @@ -598,7 +608,7 @@ class repo extends control } if($this->post->encoding) $encoding = $this->post->encoding; - $this->locate($this->repo->createLink('diff', "repoID=$repoID&entry=&oldrevision=$oldRevision&newRevision=$newRevision&showBug=&encoding=$encoding", 'entry=' . $this->repo->encodePath($entry))); + $this->locate($this->repo->createLink('diff', "repoID=$repoID&entry=" . $this->repo->encodePath($entry) . "&oldrevision=$oldRevision&newRevision=$newRevision&showBug=&encoding=$encoding")); } $this->scm->setEngine($repo); @@ -681,7 +691,7 @@ class repo extends control */ public function download($repoID, $path, $fromRevision = 'HEAD', $toRevision = '', $type = 'file') { - if($this->get->path) $path = $this->get->path; + if($this->get->repoPath) $path = $this->get->repoPath; $entry = $this->repo->decodePath($path); $repo = $this->repo->getRepoByID($repoID); $this->scm->setEngine($repo); @@ -896,7 +906,7 @@ class repo extends control */ public function ajaxSideCommits($repoID, $path, $type = 'dir', $recTotal = 0, $recPerPage = 8, $pageID = 1) { - if($this->get->path) $path = $this->get->path; + if($this->get->repoPath) $path = $this->get->repoPath; $this->app->loadClass('pager', $static = true); $pager = new pager($recTotal, $recPerPage, $pageID); diff --git a/module/repo/model.php b/module/repo/model.php index 6fe5b0c37c..8d33479f5f 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -776,15 +776,31 @@ class repoModel extends model * * @param string $method * @param string $params - * @param string $pathParams * @param string $viewType * @param bool $onlybody * @access public * @return string */ - public function createLink($method, $params = '', $pathParams = '', $viewType = '', $onlybody = false) + public function createLink($method, $params = '', $viewType = '', $onlybody = false) { - $link = helper::createLink('repo', $method, $params, $viewType, $onlybody); + if($this->config->requestType == 'GET') return helper::createLink('repo', $method, $params, $viewType, $onlybody); + + $parsedParams = array(); + parse_str($params, $parsedParams); + + $pathParams = ''; + $pathKey = 'path'; + if(isset($parsedParams['entry'])) $pathKey = 'entry'; + if(isset($parsedParams['file'])) $pathKey = 'file'; + if(isset($parsedParams['root'])) $pathKey = 'root'; + if(isset($parsedParams[$pathKey])) + { + $pathParams = 'repoPath=' . $parsedParams[$pathKey]; + $parsedParams[$pathKey] = ''; + } + + $params = http_build_query($parsedParams); + $link = helper::createLink('repo', $method, $params, $viewType, $onlybody); if(empty($pathParams)) return $link; $link .= strpos($link, '?') === false ? '?' : '&'; diff --git a/module/repo/view/ajaxsidecommits.html.php b/module/repo/view/ajaxsidecommits.html.php index 71df22223c..613b537b19 100644 --- a/module/repo/view/ajaxsidecommits.html.php +++ b/module/repo/view/ajaxsidecommits.html.php @@ -51,15 +51,15 @@ if(isset($entry)) $pathInfo .= '&type=file';
@@ -57,7 +57,7 @@ name, '/'); - $link = $info->kind == 'dir' ? $this->repo->createLink('browse', "repoID=$repoID", "path=" . $this->repo->encodePath($infoPath)) : $this->repo->createLink('view', "repoID=$repoID&entry=", 'entry=' . $this->repo->encodePath($infoPath)); + $link = $info->kind == 'dir' ? $this->repo->createLink('browse', "repoID=$repoID&path=" . $this->repo->encodePath($infoPath)) : $this->repo->createLink('view', "repoID=$repoID&entry=" . $this->repo->encodePath($infoPath)); echo html::a($link, $info->name, '', "title='{$info->name}'"); ?> diff --git a/module/repo/view/diff.html.php b/module/repo/view/diff.html.php index c158d36596..a3a4313291 100644 --- a/module/repo/view/diff.html.php +++ b/module/repo/view/diff.html.php @@ -35,7 +35,7 @@ foreach($paths as $pathName) { $postPath .= $pathName . '/'; - echo '/' . ' ' . html::a($this->repo->createLink('browse', "repoID=$repoID", "path=" . $this->repo->encodePath($postPath)), trim($pathName, '/')); + echo '/' . ' ' . html::a($this->repo->createLink('browse', "repoID=$repoID&path=" . $this->repo->encodePath($postPath)), trim($pathName, '/')); } echo '/' . ' ' . $fileName; if($repo->SCM == 'Git') @@ -63,7 +63,7 @@
- repo->createLink('download', "repoID=$repoID&path=&fromRevison=$oldRevision&toRevision=$newRevision&type=path", "path=" . $this->repo->encodePath($entry)), $lang->repo->downloadDiff, 'hiddenwin', "class='btn btn-sm btn-download'");?> + repo->createLink('download', "repoID=$repoID&path=" . $this->repo->encodePath($entry) . "&fromRevison=$oldRevision&toRevision=$newRevision&type=path"), $lang->repo->downloadDiff, 'hiddenwin', "class='btn btn-sm btn-download'");?>
repo->encodingList, $encoding, $lang->repo->encoding) . "", "data-toggle='dropdown'", 'btn dropdown-toggle btn-sm')?>