3 * Popularity Feedback Plugin
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author Andreas Gohr <andi@splitbrain.org>
8 // must be run within Dokuwiki
9 if(!defined('DOKU_INC')) die();
11 if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC
.'lib/plugins/');
12 require_once(DOKU_PLUGIN
.'admin.php');
13 require_once(DOKU_INC
.'inc/infoutils.php');
14 require_once(DOKU_INC
.'inc/pluginutils.php');
15 require_once(DOKU_INC
.'inc/search.php');
18 * All DokuWiki plugins to extend the admin function
19 * need to inherit from this class
21 class admin_plugin_popularity
extends DokuWiki_Admin_Plugin
{
22 var $version = '2008-02-20';
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://dokuwiki.org/plugin:popularity',
40 * return prompt for admin menu
42 function getMenuText($language) {
43 return $this->getLang('name');
47 * return sort order for position in admin menu
49 function getMenuSort() {
54 * Accessible for managers
56 function forAdminOnly() {
71 echo $this->locale_xhtml('intro');
74 $data = $this->_gather();
75 echo '<form method="post" action="http://update.dokuwiki.org/popularity.php" accept-charset="utf-8">';
76 echo '<fieldset style="width: 60%;">';
77 echo '<textarea class="edit" rows="10" cols="80" readonly="readonly" name="data">';
78 foreach($data as $key => $val){
79 if(is_array($val)) foreach($val as $v){
80 echo hsc($key)."\t".hsc($v)."\n";
82 echo hsc($key)."\t".hsc($val)."\n";
85 echo '</textarea><br />';
86 echo '<input type="submit" class="button" value="'.$this->getLang('submit').'"/>';
95 * Gather all information
101 $phptime = ini_get('max_execution_time');
105 $data['anon_id'] = md5(auth_cookiesalt());
106 $data['version'] = getVersion();
107 $data['popversion'] = $this->version
;
108 $data['language'] = $conf['lang'];
109 $data['now'] = time();
111 // some config values
112 $data['conf_useacl'] = $conf['useacl'];
113 $data['conf_authtype'] = $conf['authtype'];
114 $data['conf_template'] = $conf['template'];
116 // number and size of pages
118 search($list,$conf['datadir'],array($this,'_search_count'),'','');
119 $data['page_count'] = $list['file_count'];
120 $data['page_size'] = $list['file_size'];
121 $data['page_biggest'] = $list['file_max'];
122 $data['page_smallest'] = $list['file_min'];
123 if($list['file_count']) $data['page_avg'] = $list['file_size'] / $list['file_count'];
124 $data['page_oldest'] = $list['file_oldest'];
127 // number and size of media
129 search($list,$conf['mediadir'],array($this,'_search_count'),array('all'=>true));
130 $data['media_count'] = $list['file_count'];
131 $data['media_size'] = $list['file_size'];
132 $data['media_biggest'] = $list['file_max'];
133 $data['media_smallest'] = $list['file_min'];
134 if($list['file_count']) $data['media_avg'] = $list['file_size'] / $list['file_count'];
137 // number and size of cache
139 search($list,$conf['cachedir'],array($this,'_search_count'),array('all'=>true));
140 $data['cache_count'] = $list['file_count'];
141 $data['cache_size'] = $list['file_size'];
142 $data['cache_biggest'] = $list['file_max'];
143 $data['cache_smallest'] = $list['file_min'];
144 if($list['file_count']) $data['cache_avg'] = $list['file_size'] / $list['file_count'];
147 // number and size of index
149 search($list,$conf['indexdir'],array($this,'_search_count'),array('all'=>true));
150 $data['index_count'] = $list['file_count'];
151 $data['index_size'] = $list['file_size'];
152 $data['index_biggest'] = $list['file_max'];
153 $data['index_smallest'] = $list['file_min'];
154 if($list['file_count']) $data['index_avg'] = $list['file_size'] / $list['file_count'];
157 // number and size of meta
159 search($list,$conf['metadir'],array($this,'_search_count'),array('all'=>true));
160 $data['meta_count'] = $list['file_count'];
161 $data['meta_size'] = $list['file_size'];
162 $data['meta_biggest'] = $list['file_max'];
163 $data['meta_smallest'] = $list['file_min'];
164 if($list['file_count']) $data['meta_avg'] = $list['file_size'] / $list['file_count'];
167 // number and size of attic
169 search($list,$conf['olddir'],array($this,'_search_count'),array('all'=>true));
170 $data['attic_count'] = $list['file_count'];
171 $data['attic_size'] = $list['file_size'];
172 $data['attic_biggest'] = $list['file_max'];
173 $data['attic_smallest'] = $list['file_min'];
174 if($list['file_count']) $data['attic_avg'] = $list['file_size'] / $list['file_count'];
175 $data['attic_oldest'] = $list['file_oldest'];
179 if($auth && $auth->canDo('getUserCount')){
180 $data['user_count'] = $auth->getUserCount();
183 // calculate edits per day
184 $list = @file
($conf['metadir'].'/_dokuwiki.changes');
185 $count = count($list);
187 $first = (int) substr(array_shift($list),0,10);
188 $last = (int) substr(array_pop($list),0,10);
189 $dur = ($last - $first)/(60*60*24); // number of days in the changelog
190 $data['edits_per_day'] = $count/$dur;
195 $data['plugin'] = plugin_list();
198 if(defined('PCRE_VERSION')) $data['pcre_version'] = PCRE_VERSION
;
199 $data['pcre_backtrack'] = ini_get('pcre.backtrack_limit');
200 $data['pcre_recursion'] = ini_get('pcre.recursion_limit');
203 $data['os'] = PHP_OS
;
204 $data['webserver'] = $_SERVER['SERVER_SOFTWARE'];
205 $data['php_version'] = phpversion();
206 $data['php_sapi'] = php_sapi_name();
207 $data['php_memory'] = $this->_to_byte(ini_get('memory_limit'));
208 $data['php_exectime'] = $phptime;
209 $data['php_extension'] = get_loaded_extensions();
215 function _search_count(&$data,$base,$file,$type,$lvl,$opts){
218 $data['dir_count']++
;
222 //only search txt files if 'all' option not set
223 if($opts['all'] ||
substr($file,-4) == '.txt'){
224 $size = filesize($base.'/'.$file);
225 $date = filemtime($base.'/'.$file);
226 $data['file_count']++
;
227 $data['file_size'] +
= $size;
228 if(!isset($data['file_min']) ||
$data['file_min'] > $size) $data['file_min'] = $size;
229 if($data['file_max'] < $size) $data['file_max'] = $size;
230 if(!isset($data['file_oldest']) ||
$data['file_oldest'] > $date) $data['file_oldest'] = $date;
236 * Convert php.ini shorthands to byte
238 * @author <gilthans dot NO dot SPAM at gmail dot com>
239 * @link http://de3.php.net/manual/en/ini.core.php#79564
241 function _to_byte($v){
243 $ret = substr($v, 0, -1);
244 switch(strtoupper($l)){