first checkin of files - pages are synced, no media sync support at the moment
[sitka-infra/dokuwiki-plugin-gitbacked.git] / action / editcommit.php
CommitLineData
fa53f2a3
WG
1<?php
2/**
3 * DokuWiki Plugin gitbacked (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author Wolfgang Gassler <wolfgang@gassler.org>
7 */
8
9// must be run within Dokuwiki
10if (!defined('DOKU_INC')) die();
11
12if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
13if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
14if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
15
16require_once DOKU_PLUGIN.'action.php';
17require_once(DOKU_PLUGIN.'gitbacked/lib/Git.php');
18
19class action_plugin_gitbacked_editcommit extends DokuWiki_Action_Plugin {
20
21 public function register(Doku_Event_Handler &$controller) {
22
23 $controller->register_hook('IO_WIKIPAGE_WRITE', 'AFTER', $this, 'handle_io_wikipage_write');
24
25 }
26
27 public function handle_io_wikipage_write(Doku_Event &$event, $param) {
28
29 $rev = $event->data[3];
30
31 /* On update to an existing page this event is called twice,
32 * once for the transfer of the old version to the attic (rev will have a value)
33 * and once to write the new version of the page into the wiki (rev is false)
34 */
35 if (!$rev) {
36
37 $pagePath = $event->data[0][0];
38 $pageName = $event->data[2];
39
40 $authorName = $GLOBALS['USERINFO']['name'];
41 $editSummary = $GLOBALS['INFO']['meta']['last_change']['sum'];
42
43 $message = str_replace(
44 array('%page%','%summary%','%user%'),
45 array($pageName,$editSummary,$authorName),
46 $this->getConf('commitMsg')
47 );
48
49 //get path to the repo root (by default DokuWiki's savedir)
50 $repoPath = $this->getConf('repoPath');
51
52 //init the repo and create a new one if it is not present
53 $repo = new GitRepo($repoPath, true, true);
54
55 //add the changed file and set the commit message
56 $repo->add($pagePath);
57 $repo->commit($message);
58
59 //if the push after Commit option is set we push the active branch to origin
60 if ($this->getConf('pushAfterCommit')) {
61 $repo->push('origin',$repo->active_branch());
62 }
63
64 }
65
66 }
67
68}
69
70// vim:ts=4:sw=4:et: