xref: /dokuwiki/lib/plugins/popularity/admin.php (revision 0deaa5d831fea288ae11f05e633add33e4de36cb)
15faeb1e6SAndreas Gohr<?php
25faeb1e6SAndreas Gohr/**
35faeb1e6SAndreas Gohr * Popularity Feedback Plugin
45faeb1e6SAndreas Gohr *
55faeb1e6SAndreas Gohr * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
65faeb1e6SAndreas Gohr * @author     Andreas Gohr <andi@splitbrain.org>
75faeb1e6SAndreas Gohr */
85faeb1e6SAndreas Gohr// must be run within Dokuwiki
95faeb1e6SAndreas Gohrif(!defined('DOKU_INC')) die();
105faeb1e6SAndreas Gohr
115faeb1e6SAndreas Gohrif(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
125faeb1e6SAndreas Gohrrequire_once(DOKU_PLUGIN.'admin.php');
135faeb1e6SAndreas Gohrrequire_once(DOKU_INC.'inc/infoutils.php');
145faeb1e6SAndreas Gohrrequire_once(DOKU_INC.'inc/pluginutils.php');
155faeb1e6SAndreas Gohrrequire_once(DOKU_INC.'inc/search.php');
165faeb1e6SAndreas Gohr
175faeb1e6SAndreas Gohr/**
185faeb1e6SAndreas Gohr * All DokuWiki plugins to extend the admin function
195faeb1e6SAndreas Gohr * need to inherit from this class
205faeb1e6SAndreas Gohr */
215faeb1e6SAndreas Gohrclass admin_plugin_popularity extends DokuWiki_Admin_Plugin {
22*0deaa5d8SAndreas Gohr    var $version = '2008-02-20';
235faeb1e6SAndreas Gohr
245faeb1e6SAndreas Gohr
255faeb1e6SAndreas Gohr    /**
265faeb1e6SAndreas Gohr     * return some info
275faeb1e6SAndreas Gohr     */
285faeb1e6SAndreas Gohr    function getInfo(){
295faeb1e6SAndreas Gohr        return array(
305faeb1e6SAndreas Gohr            'author' => 'Andreas Gohr',
315faeb1e6SAndreas Gohr            'email'  => 'andi@splitbrain.org',
325faeb1e6SAndreas Gohr            'date'   => $this->version,
335faeb1e6SAndreas Gohr            'name'   => 'Popularity Feedback Plugin',
345faeb1e6SAndreas Gohr            'desc'   => 'Send anonymous data about your wiki to the developers.',
355faeb1e6SAndreas Gohr            'url'    => 'http://wiki.splitbrain.org/wiki:popularity',
365faeb1e6SAndreas Gohr        );
375faeb1e6SAndreas Gohr    }
385faeb1e6SAndreas Gohr
395faeb1e6SAndreas Gohr    /**
405faeb1e6SAndreas Gohr     * return prompt for admin menu
415faeb1e6SAndreas Gohr     */
425faeb1e6SAndreas Gohr    function getMenuText($language) {
435faeb1e6SAndreas Gohr        return $this->getLang('name');
445faeb1e6SAndreas Gohr    }
455faeb1e6SAndreas Gohr
465faeb1e6SAndreas Gohr    /**
475faeb1e6SAndreas Gohr     * return sort order for position in admin menu
485faeb1e6SAndreas Gohr     */
495faeb1e6SAndreas Gohr    function getMenuSort() {
505faeb1e6SAndreas Gohr        return 2000;
515faeb1e6SAndreas Gohr    }
525faeb1e6SAndreas Gohr
535faeb1e6SAndreas Gohr    /**
545faeb1e6SAndreas Gohr     * handle user request
555faeb1e6SAndreas Gohr     *
565faeb1e6SAndreas Gohr     *
575faeb1e6SAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
585faeb1e6SAndreas Gohr     */
595faeb1e6SAndreas Gohr    function handle() {
605faeb1e6SAndreas Gohr    }
615faeb1e6SAndreas Gohr
625faeb1e6SAndreas Gohr    /**
635faeb1e6SAndreas Gohr     * @author  Andreas Gohr <andi@splitbrain.org>
645faeb1e6SAndreas Gohr     */
655faeb1e6SAndreas Gohr    function html() {
665faeb1e6SAndreas Gohr        echo $this->locale_xhtml('intro');
675faeb1e6SAndreas Gohr
685faeb1e6SAndreas Gohr        flush();
695faeb1e6SAndreas Gohr        $data = $this->_gather();
705faeb1e6SAndreas Gohr        echo '<form method="post" action="http://update.dokuwiki.org/popularity.php" accept-charset="utf-8">';
715faeb1e6SAndreas Gohr        echo '<fieldset style="width: 60%;">';
725faeb1e6SAndreas Gohr        echo '<textarea class="edit" rows="10" cols="80" readonly="readonly" name="data">';
735faeb1e6SAndreas Gohr        foreach($data as $key => $val){
745faeb1e6SAndreas Gohr            if(is_array($val)) foreach($val as $v){
755faeb1e6SAndreas Gohr                echo hsc($key)."\t".hsc($v)."\n";
765faeb1e6SAndreas Gohr            }else{
775faeb1e6SAndreas Gohr                echo hsc($key)."\t".hsc($val)."\n";
785faeb1e6SAndreas Gohr            }
795faeb1e6SAndreas Gohr        }
805faeb1e6SAndreas Gohr        echo '</textarea><br />';
815faeb1e6SAndreas Gohr        echo '<input type="submit" class="button" value="'.$this->getLang('submit').'"/>';
825faeb1e6SAndreas Gohr        echo '</fieldset>';
835faeb1e6SAndreas Gohr        echo '</form>';
845faeb1e6SAndreas Gohr
855faeb1e6SAndreas Gohr//        dbg($data);
865faeb1e6SAndreas Gohr    }
875faeb1e6SAndreas Gohr
885faeb1e6SAndreas Gohr
895faeb1e6SAndreas Gohr    /**
905faeb1e6SAndreas Gohr     * Gather all information
915faeb1e6SAndreas Gohr     */
925faeb1e6SAndreas Gohr    function _gather(){
935faeb1e6SAndreas Gohr        global $conf;
945faeb1e6SAndreas Gohr        global $auth;
955faeb1e6SAndreas Gohr        $data = array();
965faeb1e6SAndreas Gohr        $phptime = ini_get('max_execution_time');
975faeb1e6SAndreas Gohr        @set_time_limit(0);
985faeb1e6SAndreas Gohr
995faeb1e6SAndreas Gohr        // version
1005faeb1e6SAndreas Gohr        $data['anon_id'] = md5(auth_cookiesalt());
1015faeb1e6SAndreas Gohr        $data['version'] = getVersion();
1025faeb1e6SAndreas Gohr        $data['popversion'] = $this->version;
1035faeb1e6SAndreas Gohr        $data['language'] = $conf['lang'];
1045faeb1e6SAndreas Gohr        $data['now']      = time();
1055faeb1e6SAndreas Gohr
1065faeb1e6SAndreas Gohr        // some config values
1075faeb1e6SAndreas Gohr        $data['conf_useacl']   = $conf['useacl'];
1085faeb1e6SAndreas Gohr        $data['conf_authtype'] = $conf['authtype'];
1095faeb1e6SAndreas Gohr        $data['conf_template'] = $conf['template'];
1105faeb1e6SAndreas Gohr
1115faeb1e6SAndreas Gohr        // number and size of pages
1125faeb1e6SAndreas Gohr        $list = array();
1135faeb1e6SAndreas Gohr        search($list,$conf['datadir'],array($this,'_search_count'),'','');
1145faeb1e6SAndreas Gohr        $data['page_count']    = $list['file_count'];
1155faeb1e6SAndreas Gohr        $data['page_size']     = $list['file_size'];
1165faeb1e6SAndreas Gohr        $data['page_biggest']  = $list['file_max'];
1175faeb1e6SAndreas Gohr        $data['page_smallest'] = $list['file_min'];
1185faeb1e6SAndreas Gohr        if($list['file_count']) $data['page_avg'] = $list['file_size'] / $list['file_count'];
1195faeb1e6SAndreas Gohr        $data['page_oldest']   = $list['file_oldest'];
1205faeb1e6SAndreas Gohr        unset($list);
1215faeb1e6SAndreas Gohr
1225faeb1e6SAndreas Gohr        // number and size of media
1235faeb1e6SAndreas Gohr        $list = array();
1245faeb1e6SAndreas Gohr        search($list,$conf['mediadir'],array($this,'_search_count'),array('all'=>true));
1255faeb1e6SAndreas Gohr        $data['media_count']    = $list['file_count'];
1265faeb1e6SAndreas Gohr        $data['media_size']     = $list['file_size'];
1275faeb1e6SAndreas Gohr        $data['media_biggest']  = $list['file_max'];
1285faeb1e6SAndreas Gohr        $data['media_smallest'] = $list['file_min'];
1295faeb1e6SAndreas Gohr        if($list['file_count']) $data['media_avg'] = $list['file_size'] / $list['file_count'];
1305faeb1e6SAndreas Gohr        unset($list);
1315faeb1e6SAndreas Gohr
1325faeb1e6SAndreas Gohr        // number and size of cache
1335faeb1e6SAndreas Gohr        $list = array();
1345faeb1e6SAndreas Gohr        search($list,$conf['cachedir'],array($this,'_search_count'),array('all'=>true));
1355faeb1e6SAndreas Gohr        $data['cache_count']    = $list['file_count'];
1365faeb1e6SAndreas Gohr        $data['cache_size']     = $list['file_size'];
1375faeb1e6SAndreas Gohr        $data['cache_biggest']  = $list['file_max'];
1385faeb1e6SAndreas Gohr        $data['cache_smallest'] = $list['file_min'];
1395faeb1e6SAndreas Gohr        if($list['file_count']) $data['cache_avg'] = $list['file_size'] / $list['file_count'];
1405faeb1e6SAndreas Gohr        unset($list);
1415faeb1e6SAndreas Gohr
1425faeb1e6SAndreas Gohr        // number and size of index
1435faeb1e6SAndreas Gohr        $list = array();
1445faeb1e6SAndreas Gohr        search($list,$conf['indexdir'],array($this,'_search_count'),array('all'=>true));
1455faeb1e6SAndreas Gohr        $data['index_count']    = $list['file_count'];
1465faeb1e6SAndreas Gohr        $data['index_size']     = $list['file_size'];
1475faeb1e6SAndreas Gohr        $data['index_biggest']  = $list['file_max'];
1485faeb1e6SAndreas Gohr        $data['index_smallest'] = $list['file_min'];
1495faeb1e6SAndreas Gohr        if($list['file_count']) $data['index_avg'] = $list['file_size'] / $list['file_count'];
1505faeb1e6SAndreas Gohr        unset($list);
1515faeb1e6SAndreas Gohr
1525faeb1e6SAndreas Gohr        // number and size of meta
1535faeb1e6SAndreas Gohr        $list = array();
1545faeb1e6SAndreas Gohr        search($list,$conf['metadir'],array($this,'_search_count'),array('all'=>true));
1555faeb1e6SAndreas Gohr        $data['meta_count']    = $list['file_count'];
1565faeb1e6SAndreas Gohr        $data['meta_size']     = $list['file_size'];
1575faeb1e6SAndreas Gohr        $data['meta_biggest']  = $list['file_max'];
1585faeb1e6SAndreas Gohr        $data['meta_smallest'] = $list['file_min'];
1595faeb1e6SAndreas Gohr        if($list['file_count']) $data['meta_avg'] = $list['file_size'] / $list['file_count'];
1605faeb1e6SAndreas Gohr        unset($list);
1615faeb1e6SAndreas Gohr
1625faeb1e6SAndreas Gohr        // number and size of attic
1635faeb1e6SAndreas Gohr        $list = array();
1645faeb1e6SAndreas Gohr        search($list,$conf['olddir'],array($this,'_search_count'),array('all'=>true));
1655faeb1e6SAndreas Gohr        $data['attic_count']    = $list['file_count'];
1665faeb1e6SAndreas Gohr        $data['attic_size']     = $list['file_size'];
1675faeb1e6SAndreas Gohr        $data['attic_biggest']  = $list['file_max'];
1685faeb1e6SAndreas Gohr        $data['attic_smallest'] = $list['file_min'];
1695faeb1e6SAndreas Gohr        if($list['file_count']) $data['attic_avg'] = $list['file_size'] / $list['file_count'];
1705faeb1e6SAndreas Gohr        $data['attic_oldest']   = $list['file_oldest'];
1715faeb1e6SAndreas Gohr        unset($list);
1725faeb1e6SAndreas Gohr
1735faeb1e6SAndreas Gohr        // user count
1745faeb1e6SAndreas Gohr        if($auth && $auth->canDo('getUserCount')){
1755faeb1e6SAndreas Gohr            $data['user_count'] = $auth->getUserCount();
1765faeb1e6SAndreas Gohr        }
1775faeb1e6SAndreas Gohr
1785faeb1e6SAndreas Gohr        // calculate edits per day
1795faeb1e6SAndreas Gohr        $list = @file($conf['metadir'].'/_dokuwiki.changes');
1805faeb1e6SAndreas Gohr        $count = count($list);
1815faeb1e6SAndreas Gohr        if($count > 2){
1825faeb1e6SAndreas Gohr            $first = (int) substr(array_shift($list),0,10);
1835faeb1e6SAndreas Gohr            $last  = (int) substr(array_pop($list),0,10);
1845faeb1e6SAndreas Gohr            $dur = ($last - $first)/(60*60*24); // number of days in the changelog
1855faeb1e6SAndreas Gohr            $data['edits_per_day'] = $count/$dur;
1865faeb1e6SAndreas Gohr        }
1875faeb1e6SAndreas Gohr        unset($list);
1885faeb1e6SAndreas Gohr
1895faeb1e6SAndreas Gohr        // plugins
1905faeb1e6SAndreas Gohr        $data['plugin'] = plugin_list();
1915faeb1e6SAndreas Gohr
192*0deaa5d8SAndreas Gohr        // pcre info
193*0deaa5d8SAndreas Gohr        if(defined('PCRE_VERSION')) $data['pcre_version'] = PCRE_VERSION;
194*0deaa5d8SAndreas Gohr        $data['pcre_backtrack'] = ini_get('pcre.backtrack_limit');
195*0deaa5d8SAndreas Gohr        $data['pcre_recursion'] = ini_get('pcre.recursion_limit');
196*0deaa5d8SAndreas Gohr
1975faeb1e6SAndreas Gohr        // php info
1985faeb1e6SAndreas Gohr        $data['os'] = PHP_OS;
1995faeb1e6SAndreas Gohr        $data['webserver'] = $_SERVER['SERVER_SOFTWARE'];
2005faeb1e6SAndreas Gohr        $data['php_version'] = phpversion();
2015faeb1e6SAndreas Gohr        $data['php_sapi'] = php_sapi_name();
2025faeb1e6SAndreas Gohr        $data['php_memory'] = $this->_to_byte(ini_get('memory_limit'));
2035faeb1e6SAndreas Gohr        $data['php_exectime'] = $phptime;
2045faeb1e6SAndreas Gohr        $data['php_extension'] = get_loaded_extensions();
2055faeb1e6SAndreas Gohr
2065faeb1e6SAndreas Gohr        return $data;
2075faeb1e6SAndreas Gohr    }
2085faeb1e6SAndreas Gohr
2095faeb1e6SAndreas Gohr
2105faeb1e6SAndreas Gohr    function _search_count(&$data,$base,$file,$type,$lvl,$opts){
2115faeb1e6SAndreas Gohr        // traverse
2125faeb1e6SAndreas Gohr        if($type == 'd'){
2135faeb1e6SAndreas Gohr            $data['dir_count']++;
2145faeb1e6SAndreas Gohr            return true;
2155faeb1e6SAndreas Gohr        }
2165faeb1e6SAndreas Gohr
2175faeb1e6SAndreas Gohr        //only search txt files if 'all' option not set
2185faeb1e6SAndreas Gohr        if($opts['all'] || substr($file,-4) == '.txt'){
2195faeb1e6SAndreas Gohr            $size = filesize($base.'/'.$file);
2205faeb1e6SAndreas Gohr            $date = filemtime($base.'/'.$file);
2215faeb1e6SAndreas Gohr            $data['file_count']++;
2225faeb1e6SAndreas Gohr            $data['file_size'] += $size;
2235faeb1e6SAndreas Gohr            if(!isset($data['file_min']) || $data['file_min'] > $size) $data['file_min'] = $size;
2245faeb1e6SAndreas Gohr            if($data['file_max'] < $size) $data['file_max'] = $size;
2255faeb1e6SAndreas Gohr            if(!isset($data['file_oldest']) || $data['file_oldest'] > $date) $data['file_oldest'] = $date;
2265faeb1e6SAndreas Gohr        }
2275faeb1e6SAndreas Gohr        return false;
2285faeb1e6SAndreas Gohr    }
2295faeb1e6SAndreas Gohr
2305faeb1e6SAndreas Gohr    /**
2315faeb1e6SAndreas Gohr     * Convert php.ini shorthands to byte
2325faeb1e6SAndreas Gohr     *
2335faeb1e6SAndreas Gohr     * @author <gilthans dot NO dot SPAM at gmail dot com>
2345faeb1e6SAndreas Gohr     * @link   http://de3.php.net/manual/en/ini.core.php#79564
2355faeb1e6SAndreas Gohr     */
2365faeb1e6SAndreas Gohr    function _to_byte($v){
2375faeb1e6SAndreas Gohr        $l = substr($v, -1);
2385faeb1e6SAndreas Gohr        $ret = substr($v, 0, -1);
2395faeb1e6SAndreas Gohr        switch(strtoupper($l)){
2405faeb1e6SAndreas Gohr            case 'P':
2415faeb1e6SAndreas Gohr                $ret *= 1024;
2425faeb1e6SAndreas Gohr            case 'T':
2435faeb1e6SAndreas Gohr                $ret *= 1024;
2445faeb1e6SAndreas Gohr            case 'G':
2455faeb1e6SAndreas Gohr                $ret *= 1024;
2465faeb1e6SAndreas Gohr            case 'M':
2475faeb1e6SAndreas Gohr                $ret *= 1024;
2485faeb1e6SAndreas Gohr            case 'K':
2495faeb1e6SAndreas Gohr                $ret *= 1024;
2505faeb1e6SAndreas Gohr            break;
2515faeb1e6SAndreas Gohr        }
2525faeb1e6SAndreas Gohr        return $ret;
2535faeb1e6SAndreas Gohr    }
2545faeb1e6SAndreas Gohr}
255