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