@date 2007.08.07 */ 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'); require_once(DOKU_INC.'inc/io.php'); /** * All DokuWiki plugins to extend the admin function * need to inherit from this class */ class admin_plugin_darcspatch extends DokuWiki_Admin_Plugin { var $log=array(); /** * return some info */ function getInfo(){ return array( 'author' => 'Todd Augsburger', 'email' => 'todd@rollerorgans.com', 'date' => '2007-08-07', 'name' => 'darcspatch', 'desc' => 'manually apply darcs-style raw patches', 'url' => 'http://wiki.splitbrain.org/plugin:darcspatch', ); } /** * 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; $my_page.='====== '.$this->lang['menu']." ======\n"; switch ($_REQUEST['darcspatch_do']) { case 'apply_patch': if(isset($_REQUEST['darcspatch_url']) && ($_REQUEST['darcspatch_url'] != '') && ($_REQUEST['darcspatch_url'] != 'http://')) { $my_page.=$this->apply_raw_darcs_patch($_REQUEST['darcspatch_url'],DOKU_INC,isset($_REQUEST['test_only']),isset($_REQUEST['reverse'])); } else { $my_page.=' '.$this->lang['msg_errurl']."\n\n"; } $my_page.=$this->wiki_admin_page(); break; default: $my_page.=$this->wiki_admin_page(); } echo $this->plugin_render($my_page, $format='xhtml') ; } function wiki_admin_page () { global $ID; $my_page.='^ '.$this->lang['head']." ^^^\n"; $my_page.='| //'.$this->lang['instructions']."// |||\n"; $my_page.='|
|\n"; $patchlist = explode("\n",trim($this->getConf('patchlist'))); $my_page.='^ '.$this->lang['head_stored']." ^^^\n"; $my_page.='| //'.str_replace('%1',wl($ID,'do=admin,page=config').'#plugin_settings',$this->lang['setup'])."// |||\n"; foreach($patchlist as $patch_url) { $patch_url = trim($patch_url); if($patch_url == '') continue; $my_page.='| '.$patch_url.' | |\n"; } $my_page.=''; return $my_page; } function apply_raw_darcs_patch($patch,$repo,$test_only=false,$reverse=false) { $plus = ($reverse ? '-' : '+'); $minus = ($reverse ? '+' : '-'); $return_string = ''; chdir($repo); if(($contents = file_get_contents($patch)) !== false) { $contents = str_replace("\r",'',$contents); $sections = array(); if(preg_match_all('/(^\[.*?\])\s*\{(.*?)^\}/ms',$contents,$sections) > 0) { if($reverse) $sections[1] = array_reverse($sections[1]); for($c=0;$c