1<?php 2/** 3 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 4 * @author Stephan Dekker <Stephan@SparklingSoftware.com.au> 5 */ 6 7if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 8require_once DOKU_PLUGIN.'action.php'; 9require_once(DOKU_PLUGIN.'git/lib/Git.php'); 10 11 12class action_plugin_git_revert extends DokuWiki_Action_Plugin { 13 14 var $helper = null; 15 16 function action_plugin_git_revert(){ 17 $this->helper =& plugin_load('helper', 'git'); 18 if (is_null($this->helper)) { 19 msg('The GIT plugin could not load its helper class', -1); 20 return false; 21 } 22 } 23 24 function register(&$controller) { 25 $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, '_handle'); 26 } 27 28 function _handle(&$event, $param) { 29 30 if ($_REQUEST['cmd'] === null) return; 31 32 // verify valid values 33 switch (key($_REQUEST['cmd'])) { 34 case 'revert' : $this->revert(); 35 $this->helper->changeReadOnly(false); 36 break; 37 } 38 } 39 40 function revert() 41 { 42 try { 43 global $conf; 44 $this->getConf(''); 45 46 $git_exe_path = $conf['plugin']['git']['git_exe_path']; 47 $datapath = $conf['savedir']; 48 49 $repo = new GitRepo($datapath); 50 $repo->git_path = $git_exe_path; 51 $repo->revertLastCommit(); 52 } 53 catch(Exception $e) 54 { 55 msg($e->getMessage()); 56 return false; 57 } 58 } 59 60}