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