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