From a90503cf9dc2760de104bdb33e0cb545f929cc34 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 4 Feb 2009 22:55:00 -0700 Subject: [PATCH] Split browse.php into dir and file components. --- chora/browse.php | 192 -------------------------------- chora/browsedir.php | 123 ++++++++++++++++++++ chora/browsefile.php | 88 +++++++++++++++ chora/co.php | 4 +- chora/cvsgraph.php | 4 +- chora/history.php | 2 +- chora/index.php | 2 +- chora/lib/Block/tree_menu.php | 2 +- chora/lib/Chora.php | 16 +-- chora/patchsets.php | 2 +- chora/templates/checkout/checkout.inc | 2 +- chora/templates/diff/hr/header.inc | 2 +- chora/templates/headerbar.inc | 2 +- chora/templates/history/branch_cell.inc | 2 +- chora/templates/history/rev.inc | 2 +- chora/templates/log/header.inc | 2 +- chora/templates/log/rev.inc | 2 +- 17 files changed, 234 insertions(+), 215 deletions(-) delete mode 100644 chora/browse.php create mode 100644 chora/browsedir.php create mode 100644 chora/browsefile.php diff --git a/chora/browse.php b/chora/browse.php deleted file mode 100644 index 10090f46a..000000000 --- a/chora/browse.php +++ /dev/null @@ -1,192 +0,0 @@ - - * @author Chuck Hagenbuch - * @package Chora - */ - -require_once dirname(__FILE__) . '/lib/base.php'; - -if (!$atdir && !$VC->isFile($fullname)) { - Chora::fatal(sprintf(_("$fullname: no such file or directory"), $where), '404 Not Found'); -} - -/* Scripts needed for both dirs and files. */ -Horde::addScriptFile('prototype.js', 'horde', true); -Horde::addScriptFile('tables.js', 'horde', true); - -if ($atdir) { - $rev = $VC->hasFeature('snapshots') - ? Util::getFormData('rev') - : null; - - try { - $atticFlags = (bool)$acts['sa']; - $dir = $VC->getDirObject($where, array('quicklog' => true, 'rev' => $rev, 'showattic' => $atticFlags)); - $dir->applySort($acts['sbt'], $acts['ord']); - $dirList = $dir->queryDirList(); - $fileList = $dir->queryFileList($atticFlags); - } catch (Horde_Vcs_Exception $e) { - Chora::fatal($e); - } - - /* Decide what title to display. */ - $title = ($where == '') - ? $conf['options']['introTitle'] - : sprintf(_("Source Directory of /%s"), $where); - - $extraLink = $VC->hasFeature('deleted') - ? Horde::widget(Chora::url('browse', $where . '/', array('sa' => ($acts['sa'] ? 0 : 1))), $acts['sa'] ? _("Hide Deleted Files") : _("Show Deleted Files"), 'widget', '', '', $acts['sa'] ? _("Hide _Deleted Files") : _("Show _Deleted Files")) - : ''; - - $umap = array( - 'age' => Horde_Vcs::SORT_AGE, - 'rev' => Horde_Vcs::SORT_REV, - 'name' => Horde_Vcs::SORT_NAME, - 'author' => Horde_Vcs::SORT_AUTHOR - ); - - foreach ($umap as $key => $val) { - $arg = array('sbt' => $val); - if ($acts['sbt'] == $val) { - $arg['ord'] = !$acts['ord']; - } - $url[$key] = Chora::url('browse', $where . '/', $arg); - } - - /* Print out the directory header. */ - $printAllCols = count($fileList); - - require CHORA_TEMPLATES . '/common-header.inc'; - require CHORA_TEMPLATES . '/menu.inc'; - require CHORA_TEMPLATES . '/headerbar.inc'; - require CHORA_TEMPLATES . '/directory/header.inc'; - - /* Unless we're at the top, display the 'back' bar. */ - if ($where != '') { - $url = Chora::url('browse', preg_replace('|[^/]+$|', '', $where)); - require CHORA_TEMPLATES . '/directory/back.inc'; - } - - /* Display all the directories first. */ - if ($dirList) { - echo ''; - foreach ($dirList as $currentDir) { - if ($conf['hide_restricted'] && Chora::isRestricted($currentDir)) { - continue; - } - $url = Chora::url('browse', $where . '/' . $currentDir . '/'); - $currDir = Text::htmlAllSpaces($currentDir); - require CHORA_TEMPLATES . '/directory/dir.inc'; - } - echo ''; - } - - /* Display all of the files in this directory */ - if ($fileList) { - echo ''; - foreach ($fileList as $currFile) { - if ($conf['hide_restricted'] && - Chora::isRestricted($currFile->queryName())) { - continue; - } - $lg = $currFile->queryLastLog(); - $realname = $currFile->queryName(); - $mimeType = Horde_Mime_Magic::filenameToMIME($realname); - - $icon = Horde_Mime_Viewer::getIcon($mimeType); - - $author = Chora::showAuthorName($lg->queryAuthor()); - $head = $currFile->queryHead(); - $date = $lg->queryDate(); - $log = $lg->queryLog(); - $attic = $currFile->isDeleted(); - $fileName = $where . ($attic ? '/' . 'Attic' : '') . '/' . $realname; - $name = Text::htmlAllSpaces($realname); - $url = Chora::url('browse', $fileName); - $readableDate = Chora::readableTime($date); - if ($log) { - $shortLog = str_replace("\n", ' ', trim(substr($log, 0, $conf['options']['shortLogLength'] - 1))); - if (strlen($log) > 80) { - $shortLog .= '...'; - } - } - require CHORA_TEMPLATES . '/directory/file.inc'; - } - echo ''; - } - - echo ''; - require $registry->get('templates', 'horde') . '/common-footer.inc'; - exit; -} - -/* Showing a file. */ -$onb = Util::getFormData('onb'); -try { - $fl = $VC->getFileObject($where, array('branch' => $onb)); -} catch (Horde_Vcs_Exception $e) { - Chora::fatal($e); -} - -$title = sprintf(_("Revisions for %s"), $where); - -$extraLink = Chora::getFileViews($where, 'browse'); -$logs = $fl->queryLogs(); -$first = end($logs); -$diffValueLeft = $first->queryRevision(); -$diffValueRight = $fl->queryRevision(); - -$sel = ''; -foreach ($fl->querySymbolicRevisions() as $sm => $rv) { - $sel .= ''; -} - -$selAllBranches = ''; -if ($VC->hasFeature('branches')) { - foreach (array_keys($fl->queryBranches()) as $sym) { - $selAllBranches .= ''; - } -} - -Horde::addScriptFile('QuickFinder.js', 'horde', true); -Horde::addScriptFile('revlog.js', 'chora', true); -require CHORA_TEMPLATES . '/common-header.inc'; -require CHORA_TEMPLATES . '/menu.inc'; -require CHORA_TEMPLATES . '/headerbar.inc'; -require CHORA_TEMPLATES . '/log/header.inc'; - -$i = 0; -reset($logs); -while (list(,$lg) = each($logs)) { - $rev = $lg->queryRevision(); - $branch_info = $lg->queryBranch(); - - $textUrl = Chora::url('co', $where, array('r' => $rev)); - $commitDate = Chora::formatDate($lg->queryDate()); - $readableDate = Chora::readableTime($lg->queryDate(), true); - - $author = Chora::showAuthorName($lg->queryAuthor(), true); - $tags = Chora::getTags($lg, $where); - - if ($prevRevision = $fl->queryPreviousRevision($lg->queryRevision())) { - $diffUrl = Chora::url('diff', $where, array('r1' => $prevRevision, 'r2' => $rev)); - } else { - $diffUrl = ''; - } - - $logMessage = Chora::formatLogMessage($lg->queryLog()); - - require CHORA_TEMPLATES . '/log/rev.inc'; - - if (($i++ > 100) && !Util::getFormData('all')) { - break; - } -} -require CHORA_TEMPLATES . '/log/footer.inc'; -require $registry->get('templates', 'horde') . '/common-footer.inc'; diff --git a/chora/browsedir.php b/chora/browsedir.php new file mode 100644 index 000000000..8fe1f483b --- /dev/null +++ b/chora/browsedir.php @@ -0,0 +1,123 @@ + + * @author Chuck Hagenbuch + * @package Chora + */ + +require_once dirname(__FILE__) . '/lib/base.php'; + +if (!$atdir) { + require CHORA_BASE . '/browsefile.php'; + exit; +} + +$rev = $VC->hasFeature('snapshots') + ? Util::getFormData('rev') + : null; + +try { + $atticFlags = (bool)$acts['sa']; + $dir = $VC->getDirObject($where, array('quicklog' => true, 'rev' => $rev, 'showattic' => $atticFlags)); + $dir->applySort($acts['sbt'], $acts['ord']); + $dirList = $dir->queryDirList(); + $fileList = $dir->queryFileList($atticFlags); +} catch (Horde_Vcs_Exception $e) { + Chora::fatal($e); +} + +/* Decide what title to display. */ +$title = ($where == '') + ? $conf['options']['introTitle'] + : sprintf(_("Source Directory of /%s"), $where); + +$extraLink = $VC->hasFeature('deleted') + ? Horde::widget(Chora::url('browsedir', $where . '/', array('sa' => ($acts['sa'] ? 0 : 1))), $acts['sa'] ? _("Hide Deleted Files") : _("Show Deleted Files"), 'widget', '', '', $acts['sa'] ? _("Hide _Deleted Files") : _("Show _Deleted Files")) + : ''; + +$umap = array( + 'age' => Horde_Vcs::SORT_AGE, + 'rev' => Horde_Vcs::SORT_REV, + 'name' => Horde_Vcs::SORT_NAME, + 'author' => Horde_Vcs::SORT_AUTHOR +); + +foreach ($umap as $key => $val) { + $arg = array('sbt' => $val); + if ($acts['sbt'] == $val) { + $arg['ord'] = !$acts['ord']; + } + $url[$key] = Chora::url('browsedir', $where . '/', $arg); +} + +/* Print out the directory header. */ +$printAllCols = count($fileList); + +Horde::addScriptFile('prototype.js', 'horde', true); +Horde::addScriptFile('tables.js', 'horde', true); +require CHORA_TEMPLATES . '/common-header.inc'; +require CHORA_TEMPLATES . '/menu.inc'; +require CHORA_TEMPLATES . '/headerbar.inc'; +require CHORA_TEMPLATES . '/directory/header.inc'; + +/* Unless we're at the top, display the 'back' bar. */ +if ($where != '') { + $url = Chora::url('browsedir', preg_replace('|[^/]+$|', '', $where)); + require CHORA_TEMPLATES . '/directory/back.inc'; +} + +/* Display all the directories first. */ +if ($dirList) { + echo ''; + foreach ($dirList as $currentDir) { + if ($conf['hide_restricted'] && Chora::isRestricted($currentDir)) { + continue; + } + $url = Chora::url('browsedir', $where . '/' . $currentDir . '/'); + $currDir = Text::htmlAllSpaces($currentDir); + require CHORA_TEMPLATES . '/directory/dir.inc'; + } + echo ''; +} + +/* Display all of the files in this directory */ +if ($fileList) { + echo ''; + foreach ($fileList as $currFile) { + if ($conf['hide_restricted'] && + Chora::isRestricted($currFile->queryName())) { + continue; + } + $lg = $currFile->queryLastLog(); + $realname = $currFile->queryName(); + $mimeType = Horde_Mime_Magic::filenameToMIME($realname); + + $icon = Horde_Mime_Viewer::getIcon($mimeType); + + $author = Chora::showAuthorName($lg->queryAuthor()); + $head = $currFile->queryHead(); + $date = $lg->queryDate(); + $log = $lg->queryLog(); + $attic = $currFile->isDeleted(); + $fileName = $where . ($attic ? '/' . 'Attic' : '') . '/' . $realname; + $name = Text::htmlAllSpaces($realname); + $url = Chora::url('browsefile', $fileName); + $readableDate = Chora::readableTime($date); + if ($log) { + $shortLog = str_replace("\n", ' ', trim(substr($log, 0, $conf['options']['shortLogLength'] - 1))); + if (strlen($log) > 80) { + $shortLog .= '...'; + } + } + require CHORA_TEMPLATES . '/directory/file.inc'; + } + echo ''; +} + +echo ''; +require $registry->get('templates', 'horde') . '/common-footer.inc'; diff --git a/chora/browsefile.php b/chora/browsefile.php new file mode 100644 index 000000000..fbf9f6601 --- /dev/null +++ b/chora/browsefile.php @@ -0,0 +1,88 @@ + + * @author Chuck Hagenbuch + * @package Chora + */ + +require_once dirname(__FILE__) . '/lib/base.php'; + +if ($atdir) { + require CHORA_BASE . '/browsedir.php'; + exit; +} + +if (!$VC->isFile($fullname)) { + Chora::fatal(sprintf(_("$fullname: no such file or directory"), $where), '404 Not Found'); +} + +$onb = Util::getFormData('onb'); +try { + $fl = $VC->getFileObject($where, array('branch' => $onb)); +} catch (Horde_Vcs_Exception $e) { + Chora::fatal($e); +} + +$title = sprintf(_("Revisions for %s"), $where); + +$extraLink = Chora::getFileViews($where, 'browsefile'); +$logs = $fl->queryLogs(); +$first = end($logs); +$diffValueLeft = $first->queryRevision(); +$diffValueRight = $fl->queryRevision(); + +$sel = ''; +foreach ($fl->querySymbolicRevisions() as $sm => $rv) { + $sel .= ''; +} + +$selAllBranches = ''; +if ($VC->hasFeature('branches')) { + foreach (array_keys($fl->queryBranches()) as $sym) { + $selAllBranches .= ''; + } +} + +Horde::addScriptFile('QuickFinder.js', 'horde', true); +Horde::addScriptFile('revlog.js', 'chora', true); +require CHORA_TEMPLATES . '/common-header.inc'; +require CHORA_TEMPLATES . '/menu.inc'; +require CHORA_TEMPLATES . '/headerbar.inc'; +require CHORA_TEMPLATES . '/log/header.inc'; + +$i = 0; +reset($logs); +while (list(,$lg) = each($logs)) { + $rev = $lg->queryRevision(); + $branch_info = $lg->queryBranch(); + + $textUrl = Chora::url('co', $where, array('r' => $rev)); + $commitDate = Chora::formatDate($lg->queryDate()); + $readableDate = Chora::readableTime($lg->queryDate(), true); + + $author = Chora::showAuthorName($lg->queryAuthor(), true); + $tags = Chora::getTags($lg, $where); + + if ($prevRevision = $fl->queryPreviousRevision($lg->queryRevision())) { + $diffUrl = Chora::url('diff', $where, array('r1' => $prevRevision, 'r2' => $rev)); + } else { + $diffUrl = ''; + } + + $logMessage = Chora::formatLogMessage($lg->queryLog()); + + require CHORA_TEMPLATES . '/log/rev.inc'; + + if (($i++ > 100) && !Util::getFormData('all')) { + break; + } +} +require CHORA_TEMPLATES . '/log/footer.inc'; +require $registry->get('templates', 'horde') . '/common-footer.inc'; diff --git a/chora/co.php b/chora/co.php index 968ad62ee..570511327 100644 --- a/chora/co.php +++ b/chora/co.php @@ -13,7 +13,7 @@ require_once dirname(__FILE__) . '/lib/base.php'; /* If we know we're at a directory, just go to browse.php. */ if ($atdir) { - require CHORA_BASE . '/browse.php'; + require CHORA_BASE . '/browsedir.php'; exit; } @@ -75,7 +75,7 @@ if (!$plain) { ); if ($VC->hasFeature('snapshots')) { $snapdir = dirname($file->queryPath()); - $views[] = Horde::widget(Chora::url('browse', $snapdir == '.' ? '' : $snapdir, array('rev' => $r)), _("Snapshot"), 'widget', '', '', _("_Snapshot")); + $views[] = Horde::widget(Chora::url('browsedir', $snapdir == '.' ? '' : $snapdir, array('rev' => $r)), _("Snapshot"), 'widget', '', '', _("_Snapshot")); } $extraLink = _("View:") . ' ' . implode(' | ', $views); diff --git a/chora/cvsgraph.php b/chora/cvsgraph.php index c8eb41fca..09228ef4c 100644 --- a/chora/cvsgraph.php +++ b/chora/cvsgraph.php @@ -16,7 +16,7 @@ require_once dirname(__FILE__) . '/lib/base.php'; // Exit if cvsgraph isn't active or it's not supported. if (empty($conf['paths']['cvsgraph']) || !$VC->hasFeature('branches')) { - header('Location: ' . Chora::url('browse', $where)); + header('Location: ' . Chora::url('browsefile', $where)); exit; } @@ -61,7 +61,7 @@ if (Util::getFormData('show_image')) { 'M' => 'graphMap', 'r' => $root, '0' => '&', - '1' => Chora::url('browse', $where, array('dummy' => 'true')), + '1' => Chora::url('browsefile', $where, array('dummy' => 'true')), '2' => Chora::url('diff', $where, array('dummy' =>'true')), '3' => Chora::url('co', $where, array('dummy' => 'true')), ); diff --git a/chora/history.php b/chora/history.php index 1962f07a2..481ad5750 100644 --- a/chora/history.php +++ b/chora/history.php @@ -16,7 +16,7 @@ Chora::fatal('History display is currently broken', '500 Internal Server Error') /* Exit if it's not supported. */ if (!$VC->hasFeature('branches')) { - header('Location: ' . Chora::url('browse', $where)); + header('Location: ' . Chora::url('browsefile', $where)); exit; } diff --git a/chora/index.php b/chora/index.php index 19ee8171c..05362c2fc 100644 --- a/chora/index.php +++ b/chora/index.php @@ -23,4 +23,4 @@ if (!$chora_configured) { array('sourceroots.php' => 'This file defines all of the source repositories that you wish Chora to display.')); } -require CHORA_BASE . '/browse.php'; +require CHORA_BASE . '/browsedir.php'; diff --git a/chora/lib/Block/tree_menu.php b/chora/lib/Block/tree_menu.php index 8ef543e9b..fc4e3d047 100644 --- a/chora/lib/Block/tree_menu.php +++ b/chora/lib/Block/tree_menu.php @@ -25,7 +25,7 @@ class Horde_Block_chora_tree_menu extends Horde_Block array( 'icon' => 'folder.png', 'icondir' => $GLOBALS['registry']->getImageDir('horde') . '/tree', - 'url' => Chora::url('browse', '', array('rt' => $key)) + 'url' => Chora::url('browsedir', '', array('rt' => $key)) ) ); } diff --git a/chora/lib/Chora.php b/chora/lib/Chora.php index 85ee6a011..4f1420b62 100644 --- a/chora/lib/Chora.php +++ b/chora/lib/Chora.php @@ -186,7 +186,7 @@ class Chora foreach ($dirs as $i => $dir) { if (!empty($dir)) { - $bar .= '/ '. Text::htmlallspaces($dir) . ' '; + $bar .= '/ '. Text::htmlallspaces($dir) . ' '; } } @@ -241,7 +241,7 @@ class Chora $script .= '.php'; if ($GLOBALS['conf']['options']['urls'] == 'rewrite') { - if ($script == 'browse.php') { + if (in_array($script, array('browse.php', 'browsedir.php'))) { $script = $uri; if (substr($script, 0, 1) == '/') { $script = substr($script, 1); @@ -337,7 +337,7 @@ class Chora $arr = array(); foreach ($sourceroots as $key => $val) { if ($GLOBALS['sourceroot'] != $key) { - $arr[] = ''; + $arr[] = ''; } } @@ -425,7 +425,7 @@ class Chora { require_once 'Horde/Menu.php'; $menu = new Menu(); - $menu->add(self::url('browse'), _("_Browse"), 'chora.png'); + $menu->add(self::url('browsedir'), _("_Browse"), 'chora.png'); return $menu->render(); } @@ -433,16 +433,16 @@ class Chora * Generate the link used for various file-based views. * * @param string $where The current file path. - * @param string $current The current view ('browse', 'patchsets', + * @param string $current The current view ('browsefile', 'patchsets', * 'history', 'cvsgraph', or 'stats'). * * @return array An array of file view links. */ static public function getFileViews($where, $current) { - $views = ($current == 'browse') + $views = ($current == 'browsefile') ? array('' . _("Logs") . '') - : array(Horde::widget(self::url('browse', $where), _("Logs"), 'widget', '', '', _("_Logs"))); + : array(Horde::widget(self::url('browsefile', $where), _("Logs"), 'widget', '', '', _("_Logs"))); if ($GLOBALS['VC']->hasFeature('patchsets')) { $views[] = ($current == 'patchsets') @@ -482,7 +482,7 @@ class Chora $tags = array(); foreach ($lg->querySymbolicBranches() as $symb => $bra) { - $tags[] = ''. htmlspecialchars($symb) . ''; + $tags[] = ''. htmlspecialchars($symb) . ''; } foreach ($lg->queryTags() as $tag) { diff --git a/chora/patchsets.php b/chora/patchsets.php index d8454f3eb..7df1e59ee 100644 --- a/chora/patchsets.php +++ b/chora/patchsets.php @@ -17,7 +17,7 @@ require_once dirname(__FILE__) . '/lib/base.php'; // Exit if patchset feature is not available. if (!$GLOBALS['VC']->hasFeature('patchsets')) { - header('Location: ' . Chora::url('browse', $where)); + header('Location: ' . Chora::url('browsefile', $where)); exit; } diff --git a/chora/templates/checkout/checkout.inc b/chora/templates/checkout/checkout.inc index fd6765d54..b05523db4 100644 --- a/chora/templates/checkout/checkout.inc +++ b/chora/templates/checkout/checkout.inc @@ -5,7 +5,7 @@
  • - +
  • diff --git a/chora/templates/diff/hr/header.inc b/chora/templates/diff/hr/header.inc index e3d087eb9..568400ab1 100644 --- a/chora/templates/diff/hr/header.inc +++ b/chora/templates/diff/hr/header.inc @@ -45,7 +45,7 @@
  • - +
  • diff --git a/chora/templates/headerbar.inc b/chora/templates/headerbar.inc index 4e49ff99f..106271f64 100644 --- a/chora/templates/headerbar.inc +++ b/chora/templates/headerbar.inc @@ -3,7 +3,7 @@ - [ ] + [ ] ( ) diff --git a/chora/templates/history/branch_cell.inc b/chora/templates/history/branch_cell.inc index 56c54bf21..d8e2d69ae 100644 --- a/chora/templates/history/branch_cell.inc +++ b/chora/templates/history/branch_cell.inc @@ -1,6 +1,6 @@ :
    - +
    () diff --git a/chora/templates/history/rev.inc b/chora/templates/history/rev.inc index 6e42976b6..3146f03f9 100644 --- a/chora/templates/history/rev.inc +++ b/chora/templates/history/rev.inc @@ -1,5 +1,5 @@ - "> +
    diff --git a/chora/templates/log/header.inc b/chora/templates/log/header.inc index 67d396899..857d28818 100644 --- a/chora/templates/log/header.inc +++ b/chora/templates/log/header.inc @@ -23,7 +23,7 @@ -
    + diff --git a/chora/templates/log/rev.inc b/chora/templates/log/rev.inc index ad9f124c0..cdf066d68 100644 --- a/chora/templates/log/rev.inc +++ b/chora/templates/log/rev.inc @@ -7,7 +7,7 @@ abbrev($rev)) ?> - $val))) . htmlspecialchars($val) ?> + $val))) . htmlspecialchars($val) ?> lines)): ?> (lines) ?>) -- 2.11.0