* (bug 153) Adjust thumbnail size calculations to match consistently;
[lhc/web/wiklou.git] / includes / LogPage.php
1 <?php
2 #
3 # Copyright (C) 2002, 2004 Brion Vibber <brion@pobox.com>
4 # http://www.mediawiki.org/
5 #
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.
10 #
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.
15 #
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
20
21 /**
22 * Contain log classes
23 *
24 * @package MediaWiki
25 */
26
27 /**
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.
31 *
32 * @package MediaWiki
33 */
34 class LogPage {
35 /* @access private */
36 var $type, $action, $comment, $params, $target;
37 /* @acess public */
38 var $updateRecentChanges;
39
40 /**
41 * Constructor
42 *
43 * @param string $type One of '', 'block', 'protect', 'rights', 'delete',
44 * 'upload', 'move'
45 * @param bool $rc Whether to update recent changes as well as the logging table
46 */
47 function LogPage( $type, $rc = true ) {
48 $this->type = $type;
49 $this->updateRecentChanges = $rc;
50 }
51
52 function saveContent() {
53 if( wfReadOnly() ) return;
54
55 global $wgUser;
56 $fname = 'LogPage::saveContent';
57
58 $dbw =& wfGetDB( DB_MASTER );
59 $uid = $wgUser->getID();
60
61 $this->timestamp = $now = wfTimestampNow();
62 $dbw->insert( 'logging',
63 array(
64 'log_type' => $this->type,
65 'log_action' => $this->action,
66 'log_timestamp' => $dbw->timestamp( $now ),
67 'log_user' => $uid,
68 'log_namespace' => $this->target->getNamespace(),
69 'log_title' => $this->target->getDBkey(),
70 'log_comment' => $this->comment,
71 'log_params' => $this->params
72 ), $fname
73 );
74
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 ) {
80 if ($rcComment == '')
81 $rcComment = $this->comment;
82 else
83 $rcComment .= ': ' . $this->comment;
84 }
85
86 RecentChange::notifyLog( $now, $titleObj, $wgUser, $rcComment );
87 }
88 return true;
89 }
90
91 /**
92 * @static
93 */
94 function validTypes() {
95 static $types = array( '', 'block', 'protect', 'rights', 'delete', 'upload', 'move' );
96 wfRunHooks( 'LogPageValidTypes', array( &$types ) );
97 return $types;
98 }
99
100 /**
101 * @static
102 */
103 function isLogType( $type ) {
104 return in_array( $type, LogPage::validTypes() );
105 }
106
107 /**
108 * @static
109 */
110 function logName( $type ) {
111 static $typeText = array(
112 '' => 'log',
113 'block' => 'blocklogpage',
114 'protect' => 'protectlogpage',
115 'rights' => 'bureaucratlog',
116 'delete' => 'dellogpage',
117 'upload' => 'uploadlogpage',
118 'move' => 'movelogpage'
119 );
120 wfRunHooks( 'LogPageLogName', array( &$typeText ) );
121
122 return str_replace( '_', ' ', wfMsg( $typeText[$type] ) );
123 }
124
125 /**
126 * @static
127 */
128 function logHeader( $type ) {
129 static $headerText = array(
130 '' => 'alllogstext',
131 'block' => 'blocklogtext',
132 'protect' => 'protectlogtext',
133 'rights' => 'rightslogtext',
134 'delete' => 'dellogpagetext',
135 'upload' => 'uploadlogpagetext',
136 'move' => 'movelogpagetext'
137 );
138 wfRunHooks( 'LogPageLogHeader', array( &$headerText ) );
139
140 return wfMsg( $headerText[$type] );
141 }
142
143 /**
144 * @static
145 */
146 function actionText( $type, $action, $title = NULL, $skin = NULL, $params = array(), $filterWikilinks=false, $translate=false ) {
147 global $wgLang;
148 static $actions = array(
149 'block/block' => 'blocklogentry',
150 'block/unblock' => 'unblocklogentry',
151 'protect/protect' => 'protectedarticle',
152 'protect/unprotect' => 'unprotectedarticle',
153
154 // TODO: This whole section should be moved to extensions/Makesysop/SpecialMakesysop.php
155 'rights/rights' => 'bureaucratlogentry',
156 'rights/addgroup' => 'addgrouplogentry',
157 'rights/rngroup' => 'renamegrouplogentry',
158 'rights/chgroup' => 'changegrouplogentry',
159
160 'delete/delete' => 'deletedarticle',
161 'delete/restore' => 'undeletedarticle',
162 'upload/upload' => 'uploadedimage',
163 'upload/revert' => 'uploadedimage',
164 'move/move' => '1movedto2',
165 'move/move_redir' => '1movedto2_redir'
166 );
167 wfRunHooks( 'LogPageActionText', array( &$actions ) );
168
169 $key = "$type/$action";
170 if( isset( $actions[$key] ) ) {
171 if( is_null( $title ) ) {
172 $rv=wfMsg( $actions[$key] );
173 } else {
174 if( $skin ) {
175 if ( $type == 'move' ) {
176 $titleLink = $skin->makeLinkObj( $title, $title->getPrefixedText(), 'redirect=no' );
177 // Change $param[0] into a link to the title specified in $param[0]
178 $movedTo = Title::newFromText( $params[0] );
179 $params[0] = $skin->makeLinkObj( $movedTo, $params[0] );
180 } else {
181 $titleLink = $skin->makeLinkObj( $title );
182 }
183 } else {
184 $titleLink = $title->getPrefixedText();
185 }
186 if( count( $params ) == 0 ) {
187 $rv = wfMsg( $actions[$key], $titleLink );
188 } else {
189 array_unshift( $params, $titleLink );
190 if ( $translate && $key == 'block/block' ) {
191 $params[1] = $wgLang->translateBlockExpiry($params[1]);
192 }
193 $rv = wfMsgReal( $actions[$key], $params, true, false ); // FIXME: use wfMsgForContent() ?
194 }
195 }
196 } else {
197 wfDebug( "LogPage::actionText - unknown action $key\n" );
198 $rv = "$action";
199 }
200 if( $filterWikilinks ) {
201 $rv = str_replace( "[[", "", $rv );
202 $rv = str_replace( "]]", "", $rv );
203 }
204 return $rv;
205 }
206
207 /**
208 * Add a log entry
209 * @param string $action one of '', 'block', 'protect', 'rights', 'delete', 'upload', 'move', 'move_redir'
210 * @param object &$target A title object.
211 * @param string $comment Description associated
212 * @param array $params Parameters passed later to wfMsg.* functions
213 */
214 function addEntry( $action, &$target, $comment, $params = array() ) {
215 if ( !is_array( $params ) ) {
216 $params = array( $params );
217 }
218
219 $this->action = $action;
220 $this->target =& $target;
221 $this->comment = $comment;
222 $this->params = LogPage::makeParamBlob( $params );
223
224 $this->actionText = LogPage::actionText( $this->type, $action, $target, NULL, $params );
225
226 return $this->saveContent();
227 }
228
229 /**
230 * Create a blob from a parameter array
231 * @static
232 */
233 function makeParamBlob( $params ) {
234 return implode( "\n", $params );
235 }
236
237 /**
238 * Extract a parameter array from a blob
239 * @static
240 */
241 function extractParams( $blob ) {
242 if ( $blob === '' ) {
243 return array();
244 } else {
245 return explode( "\n", $blob );
246 }
247 }
248 }
249
250 ?>