c2f0d6ad5560b7c58d3890483ff9d64a8cc4ad92
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
27 * Class to simplify the use of log pages.
28 * The logs are now kept in a table which is easier to manage and trim
29 * than ever-growing wiki pages.
32 /* private */ var $type, $action, $comment;
33 var $updateRecentChanges = true;
35 function LogPage( $type ) {
36 # Type is one of 'block', 'protect', 'rights', 'delete', 'upload'
40 function saveContent() {
41 if( wfReadOnly() ) return;
44 $fname = 'LogPage::saveContent';
46 $dbw =& wfGetDB( DB_MASTER
);
47 $uid = $wgUser->getID();
49 $this->timestamp
= $now = wfTimestampNow();
50 $dbw->insertArray( 'logging',
52 'log_type' => $this->type
,
53 'log_action' => $this->action
,
54 'log_timestamp' => $dbw->timestamp( $now ),
56 'log_namespace' => $this->target
->getNamespace(),
57 'log_title' => $this->target
->getDBkey(),
58 'log_comment' => $this->comment
62 # And update recentchanges
63 if ( $this->updateRecentChanges
) {
64 $rcComment = $this->actionText
;
65 if( '' != $this->comment
) {
66 $rcComment .= ': ' . $this->comment
;
68 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Log/' . $this->type
);
69 RecentChange
::notifyLog( $now, $titleObj, $wgUser, $rcComment );
77 function validTypes() {
78 static $types = array( '', 'block', 'protect', 'rights', 'delete', 'upload' );
85 function validActions( $type ) {
86 static $actions = array(
88 'block' => array( 'block', 'unblock' ),
89 'protect' => array( 'protect', 'unprotect' ),
90 'rights' => array( 'rights' ),
91 'delete' => array( 'delete', 'restore' ),
92 'upload' => array( 'upload' )
94 return $actions[$type];
100 function isLogType( $type ) {
101 return in_array( $type, LogPage
::validTypes() );
107 function logName( $type ) {
108 static $typeText = array(
110 'block' => 'blocklogpage',
111 'protect' => 'protectlogpage',
112 'rights' => 'bureaucratlog',
113 'delete' => 'dellogpage',
114 'upload' => 'uploadlogpage',
116 return str_replace( '_', ' ', wfMsg( $typeText[$type] ) );
122 function logHeader( $type ) {
123 static $headerText = array(
125 'block' => 'blocklogtext',
126 'protect' => 'protectlogtext',
128 'delete' => 'dellogpagetext',
129 'upload' => 'uploadlogpagetext'
131 return wfMsg( $headerText[$type] );
137 function actionText( $type, $action, $titleLink = NULL ) {
138 static $actions = array(
139 'block/block' => 'blocklogentry',
140 'block/unblock' => 'blocklogentry',
141 'protect/protect' => 'protectedarticle',
142 'protect/unprotect' => 'unprotectedarticle',
143 'rights/rights' => 'bureaucratlogentry',
144 'delete/delete' => 'deletedarticle',
145 'delete/restore' => 'undeletedarticle',
146 'upload/upload' => 'uploadedimage',
147 'upload/revert' => 'uploadedimage',
149 $key = "$type/$action";
150 if( isset( $actions[$key] ) ) {
151 if( is_null( $titleLink ) ) {
152 return wfMsg( $actions[$key] );
154 return wfMsg( $actions[$key], $titleLink );
157 wfDebug( "LogPage::actionText - unknown action $key\n" );
158 return "$action $titleLink";
162 function addEntry( $action, &$target, $comment ) {
163 global $wgLang, $wgUser;
165 $this->action
= $action;
166 $this->target
=& $target;
167 $this->comment
= $comment;
168 $this->actionText
= LogPage
::actionText( $this->type
, $action,
169 $target->getPrefixedText() );
171 return $this->saveContent();