Added hook events for article protection. Added sample code to Syslog
[lhc/web/wiklou.git] / extensions / Syslog.php
1 <?
2 /* Syslog.php -- an extension to log events to the system logger
3 * Copyright 2004 Evan Prodromou <evan@wikitravel.org>
4 *
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.
9 *
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.
14 *
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
18 *
19 * @author Evan Prodromou <evan@wikitravel.org>
20 * @package MediaWiki
21 * @subpackage Extensions
22 */
23
24 if (defined('MEDIAWIKI')) {
25
26 # Setup globals
27
28 if (!isset($wgSyslogIdentity)) {
29 $wgSyslogIdentity = $wgDBname;
30 }
31 if (!isset($wgSyslogFacility)) {
32 $wgSyslogFacility = LOG_USER;
33 }
34
35 # Hook for login
36
37 function syslogUserLogin(&$user) {
38 syslog(LOG_INFO, "User '" . $user->getName() . "' logged in.");
39 return true;
40 }
41
42 # Hook for logout
43
44 function syslogUserLogout(&$user) {
45 syslog(LOG_INFO, "User '" . $user->getName() . "' logged out.");
46 return true;
47 }
48
49 function syslogBlockIp(&$block, &$user) {
50 syslog(LOG_NOTICE, "User '" . $user->getName() .
51 "' blocked '" . (($block->mUser) ? $block->mUser : $block->mAddress) .
52 "' for '" . $block->mReason . "' until '" . $block->mExpiry . "'");
53 return true;
54 }
55
56 function syslogArticleProtect(&$article, &$user, $protect, &$reason, &$moveonly) {
57 $title = $article->mTitle;
58 syslog(LOG_NOTICE, "User '" . $user->getName() . "' " .
59 (($protect) ? "protected" : "unprotected") . " article '" .
60 $title->getPrefixedText() .
61 "' for '" . $reason . "' " . (($moveonly) ? "(moves only)" : "") );
62 return true;
63 }
64
65 # Setup -- called once environment is configured
66
67 function setupSyslog() {
68
69 global $wgSyslogIdentity, $wgSyslogFacility, $_syslogId;
70 global $wgHooks;
71
72 openlog($wgSyslogIdentity, LOG_ODELAY | LOG_PID, $wgSyslogFacility);
73
74 $wgHooks['UserLoginComplete'][] = syslogUserLogin;
75 $wgHooks['UserLogout'][] = syslogUserLogout;
76 $wgHooks['BlockIpComplete'][] = syslogBlockIp;
77 $wgHooks['ArticleProtectComplete'][] = syslogArticleProtect;
78
79 return true;
80 }
81
82 # Add to global list of extensions
83
84 $wgExtensionFunctions[] = setupSyslog;
85 }
86
87 ?>