MediaWiki扩展:用户最后登录清单
天下维客,你可以修改的网络知识库
本文取自元维基,欢迎共同翻译、整理与大家共享,促进中文wiki发展^_^
目录 |
Last User Login
Last User Login displays a simple table of users and the last time they logged in. This can be useful, if your wiki is used as a knowledge base for outside personnel. If you have a requirement that they check the wiki prior to placing a call or email Last User Login can be used to verify that this policy is being enforced.
Security
While this extension only shows up in the restricted extension list for sysops, there is nothing in the code that authorizes the user to ensure they should be able to view this special page (i.e., 'if you type the path to this extension directly, it will show anyone your user list').
If you only want sysops to be able to see the user information you can add the following code at the top of the execte function (~line 71) JT 04:35, 19 December 2005 (UTC)
Add the following:
if ( ! $wgUser->isSysop() ) {
$wgOut->sysopRequired();
return;
}
- Thank you for your reference. I built it into the new version. --Thomas Klein 11:42, 20 December 2005 (UTC)
Impact to other functions
Adding a log entry for every user login impacts the script /maintenance/removeUnusedAccounts.php as the script checks for the number of page-edits, image-uploads and log-entries. However you can patch removeUnusedAccounts.php to ignore the first login which is very common for spamming robots:
original
if( CountEdits( $user, false ) == 0 && CountImages( $user, false ) == 0 && CountLogs( $user, false ) ==0 ) {
# User has no edits or images, mark them for deletion
$del[] = $user;
$count++;
}
change to that
if( CountEdits( $user, false ) == 0 && CountImages( $user, false ) == 0 && CountLogs( $user, false ) <= 1 ) {
# User has no edits or images, mark them for deletion
$del[] = $user;
$count++;
}
Modified Version
This is yet another minor modified
- version of the SpecialLastUserLogin extension by User:Yazheirx.
The following is new in the version:
- Installation in the path extensions
- Internationalization of the texts (s. MediaWiki:Lastuserlogin and next)
- Internationalization of the format of date
- Internationalization the output of database
Change to Version 1.0.1
- Make a link to the user page
Change to Version 1.0.2
- The code checked the user authorizes
Change to Version 1.0.3
- Fixed problems with varibale $_COOKIE and $PHPSELF
- Translation to german
- Insert sytel cellpadding in table
Change to Version 1.0.4
- Fixed problems with MediaWiki 1.6
Installation
Changing configuration
Add the following line to LocalSettings.php:
include('extensions/SpecialLastUserLogin.php');
Source Code
Copy the following code in to extensions/SpecialLastUserLogin.php
<?php
#
# SpecialLastUserLogin Mediawiki extension
#
# original by Justin G. Cramer and Danila Ulyanov 22.11.2005
#
# Copyright (C) 2005 - 2006 Thomas Klein
# 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
/**
* ChangeLog
*
* 04.04.2006 1.0.4
* - Fixed problems with MediaWiki 1.6
*
* 29.03.2006 1.0.3
* - Fixed problems with varibale $_COOKIE and $PHPSELF
* - Translation to german
* - Insert style cellpadding in table
*
* 20.12.2005 1.0.2
* - The code checked the user authorizes
*
* 09.12.2005 1.0.1
* - Make a link to the user page
*
* 30.11.2005 1.0.0
* - Release of the first version
*/
if( !defined( 'MEDIAWIKI' ) ) {
die();
}
require_once "$IP/includes/SpecialPage.php";
$wgExtensionFunctions[] = "wfLastUserLogin";
$wgExtensionFunctions[] = "wfUpdateUserTouched";
$wgExtensionCredits['specialpage'][] = array(
'name' => 'LastUserLogin',
'description' => 'Displays the last time a user logged in',
'url' => 'http://meta.wikimedia.org/wiki/SpecialLastUserLoginEx',
'author' => 'Justin G. Cramer, Danila Ulyanov, Thomas Klein',
'version'=>'1.0.4');
function wfUpdateUserTouched() {
global $wgDBprefix, $wgOut, $wgDBname;
$db = &wfGetDB(DB_SLAVE);
$query = "UPDATE {$wgDBprefix}user SET user_touched = '".wfTimestamp(TS_MW)."' WHERE user_id = ".intval($_COOKIE["{$wgDBname}UserID"]);
$db->doQuery($query);
}
function wfLastUserLogin() {
class SpezialLastUserLogin extends SpecialPage {
function SpezialLastUserLogin() {
SpecialPage::SpecialPage('LastUserLogin', 'renameuser');
}
function execute() {
global $wgDBprefix, $wgOut, $wgLang, $PHPSELF;
global $wgUser;
if ( ! $wgUser->isAllowed('renameuser') ) {
$wgOut->permissionRequired('renameuser');
return;
}
$this->setHeaders();
$skin = $wgUser->getSkin( );
$wgOut->setPagetitle( wfMsg( 'lastuserlogin' ) );
$db = &wfGetDB(DB_SLAVE);
$style = 'style="border:1px solid #000;text-align:left;"';
$fields = array('user_name'=>'lastuserlogin_userid',
'user_real_name'=>'lastuserlogin_username',
'user_email'=>'lastuserlogin_useremail',
'user_touched'=>'lastuserlogin_lastlogin'
);
//get order by and check it
if(isset($_REQUEST['order_by'])){
if(isset($fields[$_REQUEST['order_by']])){
$orderby = $_REQUEST['order_by'];
}else{
$orderby = 'user_name';
}
}else{
$orderby = 'user_name';
}
//get order type and check it
if(isset($_REQUEST['order_type'])){
if($_REQUEST['order_type']=='DESC'){
$ordertype = $_REQUEST['order_type'];
}else{
$ordertype = 'ASC';
}
}else{
$ordertype = 'ASC';
}
$query = "SELECT user_name, user_real_name, user_email, user_touched FROM ".$wgDBprefix."user ORDER BY ".$orderby." ".$ordertype;
$ordertype = $ordertype=='ASC'?'DESC':'ASC';
if ($result = $db->doQuery($query)) {
$out = '<table width="100%" cellpadding="3" '.$style.'><tr>';
foreach($fields as $key=>$value){
$out .= '<th '.$style.'><a href="?order_by='.$key.'&order_type='.$ordertype.'">'.wfMsg( $value ).'</a></th>';
}
$out .= "<th $style>".wfMsg( 'lastuserlogin_daysago' )."</th>";
$out .= '</tr>';
while ($row = $db->fetchRow($result)) {
$out .= '<tr>';
foreach($fields as $key=>$value){
if ($key == "user_touched") {
$style = 'style="border:1px solid #000"';
$out .= "<td $style>".$wgLang->timeanddate( wfTimestamp(TS_MW, $row[$key])).
'</td><td style="border: 1px solid #000; text-align:right;">'.
$wgLang->formatNum(round((mktime() - wfTimestamp(TS_UNIX, $row[$key]))/3600/24, 2), 2)."</td>";
} else {
if ($key == "user_name") {
$userPage = Title::makeTitle( NS_USER, htmlspecialchars($row[$key]));
$name = $skin->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );
$out .= '<td '.$style.'>'.$name.'</a></td>';
} else {
$out .= '<td '.$style.'>'.htmlspecialchars($row[$key]).' </td>';
}
}
}
$out .= '</tr>';
}
}
$out .= '</table>';
$wgOut->addHTML( $out );
}
}
SpecialPage::addPage( new SpezialLastUserLogin );
global $wgMessageCache, $wgLanguageCode;
if ($wgLanguageCode == 'de') {
$wgMessageCache->addMessage('lastuserlogin' ,'Letzte Anmeldungen');
$wgMessageCache->addMessage('lastuserlogin_userid', 'Anmeldename');
$wgMessageCache->addMessage('lastuserlogin_username', 'Benutzername');
$wgMessageCache->addMessage('lastuserlogin_useremail', 'E-Mail-Adresse');
$wgMessageCache->addMessage('lastuserlogin_lastlogin', 'Letzte Anmeldung');
$wgMessageCache->addMessage('lastuserlogin_daysago', 'Tage');
}
else {
$wgMessageCache->addMessage('lastuserlogin' ,'Last User Login');
$wgMessageCache->addMessage('lastuserlogin_userid', 'User ID');
$wgMessageCache->addMessage('lastuserlogin_username', 'User Name');
$wgMessageCache->addMessage('lastuserlogin_useremail', 'User Email');
$wgMessageCache->addMessage('lastuserlogin_lastlogin', 'Last Login');
$wgMessageCache->addMessage('lastuserlogin_daysago', 'Days Ago');
}
}
?>
原文参见: SpecialLastUserLoginEx


