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