Info Handler
This is the development page for the info handler.
The info handler displays information and statistics about the current page.
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.
Usage
Append /info to the URL of the page or click on "Stats" in the page footer.Sample output
Page statistics for HomePage
Page revisions (author/page totals):
User | Edits | % | Percentage |
---|---|---|---|
JsnX | 124/183 | 67.76% | |
DarTar | 53/183 | 28.96% | |
JavaWoman | 5/183 | 2.73% | |
WakkaInstaller | 1/183 | 0.55% |
Global statistics (page/site totals):
Statistics | Count | % | Percentage |
---|---|---|---|
Hits | 1/1 | 100% | |
Revisions | 183/10193 | 1.8% | |
Comments | 96/2051 | 4.68% | |
Backlinks | 50/5549 | 0.9% | |
Referrers | 34294/67978 | 50.45% |
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 FormatUser() method, that must be added to wikka.php, at the end of the user-related functions, right after function UserWantsComments();
- the getCount() method, that must be added to wikka.php right after the LoadAll() method.
Copy the following code as: handlers/page/info.php
- <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_STYLE', 'float:left; height: 1.4em; width: %s'); # style attribute for percentage bar (do not edit the width value)
- // -------------------------------------
- // User-interface: strings
- //initialize variables
- $output = '';
- $tag = '';
- $box = '';
- // print header
- // 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';
- $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)
- {
- } 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)
- {
- } 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)
- {
- } 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)
- {
- } 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)
- {
- } 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
- // print form
- ?>
- </div>
Styling
The info handler uses a bunch of CSS classes for styling the percentage bars.
CategoryDevelopmentHandlers