phpHgAdmin / admin / application / controllers / hgdir.php

The default branch has multiple heads

<?php

class HgDir extends Private_Controller {
	
	private $ofl_lock_hgwebconf;

	function HgDir()
	{
		parent::Private_Controller();
		$this->load->helper('hg_directory');
	}
	
	function index()
	{
		// retrieve the latest OF lock for hgweb
		$this->ofl_lock_hgwebconf = $this->session->flashdata('ofl_hgwebconf');

		/*
		 * Action handler
		 */
		$form_action = $this->input->post('form_action');
		if($form_action == 'create_repository')
		{
			$this->create();
		}
		else if($form_action == 'delete_repository')
		{
			$this->delete();
		}		
		
		$this->load->vars(array('title'=>current_profile() . ' ' . lang('hgphp_title_directory') .' | ' . HGPHP_NAME));

		// view the latest repository listings, updating the OF lock
		$this->phphgadmin->start_tx($this->ofl_lock_hgwebconf, $dummy='');
		$lsdir = $this->phphgadmin->lsdir();
		$this->phphgadmin->end_tx();
		
		// error handling
		if(!is_array($lsdir))
		{
			$this->load->vars(array('user_err'=>lang('hgphp_msg_hgwebconf_read_err_absdirs')));
		}
		
		$this->session->set_flashdata('ofl_hgwebconf', $this->ofl_lock_hgwebconf);
		
		$this->load->vars(array('pagetype'=>'directory'));

		$this->render_view();
	}
	
	function create()
	{
		$r_name = $this->input->post('form_create_name');
		$this->form_validation->set_rules('form_create_name', 'form_create_name', 'required|alpha_dash|min_length[1]|max_length[255]');
			
		$blacklist = '';
		$path = @parse_url($this->config->item('base_url'), PHP_URL_PATH);
		if($path !== FALSE)
		{
			$components = @explode('/', $path);
			if(isset($components[1]))
			{
				$blacklist = $components[1];
			}
		}
		
		if ($this->form_validation->run() == FALSE)
		{
			$this->load->vars(array('user_err'=>lang('hgphp_msg_hgwebconf_create_err_validname')));
		}
		else if($r_name == $blacklist)
		{
			$this->load->vars(array('user_err'=>lang('hgphp_msg_hgwebconf_create_err_blacklistname')));
		}
		else
		{
			$this->phphgadmin->start_tx($this->ofl_lock_hgwebconf, $dummy='');
			$action_status = $this->phphgadmin->create_repository($r_name);
			$this->phphgadmin->end_tx();
			
			switch($action_status){
				case HGPHP_OK:
					$this->load->vars(array('user_msg'=>$r_name.': '. lang('hgphp_msg_hgwebconf_create_success')));
					break;
				case HGPHP_ERR_PERM_USR:
					$this->load->vars(array('user_err'=>$r_name.': '. lang('hgphp_msg_hgwebconf_create_err_permuser')));
					break;
				case HGPHP_ERR_PERM_SYS_REPODIR:
					$this->load->vars(array('user_err'=>$r_name.': '. lang('hgphp_msg_hgwebconf_create_err_permsys')));
					break;
				case -100:
					$this->load->vars(array('user_err'=>$r_name.': '.'" RESTORE UNSUPPORTED.'));
					break;
				case HGPHP_ERR_FS_PREEXISTS:
					$this->load->vars(array('user_err'=>$r_name.': '. lang('hgphp_msg_hgwebconf_create_err_preexists')));
					break;	
				case OFL_ERR_LOCKING:
					$this->load->vars(array('user_err'=>$r_name.': '. lang('hgphp_msg_hgwebconf_create_err_locking') . ' <a href="'.site_url('/hgdir').'" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span>'.lang('hgphp_action_reload').'</a>'));
					break;			
				default:
					$this->load->vars(array('user_err'=>$r_name.': '. lang('hgphp_msg_unknown_err'). $action_status));
					break;
			}
		}
	}
	
	function delete()
	{
		$r_name = $this->input->post('form_delete_name');
		$this->form_validation->set_rules('form_delete_name', 'form_delete_name', 'required');
			
		if ($this->form_validation->run() == FALSE)
		{
			$this->load->vars(array('user_err'=>lang('hgphp_msg_hgwebconf_delete_err_unspecified_name')));
		}
		else
		{
			$this->phphgadmin->start_tx($this->ofl_lock_hgwebconf, $dummy='');
			$action_status = $this->phphgadmin->delete_repository($r_name);
			$this->phphgadmin->end_tx();
			
			switch($action_status){
				case HGPHP_OK:
					$this->load->vars(array('user_msg'=>$r_name.': '. lang('hgphp_msg_hgwebconf_delete_success')));
					break;
				case HGPHP_ERR_PERM_USR:
					$this->load->vars(array('user_err'=>$r_name.': '. lang('hgphp_msg_hgwebconf_delete_err_permuser')));
					break;
				case HGPHP_ERR_PERM_SYS_REPODIR:
					$this->load->vars(array('user_err'=>$r_name.': '. lang('hgphp_msg_hgwebconf_delete_err_permsys')));
					break;
				case HGPHP_ERR_FS_PREEXISTS:
					$this->load->vars(array('user_err'=>$r_name.': '. lang('hgphp_msg_hgwebconf_delete_err_preexists')));
					break;	
				case OFL_ERR_LOCKING:
					$this->load->vars(array('user_err'=>$r_name.': '. lang('hgphp_msg_hgwebconf_delete_err_locking') . ' <a href="'.site_url('/hgdir').'" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span>'.lang('hgphp_action_reload').'</a>'));
					break;			
				default:
					$this->load->vars(array('user_err'=>$r_name.': '. lang('hgphp_msg_unknown_err') . $action_status));
					break;
			}
		}
	}
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.