xref: /plugin/struct/action/diff.php (revision 08e7b568f1c5230d7a69f10078bf85611fd6c0a4)
110caaf49SAndreas Gohr<?php
210caaf49SAndreas Gohr/**
310caaf49SAndreas Gohr * DokuWiki Plugin struct (Action Component)
410caaf49SAndreas Gohr *
510caaf49SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
610caaf49SAndreas Gohr * @author  Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
710caaf49SAndreas Gohr */
810caaf49SAndreas Gohr
910caaf49SAndreas Gohr// must be run within Dokuwiki
1010caaf49SAndreas Gohruse plugin\struct\meta\Assignments;
1110caaf49SAndreas Gohruse plugin\struct\meta\SchemaData;
1210caaf49SAndreas Gohr
1310caaf49SAndreas Gohrif(!defined('DOKU_INC')) die();
1410caaf49SAndreas Gohr
1510caaf49SAndreas Gohrclass action_plugin_struct_diff extends DokuWiki_Action_Plugin {
1610caaf49SAndreas Gohr
1710caaf49SAndreas Gohr    /**
1810caaf49SAndreas Gohr     * Registers a callback function for a given event
1910caaf49SAndreas Gohr     *
2010caaf49SAndreas Gohr     * @param Doku_Event_Handler $controller DokuWiki's event controller object
2110caaf49SAndreas Gohr     * @return void
2210caaf49SAndreas Gohr     */
2310caaf49SAndreas Gohr    public function register(Doku_Event_Handler $controller) {
2410caaf49SAndreas Gohr        $controller->register_hook('IO_WIKIPAGE_READ', 'AFTER', $this, 'handle_diffload');
2510caaf49SAndreas Gohr    }
2610caaf49SAndreas Gohr
2710caaf49SAndreas Gohr    /**
2810caaf49SAndreas Gohr     * Add structured data to the diff
2910caaf49SAndreas Gohr     *
3010caaf49SAndreas Gohr     * This is done by adding pseudo syntax to the page source when it is loaded in diff context
3110caaf49SAndreas Gohr     *
3210caaf49SAndreas Gohr     * @param Doku_Event $event event object by reference
3310caaf49SAndreas Gohr     * @param mixed $param [the parameters passed as fifth argument to register_hook() when this
3410caaf49SAndreas Gohr     *                           handler was registered]
3510caaf49SAndreas Gohr     * @return bool
3610caaf49SAndreas Gohr     */
3710caaf49SAndreas Gohr    public function handle_diffload(Doku_Event $event, $param) {
3810caaf49SAndreas Gohr        global $ACT;
3910caaf49SAndreas Gohr        global $INFO;
4010caaf49SAndreas Gohr        if($ACT != 'diff') return;
4110caaf49SAndreas Gohr        $id = $event->data[2];
4210caaf49SAndreas Gohr        $rev = $event->data[3];
4310caaf49SAndreas Gohr        if($INFO['id'] != $id) return;
4410caaf49SAndreas Gohr
4510caaf49SAndreas Gohr        $assignments = new Assignments();
4610caaf49SAndreas Gohr        $tables = $assignments->getPageAssignments($id);
4710caaf49SAndreas Gohr        if(!$tables) return;
4810caaf49SAndreas Gohr
49*08e7b568SAndreas Gohr        $event->result .= "\n---- struct data ----\n";
5010caaf49SAndreas Gohr        foreach($tables as $table) {
5110caaf49SAndreas Gohr            $schemadata = new SchemaData($table, $id, $rev);
52*08e7b568SAndreas Gohr            $event->result .= $schemadata->getDataPseudoSyntax();
5310caaf49SAndreas Gohr        }
54*08e7b568SAndreas Gohr        $event->result .= "----\n";
5510caaf49SAndreas Gohr    }
5610caaf49SAndreas Gohr
5710caaf49SAndreas Gohr}
5810caaf49SAndreas Gohr
5910caaf49SAndreas Gohr// vim:ts=4:sw=4:et:
60