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