Revision [10364]

This is an old revision of InfoHandler made by DarTar on 2005-08-01 15:27:17.

 

Info Handler

See also: 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 the URL of the page.


Sample output:

Page statistics for WikkaInternationalization




Revisions:
User Edits Percentage
JordaPolo 4 25%
JsnX 4 25%
AndreaRossato 2 12.5%
DarTar 2 12.5%
DotMG 1 6.25%
DreckFehler 1 6.25%
GregorLindner 1 6.25%
JavaWoman 1 6.25%
Statistics:
Statistics Count Site totals Percentage
Hits0  
Revisions16100560.16%
Comments920420.44%
Backlinks554780.09%
Referrers80657070.12%



Current version

(2007-07-30)

Latest available version: 0.1

Note: the rendering of the percentage bar for small values may not be correct in IE since the bar's size is always adjusted to accomodate with the text width. A small tweak in the style or in the code might be needed for the style to be compatible with IE. Browsers with good CSS support display bars of any size correctly.

The code


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.1
  13.  * @since               Wikka 1.1.X.X
  14.  *
  15.  * @todo                - bar styling in the CSS;
  16.  *                          - optimize queries and code;
  17.  */
  18.  
  19.  
  20. //Default constants
  21. // -------------------------------------
  22.  
  23. // set default constant values
  24. define('PERCENTAGE_BAR_WIDTH', '400'); # max width of percentage bar in pixels
  25. //define('PERCENTAGE_BAR_STYLE', 'display:block; font-size:.8em; background-color:#DEE; border-left:1px solid #EFF; border-top:1px solid #EFF; border-right:1px solid #CDD; border-bottom:1px solid #CDD; width: %s'); # style attribute for percentage bar (do not edit the width value)
  26. define('PERCENTAGE_BAR_STYLE', 'display:block; font-size:.8em; background-color:#DEE; border:1px outset #EFF; width: %s'); # style attribute for percentage bar (do not edit the width value)
  27. define('PERCENTAGE_DECIMALS_ROUND', '2'); # decimals for rounding percentage values;
  28. define('OPTION_LINK', '1'); # enable linking to userpages
  29. define('OPTION_HOSTNAME_LENGTH', '20'); # max. length for hostnames
  30.  
  31. // -------------------------------------
  32. // User-interface: strings
  33.    
  34. define('PAGE_TITLE','Page statistics for %s');
  35. define('HEADING_AUTHORS','Revisions:');
  36. define('HEADING_STATS','Statistics:');
  37. define('ERROR_PAGE_NOT_EXISTING','Sorry, this page does not exist.');
  38. define('ERROR_NO_ACCESS','Sorry, You don\'t have access to this page.');
  39. define('TABLE_AUTHORS_SUMMARY','List of authors of the current page ordered by number of edits');
  40. define('TABLE_AUTHORS_HEADING_USER','User');
  41. define('TABLE_AUTHORS_HEADING_EDITS','Edits');
  42. define('TABLE_AUTHORS_HEADING_PERCENTAGE','Percentage');
  43. define('TABLE_CELL_HITS_TITLE','Hits for %s (%d)');
  44. define('TABLE_CELL_REVISIONS_TITLE','Display revisions for %s (%d)');
  45. define('TABLE_CELL_COMMENTS_TITLE','Display comments for %s (%d)');
  46. define('TABLE_CELL_BACKLINKS_TITLE','Display pages linking to %s (%d)');
  47. define('TABLE_CELL_REFERRERS_TITLE','Display external sites linking to %s (%d)');
  48. define('TABLE_STATS_SUMMARY','Statistics for current page');
  49. define('TABLE_STATS_HEADING_STATISTICS','Statistics');
  50. define('TABLE_STATS_HEADING_COUNT','Count');
  51. define('TABLE_STATS_HEADING_SITE','Site totals');
  52. define('TABLE_STATS_HEADING_PERCENTAGE','Percentage');
  53.        
  54. //initialize variables
  55.  
  56. $output = '';
  57. $tag = '';
  58. $box = '';
  59.  
  60. // print header
  61. echo $this->Format('=== '.sprintf(PAGE_TITLE,'[['.$this->tag.']]').' ===');
  62.  
  63. // 1. check source page existence
  64. if (!$this->page)
  65. {
  66.     // source page does not exist!
  67.     $box = ERROR_PAGE_NOT_EXISTING;
  68. }
  69. else
  70. {
  71.     $tag = $this->page['tag'];
  72.    
  73.     // 2. page exists - now check user's read-access to the source page
  74.     if (!$this->HasAccess('read'))
  75.     {
  76.         // user can't read source page!
  77.         $box = ERROR_NO_ACCESS;
  78.     } else
  79.     {
  80.         // page exists and user has read-access to the source - proceed
  81.  
  82.         // --- Authors ---
  83.        
  84.         $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');
  85.         $totaledits = $this->getCount('pages', '`tag`  =  "'.$tag.'"');
  86.         $output .= $this->Format('=='.HEADING_AUTHORS.'==');
  87.         if ($authors)
  88.         {
  89.             $output .= "<table summary=\"".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";
  90.             foreach($authors as $author)
  91.             {
  92.                 $percentage = $author['edits'] / $totaledits * 100;
  93.                 $width = (PERCENTAGE_BAR_WIDTH * $author['edits'] / $totaledits).'px';
  94.                 $bar = '<span style="'.sprintf(PERCENTAGE_BAR_STYLE, $width).'">'.round($percentage,PERCENTAGE_DECIMALS_ROUND).'%</span>';
  95.                 // use new FormatUser() method - added to wikka.php by DarTar 2005-07-30
  96.                 $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";
  97.             }
  98.             $output .= "</tbody></table>\n";
  99.         }
  100.  
  101.         // --- Statistics ---
  102.        
  103.         $whereTag       = "`tag` = '".$tag."'";
  104.         $wherePageTag   = "`page_tag` = '".$tag."'";
  105.         $whereToTag     = "`to_tag` = '".$tag."'";
  106.         $rv = $this->getCount('pages',$whereTag);
  107.         $cn = $this->getCount('comments',$wherePageTag);
  108.         $bn = $this->getCount('links',$whereToTag);
  109.         $rn = $this->getCount('referrers',$wherePageTag);
  110.  
  111.         $totalrv = $this->getCount('pages');
  112.         $totalcn = $this->getCount('comments');
  113.         $totalbn = $this->getCount('links');
  114.         $totalrn = $this->getCount('referrers');
  115.  
  116.         // @@ note: the link generation below is redundant and should be optimized
  117.  
  118.         // get page hits (forthcoming)
  119.         $hitspage = ($hn > 0) ? '<a href="'.$this->Href('hits',$tag, '').'" title="'.sprintf(TABLE_CELL_HITS_TITLE, $tag, $hn).'">'.$hn.'</a>' : '0';
  120.  
  121.         // get page revisions and create revision link if needed
  122.         $revpage = ($rv > 0) ? '<a href="'.$this->Href('revisions',$tag, '').'" title="'.sprintf(TABLE_CELL_REVISIONS_TITLE, $tag, $rv).'">'.$rv.'</a>' : '0';
  123.         $rvpercentage = $rv / $totalrv * 100;
  124.         $rvwidth = (PERCENTAGE_BAR_WIDTH * $rv / $totalrv).'px';
  125.         $rvbar = '<span style="'.sprintf(PERCENTAGE_BAR_STYLE, $rvwidth).'">'.round($rvpercentage,PERCENTAGE_DECIMALS_ROUND).'%</span>';
  126.  
  127.         // get page comments and create comments link if needed
  128.         $commentspage = ($cn > 0) ? '<a href="'.$this->Href('',$tag, 'show_comments=1#comments').'" title="'.sprintf(TABLE_CELL_COMMENTS_TITLE, $tag, $cn).'">'.$cn.'</a>' : '0';
  129.         $cnpercentage = $cn / $totalcn * 100;
  130.         $cnwidth = (PERCENTAGE_BAR_WIDTH * $cn / $totalcn).'px';
  131.         $cnbar = '<span style="'.sprintf(PERCENTAGE_BAR_STYLE, $cnwidth).'">'.round($cnpercentage,PERCENTAGE_DECIMALS_ROUND).'%</span>';
  132.  
  133.         // get page backlinks and create backlinks link
  134.         $backlinkpage = ($bn > 0) ? '<a href="'.$this->Href('backlinks',$tag, '').'" title="'.sprintf(TABLE_CELL_BACKLINKS_TITLE, $tag, $bn).'">'.$bn.'</a>' : '0';
  135.         $bnpercentage = $bn / $totalbn * 100;
  136.         $bnwidth = (PERCENTAGE_BAR_WIDTH * $bn / $totalbn).'px';
  137.         $bnbar = '<span style="'.sprintf(PERCENTAGE_BAR_STYLE, $bnwidth).'">'.round($bnpercentage,PERCENTAGE_DECIMALS_ROUND).'%</span>';
  138.  
  139.         // get page referrers and create referrer link
  140.         $refpage = ($rn > 0) ? '<a href="'.$this->Href('referrers',$tag, '').'" title="'.sprintf(TABLE_CELL_REFERRERS_TITLE, $tag, $rn).'">'.$rn.'</a>' : '0';
  141.         $rnpercentage = $rn / $totalrn * 100;
  142.         $rnwidth = (PERCENTAGE_BAR_WIDTH * $rn / $totalrn).'px';
  143.         $rnbar = '<span style="'.sprintf(PERCENTAGE_BAR_STYLE, $rnwidth).'">'.round($rnpercentage,PERCENTAGE_DECIMALS_ROUND).'%</span>';
  144.  
  145.         $output .= $this->Format('=='.HEADING_STATS.'==');
  146.  
  147.         $output .= "<table summary=\"".TABLE_STATS_SUMMARY."\">\n<thead>\n<tr>\n<th>".TABLE_STATS_HEADING_STATISTICS."</th>\n<th>".TABLE_STATS_HEADING_COUNT."</th>\n<th>".TABLE_STATS_HEADING_SITE."</th>\n<th>".TABLE_STATS_HEADING_PERCENTAGE."</th>\n</tr>\n</thead>\n<tbody>\n".
  148.  
  149.         '<tr><td>Hits</td><td class="number">'.$hitspage.'</td><td class="number">&nbsp;</td><td>&nbsp;</td></tr>'."\n".
  150.         '<tr><td>Revisions</td><td class="number">'.$revpage.'</td><td class="number">'.$totalrv.'</td><td>'.$rvbar.'</td></tr>'."\n".
  151.         '<tr><td>Comments</td><td class="number">'.$commentspage.'</td><td class="number">'.$totalcn.'</td><td>'.$cnbar.'</td></tr>'."\n".
  152.         '<tr><td>Backlinks</td><td class="number">'.$backlinkpage.'</td><td class="number">'.$totalbn.'</td><td>'.$bnbar.'</td></tr>'."\n".
  153.         '<tr><td>Referrers</td><td class="number">'.$refpage.'</td><td class="number">'.$totalrn.'</td><td>'.$rnbar.'</td></tr>'."\n".
  154.         '</tbody></table>'."\n";
  155.        
  156.         // --- actions --- (forthcoming)
  157.  
  158.     }
  159. }
  160.  
  161. // display messages
  162. if (isset($box)) echo $this->Format(' --- '.$box.' --- --- ');
  163. // print form
  164. if (isset($output)) print $output;
  165. ?>
  166. </div>


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()):


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