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, $REV ?: $INFO['currentrev']); 38 39 /** @var action_plugin_structpublish_sqlitefunction $functions */ 40 $functions = plugin_load('action', 'structpublish_sqlitefunction'); 41 if ( 42 $currentRevision->getStatus() !== Constants::STATUS_PUBLISHED 43 && !$functions->IS_PUBLISHER($ID) 44 ) { 45 $latestPublished = $currentRevision->getLatestPublishedRevision(); 46 if (is_null($latestPublished)) { 47 $event->data = 'denied'; 48 // FIXME we could add our own action to display a custom message instead of standard denied action 49 return; 50 } 51 52 $latestPublishedRev = $latestPublished->getRev(); 53 $REV = $latestPublishedRev; 54 $INFO['rev'] = $latestPublishedRev; 55 } 56 } 57} 58