4 # Copyright (C) 2002, 2004 Brion Vibber <brion@pobox.com>
5 # http://www.mediawiki.org/
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 # http://www.gnu.org/copyleft/gpl.html
22 # Class to simplify the use of log pages.
23 # The logs are now kept in a table which is easier to manage and trim
24 # than ever-growing wiki pages.
27 /* private */ var $type, $action, $comment;
28 var $updateRecentChanges = true;
30 function LogPage( $type ) {
31 # Type is one of 'block', 'protect', 'rights', 'delete', 'upload'
35 function saveContent() {
36 if( wfReadOnly() ) return;
39 $fname = 'LogPage::saveContent';
41 $dbw =& wfGetDB( DB_MASTER
);
42 $uid = $wgUser->getID();
44 $this->timestamp
= $now = wfTimestampNow();
45 $dbw->insertArray( 'logging',
47 'log_type' => $this->type
,
48 'log_action' => $this->action
,
49 'log_timestamp' => $dbw->timestamp( $now ),
51 'log_namespace' => $this->target
->getNamespace(),
52 'log_title' => $this->target
->getDBkey(),
53 'log_comment' => $this->comment
57 # And update recentchanges
58 if ( $this->updateRecentChanges
) {
59 $rcComment = $this->actionText
;
60 if( '' != $this->comment
) {
61 $rcComment .= ': ' . $this->comment
;
63 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Log/' . $this->type
);
64 RecentChange
::notifyLog( $now, $titleObj, $wgUser, $rcComment );
69 /* static */ function actionText( $type, $action, $titleLink ) {
70 static $actions = array(
71 'block/block' => 'blocklogentry',
72 'block/unblock' => 'blocklogentry',
73 'protect/protect' => 'protectedarticle',
74 'protect/unprotect' => 'unprotectedarticle',
75 'rights/rights' => 'bureaucratlogentry',
76 'delete/delete' => 'deletedarticle',
77 'delete/restore' => 'undeletedarticle',
78 'upload/upload' => 'uploadedimage',
79 'upload/revert' => 'uploadedimage',
81 $key = "$type/$action";
82 if( isset( $actions[$key] ) ) {
83 return wfMsg( $actions[$key], $titleLink );
85 wfDebug( "LogPage::actionText - unknown action $key\n" );
86 return "$action $titleLink";
90 function addEntry( $action, &$target, $comment ) {
91 global $wgLang, $wgUser;
93 $this->action
= $action;
94 $this->target
=& $target;
95 $this->comment
= $comment;
96 $this->actionText
= LogPage
::actionText( $this->type
, $action,
97 $target->getPrefixedText() );
99 return $this->saveContent();