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; 13*a28d6152SAndreas Gohruse dokuwiki\plugin\struct\meta\StructException; 1410caaf49SAndreas Gohr 1510caaf49SAndreas Gohrif(!defined('DOKU_INC')) die(); 1610caaf49SAndreas Gohr 1710caaf49SAndreas Gohrclass action_plugin_struct_diff extends DokuWiki_Action_Plugin { 1810caaf49SAndreas Gohr 1910caaf49SAndreas Gohr /** 2010caaf49SAndreas Gohr * Registers a callback function for a given event 2110caaf49SAndreas Gohr * 2210caaf49SAndreas Gohr * @param Doku_Event_Handler $controller DokuWiki's event controller object 2310caaf49SAndreas Gohr * @return void 2410caaf49SAndreas Gohr */ 2510caaf49SAndreas Gohr public function register(Doku_Event_Handler $controller) { 2610caaf49SAndreas Gohr $controller->register_hook('IO_WIKIPAGE_READ', 'AFTER', $this, 'handle_diffload'); 2710caaf49SAndreas Gohr } 2810caaf49SAndreas Gohr 2910caaf49SAndreas Gohr /** 3010caaf49SAndreas Gohr * Add structured data to the diff 3110caaf49SAndreas Gohr * 3210caaf49SAndreas Gohr * This is done by adding pseudo syntax to the page source when it is loaded in diff context 3310caaf49SAndreas Gohr * 3410caaf49SAndreas Gohr * @param Doku_Event $event event object by reference 3510caaf49SAndreas Gohr * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 3610caaf49SAndreas Gohr * handler was registered] 3710caaf49SAndreas Gohr * @return bool 3810caaf49SAndreas Gohr */ 3910caaf49SAndreas Gohr public function handle_diffload(Doku_Event $event, $param) { 4010caaf49SAndreas Gohr global $ACT; 4110caaf49SAndreas Gohr global $INFO; 4210caaf49SAndreas Gohr if($ACT != 'diff') return; 4310caaf49SAndreas Gohr $id = $event->data[2]; 440c555ad4SMichael Grosse if (!blank($event->data[1])) { 450c555ad4SMichael Grosse $id = $event->data[1] . ':' . $id; 460c555ad4SMichael Grosse } 4710caaf49SAndreas Gohr $rev = $event->data[3]; 4810caaf49SAndreas Gohr if($INFO['id'] != $id) return; 4910caaf49SAndreas Gohr 50025cb9daSAndreas Gohr $assignments = Assignments::getInstance(); 5110caaf49SAndreas Gohr $tables = $assignments->getPageAssignments($id); 5210caaf49SAndreas Gohr if(!$tables) return; 5310caaf49SAndreas Gohr 5408e7b568SAndreas Gohr $event->result .= "\n---- struct data ----\n"; 5510caaf49SAndreas Gohr foreach($tables as $table) { 56*a28d6152SAndreas Gohr try { 57f411d872SAndreas Gohr $schemadata = AccessTable::byTableName($table, $id, $rev); 58*a28d6152SAndreas Gohr } catch(StructException $ignored) { 59*a28d6152SAndreas Gohr continue; // no such schema at this revision 60*a28d6152SAndreas Gohr } 6108e7b568SAndreas Gohr $event->result .= $schemadata->getDataPseudoSyntax(); 6210caaf49SAndreas Gohr } 6308e7b568SAndreas Gohr $event->result .= "----\n"; 6410caaf49SAndreas Gohr } 6510caaf49SAndreas Gohr 6610caaf49SAndreas Gohr} 6710caaf49SAndreas Gohr 6810caaf49SAndreas Gohr// vim:ts=4:sw=4:et: 69