MediaWiki扩展:贡献排行
天下维客,你可以修改的网络知识库
| Template:If | |
| Type: | Special Page |
|---|---|
| Maturity: | Alpha |
| MediaWiki: | 1.6.3 |
| Version: | 1.1 |
| Last Update: | 2006-05-12 |
| Description: | user score as meassured by number of contributions |
| MediaWiki extensions | |
目录 |
[编辑]
User Score
For a smaller installation of MediaWiki it may be usefull, to watch, who are the most active users. This special page shows the list of users sorted by the number of contributions. The code is written for MediaWiki 1.6.3 but it also should work with 1.5.x.
[编辑]
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 behindrequire_once( "includes/DefaultSettings.php" );
require_once("extensions/SpecialUserScore.php");
[编辑]
Register Special Page
Add the new file SpecialUserScore.php into the directory extensions:
<?php
$wgExtensionFunctions[] = "wfExtensionSpecialUserScore";
function wfExtensionSpecialUserScore() {
global $wgMessageCache;
$wgMessageCache->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
#
# 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=' . $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
rev_user
should be added on the tablerevision
.


