====== Statistics ====== ===== Best Links ===== phpWiki has a very nice feature: shows the top 5 best incoming links, the top 5 outgoing links and the 5 most popular pages related to each current page. This is something that DokuWiki misses. It's not just a Most/Least popular pages (overall), but a per page statistical overview of page's association. How hard it is to implement this, doesn't require a database or should it use a database engine? If a DB engine is required, then it's something outside the scope of DokuWiki's goals and philosophy, am I right? -- Straider (2004.09.09). > This kind of statistics is usually provided by loganalyzers. Including it into DokuWiki would require some kind of metadata storage for every single page which could be done as plain textfile. But this is currently not on my todo list as I don't need it. --- [[andi@splitbrain.org|Andi]] >> I understand your point. It's just that most times the visitors have no access to statistics from log analyzers. That prevents them from knowing which is best. There are some very light-weighted statistics libraries/packages that could be "thrown-in" to support this feature. And now coming to think about it, not many analyzers have this: for each page do keep track of top-5 referer-page and exiting-page. It's not a hits/log statistics functionality, but a page-tracking feature. >>> Have a look at http://ubuntuusers.de/wiki/start. That site uses [[http://bbclone.de/|bbclone]] for doing statistics (-> http://ubuntuusers.de/stats/). As bbclone is php-based it should run on every site hosting Dokuwiki as well. Unfortunately ubuntuusers only seem to log access to html-pages, so all wiki pages are only logged to Wiki->Doku. I had better results with the following setup: just download and unpack bbclone and extend Dokuwiki's doku.php with the following code: // ************* // BBCLONE // ************* define("_BBC_PAGE_NAME", $_GET["id"]); define("_BBCLONE_DIR", "bbclone/"); define("COUNTER", _BBCLONE_DIR."mark_page.php"); if (is_readable(COUNTER)) include_once(COUNTER); >**IMPORTANT NOTICE** - as the system administrator of [[http://www.ubuntuusers.de|ubuntuusers]] i've noticed that bbclone has big problems with pages of more than 50 Users online at one time. You shouldn't use bbclone if you have a big page. >> yes, bbclone isn't a good idea for big sites. I used it at [[http://www.running-gag.de]] and it killed my site multiple times... The problem: bbclone is file driven, and saved everything in php arrays inside of the files. If the files are to big the php parser ends the parsing of the real page. So the website is broken and nobody can use it anymore until the bbclone cache was dropped. It happens on my webpage with 3000 users a day at least once a day so I dropped it out. But for my smaller DokuWiki page [[http://www.tinytoon-fan.de]] it's a good solution, but all statistics are PIs, not users -- LH (2005.10.27) > The stats page seems to be gone. > Have a look at [[wiki:tips:logging|Page statistics with Dokuwiki]]. This patch adds code to Dokuwiki that writes a apache like log file so that usual report generators could be used to get nice wiki statistics.\\ --- //[[matthiasgrimm@users.sourceforge.net|Matthias Grimm]] 2005-11-22 20:13// ====== Adding access count to your DokuWiki pages ====== function handle_counter() { global $INFO; $counter_file=str_replace('pages','accesses',$INFO[filepath]); clearstatcache(); ignore_user_abort(true); ## prevent refresh from aborting file operations and hosing file if (file_exists($counter_file)) { $fh = fopen($counter_file, 'r+'); while(1) { if (flock($fh, LOCK_EX)) { $buffer = chop(fread($fh, filesize($counter_file))); $buffer++; rewind($fh); fwrite($fh, $buffer); fflush($fh); ftruncate($fh, ftell($fh)); flock($fh, LOCK_UN); break; } } } else { $fh = fopen($counter_file, 'w+'); fwrite($fh, "1"); $buffer="1"; } fclose($fh); ignore_user_abort(false); return $buffer*1; // If something goes wrong with the file, make sure we return a number, so 0 if its some string } in template.php function tpl_pageinfo(), in the block: if($INFO['exists']){ add something like print 'Acessed '.handle_counter().' times'; You have to create a directory "accesses" under data (with the right permission), if you have multiple wikis you have to create individual directories for each of them under this folder. > I did this, but changed a bit. To keep your dokuwiki install easilly upgradeable, you should put the function above to the end of your tpl/yourOwnTemplate/main.php file. You can also add the call to the template next to the **tpl_pageinfo()** call. Like this. I also would change the end of the fuonction like this. Add @ to the fopen calls. Also add a check for the success of fopen. function handle_counter() { global $INFO; $counter_file=str_replace('pages','accesses',$INFO[filepath]); clearstatcache(); ignore_user_abort(true); ## prevent refresh from aborting file operations and hosing file if (file_exists($counter_file)) { $fh = @fopen($counter_file, 'r+'); if ($fh) { while(1) { if (flock($fh, LOCK_EX)) { $buffer = chop(fread($fh, filesize($counter_file))); $buffer++; rewind($fh); fwrite($fh, $buffer); fflush($fh); ftruncate($fh, ftell($fh)); flock($fh, LOCK_UN); break; } } } } else { $fh = @fopen($counter_file, 'w+'); if ($fh) { fwrite($fh, "1"); } $buffer="1"; } if ($fh) { fclose($fh); } ignore_user_abort(false); return $buffer*1; // If something goes wrong with the file, make sure we return a number, so 0 if its some string } --- //[[otto@valjakko.net|Otto Vainio]] 2005-10-02 21:29// Also refer [[http://wiki.erazor-zone.de/doku.php?id=wiki:projects:php:dokuwiki:counter|E-Razor's tip]] as mentioned on [[wiki:tips]]. This page includes methods for several different versions of Dokuwiki. --- //Richard Rayner 2007-09-05 // instead of: $counter_file=str_replace('pages','accesses',$INFO[filepath]); i used $counter_file=str_replace('.txt','.accesses',$INFO[filepath]); because otherwise it was throwing up errors if the namespaces were not created in the accesses dir. This way it creates a file in the namespace matching the filename and since the file and namespace is already created before the accesses are logged, i dont get any errors, nor do i need to manually create the structure.