Extension:LastLoginTime

From MediaWiki.org

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

Release status: beta

Implementation User activity
Description This Extension displays Last Login Time for a user as a personal url.
Author(s) Sanjeev
Version 1.0
MediaWiki 1.9+
Download LastLoginTime.php
Hooks used UserLoginComplete

PersonalUrls

Contents

[edit] What can this extension do?

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.

[edit] Usage

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.

[edit] Installation

  1. Copy the code given at LastLoginTime.php
  2. Save it in extensions directory as LastLoginTime.php
  3. Include it in LocalSettings.php
  4. That's all you need to do.

[edit] Changes to LocalSettings.php

require_once("$IP/extensions/LastLoginTime.php");

[edit] Code

<?php
/**
 * 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' ) )
        die();
 
$wgExtensionCredits['other'][] = array(
    'name' => 'LastLoginTime',
    'version' => '1.0',
    'author' => 'Sanjeev',
    '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 databease in stored in session.
           $dbr =& wfGetDB( DB_SLAVE );
                $lastLogin = $dbr->selectField('mwuser','user_touched',
                        array('user_name' => $_SESSION['wsUserName']),
                                _METHOD_);
                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( 'mwuser',
                        /* 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];
}

[edit] Contact

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

[edit] See also

Personal tools