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;
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 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Log/' . $this->type
);
69 $rcComment = $this->actionText
;
70 if( '' != $this->comment
) {
71 $rcComment .= ': ' . $this->comment
;
74 RecentChange
::notifyLog( $now, $titleObj, $wgUser, $rcComment );
82 function validTypes() {
83 static $types = array( '', 'block', 'protect', 'rights', 'delete', 'upload', 'move' );
90 function validActions( $type ) {
91 static $actions = array(
93 'block' => array( 'block', 'unblock' ),
94 'protect' => array( 'protect', 'unprotect' ),
95 'rights' => array( 'rights' ),
96 'delete' => array( 'delete', 'restore' ),
97 'upload' => array( 'upload' ),
98 'move' => array( 'move' )
100 return $actions[$type];
106 function isLogType( $type ) {
107 return in_array( $type, LogPage
::validTypes() );
113 function logName( $type ) {
114 static $typeText = array(
116 'block' => 'blocklogpage',
117 'protect' => 'protectlogpage',
118 'rights' => 'bureaucratlog',
119 'delete' => 'dellogpage',
120 'upload' => 'uploadlogpage',
121 'move' => 'movelogpage'
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 return wfMsg( $headerText[$type] );
145 function actionText( $type, $action, $title = NULL, $skin = NULL, $params = array(), $filterWikilinks=false ) {
146 static $actions = array(
147 'block/block' => 'blocklogentry',
148 'block/unblock' => 'unblocklogentry',
149 'protect/protect' => 'protectedarticle',
150 'protect/unprotect' => 'unprotectedarticle',
151 'rights/rights' => 'bureaucratlogentry',
152 'rights/addgroup' => 'addgrouplogentry',
153 'rights/rngroup' => 'renamegrouplogentry',
154 'rights/chgroup' => 'changegrouplogentry',
155 'delete/delete' => 'deletedarticle',
156 'delete/restore' => 'undeletedarticle',
157 'upload/upload' => 'uploadedimage',
158 'upload/revert' => 'uploadedimage',
159 'move/move' => '1movedto2',
160 'move/move_redir' => '1movedto2_redir'
162 $key = "$type/$action";
163 if( isset( $actions[$key] ) ) {
164 if( is_null( $title ) ) {
165 $rv=wfMsgForContent( $actions[$key] );
168 if ( $type == 'move' ) {
169 $titleLink = $skin->makeLinkObj( $title, $title->getPrefixedText(), 'redirect=no' );
170 // Change $param[0] into a link to the title specified in $param[0]
171 $movedTo = Title
::newFromText( $params[0] );
172 $params[0] = $skin->makeLinkObj( $movedTo, $params[0] );
174 $titleLink = $skin->makeLinkObj( $title );
177 $titleLink = $title->getPrefixedText();
179 if( count( $params ) == 0 ) {
180 $rv = wfMsgForContent( $actions[$key], $titleLink );
182 array_unshift( $params, $titleLink );
183 $rv = wfMsgReal( $actions[$key], $params, true, true );
187 wfDebug( "LogPage::actionText - unknown action $key\n" );
188 $rv = "$action $titleLink";
190 if( $filterWikilinks ) {
191 $rv = str_replace( "[[", "", $rv );
192 $rv = str_replace( "]]", "", $rv );
199 * @param string $action one of 'block', 'protect', 'rights', 'delete', 'upload', 'move', 'move_redir'
200 * @param object &$target A title object.
201 * @param string $comment Description associated
202 * @param array $params Parameters passed later to wfMsg.* functions
204 function addEntry( $action, &$target, $comment, $params = array() ) {
205 if ( !is_array( $params ) ) {
206 $params = array( $params );
209 $this->action
= $action;
210 $this->target
=& $target;
211 $this->comment
= $comment;
212 $this->params
= LogPage
::makeParamBlob( $params );
214 $this->actionText
= LogPage
::actionText( $this->type
, $action,
215 $target, NULL, $params );
217 return $this->saveContent();
221 * Create a blob from a parameter array
224 function makeParamBlob( $params ) {
225 return implode( "\n", $params );
229 * Extract a parameter array from a blob
232 function extractParams( $blob ) {
233 if ( $blob === '' ) {
236 return explode( "\n", $blob );