A replacement for the InfoHandler


This is a drop-in replacement for the InfoHandler.

The Code


First things first, go to the BarGraph action and follow the installation instructions.

When the BarGraph action is running without a hitch, save the following code as actions/pagestats.php --

<?php

require_once('3rdparty/plugins/bar_graph.php');

if ($this->HasAccess('read'))
{
    $prefix = $this->config['table_prefix'];

    $sql = "(SELECT 'total_referrers', count(*) FROM {$prefix}referrers) UNION
    (SELECT 'page_referrers', count(*) FROM {$prefix}referrers WHERE page_tag = '$this->tag') UNION
    (SELECT 'total_comments', count(*) FROM {$prefix}comments) UNION
    (SELECT 'page_comments', count(*) FROM {$prefix}comments WHERE page_tag = '$this->tag') UNION
    (SELECT 'total_backlinks', count(*) FROM {$prefix}links) UNION
    (SELECT 'page_backlinks', count(*) FROM {$prefix}links WHERE to_tag = '$this->tag') UNION
    (SELECT 'total_revisions', count(*) FROM {$prefix}pages) UNION
    (SELECT 'page_revisions', count(*) FROM {$prefix}pages WHERE tag = '$this->tag')"
;

    $results = mysql_query($sql);
    if (mysql_num_rows($results))
    {
        while ($row = mysql_fetch_row($results)) $stats[$row[0]] = $row[1];
    }

    $authors = $this->LoadAll("SELECT user, COUNT(*) AS edits FROM {$prefix}pages WHERE tag = '$this->tag' GROUP  BY user ORDER BY edits DESC, user ASC");
    if ($authors)
    {
        $graph =& new bar_graph('Revisions by Author');
        $graph->total = $stats['page_revisions'];
        foreach($authors as $author) $graph->add($author['user'], $author['edits']);
        $graph->show();
    }

    echo '<p>&nbsp;</p>';

    $graph =& new bar_graph('Global Statistics');
    foreach (array('revisions', 'comments', 'backlinks', 'referrers') as $index)
    {
        if (isset($stats["page_$index"]) && isset($stats["total_$index"]))
        {
            $graph->add(ucwords($index), $stats["page_$index"] . '/' . $stats["total_$index"]);
        }
    }
    $graph->show();
}

?>


The Example


{{pagestats}}


The Screenshot


 (image: http://bytebrite.com/img/psss.gif)

Authors


DennyShimkoski


CategoryUserContributions
Comments
Comment by DarTar
2005-08-25 19:14:56
Nice contribution, Denny :)

Here's a few quick comments:

-JavaWoman has some doubts about using UNION - not all versions of MySQL support it; we support 3.23 and higher.
- For record counting, you might use the new getCount() method available as a beta on this server: see WikkaCountingRecords.
- There are some minor issues with the CSS, like the table borders that look a little weird. Also consider that we should try to define a consistent layout for all data tables and avoid creating a lot of specific classes for specific actions/handlers if possible.
- You might also want to add column headings, take a look at http://wikka.jsnx.com/MediaWikiComparison to see the kind of layout and structure we would like to adopt for data tables.

Good job!
Comment by DarTar
2005-08-25 19:23:59
Also, consider that with minor changes in the code, the same page-related functionality can be easily adapted to be used either as action or as a handler: there are cases in which a handler (which provides on-the-fly, invisible services) makes more sense than an action (which provides content or services embedded in the page body) and viceversa. An example of this double use is the /backlinks handler that provides the same functionality as the {{backlinks}} action, but spares you from adding the action to a page and previewing it if what you need is only a quick look to some page statistics. Obviously, deciding the best flavour for page-related functionality (action vs. handler) is a matter of taste and needs of the wiki administrator.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki