Extension talk:LastLoginTime

From mediawiki.org
Latest comment: 15 years ago by Subfader in topic Usage

i did a fix for mw 1.10

<?php
#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'

#this Extension is tested for MediaWiki 1.9.*
if ( ! defined( 'MEDIAWIKI' ) )
        die();

$wgExtensionCredits['other'][] = array(
    'name' => "LastLoginTime (version-1.0)",
    'author' => 'Sanjeev [[User:Sanjualone|Sanjeev]]'
);

$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('user','user_touched',
                        array('user_name' => $_SESSION['wsUserName']),
                                _METHOD_);
                if(isset($lastLogin))
                {
                        $day = substr($lastLogin,6,2);
                        $month = substr($lastLogin,4,2);
                        $month = getMonth($month);
                        $seconds = substr($lastLogin,12,2);
                        $minutes = substr($lastLogin,10,2);
                        $hour = substr($lastLogin,8,2);
                        $year = substr($lastLogin,0,4);
                        $dateTime = "last login ".$day.".".$month." ".$year." ".$hour.":".$minutes.":".$seconds;
                        $_SESSION['wsLastLogin'] = $dateTime;
                }

        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];
}
?>

Usage[edit]

Hello, sorry my question but I don't know how to use your extension... :-/ - I installed it but after that I couldn't find the "LastLogineTime" on any page... - Please explain it! :) THX

Same here. Would be cool if it's auto added on every user profile. --Subfader 14:46, 10 May 2008 (UTC)Reply
Ok it appears after loggin in again in user link section (upper right) appearing like ... Log out   last login 11.May 2008 14:43:17 and stays there all the time while being logged in >> pretty useless!!! --Subfader 14:42, 11 May 2008 (UTC)Reply