1<?php 2 3use dokuwiki\plugin\structpublish\meta\Revision; 4use \dokuwiki\plugin\structpublish\meta\Constants; 5 6class action_plugin_structpublish_revisions extends DokuWiki_Action_Plugin 7{ 8 9 public function register(Doku_Event_Handler $controller) 10 { 11 $controller->register_hook('FORM_REVISIONS_OUTPUT', 'BEFORE', $this, 'handleRevisions'); 12 } 13 14 /** 15 * Adds publish info to page revisions 16 * 17 * @param Doku_Event $event 18 * @return void 19 */ 20 public function handleRevisions(Doku_Event $event) 21 { 22 global $INFO; 23 24 /** @var dokuwiki\Form\Form $form */ 25 $form = $event->data; 26 27 /** @var helper_plugin_structpublish_db $helper */ 28 $helper = plugin_load('helper', 'structpublish_db'); 29 30 if (!$helper->isPublishable()) return; 31 32 $sqlite = $helper->getDB(); 33 34 $elCount = $form->elementCount(); 35 $checkName = 'rev2[]'; 36 37 for ($i = 0; $i < $elCount; $i++) { 38 $el = $form->getElementAt($i); 39 40 if (!is_a($el, \dokuwiki\Form\CheckableElement::class) && !is_a($el, \dokuwiki\Form\HTMLElement::class)) { 41 continue; 42 } 43 44 // extract rev from checkbox info 45 if (is_a($el, \dokuwiki\Form\CheckableElement::class)) { 46 if ($el->attr('name') === $checkName) { 47 $rev = $el->attr('value'); 48 } 49 } 50 51 // get most recent status for rev 52 $revision = new Revision($sqlite, $INFO['id'], $rev); 53 $status = $revision->getStatus(); 54 $version = $revision->getVersion(); 55 56 // insert status for published revisions 57 if (is_a($el, \dokuwiki\Form\HTMLElement::class) && !empty(trim($el->val())) && $status === Constants::STATUS_PUBLISHED) { 58 $val = $el->val(); 59 $label = '<span class="plugin-structpublish-version">' . $status . ' (' . $this->getLang('version') . ' ' . $version . ')</span>'; 60 $el->val("$val $label"); 61 } 62 } 63 } 64} 65