3 # Copyright (C) 2002, 2004 Brion Vibber <brion@pobox.com>
4 # http://www.mediawiki.org/
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 # http://www.gnu.org/copyleft/gpl.html
28 * Class to simplify the use of log pages.
29 * The logs are now kept in a table which is easier to manage and trim
30 * than ever-growing wiki pages.
35 /* private */ var $type, $action, $comment;
36 var $updateRecentChanges = true;
38 function LogPage( $type ) {
39 # Type is one of 'block', 'protect', 'rights', 'delete', 'upload'
43 function saveContent() {
44 if( wfReadOnly() ) return;
47 $fname = 'LogPage::saveContent';
49 $dbw =& wfGetDB( DB_MASTER
);
50 $uid = $wgUser->getID();
52 $this->timestamp
= $now = wfTimestampNow();
53 $dbw->insert( 'logging',
55 'log_type' => $this->type
,
56 'log_action' => $this->action
,
57 'log_timestamp' => $dbw->timestamp( $now ),
59 'log_namespace' => $this->target
->getNamespace(),
60 'log_title' => $this->target
->getDBkey(),
61 'log_comment' => $this->comment
65 # And update recentchanges
66 if ( $this->updateRecentChanges
) {
67 $rcComment = $this->actionText
;
68 if( '' != $this->comment
) {
69 $rcComment .= ': ' . $this->comment
;
71 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Log/' . $this->type
);
72 RecentChange
::notifyLog( $now, $titleObj, $wgUser, $rcComment );
80 function validTypes() {
81 static $types = array( '', 'block', 'protect', 'rights', 'delete', 'upload' );
88 function validActions( $type ) {
89 static $actions = array(
91 'block' => array( 'block', 'unblock' ),
92 'protect' => array( 'protect', 'unprotect' ),
93 'rights' => array( 'rights' ),
94 'delete' => array( 'delete', 'restore' ),
95 'upload' => array( 'upload' )
97 return $actions[$type];
103 function isLogType( $type ) {
104 return in_array( $type, LogPage
::validTypes() );
110 function logName( $type ) {
111 static $typeText = array(
113 'block' => 'blocklogpage',
114 'protect' => 'protectlogpage',
115 'rights' => 'bureaucratlog',
116 'delete' => 'dellogpage',
117 'upload' => 'uploadlogpage',
119 return str_replace( '_', ' ', wfMsg( $typeText[$type] ) );
125 function logHeader( $type ) {
126 static $headerText = array(
128 'block' => 'blocklogtext',
129 'protect' => 'protectlogtext',
131 'delete' => 'dellogpagetext',
132 'upload' => 'uploadlogpagetext'
134 return wfMsg( $headerText[$type] );
140 function actionText( $type, $action, $titleLink = NULL ) {
141 static $actions = array(
142 'block/block' => 'blocklogentry',
143 'block/unblock' => 'unblocklogentry',
144 'protect/protect' => 'protectedarticle',
145 'protect/unprotect' => 'unprotectedarticle',
146 'rights/rights' => 'bureaucratlogentry',
147 'delete/delete' => 'deletedarticle',
148 'delete/restore' => 'undeletedarticle',
149 'upload/upload' => 'uploadedimage',
150 'upload/revert' => 'uploadedimage',
152 $key = "$type/$action";
153 if( isset( $actions[$key] ) ) {
154 if( is_null( $titleLink ) ) {
155 return wfMsg( $actions[$key] );
157 return wfMsg( $actions[$key], $titleLink );
160 wfDebug( "LogPage::actionText - unknown action $key\n" );
161 return "$action $titleLink";
167 * @param string $action one of 'block', 'protect', 'rights', 'delete', 'upload'
169 * @param string $comment Description associated
171 function addEntry( $action, &$target, $comment ) {
172 global $wgLang, $wgUser;
174 $this->action
= $action;
175 $this->target
=& $target;
176 $this->comment
= $comment;
177 $this->actionText
= LogPage
::actionText( $this->type
, $action,
178 $target->getPrefixedText() );
180 return $this->saveContent();