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' );
92 wfRunHooks( 'LogPageValidTypes', array( &$types) );
99 function validActions( $type ) {
100 static $actions = array(
102 'block' => array( 'block', 'unblock' ),
103 'protect' => array( 'protect', 'unprotect' ),
104 'rights' => array( 'rights' ),
105 'delete' => array( 'delete', 'restore' ),
106 'upload' => array( 'upload' ),
107 'move' => array( 'move' )
109 return $actions[$type];
115 function isLogType( $type ) {
116 return in_array( $type, LogPage
::validTypes() );
122 function logName( $type ) {
123 static $typeText = array(
125 'block' => 'blocklogpage',
126 'protect' => 'protectlogpage',
127 'rights' => 'bureaucratlog',
128 'delete' => 'dellogpage',
129 'upload' => 'uploadlogpage',
130 'move' => 'movelogpage'
132 wfRunHooks( 'LogPageLogName', array( &$typeText) );
134 return str_replace( '_', ' ', wfMsg( $typeText[$type] ) );
140 function logHeader( $type ) {
141 static $headerText = array(
143 'block' => 'blocklogtext',
144 'protect' => 'protectlogtext',
145 'rights' => 'rightslogtext',
146 'delete' => 'dellogpagetext',
147 'upload' => 'uploadlogpagetext',
148 'move' => 'movelogpagetext'
150 wfRunHooks( 'LogPageLogHeader', array( &$headerText ) );
152 return wfMsg( $headerText[$type] );
158 function actionText( $type, $action, $title = NULL, $skin = NULL, $params = array(), $filterWikilinks=false, $translate=false ) {
160 static $actions = array(
161 'block/block' => 'blocklogentry',
162 'block/unblock' => 'unblocklogentry',
163 'protect/protect' => 'protectedarticle',
164 'protect/unprotect' => 'unprotectedarticle',
165 'rights/rights' => 'bureaucratlogentry',
166 'rights/addgroup' => 'addgrouplogentry',
167 'rights/rngroup' => 'renamegrouplogentry',
168 'rights/chgroup' => 'changegrouplogentry',
169 'delete/delete' => 'deletedarticle',
170 'delete/restore' => 'undeletedarticle',
171 'upload/upload' => 'uploadedimage',
172 'upload/revert' => 'uploadedimage',
173 'move/move' => '1movedto2',
174 'move/move_redir' => '1movedto2_redir'
176 $key = "$type/$action";
177 if( isset( $actions[$key] ) ) {
178 if( is_null( $title ) ) {
179 $rv=wfMsg( $actions[$key] );
182 if ( $type == 'move' ) {
183 $titleLink = $skin->makeLinkObj( $title, $title->getPrefixedText(), 'redirect=no' );
184 // Change $param[0] into a link to the title specified in $param[0]
185 $movedTo = Title
::newFromText( $params[0] );
186 $params[0] = $skin->makeLinkObj( $movedTo, $params[0] );
188 $titleLink = $skin->makeLinkObj( $title );
191 $titleLink = $title->getPrefixedText();
193 if( count( $params ) == 0 ) {
194 $rv = wfMsg( $actions[$key], $titleLink );
196 array_unshift( $params, $titleLink );
197 if ( $translate && $key == 'block/block' ) {
198 $params[1] = $wgLang->translateBlockExpiry($params[1]);
200 $rv = wfMsgReal( $actions[$key], $params, true, false );
204 wfDebug( "LogPage::actionText - unknown action $key\n" );
207 if( $filterWikilinks ) {
208 $rv = str_replace( "[[", "", $rv );
209 $rv = str_replace( "]]", "", $rv );
216 * @param string $action one of '', 'block', 'protect', 'rights', 'delete', 'upload', 'move', 'move_redir'
217 * @param object &$target A title object.
218 * @param string $comment Description associated
219 * @param array $params Parameters passed later to wfMsg.* functions
221 function addEntry( $action, &$target, $comment, $params = array() ) {
222 if ( !is_array( $params ) ) {
223 $params = array( $params );
226 $this->action
= $action;
227 $this->target
=& $target;
228 $this->comment
= $comment;
229 $this->params
= LogPage
::makeParamBlob( $params );
231 $this->actionText
= LogPage
::actionText( $this->type
, $action, $target, NULL, $params );
233 return $this->saveContent();
237 * Create a blob from a parameter array
240 function makeParamBlob( $params ) {
241 return implode( "\n", $params );
245 * Extract a parameter array from a blob
248 function extractParams( $blob ) {
249 if ( $blob === '' ) {
252 return explode( "\n", $blob );