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
) {
77 $rcComment = $this->comment
;
79 $rcComment .= ': ' . $this->comment
;
82 RecentChange
::notifyLog( $now, $titleObj, $wgUser, $rcComment );
90 function validTypes() {
91 static $types = array( '', 'block', 'protect', 'rights', 'delete', 'upload', 'move' );
98 function validActions( $type ) {
99 static $actions = array(
101 'block' => array( 'block', 'unblock' ),
102 'protect' => array( 'protect', 'unprotect' ),
103 'rights' => array( 'rights' ),
104 'delete' => array( 'delete', 'restore' ),
105 'upload' => array( 'upload' ),
106 'move' => array( 'move' )
108 return $actions[$type];
114 function isLogType( $type ) {
115 return in_array( $type, LogPage
::validTypes() );
121 function logName( $type ) {
122 static $typeText = array(
124 'block' => 'blocklogpage',
125 'protect' => 'protectlogpage',
126 'rights' => 'bureaucratlog',
127 'delete' => 'dellogpage',
128 'upload' => 'uploadlogpage',
129 'move' => 'movelogpage'
131 return str_replace( '_', ' ', wfMsg( $typeText[$type] ) );
137 function logHeader( $type ) {
138 static $headerText = array(
140 'block' => 'blocklogtext',
141 'protect' => 'protectlogtext',
142 'rights' => 'rightslogtext',
143 'delete' => 'dellogpagetext',
144 'upload' => 'uploadlogpagetext',
145 'move' => 'movelogpagetext'
147 return wfMsg( $headerText[$type] );
153 function actionText( $type, $action, $title = NULL, $skin = NULL, $params = array(), $filterWikilinks=false ) {
154 static $actions = array(
155 'block/block' => 'blocklogentry',
156 'block/unblock' => 'unblocklogentry',
157 'protect/protect' => 'protectedarticle',
158 'protect/unprotect' => 'unprotectedarticle',
159 'rights/rights' => 'bureaucratlogentry',
160 'rights/addgroup' => 'addgrouplogentry',
161 'rights/rngroup' => 'renamegrouplogentry',
162 'rights/chgroup' => 'changegrouplogentry',
163 'delete/delete' => 'deletedarticle',
164 'delete/restore' => 'undeletedarticle',
165 'upload/upload' => 'uploadedimage',
166 'upload/revert' => 'uploadedimage',
167 'move/move' => '1movedto2',
168 'move/move_redir' => '1movedto2_redir'
170 $key = "$type/$action";
171 if( isset( $actions[$key] ) ) {
172 if( is_null( $title ) ) {
173 $rv=wfMsgForContent( $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 $titleLink = $skin->makeLinkObj( $title );
185 $titleLink = $title->getPrefixedText();
187 if( count( $params ) == 0 ) {
188 $rv = wfMsgForContent( $actions[$key], $titleLink );
190 array_unshift( $params, $titleLink );
191 $rv = wfMsgReal( $actions[$key], $params, true, true );
195 wfDebug( "LogPage::actionText - unknown action $key\n" );
198 if( $filterWikilinks ) {
199 $rv = str_replace( "[[", "", $rv );
200 $rv = str_replace( "]]", "", $rv );
207 * @param string $action one of '', 'block', 'protect', 'rights', 'delete', 'upload', 'move', 'move_redir'
208 * @param object &$target A title object.
209 * @param string $comment Description associated
210 * @param array $params Parameters passed later to wfMsg.* functions
212 function addEntry( $action, &$target, $comment, $params = array() ) {
213 if ( !is_array( $params ) ) {
214 $params = array( $params );
217 $this->action
= $action;
218 $this->target
=& $target;
219 $this->comment
= $comment;
220 $this->params
= LogPage
::makeParamBlob( $params );
222 $this->actionText
= LogPage
::actionText( $this->type
, $action, $target, NULL, $params );
224 return $this->saveContent();
228 * Create a blob from a parameter array
231 function makeParamBlob( $params ) {
232 return implode( "\n", $params );
236 * Extract a parameter array from a blob
239 function extractParams( $blob ) {
240 if ( $blob === '' ) {
243 return explode( "\n", $blob );