xref: /plugin/struct/action/diff.php (revision 10caaf49b40633de3b5904a1b930df150efdf1d6)
1*10caaf49SAndreas Gohr<?php
2*10caaf49SAndreas Gohr/**
3*10caaf49SAndreas Gohr * DokuWiki Plugin struct (Action Component)
4*10caaf49SAndreas Gohr *
5*10caaf49SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6*10caaf49SAndreas Gohr * @author  Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
7*10caaf49SAndreas Gohr */
8*10caaf49SAndreas Gohr
9*10caaf49SAndreas Gohr// must be run within Dokuwiki
10*10caaf49SAndreas Gohruse plugin\struct\meta\Assignments;
11*10caaf49SAndreas Gohruse plugin\struct\meta\SchemaData;
12*10caaf49SAndreas Gohr
13*10caaf49SAndreas Gohrif(!defined('DOKU_INC')) die();
14*10caaf49SAndreas Gohr
15*10caaf49SAndreas Gohrclass action_plugin_struct_diff extends DokuWiki_Action_Plugin {
16*10caaf49SAndreas Gohr
17*10caaf49SAndreas Gohr    /**
18*10caaf49SAndreas Gohr     * Registers a callback function for a given event
19*10caaf49SAndreas Gohr     *
20*10caaf49SAndreas Gohr     * @param Doku_Event_Handler $controller DokuWiki's event controller object
21*10caaf49SAndreas Gohr     * @return void
22*10caaf49SAndreas Gohr     */
23*10caaf49SAndreas Gohr    public function register(Doku_Event_Handler $controller) {
24*10caaf49SAndreas Gohr        $controller->register_hook('IO_WIKIPAGE_READ', 'AFTER', $this, 'handle_diffload');
25*10caaf49SAndreas Gohr    }
26*10caaf49SAndreas Gohr
27*10caaf49SAndreas Gohr    /**
28*10caaf49SAndreas Gohr     * Add structured data to the diff
29*10caaf49SAndreas Gohr     *
30*10caaf49SAndreas Gohr     * This is done by adding pseudo syntax to the page source when it is loaded in diff context
31*10caaf49SAndreas Gohr     *
32*10caaf49SAndreas Gohr     * @param Doku_Event $event event object by reference
33*10caaf49SAndreas Gohr     * @param mixed $param [the parameters passed as fifth argument to register_hook() when this
34*10caaf49SAndreas Gohr     *                           handler was registered]
35*10caaf49SAndreas Gohr     * @return bool
36*10caaf49SAndreas Gohr     */
37*10caaf49SAndreas Gohr    public function handle_diffload(Doku_Event $event, $param) {
38*10caaf49SAndreas Gohr        global $ACT;
39*10caaf49SAndreas Gohr        global $INFO;
40*10caaf49SAndreas Gohr        if($ACT != 'diff') return;
41*10caaf49SAndreas Gohr        $id = $event->data[2];
42*10caaf49SAndreas Gohr        $rev = $event->data[3];
43*10caaf49SAndreas Gohr        if($INFO['id'] != $id) return;
44*10caaf49SAndreas Gohr
45*10caaf49SAndreas Gohr        $assignments = new Assignments();
46*10caaf49SAndreas Gohr        $tables = $assignments->getPageAssignments($id);
47*10caaf49SAndreas Gohr        if(!$tables) return;
48*10caaf49SAndreas Gohr
49*10caaf49SAndreas Gohr        $event->result .= "\n---- struct data ----";
50*10caaf49SAndreas Gohr        foreach($tables as $table) {
51*10caaf49SAndreas Gohr            $schemadata = new SchemaData($table, $id, $rev);
52*10caaf49SAndreas Gohr            $data = $schemadata->getDataArray();
53*10caaf49SAndreas Gohr            foreach($data as $key => $value) {
54*10caaf49SAndreas Gohr                $key = "$table.$key";
55*10caaf49SAndreas Gohr                if(is_array($value)) $value = join(', ', $value);
56*10caaf49SAndreas Gohr                $event->result .= sprintf("\n% -20s : %s", $key, $value);
57*10caaf49SAndreas Gohr            }
58*10caaf49SAndreas Gohr        }
59*10caaf49SAndreas Gohr        $event->result .= "\n----";
60*10caaf49SAndreas Gohr    }
61*10caaf49SAndreas Gohr
62*10caaf49SAndreas Gohr}
63*10caaf49SAndreas Gohr
64*10caaf49SAndreas Gohr// vim:ts=4:sw=4:et:
65