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