RC patrol fixlet: include rcid in 'diff' link in enhanced mode, for individually...
[mediawiki.git] / includes / LogPage.php
blob68b73b2dcbd63a04d7685bd625d149ed6ad11374
1 <?php
2 #$Id$
4 # Copyright (C) 2002, 2004 Brion Vibber <brion@pobox.com>
5 # http://www.mediawiki.org/
6 #
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 /**
23 * Contain log classes
25 * @package MediaWiki
28 /**
29 * Class to simplify the use of log pages.
30 * The logs are now kept in a table which is easier to manage and trim
31 * than ever-growing wiki pages.
33 * @package MediaWiki
35 class LogPage {
36 /* private */ var $type, $action, $comment;
37 var $updateRecentChanges = true;
39 function LogPage( $type ) {
40 # Type is one of 'block', 'protect', 'rights', 'delete', 'upload'
41 $this->type = $type;
44 function saveContent() {
45 if( wfReadOnly() ) return;
47 global $wgUser;
48 $fname = 'LogPage::saveContent';
50 $dbw =& wfGetDB( DB_MASTER );
51 $uid = $wgUser->getID();
53 $this->timestamp = $now = wfTimestampNow();
54 $dbw->insert( 'logging',
55 array(
56 'log_type' => $this->type,
57 'log_action' => $this->action,
58 'log_timestamp' => $dbw->timestamp( $now ),
59 'log_user' => $uid,
60 'log_namespace' => $this->target->getNamespace(),
61 'log_title' => $this->target->getDBkey(),
62 'log_comment' => $this->comment
63 ), $fname
66 # And update recentchanges
67 if ( $this->updateRecentChanges ) {
68 $rcComment = $this->actionText;
69 if( '' != $this->comment ) {
70 $rcComment .= ': ' . $this->comment;
72 $titleObj = Title::makeTitle( NS_SPECIAL, 'Log/' . $this->type );
73 RecentChange::notifyLog( $now, $titleObj, $wgUser, $rcComment );
75 return true;
78 /**
79 * @static
81 function validTypes() {
82 static $types = array( '', 'block', 'protect', 'rights', 'delete', 'upload' );
83 return $types;
86 /**
87 * @static
89 function validActions( $type ) {
90 static $actions = array(
91 '' => NULL,
92 'block' => array( 'block', 'unblock' ),
93 'protect' => array( 'protect', 'unprotect' ),
94 'rights' => array( 'rights' ),
95 'delete' => array( 'delete', 'restore' ),
96 'upload' => array( 'upload' )
98 return $actions[$type];
102 * @static
104 function isLogType( $type ) {
105 return in_array( $type, LogPage::validTypes() );
109 * @static
111 function logName( $type ) {
112 static $typeText = array(
113 '' => 'log',
114 'block' => 'blocklogpage',
115 'protect' => 'protectlogpage',
116 'rights' => 'bureaucratlog',
117 'delete' => 'dellogpage',
118 'upload' => 'uploadlogpage',
120 return str_replace( '_', ' ', wfMsg( $typeText[$type] ) );
124 * @static
126 function logHeader( $type ) {
127 static $headerText = array(
128 '' => 'alllogstext',
129 'block' => 'blocklogtext',
130 'protect' => 'protectlogtext',
131 'rights' => '',
132 'delete' => 'dellogpagetext',
133 'upload' => 'uploadlogpagetext'
135 return wfMsg( $headerText[$type] );
139 * @static
141 function actionText( $type, $action, $titleLink = NULL ) {
142 static $actions = array(
143 'block/block' => 'blocklogentry',
144 'block/unblock' => 'blocklogentry',
145 'protect/protect' => 'protectedarticle',
146 'protect/unprotect' => 'unprotectedarticle',
147 'rights/rights' => 'bureaucratlogentry',
148 'delete/delete' => 'deletedarticle',
149 'delete/restore' => 'undeletedarticle',
150 'upload/upload' => 'uploadedimage',
151 'upload/revert' => 'uploadedimage',
153 $key = "$type/$action";
154 if( isset( $actions[$key] ) ) {
155 if( is_null( $titleLink ) ) {
156 return wfMsg( $actions[$key] );
157 } else {
158 return wfMsg( $actions[$key], $titleLink );
160 } else {
161 wfDebug( "LogPage::actionText - unknown action $key\n" );
162 return "$action $titleLink";
167 * Add a log entry
168 * @param string $action one of 'block', 'protect', 'rights', 'delete', 'upload'
169 * @param &$target
170 * @param string $comment Description associated
172 function addEntry( $action, &$target, $comment ) {
173 global $wgLang, $wgUser;
175 $this->action = $action;
176 $this->target =& $target;
177 $this->comment = $comment;
178 $this->actionText = LogPage::actionText( $this->type, $action,
179 $target->getPrefixedText() );
181 return $this->saveContent();