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.
36 var $type, $action, $comment, $params, $target;
38 var $updateRecentChanges;
43 * @param string $type One of '', 'block', 'protect', 'rights', 'delete',
45 * @param bool $rc Whether to update recent changes as well as the logging table
47 function LogPage( $type, $rc = true ) {
49 $this->updateRecentChanges
= $rc;
52 function saveContent() {
53 if( wfReadOnly() ) return;
56 $fname = 'LogPage::saveContent';
58 $dbw =& wfGetDB( DB_MASTER
);
59 $uid = $wgUser->getID();
61 $this->timestamp
= $now = wfTimestampNow();
62 $dbw->insert( 'logging',
64 'log_type' => $this->type
,
65 'log_action' => $this->action
,
66 'log_timestamp' => $dbw->timestamp( $now ),
68 'log_namespace' => $this->target
->getNamespace(),
69 'log_title' => $this->target
->getDBkey(),
70 'log_comment' => $this->comment
,
71 'log_params' => $this->params
75 # And update recentchanges
76 if ( $this->updateRecentChanges
) {
77 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Log/' . $this->type
);
78 $rcComment = $this->actionText
;
79 if( '' != $this->comment
) {
81 $rcComment = $this->comment
;
83 $rcComment .= ': ' . $this->comment
;
86 require_once( 'RecentChange.php' );
87 RecentChange
::notifyLog( $now, $titleObj, $wgUser, $rcComment );
95 function validTypes() {
96 static $types = array( '', 'block', 'protect', 'rights', 'delete', 'upload', 'move' );
97 wfRunHooks( 'LogPageValidTypes', array( &$types ) );
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',
119 'move' => 'movelogpage'
121 wfRunHooks( 'LogPageLogName', array( &$typeText ) );
123 return str_replace( '_', ' ', wfMsg( $typeText[$type] ) );
129 function logHeader( $type ) {
130 static $headerText = array(
132 'block' => 'blocklogtext',
133 'protect' => 'protectlogtext',
134 'rights' => 'rightslogtext',
135 'delete' => 'dellogpagetext',
136 'upload' => 'uploadlogpagetext',
137 'move' => 'movelogpagetext'
139 wfRunHooks( 'LogPageLogHeader', array( &$headerText ) );
141 return wfMsg( $headerText[$type] );
147 function actionText( $type, $action, $title = NULL, $skin = NULL, $params = array(), $filterWikilinks=false, $translate=false ) {
149 static $actions = array(
150 'block/block' => 'blocklogentry',
151 'block/unblock' => 'unblocklogentry',
152 'protect/protect' => 'protectedarticle',
153 'protect/unprotect' => 'unprotectedarticle',
155 // TODO: This whole section should be moved to extensions/Makesysop/SpecialMakesysop.php
156 'rights/rights' => 'bureaucratlogentry',
157 'rights/addgroup' => 'addgrouplogentry',
158 'rights/rngroup' => 'renamegrouplogentry',
159 'rights/chgroup' => 'changegrouplogentry',
161 'delete/delete' => 'deletedarticle',
162 'delete/restore' => 'undeletedarticle',
163 'upload/upload' => 'uploadedimage',
164 'upload/revert' => 'uploadedimage',
165 'move/move' => '1movedto2',
166 'move/move_redir' => '1movedto2_redir'
168 wfRunHooks( 'LogPageActionText', array( &$actions ) );
170 $key = "$type/$action";
171 if( isset( $actions[$key] ) ) {
172 if( is_null( $title ) ) {
173 $rv=wfMsg( $actions[$key] );
176 if ( $type == 'move' ) {
177 $titleLink = $skin->makeLinkObj( $title, $title->getPrefixedText(), 'redirect=no' );
178 // Change $param[0] into a link to the title specified in $param[0]
179 $movedTo = Title
::newFromText( $params[0] );
180 $params[0] = $skin->makeLinkObj( $movedTo, $params[0] );
182 # Bug 4359: red [[user:#id]] links generated in [[special:Log]]
183 # If it's an autoblock, don't do a link
184 if( $type == 'block' ) {
185 $titletext = $title->getText();
186 $titleLink = ( ( substr( $titletext, 0, 1 ) == '#' ) ?
$titletext : $skin->makeLinkObj( $title ) );
188 $titleLink = $skin->makeLinkObj( $title );
192 $titleLink = $title->getPrefixedText();
194 if( count( $params ) == 0 ) {
195 $rv = wfMsg( $actions[$key], $titleLink );
197 array_unshift( $params, $titleLink );
198 if ( $translate && $key == 'block/block' ) {
199 $params[1] = $wgLang->translateBlockExpiry($params[1]);
201 $rv = wfMsgReal( $actions[$key], $params, true, false ); // FIXME: use wfMsgForContent() ?
205 wfDebug( "LogPage::actionText - unknown action $key\n" );
208 if( $filterWikilinks ) {
209 $rv = str_replace( "[[", "", $rv );
210 $rv = str_replace( "]]", "", $rv );
217 * @param string $action one of '', 'block', 'protect', 'rights', 'delete', 'upload', 'move', 'move_redir'
218 * @param object &$target A title object.
219 * @param string $comment Description associated
220 * @param array $params Parameters passed later to wfMsg.* functions
222 function addEntry( $action, &$target, $comment, $params = array() ) {
223 if ( !is_array( $params ) ) {
224 $params = array( $params );
227 $this->action
= $action;
228 $this->target
=& $target;
229 $this->comment
= $comment;
230 $this->params
= LogPage
::makeParamBlob( $params );
232 $this->actionText
= LogPage
::actionText( $this->type
, $action, $target, NULL, $params );
234 return $this->saveContent();
238 * Create a blob from a parameter array
241 function makeParamBlob( $params ) {
242 return implode( "\n", $params );
246 * Extract a parameter array from a blob
249 function extractParams( $blob ) {
250 if ( $blob === '' ) {
253 return explode( "\n", $blob );