Difference between revisions of "Extension:UserLoginLog.php"

From Organic Design wiki
m
(debugged)
Line 6: Line 6:
 
if (!defined('MEDIAWIKI')) die('Not an entry point.');
 
if (!defined('MEDIAWIKI')) die('Not an entry point.');
  
define('USER LOGIN LOG_VERSION','1.0.0, 2007-07-26');
+
define('USER_LOGIN_LOG_VERSION','1.0.0, 2007-07-26');
  
 +
$wgServerUser = 1; # User ID to use for logging if no user exists
 +
 +
$wgExtensionFunctions[] = 'wfSetupUserLoginLog';
 
$wgExtensionCredits['other'][] = array(
 
$wgExtensionCredits['other'][] = array(
 
'name'        => 'User login log',
 
'name'        => 'User login log',
Line 13: Line 16:
 
'description' => 'Creates a new MediaWiki log for user logins and logout events',
 
'description' => 'Creates a new MediaWiki log for user logins and logout events',
 
'url'        => 'http://www.mediawiki.org/wiki/Extension:User_login_log',
 
'url'        => 'http://www.mediawiki.org/wiki/Extension:User_login_log',
'version'    => USER LOGIN LOG_VERSION
+
'version'    => USER_LOGIN_LOG_VERSION
 
);
 
);
  
 
# Add a new log type
 
# Add a new log type
$wgLogTypes[]                     = 'userlogin';
+
$wgLogTypes[]                     = 'userlogin';
$wgLogNames  ['userlogin']       = 'userloginlogpage';
+
$wgLogNames  ['userlogin']         = 'userloginlogpage';
$wgLogHeaders['userlogin']       = 'userloginlogpagetext';
+
$wgLogHeaders['userlogin']         = 'userloginlogpagetext';
$wgLogActions['userlogin/ok']     = 'userlogin-ok';
+
$wgLogActions['userlogin/success'] = 'userlogin-success';
$wgLogActions['userlogin/fail']  = 'userlogin-fail';
+
$wgLogActions['userlogin/error']  = 'userlogin-error';
$wgLogActions['userlogin/logout'] = 'userlogin-logout';
+
$wgLogActions['userlogin/logout'] = 'userlogin-logout';
  
 
# Add hooks to the login/logout events
 
# Add hooks to the login/logout events
#$wgHooks
+
$wgHooks['UserLoginForm'][]      = 'wfUserLoginLogError';
 +
$wgHooks['UserLoginComplete'][]  = 'wfUserLoginLogSuccess';
 +
$wgHooks['UserLogout'][]        = 'wfUserLoginLogout';
 +
$wgHooks['UserLogoutComplete'][] = 'wfUserLoginLogoutComplete';
 +
 
 +
function wfUserLoginLogSuccess(&$user) {
 +
$log = new LogPage('userlogin',false);
 +
$log->addEntry('success',$user->getUserPage(),wfGetIP());
 +
return true;
 +
}
 +
 
 +
function wfUserLoginLogError(&$tmpl) {
 +
global $wgUser,$wgServerUser;
 +
if ($tmpl->data['message'] && $tmpl->data['messagetype'] == 'error') {
 +
$log = new LogPage('userlogin',false);
 +
$tmp = $wgUser->mId;
 +
if ($tmp == 0) $wgUser->mId = $wgServerUser;
 +
$log->addEntry('error',$wgUser->getUserPage(),$tmpl->data['message'],array(wfGetIP()));
 +
$wgUser->mId = $tmp;
 +
}
 +
return true;
 +
}
 +
 
 +
# Create a copy of the current user for logging after logout
 +
function wfUserLoginLogout(&$user) {
 +
global $wgUserBeforeLogout;
 +
$wgUserBeforeLogout = User::newFromId($user->getID());
 +
return true;
 +
}
 +
 +
function wfUserLoginLogoutComplete(&$user) {
 +
global $wgUser,$wgUserBeforeLogout;
 +
$tmp = $wgUser->mId;
 +
$wgUser->mId = $wgUserBeforeLogout->getId();
 +
$log = new LogPage('userlogin',false);
 +
$log->addEntry('logout',$wgUserBeforeLogout->getUserPage(),$user->getName());
 +
$wgUser->mId = $tmp;
 +
return true;
 +
}
  
 
function wfSetupUserLoginLog() {
 
function wfSetupUserLoginLog() {
Line 31: Line 72:
 
if ($wgLanguageCode == 'en') {
 
if ($wgLanguageCode == 'en') {
 
$wgMessageCache->addMessages(array(
 
$wgMessageCache->addMessages(array(
'userlogin'            => "User login log",
 
 
'userloginlogpage'    => "User login log",
 
'userloginlogpage'    => "User login log",
'userloginlogpagetext' => "This is a log of events associated with users logging in or out of the wiki.",
+
'userloginlogpagetext' => "This is a log of events associated with users logging in or out of the wiki",
'userlogin/ok'         => "User '''[[User:$1|$1]]''' has successfully logged in.",
+
'userlogin-success'   => "Login completed successfully",
'userlogin/fail'       => "User '''[[User:$1|$1]]''' failed to logged in.",
+
'userlogin-error'     => "Login failure from $2",
'userlogin/logout'    => "User '''[[User:$1|$1]]''' has successfully logged out.",
+
'userlogin-logout'    => "Logout completed successfully",
 
'userloginlogentry'    => ""
 
'userloginlogentry'    => ""
 
));
 
));

Revision as of 10:51, 30 July 2007

<?php

  1. Extension:User login log
Info.svg These are the MediaWiki extensions we're using and/or developing. Please refer to the information on the mediawiki.org wiki for installation and usage details. Extensions here which have no corresponding mediawiki article are either not ready for use or have been superseded. You can also browse our extension code in our local Subversion repository or our GitHub mirror.

Template:Php

  1. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
  2. - Author: User:NadCategory:Extensions created with Template:Extension

if (!defined('MEDIAWIKI')) die('Not an entry point.');

define('USER_LOGIN_LOG_VERSION','1.0.0, 2007-07-26');

$wgServerUser = 1; # User ID to use for logging if no user exists

$wgExtensionFunctions[] = 'wfSetupUserLoginLog'; $wgExtensionCredits['other'][] = array( 'name' => 'User login log', 'author' => 'User:Nad', 'description' => 'Creates a new MediaWiki log for user logins and logout events', 'url' => 'http://www.mediawiki.org/wiki/Extension:User_login_log', 'version' => USER_LOGIN_LOG_VERSION );

  1. Add a new log type

$wgLogTypes[] = 'userlogin'; $wgLogNames ['userlogin'] = 'userloginlogpage'; $wgLogHeaders['userlogin'] = 'userloginlogpagetext'; $wgLogActions['userlogin/success'] = 'userlogin-success'; $wgLogActions['userlogin/error'] = 'userlogin-error'; $wgLogActions['userlogin/logout'] = 'userlogin-logout';

  1. Add hooks to the login/logout events

$wgHooks['UserLoginForm'][] = 'wfUserLoginLogError'; $wgHooks['UserLoginComplete'][] = 'wfUserLoginLogSuccess'; $wgHooks['UserLogout'][] = 'wfUserLoginLogout'; $wgHooks['UserLogoutComplete'][] = 'wfUserLoginLogoutComplete';

function wfUserLoginLogSuccess(&$user) { $log = new LogPage('userlogin',false); $log->addEntry('success',$user->getUserPage(),wfGetIP()); return true; }

function wfUserLoginLogError(&$tmpl) { global $wgUser,$wgServerUser; if ($tmpl->data['message'] && $tmpl->data['messagetype'] == 'error') { $log = new LogPage('userlogin',false); $tmp = $wgUser->mId; if ($tmp == 0) $wgUser->mId = $wgServerUser; $log->addEntry('error',$wgUser->getUserPage(),$tmpl->data['message'],array(wfGetIP())); $wgUser->mId = $tmp; } return true; }

  1. Create a copy of the current user for logging after logout

function wfUserLoginLogout(&$user) { global $wgUserBeforeLogout; $wgUserBeforeLogout = User::newFromId($user->getID()); return true; }

function wfUserLoginLogoutComplete(&$user) { global $wgUser,$wgUserBeforeLogout; $tmp = $wgUser->mId; $wgUser->mId = $wgUserBeforeLogout->getId(); $log = new LogPage('userlogin',false); $log->addEntry('logout',$wgUserBeforeLogout->getUserPage(),$user->getName()); $wgUser->mId = $tmp; return true; }

function wfSetupUserLoginLog() { global $wgLanguageCode,$wgMessageCache; if ($wgLanguageCode == 'en') { $wgMessageCache->addMessages(array( 'userloginlogpage' => "User login log", 'userloginlogpagetext' => "This is a log of events associated with users logging in or out of the wiki", 'userlogin-success' => "Login completed successfully", 'userlogin-error' => "Login failure from $2", 'userlogin-logout' => "Logout completed successfully", 'userloginlogentry' => "" )); }

} ?>