From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.png

Release status:Extension status unmaintained

ImplementationTemplate:Extension#type User activity
DescriptionTemplate:Extension#description This extension displays Last Login Time for a user as a personal URL.
Author(s)Template:Extension#username Sanjeev (Sanjualonetalk)
Latest versionTemplate:Extension#version 1.0
MediaWikiTemplate:Extension#mediawiki 1.9+
LicenseTemplate:Extension#license No license specified
Download LastLoginTime.php
Hooks usedTemplate:Extension#hook

Translate the LastLoginTime extension if it is available at translatewiki.net

Check usage and version matrix.

What can this extension do?[edit]

This extension is a simple one which displays User's Last login time at the top of the page as a personal url. I wrote this extension because i thought this will be a good idea to display last login time for the users. It may help others if they have same requirement for their application.


This extension is as mentioned a simple one so usage is not a big deal. Just confirm the table and column names in the code are according to your database. Install it and that's it.


  • Copy the code below for LastLoginTime.php and place the file(s) in a directory called LastLoginTime in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    require_once "$IP/extensions/LastLoginTime/LastLoginTime.php";
  • YesY Done - Navigate to Special:Version on your wiki to verify that the extension is successfully installed.


 * LastLoginTime extension
 * Shows the date with time user logged in wiki last time.
 * the Date Time will be shown as a personal url at the top of the page
 * like '20:43, 14 Jun 2007'
 * @author Sanjeev
 * @version 1.0
 * @url http://www.mediawiki.org/wiki/Extension:LastLoginTime
if ( ! defined( 'MEDIAWIKI' ) )

$wgExtensionCredits['other'][] = array(
	'name' => 'LastLoginTime',
	'version' => '1.0',
	'author' => 'Sanjeev',
	'description' => 'Shows the date with time user logged in to the wiki the last time.',
	'url' => 'http://www.mediawiki.org/wiki/Extension:LastLoginTime'

$wgHooks['UserLoginComplete'][] = 'wfLastLoginTime';

$wgHooks['PersonalUrls'][] = 'wfShowLastLoginTime';

#Event handler for PersonalUrls Hook
function wfShowLastLoginTime(&$personal_urls, &$wgTitle) {
	#Displays the last login time for the current user as a personal URL.
	if( isset($_SESSION['wsLastLogin']) ) {
		$personal_urls['lastlogin'] = array(
			'text' => $_SESSION['wsLastLogin']
	return true;

#Event handler for UserLoginComplete
function wfLastLoginTime() {
	#The last login time is read from database in stored in session.
	$dbr = wfGetDB( DB_SLAVE );
		$lastLogin = $dbr->selectField('user','user_touched',
			array('user_name' => $_SESSION['wsUserName']),
		if(isset($lastLogin)) {
			$day = substr($lastLogin, 8, 2);
			$month = substr($lastLogin, 5, 2);
			$month = getMonth($month);
			$time = substr($lastLogin, 11, 5);
			$year = substr($lastLogin, 0, 4);
			$dateTime = $time.", ".$day." ".$month." ".$year;
			$_SESSION['wsLastLogin'] = $dateTime;

	#The login time is updated with the current time
	$dbw = wfGetDB( DB_MASTER );
	$dbw->update( 'user',
		/* SET */ array( 'user_touched'  => 'now()' ),
		/* WHERE */ array( 'user_name' => $_SESSION['wsUserName'])
	return true;

#This function will return month name.
function getMonth($month) {
	$months = array('01' => 'Jan', '02' => 'Feb', '03' => 'Mar', '04' => 'Apr', '05' => 'May', '06' => 'Jun',
	'07' => 'Jul', '08' => 'Aug', '09' => 'Sep', '10' => 'Oct', '11' => 'Nov', '12' => 'Dec');
	return $months[$month];


In case of any issues please get in touch with Sanjeev. Thanks!