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 # Hook for IP & user blocks
51 function syslogBlockIp(&$block, &$user) {
52 syslog(LOG_NOTICE
, "User '" . $user->getName() .
53 "' blocked '" . (($block->mUser
) ?
$block->mUser
: $block->mAddress
) .
54 "' for '" . $block->mReason
. "' until '" . $block->mExpiry
. "'");
58 # Hook for article protection
60 function syslogArticleProtect(&$article, &$user, $protect, &$reason, &$moveonly) {
61 $title = $article->mTitle
;
62 syslog(LOG_NOTICE
, "User '" . $user->getName() . "' " .
63 (($protect) ?
"protected" : "unprotected") . " article '" .
64 $title->getPrefixedText() .
65 "' for '" . $reason . "' " . (($moveonly) ?
"(moves only)" : "") );
69 # Hook for article deletion
71 function syslogArticleDelete(&$article, &$user, &$reason) {
72 $title = $article->mTitle
;
73 syslog(LOG_NOTICE
, "User '" . $user->getName() . "' deleted '" .
74 $title->getPrefixedText() .
75 "' for '" . $reason . "' ");
79 # Hook for article save
81 function syslogArticleSave(&$article, &$user, &$text, $summary,
82 $isminor, $iswatch, $section)
84 $title = $article->mTitle
;
85 syslog(LOG_NOTICE
, "User '" . $user->getName() . "' saved '" .
86 $title->getPrefixedText() .
87 "' with comment '" . $summary . "' ");
91 # Setup -- called once environment is configured
93 function setupSyslog() {
95 global $wgSyslogIdentity, $wgSyslogFacility, $_syslogId;
98 openlog($wgSyslogIdentity, LOG_ODELAY | LOG_PID
, $wgSyslogFacility);
100 $wgHooks['UserLoginComplete'][] = 'syslogUserLogin';
101 $wgHooks['UserLogout'][] = 'syslogUserLogout';
102 $wgHooks['BlockIpComplete'][] = 'syslogBlockIp';
103 $wgHooks['ArticleProtectComplete'][] = 'syslogArticleProtect';
104 $wgHooks['ArticleDeleteComplete'][] = 'syslogArticleDelete';
105 $wgHooks['ArticleSaveComplete'][] = 'syslogArticleSave';
110 # Add to global list of extensions
112 $wgExtensionFunctions[] = setupSyslog
;