Wiki source for InfoHandler


Show raw source

=====Info Handler=====

This is the development page for the ##**info**## handler.
The ##info## handler displays information and statistics about the current page.

>>**See also:**
~-UnderDevelopment
~-WikkaBetaFeatures
~-PageAdminAction
~-PageStatsAction
**Note:** The ##info## handler is installed on this server as a beta feature.
>><<**Table of Contents:**
~-""<a href="InfoHandler#hn_Usage">Usage</a>""
~-""<a href="InfoHandler#hn_Sample_output">Sample output</a>""
~-""<a href="InfoHandler#hn_Current_version">Current version</a>""
~-""<a href="InfoHandler#hn_Change_log">Change log</a>""
~-""<a href="InfoHandler#hn_The_code">The code</a>""
~-""<a href="InfoHandler#hn_Styling">Styling</a>""<<
::c::

=== Usage ===
Append ##[[http://wikka.jsnx.com/HomePage/info | /info]]## to the URL of the page or click on "Stats" in the page footer.

----
==Sample output==
""
<h4 id="hn_Page_statistics_for_HomePage"> Page statistics for <a href="http://wikka.jsnx.com/HomePage">HomePage</a> </h4>
<!-- Header id generation took 0.000024 seconds --> <br /> <br /> <br /> <!-- Header id generation took 0.000220 seconds --><h5 id="hn_Page_revisions_authorpage_totals:">Page revisions (<tt>author/page totals</tt>):</h5>
<table summary="List of authors of the current page ordered by number of edits">
<thead>
<tr>
<th>User</th>
<th class="number">Edits</th>
<th class="number">%</th>
<th>Percentage</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="http://wikka.jsnx.com/JsnX">JsnX</a></td>
<td class="number">124/183</td>
<td class="number">67.76%</td>
<td><span title = "67.76%" class="c6" style="float:left; height: 1.4em; width: 203.28px"></span></td>
</tr>
<tr>
<td><a href="http://wikka.jsnx.com/DarTar">DarTar</a></td>
<td class="number">53/183</td>
<td class="number">28.96%</td>
<td><span title = "28.96%" class="c6" style="float:left; height: 1.4em; width: 86.89px"></span></td>
</tr>
<tr>
<td><a href="http://wikka.jsnx.com/JavaWoman">JavaWoman</a></td>
<td class="number">5/183</td>
<td class="number">2.73%</td>
<td><span title = "2.73%" class="c6" style="float:left; height: 1.4em; width: 8.2px"></span></td>
</tr>
<tr>
<td><tt>WakkaInstaller</tt></td>
<td class="number">1/183</td>
<td class="number">0.55%</td>
<td><span title = "0.55%" class="c6" style="float:left; height: 1.4em; width: 1.64px"></span></td>
</tr>
</tbody></table>
<p> </p>
<!-- Header id generation took 0.000229 seconds --><h5 id="hn_Global_statistics_pagesite_totals:">Global statistics (<tt>page/site totals</tt>):</h5>
<table summary="Statistics for current page">
<thead>
<tr>
<th>Statistics</th>
<th class="number">Count</th>
<th class="number">%</th>
<th>Percentage</th>
</tr>
</thead>
<tbody>
<tr><td>Hits</td><td class="number"><a href="http://wikka.jsnx.com/HomePage/hits" title="Hits for HomePage (1)">1</a>/1</td><td class="number">100%</td><td><span title = "100%" class="c1" style="float:left; height: 1.4em; width: 300px"></span></td></tr>
<tr><td>Revisions</td><td class="number"><a href="http://wikka.jsnx.com/HomePage/revisions" title="Display revisions for HomePage (183)">183</a>/10193</td><td class="number">1.8%</td><td><span title = "1.8%" class="c2" style="float:left; height: 1.4em; width: 5.39px"></span></td></tr>
<tr><td>Comments</td><td class="number"><a href="http://wikka.jsnx.com/HomePage?show_comments=1#comments" title="Display comments for HomePage (96)">96</a>/2051</td><td class="number">4.68%</td><td><span title = "4.68%" class="c3" style="float:left; height: 1.4em; width: 14.04px"></span></td></tr>
<tr><td>Backlinks</td><td class="number"><a href="http://wikka.jsnx.com/HomePage/backlinks" title="Display pages linking to HomePage (50)">50</a>/5549</td><td class="number">0.9%</td><td><span title = "0.9%" class="c4" style="float:left; height: 1.4em; width: 2.7px"></span></td></tr>
<tr><td>Referrers</td><td class="number"><a href="http://wikka.jsnx.com/HomePage/referrers" title="Display external sites linking to HomePage (34294)">34294</a>/67978</td><td class="number">50.45%</td><td><span title = "50.45%" class="c5" style="float:left; height: 1.4em; width: 151.35px"></span></td></tr>
</tbody></table>
""
----

=== Current version ===
(2005-08-07)

Latest available version: ##**0.3**##

=== Change log ===

==0.3==
~- bugfix: preventing divide by zero errors;

----
=== The code ===

**Dependencies:** The ##info## handler uses:
~-the **##[[FormatUserMethod | FormatUser()]]##** method, that must be added to ##wikka.php##, at the end of the user-related functions, right after ##""function UserWantsComments()""##;
~-the **##[[WikkaCountingRecords | getCount()]]##** method, that must be added to ##wikka.php## right after the ##""LoadAll()""## method.

Copy the following code as: ##handlers/page/info.php##

%%(php;1)
<div class="page">
<?php
/**
* Displays information on the current page.
*
* Usage: append /info to the URL of the page.
*
* @package Handlers
* @name info
*
* @author {@link http://wikka.jsnx.com/DarTar Dario Taraborelli} - first draft.
* @version 0.3
* @since Wikka 1.1.X.X
*
* @todo - bar styling in the CSS;
* - optimize queries and code;
*/

//Defaults as constants
// -------------------------------------

// set default constant values
define('PERCENTAGE_BAR_WIDTH', '300'); # max width of percentage bar in pixels
define('PERCENTAGE_BAR_STYLE', 'float:left; height: 1.4em; width: %s'); # style attribute for percentage bar (do not edit the width value)
define('PERCENTAGE_BAR_COLOR_AUTHORS', 'c6'); # class for setting percentage bar color
define('PERCENTAGE_BAR_COLOR_HITS', 'c1'); # class for setting percentage bar color
define('PERCENTAGE_BAR_COLOR_REVISIONS', 'c2'); # class for setting percentage bar color
define('PERCENTAGE_BAR_COLOR_COMMENTS', 'c3'); # class for setting percentage bar color
define('PERCENTAGE_BAR_COLOR_BACKLINKS', 'c4'); # class for setting percentage bar color
define('PERCENTAGE_BAR_COLOR_REFERRERS', 'c5'); # class for setting percentage bar color
define('PERCENTAGE_DECIMALS_ROUND', '2'); # decimals for rounding percentage values;
define('OPTION_LINK', '1'); # enable linking to userpages
define('OPTION_HOSTNAME_LENGTH', '20'); # max. length for hostnames

// -------------------------------------
// User-interface: strings

define('PAGE_TITLE','Page statistics for %s');
define('HEADING_AUTHORS','Page revisions (##author/page totals##):');
define('HEADING_STATS','Global statistics (##page/site totals##):');
define('ERROR_PAGE_NOT_EXISTING','Sorry, this page does not exist.');
define('ERROR_NO_ACCESS','Sorry, You don\'t have access to this page.');
define('TABLE_AUTHORS_SUMMARY','List of authors of the current page ordered by number of edits');
define('TABLE_AUTHORS_HEADING_USER','User');
define('TABLE_AUTHORS_HEADING_EDITS','Edits');
define('TABLE_AUTHORS_HEADING_PERCENTAGE_BAR','Percentage');
define('TABLE_AUTHORS_HEADING_PERCENTAGE','%');
define('TABLE_CELL_HITS_TITLE','Hits for %s (%d)');
define('TABLE_CELL_REVISIONS_TITLE','Display revisions for %s (%d)');
define('TABLE_CELL_COMMENTS_TITLE','Display comments for %s (%d)');
define('TABLE_CELL_BACKLINKS_TITLE','Display pages linking to %s (%d)');
define('TABLE_CELL_REFERRERS_TITLE','Display external sites linking to %s (%d)');
define('TABLE_STATS_SUMMARY','Statistics for current page');
define('TABLE_STATS_HEADING_STATISTICS','Statistics');
define('TABLE_STATS_HEADING_COUNT','Count');
define('TABLE_STATS_HEADING_PERCENTAGE_BAR','Percentage');
define('TABLE_STATS_HEADING_PERCENTAGE','%');

//initialize variables

$output = '';
$tag = '';
$box = '';

// print header
echo $this->Format('=== '.sprintf(PAGE_TITLE,'[['.$this->tag.']]').' ===');

// 1. check source page existence
if (!$this->page)
{
// source page does not exist!
$box = ERROR_PAGE_NOT_EXISTING;
}
else
{
$tag = $this->page['tag'];

// 2. page exists - now check user's read-access to the source page
if (!$this->HasAccess('read'))
{
// user can't read source page!
$box = ERROR_NO_ACCESS;
} else
{
// page exists and user has read-access to the source - proceed

// --- Authors ---

$authors = $this->LoadAll('SELECT user, COUNT(*) AS edits FROM '.$this->config['table_prefix'].'pages WHERE `tag` = "'.$tag.'" GROUP BY user ORDER BY edits DESC, user ASC');
$totaledits = $this->getCount('pages', '`tag` = "'.$tag.'"');
$output .= $this->Format('=='.HEADING_AUTHORS.'==');
if ($authors)
{
$output .= "<table summary=\"".TABLE_AUTHORS_SUMMARY."\">\n<thead>\n<tr>\n<th>".TABLE_AUTHORS_HEADING_USER."</th>\n<th class=\"number\">".TABLE_AUTHORS_HEADING_EDITS."</th>\n<th class=\"number\">".TABLE_AUTHORS_HEADING_PERCENTAGE."</th>\n<th>".TABLE_AUTHORS_HEADING_PERCENTAGE_BAR."</th>\n</tr>\n</thead>\n<tbody>\n";
foreach($authors as $author)
{
$percentage = $author['edits'] / $totaledits * 100;
$bar_width = round((PERCENTAGE_BAR_WIDTH * $author['edits'] / $totaledits),PERCENTAGE_DECIMALS_ROUND).'px';
$rounded_percentage = round($percentage,PERCENTAGE_DECIMALS_ROUND).'%';
$bar = '<span title = "'.$rounded_percentage.'" class="'.PERCENTAGE_BAR_COLOR_AUTHORS.'" style="'.sprintf(PERCENTAGE_BAR_STYLE, $bar_width).'"></span>';
$output .= "<tr>\n<td>".$this->FormatUser($author['user'], OPTION_LINK, OPTION_HOSTNAME_LENGTH)."</td>\n".
"<td class=\"number\">".$author['edits']."/".$totaledits."</td>\n".
"<td class=\"number\">".$rounded_percentage."</td>\n".
"<td>".$bar."</td>\n".
"</tr>\n";
}
$output .= "</tbody></table>\n";
}

$output .= "<p> </p>\n";

// --- Statistics ---

$whereTag = "`tag` = '".$tag."'";
$wherePageTag = "`page_tag` = '".$tag."'";
$whereToTag = "`to_tag` = '".$tag."'";
$hn = 1; #forthcoming
$rv = $this->getCount('pages',$whereTag);
$cn = $this->getCount('comments',$wherePageTag);
$bn = $this->getCount('links',$whereToTag);
$rn = $this->getCount('referrers',$wherePageTag);

$totalhn = 1; #forthcoming
$totalrv = $this->getCount('pages');
$totalcn = $this->getCount('comments');
$totalbn = $this->getCount('links');
$totalrn = $this->getCount('referrers');

// @@ note: the link generation below is redundant and should be optimized

// get page hits (forthcoming)
$hitspage = ($hn > 0) ? '<a href="'.$this->Href('hits',$tag, '').'" title="'.sprintf(TABLE_CELL_HITS_TITLE, $tag, $hn).'">'.$hn.'</a>' : '0';
if ($totalhn > 0)
{
$hnpercentage = round($hn / $totalhn * 100, PERCENTAGE_DECIMALS_ROUND).'%';
$hnwidth = round((PERCENTAGE_BAR_WIDTH * $hn / $totalhn), PERCENTAGE_DECIMALS_ROUND).'px';
} else
{
$hnpercentage = '0%';
$hnwidth = '0px';
}
$hnbar = '<span title = "'.$hnpercentage.'" class="'.PERCENTAGE_BAR_COLOR_HITS.'" style="'.sprintf(PERCENTAGE_BAR_STYLE, $hnwidth).'"></span>';

// get page revisions and create revision link if needed
$revpage = ($rv > 0) ? '<a href="'.$this->Href('revisions',$tag, '').'" title="'.sprintf(TABLE_CELL_REVISIONS_TITLE, $tag, $rv).'">'.$rv.'</a>' : '0';
if ($totalrv > 0)
{
$rvpercentage = round($rv / $totalrv * 100, PERCENTAGE_DECIMALS_ROUND).'%';
$rvwidth = round((PERCENTAGE_BAR_WIDTH * $rv / $totalrv), PERCENTAGE_DECIMALS_ROUND).'px';
} else
{
$rvpercentage = '0%';
$rvwidth = '0px';
}
$rvbar = '<span title = "'.$rvpercentage.'" class="'.PERCENTAGE_BAR_COLOR_REVISIONS.'" style="'.sprintf(PERCENTAGE_BAR_STYLE, $rvwidth).'"></span>';

// get page comments and create comments link if needed
$commentspage = ($cn > 0) ? '<a href="'.$this->Href('',$tag, 'show_comments=1#comments').'" title="'.sprintf(TABLE_CELL_COMMENTS_TITLE, $tag, $cn).'">'.$cn.'</a>' : '0';
if ($totalcn > 0)
{
$cnpercentage = round($cn / $totalcn * 100, PERCENTAGE_DECIMALS_ROUND).'%';
$cnwidth = round((PERCENTAGE_BAR_WIDTH * $cn / $totalcn), PERCENTAGE_DECIMALS_ROUND).'px';
} else
{
$cnpercentage = '0%';
$cnwidth = '0px';
}
$cnbar = '<span title = "'.$cnpercentage.'" class="'.PERCENTAGE_BAR_COLOR_COMMENTS.'" style="'.sprintf(PERCENTAGE_BAR_STYLE, $cnwidth).'"></span>';

// get page backlinks and create backlinks link
$backlinkpage = ($bn > 0) ? '<a href="'.$this->Href('backlinks',$tag, '').'" title="'.sprintf(TABLE_CELL_BACKLINKS_TITLE, $tag, $bn).'">'.$bn.'</a>' : '0';
if ($totalbn > 0)
{
$bnpercentage = round($bn / $totalbn * 100, PERCENTAGE_DECIMALS_ROUND).'%';
$bnwidth = round((PERCENTAGE_BAR_WIDTH * $bn / $totalbn), PERCENTAGE_DECIMALS_ROUND).'px';
} else
{
$bnpercentage = '0%';
$bnwidth = '0px';
}
$bnbar = '<span title = "'.$bnpercentage.'" class="'.PERCENTAGE_BAR_COLOR_BACKLINKS.'" style="'.sprintf(PERCENTAGE_BAR_STYLE, $bnwidth).'"></span>';

// get page referrers and create referrer link
$refpage = ($rn > 0) ? '<a href="'.$this->Href('referrers',$tag, '').'" title="'.sprintf(TABLE_CELL_REFERRERS_TITLE, $tag, $rn).'">'.$rn.'</a>' : '0';
if ($totalrn > 0)
{
$rnpercentage = round($rn / $totalrn * 100, PERCENTAGE_DECIMALS_ROUND).'%';
$rnwidth = round((PERCENTAGE_BAR_WIDTH * $rn / $totalrn), PERCENTAGE_DECIMALS_ROUND).'px';
} else
{
$rnpercentage = '0%';
$rnwidth = '0px';
}
$rnbar = '<span title = "'.$rnpercentage.'" class="'.PERCENTAGE_BAR_COLOR_REFERRERS.'" style="'.sprintf(PERCENTAGE_BAR_STYLE, $rnwidth).'"></span>';

$output .= $this->Format('=='.HEADING_STATS.'==');

$output .= "<table summary=\"".TABLE_STATS_SUMMARY."\">\n<thead>\n<tr>\n<th>".TABLE_STATS_HEADING_STATISTICS."</th>\n<th class=\"number\">".TABLE_STATS_HEADING_COUNT."</th>\n<th class=\"number\">".TABLE_STATS_HEADING_PERCENTAGE."</th>\n<th>".TABLE_STATS_HEADING_PERCENTAGE_BAR."</th>\n</tr>\n</thead>\n<tbody>\n".
'<tr><td>Hits</td><td class="number">'.$hitspage.'/'.$totalhn.'</td><td class="number">'.$hnpercentage.'</td><td>'.$hnbar.'</td></tr>'."\n".
'<tr><td>Revisions</td><td class="number">'.$revpage.'/'.$totalrv.'</td><td class="number">'.$rvpercentage.'</td><td>'.$rvbar.'</td></tr>'."\n".
'<tr><td>Comments</td><td class="number">'.$commentspage.'/'.$totalcn.'</td><td class="number">'.$cnpercentage.'</td><td>'.$cnbar.'</td></tr>'."\n".
'<tr><td>Backlinks</td><td class="number">'.$backlinkpage.'/'.$totalbn.'</td><td class="number">'.$bnpercentage.'</td><td>'.$bnbar.'</td></tr>'."\n".
'<tr><td>Referrers</td><td class="number">'.$refpage.'/'.$totalrn.'</td><td class="number">'.$rnpercentage.'</td><td>'.$rnbar.'</td></tr>'."\n".
'</tbody></table>'."\n";

// --- actions --- (forthcoming)

}
}

// display messages
if (isset($box)) echo $this->Format(' --- '.$box.' --- --- ');
// print form
if (isset($output)) print $output;
?>
</div>
%%

=== Styling ===

The ##info## handler uses a bunch of [[ChartStyling | CSS classes]] for styling the percentage bars.


----
CategoryDevelopmentHandlers
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki