summaryrefslogtreecommitdiff
path: root/GitTimeline_body.php
blob: e1ea75b49a974a564e75e7fbc0bddf265f885f8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php

class GitTimeline {

    static function onParserInit( Parser $parser ) {

        $parser->setHook( 'GitTimeline', array( __CLASS__, 'renderGitTimeline' ) );
        return true;

    }

    static function onBeforePageDisplay( OutputPage &$out, Skin &$skin ) {

        $out->addModuleStyles( array (
            'ext.gittimeline'
        ) );

    }

    static function renderGitTimeline( $input, array $args, Parser $parser, PPFrame $frame ) {

        global $wgRepositoriesDirectory;
        global $wgCGitUrl;

        if ( ! isset( $args['repo'] ) )
            return '';

        if ( ! isset( $args['keep'] ) )
            return '';

        $repo = $args['repo'];
        $keep = $args['keep'];

        $git_command = <<<EOT
cd $wgRepositoriesDirectory/$repo
for h in `git rev-list HEAD -$keep`; do
    url="$wgCGitUrl/$repo/commit/?id=\$h"
    revision=\$(( \$(git rev-list \$h | wc -l) + 4))
    message=\$( git log -1 \$h --pretty=format:"%s <span class=\"gitdate\">(%ar)</span>" )
    echo -e "\t<li><a href=\"\$url\">r\$revision</A> - \$message</li>"
done
EOT;

        $output = shell_exec($git_command);

        return array( "$output", 'noparse' => true, 'isHTML' => true );

    }

}

?>