*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'admin.php');
/**
* All DokuWiki plugins to extend the admin function
* need to inherit from this class
*/
class admin_plugin_dwcommits extends DokuWiki_Admin_Plugin {
private $output = '';
private $submitted = false;
private $helper;
private $db;
private $current_page;
function __construct() {
$this->helper =& plugin_load('helper', 'dwcommits');
$this->db = $this->helper->_getDB();
$this->helper->set_branches();
$this->helper->set_repros();
//ini_set('display_errors',1);
//ini_set('error_reporting',E_ALL);
}
/**
* return some info
*/
function getInfo(){
return array(
'author' => 'Myron Turner',
'email' => 'turnermm02@shaw.ca',
'date' => '2015-10-01',
'name' => 'admin plugin dwcommits',
'desc' => 'demonstration dwcommits',
'url' => 'http://www.dokuwiki.org/plugin:commits',
);
}
/**
* return sort order for position in admin menu
*/
function getMenuSort() {
return 999;
}
/**
* return a menu prompt for the admin menu
* NOT REQUIRED - its better to place $lang['menu'] string in localised string file
* only use this function when you need to vary the string returned
*/
/**
* handle user request
*/
function handle() {
if (!isset($_REQUEST['cmd'])) return; // first time - nothing to do
$this->output = 'invalid';
$nov_11 = mktime(0,0,0,11,11,2010);
$dwc_Divs = array(
'init'=>"dcw_db_update",'update'=>"dcw_db_update",
'fetch'=>"dwc_git_advanced",'merge'=>"dwc_git_advanced",'commit'=>"dwc_git_advanced",'add'=>"dwc_git_advanced",
'status'=>"dcw_update_git", 'pull'=>"dcw_update_git",'remote_url'=>"dcw_update_git",
'branch'=>"dwc_repos_div",'repro'=>"dwc_repos_div",
'info'=>"dwc_info_div",
'query'=>"dwc_query_div",
'prune' =>"dwc_prune_div", 'restore'=>"dwc_prune_div",'prune_del'=>"dwc_prune_div"
);
if (!is_array($_REQUEST['cmd'])) return;
// verify valid values
switch (key($_REQUEST['cmd'])) {
case 'init' :
$start_timestamp = $this->get_timestamp($_REQUEST['d']);
if(!$start_timestamp) $start_timestamp = $nov_11;
$rows_done = $this->helper->recreate_table($start_timestamp);
$this->output = 'Initialized ' . $rows_done . ' rows';
break;
case 'fetch' :
case 'merge' :
case 'commit' :
case 'pull' :
case 'branch':
case 'remote_url':
case 'add':
$status = "";
$this->helper->update_commits(key($_REQUEST['cmd']));
$status = $this->helper->get_status_msg();
$this->output = $status;
break;
case 'update' :
$start_timestamp = $this->get_timestamp($_REQUEST['dup']);
if(!$start_timestamp){
$start_timestamp = $nov_11;
$this->output = 'date set to default';
}
$retv = $this->helper->populate($start_timestamp);
if(is_array($retv)) {
list($num,$recs) = $retv;
$this->output = "Records written to database: $num. Records in database: $recs.";
}
break;
case 'status' :
$status = "";
if(!$this->helper->get_status()) {
$status = $this->helper->get_status_msg();
}
else $status = $this->helper->get_status_msg();
$this->output = $status;
break;
case 'repro':
//path switched in helper constructor
$this->output = $this->getLang('repro_switched') . ':' . $_REQUEST['dwc__repro'];
break;
case 'query':
list($arr,$q) = $this->helper->select_all();
$this->output = "$q
";
if($arr) {
if($_REQUEST['output_type'] == 'plain') {
$this->output .= $this->helper->format_result_plain($arr);
}
else {
$this->output .= $this->helper->format_result_table($arr);
}
}
else $this->output .= "no result";
break;
case 'set_remote_url':
$this->output = $this->helper->set_githubURL($_REQUEST['remote_url_name']);
break;
case 'prune':
$this->output = $this->helper->prune(false);
break;
case 'prune_del':
$this->output = $this->helper->prune(true);
break;
case 'restore':
$this->output = $this->helper->restore_backup();
break;
}
$this->current_page = $dwc_Divs[key($_REQUEST['cmd'])];
$this->submitted = "";
$this->submitted = $this->current_page . '
' . key($_REQUEST['cmd']) . '
' . print_r($_REQUEST,1) . ''; } /** * output appropriate html */ function html() { global $ID; $date_str = $this->getConf('default_date'); if(isset($date_str)) { list($month,$day,$year) = explode('-',$date_str); } else { $month ='MM'; $day='DD'; $year='YYY'; } /* Navigation Bar */ ptln(' '); /* Form */ ptln(''); /* Info Div */ ptln('
'.$this->output.'
'); ptln('