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
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.
36 /* private */ var $type, $action, $comment;
37 var $updateRecentChanges = true;
39 function LogPage( $type ) {
40 # Type is one of 'block', 'protect', 'rights', 'delete', 'upload'
44 function saveContent() {
45 if( wfReadOnly() ) return;
48 $fname = 'LogPage::saveContent';
50 $dbw =& wfGetDB( DB_MASTER
);
51 $uid = $wgUser->getID();
53 $this->timestamp
= $now = wfTimestampNow();
54 $dbw->insertArray( 'logging',
56 'log_type' => $this->type
,
57 'log_action' => $this->action
,
58 'log_timestamp' => $dbw->timestamp( $now ),
60 'log_namespace' => $this->target
->getNamespace(),
61 'log_title' => $this->target
->getDBkey(),
62 'log_comment' => $this->comment
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 );
81 function validTypes() {
82 static $types = array( '', 'block', 'protect', 'rights', 'delete', 'upload' );
89 function validActions( $type ) {
90 static $actions = array(
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];
104 function isLogType( $type ) {
105 return in_array( $type, LogPage
::validTypes() );
111 function logName( $type ) {
112 static $typeText = array(
114 'block' => 'blocklogpage',
115 'protect' => 'protectlogpage',
116 'rights' => 'bureaucratlog',
117 'delete' => 'dellogpage',
118 'upload' => 'uploadlogpage',
120 return str_replace( '_', ' ', wfMsg( $typeText[$type] ) );
126 function logHeader( $type ) {
127 static $headerText = array(
129 'block' => 'blocklogtext',
130 'protect' => 'protectlogtext',
132 'delete' => 'dellogpagetext',
133 'upload' => 'uploadlogpagetext'
135 return wfMsg( $headerText[$type] );
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] );
158 return wfMsg( $actions[$key], $titleLink );
161 wfDebug( "LogPage::actionText - unknown action $key\n" );
162 return "$action $titleLink";
166 function addEntry( $action, &$target, $comment ) {
167 global $wgLang, $wgUser;
169 $this->action
= $action;
170 $this->target
=& $target;
171 $this->comment
= $comment;
172 $this->actionText
= LogPage
::actionText( $this->type
, $action,
173 $target->getPrefixedText() );
175 return $this->saveContent();