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 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 false;
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, '',
88 $this->type
, $this->action
, $this->target
, $this->comment
, $this->params
);
96 function validTypes() {
104 function isLogType( $type ) {
105 return in_array( $type, LogPage
::validTypes() );
111 function logName( $type ) {
114 if( isset( $wgLogNames[$type] ) ) {
115 return str_replace( '_', ' ', wfMsg( $wgLogNames[$type] ) );
117 // Bogus log types? Perhaps an extension was removed.
123 * @fixme: handle missing log types
126 function logHeader( $type ) {
127 global $wgLogHeaders;
128 return wfMsg( $wgLogHeaders[$type] );
134 function actionText( $type, $action, $title = NULL, $skin = NULL, $params = array(), $filterWikilinks=false, $translate=false ) {
135 global $wgLang, $wgContLang, $wgLogActions;
137 $key = "$type/$action";
138 if( isset( $wgLogActions[$key] ) ) {
139 if( is_null( $title ) ) {
140 $rv=wfMsg( $wgLogActions[$key] );
146 $titleLink = $skin->makeLinkObj( $title, $title->getPrefixedText(), 'redirect=no' );
147 $params[0] = $skin->makeLinkObj( Title
::newFromText( $params[0] ), $params[0] );
150 if( substr( $title->getText(), 0, 1 ) == '#' ) {
151 $titleLink = $title->getText();
153 $titleLink = $skin->makeLinkObj( $title, $title->getText() );
154 $titleLink .= ' (' . $skin->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Contributions/' . $title->getDBkey() ), wfMsg( 'contribslink' ) ) . ')';
158 if( trim( $params[0] ) == '' )
159 $params[0] = wfMsg( 'rightsnone' );
160 $text = $wgContLang->ucfirst( $title->getText() );
161 $titleLink = $skin->makeLinkObj( Title
::makeTitle( NS_USER
, $text ) );
164 $titleLink = $skin->makeLinkObj( $title );
168 $titleLink = $title->getPrefixedText();
170 if( count( $params ) == 0 ) {
172 $rv = wfMsg( $wgLogActions[$key], $titleLink );
174 $rv = wfMsgForContent( $wgLogActions[$key], $titleLink );
177 array_unshift( $params, $titleLink );
178 if ( $translate && $key == 'block/block' ) {
179 $params[1] = $wgLang->translateBlockExpiry($params[1]);
181 $rv = wfMsgReal( $wgLogActions[$key], $params, true, !$skin );
185 wfDebug( "LogPage::actionText - unknown action $key\n" );
188 if( $filterWikilinks ) {
189 $rv = str_replace( "[[", "", $rv );
190 $rv = str_replace( "]]", "", $rv );
197 * @param string $action one of '', 'block', 'protect', 'rights', 'delete', 'upload', 'move', 'move_redir'
198 * @param object &$target A title object.
199 * @param string $comment Description associated
200 * @param array $params Parameters passed later to wfMsg.* functions
202 function addEntry( $action, &$target, $comment, $params = array() ) {
203 if ( !is_array( $params ) ) {
204 $params = array( $params );
207 $this->action
= $action;
208 $this->target
=& $target;
209 $this->comment
= $comment;
210 $this->params
= LogPage
::makeParamBlob( $params );
212 $this->actionText
= LogPage
::actionText( $this->type
, $action, $target, NULL, $params );
214 return $this->saveContent();
218 * Create a blob from a parameter array
221 function makeParamBlob( $params ) {
222 return implode( "\n", $params );
226 * Extract a parameter array from a blob
229 function extractParams( $blob ) {
230 if ( $blob === '' ) {
233 return explode( "\n", $blob );