Extension:SpecialLastUserLoginEx
From MediaWiki.org
|
Release status: stable |
|||
|---|---|---|---|
| Implementation | Special page, User activity | ||
| Description | Displays the last time a user logged in | ||
| Author(s) | Justin G. Cramer, Danila Ulyanov, Thomas Klein | ||
| Last Version | 1.2.0 (November 8, 2008) | ||
| MediaWiki | 1.11 and higher | ||
| License | GNU General Public License version 2 or later | ||
| Download | see below | ||
|
|||
|
check usage (experimental) |
|||
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.
Contents |
[edit] 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++; }
[edit] 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
Change to Version 1.0.5
- Fixed some formals problems
Change to Version 1.0.6
- Specialpage is only display, when user have right 'lastlogin'
- Change name of COOKIE variable
- Fixed problem with MediaWiki 1.5.x
Change to Version 1.0.7
- Fixed update timestamp query to be database agnostic for MediaWiki Version >=1.6
(Note: Tested with postgresql and mysql only on versions 1.10.0 and 1.11.0 only)
Change to Version 1.1.0
- Separate file for i18n and a better i18n code
- Added Dutch (nl) translation
- Starting French (fr) and Latin (la) translations
- Better English messages
- New directory 'extensions/SpecialLastUserLogin/' for holding the new i18n file and the normal file together
Changes in version 1.2.0
- MediaWiki versions older than 1.11 are no longer supported
- Better standards compliance (see Manual:Coding conventions)
- Uses class autoloading → less server-intensive than before
- Internationalization messages are only loaded when needed
- Indentation fixes; uses now tab indentation rather than messy space indentation
[edit] Installation
[edit] Changing configuration
Add the following line to LocalSettings.php:
require_once($IP.'/extensions/SpecialLastUserLogin/SpecialLastUserLogin.php');
and expand the rights in LocalSettings.php (sample):
$wgGroupPermissions['sysop']['lastlogin'] = true;
[edit] Source Code
Copy the following three files into the SpecialLastUserLogin directory in your $IP/extensions/ directory.
[edit] SpecialLastUserLogin.php
<?php /** * SpecialLastUserLogin MediaWiki extension * * @file * @ingroup Extensions * @version 1.2.0 * @author Justin G. Cramer * @author Danila Ulyanov * @author Thomas Klein * @link http://www.mediawiki.org/wiki/Extension:SpecialLastUserLoginEx Documentation * * 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 */ if( !defined( 'MEDIAWIKI' ) ) { die(); } // Extension credits that will show up on Special:Version $wgExtensionCredits['specialpage'][] = array( 'name' => 'LastUserLogin', 'version' => '1.2.0', 'author' => array('Justin G. Cramer', 'Danila Ulyanov', 'Thomas Klein'), 'description' => 'Displays the last time a user logged in', 'url' => 'http://www.mediawiki.org/wiki/Extension:SpecialLastUserLoginEx', ); // New user right $wgAvailableRights[] = 'lastlogin'; // Set up the new special page $dir = dirname(__FILE__) . '/'; $wgAutoloadClasses['LastUserLogin'] = $dir . 'SpecialLastUserLogin_body.php'; $wgExtensionMessagesFiles['LastUserLogin'] = $dir . 'SpecialLastUserLogin.i18n.php'; $wgSpecialPages['LastUserLogin'] = 'LastUserLogin'; // Function that updates the database when a user logs in $wgExtensionFunctions[] = 'wfUpdateUserTouched'; function wfUpdateUserTouched() { global $wgOut, $wgCookiePrefix; if( isset( $_COOKIE ) && isset( $_COOKIE["{$wgCookiePrefix}UserID"] ) ) { $dbw = wfGetDB( DB_MASTER ); $query = "UPDATE ".$dbw->tableName('user')." SET user_touched = '".$dbw->timestamp()."' WHERE user_id = ".intval($_COOKIE["{$wgCookiePrefix}UserID"]); $dbw->doQuery($query); } }
[edit] SpecialLastUserLogin_body.php
<?php class LastUserLogin extends SpecialPage { /** * Constructor */ public function __construct() { parent::__construct( 'LastUserLogin'/*class*/, 'lastlogin'/*restriction*/ ); } /** * Show the special page * * @param $par Mixed: parameter passed to the page or null */ public function execute( $par ) { global $wgUser, $wgOut, $wgLang; wfLoadExtensionMessages( 'LastUserLogin' ); # If user is blocked, s/he doesn't need to access this page if ( $wgUser->isBlocked() ) { $wgOut->blockedPage(); return; } # Show a message if the database is in read-only mode if ( wfReadOnly() ) { $wgOut->readOnlyPage(); return; } # If the user doesn't have the required 'lastlogin' permission, display an error if( !$wgUser->isAllowed( 'lastlogin' ) ) { $wgOut->permissionRequired( 'lastlogin' ); return; } $this->setHeaders(); $skin = $wgUser->getSkin(); $wgOut->setPageTitle( wfMsg( 'lastuserlogin' ) ); $dbr = 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 ".$dbr->tableName('user')." ORDER BY ".$orderby." ".$ordertype; $ordertype = $ordertype == 'ASC' ? 'DESC' : 'ASC'; if( $result = $dbr->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 = $dbr->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] ), true ). '</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 ); } }
[edit] SpecialLastUserLogin.i18n.php
<?php /** * Internationalization file for LastUserLogin extension. * * @file * @ingroup Extensions */ $messages = array(); /** English * @author Justin G. Cramer * @author Danila Ulyanov * @author Thomas Klein */ $messages['en'] = array( 'lastuserlogin' => 'Last user login', 'lastuserlogin_userid' => 'Username', 'lastuserlogin_username' => 'Real name', 'lastuserlogin_useremail' => 'User email', 'lastuserlogin_lastlogin' => 'Last login', 'lastuserlogin_daysago' => 'Days ago', ); /** German (Deutsch) */ $messages['de'] = array( 'lastuserlogin' => 'Letzte Anmeldungen', 'lastuserlogin_userid' => 'Benutzername', 'lastuserlogin_username' => 'Echter Name', 'lastuserlogin_useremail' => 'E-Mail-Adresse', 'lastuserlogin_lastlogin' => 'Letzte Anmeldung', 'lastuserlogin_daysago' => 'Tage', ); /** French (Français) */ $messages['fr'] = array( 'lastuserlogin_userid' => 'Nom d’utilisateur', 'lastuserlogin_username' => 'Nom réel', ); /** Latin (Latina) */ $messages['la'] = array( 'lastuserlogin_userid' => 'Nomen usoris', 'lastuserlogin_username' => 'Nomen tuum verum', ); /** Dutch (Nederlands) */ $messages['nl'] = array( 'lastuserlogin' => 'Laatste aanmeldingen van gebruikers', 'lastuserlogin_userid' => 'Gebruikersnaam', 'lastuserlogin_username' => 'Echte naam', 'lastuserlogin_useremail' => 'E-mail', 'lastuserlogin_lastlogin' => 'Laatste aanmelding', 'lastuserlogin_daysago' => 'Aantal dagen geleden', ); /* Lithuanian (Lietuvių) */ $messages['lt'] = array( 'lastuserlogin' => 'Paskutinis naudotojo prisijungimas', 'lastuserlogin_userid' => 'Naudotojo vardas', 'lastuserlogin_username' => 'Tikras vardas', 'lastuserlogin_useremail' => 'Naudotojo el. paštas', 'lastuserlogin_lastlogin' => 'Paskutinis prisijungimas', 'lastuserlogin_daysago' => 'Dienų prieš', ); /* Polish (Polski) */ $messages['pl'] = array( 'lastuserlogin' => 'Ostatnie zalogowania użytkownika', 'lastuserlogin_userid' => 'Login', 'lastuserlogin_username' => 'Prawdziwa nazwa', 'lastuserlogin_useremail' => 'Adres e-mail', 'lastuserlogin_lastlogin' => 'Ostatnie zalogowanie', 'lastuserlogin_daysago' => 'dni temu', ); /* Russian (Russian) */ $messages['ru'] = array( 'lastuserlogin' => 'Недавние посещения пользователей', 'lastuserlogin_userid' => 'Имя пользователя', 'lastuserlogin_username' => 'Настоящее имя', 'lastuserlogin_useremail' => 'Электронная почта', 'lastuserlogin_lastlogin' => 'Недавнее посещение', 'lastuserlogin_daysago' => 'Дней назад', ); /* Japanese (日本語) */ $messages['ja'] = array( 'lastuserlogin' => '利用者の最終ログイン', 'lastuserlogin_userid' => '利用者名', 'lastuserlogin_username' => '本名', 'lastuserlogin_useremail' => 'メールアドレス', 'lastuserlogin_lastlogin' => '最終ログイン', 'lastuserlogin_daysago' => '経過日数', );