1<?php 2 3use dokuwiki\plugin\structpublish\meta\Constants; 4use dokuwiki\plugin\structpublish\meta\Revision; 5 6class action_plugin_structpublish_show extends DokuWiki_Action_Plugin 7{ 8 /** @inheritDoc */ 9 public function register(Doku_Event_Handler $controller) 10 { 11 $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handleShow'); 12 } 13 14 /** 15 * Decide which revision to show based on role assignments 16 * 17 * @param Doku_Event $event 18 * @return void 19 */ 20 public function handleShow(Doku_Event $event) 21 { 22 if ($event->data != 'show') { 23 return; 24 } 25 26 global $ID; 27 global $REV; 28 global $INFO; 29 30 /** @var helper_plugin_structpublish_db $dbHelper */ 31 $dbHelper = plugin_load('helper', 'structpublish_db'); 32 33 if (!$dbHelper->isPublishable()) { 34 return; 35 } 36 37 $currentRevision = new Revision($dbHelper->getDB(), $ID, $INFO['currentrev']); 38 /** @var action_plugin_structpublish_sqlitefunction $functions */ 39 $functions = plugin_load('action', 'structpublish_sqlitefunction'); 40 if ( 41 $currentRevision->getStatus() !== Constants::STATUS_PUBLISHED 42 && !$functions->IS_PUBLISHER($ID) 43 ) { 44 $latestPublishedRev = $currentRevision->getLatestPublishedRevision()->getRev(); 45 if (!$latestPublishedRev) { 46 $event->data = 'denied'; 47 // FIXME we could add our own action to display a custom message instead of standard denied action 48 } 49 50 $REV = $latestPublishedRev; 51 $INFO['rev'] = $latestPublishedRev; 52 } 53 } 54} 55