changeset 11:2ec108f96fad

Cleaned up config. UI tidy up. Commenting. Still missing caching and concurrency checks.
author joshjcarrier
date Thu, 13 May 2010 23:28:00 -0700
parents 0e7e4cead7c9
children f412765393c9
files admin/application/config/hgphp.php admin/application/controllers/hgdir.php admin/application/libraries/hgconf2ini.php admin/application/libraries/hgphp.php admin/application/views/repo_directory.php admin/application/views/repository.php admin/themes/mercurial/views/coal.php
diffstat 7 files changed, 167 insertions(+), 96 deletions(-) [+]
line wrap: on
line diff
--- a/admin/application/config/hgphp.php	Thu May 13 21:16:14 2010 -0700
+++ b/admin/application/config/hgphp.php	Thu May 13 23:28:00 2010 -0700
@@ -2,6 +2,7 @@
 
 /*
  * Global permission levels, which override the authenticated user's permissions.
+ * For when you want to completely lock down access.
  */
 $config['hgwebconf_allow_repo_create'] = true;
 $config['hgwebconf_allow_repo_edit'] = false;
@@ -11,17 +12,49 @@
  * Accessing the Mercurial repository.
  * This management tool assumes all Mercurial repositories reside in one location.
  */
-$config['hgwebconf_path'] = './../cgi-bin/hgweb.config';
-$config['repositories_rel_dir'] = './../cgi-bin/'; // relative to CI index.php
+$config['repositories_abs_dir'] = '/host/Users/jcarrier/workspace/hg-php.joshjcarrier.com/cgi-bin/'; // absolute path
+
 
+/******************
+ * HGRC Configuration
+ ****************************/
 /*
- * Hgweb.config prepended collection item's path
+ * Default available configuration of HGRC.
  */
-$config['repositories_abs_dir'] = '/home/joshjca1/public_html/hg-php.joshjcarrier.com/cgi-bin/'; // absolute path
-
+$config['hgrc_default_arr'] = array(
+		'paths' => array(
+			'default' 			=> 	'http://localhost' // no trailing slash
+		),
+			
+		'web' => array(
+			'allow_archive' 	=> 	'',
+			'allow_push' 		=> 	'',
+			'allowpull' 		=> 	'false',
+			'allow_read' 		=> 	'',
+			'contact' 			=> 	'',
+			'description' 		=> 	'',
+			'name' 				=> 	'', // project name automatically appended
+			'push_ssl' 			=> 	'false',
+			'style' 			=> 	'',
+		)
+	);
+	
+/*
+ * HGRC config which are booleans
+ */
+$config['hgrc_bools_arr'] = array(
+		'web' => array(
+			'allowpull',
+			'push_ssl'
+		)
+	);
+	
+/***********************
+ * Not recommended to change once deployed beyond this point
+ *****************************/
+	
 /*
  * Working directory
  */
 $config['compatability_delimiter'] = '----';
-$config['lock_dir'] = './lock/';
-
+$config['lock_dir'] = './lock/';
\ No newline at end of file
--- a/admin/application/controllers/hgdir.php	Thu May 13 21:16:14 2010 -0700
+++ b/admin/application/controllers/hgdir.php	Thu May 13 23:28:00 2010 -0700
@@ -25,7 +25,7 @@
 			$this->delete();
 		}		
 		
-		$this->template->title('Repository Directory', 'Mercurial Repository Manager');
+		$this->template->title('Directory', 'Mercurial Repository Manager');
 
 		$lsdir = $this->hgphp->lsdir();
 		$this->template->build('repo_directory', array('lsdir'=>$lsdir));
--- a/admin/application/libraries/hgconf2ini.php	Thu May 13 21:16:14 2010 -0700
+++ b/admin/application/libraries/hgconf2ini.php	Thu May 13 23:28:00 2010 -0700
@@ -3,8 +3,8 @@
 /**
  * CodeIgniter Mercurial Config Parser Class
  * 
- * Overcomes general PHP ini parsing limitation due to invalid characters in hgwebdir.conf 'Collection' keys when
- * generating key-value pairs, and handles concurrency.
+ * Overcomes general PHP ini parsing limitation due to invalid characters in hgweb.conf 'Collection' keys when
+ * generating key-value pairs, and handles concurrency. Also handles per-repository HGRC configuration.
  * 
  * @package        	CodeIgniter
  * @subpackage    	Libraries
@@ -42,22 +42,39 @@
 	
 	
 	/**
-	 * Scans Mercurial's webconf.config configuration file and returns
+	 * getHgWebDirConfig
+	 * Scans Mercurial's hgweb.conf configuration file and returns
 	 * representation in key/value pairs.
+	 * @param fs_hgwebdir (optional) name of the config file used for Hg directory listings
+	 * @return multi-dimensional array representing Hg directory config file (see PHP ini parsing), FALSE otherwise
 	 */
-	function getHgWebDirConfig($fs_hgwebdir = 'hgwebdir.config')
+	function getHgWebDirConfig($fs_hgwebdir = 'hgweb.config')
 	{
-		$hgwebconf_all = $this->__hgwebconf_compat_load();
+		$hgwebconf_all = $this->__hgwebconf_compat_load($fs_hgwebdir);
 		
 		return $hgwebconf_all;
 	}
 	
-	function setHgWebDirConfig($hg_hgwebdirconfig, $fs_hgwebdir = 'hgwebdir.config')
+	/**
+	 * setHgWebDirConfig
+	 * Converts a multi-dimensional array representing a Hg directory config file (see PHP ini parsing) to file
+	 * @param hg_hgwebdirconfig multi-dimensional array representing a Hg directory config file
+	 * @param fs_hgwebdir (optional) name of the config file used for Hg directory listings
+	 * @return TRUE on success, FALSE otherwise
+	 */
+	function setHgWebDirConfig($hg_hgwebdirconfig, $fs_hgwebdir = 'hgweb.config')
 	{
 		return $this->__hgwebconf_compat_persist($hg_hgwebdirconfig);
 	}
 	
-	function getHgWebDirCollections($fs_hgwebdir = 'hgwebdir.config')
+	/**
+	 * getHgWebDirCollections
+	 * Scans Mercurial's hgweb.conf configuration file and returns
+	 * a single associative array whose key/value pairs are the names of each listed repository
+	 * @param fs_hgwebdir (optional) name of the config file used for Hg directory listings
+	 * @return a single associative array whose key/value pairs are the names of each listed repository, FALSE otherwise
+	 */
+	function getHgWebDirCollections($fs_hgwebdir = 'hgweb.config')
 	{
 		$hgwebconf_all = $this->getHgWebDirConfig($fs_hgwebdir);
 		
@@ -65,9 +82,14 @@
 	}
 	
 	/**
-	 * Keys in hg_collections are project names.
+	 * setHgWebDirCollections
+	 * Replaces the current directory config collections with ones represented by a single associative array whose key/value pairs 
+	 * are the names of each listed repository
+	 * @param hg_collections a single associative array whose key/value pairs are the names of each listed repository
+	 * @param fs_hgwebdir (optional) name of the config file used for Hg directory listings
+	 * @return TRUE on success, FALSE otherwise
 	 */
-	function setHgWebDirCollections($hg_collections, $fs_hgwebdir = 'hgwebdir.config')
+	function setHgWebDirCollections($hg_collections, $fs_hgwebdir = 'hgweb.config')
 	{
 		$hgwebconf_all = $this->getHgWebDirConfig($fs_hgwebdir);
 		
@@ -76,14 +98,21 @@
 		return $this->setHgWebDirConfig($hgwebconf_all, $fs_hgwebdir);
 	}
 	
+	/**
+	 * getHGRC
+	 * Scans a Mercurial repository's HGRC configuration file into a multi-dimensional array representing 
+	 * Hg directory config file (see PHP ini parsing)
+	 * @param r_name name of the repository containing the target HGRC file
+	 * @return a multi-dimensional array representing HGRC configuration file, FALSE otherwise
+	 */
 	function getHGRC($r_name)
 	{
-		$hgrc = $this->_repositories_rel_dir . $r_name . '/.hg/hgrc';
+		$hgrc = $this->_repositories_abs_dir . $r_name . '/.hg/hgrc';
 		
 		$hgrc_all = @parse_ini_file($hgrc, true);
-		
-		$bool_keys = array('web'=>array('push_ssl'));
-		
+
+		// help out the php ini parser (remove PHP 5.3 dependency on SCANNER_RAW) detecting true/false values
+		$bool_keys = $this->_hgrc_bools_arr;
 		foreach($bool_keys as $collection => $collection_keys)
 		{
 			foreach($collection_keys as $key)
@@ -98,18 +127,39 @@
 					{
 						$hgrc_all[$collection][$key] = 'false';
 					}
-			}
+				}
 			}
 		}
 		
-		return $hgrc_all;
+		// ensures new (default) hgrc keys are made available, retaining old ones
+		$hgrc_all_sorted = array();
+		foreach($hgrc_all as $collection_name => $collection)
+		{
+			$hgrc_all_sorted[$collection_name] = array_merge($this->_hgrc_default_arr[$collection_name], $hgrc_all[$collection_name]);
+		}
+		
+		return $hgrc_all_sorted;
 	}
 	
+	/**
+	 * setHGRC
+	 * Replaces the current HGRC file with one generated represented by a multi-dimensional array
+	 * @param r_name name of the repository containing the target HGRC file
+	 * @param hgrc_data multi-array representation of the new HGRC file
+	 * @return TRUE on success, FALSE otherwise
+	 */
 	function setHGRC($r_name, $hgrc_data)
 	{
-		$hgrc = $this->_repositories_rel_dir . $r_name . '/.hg/hgrc';
+		$hgrc = $this->_repositories_abs_dir . $r_name . '/.hg/hgrc';
 		
 		$hgrc_new_ini = ';Generated by Hg-PHP Mercurial Repository Manager';
+		
+		// order before saving
+		foreach($hgrc_data as $collection_name => $collection)
+		{
+			ksort($hgrc_data[$collection_name]);
+		}
+		
 		// generate ini string
 		foreach($hgrc_data as $ini_section_name => $ini_section_items)
 		{
@@ -145,34 +195,36 @@
 		return true;
 	}
 	
+	/**
+	 * touchHGRC
+	 * Generates a new HGRC file in a given project directory, with default values
+	 * @param project_name name of the project which will have an HGRC file added to
+	 * @return TRUE on sucess, FALSE otherwise
+	 */
 	function touchHGRC($project_name)
 	{
-		$cd = $this->_repositories_rel_dir . $project_name . '/.hg/';
+		$cd = $this->_repositories_abs_dir . $project_name . '/.hg/';
 		
 		// create file
+		// FIXME error check
 		touch($cd . 'hgrc');
 		
-		// FIXME as config
-		$blank_hgrc = array(
-			'paths' => array('default' => 'http://localhost/' . $project_name),
-			'web' => array(
-				'contact' => 'admin',
-				'description' => '',
-				'push_ssl' => 'false',
-				)
-			);
-		$this->setHGRC($project_name, $blank_hgrc);
+		// automatic appending
+		$blank_hgrc = $this->_hgrc_default_arr;
+		$blank_hgrc['paths']['default'] .= '/' . $project_name;
+		$blank_hgrc['web']['name'] .= $project_name;
 		
-		return true;
+		return $this->setHGRC($project_name, $blank_hgrc);
 	}
 	
 	/**
+	 * __hgwebconf_compat_load (private method)
 	 * Compatibility layer for Mercurial PHP config files,
 	 * which contain forward slashes '\' as key values.
 	 * 
 	 * @return contents of a php_ini array compatible representation
 	 */
-	function __hgwebconf_compat_load()
+	function __hgwebconf_compat_load($fs_hgwebdir = 'hgweb.config')
 	{
 		$hgwebconf_lock_path = $this->_lock_dir . 'hgweb.config.lock';
 		
@@ -181,22 +233,24 @@
 		if(!is_readable($hgwebconf_lock_path))
 		{
 			// load the PHP to file
-			$hgwebconf = $this->_hgwebconf_path;
+			$hgwebconf = $this->_repositories_abs_dir . $fs_hgwebdir;
+			// FIXME error check
 			$hgwebconf_str = file_get_contents($hgwebconf);
 			
 			// replace all occurances of the forward slash '/'
 			$hgwebconf_str = str_replace('/', $this->_compatability_delimiter, $hgwebconf_str);
 			
 			// write temp compatible ini file
+			// FIXME error check
 			file_put_contents($hgwebconf_lock_path, $hgwebconf_str);
 		}
 		
 		// load the new compat ini
 		// FIXME minimize the number of times we need to do this
-		$hgwebconf_all = parse_ini_file($hgwebconf_lock_path, true);
+		$hgwebconf_all = @parse_ini_file($hgwebconf_lock_path, true);
 		
 		$hgwebconf_collections = array();
-		if(isset($hgwebconf_all['collections']))
+		if(is_array($hgwebconf_all) && isset($hgwebconf_all['collections']))
 		{
 			foreach($hgwebconf_all['collections'] as $path => $name)
 			{
@@ -209,10 +263,12 @@
 	}
 	
 	/**
+	 * __hgwebconf_compat_persist (private method)
 	 * Takes a PHP-compatable php_ini array and converts it back into the original file.
-	 *  
+	 * @param hgwebconf_all a multi-dimensional array representing hgweb.conf 
 	 */
-	function __hgwebconf_compat_persist($hgwebconf_all)
+	// FIXME hgweb.conf as parameter
+	function __hgwebconf_compat_persist($hgwebconf_all, $fs_hgwebdir = 'hgweb.config')
 	{
 		$hgwebconf_new_ini = ';Generated by Hg-PHP Mercurial Repository Manager';
 		// generate ini string
@@ -249,13 +305,16 @@
 		$hgwebconf_tmp_path = $this->_lock_dir . 'hgweb.config.tmp';
 		
 		// persist to disk in a temporary file
+		// FIXME error check
 		file_put_contents($hgwebconf_tmp_path, $hgwebconf_new_ini);
 		
 		// TODO concurrency check
 		// overwrite existing hgweb.conf
-		rename($hgwebconf_tmp_path, $this->_hgwebconf_path);
+		// FIXME error check
+		rename($hgwebconf_tmp_path, $this->_repositories_abs_dir . $fs_hgwebdir);
 		
-		// cleanup 
+		// cleanup
+		// FIXME error check 
 		unlink($hgwebconf_lock_path);
 		
 		return true;
--- a/admin/application/libraries/hgphp.php	Thu May 13 21:16:14 2010 -0700
+++ b/admin/application/libraries/hgphp.php	Thu May 13 23:28:00 2010 -0700
@@ -4,7 +4,7 @@
  * CodeIgniter Mercurial Repository Management class
  * 
  * Scans file system and Mercurial projects directory, allowing
- * web-based manipulation of the hgwebdir.config and hgrc configuration files.
+ * web-based manipulation of the hgweb.config and hgrc configuration files.
  * 
  * Depends on the HgConf2Ini library.
  * 
@@ -230,7 +230,7 @@
 			return false;
 		}
 		
-		$cd = $this->_repositories_rel_dir;
+		$cd = $this->_repositories_abs_dir;
 		mkdir($cd . $repository_name . '/.hg/store/data/', 0755, TRUE);
 		
 		// create hgrc
@@ -244,7 +244,7 @@
 			return false;
 		}
 		
-		$cd = $this->_repositories_rel_dir . $repository_name;
+		$cd = $this->_repositories_abs_dir . $repository_name;
 		
 		$this->recursiveDelete($cd . '/.hg/');
 		return $this->recursiveDelete($cd);
@@ -264,13 +264,13 @@
 		$this->_ci->load->helper('directory');
 		
 		// FIXME this doesn't check if file or directory...
-		$realdir = directory_map($this->_repositories_rel_dir, TRUE);
+		$realdir = directory_map($this->_repositories_abs_dir, TRUE);
 		
 		$verifiedrealdir = array();
 		foreach($realdir as $file)
 		{
 			// checks if we detected a folder
-			if(is_dir($this->_repositories_rel_dir . $file))
+			if(is_dir($this->_repositories_abs_dir . $file))
 			{
 				$verifiedrealdir[$file] = $file;
 			}
@@ -279,16 +279,6 @@
 		return $verifiedrealdir;
 	}
 	
-	
-	
-	function getProjectParams()
-	{
-		return array('ui'=>array('config1'=>'value'));
-	}
-	
-
-	
-	
 	/**
      * Delete a file or recursively delete a directory
      *
--- a/admin/application/views/repo_directory.php	Thu May 13 21:16:14 2010 -0700
+++ b/admin/application/views/repo_directory.php	Thu May 13 23:28:00 2010 -0700
@@ -16,20 +16,6 @@
 			}
 		});
 		
-		$('#dialog_disable').dialog({
-			autoOpen: false,
-			width: 600,
-			modal: true,
-			buttons: {
-				"Ok": function() { 
-					$(this).dialog("close"); 
-				}, 
-				"Cancel": function() { 
-					$(this).dialog("close"); 
-				} 
-			}
-		});
-		
 		$('#dialog_delete').dialog({
 			autoOpen: false,
 			width: 600,
@@ -53,12 +39,6 @@
 		});
 		
 		// Dialog Link
-		$('#dialog_link_disable, #dialog_link2_disable').click(function(){
-			$('#dialog_disable').dialog('open');
-			return false;
-		});
-		
-		// Dialog Link
 		$('#dialog_link_delete, #dialog_link2_delete').click(function(){
 			document.forms['form_delete'].form_delete_name.focus();
 			$('#dialog_delete').dialog('open');
@@ -73,11 +53,10 @@
 		
 	});
 </script>
-<table class="bigtable">
+<table class="bigtable" style="border-bottom: 0px">
     <tr>
 	  <td colspan="4">
 		<p><a href="#" id="dialog_link_create" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon ui-icon-newwin"></span><?php print lang('hg_configparser_action_create'); ?></a>
-	  	<a href="#" id="dialog_link_disable" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon ui-icon-newwin"></span><?php print lang('hg_configparser_action_disable'); ?></a>
 		<a href="#" id="dialog_link_delete" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon ui-icon-newwin"></span><?php print lang('hg_configparser_action_delete'); ?></a></p>
 	  </td>
 	</tr>
@@ -111,7 +90,6 @@
 	<tr>
 	  <td colspan="4">
 		<p><a href="#" id="dialog_link2_create" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon ui-icon-newwin"></span><?php print lang('hg_configparser_action_create'); ?></a>
-	  	<a href="#" id="dialog_link2_disable" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon ui-icon-newwin"></span><?php print lang('hg_configparser_action_disable'); ?></a>
 		<a href="#" id="dialog_link2_delete" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon ui-icon-newwin"></span><?php print lang('hg_configparser_action_delete'); ?></a></p>
 	  </td>
 	</tr>
@@ -123,23 +101,22 @@
 			<table style="width: 100%">
 				<tr>
 					<td>
+						Enter a new repository name:
+						<br />
 						<input type="hidden" name="form_action" value="create_repository" />
-						<input type="text" style="width:100%" name="form_create_name" id="form_create_name"/>
+						<input type="text" style="width:100%" name="form_create_name" id="form_create_name" autocomplete="off"/>
 					</td>
 				</tr>
 			</table>
 			</form>
 		</div>
-		<div id="dialog_disable" class="dialog" title="Dialog Title">
-			<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
-		</div>
 		<div id="dialog_delete" class="dialog" title="<?php echo lang('hg_configparser_action_delete'); ?>">
 			<form action="<?php echo site_url('hgdir'); ?>" method="post" id="form_delete" name="form_delete">
 			<table style="width: 100%">
 				<tr>
 					<td>
 					<input type="hidden" name="form_action" value="delete_repository" />
-						Deleting a repository cannot be undone. The following repositories will be removed:
+						Deleting a repository cannot be undone. Choose a repository to be removed:
 						<br />
 						<select style="width:100%" name="form_delete_name" id="form_delete_name">
 							<option selected="selected" value=""></option>
--- a/admin/application/views/repository.php	Thu May 13 21:16:14 2010 -0700
+++ b/admin/application/views/repository.php	Thu May 13 23:28:00 2010 -0700
@@ -31,9 +31,18 @@
 	});
 </script>
 
-<table class="bigtable">
+<table class="bigtable" style="border-bottom: 0">
 <form action="<?php echo current_url(); ?>" method="post" id="form_hgrc" name="form_hgrc">
 	<input type="hidden" name="form_action" id="form_action" value="" />
+	<tr>
+	  <td colspan="3" align="right">
+	  	<p>
+	  	<a href="<?php echo site_url('hgdir'); ?>" id="dialog_link_cancel" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span><?php print lang('hg_configparser_action_cancel'); ?></a>
+	  	<a href="#" id="dialog_link_reset" class="ui-state-default ui-corner-all dialog_link" onclick="javascript:document.forms['form_hgrc'].reset()"><span class="ui-icon"></span><?php print lang('hg_configparser_action_reset'); ?></a>
+	  	<a href="#" id="dialog_link_save" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span><?php print lang('hg_configparser_action_save'); ?></a>
+	  	</p>
+	  </td>
+	</tr>	
     <?php if(isset($hgrc) && is_array($hgrc)): foreach($hgrc as $section_name => $section): ?>
     <tr> 
         <th><?php echo $section_name ?></th> 
@@ -51,11 +60,12 @@
     
     <?php endforeach; endif; ?>
 	<tr>
-	  <td colspan="3">
-	  	<p><a href="#" id="dialog_link_save" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span><?php print lang('hg_configparser_action_save'); ?></a>
-	  	<a href="#" id="dialog_link_reset" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span><?php print lang('hg_configparser_action_reset'); ?></a>
-	  	<a href="#" id="dialog_link_cancel" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span><?php print lang('hg_configparser_action_cancel'); ?></a>
-	  	<a href="#" id="dialog_link_delete" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span><?php print lang('hg_configparser_action_delete'); ?></a></p>
+	  <td colspan="3" align="right">
+	  	<p>
+	  	<a href="<?php echo site_url('hgdir'); ?>" id="dialog_link2_cancel" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span><?php print lang('hg_configparser_action_cancel'); ?></a>
+	  	<a href="#" id="dialog_link2_reset" class="ui-state-default ui-corner-all dialog_link" onclick="javascript:document.forms['form_hgrc'].reset()"><span class="ui-icon"></span><?php print lang('hg_configparser_action_reset'); ?></a>
+	  	<a href="#" id="dialog_link2_save" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span><?php print lang('hg_configparser_action_save'); ?></a>
+	  	</p>
 	  </td>
 	</tr>
 </table>
--- a/admin/themes/mercurial/views/coal.php	Thu May 13 21:16:14 2010 -0700
+++ b/admin/themes/mercurial/views/coal.php	Thu May 13 23:28:00 2010 -0700
@@ -45,7 +45,7 @@
 <div class="main"> 
 <h2><?php echo $template['title']; ?></h2> 
  
-<table class="bigtable">
+<table class="bigtable" style="border-bottom: 0">
 <?php if(isset($template['partials']['user_err'])): ?>
   <tr>
     <td>
@@ -79,13 +79,15 @@
   </tr>
   <tr>
   	<td>
-  	
+<span style="background:#ffc;font-size:70%;">
+Processed in {elapsed_time} seconds. Hg-PHP Mercurial Repository Manager. 2010 <a href="http://www.joshjcarrier.com">Josh Carrier</a>. 
+</span>  	
   	</td>
   </tr>
 </table>
 
 </div> 
-<span style="background:#ffc">Processed in {elapsed_time} seconds.</span>
+
 </div> 
   
 </body>