Extension:SpecialUserScore

From MediaWiki.org

Jump to: navigation, search
Manual on MediaWiki Extensions
List of MediaWiki Extensions
Special:UserScore

Release status: unknown

Implementation Special page, User activity
Description User score as measured by number of contributions
Author(s) Mathias Feindt
Version 1.1 (2006-05-12)
MediaWiki 1.6.3 or later
Download see below

Contents

[edit] 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 and 1.10.0

[edit] Security

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

[edit] Installation

The installation follows the common way for adding special pages.

[edit] Changing Configuration

Add the following line to the end of LocalSettings.php:

require_once("extensions/SpecialUserScore.php");

[edit] Register Special Page

Add the new file SpecialUserScore.php into the directory extensions:

<?php
$wgExtensionFunctions[] = "wfExtensionSpecialUserScore";
 
// Extension credits that show up on Special:Version
$wgExtensionCredits['specialpage'][] = array(
        'name' => 'Special:UserScore',
        'author' => 'Mathias Feindt',
        'url' => 'http://www.mediawiki.org/wiki/Extension:SpecialUserScore',
        'description' => 'Special page for displaying user score as measured by number of contributions.'
);
 
function wfExtensionSpecialUserScore() {
    global $wgMessageCache;
    $wgMessageCache->addMessages(array('userscore' => 'UserScore')); 
    SpecialPage::addPage( new SpecialPage( 'UserScore' , 'userrights') );
}

[edit] Source Code

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

<?php
 
#
# SpecialUserScore MediaWiki extension
#
# Copyright (C) 2006 Mathias Feindt
# http://www.mediawiki.org/
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# http://www.gnu.org/copyleft/gpl.html
#
#
# Revisions
# 5-12-2006 MPalmer
# I changed the SQL (also changed SQL to use SQL aliases and FROM clause) statement and modifed 
# formatResult to report n Edits on m pages
# 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: <br />\n"; #German
                return "The most active users are, in order: <br />\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=' . $result->name );
                return "$plink $real_name ($nlink)";
        }
}
 
function wfSpecialUserScore() {
        list( $limit, $offset ) = wfCheckLimits();
        $cap = new UserScorePage();
        return $cap->doQuery( $offset, $limit );
}

[edit] 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 rev_user should be added on the table revision.
  • Make into a proper extension that doesn't require copying the special page into the "includes" directory and modifying core files that will get changed in the next MediaWiki version.
  • Add % of total wiki edits.
  • Add option for filtering by certain time frames, IE past 30 days

[edit] Similar Extensions

Personal tools