Revision [10274]
This is an old revision of InfoHandler made by DarTar on 2005-07-30 18:03:26.
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 DarTar
Authors:
User | Edits | Percentage |
---|---|---|
DarTar | 46 | 86.8% |
ppp15-148-59-62.dial… | 5 | 9.4% |
DarTar2 | 1 | 1.9% |
132.229.91.74 | 1 | 1.9% |
Statistics:
Statistics | Count | Percentage |
---|---|---|
Hits | 0 | |
Revisions | 53 | 0.5% |
Comments | 8 | 0.4% |
Backlinks | 94 | 1.7% |
Referrers | 86 | 0.1% |
Current version
(2007-07-30)Latest available version: 0.1
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 values as constants
- // -------------------------------------
- // 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');
- $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';
- $bar = '<span style="display:block; background-color:red; width:'.$width.'">'.round($percentage,1).'%</span>';
- // 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',$page['tag'], '').'" title="'.sprintf(TABLE_CELL_HITS_TITLE, $page['tag'], $hn).'">'.$hn.'</a>' : '0';
- // get page revisions and create revision link if needed
- $revpage = ($rv > 0) ? '<a href="'.$this->Href('revisions',$page['tag'], '').'" title="'.sprintf(TABLE_CELL_REVISIONS_TITLE, $page['tag'], $rv).'">'.$rv.'</a>' : '0';
- $rvpercentage = $rv / $totalrv * 100;
- $rvwidth = (PERCENTAGE_BAR_WIDTH * $rv / $totalrv).'px';
- $rvbar = '<span style="display:block; background-color:red; width:'.$rvwidth.'">'.round($rvpercentage,1).'%</span>';
- // get page comments and create comments link if needed
- $commentspage = ($cn > 0) ? '<a href="'.$this->Href('',$page['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="display:block; background-color:red; width:'.$cnwidth.'">'.round($cnpercentage,1).'%</span>';
- // get page backlinks and create backlinks link
- $backlinkpage = ($bn > 0) ? '<a href="'.$this->Href('backlinks',$page['tag'], '').'" title="'.sprintf(TABLE_CELL_BACKLINKS_TITLE, $page['tag'], $bn).'">'.$bn.'</a>' : '0';
- $bnpercentage = $bn / $totalbn * 100;
- $bnwidth = (PERCENTAGE_BAR_WIDTH * $bn / $totalbn).'px';
- $bnbar = '<span style="display:block; background-color:red; width:'.$bnwidth.'">'.round($bnpercentage,1).'%</span>';
- // get page referrers and create referrer link
- $refpage = ($rn > 0) ? '<a href="'.$this->Href('referrers',$page['tag'], '').'" title="'.sprintf(TABLE_CELL_REFERRERS_TITLE, $page['tag'], $rn).'">'.$rn.'</a>' : '0';
- $rnpercentage = $rn / $totalrn * 100;
- $rnwidth = (PERCENTAGE_BAR_WIDTH * $rn / $totalrn).'px';
- $rnbar = '<span style="display:block; background-color:red; width:'.$rnwidth.'">'.round($rnpercentage,1).'%</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>".TABLE_STATS_HEADING_COUNT."</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> </td></tr>'."\n".
- '<tr><td>Revisions</td><td class="number">'.$revpage.'</td><td>'.$rvbar.'</td></tr>'."\n".
- '<tr><td>Comments</td><td class="number">'.$commentspage.'</td><td>'.$cnbar.'</td></tr>'."\n".
- '<tr><td>Backlinks</td><td class="number">'.$backlinkpage.'</td><td>'.$bnbar.'</td></tr>'."\n".
- '<tr><td>Referrers</td><td class="number">'.$refpage.'</td><td>'.$rnbar.'</td></tr>'."\n".
- '</tbody></table>'."\n";
- // --- actions --- (forthcoming)
- }
- }
- // display messages
- // print form
- ?>
- </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()):
- 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