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