Tested with: WikkaWiki version 1.1.6.4, in the footer only.
Example: DescentiaPedia

Stats

StatsFooter is an action I cobbled together from existing actions, (highscores.php, ownedpages.php, countusers.php) it is intended to be used in the footer, as seen at DescentiaPedia. I have not tested this to see if it can be used in a page. Nor have I tested this in any version of wikka other than 1.1.6.4. Here is the code:
statsft.php (line 1)
  1. <?php
  2. /**
  3.  * Displays a list of top contributors, ranked by number of pages owned, edits or comments.
  4.  * Displays number/ percent of pages owned by current user, total pages of wiki.
  5.  * Displays number of registered users.
  6.  *
  7.  * @package     Actions
  8.  * @version     $Id: highscores.php 820 2007-11-23 09:21:08Z DotMG $
  9.  * @license     http://www.gnu.org/copyleft/gpl.html GNU General Public License
  10.  * @filesource
  11.  *
  12.  * @author  Chris Tessmer ... highscores.php, ownedpages.php (original code)
  13.  * @author  {@link http://wikkawiki.org/DarTar Dario Taraborelli} (adding action parameters, styling, accessibility)
  14.  * @author   {@link http://wikkawiki.org/WillyPs W. P. Sullivan} Hacked together code from several actions, removed  unneeded code, and format for use in the footer.
  15.  * ToDo: Change count user to reflect the number of actual users, instead of the total number of users in the database.
  16. */
  17. //define:
  18. if(!defined('STATS_TOP_QTY')) define('STATS_TOP_QTY', 5); // number of high scores to show
  19. if(!defined('STATS_RANK_BY')) define('STATS_RANK_BY', 'pages');// rank by: 'edits', 'pages', 'comments'
  20. //i18n   USE WIKI FORMATTING... %s will be replaced by the appropriate numerical value.
  21. if(!defined('STATS_USERS')) define('STATS_USERS', 'There are %s registered members.');
  22. if(!defined('STATS_PAGES_OWNED')) define('STATS_PAGES_OWNED', 'You own %s pages,');
  23. if(!defined('STATS_PERCENT_OWNED')) define('STATS_PERCENT_OWNED', '%s percent of the total pages.');
  24. if(!defined('STATS_RANK_HEADER')) define('STATS_RANK_HEADER', 'Top %s contributors, by number of pages owned: ');
  25.  
  26.     // count the number of users
  27.     $userdata = $this->LoadSingle("SELECT count(*) as num FROM ".$this->config["table_prefix"]."users ");
  28.     $users = $userdata["num"];
  29.    
  30.     // stats about user... logged in?
  31.     if (($this->IsAdmin() && !empty($username)) ||
  32.     ($this->GetUser() &&  $username = $this->GetUserName()))
  33.         {
  34.             $str = 'SELECT COUNT(*) FROM '.$this->config["table_prefix"].'pages WHERE `owner` ';
  35.             $str .= "= '" . $this->GetUserName() . "' AND `latest` = 'Y'";
  36.             $countQuery = $this->Query( $str );
  37.    
  38.             // get the total # of pages
  39.             $str = 'SELECT COUNT(*) FROM '.$this->config["table_prefix"].'pages WHERE `latest` = \'Y\' ';
  40.             $totalQuery = $this->Query( $str );    
  41.    
  42.             $count  = mysql_result($countQuery, 0);
  43.             $totalpages  = mysql_result($totalQuery, 0);
  44.    
  45.             $percent = round( ($count/$totalpages )*100, 2 ) ;
  46.             //make a string to print... for logged in users
  47.             $output = sprintf(STATS_USERS, $users) . ' ' . sprintf(STATS_PAGES_OWNED, $count) . ' ' . sprintf(STATS_PERCENT_OWNED, $percent);
  48.         }else{
  49.             //output for not logged in user
  50.             $output = sprintf(STATS_USERS, $users);
  51.             }
  52.        
  53.     $limit = STATS_TOP_QTY;
  54.  
  55. //  query for top contributers
  56.     $query = 'SELECT COUNT(*) AS cnt, `name`  FROM '.$this->GetConfigValue('table_prefix').'users, '.$this->GetConfigValue('table_prefix').'pages WHERE `name` = `owner` AND `latest` = "Y" GROUP BY name ORDER BY cnt DESC LIMIT '.$limit;
  57.     $total = $this->getCount('pages', "`latest` = 'Y'");
  58.  
  59.  
  60. //fetch data
  61. $rank_query = $this->Query($query);
  62.  
  63. $i = 0;
  64. $str = '';
  65. while($row = mysql_fetch_array($rank_query))
  66. {
  67.     $i++;
  68.     $str .= ' '.$this->Link($row['name']);
  69.     $str .= ':('.round(($row['cnt']/$total)*100, 1).'%)'."\n";
  70.     if ($i < $limit)
  71.         {$str .= ' | '."\n";
  72.         }else{
  73.             $str .= '<br />';
  74.             }
  75. }
  76. // print it out...
  77. echo sprintf(STATS_RANK_HEADER, STATS_TOP_QTY);
  78. echo '<span class="clip">'. $str .'</span>';
  79. echo '<br /><span class="clip">'. ($this->Format($output)).'</span>';
  80. ?>



See also:
ActionsInFooter

Categories:
CategoryStyle
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki