@url http://wiki.erazor-zone.de/wiki:projects:php:dokuwiki:plugins:darcs
@date 2006.03.19
*/
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_darcs extends DokuWiki_Admin_Plugin {
var $log=array();
/**
* return some info
*/
function getInfo(){
return array(
'author' => 'Alexander Krause',
'email' => 'alexander.krause@erazor-zone.de',
'date' => '2005-09-07',
'name' => 'darcs repository',
'desc' => 'Manipulate the DokuWiki devel',
'url' => 'https://www.dokuwiki.org/plugin:darcs',
);
}
/**
* return sort order for position in admin menu
*/
function getMenuSort() {
return 2;
}
/**
* handle user request
*/
function handle() {
}
/**
* output appropriate html
*/
function html() {
global $conf;
$this->setupLocale();
$conf['htmlok']=1;
require_once(realpath(dirname(__FILE__)).'/darcs.php');
$my_repos=new Darcs_Repository();
$my_repos->set_repository(DOKU_INC);
$my_page.='====== '.$this->lang['menu']." ======\n";
switch ($_REQUEST['darcs_do']) {
case 'get_plugin':
$my_page.=$this->wiki_getplugin_page (&$my_repos);
break;
case 'apply_all':
$my_page.=$this->wiki_update_page (&$my_repos);
break;
case 'apply_plugins':
$my_page.=$this->wiki_plugin_page (&$my_repos);
break;
case 'do_remove':
if (is_array($_REQUEST['remove'])) {
while (list($plugin_id, $plugin_name) = each($_REQUEST['remove'])) {
exec('rm -r '.DOKU_INC.'lib/plugins/'.$plugin_name);
}
}
$my_page.=$this->wiki_admin_page (&$my_repos);
break;
default:
$my_page.=$this->wiki_admin_page (&$my_repos);
}
if ($conf['darcs']['debug']=='1') {
$my_page.="\n\n=====".$this->lang['stdout']."=====\n";
$my_page.="".implode("\n",$this->log)."";
}
echo $this->plugin_render($my_page, $format='xhtml') ;
}
function wiki_admin_page (&$my_repos) {
global $ID;
$my_page.="===== dokuwiki =====\n";
$my_page.='^ '.$this->lang['head_new']." ^^^^\n";
$my_page.='^ '.$this->lang['name'].' ^ '.$this->lang['date'].' ^ '.$this->lang['author'].
' ^ '.$this->lang['description']." ^\n";
if ($my_repos->last_ec>=0) {
$my_repos->get_patches();
array_push($this->log,"--\n",'>cd '.$my_repos->repos_dir,'>cd '.$my_repos->last_cmd,
implode("\n",$my_repos->stdout));
if ($my_repos->patch_count==0) {
$my_page.='| **'.$this->lang['error_u2d']."** ||||\n";
} else {
while (list($patch_no, $patch) = each($my_repos->patch_list)) {
$my_page.='| '.$patch['name'].' | '.$patch['date'].' | '.$patch['author'].
'| %%'.$patch['description']."%% |\n";
}
$my_page.='|
||||\n";
}
} else {
if ($my_repos->last_ec==-1) {
$my_page.='| **'.$this->lang['error_dir']."** ||||\n";
} else if ($my_repos->last_ec==-2) {
$my_page.='| **'.$this->lang['error_darcs']."** ||||\n";
}
}
$my_page.="===== ".$this->lang['plugins']." =====\n";
$my_page.='\n";
$my_page.="\n\n\n";
$my_page.="^ ".$this->lang['install_plugin']." ^\n";
$my_page.='| **darcs get** |\n";
return $my_page;
}
function wiki_update_page (&$my_repos) {
$my_repos->set_repository(DOKU_INC);
if ($my_repos->last_ec>=0) {
$my_repos->apply_patches();
array_push($this->log,"--\n",'>cd '.$my_repos->repos_dir,'>cd '.$my_repos->last_cmd,
implode("\n",$my_repos->stdout));
$this->wiki_admin_page (&$my_repos);
} else {
if ($my_repos->last_ec==-1) {
$my_page='**'.$this->lang['error_dir']."**\n";
} else if ($my_repos->last_ec<0) {
$my_page='**'.$this->lang['error_darcs']."**\n";
}
$my_page.=$this->wiki_backbt ();
}
$my_page.=$this->wiki_admin_page (&$my_repos);
return $my_page;
}
function wiki_getplugin_page (&$my_repos) {
$my_repos->set_repository(DOKU_INC.'lib/plugins/');
$plugin_name=basename($_REQUEST['plugin_url'],"/");
if (is_dir(DOKU_INC.'lib/plugins/'.$plugin_name) ) {
$my_page.='**'.$this->lang['error_pe']."**\n";
$my_page.=$this->wiki_backbt();
} else {
if ($my_repos->last_ec>=0) {
$my_repos->darcs_get($_REQUEST['plugin_url']);
array_push($this->log,"--\n",'>cd '.$my_repos->repos_dir,'>cd '.$my_repos->last_cmd,
implode("\n",$my_repos->stdout));
$my_page.=$this->wiki_admin_page(&$my_repos);
} else {
if ($my_repos->last_ec==-1) {
$my_page.='**'.$this->lang['error_dir']."**\n";
} else if ($my_repos->last_ec<0) {
$my_page.='**'.$this->lang['error_darcs']."**\n";
}
$my_page.=$this->wiki_backbt();
}
}
return $my_page;
}
function wiki_plugin_page (&$my_repos) {
if (($_REQUEST['remove_plugins']!='') && (is_array($_REQUEST['remove']))) {
$my_page.="===== ".$this->lang['plugins']." =====\n";
$my_page.='===== '.$this->lang['remove_warn']." =====\n".
'';
$my_page.=$this->wiki_backbt ($this->lang['no']).' ||||';
} else {
if (is_array($_REQUEST['update'])) {
while (list($plugin_id, $plugin_name) = each($_REQUEST['update'])) {
$my_repos->set_repository(realpath(dirname(__FILE__).'/../'.$plugin_name));
$my_repos->apply_patches();
array_push($this->log,"--\n",'>cd '.$my_repos->repos_dir,'>cd '.$my_repos->last_cmd,
implode("\n",$my_repos->stdout));
}
}
$my_page.=$this->wiki_admin_page (&$my_repos);
}
return $my_page;
}
function wiki_backbt ($caption='') {
global $ID;
if ($caption=='') $caption=$this->lang['bt_back'];
$retval='';
return $retval;
}
}