1*5faeb1e6SAndreas Gohr<?php 2*5faeb1e6SAndreas Gohr/** 3*5faeb1e6SAndreas Gohr * Popularity Feedback Plugin 4*5faeb1e6SAndreas Gohr * 5*5faeb1e6SAndreas Gohr * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6*5faeb1e6SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 7*5faeb1e6SAndreas Gohr */ 8*5faeb1e6SAndreas Gohr// must be run within Dokuwiki 9*5faeb1e6SAndreas Gohrif(!defined('DOKU_INC')) die(); 10*5faeb1e6SAndreas Gohr 11*5faeb1e6SAndreas Gohrif(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 12*5faeb1e6SAndreas Gohrrequire_once(DOKU_PLUGIN.'admin.php'); 13*5faeb1e6SAndreas Gohrrequire_once(DOKU_INC.'inc/infoutils.php'); 14*5faeb1e6SAndreas Gohrrequire_once(DOKU_INC.'inc/pluginutils.php'); 15*5faeb1e6SAndreas Gohrrequire_once(DOKU_INC.'inc/search.php'); 16*5faeb1e6SAndreas Gohr 17*5faeb1e6SAndreas Gohr/** 18*5faeb1e6SAndreas Gohr * All DokuWiki plugins to extend the admin function 19*5faeb1e6SAndreas Gohr * need to inherit from this class 20*5faeb1e6SAndreas Gohr */ 21*5faeb1e6SAndreas Gohrclass admin_plugin_popularity extends DokuWiki_Admin_Plugin { 22*5faeb1e6SAndreas Gohr var $version = '2008-02-18'; 23*5faeb1e6SAndreas Gohr 24*5faeb1e6SAndreas Gohr 25*5faeb1e6SAndreas Gohr /** 26*5faeb1e6SAndreas Gohr * return some info 27*5faeb1e6SAndreas Gohr */ 28*5faeb1e6SAndreas Gohr function getInfo(){ 29*5faeb1e6SAndreas Gohr return array( 30*5faeb1e6SAndreas Gohr 'author' => 'Andreas Gohr', 31*5faeb1e6SAndreas Gohr 'email' => 'andi@splitbrain.org', 32*5faeb1e6SAndreas Gohr 'date' => $this->version, 33*5faeb1e6SAndreas Gohr 'name' => 'Popularity Feedback Plugin', 34*5faeb1e6SAndreas Gohr 'desc' => 'Send anonymous data about your wiki to the developers.', 35*5faeb1e6SAndreas Gohr 'url' => 'http://wiki.splitbrain.org/wiki:popularity', 36*5faeb1e6SAndreas Gohr ); 37*5faeb1e6SAndreas Gohr } 38*5faeb1e6SAndreas Gohr 39*5faeb1e6SAndreas Gohr /** 40*5faeb1e6SAndreas Gohr * return prompt for admin menu 41*5faeb1e6SAndreas Gohr */ 42*5faeb1e6SAndreas Gohr function getMenuText($language) { 43*5faeb1e6SAndreas Gohr return $this->getLang('name'); 44*5faeb1e6SAndreas Gohr } 45*5faeb1e6SAndreas Gohr 46*5faeb1e6SAndreas Gohr /** 47*5faeb1e6SAndreas Gohr * return sort order for position in admin menu 48*5faeb1e6SAndreas Gohr */ 49*5faeb1e6SAndreas Gohr function getMenuSort() { 50*5faeb1e6SAndreas Gohr return 2000; 51*5faeb1e6SAndreas Gohr } 52*5faeb1e6SAndreas Gohr 53*5faeb1e6SAndreas Gohr /** 54*5faeb1e6SAndreas Gohr * handle user request 55*5faeb1e6SAndreas Gohr * 56*5faeb1e6SAndreas Gohr * 57*5faeb1e6SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 58*5faeb1e6SAndreas Gohr */ 59*5faeb1e6SAndreas Gohr function handle() { 60*5faeb1e6SAndreas Gohr } 61*5faeb1e6SAndreas Gohr 62*5faeb1e6SAndreas Gohr /** 63*5faeb1e6SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 64*5faeb1e6SAndreas Gohr */ 65*5faeb1e6SAndreas Gohr function html() { 66*5faeb1e6SAndreas Gohr echo $this->locale_xhtml('intro'); 67*5faeb1e6SAndreas Gohr 68*5faeb1e6SAndreas Gohr flush(); 69*5faeb1e6SAndreas Gohr $data = $this->_gather(); 70*5faeb1e6SAndreas Gohr echo '<form method="post" action="http://update.dokuwiki.org/popularity.php" accept-charset="utf-8">'; 71*5faeb1e6SAndreas Gohr echo '<fieldset style="width: 60%;">'; 72*5faeb1e6SAndreas Gohr echo '<textarea class="edit" rows="10" cols="80" readonly="readonly" name="data">'; 73*5faeb1e6SAndreas Gohr foreach($data as $key => $val){ 74*5faeb1e6SAndreas Gohr if(is_array($val)) foreach($val as $v){ 75*5faeb1e6SAndreas Gohr echo hsc($key)."\t".hsc($v)."\n"; 76*5faeb1e6SAndreas Gohr }else{ 77*5faeb1e6SAndreas Gohr echo hsc($key)."\t".hsc($val)."\n"; 78*5faeb1e6SAndreas Gohr } 79*5faeb1e6SAndreas Gohr } 80*5faeb1e6SAndreas Gohr echo '</textarea><br />'; 81*5faeb1e6SAndreas Gohr echo '<input type="submit" class="button" value="'.$this->getLang('submit').'"/>'; 82*5faeb1e6SAndreas Gohr echo '</fieldset>'; 83*5faeb1e6SAndreas Gohr echo '</form>'; 84*5faeb1e6SAndreas Gohr 85*5faeb1e6SAndreas Gohr// dbg($data); 86*5faeb1e6SAndreas Gohr } 87*5faeb1e6SAndreas Gohr 88*5faeb1e6SAndreas Gohr 89*5faeb1e6SAndreas Gohr /** 90*5faeb1e6SAndreas Gohr * Gather all information 91*5faeb1e6SAndreas Gohr */ 92*5faeb1e6SAndreas Gohr function _gather(){ 93*5faeb1e6SAndreas Gohr global $conf; 94*5faeb1e6SAndreas Gohr global $auth; 95*5faeb1e6SAndreas Gohr $data = array(); 96*5faeb1e6SAndreas Gohr $phptime = ini_get('max_execution_time'); 97*5faeb1e6SAndreas Gohr @set_time_limit(0); 98*5faeb1e6SAndreas Gohr 99*5faeb1e6SAndreas Gohr // version 100*5faeb1e6SAndreas Gohr $data['anon_id'] = md5(auth_cookiesalt()); 101*5faeb1e6SAndreas Gohr $data['version'] = getVersion(); 102*5faeb1e6SAndreas Gohr $data['popversion'] = $this->version; 103*5faeb1e6SAndreas Gohr $data['language'] = $conf['lang']; 104*5faeb1e6SAndreas Gohr $data['now'] = time(); 105*5faeb1e6SAndreas Gohr 106*5faeb1e6SAndreas Gohr // some config values 107*5faeb1e6SAndreas Gohr $data['conf_useacl'] = $conf['useacl']; 108*5faeb1e6SAndreas Gohr $data['conf_authtype'] = $conf['authtype']; 109*5faeb1e6SAndreas Gohr $data['conf_template'] = $conf['template']; 110*5faeb1e6SAndreas Gohr 111*5faeb1e6SAndreas Gohr // number and size of pages 112*5faeb1e6SAndreas Gohr $list = array(); 113*5faeb1e6SAndreas Gohr search($list,$conf['datadir'],array($this,'_search_count'),'',''); 114*5faeb1e6SAndreas Gohr $data['page_count'] = $list['file_count']; 115*5faeb1e6SAndreas Gohr $data['page_size'] = $list['file_size']; 116*5faeb1e6SAndreas Gohr $data['page_biggest'] = $list['file_max']; 117*5faeb1e6SAndreas Gohr $data['page_smallest'] = $list['file_min']; 118*5faeb1e6SAndreas Gohr if($list['file_count']) $data['page_avg'] = $list['file_size'] / $list['file_count']; 119*5faeb1e6SAndreas Gohr $data['page_oldest'] = $list['file_oldest']; 120*5faeb1e6SAndreas Gohr unset($list); 121*5faeb1e6SAndreas Gohr 122*5faeb1e6SAndreas Gohr // number and size of media 123*5faeb1e6SAndreas Gohr $list = array(); 124*5faeb1e6SAndreas Gohr search($list,$conf['mediadir'],array($this,'_search_count'),array('all'=>true)); 125*5faeb1e6SAndreas Gohr $data['media_count'] = $list['file_count']; 126*5faeb1e6SAndreas Gohr $data['media_size'] = $list['file_size']; 127*5faeb1e6SAndreas Gohr $data['media_biggest'] = $list['file_max']; 128*5faeb1e6SAndreas Gohr $data['media_smallest'] = $list['file_min']; 129*5faeb1e6SAndreas Gohr if($list['file_count']) $data['media_avg'] = $list['file_size'] / $list['file_count']; 130*5faeb1e6SAndreas Gohr unset($list); 131*5faeb1e6SAndreas Gohr 132*5faeb1e6SAndreas Gohr // number and size of cache 133*5faeb1e6SAndreas Gohr $list = array(); 134*5faeb1e6SAndreas Gohr search($list,$conf['cachedir'],array($this,'_search_count'),array('all'=>true)); 135*5faeb1e6SAndreas Gohr $data['cache_count'] = $list['file_count']; 136*5faeb1e6SAndreas Gohr $data['cache_size'] = $list['file_size']; 137*5faeb1e6SAndreas Gohr $data['cache_biggest'] = $list['file_max']; 138*5faeb1e6SAndreas Gohr $data['cache_smallest'] = $list['file_min']; 139*5faeb1e6SAndreas Gohr if($list['file_count']) $data['cache_avg'] = $list['file_size'] / $list['file_count']; 140*5faeb1e6SAndreas Gohr unset($list); 141*5faeb1e6SAndreas Gohr 142*5faeb1e6SAndreas Gohr // number and size of index 143*5faeb1e6SAndreas Gohr $list = array(); 144*5faeb1e6SAndreas Gohr search($list,$conf['indexdir'],array($this,'_search_count'),array('all'=>true)); 145*5faeb1e6SAndreas Gohr $data['index_count'] = $list['file_count']; 146*5faeb1e6SAndreas Gohr $data['index_size'] = $list['file_size']; 147*5faeb1e6SAndreas Gohr $data['index_biggest'] = $list['file_max']; 148*5faeb1e6SAndreas Gohr $data['index_smallest'] = $list['file_min']; 149*5faeb1e6SAndreas Gohr if($list['file_count']) $data['index_avg'] = $list['file_size'] / $list['file_count']; 150*5faeb1e6SAndreas Gohr unset($list); 151*5faeb1e6SAndreas Gohr 152*5faeb1e6SAndreas Gohr // number and size of meta 153*5faeb1e6SAndreas Gohr $list = array(); 154*5faeb1e6SAndreas Gohr search($list,$conf['metadir'],array($this,'_search_count'),array('all'=>true)); 155*5faeb1e6SAndreas Gohr $data['meta_count'] = $list['file_count']; 156*5faeb1e6SAndreas Gohr $data['meta_size'] = $list['file_size']; 157*5faeb1e6SAndreas Gohr $data['meta_biggest'] = $list['file_max']; 158*5faeb1e6SAndreas Gohr $data['meta_smallest'] = $list['file_min']; 159*5faeb1e6SAndreas Gohr if($list['file_count']) $data['meta_avg'] = $list['file_size'] / $list['file_count']; 160*5faeb1e6SAndreas Gohr unset($list); 161*5faeb1e6SAndreas Gohr 162*5faeb1e6SAndreas Gohr // number and size of attic 163*5faeb1e6SAndreas Gohr $list = array(); 164*5faeb1e6SAndreas Gohr search($list,$conf['olddir'],array($this,'_search_count'),array('all'=>true)); 165*5faeb1e6SAndreas Gohr $data['attic_count'] = $list['file_count']; 166*5faeb1e6SAndreas Gohr $data['attic_size'] = $list['file_size']; 167*5faeb1e6SAndreas Gohr $data['attic_biggest'] = $list['file_max']; 168*5faeb1e6SAndreas Gohr $data['attic_smallest'] = $list['file_min']; 169*5faeb1e6SAndreas Gohr if($list['file_count']) $data['attic_avg'] = $list['file_size'] / $list['file_count']; 170*5faeb1e6SAndreas Gohr $data['attic_oldest'] = $list['file_oldest']; 171*5faeb1e6SAndreas Gohr unset($list); 172*5faeb1e6SAndreas Gohr 173*5faeb1e6SAndreas Gohr // user count 174*5faeb1e6SAndreas Gohr if($auth && $auth->canDo('getUserCount')){ 175*5faeb1e6SAndreas Gohr $data['user_count'] = $auth->getUserCount(); 176*5faeb1e6SAndreas Gohr } 177*5faeb1e6SAndreas Gohr 178*5faeb1e6SAndreas Gohr // calculate edits per day 179*5faeb1e6SAndreas Gohr $list = @file($conf['metadir'].'/_dokuwiki.changes'); 180*5faeb1e6SAndreas Gohr $count = count($list); 181*5faeb1e6SAndreas Gohr if($count > 2){ 182*5faeb1e6SAndreas Gohr $first = (int) substr(array_shift($list),0,10); 183*5faeb1e6SAndreas Gohr $last = (int) substr(array_pop($list),0,10); 184*5faeb1e6SAndreas Gohr $dur = ($last - $first)/(60*60*24); // number of days in the changelog 185*5faeb1e6SAndreas Gohr $data['edits_per_day'] = $count/$dur; 186*5faeb1e6SAndreas Gohr } 187*5faeb1e6SAndreas Gohr unset($list); 188*5faeb1e6SAndreas Gohr 189*5faeb1e6SAndreas Gohr // plugins 190*5faeb1e6SAndreas Gohr $data['plugin'] = plugin_list(); 191*5faeb1e6SAndreas Gohr 192*5faeb1e6SAndreas Gohr // php info 193*5faeb1e6SAndreas Gohr $data['os'] = PHP_OS; 194*5faeb1e6SAndreas Gohr $data['webserver'] = $_SERVER['SERVER_SOFTWARE']; 195*5faeb1e6SAndreas Gohr $data['php_version'] = phpversion(); 196*5faeb1e6SAndreas Gohr $data['php_sapi'] = php_sapi_name(); 197*5faeb1e6SAndreas Gohr $data['php_memory'] = $this->_to_byte(ini_get('memory_limit')); 198*5faeb1e6SAndreas Gohr $data['php_exectime'] = $phptime; 199*5faeb1e6SAndreas Gohr $data['php_extension'] = get_loaded_extensions(); 200*5faeb1e6SAndreas Gohr 201*5faeb1e6SAndreas Gohr return $data; 202*5faeb1e6SAndreas Gohr } 203*5faeb1e6SAndreas Gohr 204*5faeb1e6SAndreas Gohr 205*5faeb1e6SAndreas Gohr function _search_count(&$data,$base,$file,$type,$lvl,$opts){ 206*5faeb1e6SAndreas Gohr // traverse 207*5faeb1e6SAndreas Gohr if($type == 'd'){ 208*5faeb1e6SAndreas Gohr $data['dir_count']++; 209*5faeb1e6SAndreas Gohr return true; 210*5faeb1e6SAndreas Gohr } 211*5faeb1e6SAndreas Gohr 212*5faeb1e6SAndreas Gohr //only search txt files if 'all' option not set 213*5faeb1e6SAndreas Gohr if($opts['all'] || substr($file,-4) == '.txt'){ 214*5faeb1e6SAndreas Gohr $size = filesize($base.'/'.$file); 215*5faeb1e6SAndreas Gohr $date = filemtime($base.'/'.$file); 216*5faeb1e6SAndreas Gohr $data['file_count']++; 217*5faeb1e6SAndreas Gohr $data['file_size'] += $size; 218*5faeb1e6SAndreas Gohr if(!isset($data['file_min']) || $data['file_min'] > $size) $data['file_min'] = $size; 219*5faeb1e6SAndreas Gohr if($data['file_max'] < $size) $data['file_max'] = $size; 220*5faeb1e6SAndreas Gohr if(!isset($data['file_oldest']) || $data['file_oldest'] > $date) $data['file_oldest'] = $date; 221*5faeb1e6SAndreas Gohr } 222*5faeb1e6SAndreas Gohr return false; 223*5faeb1e6SAndreas Gohr } 224*5faeb1e6SAndreas Gohr 225*5faeb1e6SAndreas Gohr /** 226*5faeb1e6SAndreas Gohr * Convert php.ini shorthands to byte 227*5faeb1e6SAndreas Gohr * 228*5faeb1e6SAndreas Gohr * @author <gilthans dot NO dot SPAM at gmail dot com> 229*5faeb1e6SAndreas Gohr * @link http://de3.php.net/manual/en/ini.core.php#79564 230*5faeb1e6SAndreas Gohr */ 231*5faeb1e6SAndreas Gohr function _to_byte($v){ 232*5faeb1e6SAndreas Gohr $l = substr($v, -1); 233*5faeb1e6SAndreas Gohr $ret = substr($v, 0, -1); 234*5faeb1e6SAndreas Gohr switch(strtoupper($l)){ 235*5faeb1e6SAndreas Gohr case 'P': 236*5faeb1e6SAndreas Gohr $ret *= 1024; 237*5faeb1e6SAndreas Gohr case 'T': 238*5faeb1e6SAndreas Gohr $ret *= 1024; 239*5faeb1e6SAndreas Gohr case 'G': 240*5faeb1e6SAndreas Gohr $ret *= 1024; 241*5faeb1e6SAndreas Gohr case 'M': 242*5faeb1e6SAndreas Gohr $ret *= 1024; 243*5faeb1e6SAndreas Gohr case 'K': 244*5faeb1e6SAndreas Gohr $ret *= 1024; 245*5faeb1e6SAndreas Gohr break; 246*5faeb1e6SAndreas Gohr } 247*5faeb1e6SAndreas Gohr return $ret; 248*5faeb1e6SAndreas Gohr } 249*5faeb1e6SAndreas Gohr} 250