Extension:SpecialUserScore

User Score
For a smaller installation of MediaWiki it may be useful, to watch, who are the most active users. This special page shows the list of users sorted by the number of contributions.


 * Mediawiki-Version:
 * The code was written for MediaWiki 1.6.3
 * should work with 1.5.x.
 * successfully tested in MediaWiki 1.9.0

Security
The access to this page should restricted to those, who are managing the user accounts. This is done in the registration of the extension.

Installation
The installation follows the common way for adding special pages.

Changing Configuration
Add the following line to the LocalSettings.php just behind require_once("extensions/SpecialUserScore.php");

Register Special Page
Add the new file SpecialUserScore.php into the directory extensions: addMessages(array('userscore' => 'UserScore')); SpecialPage::addPage( new SpecialPage( 'UserScore', 'userrights') ); } ?>

Source Code
Add the new file SpecialUserScore.php into the directory includes with this code:

<?php


 * 1) SpecialUserScore Mediawiki extension
 * 2) Copyright (C) 2006 Mathias Feindt
 * 3) http://www.mediawiki.org/
 * 4) This program is free software; you can redistribute it and/or modify
 * 5) it under the terms of the GNU General Public License as published by
 * 6) the Free Software Foundation; either version 2 of the License, or
 * 7) (at your option) any later version.
 * 8) This program is distributed in the hope that it will be useful,
 * 9) but WITHOUT ANY WARRANTY; without even the implied warranty of
 * 10) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * 11) GNU General Public License for more details.
 * 12) You should have received a copy of the GNU General Public License along
 * 13) with this program; if not, write to the Free Software Foundation, Inc.,
 * 14) 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 * 15) http://www.gnu.org/copyleft/gpl.html
 * 16) Revisions
 * 17) 5-12-2006 MPalmer
 * 18) I changed the SQL (also changed SQL to use SQL aliases and FROM clause) statement and modifed
 * 19) formatResult to report n Edits on m pages
 * 20) I thought it would be useful to know how many actual pages were being edited...
 * 1) Revisions
 * 2) 5-12-2006 MPalmer
 * 3) I changed the SQL (also changed SQL to use SQL aliases and FROM clause) statement and modifed
 * 4) formatResult to report n Edits on m pages
 * 5) I thought it would be useful to know how many actual pages were being edited...
 * 1) formatResult to report n Edits on m pages
 * 2) I thought it would be useful to know how many actual pages were being edited...

require_once("QueryPage.php");

class UserScorePage extends QueryPage {

function getName { return "UserScore"; }

function isExpensive { return false; }

function isSyndicated { return false; }

function getPageHeader { # return "Es gibt folgende Rangfolge der aktiven Benutzer: \n"; #German return "The most active users are, in order: \n"; #English

}

function getSQL { $NScat = NS_CATEGORY; $dbr =& wfGetDB( DB_SLAVE ); $user= $dbr->tableName ('user'); $revision = $dbr->tableName ('revision'); $page = $dbr->tableName ('page'); $s= "               SELECT                  COUNT(wr.rev_id) as value,                  COUNT(DISTINCT wr.rev_page) as page_value,                  wu.user_name as name,                  wu.user_real_name as real_name                FROM                  $user wu,                  $revision wr,                  $page wp                WHERE                      wu.user_id = wr.rev_user                  and wp.page_id = wr.rev_page                  and wp.page_namespace = 0                  GROUP BY wu.user_name";

return $s; }

function sortDescending { return true; }

function formatResult( $skin, $result ) { global $wgContLang;

$title = Title::makeTitle( NS_USER, $result->name ); $real_name = $result->real_name ; $plink = $skin->makeLinkObj( $title, $title->getText ); $nl= $result->value. " Edits on ". $result->page_value. " pages"; $nlink = $skin->makeKnownLink(                               $wgContLang->specialPage( 'Contributions' ),                                $nl,                                'target=' . $title->getPrefixedURL ); return "$plink $real_name ($nlink)"; } }

function wfSpecialUserScore { list( $limit, $offset ) = wfCheckLimits; $cap = new UserScorePage; return $cap->doQuery( $offset, $limit ); } ?>

Room for Improvement

 * Language support: Page header and report should use the translation function. Current code is in english.
 * SQL: For large databases an index on  should be added on the table.