This is what the output looks like in DokuWiki:
The DokuWiki markup for it is:
[gitlabcommits]
GitLab provides a very handy API to fetching data. It requires a key to fetch the data, which is passed in the request URL and then it returns a JSON string with the response. Then it's a matter of iterating through the results and displaying them in a table.
So here's the plugin code. I've made use of some CSS that's defined by the pagelist plugin. That plugin does provide a way to use it programatically too, but I didn't bother with that since I wanted more control on the size of my output table.
<?php
/**
* Plugin: GitLab Commits
* @author Igor Kromin (http://www.igorkromin.net)
*/
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.'syntax.php');
class syntax_plugin_gitlabcommits extends DokuWiki_Syntax_Plugin {
function getInfo() {
return array('author' => 'Igor Kromin',
'email' => '[email protected]',
'date' => '2013-04-21',
'name' => 'GitLab Commits Plugin',
'desc' => 'Shows last commits from GitLab',
'url' => 'http://www.igorkromin.net/');
}
function getType(){ return 'substition'; }
function getPType(){ return 'block'; }
function getSort(){ return 100; }
function connectTo($mode) {
$this->Lexer->addSpecialPattern('[gitlabcommits]',$mode,'plugin_gitlabcommits');
}
function handle($match, $state, $pos, &$handler){
return array($match, $state, $pos);
}
function render($mode, &$renderer, $data) {
if($mode == 'xhtml'){
$pageurl = "*** GITLAB COMMITS URL ***";
$ch=curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $pageurl);
$html = curl_exec($ch);
curl_close($ch);
$json = new JSON();
$array = $json->decode($html);
$renderer->doc .= '<table class="pagelist" style="width:725px"><tr><th class="page">ID</th><th class="page">Author</th><th class="page">Title</th><th class="date">Date</th></tr>';
foreach($array as &$val) {
$renderer->doc .= '<tr><td class="desc">' . $val->short_id . '</td><td class="desc">' . $val->author_name . '</td><td class="desc">' . $val->title . '</td><td class="date">' . $val->created_at . '</td></tr>';
}
$renderer->doc .= '</table>';
return true;
}
return false;
}
}
?>
Without going into too much detail, this is a very basic syntax plugin. The majority of the code is really just setting up the plugin itself.
The bit that needs to change is the $pageurl, which is the URL to the GitLab commits page, which has to include the key assigned by GitLab.
There is definitely room for improvements here, however this plugin will get a list of commits and will display it in a wiki page. If I get more time, I will try to clean it up, but for now this plugin is 'as is'.
-i