ef633358dd9b2462667b88bce972fb9ba0b1fd47
[lhc/web/wiklou.git] / includes / logging / LogEventsList.php
1 <?php
2 /**
3 * Contain classes to list log entries
4 *
5 * Copyright © 2004 Brion Vibber <brion@pobox.com>, 2008 Aaron Schulz
6 * http://www.mediawiki.org/
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
22 *
23 * @file
24 */
25
26 class LogEventsList {
27 const NO_ACTION_LINK = 1;
28 const NO_EXTRA_USER_LINKS = 2;
29
30 /**
31 * @var Skin
32 */
33 private $skin;
34
35 /**
36 * @var OutputPage
37 */
38 private $out;
39 public $flags;
40
41 /**
42 * @var Array
43 */
44 protected $message;
45
46 /**
47 * @var Array
48 */
49 protected $mDefaultQuery;
50
51 public function __construct( $skin, $out, $flags = 0 ) {
52 $this->skin = $skin;
53 $this->out = $out;
54 $this->flags = $flags;
55 $this->preCacheMessages();
56 }
57
58 /**
59 * As we use the same small set of messages in various methods and that
60 * they are called often, we call them once and save them in $this->message
61 */
62 private function preCacheMessages() {
63 // Precache various messages
64 if( !isset( $this->message ) ) {
65 $messages = array( 'revertmerge', 'protect_change', 'unblocklink', 'change-blocklink',
66 'revertmove', 'undeletelink', 'undeleteviewlink', 'revdel-restore', 'hist', 'diff',
67 'pipe-separator', 'revdel-restore-deleted', 'revdel-restore-visible' );
68 foreach( $messages as $msg ) {
69 $this->message[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
70 }
71 }
72 }
73
74 /**
75 * Set page title and show header for this log type
76 * @param $type Array
77 * @deprecated in 1.19
78 */
79 public function showHeader( $type ) {
80 wfDeprecated( __METHOD__, '1.19' );
81 // If only one log type is used, then show a special message...
82 $headerType = (count($type) == 1) ? $type[0] : '';
83 if( LogPage::isLogType( $headerType ) ) {
84 $page = new LogPage( $headerType );
85 $this->out->setPageTitle( $page->getName()->text() );
86 $this->out->addHTML( $page->getDescription()->parseAsBlock() );
87 } else {
88 $this->out->addHTML( wfMsgExt('alllogstext',array('parseinline')) );
89 }
90 }
91
92 /**
93 * Show options for the log list
94 *
95 * @param $types string or Array
96 * @param $user String
97 * @param $page String
98 * @param $pattern String
99 * @param $year Integer: year
100 * @param $month Integer: month
101 * @param $filter: array
102 * @param $tagFilter: array?
103 */
104 public function showOptions( $types=array(), $user='', $page='', $pattern='', $year='',
105 $month = '', $filter = null, $tagFilter='' ) {
106 global $wgScript, $wgMiserMode;
107
108 $action = $wgScript;
109 $title = SpecialPage::getTitleFor( 'Log' );
110 $special = $title->getPrefixedDBkey();
111
112 // For B/C, we take strings, but make sure they are converted...
113 $types = ($types === '') ? array() : (array)$types;
114
115 $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter );
116
117 $html = Html::hidden( 'title', $special );
118
119 // Basic selectors
120 $html .= $this->getTypeMenu( $types ) . "\n";
121 $html .= $this->getUserInput( $user ) . "\n";
122 $html .= $this->getTitleInput( $page ) . "\n";
123 $html .= $this->getExtraInputs( $types ) . "\n";
124
125 // Title pattern, if allowed
126 if (!$wgMiserMode) {
127 $html .= $this->getTitlePattern( $pattern ) . "\n";
128 }
129
130 // date menu
131 $html .= Xml::tags( 'p', null, Xml::dateMenu( $year, $month ) );
132
133 // Tag filter
134 if ($tagSelector) {
135 $html .= Xml::tags( 'p', null, implode( '&#160;', $tagSelector ) );
136 }
137
138 // Filter links
139 if ($filter) {
140 $html .= Xml::tags( 'p', null, $this->getFilterLinks( $filter ) );
141 }
142
143 // Submit button
144 $html .= Xml::submitButton( wfMsg( 'allpagessubmit' ) );
145
146 // Fieldset
147 $html = Xml::fieldset( wfMsg( 'log' ), $html );
148
149 // Form wrapping
150 $html = Xml::tags( 'form', array( 'action' => $action, 'method' => 'get' ), $html );
151
152 $this->out->addHTML( $html );
153 }
154
155 /**
156 * @param $filter Array
157 * @return String: Formatted HTML
158 */
159 private function getFilterLinks( $filter ) {
160 global $wgLang;
161 // show/hide links
162 $messages = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
163 // Option value -> message mapping
164 $links = array();
165 $hiddens = ''; // keep track for "go" button
166 foreach( $filter as $type => $val ) {
167 // Should the below assignment be outside the foreach?
168 // Then it would have to be copied. Not certain what is more expensive.
169 $query = $this->getDefaultQuery();
170 $queryKey = "hide_{$type}_log";
171
172 $hideVal = 1 - intval($val);
173 $query[$queryKey] = $hideVal;
174
175 $link = Linker::link(
176 $this->getDisplayTitle(),
177 $messages[$hideVal],
178 array(),
179 $query,
180 array( 'known', 'noclasses' )
181 );
182
183 $links[$type] = wfMsgHtml( "log-show-hide-{$type}", $link );
184 $hiddens .= Html::hidden( "hide_{$type}_log", $val ) . "\n";
185 }
186 // Build links
187 return '<small>'.$wgLang->pipeList( $links ) . '</small>' . $hiddens;
188 }
189
190 private function getDefaultQuery() {
191 global $wgRequest;
192
193 if ( !isset( $this->mDefaultQuery ) ) {
194 $this->mDefaultQuery = $wgRequest->getQueryValues();
195 unset( $this->mDefaultQuery['title'] );
196 unset( $this->mDefaultQuery['dir'] );
197 unset( $this->mDefaultQuery['offset'] );
198 unset( $this->mDefaultQuery['limit'] );
199 unset( $this->mDefaultQuery['order'] );
200 unset( $this->mDefaultQuery['month'] );
201 unset( $this->mDefaultQuery['year'] );
202 }
203 return $this->mDefaultQuery;
204 }
205
206 /**
207 * Get the Title object of the page the links should point to.
208 * This is NOT the Title of the page the entries should be restricted to.
209 *
210 * @return Title object
211 */
212 public function getDisplayTitle() {
213 return $this->out->getTitle();
214 }
215
216 public function getContext() {
217 return $this->out->getContext();
218 }
219
220 /**
221 * @param $queryTypes Array
222 * @return String: Formatted HTML
223 */
224 private function getTypeMenu( $queryTypes ) {
225 $queryType = count($queryTypes) == 1 ? $queryTypes[0] : '';
226 $selector = $this->getTypeSelector();
227 $selector->setDefault( $queryType );
228 return $selector->getHtml();
229 }
230
231 /**
232 * Returns log page selector.
233 * @return XmlSelect
234 * @since 1.19
235 */
236 public function getTypeSelector() {
237 global $wgUser;
238
239 $typesByName = array(); // Temporary array
240 // First pass to load the log names
241 foreach( LogPage::validTypes() as $type ) {
242 $page = new LogPage( $type );
243 $restriction = $page->getRestriction();
244 if ( $wgUser->isAllowed( $restriction ) ) {
245 $typesByName[$type] = $page->getName()->text();
246 }
247 }
248
249 // Second pass to sort by name
250 asort($typesByName);
251
252 // Always put "All public logs" on top
253 $public = $typesByName[''];
254 unset( $typesByName[''] );
255 $typesByName = array( '' => $public ) + $typesByName;
256
257 $select = new XmlSelect( 'type' );
258 foreach( $typesByName as $type => $name ) {
259 $select->addOption( $name, $type );
260 }
261
262 return $select;
263 }
264
265 /**
266 * @param $user String
267 * @return String: Formatted HTML
268 */
269 private function getUserInput( $user ) {
270 return '<span style="white-space: nowrap">' .
271 Xml::inputLabel( wfMsg( 'specialloguserlabel' ), 'user', 'mw-log-user', 15, $user ) .
272 '</span>';
273 }
274
275 /**
276 * @param $title String
277 * @return String: Formatted HTML
278 */
279 private function getTitleInput( $title ) {
280 return '<span style="white-space: nowrap">' .
281 Xml::inputLabel( wfMsg( 'speciallogtitlelabel' ), 'page', 'mw-log-page', 20, $title ) .
282 '</span>';
283 }
284
285 /**
286 * @param $pattern
287 * @return string Checkbox
288 */
289 private function getTitlePattern( $pattern ) {
290 return '<span style="white-space: nowrap">' .
291 Xml::checkLabel( wfMsg( 'log-title-wildcard' ), 'pattern', 'pattern', $pattern ) .
292 '</span>';
293 }
294
295 /**
296 * @param $types
297 * @return string
298 */
299 private function getExtraInputs( $types ) {
300 global $wgRequest;
301 $offender = $wgRequest->getVal('offender');
302 $user = User::newFromName( $offender, false );
303 if( !$user || ($user->getId() == 0 && !IP::isIPAddress($offender) ) ) {
304 $offender = ''; // Blank field if invalid
305 }
306 if( count($types) == 1 && $types[0] == 'suppress' ) {
307 return Xml::inputLabel( wfMsg('revdelete-offender'), 'offender',
308 'mw-log-offender', 20, $offender );
309 }
310 return '';
311 }
312
313 /**
314 * @return string
315 */
316 public function beginLogEventsList() {
317 return "<ul>\n";
318 }
319
320 /**
321 * @return string
322 */
323 public function endLogEventsList() {
324 return "</ul>\n";
325 }
326
327 /**
328 * @param $row Row: a single row from the result set
329 * @return String: Formatted HTML list item
330 */
331 public function logLine( $row ) {
332 $entry = DatabaseLogEntry::newFromRow( $row );
333 $formatter = LogFormatter::newFromEntry( $entry );
334 $formatter->setShowUserToolLinks( !( $this->flags & self::NO_EXTRA_USER_LINKS ) );
335
336 $action = $formatter->getActionText();
337 $comment = $formatter->getComment();
338
339 $classes = array( 'mw-logline-' . $entry->getType() );
340 $title = $entry->getTarget();
341 $time = $this->logTimestamp( $entry );
342
343 // Extract extra parameters
344 $paramArray = LogPage::extractParams( $row->log_params );
345 // Add review/revert links and such...
346 $revert = $this->logActionLinks( $row, $title, $paramArray, $comment );
347
348 // Some user can hide log items and have review links
349 $del = $this->getShowHideLinks( $row );
350 if( $del != '' ) $del .= ' ';
351
352 // Any tags...
353 list( $tagDisplay, $newClasses ) = ChangeTags::formatSummaryRow( $row->ts_tags, 'logevent' );
354 $classes = array_merge( $classes, $newClasses );
355
356 return Xml::tags( 'li', array( "class" => implode( ' ', $classes ) ),
357 $del . "$time $action $comment $revert $tagDisplay" ) . "\n";
358 }
359
360 private function logTimestamp( LogEntry $entry ) {
361 global $wgLang;
362 $time = $wgLang->timeanddate( wfTimestamp( TS_MW, $entry->getTimestamp() ), true );
363 return htmlspecialchars( $time );
364 }
365
366 /**
367 * @TODO: split up!
368 *
369 * @param $row
370 * @param Title $title
371 * @param Array $paramArray
372 * @param $comment
373 * @return String
374 */
375 private function logActionLinks( $row, $title, $paramArray, &$comment ) {
376 global $wgUser;
377 if( ( $this->flags & self::NO_ACTION_LINK ) // we don't want to see the action
378 || self::isDeleted( $row, LogPage::DELETED_ACTION ) ) // action is hidden
379 {
380 return '';
381 }
382 $revert = '';
383 if( self::typeAction( $row, 'move', 'move', 'move' ) && !empty( $paramArray[0] ) ) {
384 $destTitle = Title::newFromText( $paramArray[0] );
385 if( $destTitle ) {
386 $revert = Linker::link(
387 SpecialPage::getTitleFor( 'Movepage' ),
388 $this->message['revertmove'],
389 array(),
390 array(
391 'wpOldTitle' => $destTitle->getPrefixedDBkey(),
392 'wpNewTitle' => $title->getPrefixedDBkey(),
393 'wpReason' => wfMsgForContent( 'revertmove' ),
394 'wpMovetalk' => 0
395 ),
396 array( 'known', 'noclasses' )
397 );
398 $revert = wfMessage( 'parentheses' )->rawParams( $revert )->escaped();
399 }
400 // Show undelete link
401 } elseif( self::typeAction( $row, array( 'delete', 'suppress' ), 'delete', 'deletedhistory' ) ) {
402 if( !$wgUser->isAllowed( 'undelete' ) ) {
403 $viewdeleted = $this->message['undeleteviewlink'];
404 } else {
405 $viewdeleted = $this->message['undeletelink'];
406 }
407 $revert = Linker::link(
408 SpecialPage::getTitleFor( 'Undelete' ),
409 $viewdeleted,
410 array(),
411 array( 'target' => $title->getPrefixedDBkey() ),
412 array( 'known', 'noclasses' )
413 );
414 $revert = wfMessage( 'parentheses' )->rawParams( $revert )->escaped();
415 // Show unblock/change block link
416 } elseif( self::typeAction( $row, array( 'block', 'suppress' ), array( 'block', 'reblock' ), 'block' ) ) {
417 $revert = Linker::link(
418 SpecialPage::getTitleFor( 'Unblock', $row->log_title ),
419 $this->message['unblocklink'],
420 array(),
421 array(),
422 'known'
423 ) .
424 $this->message['pipe-separator'] .
425 Linker::link(
426 SpecialPage::getTitleFor( 'Block', $row->log_title ),
427 $this->message['change-blocklink'],
428 array(),
429 array(),
430 'known'
431 );
432 $revert = wfMessage( 'parentheses' )->rawParams( $revert )->escaped();
433 // Show change protection link
434 } elseif( self::typeAction( $row, 'protect', array( 'modify', 'protect', 'unprotect' ) ) ) {
435 $revert .= Linker::link( $title,
436 $this->message['hist'],
437 array(),
438 array(
439 'action' => 'history',
440 'offset' => $row->log_timestamp
441 )
442 );
443 if( $wgUser->isAllowed( 'protect' ) ) {
444 $revert .= $this->message['pipe-separator'] .
445 Linker::link( $title,
446 $this->message['protect_change'],
447 array(),
448 array( 'action' => 'protect' ),
449 'known' );
450 }
451 $revert = ' ' . wfMessage( 'parentheses' )->rawParams( $revert )->escaped();
452 // Show unmerge link
453 } elseif( self::typeAction( $row, 'merge', 'merge', 'mergehistory' ) ) {
454 $revert = Linker::link(
455 SpecialPage::getTitleFor( 'MergeHistory' ),
456 $this->message['revertmerge'],
457 array(),
458 array(
459 'target' => $paramArray[0],
460 'dest' => $title->getPrefixedDBkey(),
461 'mergepoint' => $paramArray[1]
462 ),
463 array( 'known', 'noclasses' )
464 );
465 $revert = wfMessage( 'parentheses' )->rawParams( $revert )->escaped();
466 // If an edit was hidden from a page give a review link to the history
467 } elseif( self::typeAction( $row, array( 'delete', 'suppress' ), 'revision', 'deletedhistory' ) ) {
468 $revert = RevisionDeleter::getLogLinks( $title, $paramArray,
469 $this->message );
470 // Hidden log items, give review link
471 } elseif( self::typeAction( $row, array( 'delete', 'suppress' ), 'event', 'deletedhistory' ) ) {
472 if( count($paramArray) >= 1 ) {
473 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
474 // $paramArray[1] is a CSV of the IDs
475 $query = $paramArray[0];
476 // Link to each hidden object ID, $paramArray[1] is the url param
477 $revert = Linker::link(
478 $revdel,
479 $this->message['revdel-restore'],
480 array(),
481 array(
482 'target' => $title->getPrefixedText(),
483 'type' => 'logging',
484 'ids' => $query
485 ),
486 array( 'known', 'noclasses' )
487 );
488 $revert = wfMessage( 'parentheses' )->rawParams( $revert )->escaped();
489 }
490 // Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
491 } else {
492 wfRunHooks( 'LogLine', array( $row->log_type, $row->log_action, $title, $paramArray,
493 &$comment, &$revert, $row->log_timestamp ) );
494 }
495 if( $revert != '' ) {
496 $revert = '<span class="mw-logevent-actionlink">' . $revert . '</span>';
497 }
498 return $revert;
499 }
500
501 /**
502 * @param $row Row
503 * @return string
504 */
505 private function getShowHideLinks( $row ) {
506 global $wgUser;
507 if( ( $this->flags & self::NO_ACTION_LINK ) // we don't want to see the links
508 || $row->log_type == 'suppress' ) { // no one can hide items from the suppress log
509 return '';
510 }
511 $del = '';
512 // Don't show useless link to people who cannot hide revisions
513 if( $wgUser->isAllowed( 'deletedhistory' ) ) {
514 if( $row->log_deleted || $wgUser->isAllowed( 'deleterevision' ) ) {
515 $canHide = $wgUser->isAllowed( 'deleterevision' );
516 // If event was hidden from sysops
517 if( !self::userCan( $row, LogPage::DELETED_RESTRICTED ) ) {
518 $del = Xml::check( 'deleterevisions', false, array( 'disabled' => 'disabled' ) );
519 } else {
520 $del = Xml::check( 'showhiderevisions', false, array( 'name' => 'ids[' . $row->log_id . ']' ) );
521 }
522 }
523 }
524 return $del;
525 }
526
527 /**
528 * @param $row Row
529 * @param $type Mixed: string/array
530 * @param $action Mixed: string/array
531 * @param $right string
532 * @return Boolean
533 */
534 public static function typeAction( $row, $type, $action, $right='' ) {
535 $match = is_array($type) ?
536 in_array( $row->log_type, $type ) : $row->log_type == $type;
537 if( $match ) {
538 $match = is_array( $action ) ?
539 in_array( $row->log_action, $action ) : $row->log_action == $action;
540 if( $match && $right ) {
541 global $wgUser;
542 $match = $wgUser->isAllowed( $right );
543 }
544 }
545 return $match;
546 }
547
548 /**
549 * Determine if the current user is allowed to view a particular
550 * field of this log row, if it's marked as deleted.
551 *
552 * @param $row Row
553 * @param $field Integer
554 * @param $user User object to check, or null to use $wgUser
555 * @return Boolean
556 */
557 public static function userCan( $row, $field, User $user = null ) {
558 return self::userCanBitfield( $row->log_deleted, $field, $user );
559 }
560
561 /**
562 * Determine if the current user is allowed to view a particular
563 * field of this log row, if it's marked as deleted.
564 *
565 * @param $bitfield Integer (current field)
566 * @param $field Integer
567 * @param $user User object to check, or null to use $wgUser
568 * @return Boolean
569 */
570 public static function userCanBitfield( $bitfield, $field, User $user = null ) {
571 if( $bitfield & $field ) {
572 if ( $bitfield & LogPage::DELETED_RESTRICTED ) {
573 $permission = 'suppressrevision';
574 } else {
575 $permission = 'deletedhistory';
576 }
577 wfDebug( "Checking for $permission due to $field match on $bitfield\n" );
578 if ( $user === null ) {
579 global $wgUser;
580 $user = $wgUser;
581 }
582 return $user->isAllowed( $permission );
583 } else {
584 return true;
585 }
586 }
587
588 /**
589 * @param $row Row
590 * @param $field Integer: one of DELETED_* bitfield constants
591 * @return Boolean
592 */
593 public static function isDeleted( $row, $field ) {
594 return ( $row->log_deleted & $field ) == $field;
595 }
596
597 /**
598 * Show log extract. Either with text and a box (set $msgKey) or without (don't set $msgKey)
599 *
600 * @param $out OutputPage|String-by-reference
601 * @param $types String|Array Log types to show
602 * @param $page String|Title The page title to show log entries for
603 * @param $user String The user who made the log entries
604 * @param $param array Associative Array with the following additional options:
605 * - lim Integer Limit of items to show, default is 50
606 * - conds Array Extra conditions for the query (e.g. "log_action != 'revision'")
607 * - showIfEmpty boolean Set to false if you don't want any output in case the loglist is empty
608 * if set to true (default), "No matching items in log" is displayed if loglist is empty
609 * - msgKey Array If you want a nice box with a message, set this to the key of the message.
610 * First element is the message key, additional optional elements are parameters for the key
611 * that are processed with wfMsgExt and option 'parse'
612 * - offset Set to overwrite offset parameter in $wgRequest
613 * set to '' to unset offset
614 * - wrap String Wrap the message in html (usually something like "<div ...>$1</div>").
615 * - flags Integer display flags (NO_ACTION_LINK,NO_EXTRA_USER_LINKS)
616 * @return Integer Number of total log items (not limited by $lim)
617 */
618 public static function showLogExtract(
619 &$out, $types=array(), $page='', $user='', $param = array()
620 ) {
621 $defaultParameters = array(
622 'lim' => 25,
623 'conds' => array(),
624 'showIfEmpty' => true,
625 'msgKey' => array(''),
626 'wrap' => "$1",
627 'flags' => 0
628 );
629 # The + operator appends elements of remaining keys from the right
630 # handed array to the left handed, whereas duplicated keys are NOT overwritten.
631 $param += $defaultParameters;
632 # Convert $param array to individual variables
633 $lim = $param['lim'];
634 $conds = $param['conds'];
635 $showIfEmpty = $param['showIfEmpty'];
636 $msgKey = $param['msgKey'];
637 $wrap = $param['wrap'];
638 $flags = $param['flags'];
639 if ( !is_array( $msgKey ) ) {
640 $msgKey = array( $msgKey );
641 }
642
643 if ( $out instanceof OutputPage ) {
644 $context = $out->getContext();
645 } else {
646 $context = RequestContext::getMain();
647 }
648
649 # Insert list of top 50 (or top $lim) items
650 $loglist = new LogEventsList( $context->getSkin(), $context->getOutput(), $flags );
651 $pager = new LogPager( $loglist, $types, $user, $page, '', $conds );
652 if ( isset( $param['offset'] ) ) { # Tell pager to ignore $wgRequest offset
653 $pager->setOffset( $param['offset'] );
654 }
655 if( $lim > 0 ) $pager->mLimit = $lim;
656 $logBody = $pager->getBody();
657 $s = '';
658 if( $logBody ) {
659 if ( $msgKey[0] ) {
660 $s = '<div class="mw-warning-with-logexcerpt">';
661
662 if ( count( $msgKey ) == 1 ) {
663 $s .= wfMsgExt( $msgKey[0], array( 'parse' ) );
664 } else { // Process additional arguments
665 $args = $msgKey;
666 array_shift( $args );
667 $s .= wfMsgExt( $msgKey[0], array( 'parse' ), $args );
668 }
669 }
670 $s .= $loglist->beginLogEventsList() .
671 $logBody .
672 $loglist->endLogEventsList();
673 } else {
674 if ( $showIfEmpty ) {
675 $s = Html::rawElement( 'div', array( 'class' => 'mw-warning-logempty' ),
676 wfMsgExt( 'logempty', array( 'parseinline' ) ) );
677 }
678 }
679 if( $pager->getNumRows() > $pager->mLimit ) { # Show "Full log" link
680 $urlParam = array();
681 if ( $page instanceof Title ) {
682 $urlParam['page'] = $page->getPrefixedDBkey();
683 } elseif ( $page != '' ) {
684 $urlParam['page'] = $page;
685 }
686 if ( $user != '')
687 $urlParam['user'] = $user;
688 if ( !is_array( $types ) ) # Make it an array, if it isn't
689 $types = array( $types );
690 # If there is exactly one log type, we can link to Special:Log?type=foo
691 if ( count( $types ) == 1 )
692 $urlParam['type'] = $types[0];
693 $s .= Linker::link(
694 SpecialPage::getTitleFor( 'Log' ),
695 wfMsgHtml( 'log-fulllog' ),
696 array(),
697 $urlParam
698 );
699 }
700 if ( $logBody && $msgKey[0] ) {
701 $s .= '</div>';
702 }
703
704 if ( $wrap != '' ) { // Wrap message in html
705 $s = str_replace( '$1', $s, $wrap );
706 }
707
708 /* hook can return false, if we don't want the message to be emitted (Wikia BugId:7093) */
709 if ( wfRunHooks( 'LogEventsListShowLogExtract', array( &$s, $types, $page, $user, $param ) ) ) {
710 // $out can be either an OutputPage object or a String-by-reference
711 if ( $out instanceof OutputPage ){
712 $out->addHTML( $s );
713 } else {
714 $out = $s;
715 }
716 }
717
718 return $pager->getNumRows();
719 }
720
721 /**
722 * SQL clause to skip forbidden log types for this user
723 *
724 * @param $db DatabaseBase
725 * @param $audience string, public/user
726 * @return Mixed: string or false
727 */
728 public static function getExcludeClause( $db, $audience = 'public' ) {
729 global $wgLogRestrictions, $wgUser;
730 // Reset the array, clears extra "where" clauses when $par is used
731 $hiddenLogs = array();
732 // Don't show private logs to unprivileged users
733 foreach( $wgLogRestrictions as $logType => $right ) {
734 if( $audience == 'public' || !$wgUser->isAllowed($right) ) {
735 $safeType = $db->strencode( $logType );
736 $hiddenLogs[] = $safeType;
737 }
738 }
739 if( count($hiddenLogs) == 1 ) {
740 return 'log_type != ' . $db->addQuotes( $hiddenLogs[0] );
741 } elseif( $hiddenLogs ) {
742 return 'log_type NOT IN (' . $db->makeList($hiddenLogs) . ')';
743 }
744 return false;
745 }
746 }