xref: /plugin/struct/action/diff.php (revision 025cb9da4274aac00be48202c8eb49058f2dd283)
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
10f411d872SAndreas Gohruse dokuwiki\plugin\struct\meta\AccessTable;
11ba766201SAndreas Gohruse dokuwiki\plugin\struct\meta\Assignments;
1294c9aa4cSAndreas Gohruse dokuwiki\plugin\struct\meta\AccessTableData;
1310caaf49SAndreas Gohr
1410caaf49SAndreas Gohrif(!defined('DOKU_INC')) die();
1510caaf49SAndreas Gohr
1610caaf49SAndreas Gohrclass action_plugin_struct_diff extends DokuWiki_Action_Plugin {
1710caaf49SAndreas Gohr
1810caaf49SAndreas Gohr    /**
1910caaf49SAndreas Gohr     * Registers a callback function for a given event
2010caaf49SAndreas Gohr     *
2110caaf49SAndreas Gohr     * @param Doku_Event_Handler $controller DokuWiki's event controller object
2210caaf49SAndreas Gohr     * @return void
2310caaf49SAndreas Gohr     */
2410caaf49SAndreas Gohr    public function register(Doku_Event_Handler $controller) {
2510caaf49SAndreas Gohr        $controller->register_hook('IO_WIKIPAGE_READ', 'AFTER', $this, 'handle_diffload');
2610caaf49SAndreas Gohr    }
2710caaf49SAndreas Gohr
2810caaf49SAndreas Gohr    /**
2910caaf49SAndreas Gohr     * Add structured data to the diff
3010caaf49SAndreas Gohr     *
3110caaf49SAndreas Gohr     * This is done by adding pseudo syntax to the page source when it is loaded in diff context
3210caaf49SAndreas Gohr     *
3310caaf49SAndreas Gohr     * @param Doku_Event $event event object by reference
3410caaf49SAndreas Gohr     * @param mixed $param [the parameters passed as fifth argument to register_hook() when this
3510caaf49SAndreas Gohr     *                           handler was registered]
3610caaf49SAndreas Gohr     * @return bool
3710caaf49SAndreas Gohr     */
3810caaf49SAndreas Gohr    public function handle_diffload(Doku_Event $event, $param) {
3910caaf49SAndreas Gohr        global $ACT;
4010caaf49SAndreas Gohr        global $INFO;
4110caaf49SAndreas Gohr        if($ACT != 'diff') return;
4210caaf49SAndreas Gohr        $id = $event->data[2];
4310caaf49SAndreas Gohr        $rev = $event->data[3];
4410caaf49SAndreas Gohr        if($INFO['id'] != $id) return;
4510caaf49SAndreas Gohr
46*025cb9daSAndreas Gohr        $assignments = Assignments::getInstance();
4710caaf49SAndreas Gohr        $tables = $assignments->getPageAssignments($id);
4810caaf49SAndreas Gohr        if(!$tables) return;
4910caaf49SAndreas Gohr
5008e7b568SAndreas Gohr        $event->result .= "\n---- struct data ----\n";
5110caaf49SAndreas Gohr        foreach($tables as $table) {
52f411d872SAndreas Gohr            $schemadata = AccessTable::byTableName($table, $id, $rev);
5308e7b568SAndreas Gohr            $event->result .= $schemadata->getDataPseudoSyntax();
5410caaf49SAndreas Gohr        }
5508e7b568SAndreas Gohr        $event->result .= "----\n";
5610caaf49SAndreas Gohr    }
5710caaf49SAndreas Gohr
5810caaf49SAndreas Gohr}
5910caaf49SAndreas Gohr
6010caaf49SAndreas Gohr// vim:ts=4:sw=4:et:
61