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
;
35 # Hook for article protection
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)" : "") );
46 # Hook for article deletion
48 function syslogArticleDelete(&$article, &$user, &$reason) {
49 $title = $article->mTitle
;
50 syslog(LOG_NOTICE
, "User '" . $user->getName() . "' deleted '" .
51 $title->getPrefixedText() .
52 "' for '" . $reason . "' ");
56 # Hook for article save
58 function syslogArticleSave(&$article, &$user, &$text, $summary,
59 $isminor, $iswatch, $section)
61 $title = $article->mTitle
;
62 syslog(LOG_NOTICE
, "User '" . $user->getName() . "' saved '" .
63 $title->getPrefixedText() .
64 "' with comment '" . $summary . "' ");
68 # Hook for IP & user blocks
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
. "'");
77 function syslogEmailUser(&$to, &$from, &$subject, &$text) {
78 syslog(LOG_INFO
, "Email sent from '$from' to '$to' with subject '$subject'");
83 function syslogUnwatch(&$user, &$article) {
84 syslog(LOG_INFO
, "User '" . $user->getName() . "' stopped watching '" .
85 $article->mTitle
->getPrefixedText() . "'");
90 function syslogUserLogin(&$user) {
91 syslog(LOG_INFO
, "User '" . $user->getName() . "' logged in");
97 function syslogUserLogout(&$user) {
98 syslog(LOG_INFO
, "User '" . $user->getName() . "' logged out");
104 function syslogWatch(&$user, &$article) {
105 syslog(LOG_INFO
, "User '" . $user->getName() . "' started watching '" .
106 $article->mTitle
->getPrefixedText() . "'");
109 # Setup -- called once environment is configured
111 function setupSyslog() {
113 global $wgSyslogIdentity, $wgSyslogFacility, $_syslogId;
116 openlog($wgSyslogIdentity, LOG_ODELAY | LOG_PID
, $wgSyslogFacility);
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';
131 # Add to global list of extensions
133 $wgExtensionFunctions[] = setupSyslog
;