1*1aeb2b4dSghi<?php 2*1aeb2b4dSghi 3*1aeb2b4dSghiif(!defined('DOKU_INC')) die(); 4*1aeb2b4dSghidefine(APPROVED, 'Approved'); 5*1aeb2b4dSghi 6*1aeb2b4dSghiclass action_plugin_approve_approve extends DokuWiki_Action_Plugin { 7*1aeb2b4dSghi 8*1aeb2b4dSghi function register(&$controller) { 9*1aeb2b4dSghi $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, handle_approve, array()); 10*1aeb2b4dSghi $controller->register_hook('TPL_ACT_RENDER', 'AFTER', $this, handle_diff_accept, array()); 11*1aeb2b4dSghi $controller->register_hook('TPL_ACT_RENDER', 'BEFORE', $this, handle_display_banner, array()); 12*1aeb2b4dSghi $controller->register_hook('HTML_SHOWREV_OUTPUT', 'BEFORE', $this, handle_showrev, array()); 13*1aeb2b4dSghi } 14*1aeb2b4dSghi 15*1aeb2b4dSghi function handle_diff_accept(&$event, $param) { 16*1aeb2b4dSghi if ($event->data == 'diff' && isset($_GET['approve'])) { 17*1aeb2b4dSghi ptln('<a href="'.DOKU_URL.'doku.php?id='.$_GET['id'].'&approve=approve">'.$this->getLang('approve').'</a>'); 18*1aeb2b4dSghi } 19*1aeb2b4dSghi } 20*1aeb2b4dSghi 21*1aeb2b4dSghi function handle_showrev(&$event, $param) { 22*1aeb2b4dSghi global $ID, $REV; 23*1aeb2b4dSghi 24*1aeb2b4dSghi $last = $this->find_lastest_approved(); 25*1aeb2b4dSghi if ($last == $REV) 26*1aeb2b4dSghi $event->preventDefault(); 27*1aeb2b4dSghi } 28*1aeb2b4dSghi 29*1aeb2b4dSghi function can_approve() { 30*1aeb2b4dSghi global $ID; 31*1aeb2b4dSghi return auth_quickaclcheck($ID) > AUTH_DELETE; 32*1aeb2b4dSghi } 33*1aeb2b4dSghi 34*1aeb2b4dSghi function handle_approve(&$event, $param) { 35*1aeb2b4dSghi global $ID, $REV; 36*1aeb2b4dSghi if ( ! $this->can_approve()) return; 37*1aeb2b4dSghi if ($event->data == 'show' && isset($_GET['approve'])) { 38*1aeb2b4dSghi //Add or remove the new line from the end of the page. Silly but needed. 39*1aeb2b4dSghi $content = rawWiki($ID, ''); 40*1aeb2b4dSghi if (substr($content, -1) == "\n") { 41*1aeb2b4dSghi $content = substr($content, 0, -1); 42*1aeb2b4dSghi } else { 43*1aeb2b4dSghi $content .= "\n"; 44*1aeb2b4dSghi } 45*1aeb2b4dSghi saveWikiText($ID, $content, APPROVED); 46*1aeb2b4dSghi 47*1aeb2b4dSghi header('Location: ?id='.$ID); 48*1aeb2b4dSghi } 49*1aeb2b4dSghi 50*1aeb2b4dSghi /*czytacze wydzą najnowszą zatwierdzaną*/ 51*1aeb2b4dSghi $last = $this->find_lastest_approved(); 52*1aeb2b4dSghi /*użytkownik może tylko czytać i jednocześnie istnieje jakaś zatwierdzona strona*/ 53*1aeb2b4dSghi if (auth_quickaclcheck($ID) <= AUTH_READ && $last != -1) 54*1aeb2b4dSghi /*najnowsza zatwierdzona nie jest najnowszą*/ 55*1aeb2b4dSghi /*i jednocześnie znajdujemy się w stronach nowszych niż aktualna zatwierdzona*/ 56*1aeb2b4dSghi if ($last != 0 && ($REV > $last || $REV == 0)) 57*1aeb2b4dSghi $REV = $last; 58*1aeb2b4dSghi } 59*1aeb2b4dSghi function find_lastest_approved() { 60*1aeb2b4dSghi global $ID; 61*1aeb2b4dSghi $m = p_get_metadata($ID); 62*1aeb2b4dSghi $sum = $m['last_change']['sum']; 63*1aeb2b4dSghi if ($sum == APPROVED) 64*1aeb2b4dSghi return 0; 65*1aeb2b4dSghi 66*1aeb2b4dSghi $changelog = new PageChangeLog($ID); 67*1aeb2b4dSghi //wyszukaj najnowszej zatwierdzonej 68*1aeb2b4dSghi //poszukaj w dół 69*1aeb2b4dSghi $chs = $changelog->getRevisions(0, 10000); 70*1aeb2b4dSghi foreach ($chs as $rev) { 71*1aeb2b4dSghi $ch = $changelog->getRevisionInfo($rev); 72*1aeb2b4dSghi if ($ch['sum'] == APPROVED) 73*1aeb2b4dSghi return $rev; 74*1aeb2b4dSghi } 75*1aeb2b4dSghi return -1; 76*1aeb2b4dSghi } 77*1aeb2b4dSghi 78*1aeb2b4dSghi function handle_display_banner(&$event, $param) { 79*1aeb2b4dSghi global $ID, $REV, $INFO; 80*1aeb2b4dSghi 81*1aeb2b4dSghi if($event->data != 'show') return; 82*1aeb2b4dSghi if (!$INFO['exists']) return; 83*1aeb2b4dSghi 84*1aeb2b4dSghi $m = p_get_metadata($ID); 85*1aeb2b4dSghi $changelog = new PageChangeLog($ID); 86*1aeb2b4dSghi 87*1aeb2b4dSghi //sprawdź status aktualnej strony 88*1aeb2b4dSghi if ($REV != 0) { 89*1aeb2b4dSghi $ch = $changelog->getRevisionInfo($REV); 90*1aeb2b4dSghi $sum = $ch['sum']; 91*1aeb2b4dSghi } else { 92*1aeb2b4dSghi $sum = $m['last_change']['sum']; 93*1aeb2b4dSghi } 94*1aeb2b4dSghi 95*1aeb2b4dSghi if ($sum != APPRVOED) { 96*1aeb2b4dSghi $class = 'approved_no'; 97*1aeb2b4dSghi $last_approved_rev = $this->find_lastest_approved(); 98*1aeb2b4dSghi } 99*1aeb2b4dSghi 100*1aeb2b4dSghi 101*1aeb2b4dSghi ptln('<div class="approval '.($sum == APPROVED ? 'approved_yes' : 'approved_no').'">'); 102*1aeb2b4dSghi 103*1aeb2b4dSghi tpl_pageinfo(); 104*1aeb2b4dSghi ptln(' | '); 105*1aeb2b4dSghi if ($sum == APPROVED) { 106*1aeb2b4dSghi ptln('<span>'.$this->getLang('approved').'</span>'); 107*1aeb2b4dSghi if ($REV != 0 && auth_quickaclcheck($ID) > AUTH_READ) { 108*1aeb2b4dSghi ptln('<a href="'.wl($ID).'">'); 109*1aeb2b4dSghi ptln($this->getLang($m['last_change']['sum'] == APPROVED ? 'newest_approved' : 'newest_draft')); 110*1aeb2b4dSghi ptln('</a>'); 111*1aeb2b4dSghi } else if ($REV != 0 && $REV != $last_approved_rev) { 112*1aeb2b4dSghi ptln('<a href="'.wl($ID).'">'); 113*1aeb2b4dSghi ptln($this->getLang('newest_approved')); 114*1aeb2b4dSghi ptln('</a>'); 115*1aeb2b4dSghi } 116*1aeb2b4dSghi } else { 117*1aeb2b4dSghi ptln('<span>'.$this->getLang('draft').'</span>'); 118*1aeb2b4dSghi 119*1aeb2b4dSghi if (isset($last_approved_rev)) { 120*1aeb2b4dSghi if ($last_approved_rev != 0) 121*1aeb2b4dSghi ptln('<a href="'.wl($ID, array('rev' => $last_approved_rev)).'">'); 122*1aeb2b4dSghi else 123*1aeb2b4dSghi ptln('<a href="'.wl($ID).'">'); 124*1aeb2b4dSghi 125*1aeb2b4dSghi ptln($this->getLang('newest_approved')); 126*1aeb2b4dSghi ptln('</a>'); 127*1aeb2b4dSghi } else { 128*1aeb2b4dSghi ptln('<a href="'.wl($ID).'">'); 129*1aeb2b4dSghi ptln($this->getLang('newest_draft')); 130*1aeb2b4dSghi ptln('</a>'); 131*1aeb2b4dSghi } 132*1aeb2b4dSghi 133*1aeb2b4dSghi //można zatwierdzać tylko najnowsze strony 134*1aeb2b4dSghi if ($REV == 0 && $this->can_approve()) { 135*1aeb2b4dSghi ptln('<a href="'.wl($ID, array('rev' => $last_approved_rev, 'do' => 'diff', 136*1aeb2b4dSghi 'approve' => 'approve')).'">'); 137*1aeb2b4dSghi ptln($this->getLang('approve')); 138*1aeb2b4dSghi ptln('</a>'); 139*1aeb2b4dSghi } 140*1aeb2b4dSghi } 141*1aeb2b4dSghi ptln('</div>'); 142*1aeb2b4dSghi } 143*1aeb2b4dSghi 144*1aeb2b4dSghi} 145