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.
 


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
Hits1/1100%
Revisions183/101931.8%
Comments96/20514.68%
Backlinks50/55490.9%
Referrers34294/6797850.45%



Current version

(2005-08-07)

Latest available version: 0.3

Change log


0.3


The code


Dependencies: The info handler uses:

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

  1. <div class="page">
  2. <?php
  3. /**
  4.  * Displays information on the current page.
  5.  *
  6.  * Usage: append /info to the URL of the page.
  7.  *
  8.  * @package         Handlers    
  9.  * @name            info
  10.  *
  11.  * @author          {@link http://wikka.jsnx.com/DarTar Dario Taraborelli} - first draft.
  12.  * @version         0.3
  13.  * @since           Wikka 1.1.X.X
  14.  *
  15.  * @todo            - bar styling in the CSS;
  16.  *              - optimize queries and code;
  17.  */
  18.  
  19. //Defaults as constants
  20. // -------------------------------------
  21.  
  22. // set default constant values
  23. define('PERCENTAGE_BAR_WIDTH', '300'); # max width of percentage bar in pixels
  24. define('PERCENTAGE_BAR_STYLE', 'float:left; height: 1.4em; width: %s'); # style attribute for percentage bar (do not edit the width value)
  25. define('PERCENTAGE_BAR_COLOR_AUTHORS', 'c6'); # class for setting percentage bar color
  26. define('PERCENTAGE_BAR_COLOR_HITS', 'c1'); # class for setting percentage bar color
  27. define('PERCENTAGE_BAR_COLOR_REVISIONS', 'c2'); # class for setting percentage bar color
  28. define('PERCENTAGE_BAR_COLOR_COMMENTS', 'c3'); # class for setting percentage bar color
  29. define('PERCENTAGE_BAR_COLOR_BACKLINKS', 'c4'); # class for setting percentage bar color
  30. define('PERCENTAGE_BAR_COLOR_REFERRERS', 'c5'); # class for setting percentage bar color
  31. define('PERCENTAGE_DECIMALS_ROUND', '2'); # decimals for rounding percentage values;
  32. define('OPTION_LINK', '1'); # enable linking to userpages
  33. define('OPTION_HOSTNAME_LENGTH', '20'); # max. length for hostnames
  34.  
  35. // -------------------------------------
  36. // User-interface: strings
  37.    
  38. define('PAGE_TITLE','Page statistics for %s');
  39. define('HEADING_AUTHORS','Page revisions (##author/page totals##):');
  40. define('HEADING_STATS','Global statistics  (##page/site totals##):');
  41. define('ERROR_PAGE_NOT_EXISTING','Sorry, this page does not exist.');
  42. define('ERROR_NO_ACCESS','Sorry, You don\'t have access to this page.');
  43. define('TABLE_AUTHORS_SUMMARY','List of authors of the current page ordered by number of edits');
  44. define('TABLE_AUTHORS_HEADING_USER','User');
  45. define('TABLE_AUTHORS_HEADING_EDITS','Edits');
  46. define('TABLE_AUTHORS_HEADING_PERCENTAGE_BAR','Percentage');
  47. define('TABLE_AUTHORS_HEADING_PERCENTAGE','%');
  48. define('TABLE_CELL_HITS_TITLE','Hits for %s (%d)');
  49. define('TABLE_CELL_REVISIONS_TITLE','Display revisions for %s (%d)');
  50. define('TABLE_CELL_COMMENTS_TITLE','Display comments for %s (%d)');
  51. define('TABLE_CELL_BACKLINKS_TITLE','Display pages linking to %s (%d)');
  52. define('TABLE_CELL_REFERRERS_TITLE','Display external sites linking to %s (%d)');
  53. define('TABLE_STATS_SUMMARY','Statistics for current page');
  54. define('TABLE_STATS_HEADING_STATISTICS','Statistics');
  55. define('TABLE_STATS_HEADING_COUNT','Count');
  56. define('TABLE_STATS_HEADING_PERCENTAGE_BAR','Percentage');
  57. define('TABLE_STATS_HEADING_PERCENTAGE','%');
  58.        
  59. //initialize variables
  60.  
  61. $output = '';
  62. $tag = '';
  63. $box = '';
  64.  
  65. // print header
  66. echo $this->Format('=== '.sprintf(PAGE_TITLE,'[['.$this->tag.']]').' ===');
  67.  
  68. // 1. check source page existence
  69. if (!$this->page)
  70. {
  71.     // source page does not exist!
  72.     $box = ERROR_PAGE_NOT_EXISTING;
  73. }
  74. else
  75. {
  76.     $tag = $this->page['tag'];
  77.    
  78.     // 2. page exists - now check user's read-access to the source page
  79.     if (!$this->HasAccess('read'))
  80.     {
  81.         // user can't read source page!
  82.         $box = ERROR_NO_ACCESS;
  83.     } else
  84.     {
  85.         // page exists and user has read-access to the source - proceed
  86.  
  87.         // --- Authors ---
  88.        
  89.         $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');
  90.         $totaledits = $this->getCount('pages', '`tag`  =  "'.$tag.'"');
  91.         $output .= $this->Format('=='.HEADING_AUTHORS.'==');
  92.         if ($authors)
  93.         {
  94.             $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";
  95.             foreach($authors as $author)
  96.             {
  97.                 $percentage = $author['edits'] / $totaledits * 100;
  98.                 $bar_width = round((PERCENTAGE_BAR_WIDTH * $author['edits'] / $totaledits),PERCENTAGE_DECIMALS_ROUND).'px';
  99.                 $rounded_percentage = round($percentage,PERCENTAGE_DECIMALS_ROUND).'%';            
  100.                 $bar = '<span title = "'.$rounded_percentage.'" class="'.PERCENTAGE_BAR_COLOR_AUTHORS.'" style="'.sprintf(PERCENTAGE_BAR_STYLE, $bar_width).'"></span>';
  101.                 $output .= "<tr>\n<td>".$this->FormatUser($author['user'], OPTION_LINK, OPTION_HOSTNAME_LENGTH)."</td>\n".
  102.                     "<td class=\"number\">".$author['edits']."/".$totaledits."</td>\n".
  103.                     "<td  class=\"number\">".$rounded_percentage."</td>\n".
  104.                     "<td>".$bar."</td>\n".
  105.                     "</tr>\n";
  106.             }
  107.             $output .= "</tbody></table>\n";
  108.         }
  109.  
  110.         $output .= "<p>&nbsp;</p>\n";
  111.  
  112.         // --- Statistics ---
  113.        
  114.         $whereTag       = "`tag` = '".$tag."'";
  115.         $wherePageTag   = "`page_tag` = '".$tag."'";
  116.         $whereToTag     = "`to_tag` = '".$tag."'";
  117.         $hn = 1; #forthcoming
  118.         $rv = $this->getCount('pages',$whereTag);
  119.         $cn = $this->getCount('comments',$wherePageTag);
  120.         $bn = $this->getCount('links',$whereToTag);
  121.         $rn = $this->getCount('referrers',$wherePageTag);
  122.  
  123.         $totalhn = 1; #forthcoming
  124.         $totalrv = $this->getCount('pages');
  125.         $totalcn = $this->getCount('comments');
  126.         $totalbn = $this->getCount('links');
  127.         $totalrn = $this->getCount('referrers');
  128.  
  129.         // @@ note: the link generation below is redundant and should be optimized
  130.  
  131.         // get page hits (forthcoming)
  132.         $hitspage = ($hn > 0) ? '<a href="'.$this->Href('hits',$tag, '').'" title="'.sprintf(TABLE_CELL_HITS_TITLE, $tag, $hn).'">'.$hn.'</a>' : '0';
  133.         if ($totalhn > 0)
  134.         {  
  135.             $hnpercentage = round($hn / $totalhn * 100, PERCENTAGE_DECIMALS_ROUND).'%';
  136.             $hnwidth = round((PERCENTAGE_BAR_WIDTH * $hn / $totalhn), PERCENTAGE_DECIMALS_ROUND).'px';
  137.         } else
  138.         {
  139.             $hnpercentage = '0%';
  140.             $hnwidth = '0px';
  141.         }
  142.         $hnbar = '<span  title = "'.$hnpercentage.'" class="'.PERCENTAGE_BAR_COLOR_HITS.'" style="'.sprintf(PERCENTAGE_BAR_STYLE, $hnwidth).'"></span>';
  143.        
  144.         // get page revisions and create revision link if needed
  145.         $revpage = ($rv > 0) ? '<a href="'.$this->Href('revisions',$tag, '').'" title="'.sprintf(TABLE_CELL_REVISIONS_TITLE, $tag, $rv).'">'.$rv.'</a>' : '0';
  146.         if ($totalrv > 0)
  147.         {  
  148.             $rvpercentage = round($rv / $totalrv * 100, PERCENTAGE_DECIMALS_ROUND).'%';
  149.             $rvwidth = round((PERCENTAGE_BAR_WIDTH * $rv / $totalrv), PERCENTAGE_DECIMALS_ROUND).'px';
  150.         } else
  151.         {
  152.             $rvpercentage = '0%';
  153.             $rvwidth = '0px';
  154.         }
  155.         $rvbar = '<span  title = "'.$rvpercentage.'" class="'.PERCENTAGE_BAR_COLOR_REVISIONS.'"  style="'.sprintf(PERCENTAGE_BAR_STYLE, $rvwidth).'"></span>';
  156.  
  157.         // get page comments and create comments link if needed
  158.         $commentspage = ($cn > 0) ? '<a href="'.$this->Href('',$tag, 'show_comments=1#comments').'" title="'.sprintf(TABLE_CELL_COMMENTS_TITLE, $tag, $cn).'">'.$cn.'</a>' : '0';
  159.         if ($totalcn > 0)
  160.         {  
  161.             $cnpercentage = round($cn / $totalcn * 100, PERCENTAGE_DECIMALS_ROUND).'%';
  162.             $cnwidth = round((PERCENTAGE_BAR_WIDTH * $cn / $totalcn), PERCENTAGE_DECIMALS_ROUND).'px';
  163.         } else
  164.         {
  165.             $cnpercentage = '0%';
  166.             $cnwidth = '0px';
  167.         }
  168.         $cnbar = '<span  title = "'.$cnpercentage.'" class="'.PERCENTAGE_BAR_COLOR_COMMENTS.'"  style="'.sprintf(PERCENTAGE_BAR_STYLE, $cnwidth).'"></span>';
  169.  
  170.         // get page backlinks and create backlinks link
  171.         $backlinkpage = ($bn > 0) ? '<a href="'.$this->Href('backlinks',$tag, '').'" title="'.sprintf(TABLE_CELL_BACKLINKS_TITLE, $tag, $bn).'">'.$bn.'</a>' : '0';
  172.         if ($totalbn > 0)
  173.         {  
  174.             $bnpercentage = round($bn / $totalbn * 100, PERCENTAGE_DECIMALS_ROUND).'%';
  175.             $bnwidth = round((PERCENTAGE_BAR_WIDTH * $bn / $totalbn), PERCENTAGE_DECIMALS_ROUND).'px';
  176.         } else
  177.         {
  178.             $bnpercentage = '0%';
  179.             $bnwidth = '0px';
  180.         }
  181.         $bnbar = '<span  title = "'.$bnpercentage.'" class="'.PERCENTAGE_BAR_COLOR_BACKLINKS.'"  style="'.sprintf(PERCENTAGE_BAR_STYLE, $bnwidth).'"></span>';
  182.  
  183.         // get page referrers and create referrer link
  184.         $refpage = ($rn > 0) ? '<a href="'.$this->Href('referrers',$tag, '').'" title="'.sprintf(TABLE_CELL_REFERRERS_TITLE, $tag, $rn).'">'.$rn.'</a>' : '0';
  185.         if ($totalrn > 0)
  186.         {  
  187.             $rnpercentage = round($rn / $totalrn * 100, PERCENTAGE_DECIMALS_ROUND).'%';
  188.             $rnwidth = round((PERCENTAGE_BAR_WIDTH * $rn / $totalrn), PERCENTAGE_DECIMALS_ROUND).'px';
  189.         } else
  190.         {
  191.             $rnpercentage = '0%';
  192.             $rnwidth = '0px';
  193.         }
  194.         $rnbar = '<span  title = "'.$rnpercentage.'" class="'.PERCENTAGE_BAR_COLOR_REFERRERS.'"  style="'.sprintf(PERCENTAGE_BAR_STYLE, $rnwidth).'"></span>';
  195.  
  196.         $output .= $this->Format('=='.HEADING_STATS.'==');
  197.  
  198.         $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".
  199.         '<tr><td>Hits</td><td class="number">'.$hitspage.'/'.$totalhn.'</td><td class="number">'.$hnpercentage.'</td><td>'.$hnbar.'</td></tr>'."\n".
  200.         '<tr><td>Revisions</td><td class="number">'.$revpage.'/'.$totalrv.'</td><td class="number">'.$rvpercentage.'</td><td>'.$rvbar.'</td></tr>'."\n".
  201.         '<tr><td>Comments</td><td class="number">'.$commentspage.'/'.$totalcn.'</td><td class="number">'.$cnpercentage.'</td><td>'.$cnbar.'</td></tr>'."\n".
  202.         '<tr><td>Backlinks</td><td class="number">'.$backlinkpage.'/'.$totalbn.'</td><td class="number">'.$bnpercentage.'</td><td>'.$bnbar.'</td></tr>'."\n".
  203.         '<tr><td>Referrers</td><td class="number">'.$refpage.'/'.$totalrn.'</td><td class="number">'.$rnpercentage.'</td><td>'.$rnbar.'</td></tr>'."\n".
  204.         '</tbody></table>'."\n";
  205.        
  206.         // --- actions --- (forthcoming)
  207.  
  208.     }
  209. }
  210.  
  211. // display messages
  212. if (isset($box)) echo $this->Format(' --- '.$box.' --- --- ');
  213. // print form
  214. if (isset($output)) print $output;
  215. ?>
  216. </div>


Styling


The info handler uses a bunch of CSS classes for styling the percentage bars.



CategoryDevelopmentHandlers
There are 7 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki