elaborate fix for bug 1156: Block log: missing expiry time. Changed schema for loggin...
[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 /* private */ var $type, $action, $comment, $params;
36 var $updateRecentChanges = true;
37
38 function LogPage( $type ) {
39 # Type is one of 'block', 'protect', 'rights', 'delete', 'upload'
40 $this->type = $type;
41 }
42
43 function saveContent() {
44 if( wfReadOnly() ) return;
45
46 global $wgUser;
47 $fname = 'LogPage::saveContent';
48
49 $dbw =& wfGetDB( DB_MASTER );
50 $uid = $wgUser->getID();
51
52 $this->timestamp = $now = wfTimestampNow();
53 $dbw->insert( 'logging',
54 array(
55 'log_type' => $this->type,
56 'log_action' => $this->action,
57 'log_timestamp' => $dbw->timestamp( $now ),
58 'log_user' => $uid,
59 'log_namespace' => $this->target->getNamespace(),
60 'log_title' => $this->target->getDBkey(),
61 'log_comment' => $this->comment,
62 'log_params' => $this->params
63 ), $fname
64 );
65
66 # And update recentchanges
67 if ( $this->updateRecentChanges ) {
68 $rcComment = $this->actionText;
69 if( '' != $this->comment ) {
70 $rcComment .= ': ' . $this->comment;
71 }
72 $titleObj = Title::makeTitle( NS_SPECIAL, 'Log/' . $this->type );
73 RecentChange::notifyLog( $now, $titleObj, $wgUser, $rcComment );
74 }
75 return true;
76 }
77
78 /**
79 * @static
80 */
81 function validTypes() {
82 static $types = array( '', 'block', 'protect', 'rights', 'delete', 'upload' );
83 return $types;
84 }
85
86 /**
87 * @static
88 */
89 function validActions( $type ) {
90 static $actions = array(
91 '' => NULL,
92 'block' => array( 'block', 'unblock' ),
93 'protect' => array( 'protect', 'unprotect' ),
94 'rights' => array( 'rights' ),
95 'delete' => array( 'delete', 'restore' ),
96 'upload' => array( 'upload' )
97 );
98 return $actions[$type];
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 );
120 return str_replace( '_', ' ', wfMsg( $typeText[$type] ) );
121 }
122
123 /**
124 * @static
125 */
126 function logHeader( $type ) {
127 static $headerText = array(
128 '' => 'alllogstext',
129 'block' => 'blocklogtext',
130 'protect' => 'protectlogtext',
131 'rights' => 'rightslogtext',
132 'delete' => 'dellogpagetext',
133 'upload' => 'uploadlogpagetext'
134 );
135 return wfMsg( $headerText[$type] );
136 }
137
138 /**
139 * @static
140 */
141 function actionText( $type, $action, $titleLink = NULL, $params = array() ) {
142 static $actions = array(
143 'block/block' => 'blocklogentry',
144 'block/unblock' => 'unblocklogentry',
145 'protect/protect' => 'protectedarticle',
146 'protect/unprotect' => 'unprotectedarticle',
147 'rights/rights' => 'bureaucratlogentry',
148 'delete/delete' => 'deletedarticle',
149 'delete/restore' => 'undeletedarticle',
150 'upload/upload' => 'uploadedimage',
151 'upload/revert' => 'uploadedimage',
152 );
153 $key = "$type/$action";
154 if( isset( $actions[$key] ) ) {
155 if( is_null( $titleLink ) ) {
156 return wfMsgForContent( $actions[$key] );
157 } elseif ( count( $params ) == 0 ) {
158 return wfMsgForContent( $actions[$key], $titleLink );
159 } else {
160 array_unshift( $params, $titleLink );
161 return wfMsgReal( $actions[$key], $params, true, true );
162 }
163 } else {
164 wfDebug( "LogPage::actionText - unknown action $key\n" );
165 return "$action $titleLink";
166 }
167 }
168
169 /**
170 * Add a log entry
171 * @param string $action one of 'block', 'protect', 'rights', 'delete', 'upload'
172 * @param &$target
173 * @param string $comment Description associated
174 */
175 function addEntry( $action, &$target, $comment, $params = array() ) {
176 global $wgLang, $wgUser;
177
178 if ( !is_array( $params ) ) {
179 $params = array( $params );
180 }
181
182 $this->action = $action;
183 $this->target =& $target;
184 $this->comment = $comment;
185 $this->params = LogPage::makeParamBlob( $params );
186
187 $this->actionText = LogPage::actionText( $this->type, $action,
188 $target->getPrefixedText(), $params );
189 return $this->saveContent();
190 }
191
192 /**
193 * Create a blob from a parameter array
194 * @static
195 */
196 function makeParamBlob( $params )
197 {
198 return implode( "\n", $params );
199 }
200
201 /**
202 * Extract a parameter array from a blob
203 * @static
204 */
205 function extractParams( $blob )
206 {
207 if ( $blob === '' ) {
208 return array();
209 } else {
210 return explode( "\n", $blob );
211 }
212 }
213 }
214
215 ?>