2 /* Syslog.php -- an extension to log events to the system logger
3 * Copyright 2004 Evan Prodromou <evan@wikitravel.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * @author Evan Prodromou <evan@wikitravel.org>
21 * @subpackage Extensions
24 if (defined('MEDIAWIKI')) {
28 if (!isset($wgSyslogIdentity)) {
29 $wgSyslogIdentity = $wgDBname;
31 if (!isset($wgSyslogFacility)) {
32 $wgSyslogFacility = LOG_USER
;
37 function syslogUserLogin(&$user) {
38 syslog(LOG_INFO
, "User '" . $user->getName() . "' logged in.");
44 function syslogUserLogout(&$user) {
45 syslog(LOG_INFO
, "User '" . $user->getName() . "' logged out.");
49 function syslogBlockIp(&$block, &$user) {
50 syslog(LOG_INFO
, "User '" . $user->getName() .
51 "' blocked '" . (($block->mUser
) ?
$block->mUser
: $block->mAddress
) .
52 "' for '" . $block->mReason
. "' until '" . $block->mExpiry
. "'");
56 # Setup -- called once environment is configured
58 function setupSyslog() {
60 global $wgSyslogIdentity, $wgSyslogFacility, $_syslogId;
63 openlog($wgSyslogIdentity, LOG_ODELAY | LOG_PID
, $wgSyslogFacility);
65 $wgHooks['UserLoginComplete'][] = syslogUserLogin
;
66 $wgHooks['UserLogout'][] = syslogUserLogout
;
67 $wgHooks['BlockIpComplete'][] = syslogBlockIp
;
72 # Add to global list of extensions
74 $wgExtensionFunctions[] = setupSyslog
;