Add event hooks for article save. Documented in hooks.doc, and example
[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 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 # Hook for IP & user blocks
50
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 . "'");
55 return true;
56 }
57
58 # Hook for article protection
59
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)" : "") );
66 return true;
67 }
68
69 # Hook for article deletion
70
71 function syslogArticleDelete(&$article, &$user, &$reason) {
72 $title = $article->mTitle;
73 syslog(LOG_NOTICE, "User '" . $user->getName() . "' deleted '" .
74 $title->getPrefixedText() .
75 "' for '" . $reason . "' ");
76 return true;
77 }
78
79 # Hook for article save
80
81 function syslogArticleSave(&$article, &$user, &$text, $summary, $isminor, $iswatch, $section) {
82 $title = $article->mTitle;
83 syslog(LOG_NOTICE, "User '" . $user->getName() . "' saved '" .
84 $title->getPrefixedText() .
85 "' with comment '" . $summary . "' ");
86 return true;
87 }
88
89 # Setup -- called once environment is configured
90
91 function setupSyslog() {
92
93 global $wgSyslogIdentity, $wgSyslogFacility, $_syslogId;
94 global $wgHooks;
95
96 openlog($wgSyslogIdentity, LOG_ODELAY | LOG_PID, $wgSyslogFacility);
97
98 $wgHooks['UserLoginComplete'][] = 'syslogUserLogin';
99 $wgHooks['UserLogout'][] = 'syslogUserLogout';
100 $wgHooks['BlockIpComplete'][] = 'syslogBlockIp';
101 $wgHooks['ArticleProtectComplete'][] = 'syslogArticleProtect';
102 $wgHooks['ArticleDeleteComplete'][] = 'syslogArticleDelete';
103 $wgHooks['ArticleSaveComplete'][] = 'syslogArticleSave';
104
105 return true;
106 }
107
108 # Add to global list of extensions
109
110 $wgExtensionFunctions[] = setupSyslog;
111 }
112
113 ?>