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