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