Extension talk:CategoryStats

Hi there, I made a couple of changes to the code on CategoryStats_body.php if you're interested. I didn't like that there was no way to select the first category when the page loaded, so I added an extra option to the list. The changes I made were to the following functions...

Instead of just checking the POST for 'catsel', I set $category, and the looked at it to see if it was set, and that it wasn't blank, then used one of the output functions based on the result. This means if you click on the dummy option, you'll be taken back to a blank screen with just the select menu. I thought it just a little cleaner than going to a non-existant category. function execute( $par ) { global $wgRequest, $wgOut;

$this->setHeaders;

// Handle whether the form was posted or not if ($wgRequest->wasPosted) { $category = $_POST["catsel"]; }   if (isset($category) && $category != "") { $this->processForm($category); } else { $this->displayForm; }   # Get request data from, e.g.                                                                                          $param = $wgRequest->getText('param'); }

Here I took the test at the top 'Select the desired category', and made it a dummy option in the drop down with a blank value. I removed the text from above the menu, as it would be redundant. function displayForm($category = null) { global $wgOut;

$htmlstr = XML::openElement('b') . 'This page will display hit statistics for pages in a selected category' . XML::closeElement('b');

$selected = false;

// Open the Database $dbr = wfGetDB(DB_SLAVE);

// Select all categories where there are at least one _real_ page. $query = 'select cat_title from '. $dbr->tableName('category'). ' where cat_pages-cat_subcats > 0 order by cat_title asc';

$res = $dbr->query($query);

// Get the dropdown box for the category $htmlstr .= XML::openElement('form',        array( 'method' => 'post', 'action' => $wgScript, )   );

$htmlstr .= XML::openElement('select',        array( 'name' => 'catsel', 'onchange' => 'this.form.submit' )   );    $htmlstr .= XML::option('Select the desired category', ''); while($row = $dbr->fetchObject($res)){ if ($category === $row->cat_title) { $selected = true; }       $title = $row->cat_title; $htmlstr .= XML::option(str_replace('_', ' ', $title), $title, $selected, null ); $selected = false; }

$htmlstr .= XML::closeElement('select'); $htmlstr .= XML::closeElement('form');

$dbr->freeResult($res);

$wgOut->addHTML($htmlstr); }

Good add-on otherwise, exactly the functionality I was looking for. I just wish that there was a little more breakdown in the Mediawiki database for page views/day and such.