Stats
Stats 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:
<?php
/**
* Displays a list of top contributors, ranked by number of pages owned, edits or comments.
* Displays number/ percent of pages owned by current user, total pages of wiki.
* Displays number of registered users.
*
* @package Actions
* @version $Id: highscores.php 820 2007-11-23 09:21:08Z DotMG $
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @filesource
*
* @author Chris Tessmer ... highscores.php, ownedpages.php (original code)
* @author {@link http://wikkawiki.org/DarTar Dario Taraborelli} (adding action parameters, styling, accessibility)
* @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.
*/
//define:
if(!
defined('STATS_TOP_QTY')) define('STATS_TOP_QTY',
5);
// number of high scores to show
if(!
defined('STATS_RANK_BY')) define('STATS_RANK_BY',
'pages');
// rank by: 'edits', 'pages', 'comments'
//i18n USE WIKI FORMATTING... %s will be replaced by the appropriate numerical value.
if(!
defined('STATS_USERS')) define('STATS_USERS',
'There are %s registered members.');
if(!
defined('STATS_PAGES_OWNED')) define('STATS_PAGES_OWNED',
'You own %s pages,');
if(!
defined('STATS_PERCENT_OWNED')) define('STATS_PERCENT_OWNED',
'%s percent of the total pages.');
if(!
defined('STATS_RANK_HEADER')) define('STATS_RANK_HEADER',
'Top %s contributors, by number of pages owned: ');
// count the number of users
$userdata = $this->LoadSingle("SELECT count(*) as num FROM ".$this->config["table_prefix"]."users ");
$users = $userdata["num"];
// stats about user... logged in?
if (($this->
IsAdmin() && !
empty($username)) ||
($this->GetUser() && $username = $this->GetUserName()))
{
$str = 'SELECT COUNT(*) FROM '.$this->config["table_prefix"].'pages WHERE `owner` ';
$str .= "= '" . $this->GetUserName() . "' AND `latest` = 'Y'";
$countQuery = $this->Query( $str );
// get the total # of pages
$str = 'SELECT COUNT(*) FROM '.$this->config["table_prefix"].'pages WHERE `latest` = \'Y\' ';
$totalQuery = $this->Query( $str );
$percent =
round( ($count/
$totalpages )*
100,
2 ) ;
//make a string to print... for logged in users
$output =
sprintf(STATS_USERS,
$users) .
' ' .
sprintf(STATS_PAGES_OWNED,
$count) .
' ' .
sprintf(STATS_PERCENT_OWNED,
$percent);
}else{
//output for not logged in user
$output =
sprintf(STATS_USERS,
$users);
}
$limit = STATS_TOP_QTY;
// query for top contributors
$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;
$total = $this->getCount('pages', "`latest` = 'Y'");
//fetch data
$rank_query = $this->Query($query);
$i = 0;
$str = '';
{
$i++;
$str .= ' '.$this->Link($row['name']);
$str .=
':('.
round(($row['cnt']/
$total)*
100,
1).
'%)'.
"\n";
if ($i < $limit)
{$str .= ' | '."\n";
}else{
$str .= '<br />';
}
}
// print it out...
echo '<span class="clip">'.
$str .
'</span>';
echo '<br /><span class="clip">'.
($this->
Format($output)).
'</span>';
?>
There are no comments on this page. [Add comment]