Extension:LastLoginTime
From MediaWiki.org
|
LastLoginTime Release status: beta |
|||
|---|---|---|---|
| Implementation | User activity | ||
| Description | This extension displays Last Login Time for a user as a personal URL. | ||
| Author(s) | Sanjeev | ||
| Last version | 1.0 | ||
| MediaWiki | 1.9+ | ||
| License | No license specified | ||
| Download | LastLoginTime.php | ||
|
|||
| Check usage and version matrix | |||
Contents |
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.
Usage [edit]
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.
Installation [edit]
- Copy the code given at LastLoginTime.php
- Save it in extensions directory as LastLoginTime.php
- Include it in LocalSettings.php
- That's all you need to do.
Changes to LocalSettings.php [edit]
require_once("$IP/extensions/LastLoginTime.php");
Code [edit]
<?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', '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']), __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( '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]; }
Contact [edit]
In case of any issues please get in touch with Sanjeev. Thanks!
