Revision [10281]
This is an old revision of InfoHandler made by DarTar on 2005-07-30 19:19:08.
Info Handler
See also:
Note: The info handler is installed on this server as a beta feature.
Note: The info handler is installed on this server as a beta feature.
This is the development page for the info handler.
The info handler displays information and statistics about the current page.
Usage:
Append /info to any pagename in your browser.Sample output:
Information about page
>WikkaInternationalization</a> </h3><!-- Header id generation took 0.000024 seconds --> <br /> <br /> <br /> <!-- Header id generation took 0.000197 seconds --><h5 id="hn_Authors:">Authors:</h5>
<table summary="List of authors of the current page ordered by number of edits">
<thead>
<tr>
<th>User</th>
<th>Edits</th>
<th>Percentage</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="http://wikka.jsnx.com/JsnX" title=" ">JsnX</a></td>
<td class="number">4</td>
<td><span style="display:block; font-size:.8em; background-color:red; width: 100px">25%</span></td>
</tr>
<tr>
<td><a href="http://wikka.jsnx.com/JordaPolo" title=" ">JordaPolo</a></td>
<td class="number">4</td>
<td><span style="display:block; font-size:.8em; background-color:red; width: 100px">25%</span></td>
</tr>
<tr>
<td><a href="http://wikka.jsnx.com/AndreaRossato" title=" ">AndreaRossato</a></td>
<td class="number">2</td>
<td><span style="display:block; font-size:.8em; background-color:red; width: 50px">12.5%</span></td>
</tr>
<tr>
<td><a href="http://wikka.jsnx.com/DarTar" title=" ">DarTar</a></td>
<td class="number">2</td>
<td><span style="display:block; font-size:.8em; background-color:red; width: 50px">12.5%</span></td>
</tr>
<tr>
<td><a href="http://wikka.jsnx.com/DreckFehler" title=" ">DreckFehler</a></td>
<td class="number">1</td>
<td><span style="display:block; font-size:.8em; background-color:red; width: 25px">6.3%</span></td>
</tr>
<tr>
<td><a href="http://wikka.jsnx.com/GregorLindner" title=" ">GregorLindner</a></td>
<td class="number">1</td>
<td><span style="display:block; font-size:.8em; background-color:red; width: 25px">6.3%</span></td>
</tr>
<tr>
<td><a href="http://wikka.jsnx.com/JavaWoman" title=" ">JavaWoman</a></td>
<td class="number">1</td>
<td><span style="display:block; font-size:.8em; background-color:red; width: 25px">6.3%</span></td>
</tr>
<tr>
<td><a href="http://wikka.jsnx.com/DotMG" title=" ">DotMG</a></td>
<td class="number">1</td>
<td><span style="display:block; font-size:.8em; background-color:red; width: 25px">6.3%</span></td>
</tr>
</tbody></table>
<!-- Header id generation took 0.000208 seconds --><h5 id="hn_Statistics:">Statistics:</h5>
<table summary="Statistics for current page">
<thead>
<tr>
<th>Statistics</th>
<th>Count</th>
<th>Percentage</th>
</tr>
</thead>
<tbody>
<tr><td>Hits</td><td class="number">0</td><td> </td></tr>
<tr><td>Revisions</td><td class="number"><a href="http://wikka.jsnx.com/WikkaInternationalization/revisions" title="Display revisions for WikkaInternationalization (16)">16</a></td><td><span style="display:block; font-size:.8em; background-color:red; width: 0.63853137783099px">0.2%</span></td></tr>
<tr><td>Comments</td><td class="number"><a href="http://wikka.jsnx.com/WikkaInternationalization?show_comments=1#comments" title="Display comments for WikkaInternationalization (9)">9</a></td><td><span style="display:block; font-size:.8em; background-color:red; width: 1.7629774730656px">0.4%</span></td></tr>
<tr><td>Backlinks</td><td class="number"><a href="http://wikka.jsnx.com/WikkaInternationalization/backlinks" title="Display pages linking to WikkaInternationalization (5)">5</a></td><td><span style="display:block; font-size:.8em; background-color:red; width: 0.36609921288669px">0.1%</span></td></tr>
<tr><td>Referrers</td><td class="number"><a href="http://wikka.jsnx.com/WikkaInternationalization/referrers" title="Display external sites linking to WikkaInternationalization (79)">79</a></td><td><span style="display:block; font-size:.8em; background-color:red; width: 0.47477388142673px">0.1%</span></td></tr>
</tbody></table>
---- === Current version === (2007-07-30) Latest available version: ##**0.1**## === The code === Copy the following code as: ##handlers/page/info.php## %%(php;1)
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');
$totaledits = $this->getCount('pages', '`tag` = "'.$tag.'"');
$output .= $this->Format('=='.HEADING_AUTHORS.'==');
if ($authors)
{
$output .= "
.TABLE_AUTHORS_SUMMARY."\">\n<thead>\n<tr>\n<th>".TABLE_AUTHORS_HEADING_USER."</th>\n<th>".TABLE_AUTHORS_HEADING_EDITS."</th>\n<th>".TABLE_AUTHORS_HEADING_PERCENTAGE."</th>\n</tr>\n</thead>\n<tbody>\n";
foreach($authors as $author)
{
$percentage = $author['edits'] / $totaledits * 100;
$width = (PERCENTAGE_BAR_WIDTH * $author['edits'] / $totaledits).'px';
$bar = '<span style="'.sprintf(PERCENTAGE_BAR_STYLE, $width).'">'.round($percentage,1).'%</span>';
$output .= "<tr>\n<td>".$this->FormatUser($author['user'], OPTION_LINK, OPTION_HOSTNAME_LENGTH)."</td>\n<td class=\"number\">".$author['edits']."</td>\n<td>".$bar."</td>\n</tr>\n";
}
$output .= "</tbody></table>\n";
}
Statistics
$whereTag = "`tag` = '".$tag."'";
$wherePageTag = "`page_tag` = '".$tag."'";
$whereToTag = "`to_tag` = '".$tag."'";
$rv = $this->getCount('pages',$whereTag);
$cn = $this->getCount('comments',$wherePageTag);
$bn = $this->getCount('links',$whereToTag);
$rn = $this->getCount('referrers',$wherePageTag);
$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';
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';
$rvpercentage = $rv / $totalrv * 100;
$rvwidth = (PERCENTAGE_BAR_WIDTH * $rv / $totalrv).'px';
$rvbar = '<span style="'.sprintf(PERCENTAGE_BAR_STYLE, $rvwidth).'">'.round($rvpercentage,1).'%</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, $page['tag'], $cn).'">'.$cn.'</a>' : '0';
$cnpercentage = $cn / $totalcn * 100;
$cnwidth = (PERCENTAGE_BAR_WIDTH * $cn / $totalcn).'px';
$cnbar = '<span style="'.sprintf(PERCENTAGE_BAR_STYLE, $cnwidth).'">'.round($cnpercentage,1).'%</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';
$bnpercentage = $bn / $totalbn * 100;
$bnwidth = (PERCENTAGE_BAR_WIDTH * $bn / $totalbn).'px';
$bnbar = '<span style="'.sprintf(PERCENTAGE_BAR_STYLE, $bnwidth).'">'.round($bnpercentage,1).'%</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';
$rnpercentage = $rn / $totalrn * 100;
$rnwidth = (PERCENTAGE_BAR_WIDTH * $rn / $totalrn).'px';
$rnbar = '<span style="'.sprintf(PERCENTAGE_BAR_STYLE, $rnwidth).'">'.round($rnpercentage,1).'%</span>';
$output .= $this->Format('
'.HEADING_STATS.'
');
$output .= "<table summary=\.TABLE_STATS_SUMMARY."\">\n\n\n".TABLE_STATS_HEADING_STATISTICS." \n".TABLE_STATS_HEADING_COUNT." \n".TABLE_STATS_HEADING_PERCENTAGE." \n \n\n\n".
'Hits '.$hitspage.' '."\n".
'Revisions '.$revpage.' '.$rvbar.' '."\n".
'Comments '.$commentspage.' '.$cnbar.' '."\n".
'Backlinks '.$backlinkpage.' '.$bnbar.' '."\n".
'Referrers '.$refpage.' '.$rnbar.' '."\n".
''."\n";
// --- actions --- (forthcoming)
}
}
// display messages
if (isset($box)) echo $this->Format(' --- '.$box.' --- --- ');
// print form
if (isset($output)) print $output;
?>
%%
The handler uses a **##FormatUser()##** method, that must be added to ##wikka.php##, at the end of the user-related functions (right after ##function UserWantsComments()""):
- function UserWantsComments() { if (!$user = $this->GetUser()) return FALSE; return ($user["show_comments"] == "Y"); }
- // 2005-07-30 added by DarTar
- /**
- * Formatter for usernames.
- *
- * Renders usernames as links only when needed, avoiding the creation of dozens
- * missing page links for users without userpage. Makes other options configurable
- * (like truncating long hostnames or disabling link formatting).
- *
- * @author {@link http://wikka.jsnx.com/DarTar Dario Taraborelli}
- * @version 0.1
- *
- * @param string $user required: name of user or hostname retrieved from the DB;
- * @param string $link optional: enables/disables linking to userpage;
- * @param string $maxhostlength optional: max length for hostname, hostnames longer
- * than this will be truncated with an ellipsis;
- * @param string $ellipsis optional: character to be use at the end of truncated hosts;
- * @return string $formatted_user: formatted username.
- */
- function FormatUser ($user, $link='1', $maxhostlength='10', $ellipsis='…')
- {
- {
- // check if user is registered
- if ($this->LoadUser($user))
- {
- // check if userpage exists and if linking is enabled
- }
- else
- {
- // truncate long host names
- $formatted_user = '<tt>'.$user.'</tt>';
- }
- }
- else
- {
- // page has empty user field
- $formatted_user = 'anonymous';
- }
- return $formatted_user;
- }
CategoryDevelopmentHandlers