1<?php 2 3use dokuwiki\Extension\AdminPlugin; 4use dokuwiki\plugin\qc\Output; 5 6/** 7 * This plugin is used to display a summery of all FIXME pages 8 * 9 * @see http://dokuwiki.org/plugin:qc 10 * @author Dominik Eckelmann <dokuwiki@cosmocode.de> 11 */ 12class admin_plugin_qc extends AdminPlugin 13{ 14 protected $data; 15 protected $order; 16 17 /** @inheritdoc */ 18 public function forAdminOnly() 19 { 20 return false; 21 } 22 23 /** @inheritDoc */ 24 public function getMenuIcon() 25 { 26 return __DIR__ . '/svg/good.svg'; 27 } 28 29 /** @inheritdoc */ 30 public function handle() 31 { 32 global $conf; 33 34 // load the quality data 35 if (is_file($conf['tmpdir'] . '/qcgather')) { 36 $this->data = file_get_contents($conf['tmpdir'] . '/qcgather'); 37 $this->data = unserialize($this->data); 38 } else { 39 $this->data = []; 40 } 41 42 // order the data 43 if (!isset($_REQUEST['pluginqc']['order'])) { 44 $_REQUEST['pluginqc']['order'] = 'quality'; 45 } 46 47 switch ($_REQUEST['pluginqc']['order']) { 48 case 'fixme': 49 uasort($this->data, [$this, 'sortFixme']); 50 $this->order = 'fixme'; 51 break; 52 default: 53 uasort($this->data, [$this, 'sortQuality']); 54 $this->order = 'quality'; 55 } 56 } 57 58 /** @inheritdoc */ 59 public function html() 60 { 61 global $ID; 62 $max = $this->getConf('maxshowen'); 63 if (!$max || $max <= 0) $max = 25; 64 65 echo '<div id="plugin__qc_admin">'; 66 echo '<h1>' . $this->getLang('admin_headline') . '</h1>'; 67 68 echo '<p>' . sprintf($this->getLang('admin_desc'), $max) . '</p>'; 69 70 echo '<table class="inline">'; 71 echo ' <tr>'; 72 echo ' <th>' . $this->getLang('admin_page') . '</th>'; 73 echo ' <th class="quality">' . $this->getOrderArrow('quality') . '<a href="' . wl($ID, ['do' => 'admin', 'page' => 'qc', 'pluginqc[order]' => 'quality']) . '">' . $this->getLang('admin_quality') . '</a></th>'; 74 echo ' <th class="fixme">' . $this->getOrderArrow('fixme') . '<a href="' . wl($ID, ['do' => 'admin', 'page' => 'qc', 'pluginqc[order]' => 'fixme']) . '">' . $this->getLang('admin_fixme') . '</a></th>'; 75 echo ' </tr>'; 76 77 if ($this->data) { 78 foreach ($this->data as $id => $data) { 79 if ($max == 0) break; 80 echo ' <tr>'; 81 echo ' <td>'; 82 tpl_pagelink(':' . $id, $id); 83 echo '</td>'; 84 echo ' <td class="centeralign">' . Output::scoreIcon($data['score']) . '</td>'; 85 echo ' <td class="centeralign">' . $data['err']['fixme'] . '</td>'; 86 echo ' </tr>'; 87 $max--; 88 } 89 } 90 91 echo '</table>'; 92 echo '</div>'; 93 } 94 95 /** 96 * return an arrow if currently sorted by this type 97 * 98 * @ return string 99 */ 100 protected function getOrderArrow($type) 101 { 102 if ($type == $this->order) return '↓ '; 103 return ''; 104 } 105 106 /** 107 * order by quality 108 */ 109 protected function sortQuality($a, $b) 110 { 111 return $b['score'] <=> $a['score']; 112 } 113 114 /** 115 * order by fixmes 116 */ 117 protected function sortFixme($a, $b) 118 { 119 return $b['err']['fixme'] <=> $a['err']['fixme']; 120 } 121} 122