<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
?>
</div>