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.
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 |
---|---|---|---|
Hits | 0 | ||
Revisions | 16 | 10056 | 0.16% |
Comments | 9 | 2042 | 0.44% |
Backlinks | 5 | 5478 | 0.09% |
Referrers | 80 | 65707 | 0.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
- <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.1
- * @since Wikka 1.1.X.X
- *
- * @todo - bar styling in the CSS;
- * - optimize queries and code;
- */
- //Default constants
- // -------------------------------------
- // set default constant values
- //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)
- 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)
- // -------------------------------------
- // 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>".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';
- // use new FormatUser() method - added to wikka.php by DarTar 2005-07-30
- $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';
- // 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';
- $cnpercentage = $cn / $totalcn * 100;
- $cnwidth = (PERCENTAGE_BAR_WIDTH * $cn / $totalcn).'px';
- // 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';
- // 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';
- $output .= $this->Format('=='.HEADING_STATS.'==');
- $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".
- '<tr><td>Hits</td><td class="number">'.$hitspage.'</td><td class="number"> </td><td> </td></tr>'."\n".
- '<tr><td>Revisions</td><td class="number">'.$revpage.'</td><td class="number">'.$totalrv.'</td><td>'.$rvbar.'</td></tr>'."\n".
- '<tr><td>Comments</td><td class="number">'.$commentspage.'</td><td class="number">'.$totalcn.'</td><td>'.$cnbar.'</td></tr>'."\n".
- '<tr><td>Backlinks</td><td class="number">'.$backlinkpage.'</td><td class="number">'.$totalbn.'</td><td>'.$bnbar.'</td></tr>'."\n".
- '<tr><td>Referrers</td><td class="number">'.$refpage.'</td><td class="number">'.$totalrn.'</td><td>'.$rnbar.'</td></tr>'."\n".
- '</tbody></table>'."\n";
- // --- actions --- (forthcoming)
- }
- }
- // display messages
- // print form
- ?>
- </div>
The handler uses a FormatUserMethod FormatUser() method, that must be added to wikka.php, at the end of the user-related functions (right after function UserWantsComments()):
CategoryDevelopmentHandlers