Revert accidental checkin of unused experimental code.
[lhc/web/wiklou.git] / extensions / Syslog.php
1 <?php
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 article protection
36
37 function syslogArticleProtect(&$article, &$user, $protect, &$reason, &$moveonly) {
38 $title = $article->mTitle;
39 syslog(LOG_NOTICE, "User '" . $user->getName() . "' " .
40 (($protect) ? "protected" : "unprotected") . " article '" .
41 $title->getPrefixedText() .
42 "' for '" . $reason . "' " . (($moveonly) ? "(moves only)" : "") );
43 return true;
44 }
45
46 # Hook for article deletion
47
48 function syslogArticleDelete(&$article, &$user, &$reason) {
49 $title = $article->mTitle;
50 syslog(LOG_NOTICE, "User '" . $user->getName() . "' deleted '" .
51 $title->getPrefixedText() .
52 "' for '" . $reason . "' ");
53 return true;
54 }
55
56 # Hook for article save
57
58 function syslogArticleSave(&$article, &$user, &$text, $summary,
59 $isminor, $iswatch, $section)
60 {
61 $title = $article->mTitle;
62 syslog(LOG_NOTICE, "User '" . $user->getName() . "' saved '" .
63 $title->getPrefixedText() .
64 "' with comment '" . $summary . "' ");
65 return true;
66 }
67
68 # Hook for IP & user blocks
69
70 function syslogBlockIp(&$block, &$user) {
71 syslog(LOG_NOTICE, "User '" . $user->getName() .
72 "' blocked '" . (($block->mUser) ? $block->mUser : $block->mAddress) .
73 "' for '" . $block->mReason . "' until '" . $block->mExpiry . "'");
74 return true;
75 }
76
77 function syslogEmailUser(&$to, &$from, &$subject, &$text) {
78 syslog(LOG_INFO, "Email sent from '$from' to '$to' with subject '$subject'");
79 }
80
81 # Hook for unwatch
82
83 function syslogUnwatch(&$user, &$article) {
84 syslog(LOG_INFO, "User '" . $user->getName() . "' stopped watching '" .
85 $article->mTitle->getPrefixedText() . "'");
86 }
87
88 # Hook for login
89
90 function syslogUserLogin(&$user) {
91 syslog(LOG_INFO, "User '" . $user->getName() . "' logged in");
92 return true;
93 }
94
95 # Hook for logout
96
97 function syslogUserLogout(&$user) {
98 syslog(LOG_INFO, "User '" . $user->getName() . "' logged out");
99 return true;
100 }
101
102 # Hook for watch
103
104 function syslogWatch(&$user, &$article) {
105 syslog(LOG_INFO, "User '" . $user->getName() . "' started watching '" .
106 $article->mTitle->getPrefixedText() . "'");
107 }
108
109 # Setup -- called once environment is configured
110
111 function setupSyslog() {
112
113 global $wgSyslogIdentity, $wgSyslogFacility, $_syslogId;
114 global $wgHooks;
115
116 openlog($wgSyslogIdentity, LOG_ODELAY | LOG_PID, $wgSyslogFacility);
117
118 $wgHooks['UserLoginComplete'][] = 'syslogUserLogin';
119 $wgHooks['UserLogout'][] = 'syslogUserLogout';
120 $wgHooks['BlockIpComplete'][] = 'syslogBlockIp';
121 $wgHooks['ArticleProtectComplete'][] = 'syslogArticleProtect';
122 $wgHooks['ArticleDeleteComplete'][] = 'syslogArticleDelete';
123 $wgHooks['ArticleSaveComplete'][] = 'syslogArticleSave';
124 $wgHooks['EmailUserComplete'][] = 'syslogEmailUser';
125 $wgHooks['WatchArticleComplete'][] = 'syslogWatch';
126 $wgHooks['UnwatchArticleComplete'][] = 'syslogUnwatch';
127
128 return true;
129 }
130
131 # Add to global list of extensions
132
133 $wgExtensionFunctions[] = setupSyslog;
134 }
135
136 ?>