Fixing the browser (mostly)
authorRobert Sesek <rsesek@bluestatic.org>
Mon, 9 Apr 2007 02:14:50 +0000 (02:14 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Mon, 9 Apr 2007 02:14:50 +0000 (02:14 +0000)
browse.php
global.php
includes/class_revision.php [new file with mode: 0644]
includes/controller.php [deleted file]
includes/functions.php [new file with mode: 0644]
includes/init.php
includes/repository.php
templates/default/browse_node.tpl

index 65c97499308017e958c71d0a3998a0270edfc74a..0a95e9665258bb420a84b0f084869208e11d1afa 100644 (file)
@@ -27,29 +27,15 @@ $fetchtemplates = array(
 
 require_once('./global.php');
 
-$navbar = $controller->construct_breadcrumb();
+$navbar = ConstructNavbar();
 
 // ###################################################################
 
-$latest = $controller->cachev->fetch_node();
-
-$link['log'] = $controller->href_compound('log.php');
-
-$show['head'] = ($latest['revision'] != $controller->revctx);
-if ($show['head'])
-{
-       $link['gohead'] = $controller->href_compound('browse.php', null, Paths::fetch_rev_str(false, 'HEAD'));
-       $link['diffhead'] = $controller->href_compound('diff.php', null, Paths::fetch_rev_str(true, 'HEAD', $controller->revctx));
-}
-
-$show['prev'] = ($controller->cachev->fetch_prev_revision($controller->revctx) != -1);
-if ($show['prev'])
-{
-       $link['diffprev'] = $controller->href_compound('diff.php', null, Paths::fetch_rev_str(false, $controller->revctx));
-}
+$revision = new Revision($input->in['repos'], $input->in['rev']);
 
 // ###################################################################
 
+/*
 $show['props'] = false;
 $proplist = '';
 if (sizeof($latest['properties']) > 0)
@@ -61,34 +47,21 @@ if (sizeof($latest['properties']) > 0)
                eval('$proplist .= "' . $template->fetch('property') . '";');
        }
 }
+*/
 
 // ###################################################################
 
-$revinfo = $controller->cachev->fetch_revision($controller->revctx);
+// $revinfo['message_clean'] = SVNCommon::format_log_message($revinfo['message']);
+// $revinfo['date'] = SVNCommon::format_date_string($revinfo['dateline']);
 
-$revinfo['message_clean'] = SVNCommon::format_log_message($revinfo['message']);
-$revinfo['date'] = SVNCommon::format_date_string($revinfo['dateline']);
-
-$listing = $controller->library->command('ls');
+$listing = BSXml::Parse($lib->run('ls --xml -r' . $revision->revision . ' ' . $lib->arg($repos->fetchPath($input->in['repos']) . $input->in['path']), true));
 
+BSXml::UnifyNode($listing['lists']['list']['entry']);
 $nodes = '';
-
-foreach ($listing AS $item)
+foreach ($listing['lists']['list']['entry'] AS $item)
 {
-       if ($item[ strlen($item) - 1 ] == '/')
-       {
-               $show['directory'] = true;
-               $browse = $controller->href_compound('browse.php', $item);
-       }
-       else
-       {
-               $show['directory'] = false;
-               $view = $controller->href_compound('view.php', $item);
-               $blame = $controller->href_compound('blame.php', $item);
-       }
-       
-       $log = $controller->href_compound('log.php', $item);
-       
+       $isDir = ($item['kind'] == 'dir');
+       $item = $item['name']['value'];
        eval('$nodes .= "' . $template->fetch('browse_node') . '";');
 }
 
index 7ef6af3a7fd26b645234526720718dadeb1beee3..c62433f78d0a977f4f9ff18cd093d8472828cf95 100644 (file)
 \*=====================================================================*/
 
 require_once('./includes/init.php');
-require_once('./includes/controller.php');
 
-$input->in['rev'] = $input->clean(substr($input->in['path'], strpos($input->in['path'], '@') + 1), TYPE_UINT);
-$input->in['path'] = substr($input->in['path'], 0, strpos($input->in['path'], '@'));
+require_once('./includes/functions.php');
+require_once('./includes/class_revision.php');
+
+// ###################################################################
+// define the path variables
+$atpos = strpos($input->in['path'], '@');
+$input->in['rev'] = $input->clean(substr($input->in['path'], $atpos + 1), TYPE_UINT);
+if ($atpos !== false)
+{
+       $input->in['path'] = substr($input->in['path'], 0, strpos($input->in['path'], '@'));
+}
+
+// ###################################################################
+// setup the SVN library
+require_once('./includes/class_libsvn.php');
+BSRegister::Register('lib', $lib = new LibSVN($conf['paths']['svn']));
 
 $fetchtemplates[] = 'header';
 $fetchtemplates[] = 'footer';
diff --git a/includes/class_revision.php b/includes/class_revision.php
new file mode 100644 (file)
index 0000000..30740cd
--- /dev/null
@@ -0,0 +1,87 @@
+<?php
+/*=====================================================================*\
+|| ###################################################################
+|| # ViewSVN [#]version[#]
+|| # Copyright ©2002-[#]year[#] Blue Static
+|| #
+|| # This program is free software; you can redistribute it and/or modify
+|| # it under the terms of the GNU General Public License as published by
+|| # the Free Software Foundation; version [#]gpl[#] of the License.
+|| #
+|| # This program is distributed in the hope that it will be useful, but
+|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+|| # more details.
+|| #
+|| # You should have received a copy of the GNU General Public License along
+|| # with this program; if not, write to the Free Software Foundation, Inc.,
+|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+|| ###################################################################
+\*=====================================================================*/
+
+/**
+* Revision
+*
+* This class represents one revision in a given repository
+*
+* @author              Blue Static
+* @copyright   Copyright (c)2002 - [#]year[#], Blue Static
+* @version             $Revision$
+* @package             ViewSVN
+*
+*/
+class Revision
+{
+       /**
+       * Repository path
+       * @var string
+       */
+       private $path;
+       
+       /**
+       * Repository name
+       * @var string
+       */
+       private $repos;
+       
+       /**
+       * The revision number
+       * @var integer
+       */
+       public $revision;
+       
+       // ###################################################################
+       /**
+       * Creates a new revision for a given repository and revision
+       *
+       * @param        string  Repository
+       * @param        integer Revision to get; to get HEAD, specify 0
+       */
+       public function __construct($repos, $rev = 0)
+       {
+               $this->path = BSRegister::Get('repos')->fetchPath($repos);
+               $this->repos = $repos;
+               
+               $this->_fetchRevision($rev);
+       }
+       
+       // ###################################################################
+       /**
+       * Gets the desired XML revision information from the repository
+       *
+       * @param        integer Desired revision
+       */
+       private function _fetchRevision($desired)
+       {
+               $xml = BSXml::Parse(BSRegister::Get('lib')->run('info --xml ' . ($desired > 0 ? '-r' . intval($desired) . ' ' : '') . BSRegister::Get('lib')->arg($this->path), true));
+               $this->revision = intval($xml['info']['entry']['commit']['revision']);
+       }
+}
+
+/*=====================================================================*\
+|| ###################################################################
+|| # $HeadURL$
+|| # $Id$
+|| ###################################################################
+\*=====================================================================*/
+?>
\ No newline at end of file
diff --git a/includes/controller.php b/includes/controller.php
deleted file mode 100644 (file)
index ceed0e5..0000000
+++ /dev/null
@@ -1,246 +0,0 @@
-<?php
-/*=====================================================================*\
-|| ###################################################################
-|| # ViewSVN [#]version[#]
-|| # Copyright ©2002-[#]year[#] Iris Studios, Inc.
-|| #
-|| # This program is free software; you can redistribute it and/or modify
-|| # it under the terms of the GNU General Public License as published by
-|| # the Free Software Foundation; version [#]gpl[#] of the License.
-|| #
-|| # This program is distributed in the hope that it will be useful, but
-|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-|| # more details.
-|| #
-|| # You should have received a copy of the GNU General Public License along
-|| # with this program; if not, write to the Free Software Foundation, Inc.,
-|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-|| ###################################################################
-\*=====================================================================*/
-
-/**
-* Node Controller
-*
-* This class represents one node in SVN. For each node that you need
-* to display information about, create a new instance of this class.
-* Generally, however, this one instance should be able to handle
-* the needs of the entire class.
-*
-* @author              Iris Studios, Inc.
-* @copyright   Copyright ©2002 - [#]year[#], Iris Studios, Inc.
-* @version             $Revision$
-* @package             ViewSVN
-* 
-*/
-class Controller
-{
-       /**
-       * Registry class
-       * @var  object
-       * @access       private
-       */
-       var $registry = null;
-       
-       /**
-       * Xquery layer
-       * @var  object
-       * @access       private
-       */
-       var $xquery = null;
-       
-       /**
-       * Xquery method library
-       * @var  object
-       * @access       private
-       */
-       var $library = null;
-       
-       /**
-       * cacheV layer
-       * @var  object
-       * @access       private
-       */
-       var $cachev = null;
-       
-       /**
-       * Full, universal path of the node
-       * @var  string
-       * @access       public
-       */
-       var $fullpath;
-       
-       /**
-       * Repository of the path
-       * @var  string
-       * @access       public
-       */
-       var $repos;
-       
-       /**
-       * The full path to the repository
-       * @var  string
-       * @access       public
-       */
-       var $repospath;
-       
-       /**
-       * Relative path in the repository
-       * @var  string
-       * @access       public
-       */
-       var $path;
-       
-       /**
-       * The current revision number
-       * @var  integer
-       * @access       public
-       */
-       var $revnum;
-       
-       /**
-       * The current revision as a string argument
-       * @var  string
-       * @access       public
-       */
-       var $revstr;
-       
-       /**
-       * The revision number in context for this node. For instance, r40 may be passed, but the file only has revision 38 (and that's what this would be)
-       * @var  integer
-       * @access       public
-       */
-       var $revctx;
-       
-       // ###################################################################
-       /**
-       * Constructor
-       *
-       * @param        string  The path of the node
-       */
-       function Controller($nodepath)
-       {
-               global $viewsvn;
-               
-               // variables
-               $this->fullpath = $nodepath;
-               
-               $temp = preg_split('#/#', $this->fullpath, -1, PREG_SPLIT_NO_EMPTY);
-               
-               $this->repos = $temp[0];
-               
-               unset($temp[0]);
-               $this->path = '/' . implode('/', $temp);
-               
-               // objects
-               $this->registry =& $viewsvn;
-               
-               $this->repospath = $this->registry->repos->fetch_path($this->repos);
-               
-               $this->revnum = Paths::fetch_rev_num();
-               $this->revstr = Paths::fetch_rev_str();
-               
-               require_once('./includes/shellcmd.php');
-               $this->xquery = new Shell($this);
-               
-               require_once('./includes/svnlib.php');
-               $this->library = new SVNLib($this);
-               
-               require_once('./includes/cachev.php');
-               $this->cachev = new cacheV($this);
-               
-               $this->revctx = $this->cachev->fetch_revision_context($this->revnum);
-               $this->revctx = $this->revctx['revision'];
-       }
-       
-       // ###################################################################
-       /**
-       * Produces a link href that allows for a completely different path
-       * than the one in the controller. This is used for navigating upstream.
-       *
-       * @access       public
-       *
-       * @param        string  Base path (e.g. browse.php)
-       * @param        string  New relative path
-       *
-       * @return       string  Constructed path
-       */
-       function href_struct($base, $path)
-       {
-               $url = Paths::fetch_arguments($base);
-               $path = Paths::sanitize($path);
-               
-               return $this->registry->path . '/' . $url[0] . '/' . $this->repos . ($path{0} != '/' ? '/' : '') . $path . ($url[1] ? '?' . $url[1] : '');
-       }
-       
-       // ###################################################################
-       /**
-       * Compounds a path by adding another level. This is used for navigating
-       * downstream.
-       *
-       * @access       public
-       *
-       * @param        string  Base path (e.g. browse.php)
-       * @param        string  Attach path (or none for current)
-       * @param        bool    Attach a given revision string, null for none
-       *
-       * @return       string  Constructed path
-       */
-       function href_compound($base, $attach = null, $revstr = null)
-       {
-               $url = Paths::fetch_arguments($base . ($revstr === null ? ((strpos($base, '?') !== false) ? '&' . $this->revstr : $this->revstr) : $revstr));
-               
-               if ($attach === null)
-               {
-                       $path = $this->path;
-               }
-               else
-               {
-                       $attach = Paths::sanitize($attach);
-                       $path = $this->path . (($attach[0] != '/' AND $this->path[ strlen($this->path) - 1 ] != '/') ? '/' : '') . $attach;
-               }
-               
-               return $this->href_struct($base . ($url[1] ? '?' . $url[1] : ''), $path);
-       }
-       
-       // ###################################################################
-       /**
-       * Create path breadcrumb
-       *
-       * @access       public
-       *
-       * @return       string  Breadcrumb HTML
-       */
-       function construct_breadcrumb()
-       {
-               $html = '/ ';
-               
-               $temp = preg_split('#/#', $this->fullpath, -1, PREG_SPLIT_NO_EMPTY);
-               $count = sizeof($temp) - 1;
-               
-               $donerepos = false;
-               
-               foreach ($temp AS $val => $item)
-               {
-                       if ($donerepos != false)
-                       {
-                               $itembit .= $item;
-                               $this->registry->debug($item . " > " . $itembit);
-                               $itembit .= (($count != $val OR $this->cachev->isdir($itembit)) ? '/' : '');
-                       }
-                       
-                       $donerepos = true;
-                       $html .= '<a href="' . $this->href_struct('browse.php' . $this->revstr, ($val == 0 ? '' : $itembit)) . '">' . $item . '</a>'. ($count != $val ? ' / ' : '');
-               }
-               
-               return $html;
-       }
-}
-
-/*=====================================================================*\
-|| ###################################################################
-|| # $HeadURL$
-|| # $Id$
-|| ###################################################################
-\*=====================================================================*/
-?>
\ No newline at end of file
diff --git a/includes/functions.php b/includes/functions.php
new file mode 100644 (file)
index 0000000..cf35e0b
--- /dev/null
@@ -0,0 +1,54 @@
+<?php
+/*=====================================================================*\
+|| ###################################################################
+|| # ViewSVN [#]version[#]
+|| # Copyright ©2002-[#]year[#] Blue Static
+|| #
+|| # This program is free software; you can redistribute it and/or modify
+|| # it under the terms of the GNU General Public License as published by
+|| # the Free Software Foundation; version [#]gpl[#] of the License.
+|| #
+|| # This program is distributed in the hope that it will be useful, but
+|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+|| # more details.
+|| #
+|| # You should have received a copy of the GNU General Public License along
+|| # with this program; if not, write to the Free Software Foundation, Inc.,
+|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+|| ###################################################################
+\*=====================================================================*/
+
+// ###################################################################
+/**
+* Constructs the navbar from the given path elememnts. The current
+* element is never selectable
+*
+* @return      string  Compiled HTML navigation bar
+*/
+function ConstructNavbar()
+{
+       $path = preg_split('#/#', BSRegister::Get('input')->in['path'], -1, PREG_SPLIT_NO_EMPTY);
+       if (empty($path))
+       {
+               return '<strong>/</strong>';
+       }
+       
+       $html = '';
+       $build = '';
+       foreach ($path AS $part)
+       {
+               $build .= '/' . $part;
+               $html .= '/ <a href="' . BSRegister::Get('webpath') .  '/browse/' . BSRegister::Get('input')->in['repos'] . ':' . $build . '"><strong>' . $part . '</strong></a> ';
+       }
+       
+       return $html;
+}
+
+/*=====================================================================*\
+|| ###################################################################
+|| # $HeadURL$
+|| # $Id$
+|| ###################################################################
+\*=====================================================================*/
+?>
\ No newline at end of file
index 140fe13b50be73611fbe510ce0baf96f88d60b12..dbc0a53687bf4aff4481c60ede50b9ad5cd4a917 100644 (file)
@@ -43,6 +43,8 @@ require_once('ISSO/Register.php');
 require_once('ISSO/Functions.php');
 require_once('ISSO/Xml.php');
 
+BSRegister::SetDebug($debug);
+
 BSRegister::Register('db', $db = BSRegister::LoadModule('DbMySql'));
 $db->connect($conf['db']['server'], $conf['db']['user'], $conf['db']['pass'], $conf['db']['name'], 0);
 
index 90da906760c1e8ff0c267791d03c952bb28926ae..ff864542856faaac45f2bfa55c9685ad1ebf9565 100644 (file)
@@ -93,7 +93,7 @@ class Repository
                
                if (sizeof($this->repositories) < 1)
                {
-                       $viewsvn->trigger->error($viewsvn->lang->string('There are no valid repositories'));
+                       $viewsvn->trigger->error(_('There are no valid repositories'));
                }
        }
        
@@ -112,19 +112,17 @@ class Repository
        /**
        * Returns a path to a repository
        *
-       * @access       public
-       *
        * @param        string  Repository name
        *
        * @return       string  Full path to the repository
        */
-       function fetch_path($repository = '')
+       public function fetchPath($repository = '')
        {
                global $viewsvn;
                
-               if (!in_array($repository, $this->fetch_list()))
+               if (!in_array($repository, $this->repositories))
                {
-                       $viewsvn->trigger->error($viewsvn->lang->string('Invalid repository name specified'));
+                       $viewsvn->trigger->error(_('Invalid repository name specified'));
                }
                
                if ($this->container)
@@ -141,18 +139,16 @@ class Repository
        /**
        * Verifies a path inside a repository
        *
-       * @access       public
-       *
        * @param        string  Repository name
        * @param        string  Path
        *
        * @return       bool    Validity
        */
-       function verify($repos, $path)
+       public function verify($repos, $path)
        {
                global $viewsvn;
                
-               if ($repospath = $this->fetch_path($repos))
+               if ($repospath = $this->fetchPath($repos))
                {
                        return true;
                }
index c2102a7538b63fb5734a6e70ab72013512e5a59b..d67275c625f2f6c6eab8c5dca61ed0107225c43e 100644 (file)
@@ -1,11 +1,11 @@
 <div class="content" style="border-width: 0px 1px 1px 1px">
-       <if condition="$show['directory']">
-               <a href="$browse"><strong>$item</strong></a>
+       <if condition="$isDir">
+               <a href="{BSRegister::Get('webpath')}/browse/{$input->in['repos']}:{$input->in['path']}/$item"><strong>$item/</strong></a>
        <else />
-               <a href="$view">$item</a>
+               <a href="{BSRegister::Get('webpath')}/view/{$input->in['repos']}:{$input->in['path']}/$item">$item</a>
        </if>
-       <span class="nodelink">
-               <if condition="!$show['directory']"><a href="$blame">{@"Blame"}</a> - </if>
+       <!-- <span class="nodelink">
+               <if condition="$isDir"><a href="$blame">{@"Blame"}</a> - </if>
                <a href="$log">{@"View Log"}</a>
-       </span>
+       </span> -->
 </div>
\ No newline at end of file