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