Fix broken contribs link in block log
[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 require_once( 'RecentChange.php' );
87 RecentChange::notifyLog( $now, $titleObj, $wgUser, $rcComment );
88 }
89 return true;
90 }
91
92 /**
93 * @static
94 */
95 function validTypes() {
96 static $types = array( '', 'block', 'protect', 'rights', 'delete', 'upload', 'move' );
97 wfRunHooks( 'LogPageValidTypes', array( &$types ) );
98 return $types;
99 }
100
101 /**
102 * @static
103 */
104 function isLogType( $type ) {
105 return in_array( $type, LogPage::validTypes() );
106 }
107
108 /**
109 * @static
110 */
111 function logName( $type ) {
112 static $typeText = array(
113 '' => 'log',
114 'block' => 'blocklogpage',
115 'protect' => 'protectlogpage',
116 'rights' => 'bureaucratlog',
117 'delete' => 'dellogpage',
118 'upload' => 'uploadlogpage',
119 'move' => 'movelogpage'
120 );
121 wfRunHooks( 'LogPageLogName', array( &$typeText ) );
122
123 return str_replace( '_', ' ', wfMsg( $typeText[$type] ) );
124 }
125
126 /**
127 * @static
128 */
129 function logHeader( $type ) {
130 static $headerText = array(
131 '' => 'alllogstext',
132 'block' => 'blocklogtext',
133 'protect' => 'protectlogtext',
134 'rights' => 'rightslogtext',
135 'delete' => 'dellogpagetext',
136 'upload' => 'uploadlogpagetext',
137 'move' => 'movelogpagetext'
138 );
139 wfRunHooks( 'LogPageLogHeader', array( &$headerText ) );
140
141 return wfMsg( $headerText[$type] );
142 }
143
144 /**
145 * @static
146 */
147 function actionText( $type, $action, $title = NULL, $skin = NULL, $params = array(), $filterWikilinks=false, $translate=false ) {
148 global $wgLang;
149 static $actions = array(
150 'block/block' => 'blocklogentry',
151 'block/unblock' => 'unblocklogentry',
152 'protect/protect' => 'protectedarticle',
153 'protect/unprotect' => 'unprotectedarticle',
154
155 // TODO: This whole section should be moved to extensions/Makesysop/SpecialMakesysop.php
156 'rights/rights' => 'bureaucratlogentry',
157 'rights/addgroup' => 'addgrouplogentry',
158 'rights/rngroup' => 'renamegrouplogentry',
159 'rights/chgroup' => 'changegrouplogentry',
160
161 'delete/delete' => 'deletedarticle',
162 'delete/restore' => 'undeletedarticle',
163 'upload/upload' => 'uploadedimage',
164 'upload/revert' => 'uploadedimage',
165 'move/move' => '1movedto2',
166 'move/move_redir' => '1movedto2_redir'
167 );
168 wfRunHooks( 'LogPageActionText', array( &$actions ) );
169
170 $key = "$type/$action";
171 if( isset( $actions[$key] ) ) {
172 if( is_null( $title ) ) {
173 $rv=wfMsg( $actions[$key] );
174 } else {
175 if( $skin ) {
176
177 switch( $type ) {
178 case 'move':
179 $titleLink = $skin->makeLinkObj( $title, $title->getPrefixedText(), 'redirect=no' );
180 $params[0] = $skin->makeLinkObj( Title::newFromText( $params[0] ), $params[0] );
181 break;
182 case 'block':
183 if( substr( $title->getText(), 0, 1 ) == '#' ) {
184 $titleLink = $$title->getText();
185 } else {
186 $titleLink = $skin->makeLinkObj( $title, $title->getText() );
187 $titleLink .= ' (' . $skin->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions/' . urlencode( $title->getDBkey() ) ), wfMsg( 'contribslink' ) ) . ')';
188 }
189 break;
190 default:
191 $titleLink = $skin->makeLinkObj( $title );
192 }
193
194 } else {
195 $titleLink = $title->getPrefixedText();
196 }
197 if( count( $params ) == 0 ) {
198 $rv = wfMsg( $actions[$key], $titleLink );
199 } else {
200 array_unshift( $params, $titleLink );
201 if ( $translate && $key == 'block/block' ) {
202 $params[1] = $wgLang->translateBlockExpiry($params[1]);
203 }
204 $rv = wfMsgReal( $actions[$key], $params, true, false ); // FIXME: use wfMsgForContent() ?
205 }
206 }
207 } else {
208 wfDebug( "LogPage::actionText - unknown action $key\n" );
209 $rv = "$action";
210 }
211 if( $filterWikilinks ) {
212 $rv = str_replace( "[[", "", $rv );
213 $rv = str_replace( "]]", "", $rv );
214 }
215 return $rv;
216 }
217
218 /**
219 * Add a log entry
220 * @param string $action one of '', 'block', 'protect', 'rights', 'delete', 'upload', 'move', 'move_redir'
221 * @param object &$target A title object.
222 * @param string $comment Description associated
223 * @param array $params Parameters passed later to wfMsg.* functions
224 */
225 function addEntry( $action, &$target, $comment, $params = array() ) {
226 if ( !is_array( $params ) ) {
227 $params = array( $params );
228 }
229
230 $this->action = $action;
231 $this->target =& $target;
232 $this->comment = $comment;
233 $this->params = LogPage::makeParamBlob( $params );
234
235 $this->actionText = LogPage::actionText( $this->type, $action, $target, NULL, $params );
236
237 return $this->saveContent();
238 }
239
240 /**
241 * Create a blob from a parameter array
242 * @static
243 */
244 function makeParamBlob( $params ) {
245 return implode( "\n", $params );
246 }
247
248 /**
249 * Extract a parameter array from a blob
250 * @static
251 */
252 function extractParams( $blob ) {
253 if ( $blob === '' ) {
254 return array();
255 } else {
256 return explode( "\n", $blob );
257 }
258 }
259 }
260
261 ?>