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 { 220deaa5d8SAndreas 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 /** 54*1bda8618SAndreas Gohr * Accessible for managers 55*1bda8618SAndreas Gohr */ 56*1bda8618SAndreas Gohr function forAdminOnly() { 57*1bda8618SAndreas Gohr return false; 58*1bda8618SAndreas Gohr } 59*1bda8618SAndreas Gohr 60*1bda8618SAndreas Gohr 61*1bda8618SAndreas Gohr /** 625faeb1e6SAndreas Gohr * handle user request 635faeb1e6SAndreas Gohr */ 645faeb1e6SAndreas Gohr function handle() { 655faeb1e6SAndreas Gohr } 665faeb1e6SAndreas Gohr 675faeb1e6SAndreas Gohr /** 68*1bda8618SAndreas Gohr * Output HTML form 695faeb1e6SAndreas Gohr */ 705faeb1e6SAndreas Gohr function html() { 715faeb1e6SAndreas Gohr echo $this->locale_xhtml('intro'); 725faeb1e6SAndreas Gohr 735faeb1e6SAndreas Gohr flush(); 745faeb1e6SAndreas Gohr $data = $this->_gather(); 755faeb1e6SAndreas Gohr echo '<form method="post" action="http://update.dokuwiki.org/popularity.php" accept-charset="utf-8">'; 765faeb1e6SAndreas Gohr echo '<fieldset style="width: 60%;">'; 775faeb1e6SAndreas Gohr echo '<textarea class="edit" rows="10" cols="80" readonly="readonly" name="data">'; 785faeb1e6SAndreas Gohr foreach($data as $key => $val){ 795faeb1e6SAndreas Gohr if(is_array($val)) foreach($val as $v){ 805faeb1e6SAndreas Gohr echo hsc($key)."\t".hsc($v)."\n"; 815faeb1e6SAndreas Gohr }else{ 825faeb1e6SAndreas Gohr echo hsc($key)."\t".hsc($val)."\n"; 835faeb1e6SAndreas Gohr } 845faeb1e6SAndreas Gohr } 855faeb1e6SAndreas Gohr echo '</textarea><br />'; 865faeb1e6SAndreas Gohr echo '<input type="submit" class="button" value="'.$this->getLang('submit').'"/>'; 875faeb1e6SAndreas Gohr echo '</fieldset>'; 885faeb1e6SAndreas Gohr echo '</form>'; 895faeb1e6SAndreas Gohr 905faeb1e6SAndreas Gohr// dbg($data); 915faeb1e6SAndreas Gohr } 925faeb1e6SAndreas Gohr 935faeb1e6SAndreas Gohr 945faeb1e6SAndreas Gohr /** 955faeb1e6SAndreas Gohr * Gather all information 965faeb1e6SAndreas Gohr */ 975faeb1e6SAndreas Gohr function _gather(){ 985faeb1e6SAndreas Gohr global $conf; 995faeb1e6SAndreas Gohr global $auth; 1005faeb1e6SAndreas Gohr $data = array(); 1015faeb1e6SAndreas Gohr $phptime = ini_get('max_execution_time'); 1025faeb1e6SAndreas Gohr @set_time_limit(0); 1035faeb1e6SAndreas Gohr 1045faeb1e6SAndreas Gohr // version 1055faeb1e6SAndreas Gohr $data['anon_id'] = md5(auth_cookiesalt()); 1065faeb1e6SAndreas Gohr $data['version'] = getVersion(); 1075faeb1e6SAndreas Gohr $data['popversion'] = $this->version; 1085faeb1e6SAndreas Gohr $data['language'] = $conf['lang']; 1095faeb1e6SAndreas Gohr $data['now'] = time(); 1105faeb1e6SAndreas Gohr 1115faeb1e6SAndreas Gohr // some config values 1125faeb1e6SAndreas Gohr $data['conf_useacl'] = $conf['useacl']; 1135faeb1e6SAndreas Gohr $data['conf_authtype'] = $conf['authtype']; 1145faeb1e6SAndreas Gohr $data['conf_template'] = $conf['template']; 1155faeb1e6SAndreas Gohr 1165faeb1e6SAndreas Gohr // number and size of pages 1175faeb1e6SAndreas Gohr $list = array(); 1185faeb1e6SAndreas Gohr search($list,$conf['datadir'],array($this,'_search_count'),'',''); 1195faeb1e6SAndreas Gohr $data['page_count'] = $list['file_count']; 1205faeb1e6SAndreas Gohr $data['page_size'] = $list['file_size']; 1215faeb1e6SAndreas Gohr $data['page_biggest'] = $list['file_max']; 1225faeb1e6SAndreas Gohr $data['page_smallest'] = $list['file_min']; 1235faeb1e6SAndreas Gohr if($list['file_count']) $data['page_avg'] = $list['file_size'] / $list['file_count']; 1245faeb1e6SAndreas Gohr $data['page_oldest'] = $list['file_oldest']; 1255faeb1e6SAndreas Gohr unset($list); 1265faeb1e6SAndreas Gohr 1275faeb1e6SAndreas Gohr // number and size of media 1285faeb1e6SAndreas Gohr $list = array(); 1295faeb1e6SAndreas Gohr search($list,$conf['mediadir'],array($this,'_search_count'),array('all'=>true)); 1305faeb1e6SAndreas Gohr $data['media_count'] = $list['file_count']; 1315faeb1e6SAndreas Gohr $data['media_size'] = $list['file_size']; 1325faeb1e6SAndreas Gohr $data['media_biggest'] = $list['file_max']; 1335faeb1e6SAndreas Gohr $data['media_smallest'] = $list['file_min']; 1345faeb1e6SAndreas Gohr if($list['file_count']) $data['media_avg'] = $list['file_size'] / $list['file_count']; 1355faeb1e6SAndreas Gohr unset($list); 1365faeb1e6SAndreas Gohr 1375faeb1e6SAndreas Gohr // number and size of cache 1385faeb1e6SAndreas Gohr $list = array(); 1395faeb1e6SAndreas Gohr search($list,$conf['cachedir'],array($this,'_search_count'),array('all'=>true)); 1405faeb1e6SAndreas Gohr $data['cache_count'] = $list['file_count']; 1415faeb1e6SAndreas Gohr $data['cache_size'] = $list['file_size']; 1425faeb1e6SAndreas Gohr $data['cache_biggest'] = $list['file_max']; 1435faeb1e6SAndreas Gohr $data['cache_smallest'] = $list['file_min']; 1445faeb1e6SAndreas Gohr if($list['file_count']) $data['cache_avg'] = $list['file_size'] / $list['file_count']; 1455faeb1e6SAndreas Gohr unset($list); 1465faeb1e6SAndreas Gohr 1475faeb1e6SAndreas Gohr // number and size of index 1485faeb1e6SAndreas Gohr $list = array(); 1495faeb1e6SAndreas Gohr search($list,$conf['indexdir'],array($this,'_search_count'),array('all'=>true)); 1505faeb1e6SAndreas Gohr $data['index_count'] = $list['file_count']; 1515faeb1e6SAndreas Gohr $data['index_size'] = $list['file_size']; 1525faeb1e6SAndreas Gohr $data['index_biggest'] = $list['file_max']; 1535faeb1e6SAndreas Gohr $data['index_smallest'] = $list['file_min']; 1545faeb1e6SAndreas Gohr if($list['file_count']) $data['index_avg'] = $list['file_size'] / $list['file_count']; 1555faeb1e6SAndreas Gohr unset($list); 1565faeb1e6SAndreas Gohr 1575faeb1e6SAndreas Gohr // number and size of meta 1585faeb1e6SAndreas Gohr $list = array(); 1595faeb1e6SAndreas Gohr search($list,$conf['metadir'],array($this,'_search_count'),array('all'=>true)); 1605faeb1e6SAndreas Gohr $data['meta_count'] = $list['file_count']; 1615faeb1e6SAndreas Gohr $data['meta_size'] = $list['file_size']; 1625faeb1e6SAndreas Gohr $data['meta_biggest'] = $list['file_max']; 1635faeb1e6SAndreas Gohr $data['meta_smallest'] = $list['file_min']; 1645faeb1e6SAndreas Gohr if($list['file_count']) $data['meta_avg'] = $list['file_size'] / $list['file_count']; 1655faeb1e6SAndreas Gohr unset($list); 1665faeb1e6SAndreas Gohr 1675faeb1e6SAndreas Gohr // number and size of attic 1685faeb1e6SAndreas Gohr $list = array(); 1695faeb1e6SAndreas Gohr search($list,$conf['olddir'],array($this,'_search_count'),array('all'=>true)); 1705faeb1e6SAndreas Gohr $data['attic_count'] = $list['file_count']; 1715faeb1e6SAndreas Gohr $data['attic_size'] = $list['file_size']; 1725faeb1e6SAndreas Gohr $data['attic_biggest'] = $list['file_max']; 1735faeb1e6SAndreas Gohr $data['attic_smallest'] = $list['file_min']; 1745faeb1e6SAndreas Gohr if($list['file_count']) $data['attic_avg'] = $list['file_size'] / $list['file_count']; 1755faeb1e6SAndreas Gohr $data['attic_oldest'] = $list['file_oldest']; 1765faeb1e6SAndreas Gohr unset($list); 1775faeb1e6SAndreas Gohr 1785faeb1e6SAndreas Gohr // user count 1795faeb1e6SAndreas Gohr if($auth && $auth->canDo('getUserCount')){ 1805faeb1e6SAndreas Gohr $data['user_count'] = $auth->getUserCount(); 1815faeb1e6SAndreas Gohr } 1825faeb1e6SAndreas Gohr 1835faeb1e6SAndreas Gohr // calculate edits per day 1845faeb1e6SAndreas Gohr $list = @file($conf['metadir'].'/_dokuwiki.changes'); 1855faeb1e6SAndreas Gohr $count = count($list); 1865faeb1e6SAndreas Gohr if($count > 2){ 1875faeb1e6SAndreas Gohr $first = (int) substr(array_shift($list),0,10); 1885faeb1e6SAndreas Gohr $last = (int) substr(array_pop($list),0,10); 1895faeb1e6SAndreas Gohr $dur = ($last - $first)/(60*60*24); // number of days in the changelog 1905faeb1e6SAndreas Gohr $data['edits_per_day'] = $count/$dur; 1915faeb1e6SAndreas Gohr } 1925faeb1e6SAndreas Gohr unset($list); 1935faeb1e6SAndreas Gohr 1945faeb1e6SAndreas Gohr // plugins 1955faeb1e6SAndreas Gohr $data['plugin'] = plugin_list(); 1965faeb1e6SAndreas Gohr 1970deaa5d8SAndreas Gohr // pcre info 1980deaa5d8SAndreas Gohr if(defined('PCRE_VERSION')) $data['pcre_version'] = PCRE_VERSION; 1990deaa5d8SAndreas Gohr $data['pcre_backtrack'] = ini_get('pcre.backtrack_limit'); 2000deaa5d8SAndreas Gohr $data['pcre_recursion'] = ini_get('pcre.recursion_limit'); 2010deaa5d8SAndreas Gohr 2025faeb1e6SAndreas Gohr // php info 2035faeb1e6SAndreas Gohr $data['os'] = PHP_OS; 2045faeb1e6SAndreas Gohr $data['webserver'] = $_SERVER['SERVER_SOFTWARE']; 2055faeb1e6SAndreas Gohr $data['php_version'] = phpversion(); 2065faeb1e6SAndreas Gohr $data['php_sapi'] = php_sapi_name(); 2075faeb1e6SAndreas Gohr $data['php_memory'] = $this->_to_byte(ini_get('memory_limit')); 2085faeb1e6SAndreas Gohr $data['php_exectime'] = $phptime; 2095faeb1e6SAndreas Gohr $data['php_extension'] = get_loaded_extensions(); 2105faeb1e6SAndreas Gohr 2115faeb1e6SAndreas Gohr return $data; 2125faeb1e6SAndreas Gohr } 2135faeb1e6SAndreas Gohr 2145faeb1e6SAndreas Gohr 2155faeb1e6SAndreas Gohr function _search_count(&$data,$base,$file,$type,$lvl,$opts){ 2165faeb1e6SAndreas Gohr // traverse 2175faeb1e6SAndreas Gohr if($type == 'd'){ 2185faeb1e6SAndreas Gohr $data['dir_count']++; 2195faeb1e6SAndreas Gohr return true; 2205faeb1e6SAndreas Gohr } 2215faeb1e6SAndreas Gohr 2225faeb1e6SAndreas Gohr //only search txt files if 'all' option not set 2235faeb1e6SAndreas Gohr if($opts['all'] || substr($file,-4) == '.txt'){ 2245faeb1e6SAndreas Gohr $size = filesize($base.'/'.$file); 2255faeb1e6SAndreas Gohr $date = filemtime($base.'/'.$file); 2265faeb1e6SAndreas Gohr $data['file_count']++; 2275faeb1e6SAndreas Gohr $data['file_size'] += $size; 2285faeb1e6SAndreas Gohr if(!isset($data['file_min']) || $data['file_min'] > $size) $data['file_min'] = $size; 2295faeb1e6SAndreas Gohr if($data['file_max'] < $size) $data['file_max'] = $size; 2305faeb1e6SAndreas Gohr if(!isset($data['file_oldest']) || $data['file_oldest'] > $date) $data['file_oldest'] = $date; 2315faeb1e6SAndreas Gohr } 2325faeb1e6SAndreas Gohr return false; 2335faeb1e6SAndreas Gohr } 2345faeb1e6SAndreas Gohr 2355faeb1e6SAndreas Gohr /** 2365faeb1e6SAndreas Gohr * Convert php.ini shorthands to byte 2375faeb1e6SAndreas Gohr * 2385faeb1e6SAndreas Gohr * @author <gilthans dot NO dot SPAM at gmail dot com> 2395faeb1e6SAndreas Gohr * @link http://de3.php.net/manual/en/ini.core.php#79564 2405faeb1e6SAndreas Gohr */ 2415faeb1e6SAndreas Gohr function _to_byte($v){ 2425faeb1e6SAndreas Gohr $l = substr($v, -1); 2435faeb1e6SAndreas Gohr $ret = substr($v, 0, -1); 2445faeb1e6SAndreas Gohr switch(strtoupper($l)){ 2455faeb1e6SAndreas Gohr case 'P': 2465faeb1e6SAndreas Gohr $ret *= 1024; 2475faeb1e6SAndreas Gohr case 'T': 2485faeb1e6SAndreas Gohr $ret *= 1024; 2495faeb1e6SAndreas Gohr case 'G': 2505faeb1e6SAndreas Gohr $ret *= 1024; 2515faeb1e6SAndreas Gohr case 'M': 2525faeb1e6SAndreas Gohr $ret *= 1024; 2535faeb1e6SAndreas Gohr case 'K': 2545faeb1e6SAndreas Gohr $ret *= 1024; 2555faeb1e6SAndreas Gohr break; 2565faeb1e6SAndreas Gohr } 2575faeb1e6SAndreas Gohr return $ret; 2585faeb1e6SAndreas Gohr } 2595faeb1e6SAndreas Gohr} 260