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 &validTypes() {
70 static $types = array( '', 'block', 'protect', 'rights', 'delete', 'upload' );
74 /* static */ function isLogType( $type ) {
75 return in_array( $type, LogPage
::validTypes() );
78 /* static */ function logName( $type ) {
79 static $typeText = array(
81 'block' => 'blocklogpage',
82 'protect' => 'protectlogpage',
83 'rights' => 'bureaucratlog',
84 'delete' => 'dellogpage',
85 'upload' => 'uploadlogpage',
87 return str_replace( '_', ' ', wfMsg( $typeText[$type] ) );
90 /* static */ function logHeader( $type ) {
91 static $headerText = array(
93 'block' => 'blocklogtext',
94 'protect' => 'protectlogtext',
96 'delete' => 'dellogpagetext',
97 'upload' => 'uploadlogpagetext'
99 return wfMsg( $headerText[$type] );
102 /* static */ function actionText( $type, $action, $titleLink ) {
103 static $actions = array(
104 'block/block' => 'blocklogentry',
105 'block/unblock' => 'blocklogentry',
106 'protect/protect' => 'protectedarticle',
107 'protect/unprotect' => 'unprotectedarticle',
108 'rights/rights' => 'bureaucratlogentry',
109 'delete/delete' => 'deletedarticle',
110 'delete/restore' => 'undeletedarticle',
111 'upload/upload' => 'uploadedimage',
112 'upload/revert' => 'uploadedimage',
114 $key = "$type/$action";
115 if( isset( $actions[$key] ) ) {
116 return wfMsg( $actions[$key], $titleLink );
118 wfDebug( "LogPage::actionText - unknown action $key\n" );
119 return "$action $titleLink";
123 function addEntry( $action, &$target, $comment ) {
124 global $wgLang, $wgUser;
126 $this->action
= $action;
127 $this->target
=& $target;
128 $this->comment
= $comment;
129 $this->actionText
= LogPage
::actionText( $this->type
, $action,
130 $target->getPrefixedText() );
132 return $this->saveContent();