hlp = plugin_load('helper', 'approve'); } function register(Doku_Event_Handler $controller) { $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_approve', array()); $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_viewer', array()); $controller->register_hook('TPL_ACT_RENDER', 'AFTER', $this, 'handle_diff_accept', array()); $controller->register_hook('TPL_ACT_RENDER', 'BEFORE', $this, 'handle_display_banner', array()); $controller->register_hook('HTML_SHOWREV_OUTPUT', 'BEFORE', $this, 'handle_showrev', array()); // ensure a page revision is created when summary changes: $controller->register_hook('COMMON_WIKIPAGE_SAVE', 'BEFORE', $this, 'handle_pagesave_before'); $controller->register_hook('COMMON_WIKIPAGE_SAVE', 'AFTER', $this, 'handle_pagesave_after'); } function handle_diff_accept(Doku_Event $event, $param) { global $ID; if ($this->hlp->in_namespace($this->getConf('no_apr_namespaces'), $ID)) return; if ($event->data == 'diff' && isset($_GET['approve'])) { ptln(''.$this->getLang('approve').''); } if ($event->data == 'diff' && isset($_GET['ready_for_approval']) && $this->getConf('ready_for_approval') === 1) { ptln(''.$this->getLang('approve_ready').''); } } function handle_showrev(Doku_Event $event, $param) { global $REV; $last = $this->find_lastest_approved(); if ($last == $REV) $event->preventDefault(); } function can_approve() { global $ID; return auth_quickaclcheck($ID) >= AUTH_DELETE; } function can_edit() { global $ID; return auth_quickaclcheck($ID) >= AUTH_EDIT; } function handle_approve(Doku_Event $event, $param) { global $ID; if ($this->hlp->in_namespace($this->getConf('no_apr_namespaces'), $ID)) return; if ($event->data == 'show' && isset($_GET['approve'])) { if ( ! $this->can_approve()) return; //create new page revison saveWikiText($ID, rawWiki($ID), ApproveConst::APPROVED); header('Location: ?id='.$ID); } elseif ($event->data == 'show' && isset($_GET['ready_for_approval'])) { if ( ! $this->can_edit()) return; //create new page revison saveWikiText($ID, rawWiki($ID), ApproveConst::READY_FOR_APPROVAL); header('Location: ?id='.$ID); } } function handle_viewer(Doku_Event $event, $param) { global $REV, $ID; if ($event->data != 'show') return; if (auth_quickaclcheck($ID) > AUTH_READ || ($this->hlp->in_namespace($this->getConf('no_apr_namespaces'), $ID))) return; $last = $this->find_lastest_approved(); //no page is approved if ($last == -1) return; //approved page is the newest page if ($last == 0) return; //if we are viewing lastest revision, show last approved if ($REV == 0) header("Location: ?id=$ID&rev=$last"); } function find_lastest_approved() { global $ID; $m = p_get_metadata($ID); $sum = $m['last_change']['sum']; if ($sum == ApproveConst::APPROVED) return 0; $changelog = new PageChangeLog($ID); $chs = $changelog->getRevisions(0, 10000); foreach ($chs as $rev) { $ch = $changelog->getRevisionInfo($rev); if ($ch['sum'] == ApproveConst::APPROVED) return $rev; } return -1; } function handle_display_banner(Doku_Event $event, $param) { global $ID, $REV, $INFO; if ($this->hlp->in_namespace($this->getConf('no_apr_namespaces'), $ID)) return; if ($event->data != 'show') return; if (!$INFO['exists']) return; $sum = $this->hlp->page_sum($ID, $REV); $classes = array(); if ($this->getConf('prettyprint')) { $classes[] = 'plugin__approve_noprint'; } if ($sum == ApproveConst::APPROVED) { $classes[] = 'plugin__approve_green'; } elseif ($sum == ApproveConst::READY_FOR_APPROVAL && $this->getConf('ready_for_approval')) { $classes[] = 'plugin__approve_ready'; } else { $classes[] = 'plugin__approve_red'; } ptln('