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