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, $target;
36 var $updateRecentChanges = true;
41 * @param string $type One of 'block', 'protect', 'rights', 'delete',
44 function LogPage( $type ) {
48 function saveContent() {
49 if( wfReadOnly() ) return;
52 $fname = 'LogPage::saveContent';
54 $dbw =& wfGetDB( DB_MASTER
);
55 $uid = $wgUser->getID();
57 $this->timestamp
= $now = wfTimestampNow();
58 $dbw->insert( 'logging',
60 'log_type' => $this->type
,
61 'log_action' => $this->action
,
62 'log_timestamp' => $dbw->timestamp( $now ),
64 'log_namespace' => $this->target
->getNamespace(),
65 'log_title' => $this->target
->getDBkey(),
66 'log_comment' => $this->comment
,
67 'log_params' => $this->params
71 # And update recentchanges
72 if ( $this->updateRecentChanges
) {
73 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Log/' . $this->type
);
74 $rcComment = $this->actionText
;
75 if( '' != $this->comment
) {
76 $rcComment .= ': ' . $this->comment
;
79 RecentChange
::notifyLog( $now, $titleObj, $wgUser, $rcComment );
87 function validTypes() {
88 static $types = array( '', 'block', 'protect', 'rights', 'delete', 'upload', 'move' );
95 function validActions( $type ) {
96 static $actions = array(
98 'block' => array( 'block', 'unblock' ),
99 'protect' => array( 'protect', 'unprotect' ),
100 'rights' => array( 'rights' ),
101 'delete' => array( 'delete', 'restore' ),
102 'upload' => array( 'upload' ),
103 'move' => array( 'move' )
105 return $actions[$type];
111 function isLogType( $type ) {
112 return in_array( $type, LogPage
::validTypes() );
118 function logName( $type ) {
119 static $typeText = array(
121 'block' => 'blocklogpage',
122 'protect' => 'protectlogpage',
123 'rights' => 'bureaucratlog',
124 'delete' => 'dellogpage',
125 'upload' => 'uploadlogpage',
126 'move' => 'movelogpage'
128 return str_replace( '_', ' ', wfMsg( $typeText[$type] ) );
134 function logHeader( $type ) {
135 static $headerText = array(
137 'block' => 'blocklogtext',
138 'protect' => 'protectlogtext',
139 'rights' => 'rightslogtext',
140 'delete' => 'dellogpagetext',
141 'upload' => 'uploadlogpagetext',
142 'move' => 'movelogpagetext'
144 return wfMsg( $headerText[$type] );
150 function actionText( $type, $action, $title = NULL, $skin = NULL, $params = array(), $filterWikilinks=false ) {
151 static $actions = array(
152 'block/block' => 'blocklogentry',
153 'block/unblock' => 'unblocklogentry',
154 'protect/protect' => 'protectedarticle',
155 'protect/unprotect' => 'unprotectedarticle',
156 'rights/rights' => 'bureaucratlogentry',
157 'rights/addgroup' => 'addgrouplogentry',
158 'rights/rngroup' => 'renamegrouplogentry',
159 'rights/chgroup' => 'changegrouplogentry',
160 'delete/delete' => 'deletedarticle',
161 'delete/restore' => 'undeletedarticle',
162 'upload/upload' => 'uploadedimage',
163 'upload/revert' => 'uploadedimage',
164 'move/move' => '1movedto2',
165 'move/move_redir' => '1movedto2_redir'
167 $key = "$type/$action";
168 if( isset( $actions[$key] ) ) {
169 if( is_null( $title ) ) {
170 $rv=wfMsgForContent( $actions[$key] );
173 if ( $type == 'move' ) {
174 $titleLink = $skin->makeLinkObj( $title, $title->getPrefixedText(), 'redirect=no' );
175 // Change $param[0] into a link to the title specified in $param[0]
176 $movedTo = Title
::newFromText( $params[0] );
177 $params[0] = $skin->makeLinkObj( $movedTo, $params[0] );
179 $titleLink = $skin->makeLinkObj( $title );
182 $titleLink = $title->getPrefixedText();
184 if( count( $params ) == 0 ) {
185 $rv = wfMsgForContent( $actions[$key], $titleLink );
187 array_unshift( $params, $titleLink );
188 $rv = wfMsgReal( $actions[$key], $params, true, true );
192 wfDebug( "LogPage::actionText - unknown action $key\n" );
195 if( $filterWikilinks ) {
196 $rv = str_replace( "[[", "", $rv );
197 $rv = str_replace( "]]", "", $rv );
204 * @param string $action one of 'block', 'protect', 'rights', 'delete', 'upload', 'move', 'move_redir'
205 * @param object &$target A title object.
206 * @param string $comment Description associated
207 * @param array $params Parameters passed later to wfMsg.* functions
209 function addEntry( $action, &$target, $comment, $params = array() ) {
210 if ( !is_array( $params ) ) {
211 $params = array( $params );
214 $this->action
= $action;
215 $this->target
=& $target;
216 $this->comment
= $comment;
217 $this->params
= LogPage
::makeParamBlob( $params );
219 $this->actionText
= LogPage
::actionText( $this->type
, $action, $target, NULL, $params );
221 return $this->saveContent();
225 * Create a blob from a parameter array
228 function makeParamBlob( $params ) {
229 return implode( "\n", $params );
233 * Extract a parameter array from a blob
236 function extractParams( $blob ) {
237 if ( $blob === '' ) {
240 return explode( "\n", $blob );