Index: branches/robchurch/logs/includes/LogPage.php |
— | — | @@ -30,69 +30,29 @@ |
31 | 31 | * |
32 | 32 | */ |
33 | 33 | class LogPage { |
34 | | - /* @access private */ |
35 | | - var $type, $action, $comment, $params, $target; |
36 | | - /* @acess public */ |
37 | | - var $updateRecentChanges; |
38 | 34 | |
39 | 35 | /** |
| 36 | + * Log type |
| 37 | + */ |
| 38 | + private $type = ''; |
| 39 | + |
| 40 | + /** |
| 41 | + * Should we update recent changes when adding a |
| 42 | + * new log item? |
| 43 | + */ |
| 44 | + private $updateRecentChanges = true; |
| 45 | + |
| 46 | + /** |
40 | 47 | * Constructor |
41 | 48 | * |
42 | | - * @param string $type One of '', 'block', 'protect', 'rights', 'delete', |
43 | | - * 'upload', 'move' |
44 | | - * @param bool $rc Whether to update recent changes as well as the logging table |
| 49 | + * @param string $type Log type |
| 50 | + * @param bool $rc Update recent changes? |
45 | 51 | */ |
46 | | - function __construct( $type, $rc = true ) { |
| 52 | + public function __construct( $type, $rc = true ) { |
47 | 53 | $this->type = $type; |
48 | 54 | $this->updateRecentChanges = $rc; |
49 | 55 | } |
50 | 56 | |
51 | | - function saveContent() { |
52 | | - if( wfReadOnly() ) return false; |
53 | | - |
54 | | - global $wgUser; |
55 | | - $fname = 'LogPage::saveContent'; |
56 | | - |
57 | | - $dbw = wfGetDB( DB_MASTER ); |
58 | | - $uid = $wgUser->getID(); |
59 | | - $log_id = $dbw->nextSequenceValue( 'log_log_id_seq' ); |
60 | | - |
61 | | - $this->timestamp = $now = wfTimestampNow(); |
62 | | - $data = array( |
63 | | - 'log_type' => $this->type, |
64 | | - 'log_action' => $this->action, |
65 | | - 'log_timestamp' => $dbw->timestamp( $now ), |
66 | | - 'log_user' => $uid, |
67 | | - 'log_namespace' => $this->target->getNamespace(), |
68 | | - 'log_title' => $this->target->getDBkey(), |
69 | | - 'log_comment' => $this->comment, |
70 | | - 'log_params' => $this->params, |
71 | | - ); |
72 | | - |
73 | | - # log_id doesn't exist on Wikimedia servers yet, and it's a tricky |
74 | | - # schema update to do. Hack it for now to ignore the field on MySQL. |
75 | | - if ( !is_null( $log_id ) ) { |
76 | | - $data['log_id'] = $log_id; |
77 | | - } |
78 | | - $dbw->insert( 'logging', $data, $fname ); |
79 | | - |
80 | | - # Update recent changes |
81 | | - if( $this->updateRecentChanges ) { |
82 | | - RecentChange::notifyLog( |
83 | | - $now, |
84 | | - $this->target, |
85 | | - $wgUser, |
86 | | - $this->comment, |
87 | | - '', |
88 | | - $this->type, |
89 | | - $this->action, |
90 | | - $this->params |
91 | | - ); |
92 | | - } |
93 | | - |
94 | | - return true; |
95 | | - } |
96 | | - |
97 | 57 | /** |
98 | 58 | * @static |
99 | 59 | */ |
— | — | @@ -105,7 +65,7 @@ |
106 | 66 | * @static |
107 | 67 | */ |
108 | 68 | public static function isLogType( $type ) { |
109 | | - return in_array( $type, LogPage::validTypes() ); |
| 69 | + return in_array( $type, self::validTypes() ); |
110 | 70 | } |
111 | 71 | |
112 | 72 | /** |
— | — | @@ -214,81 +174,88 @@ |
215 | 175 | } |
216 | 176 | |
217 | 177 | /** |
218 | | - * Add a log entry |
219 | | - * @param string $action one of '', 'block', 'protect', 'rights', 'delete', 'upload', 'move', 'move_redir' |
220 | | - * @param object &$target A title object. |
221 | | - * @param string $comment Description associated |
222 | | - * @param array $params Parameters passed later to wfMsg.* functions |
| 178 | + * Insert a new log row, updating recent changes if |
| 179 | + * we've been asked to do so |
| 180 | + * |
| 181 | + * @param string $action Log action |
| 182 | + * @param Title $target Associated title object |
| 183 | + * @param string $comment Log comment/rationale |
| 184 | + * @param array $params Log parameters |
223 | 185 | */ |
224 | | - function addEntry( $action, $target, $comment, $params = array() ) { |
225 | | - if ( !is_array( $params ) ) { |
226 | | - $params = array( $params ); |
| 186 | + public function addEntry( $action, $target, $comment, $params = array() ) { |
| 187 | + global $wgUser; |
| 188 | + wfProfileIn( __METHOD__ ); |
| 189 | + |
| 190 | + if( wfReadOnly() ) { |
| 191 | + wfProfileOut( __METHOD__ ); |
| 192 | + return false; |
227 | 193 | } |
228 | 194 | |
229 | | - $this->action = $action; |
230 | | - $this->target = $target; |
231 | | - $this->comment = $comment; |
232 | | - $this->params = LogPage::makeParamBlob( $params ); |
| 195 | + if( !is_array( $params ) ) |
| 196 | + $params = array( $params ); |
233 | 197 | |
234 | | - #$this->actionText = LogPage::actionText( $this->type, $action, $target, NULL, $params ); |
| 198 | + $dbw = wfGetDB( DB_MASTER ); |
| 199 | + $now = wfTimestampNow(); |
| 200 | + $log_id = $dbw->nextSequenceValue( 'log_log_id_seq' ); |
235 | 201 | |
236 | | - return $this->saveContent(); |
237 | | - } |
| 202 | + $data = array( |
| 203 | + 'log_type' => $this->type, |
| 204 | + 'log_action' => $action, |
| 205 | + 'log_timestamp' => $dbw->timestamp( $now ), |
| 206 | + 'log_user' => $wgUser->getId(), |
| 207 | + 'log_namespace' => $target->getNamespace(), |
| 208 | + 'log_title' => $target->getDBkey(), |
| 209 | + 'log_comment' => $comment, |
| 210 | + 'log_params' => self::makeParamBlob( $params ), |
| 211 | + ); |
238 | 212 | |
239 | | - /** |
240 | | - * Create a blob from a parameter array |
241 | | - * @static |
242 | | - */ |
243 | | - static function makeParamBlob( $params ) { |
244 | | - return implode( "\n", $params ); |
245 | | - } |
| 213 | + # log_id doesn't exist on Wikimedia servers yet, and it's a tricky |
| 214 | + # schema update to do. Hack it for now to ignore the field on MySQL. |
| 215 | + if ( !is_null( $log_id ) ) { |
| 216 | + $data['log_id'] = $log_id; |
| 217 | + } |
| 218 | + $dbw->insert( 'logging', $data, __METHOD__ ); |
246 | 219 | |
247 | | - /** |
248 | | - * Extract a parameter array from a blob |
249 | | - * @static |
250 | | - */ |
251 | | - static function extractParams( $blob ) { |
252 | | - if ( $blob === '' ) { |
253 | | - return array(); |
254 | | - } else { |
255 | | - return explode( "\n", $blob ); |
| 220 | + # Update recent changes if required |
| 221 | + if( $this->updateRecentChanges ) { |
| 222 | + RecentChange::notifyLog( |
| 223 | + $now, |
| 224 | + $target, |
| 225 | + $wgUser, |
| 226 | + $comment, |
| 227 | + '', |
| 228 | + $this->type, |
| 229 | + $action, |
| 230 | + $params |
| 231 | + ); |
256 | 232 | } |
| 233 | + |
| 234 | + wfProfileOut( __METHOD__ ); |
| 235 | + return true; |
257 | 236 | } |
258 | | - |
| 237 | + |
259 | 238 | /** |
260 | | - * Convert a comma-delimited list of block log flags |
261 | | - * into a more readable (and translated) form |
| 239 | + * Encode parameters into a BLOB-safe value |
262 | 240 | * |
263 | | - * @param $flags Flags to format |
| 241 | + * @param array $params Parameters |
264 | 242 | * @return string |
265 | 243 | */ |
266 | | - public static function formatBlockFlags( $flags ) { |
267 | | - $flags = explode( ',', trim( $flags ) ); |
268 | | - if( count( $flags ) > 0 ) { |
269 | | - for( $i = 0; $i < count( $flags ); $i++ ) |
270 | | - $flags[$i] = self::formatBlockFlag( $flags[$i] ); |
271 | | - return '(' . implode( ', ', $flags ) . ')'; |
272 | | - } else { |
273 | | - return ''; |
274 | | - } |
| 244 | + public static function makeParamBlob( $params ) { |
| 245 | + return implode( "\n", $params ); |
275 | 246 | } |
276 | | - |
| 247 | + |
277 | 248 | /** |
278 | | - * Translate a block log flag if possible |
| 249 | + * Decode parameters from a BLOB value |
279 | 250 | * |
280 | | - * @param $flag Flag to translate |
281 | | - * @return string |
| 251 | + * @param string $blob Parameter blob |
| 252 | + * @return array |
282 | 253 | */ |
283 | | - public static function formatBlockFlag( $flag ) { |
284 | | - static $messages = array(); |
285 | | - if( !isset( $messages[$flag] ) ) { |
286 | | - $k = 'block-log-flags-' . $flag; |
287 | | - $msg = wfMsg( $k ); |
288 | | - $messages[$flag] = htmlspecialchars( wfEmptyMsg( $k, $msg ) ? $flag : $msg ); |
289 | | - } |
290 | | - return $messages[$flag]; |
| 254 | + public static function extractParams( $blob ) { |
| 255 | + return $blob === '' |
| 256 | + ? array() |
| 257 | + : explode( "\n", $blob ); |
291 | 258 | } |
292 | 259 | |
293 | 260 | } |
294 | 261 | |
295 | | -?> |
| 262 | +?> |
\ No newline at end of file |