]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/SystemInfo.php
getName should not translate
[SourceForge/phpwiki.git] / lib / plugin / SystemInfo.php
1 <?php
2
3 /**
4  * Copyright (C) 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
5  * Copyright 2008-2009 Marc-Etienne Vargenau, Alcatel-Lucent
6  *
7  * This file is part of PhpWiki.
8  *
9  * PhpWiki is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * PhpWiki is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 /**
25  * Usage: <<SystemInfo all >>
26  *        or <<SystemInfo pagestats cachestats discspace hitstats >>
27  *        or <<SystemInfo version >>
28  *        or <<SystemInfo current_theme >>
29  *        or <<SystemInfo PHPWIKI_DIR >>
30  *
31  * Provide access to phpwiki's lower level system information.
32  *
33  *   version, pagestats, SERVER_NAME, database, discspace,
34  *   cachestats, userstats, linkstats, accessstats, hitstats,
35  *   revisionstats, interwikilinks, imageextensions, wikiwordregexp,
36  *   availableplugins, downloadurl  or any other predefined CONSTANT
37  *
38  * In spirit to http://www.ecyrd.com/JSPWiki/SystemInfo.jsp
39  *
40  * Done: Some calculations are heavy (~5-8 secs), so we should cache
41  *       the result. In the page or with WikiPluginCached?
42  */
43
44 require_once 'lib/WikiPluginCached.php';
45 class WikiPlugin_SystemInfo
46     extends WikiPluginCached
47 {
48     function getPluginType()
49     {
50         return PLUGIN_CACHED_HTML;
51     }
52
53     function getDescription()
54     {
55         return _("Provide access to PhpWiki's lower level system information.");
56     }
57
58     /* From lib/WikiPlugin.php:
59      * If the plugin can deduce a modification time, or equivalent
60      * sort of tag for it's content, then the plugin should
61      * call $request->appendValidators() with appropriate arguments,
62      * and should override this method to return true.
63      */
64     function managesValidators()
65     {
66         return true;
67     }
68
69     function getExpire($dbi, $argarray, $request)
70     {
71         return '+1800'; // 30 minutes
72     }
73
74     function getHtml($dbi, $argarray, $request, $basepage)
75     {
76         $loader = new WikiPluginLoader();
77         return $loader->expandPI('<<SystemInfo '
78             . WikiPluginCached::glueArgs($argarray) // all
79             . ' ?>', $request, $this, $basepage);
80     }
81
82     function getDefaultArguments()
83     {
84         return array( // 'seperator' => ' ', // on multiple args
85         );
86     }
87
88     function database()
89     {
90         $s = "DATABASE_TYPE: " . DATABASE_TYPE . ", ";
91         switch (DATABASE_TYPE) {
92             case 'SQL': // pear
93             case 'ADODB':
94             case 'PDO':
95                 $dsn = DATABASE_DSN;
96                 $s .= "DATABASE BACKEND:" . " ";
97                 $s .= (DATABASE_TYPE == 'SQL') ? 'PearDB' : 'ADODB';
98                 if (preg_match('/^(\w+):/', $dsn, $m)) {
99                     $backend = $m[1];
100                     $s .= " $backend";
101                 }
102                 $s .= ", DATABASE_PREFIX: \"" . DATABASE_PREFIX . "\", ";
103                 break;
104             case 'dba':
105                 $s .= "DATABASE_DBA_HANDLER: " . DATABASE_DBA_HANDLER . ", ";
106                 $s .= "DATABASE_DIRECTORY: \"" . DATABASE_DIRECTORY . "\", ";
107                 break;
108             case 'cvs':
109                 $s .= "DATABASE_DIRECTORY: \"" . DATABASE_DIRECTORY . "\", ";
110                 // $s .= "cvs stuff: , ";
111                 break;
112             case 'flatfile':
113                 $s .= "DATABASE_DIRECTORY: " . DATABASE_DIRECTORY . ", ";
114                 break;
115         }
116         // hack: suppress error when using sql, so no timeout
117         @$s .= "DATABASE_TIMEOUT: " . DATABASE_TIMEOUT;
118         return $s;
119     }
120
121     function cachestats()
122     {
123         if (!defined('USECACHE') or !USECACHE)
124             return _("no cache used");
125         $dbi =& $this->_dbi;
126         $cache = $dbi->_cache;
127         $s = _("cached pagedata:") . " " . count($cache->_pagedata_cache);
128         $s .= ", " . _("cached versiondata:");
129         $s .= " " . count($cache->_versiondata_cache);
130         //$s .= ", glv size: " . count($cache->_glv_cache);
131         //$s .= ", cache hits: ?";
132         //$s .= ", cache misses: ?";
133         return $s;
134     }
135
136     function ExpireParams()
137     {
138         global $ExpireParams;
139         $s = sprintf(_("Keep up to %d major edits, but keep them no longer than %d days."),
140             $ExpireParams['major']['keep'],
141             $ExpireParams['major']['max_age']);
142         $s .= sprintf(_(" Keep up to %d minor edits, but keep them no longer than %d days."),
143             $ExpireParams['minor']['keep'],
144             $ExpireParams['minor']['max_age']);
145         $s .= sprintf(_(" Keep the latest contributions of the last %d authors up to %d days."),
146             $ExpireParams['author']['keep'], $ExpireParams['author']['max_age']);
147         $s .= sprintf(_(" Additionally, try to keep the latest contributions of all authors in the last %d days (even if there are more than %d of them,) but in no case keep more than %d unique author revisions."),
148             $ExpireParams['author']['min_age'],
149             $ExpireParams['author']['keep'],
150             $ExpireParams['author']['max_keep']);
151         return $s;
152     }
153
154     function pagestats()
155     {
156         global $request;
157         $dbi = $request->getDbh();
158         $s = sprintf(_("%d pages"), $dbi->numPages(true));
159         $s .= ", " . sprintf(_("%d not-empty pages"), $dbi->numPages(false));
160         // more bla....
161         // $s  .= ", " . sprintf(_("earliest page from %s"), $earliestdate);
162         // $s  .= ", " . sprintf(_("latest page from %s"), $latestdate);
163         // $s  .= ", " . sprintf(_("latest pagerevision from %s"), $latestrevdate);
164         return $s;
165     }
166
167     //What kind of link statistics?
168     //  total links in, total links out, mean links per page, ...
169     //  Any useful numbers similar to a VisualWiki interestmap?
170     function linkstats()
171     {
172         $s = _("not yet");
173         return $s;
174     }
175
176     // number of homepages: easy
177     // number of anonymous users?
178     //   calc this from accesslog info?
179     // number of anonymous edits?
180     //   easy. related to the view/edit rate in accessstats.
181     function userstats()
182     {
183         $dbi =& $this->_dbi;
184         $h = 0;
185         $page_iter = $dbi->getAllPages(true);
186         while ($page = $page_iter->next()) {
187             if ($page->isUserPage(true)) // check if the admin is there. if not add him to the authusers.
188                 $h++;
189         }
190         $s = sprintf(_("%d homepages"), $h);
191         // $s  .= ", " . sprintf(_("%d anonymous users"), $au); // ??
192         // $s  .= ", " . sprintf(_("%d anonymous edits"), $ae); // see recentchanges
193         // $s  .= ", " . sprintf(_("%d authenticated users"), $auth); // users with password set
194         // $s  .= ", " . sprintf(_("%d externally authenticated users"), $extauth); // query AuthDB?
195         return $s;
196     }
197
198     //only from logging info possible. = hitstats per time.
199     // total hits per day/month/year
200     // view/edit rate
201     // TODO: see WhoIsOnline hit stats, and sql accesslogs
202     function accessstats()
203     {
204         $s = _("not yet");
205         return $s;
206     }
207
208     // numeric array
209     private function get_stats($hits, $treshold = 10.0)
210     {
211         sort($hits);
212         reset($hits);
213         $n = count($hits);
214         $max = 0;
215         $min = 9999999999999;
216         $sum = 0;
217         foreach ($hits as $h) {
218             $sum += $h;
219             $max = max($h, $max);
220             $min = min($h, $min);
221         }
222         $mean = $n ? $sum / $n : 0;
223         $median = $hits[ (int)($n / 2) ];
224         $mintreshold = $max * $treshold / 100.0; // lower than 10% of the hits
225         reset($hits);
226         $nmin = $hits[0] < $mintreshold ? 1 : 0;
227         while (next($hits) < $mintreshold)
228             $nmin++;
229         $maxtreshold = $max - $mintreshold; // more than 90% of the hits
230         end($hits);
231         $nmax = 1;
232         while (prev($hits) > $maxtreshold)
233             $nmax++;
234         return array('n' => $n,
235             'sum' => $sum,
236             'min' => $min,
237             'max' => $max,
238             'mean' => $mean,
239             'median' => $median,
240             'stddev' => stddev($hits, $sum),
241             'treshold' => $treshold,
242             'nmin' => $nmin,
243             'mintreshold' => $mintreshold,
244             'nmax' => $nmax,
245             'maxtreshold' => $maxtreshold);
246     }
247
248     // only absolute numbers, not for any time interval. see accessstats
249     //  some useful number derived from the curve of the hit stats.
250     //  total, max, mean, median, stddev;
251     //  %d pages less than 3 hits (<10%)    <10% percent of the leastpopular
252     //  %d pages more than 100 hits (>90%)  >90% percent of the mostpopular
253     function hitstats()
254     {
255         $dbi =& $this->_dbi;
256         $hits = array();
257         $page_iter = $dbi->getAllPages(true);
258         while ($page = $page_iter->next()) {
259             if (($current = $page->getCurrentRevision())
260                 && (!$current->hasDefaultContents())
261             ) {
262                 $hits[] = $page->get('hits');
263             }
264         }
265         $treshold = 10.0;
266         $stats = $this->get_stats($hits, $treshold);
267
268         $s = sprintf(_("total hits: %d"), $stats['sum']);
269         $s .= ", " . sprintf(_("max: %d"), $stats['max']);
270         $s .= ", " . sprintf(_("mean: %2.3f"), $stats['mean']);
271         $s .= ", " . sprintf(_("median: %d"), $stats['median']);
272         $s .= ", " . sprintf(_("stddev: %2.3f"), $stats['stddev']);
273         $s .= "; " . sprintf(_("%d pages with less than %d hits (<%d%%)."),
274             $stats['nmin'], $stats['mintreshold'], $treshold);
275         $s .= " " . sprintf(_("%d page(s) with more than %d hits (>%d%%)."),
276             $stats['nmax'], $stats['maxtreshold'], 100 - $treshold);
277         return $s;
278     }
279
280     /* not yet ready
281      */
282     function revisionstats()
283     {
284         global $LANG;
285
286         include_once 'lib/WikiPluginCached.php';
287         $cache = WikiPluginCached::newCache();
288         $id = $cache->generateId('SystemInfo::revisionstats_' . $LANG);
289         $cachedir = 'plugincache';
290         $content = $cache->get($id, $cachedir);
291
292         if (!empty($content))
293             return $content;
294
295         $dbi =& $this->_dbi;
296         $stats = array();
297         $page_iter = $dbi->getAllPages(true);
298         $stats['empty'] = $stats['latest']['major'] = $stats['latest']['minor'] = 0;
299         while ($page = $page_iter->next()) {
300             if (!$page->exists()) {
301                 $stats['empty']++;
302                 continue;
303             }
304             $current = $page->getCurrentRevision();
305             // is the latest revision a major or minor one?
306             //   latest revision: numpages 200 (100%) / major (60%) / minor (40%)
307             if ($current->get('is_minor_edit'))
308                 $stats['latest']['major']++;
309             else
310                 $stats['latest']['minor']++;
311             /*
312                         // FIXME: This needs much too long to be acceptable.
313                         // overall:
314                         //   number of revisions: all (100%) / major (60%) / minor (40%)
315                         // revs per page:
316                         //   per page: mean 20 / major (60%) / minor (40%)
317                         $rev_iter = $page->getAllRevisions();
318                         while ($rev = $rev_iter->next()) {
319                             if ($rev->get('is_minor_edit'))
320                                 $stats['page']['major']++;
321                             else
322                                 $stats['page']['minor']++;
323                         }
324                         $rev_iter->free();
325                         $stats['page']['all'] = $stats['page']['major'] + $stats['page']['minor'];
326                         $stats['perpage'][]       = $stats['page']['all'];
327                         $stats['perpage_major'][] = $stats['page']['major'];
328                         $stats['sum']['all'] += $stats['page']['all'];
329                         $stats['sum']['major'] += $stats['page']['major'];
330                         $stats['sum']['minor'] += $stats['page']['minor'];
331                         $stats['page'] = array();
332             */
333         }
334         $page_iter->free();
335         $stats['numpages'] = $stats['latest']['major'] + $stats['latest']['minor'];
336         $stats['latest']['major_perc'] = $stats['latest']['major'] * 100.0 / $stats['numpages'];
337         $stats['latest']['minor_perc'] = $stats['latest']['minor'] * 100.0 / $stats['numpages'];
338         $empty = sprintf("empty pages: %d (%02.1f%%) / %d (100%%)\n",
339             $stats['empty'], $stats['empty'] * 100.0 / $stats['numpages'],
340             $stats['numpages']);
341         $latest = sprintf("latest revision: major %d (%02.1f%%) / minor %d (%02.1f%%) / all %d (100%%)\n",
342             $stats['latest']['major'], $stats['latest']['major_perc'],
343             $stats['latest']['minor'], $stats['latest']['minor_perc'], $stats['numpages']);
344         /*
345                 $stats['sum']['major_perc'] = $stats['sum']['major'] * 100.0 / $stats['sum']['all'];
346                 $stats['sum']['minor_perc'] = $stats['sum']['minor'] * 100.0 / $stats['sum']['all'];
347                 $sum = sprintf("number of revisions: major %d (%02.1f%%) / minor %d (%02.1f%%) / all %d (100%%)\n",
348                                $stats['sum']['major'], $stats['sum']['major_perc'],
349                                $stats['sum']['minor'], $stats['sum']['minor_perc'], $stats['sum']['all']);
350
351                 $stats['perpage']       = $this->get_stats($stats['perpage']);
352                 $stats['perpage_major'] = $this->get_stats($stats['perpage_major']);
353                 $stats['perpage']['major_perc'] = $stats['perpage_major']['sum'] * 100.0 / $stats['perpage']['sum'];
354                 $stats['perpage']['minor_perc'] = 100 - $stats['perpage']['major_perc'];
355                 $stats['perpage_minor']['sum']  = $stats['perpage']['sum'] - $stats['perpage_major']['sum'];
356                 $stats['perpage_minor']['mean'] = $stats['perpage_minor']['sum'] / ($stats['perpage']['n'] - $stats['perpage_major']['n']);
357                 $perpage = sprintf("revisions per page: all %d, mean %02.1f / major %d (%02.1f%%) / minor %d (%02.1f%%)\n",
358                                    $stats['perpage']['sum'], $stats['perpage']['mean'],
359                                    $stats['perpage_major']['mean'], $stats['perpage']['major_perc'],
360                                    $stats['perpage_minor']['mean'], $stats['perpage']['minor_perc']);
361                 $perpage .= sprintf("  %d page(s) with less than %d revisions (<%d%%)\n",
362                                     $stats['perpage']['nmin'], $stats['perpage']['maintreshold'], $treshold);
363                 $perpage .= sprintf("  %d page(s) with more than %d revisions (>%d%%)\n",
364                                     $stats['perpage']['nmax'], $stats['perpage']['maxtreshold'], 100 - $treshold);
365                 $content = $empty . $latest . $sum . $perpage;
366         */
367         $content = $empty . $latest;
368
369         // regenerate cache every 30 minutes
370         $cache->save($id, $content, '+1800', $cachedir);
371         return $content;
372     }
373
374     // Size of databases/files/cvs are possible plus the known size of the app.
375     // Cache this costly operation.
376     // Even if the whole plugin call is stored internally, we cache this
377     // separately with a separate key.
378     function discspace()
379     {
380         global $DBParams;
381
382         include_once 'lib/WikiPluginCached.php';
383         $cache = WikiPluginCached::newCache();
384         $id = $cache->generateId('SystemInfo::discspace');
385         $cachedir = 'plugincache';
386         $content = $cache->get($id, $cachedir);
387
388         if (empty($content)) {
389             $dir = defined('PHPWIKI_DIR') ? PHPWIKI_DIR : '.';
390             //TODO: windows only (no cygwin)
391             $appsize = `du -s $dir | cut -f1`;
392
393             if (in_array($DBParams['dbtype'], array('SQL', 'ADODB'))) {
394                 //TODO: where is the data is actually stored? see phpMyAdmin
395                 $pagesize = 0;
396             } elseif ($DBParams['dbtype'] == 'dba') {
397                 $pagesize = 0;
398                 $dbdir = $DBParams['directory'];
399                 if ($DBParams['dba_handler'] == 'db3')
400                     $pagesize = filesize($DBParams['directory']
401                         . "/wiki_pagedb.db3") / 1024;
402                 // if issubdirof($dbdir, $dir) $appsize -= $pagesize;
403             } else { // flatfile, cvs
404                 $dbdir = $DBParams['directory'];
405                 $pagesize = `du -s $dbdir`;
406                 // if issubdirof($dbdir, $dir) $appsize -= $pagesize;
407             }
408             $content = array('appsize' => $appsize,
409                 'pagesize' => $pagesize);
410             // regenerate cache every 30 minutes
411             $cache->save($id, $content, '+1800', $cachedir);
412         } else {
413             $appsize = $content['appsize'];
414             $pagesize = $content['pagesize'];
415         }
416
417         $s = sprintf(_("Application size: %d KiB"), $appsize);
418         if ($pagesize)
419             $s .= ", " . sprintf(_("Pagedata size: %d KiB", $pagesize));
420         return $s;
421     }
422
423     function inlineimages()
424     {
425         return implode(' ', explode('|', INLINE_IMAGES));
426     }
427
428     function wikinameregexp()
429     {
430         return $GLOBALS['WikiNameRegexp'];
431     }
432
433     function allowedprotocols()
434     {
435         return implode(' ', explode('|', ALLOWED_PROTOCOLS));
436     }
437
438     function available_plugins()
439     {
440         $fileset = new FileSet(FindFile('lib/plugin'), '*.php');
441         $list = $fileset->getFiles();
442         natcasesort($list);
443         reset($list);
444         return sprintf(_("Total %d plugins: "), count($list))
445             . implode(', ', array_map(create_function('$f',
446                     'return substr($f,0,-4);'),
447                 $list));
448     }
449
450     function supported_languages()
451     {
452         $available_languages = listAvailableLanguages();
453         natcasesort($available_languages);
454
455         return sprintf(_("Total of %d languages: "),
456             count($available_languages))
457             . implode(', ', $available_languages) . ". "
458             . _("Current language") . _(": ") . $GLOBALS['LANG']
459             . ((DEFAULT_LANGUAGE != $GLOBALS['LANG'])
460                 ? ". " . sprintf(_("Default language: “%s”"), DEFAULT_LANGUAGE)
461                 : '');
462     }
463
464     function supported_themes()
465     {
466         global $WikiTheme;
467         $available_themes = listAvailableThemes();
468         natcasesort($available_themes);
469         return sprintf(_("Total of %d themes: "), count($available_themes))
470             . implode(', ', $available_themes) . ". "
471             . _("Current theme") . _(": ") . $WikiTheme->_name
472             . ((THEME != $WikiTheme->_name)
473                 ? ". " . sprintf(_("Default theme: “%s”"), THEME)
474                 : '');
475     }
476
477     function call($arg, &$availableargs)
478     {
479         if (!empty($availableargs[$arg]))
480             return $availableargs[$arg]();
481         elseif (method_exists($this, $arg)) // any defined SystemInfo->method()
482             return call_user_func_array(array(&$this, $arg), array()); elseif (defined($arg) && // any defined constant
483             !in_array($arg, array('ADMIN_PASSWD', 'DATABASE_DSN', 'DBAUTH_AUTH_DSN'))
484         )
485             return constant($arg); else
486             return $this->error(sprintf(_("unknown argument “%s” to SystemInfo"), $arg));
487     }
488
489     function run($dbi, $argstr, &$request, $basepage)
490     {
491         // don't parse argstr for name=value pairs. instead we use just 'name'
492         //$args = $this->getArgs($argstr, $request);
493         $this->_dbi =& $dbi;
494         $args['seperator'] = ' ';
495         $availableargs = // name => callback + 0 args
496             array('appname' => create_function('', "return 'PhpWiki';"),
497                 'version' => create_function('', "return sprintf('%s', PHPWIKI_VERSION);"),
498                 'LANG' => create_function('', 'return $GLOBALS["LANG"];'),
499                 'LC_ALL' => create_function('', 'return setlocale(LC_ALL, 0);'),
500                 'current_language' => create_function('', 'return $GLOBALS["LANG"];'),
501                 'system_language' => create_function('', 'return DEFAULT_LANGUAGE;'),
502                 'current_theme' => create_function('', 'return $GLOBALS["WikiTheme"]->_name;'),
503                 'system_theme' => create_function('', 'return THEME;'),
504                 // more here or as method.
505                 '' => create_function('', "return 'dummy';")
506             );
507         // split the argument string by any number of commas or space
508         // characters, which include " ", \r, \t, \n and \f
509         $allargs = preg_split("/[\s,]+/", $argstr, -1, PREG_SPLIT_NO_EMPTY);
510         if (in_array('all', $allargs) || in_array('table', $allargs)) {
511             $allargs = array('appname' => _("Application name"),
512                 'version' => _("PhpWiki engine version"),
513                 'database' => _("Database"),
514                 'cachestats' => _("Cache statistics"),
515                 'pagestats' => _("Page statistics"),
516                 //'revisionstats'    => _("Page revision statistics"),
517                 //'linkstats'        => _("Link statistics"),
518                 'userstats' => _("User statistics"),
519                 //'accessstats'      => _("Access statistics"),
520                 'hitstats' => _("Hit statistics"),
521                 'discspace' => _("Harddisc usage"),
522                 'expireparams' => _("Expiry parameters"),
523                 'wikinameregexp' => _("Wikiname regexp"),
524                 'allowedprotocols' => _("Allowed protocols"),
525                 'inlineimages' => _("Inline images"),
526                 'available_plugins' => _("Available plugins"),
527                 'supported_languages' => _("Supported languages"),
528                 'supported_themes' => _("Supported themes"),
529 //                           '' => _(""),
530                 '' => ""
531             );
532             $table = HTML::table(array('class' => 'bordered'));
533             foreach ($allargs as $arg => $desc) {
534                 if (!$arg)
535                     continue;
536                 if (!$desc)
537                     $desc = _($arg);
538                 $table->pushContent(HTML::tr(HTML::th(array('style' => "white-space:nowrap"), $desc),
539                     HTML::td(HTML($this->call($arg, $availableargs)))));
540             }
541             return $table;
542         } else {
543             $output = '';
544             foreach ($allargs as $arg) {
545                 $o = $this->call($arg, $availableargs);
546                 if (is_object($o))
547                     return $o;
548                 else
549                     $output .= ($o . $args['seperator']);
550             }
551             // if more than one arg, remove the trailing seperator
552             if ($output) $output = substr($output, 0,
553                 -strlen($args['seperator']));
554             return HTML($output);
555         }
556     }
557 }
558
559 function median($hits)
560 {
561     sort($hits);
562     reset($hits);
563     $n = count($hits);
564     $median = (int)($n / 2);
565     if (!($n % 2)) // proper rounding on even length
566         return ($hits[$median] + $hits[$median - 1]) * 0.5;
567     else
568         return $hits[$median];
569 }
570
571 function rsum($a, $b)
572 {
573     $a += $b;
574     return $a;
575 }
576
577 function mean(&$hits, $total = false)
578 {
579     $n = count($hits);
580     if (!$total)
581         $total = array_reduce($hits, 'rsum');
582     return (float)$total / ($n * 1.0);
583 }
584
585 function stddev(&$hits, $total = false)
586 {
587     $n = count($hits);
588     if (!$total) $total = array_reduce($hits, 'rsum');
589     $GLOBALS['mean'] = $total / $n;
590     $r = array_map(create_function('$i', 'global $mean; return ($i-$mean)*($i-$mean);'),
591         $hits);
592     unset($GLOBALS['mean']);
593     return (float)sqrt(mean($r, $total) * ($n / (float)($n - 1)));
594 }
595
596 // Local Variables:
597 // mode: php
598 // tab-width: 8
599 // c-basic-offset: 4
600 // c-hanging-comment-ender-p: nil
601 // indent-tabs-mode: nil
602 // End: