Wiki source for StatsFooter


Show raw source

>>Tested with: WikkaWiki version **1.1.6.4**, in the footer only.
Example: [[www.prepare4descent.net/DescentiaPedia | 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 [[www.prepare4descent.net/DescentiaPedia | 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;1;statsft.php)
<?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.
* ToDo: Change count user to reflect the number of actual users, instead of the total number of users in the database.
*/
//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 );

$count = mysql_result($countQuery, 0);
$totalpages = mysql_result($totalQuery, 0);

$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 contributers
$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 = '';
while($row = mysql_fetch_array($rank_query))
{
$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 sprintf(STATS_RANK_HEADER, STATS_TOP_QTY);
echo '<span class="clip">'. $str .'</span>';
echo '<br /><span class="clip">'. ($this->Format($output)).'</span>';
?>
%%

----
See also:
ActionsInFooter
----
Categories:
CategoryStyle
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki