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, $params;
36 var $updateRecentChanges = true;
38 function LogPage( $type ) {
39 # Type is one of 'block', 'protect', 'rights', 'delete', 'upload', 'move'
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
,
62 'log_params' => $this->params
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', 'move' );
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' ),
97 'move' => array( 'move' )
99 return $actions[$type];
105 function isLogType( $type ) {
106 return in_array( $type, LogPage
::validTypes() );
112 function logName( $type ) {
113 static $typeText = array(
115 'block' => 'blocklogpage',
116 'protect' => 'protectlogpage',
117 'rights' => 'bureaucratlog',
118 'delete' => 'dellogpage',
119 'upload' => 'uploadlogpage',
120 'move' => 'movelogpage'
122 return str_replace( '_', ' ', wfMsg( $typeText[$type] ) );
128 function logHeader( $type ) {
129 static $headerText = array(
131 'block' => 'blocklogtext',
132 'protect' => 'protectlogtext',
133 'rights' => 'rightslogtext',
134 'delete' => 'dellogpagetext',
135 'upload' => 'uploadlogpagetext',
136 'move' => 'movelogpagetext'
138 return wfMsg( $headerText[$type] );
144 function actionText( $type, $action, $titleLink = NULL, $params = array() ) {
145 static $actions = array(
146 'block/block' => 'blocklogentry',
147 'block/unblock' => 'unblocklogentry',
148 'protect/protect' => 'protectedarticle',
149 'protect/unprotect' => 'unprotectedarticle',
150 'rights/rights' => 'bureaucratlogentry',
151 'delete/delete' => 'deletedarticle',
152 'delete/restore' => 'undeletedarticle',
153 'upload/upload' => 'uploadedimage',
154 'upload/revert' => 'uploadedimage',
155 'move/move' => '1movedto2',
156 'move/move_redir' => '1movedto2_redir'
158 $key = "$type/$action";
159 if( isset( $actions[$key] ) ) {
160 if( is_null( $titleLink ) ) {
161 return wfMsgForContent( $actions[$key] );
162 } elseif ( count( $params ) == 0 ) {
163 return wfMsgForContent( $actions[$key], $titleLink );
165 array_unshift( $params, $titleLink );
166 return wfMsgReal( $actions[$key], $params, true, true );
169 wfDebug( "LogPage::actionText - unknown action $key\n" );
170 return "$action $titleLink";
176 * @param string $action one of 'block', 'protect', 'rights', 'delete', 'upload'
177 * @param object &$target A title object.
178 * @param string $comment Description associated
179 * @param array $params Parameters passed later to wfMsg.* functions
181 function addEntry( $action, &$target, $comment, $params = array() ) {
182 global $wgLang, $wgUser;
184 if ( !is_array( $params ) ) {
185 $params = array( $params );
188 $this->action
= $action;
189 $this->target
=& $target;
190 $this->comment
= $comment;
191 $this->params
= LogPage
::makeParamBlob( $params );
193 $this->actionText
= LogPage
::actionText( $this->type
, $action,
194 $target->getPrefixedText(), $params );
195 return $this->saveContent();
199 * Create a blob from a parameter array
202 function makeParamBlob( $params )
204 return implode( "\n", $params );
208 * Extract a parameter array from a blob
211 function extractParams( $blob )
213 if ( $blob === '' ) {
216 return explode( "\n", $blob );