3 * Contain classes to list log entries
5 * Copyright © 2004 Brion Vibber <brion@pobox.com>, 2008 Aaron Schulz
6 * http://www.mediawiki.org/
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.
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.
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
27 const NO_ACTION_LINK
= 1;
28 const NO_EXTRA_USER_LINKS
= 2;
34 public function __construct( $skin, $out, $flags = 0 ) {
37 $this->flags
= $flags;
38 $this->preCacheMessages();
42 * As we use the same small set of messages in various methods and that
43 * they are called often, we call them once and save them in $this->message
45 private function preCacheMessages() {
46 // Precache various messages
47 if( !isset( $this->message
) ) {
48 $messages = array( 'revertmerge', 'protect_change', 'unblocklink', 'change-blocklink',
49 'revertmove', 'undeletelink', 'undeleteviewlink', 'revdel-restore', 'hist', 'diff',
50 'pipe-separator', 'revdel-restore-deleted', 'revdel-restore-visible' );
51 foreach( $messages as $msg ) {
52 $this->message
[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
58 * Set page title and show header for this log type
61 public function showHeader( $type ) {
62 // If only one log type is used, then show a special message...
63 $headerType = (count($type) == 1) ?
$type[0] : '';
64 if( LogPage
::isLogType( $headerType ) ) {
65 $this->out
->setPageTitle( LogPage
::logName( $headerType ) );
66 $this->out
->addHTML( LogPage
::logHeader( $headerType ) );
68 $this->out
->addHTML( wfMsgExt('alllogstext',array('parseinline')) );
73 * Show options for the log list
75 * @param $types string or Array
78 * @param $pattern String
79 * @param $year Integer: year
80 * @param $month Integer: month
81 * @param $filter: array
82 * @param $tagFilter: array?
84 public function showOptions( $types=array(), $user='', $page='', $pattern='', $year='',
85 $month = '', $filter = null, $tagFilter='' )
87 global $wgScript, $wgMiserMode;
90 $title = SpecialPage
::getTitleFor( 'Log' );
91 $special = $title->getPrefixedDBkey();
93 // For B/C, we take strings, but make sure they are converted...
94 $types = ($types === '') ?
array() : (array)$types;
96 $tagSelector = ChangeTags
::buildTagFilterSelector( $tagFilter );
99 $html .= Xml
::hidden( 'title', $special );
102 $html .= $this->getTypeMenu( $types ) . "\n";
103 $html .= $this->getUserInput( $user ) . "\n";
104 $html .= $this->getTitleInput( $page ) . "\n";
105 $html .= $this->getExtraInputs( $types ) . "\n";
107 // Title pattern, if allowed
109 $html .= $this->getTitlePattern( $pattern ) . "\n";
113 $html .= Xml
::tags( 'p', null, Xml
::dateMenu( $year, $month ) );
117 $html .= Xml
::tags( 'p', null, implode( ' ', $tagSelector ) );
122 $html .= Xml
::tags( 'p', null, $this->getFilterLinks( $filter ) );
126 $html .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) );
129 $html = Xml
::fieldset( wfMsg( 'log' ), $html );
132 $html = Xml
::tags( 'form', array( 'action' => $action, 'method' => 'get' ), $html );
134 $this->out
->addHTML( $html );
138 * @param $filter Array
139 * @return String: Formatted HTML
141 private function getFilterLinks( $filter ) {
142 global $wgTitle, $wgLang;
144 $messages = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
145 // Option value -> message mapping
147 $hiddens = ''; // keep track for "go" button
148 foreach( $filter as $type => $val ) {
149 // Should the below assignment be outside the foreach?
150 // Then it would have to be copied. Not certain what is more expensive.
151 $query = $this->getDefaultQuery();
152 $queryKey = "hide_{$type}_log";
154 $hideVal = 1 - intval($val);
155 $query[$queryKey] = $hideVal;
157 $link = $this->skin
->link(
162 array( 'known', 'noclasses' )
165 $links[$type] = wfMsgHtml( "log-show-hide-{$type}", $link );
166 $hiddens .= Xml
::hidden( "hide_{$type}_log", $val ) . "\n";
169 return '<small>'.$wgLang->pipeList( $links ) . '</small>' . $hiddens;
172 private function getDefaultQuery() {
173 if ( !isset( $this->mDefaultQuery
) ) {
174 $this->mDefaultQuery
= $_GET;
175 unset( $this->mDefaultQuery
['title'] );
176 unset( $this->mDefaultQuery
['dir'] );
177 unset( $this->mDefaultQuery
['offset'] );
178 unset( $this->mDefaultQuery
['limit'] );
179 unset( $this->mDefaultQuery
['order'] );
180 unset( $this->mDefaultQuery
['month'] );
181 unset( $this->mDefaultQuery
['year'] );
183 return $this->mDefaultQuery
;
187 * @param $queryTypes Array
188 * @return String: Formatted HTML
190 private function getTypeMenu( $queryTypes ) {
191 global $wgLogRestrictions, $wgUser;
193 $html = "<select name='type'>\n";
195 $validTypes = LogPage
::validTypes();
196 $typesByName = array(); // Temporary array
198 // First pass to load the log names
199 foreach( $validTypes as $type ) {
200 $text = LogPage
::logName( $type );
201 $typesByName[$type] = $text;
204 // Second pass to sort by name
207 // Note the query type
208 $queryType = count($queryTypes) == 1 ?
$queryTypes[0] : '';
210 // Always put "All public logs" on top
211 if ( isset( $typesByName[''] ) ) {
212 $all = $typesByName[''];
213 unset( $typesByName[''] );
214 $typesByName = array( '' => $all ) +
$typesByName;
217 // Third pass generates sorted XHTML content
218 foreach( $typesByName as $type => $text ) {
219 $selected = ($type == $queryType);
221 if ( isset($wgLogRestrictions[$type]) ) {
222 if ( $wgUser->isAllowed( $wgLogRestrictions[$type] ) ) {
223 $html .= Xml
::option( $text, $type, $selected ) . "\n";
226 $html .= Xml
::option( $text, $type, $selected ) . "\n";
230 $html .= '</select>';
235 * @param $user String
236 * @return String: Formatted HTML
238 private function getUserInput( $user ) {
239 return '<span style="white-space: nowrap">' .
240 Xml
::inputLabel( wfMsg( 'specialloguserlabel' ), 'user', 'mw-log-user', 15, $user ) .
245 * @param $title String
246 * @return String: Formatted HTML
248 private function getTitleInput( $title ) {
249 return '<span style="white-space: nowrap">' .
250 Xml
::inputLabel( wfMsg( 'speciallogtitlelabel' ), 'page', 'mw-log-page', 20, $title ) .
255 * @return boolean Checkbox
257 private function getTitlePattern( $pattern ) {
258 return '<span style="white-space: nowrap">' .
259 Xml
::checkLabel( wfMsg( 'log-title-wildcard' ), 'pattern', 'pattern', $pattern ) .
263 private function getExtraInputs( $types ) {
265 $offender = $wgRequest->getVal('offender');
266 $user = User
::newFromName( $offender, false );
267 if( !$user ||
($user->getId() == 0 && !IP
::isIPAddress($offender) ) ) {
268 $offender = ''; // Blank field if invalid
270 if( count($types) == 1 && $types[0] == 'suppress' ) {
271 return Xml
::inputLabel( wfMsg('revdelete-offender'), 'offender',
272 'mw-log-offender', 20, $offender );
277 public function beginLogEventsList() {
281 public function endLogEventsList() {
286 * @param $row Row: a single row from the result set
287 * @return String: Formatted HTML list item
289 public function logLine( $row ) {
290 $classes = array( 'mw-logline-' . $row->log_type
);
291 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
293 $time = $this->logTimestamp( $row );
295 $userLink = $this->logUserLinks( $row );
296 // Extract extra parameters
297 $paramArray = LogPage
::extractParams( $row->log_params
);
299 $action = $this->logAction( $row, $title, $paramArray );
301 $comment = $this->logComment( $row );
302 // Add review/revert links and such...
303 $revert = $this->logActionLinks( $row, $title, $paramArray, $comment );
305 // Some user can hide log items and have review links
306 $del = $this->getShowHideLinks( $row );
307 if( $del != '' ) $del .= ' ';
310 list( $tagDisplay, $newClasses ) = ChangeTags
::formatSummaryRow( $row->ts_tags
, 'logevent' );
311 $classes = array_merge( $classes, $newClasses );
313 return Xml
::tags( 'li', array( "class" => implode( ' ', $classes ) ),
314 $del . "$time $userLink $action $comment $revert $tagDisplay" ) . "\n";
317 private function logTimestamp( $row ) {
319 $time = $wgLang->timeanddate( wfTimestamp( TS_MW
, $row->log_timestamp
), true );
320 return htmlspecialchars( $time );
323 private function logUserLinks( $row ) {
325 if( self
::isDeleted( $row, LogPage
::DELETED_USER
) ) {
326 $userLinks = '<span class="history-deleted">' .
327 wfMsgHtml( 'rev-deleted-user' ) . '</span>';
329 $userLinks = $this->skin
->userLink( $row->log_user
, $row->user_name
);
330 // Talk|Contribs links...
331 if( !( $this->flags
& self
::NO_EXTRA_USER_LINKS
) ) {
332 $userLinks .= $this->skin
->userToolLinks(
333 $row->log_user
, $row->user_name
, true, 0, $row->user_editcount
);
339 private function logAction( $row, $title, $paramArray ) {
341 if( self
::isDeleted( $row, LogPage
::DELETED_ACTION
) ) {
342 $action = '<span class="history-deleted">' .
343 wfMsgHtml( 'rev-deleted-event' ) . '</span>';
345 $action = LogPage
::actionText(
346 $row->log_type
, $row->log_action
, $title, $this->skin
, $paramArray, true );
351 private function logComment( $row ) {
354 if( self
::isDeleted( $row, LogPage
::DELETED_COMMENT
) ) {
355 $comment = '<span class="history-deleted">' .
356 wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
358 $comment = $wgContLang->getDirMark() .
359 $this->skin
->commentBlock( $row->log_comment
);
365 private function logActionLinks( $row, $title, $paramArray, &$comment ) {
367 if( ( $this->flags
& self
::NO_ACTION_LINK
) // we don't want to see the action
368 || self
::isDeleted( $row, LogPage
::DELETED_ACTION
) ) // action is hidden
373 if( self
::typeAction( $row, 'move', 'move', 'move' ) && !empty( $paramArray[0] ) ) {
374 $destTitle = Title
::newFromText( $paramArray[0] );
376 $revert = '(' . $this->skin
->link(
377 SpecialPage
::getTitleFor( 'Movepage' ),
378 $this->message
['revertmove'],
381 'wpOldTitle' => $destTitle->getPrefixedDBkey(),
382 'wpNewTitle' => $title->getPrefixedDBkey(),
383 'wpReason' => wfMsgForContent( 'revertmove' ),
386 array( 'known', 'noclasses' )
389 // Show undelete link
390 } else if( self
::typeAction( $row, array( 'delete', 'suppress' ), 'delete', 'deletedhistory' ) ) {
391 if( !$wgUser->isAllowed( 'undelete' ) ) {
392 $viewdeleted = $this->message
['undeleteviewlink'];
394 $viewdeleted = $this->message
['undeletelink'];
396 $revert = '(' . $this->skin
->link(
397 SpecialPage
::getTitleFor( 'Undelete' ),
400 array( 'target' => $title->getPrefixedDBkey() ),
401 array( 'known', 'noclasses' )
403 // Show unblock/change block link
404 } else if( self
::typeAction( $row, array( 'block', 'suppress' ), array( 'block', 'reblock' ), 'block' ) ) {
407 SpecialPage
::getTitleFor( 'Ipblocklist' ),
408 $this->message
['unblocklink'],
411 'action' => 'unblock',
412 'ip' => $row->log_title
416 $this->message
['pipe-separator'] .
418 SpecialPage
::getTitleFor( 'Blockip', $row->log_title
),
419 $this->message
['change-blocklink'],
425 // Show change protection link
426 } else if( self
::typeAction( $row, 'protect', array( 'modify', 'protect', 'unprotect' ) ) ) {
428 $this->skin
->link( $title,
429 $this->message
['hist'],
432 'action' => 'history',
433 'offset' => $row->log_timestamp
436 if( $wgUser->isAllowed( 'protect' ) ) {
437 $revert .= $this->message
['pipe-separator'] .
438 $this->skin
->link( $title,
439 $this->message
['protect_change'],
441 array( 'action' => 'protect' ),
446 } else if( self
::typeAction( $row, 'merge', 'merge', 'mergehistory' ) ) {
447 $revert = '(' . $this->skin
->link(
448 SpecialPage
::getTitleFor( 'MergeHistory' ),
449 $this->message
['revertmerge'],
452 'target' => $paramArray[0],
453 'dest' => $title->getPrefixedDBkey(),
454 'mergepoint' => $paramArray[1]
456 array( 'known', 'noclasses' )
458 // If an edit was hidden from a page give a review link to the history
459 } else if( self
::typeAction( $row, array( 'delete', 'suppress' ), 'revision', 'deletedhistory' ) ) {
460 $revert = RevisionDeleter
::getLogLinks( $title, $paramArray,
461 $this->skin
, $this->message
);
462 // Hidden log items, give review link
463 } else if( self
::typeAction( $row, array( 'delete', 'suppress' ), 'event', 'deletedhistory' ) ) {
464 if( count($paramArray) >= 1 ) {
465 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
466 // $paramArray[1] is a CSV of the IDs
467 $Ids = explode( ',', $paramArray[0] );
468 $query = $paramArray[0];
469 // Link to each hidden object ID, $paramArray[1] is the url param
470 $revert = '(' . $this->skin
->link(
472 $this->message
['revdel-restore'],
475 'target' => $title->getPrefixedText(),
479 array( 'known', 'noclasses' )
482 // Self-created users
483 } else if( self
::typeAction( $row, 'newusers', 'create2' ) ) {
484 if( isset( $paramArray[0] ) ) {
485 $revert = $this->skin
->userToolLinks( $paramArray[0], $title->getDBkey(), true );
487 # Fall back to a blue contributions link
488 $revert = $this->skin
->userToolLinks( 1, $title->getDBkey() );
490 $ts = wfTimestamp( TS_UNIX
, $row->log_timestamp
);
491 if( $ts < '20080129000000' ) {
492 # Suppress $comment from old entries (before 2008-01-29),
493 # not needed and can contain incorrect links
496 // Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
498 wfRunHooks( 'LogLine', array( $row->log_type
, $row->log_action
, $title, $paramArray,
499 &$comment, &$revert, $row->log_timestamp
) );
501 if( $revert != '' ) {
502 $revert = '<span class="mw-logevent-actionlink">' . $revert . '</span>';
511 private function getShowHideLinks( $row ) {
513 if( ( $this->flags
& self
::NO_ACTION_LINK
) // we don't want to see the links
514 ||
$row->log_type
== 'suppress' ) // no one can hide items from the suppress log
519 // Don't show useless link to people who cannot hide revisions
520 if( $wgUser->isAllowed( 'deletedhistory' ) ) {
521 if( $row->log_deleted ||
$wgUser->isAllowed( 'deleterevision' ) ) {
522 $canHide = $wgUser->isAllowed( 'deleterevision' );
523 // If event was hidden from sysops
524 if( !self
::userCan( $row, LogPage
::DELETED_RESTRICTED
) ) {
525 $del = $this->skin
->revDeleteLinkDisabled( $canHide );
527 $target = SpecialPage
::getTitleFor( 'Log', $row->log_type
);
529 'target' => $target->getPrefixedDBkey(),
531 'ids' => $row->log_id
,
533 $del = $this->skin
->revDeleteLink( $query,
534 self
::isDeleted( $row, LogPage
::DELETED_RESTRICTED
), $canHide );
543 * @param $type Mixed: string/array
544 * @param $action Mixed: string/array
545 * @param $right string
548 public static function typeAction( $row, $type, $action, $right='' ) {
549 $match = is_array($type) ?
550 in_array( $row->log_type
, $type ) : $row->log_type
== $type;
552 $match = is_array( $action ) ?
553 in_array( $row->log_action
, $action ) : $row->log_action
== $action;
554 if( $match && $right ) {
556 $match = $wgUser->isAllowed( $right );
563 * Determine if the current user is allowed to view a particular
564 * field of this log row, if it's marked as deleted.
567 * @param $field Integer
570 public static function userCan( $row, $field ) {
571 return self
::userCanBitfield( $row->log_deleted
, $field );
575 * Determine if the current user is allowed to view a particular
576 * field of this log row, if it's marked as deleted.
578 * @param $bitfield Integer (current field)
579 * @param $field Integer
582 public static function userCanBitfield( $bitfield, $field ) {
583 if( $bitfield & $field ) {
586 if ( $bitfield & LogPage
::DELETED_RESTRICTED
) {
587 $permission = 'suppressrevision';
589 $permission = 'deletedhistory';
591 wfDebug( "Checking for $permission due to $field match on $bitfield\n" );
592 return $wgUser->isAllowed( $permission );
600 * @param $field Integer: one of DELETED_* bitfield constants
603 public static function isDeleted( $row, $field ) {
604 return ( $row->log_deleted
& $field ) == $field;
608 * Show log extract. Either with text and a box (set $msgKey) or without (don't set $msgKey)
610 * @param $out OutputPage or String-by-reference
611 * @param $types String or Array
612 * @param $page String The page title to show log entries for
613 * @param $user String The user who made the log entries
614 * @param $param Associative Array with the following additional options:
615 * - lim Integer Limit of items to show, default is 50
616 * - conds Array Extra conditions for the query (e.g. "log_action != 'revision'")
617 * - showIfEmpty boolean Set to false if you don't want any output in case the loglist is empty
618 * if set to true (default), "No matching items in log" is displayed if loglist is empty
619 * - msgKey Array If you want a nice box with a message, set this to the key of the message.
620 * First element is the message key, additional optional elements are parameters for the key
621 * that are processed with wgMsgExt and option 'parse'
622 * - offset Set to overwrite offset parameter in $wgRequest
623 * set to '' to unset offset
624 * - wrap String Wrap the message in html (usually something like "<div ...>$1</div>").
625 * - flags Integer display flags (NO_ACTION_LINK,NO_EXTRA_USER_LINKS)
626 * @return Integer Number of total log items (not limited by $lim)
628 public static function showLogExtract(
629 &$out, $types=array(), $page='', $user='', $param = array()
631 global $wgUser, $wgOut;
632 $defaultParameters = array(
635 'showIfEmpty' => true,
636 'msgKey' => array(''),
640 # The + operator appends elements of remaining keys from the right
641 # handed array to the left handed, whereas duplicated keys are NOT overwritten.
642 $param +
= $defaultParameters;
643 # Convert $param array to individual variables
644 $lim = $param['lim'];
645 $conds = $param['conds'];
646 $showIfEmpty = $param['showIfEmpty'];
647 $msgKey = $param['msgKey'];
648 $wrap = $param['wrap'];
649 $flags = $param['flags'];
650 if ( !is_array( $msgKey ) ) {
651 $msgKey = array( $msgKey );
653 # Insert list of top 50 (or top $lim) items
654 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, $flags );
655 $pager = new LogPager( $loglist, $types, $user, $page, '', $conds );
656 if ( isset( $param['offset'] ) ) { # Tell pager to ignore $wgRequest offset
657 $pager->setOffset( $param['offset'] );
659 if( $lim > 0 ) $pager->mLimit
= $lim;
660 $logBody = $pager->getBody();
664 $s = '<div class="mw-warning-with-logexcerpt">';
666 if ( count( $msgKey ) == 1 ) {
667 $s .= wfMsgExt( $msgKey[0], array( 'parse' ) );
668 } else { // Process additional arguments
670 array_shift( $args );
671 $s .= wfMsgExt( $msgKey[0], array( 'parse' ), $args );
674 $s .= $loglist->beginLogEventsList() .
676 $loglist->endLogEventsList();
679 $s = Html
::rawElement( 'div', array( 'class' => 'mw-warning-logempty' ),
680 wfMsgExt( 'logempty', array( 'parseinline' ) ) );
682 if( $pager->getNumRows() > $pager->mLimit
) { # Show "Full log" link
685 $urlParam['page'] = $page;
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 .= $wgUser->getSkin()->link(
694 SpecialPage
::getTitleFor( 'Log' ),
695 wfMsgHtml( 'log-fulllog' ),
700 if ( $logBody && $msgKey[0] ) {
704 if ( $wrap!='' ) { // Wrap message in html
705 $s = str_replace( '$1', $s, $wrap );
708 // $out can be either an OutputPage object or a String-by-reference
709 if( $out instanceof OutputPage
){
714 return $pager->getNumRows();
718 * SQL clause to skip forbidden log types for this user
720 * @param $db Database
721 * @param $audience string, public/user
722 * @return Mixed: string or false
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;
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) . ')';
747 class LogPager
extends ReverseChronologicalPager
{
748 private $types = array(), $user = '', $title = '', $pattern = '';
749 private $typeCGI = '';
750 public $mLogEventsList;
755 * @param $list LogEventsList
756 * @param $types String or Array: log types to show
757 * @param $user String: the user who made the log entries
758 * @param $title String: the page title the log entries are for
759 * @param $pattern String: do a prefix search rather than an exact title match
760 * @param $conds Array: extra conditions for the query
761 * @param $year Integer: the year to start from
762 * @param $month Integer: the month to start from
763 * @param $tagFilter String: tag
765 public function __construct( $list, $types = array(), $user = '', $title = '', $pattern = '',
766 $conds = array(), $year = false, $month = false, $tagFilter = '' )
768 parent
::__construct();
769 $this->mConds
= $conds;
771 $this->mLogEventsList
= $list;
773 $this->limitType( $types ); // also excludes hidden types
774 $this->limitUser( $user );
775 $this->limitTitle( $title, $pattern );
776 $this->getDateCond( $year, $month );
777 $this->mTagFilter
= $tagFilter;
780 public function getDefaultQuery() {
781 $query = parent
::getDefaultQuery();
782 $query['type'] = $this->typeCGI
; // arrays won't work here
783 $query['user'] = $this->user
;
784 $query['month'] = $this->mMonth
;
785 $query['year'] = $this->mYear
;
789 // Call ONLY after calling $this->limitType() already!
790 public function getFilterParams() {
791 global $wgFilterLogTypes, $wgUser, $wgRequest;
793 if( count($this->types
) ) {
796 foreach( $wgFilterLogTypes as $type => $default ) {
797 // Avoid silly filtering
798 if( $type !== 'patrol' ||
$wgUser->useNPPatrol() ) {
799 $hide = $wgRequest->getInt( "hide_{$type}_log", $default );
800 $filters[$type] = $hide;
802 $this->mConds
[] = 'log_type != ' . $this->mDb
->addQuotes( $type );
809 * Set the log reader to return only entries of the given type.
810 * Type restrictions enforced here
812 * @param $types String or array: Log types ('upload', 'delete', etc);
813 * empty string means no restriction
815 private function limitType( $types ) {
816 global $wgLogRestrictions, $wgUser;
817 // If $types is not an array, make it an array
818 $types = ($types === '') ?
array() : (array)$types;
819 // Don't even show header for private logs; don't recognize it...
820 foreach ( $types as $type ) {
821 if( isset( $wgLogRestrictions[$type] )
822 && !$wgUser->isAllowed($wgLogRestrictions[$type])
824 $types = array_diff( $types, array( $type ) );
827 $this->types
= $types;
828 // Don't show private logs to unprivileged users.
829 // Also, only show them upon specific request to avoid suprises.
830 $audience = $types ?
'user' : 'public';
831 $hideLogs = LogEventsList
::getExcludeClause( $this->mDb
, $audience );
832 if( $hideLogs !== false ) {
833 $this->mConds
[] = $hideLogs;
835 if( count($types) ) {
836 $this->mConds
['log_type'] = $types;
837 // Set typeCGI; used in url param for paging
838 if( count($types) == 1 ) $this->typeCGI
= $types[0];
843 * Set the log reader to return only entries by the given user.
845 * @param $name String: (In)valid user name
847 private function limitUser( $name ) {
851 $usertitle = Title
::makeTitleSafe( NS_USER
, $name );
852 if( is_null($usertitle) ) {
855 /* Fetch userid at first, if known, provides awesome query plan afterwards */
856 $userid = User
::idFromName( $name );
858 /* It should be nicer to abort query at all,
859 but for now it won't pass anywhere behind the optimizer */
860 $this->mConds
[] = "NULL";
863 $this->mConds
['log_user'] = $userid;
864 // Paranoia: avoid brute force searches (bug 17342)
865 if( !$wgUser->isAllowed( 'deletedhistory' ) ) {
866 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::DELETED_USER
) . ' = 0';
867 } else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
868 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::SUPPRESSED_USER
) .
869 ' != ' . LogPage
::SUPPRESSED_USER
;
871 $this->user
= $usertitle->getText();
876 * Set the log reader to return only entries affecting the given page.
877 * (For the block and rights logs, this is a user page.)
879 * @param $page String: Title name as text
880 * @param $pattern String
882 private function limitTitle( $page, $pattern ) {
883 global $wgMiserMode, $wgUser;
885 $title = Title
::newFromText( $page );
886 if( strlen( $page ) == 0 ||
!$title instanceof Title
)
889 $this->title
= $title->getPrefixedText();
890 $ns = $title->getNamespace();
893 # Using the (log_namespace, log_title, log_timestamp) index with a
894 # range scan (LIKE) on the first two parts, instead of simple equality,
895 # makes it unusable for sorting. Sorted retrieval using another index
896 # would be possible, but then we might have to scan arbitrarily many
897 # nodes of that index. Therefore, we need to avoid this if $wgMiserMode
900 # This is not a problem with simple title matches, because then we can
901 # use the page_time index. That should have no more than a few hundred
902 # log entries for even the busiest pages, so it can be safely scanned
903 # in full to satisfy an impossible condition on user or similar.
904 if( $pattern && !$wgMiserMode ) {
905 $this->mConds
['log_namespace'] = $ns;
906 $this->mConds
[] = 'log_title ' . $db->buildLike( $title->getDBkey(), $db->anyString() );
907 $this->pattern
= $pattern;
909 $this->mConds
['log_namespace'] = $ns;
910 $this->mConds
['log_title'] = $title->getDBkey();
912 // Paranoia: avoid brute force searches (bug 17342)
913 if( !$wgUser->isAllowed( 'deletedhistory' ) ) {
914 $this->mConds
[] = $db->bitAnd('log_deleted', LogPage
::DELETED_ACTION
) . ' = 0';
915 } else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
916 $this->mConds
[] = $db->bitAnd('log_deleted', LogPage
::SUPPRESSED_ACTION
) .
917 ' != ' . LogPage
::SUPPRESSED_ACTION
;
921 public function getQueryInfo() {
922 $tables = array( 'logging', 'user' );
923 $this->mConds
[] = 'user_id = log_user';
926 # Add log_search table if there are conditions on it
927 if( array_key_exists('ls_field',$this->mConds
) ) {
928 $tables[] = 'log_search';
929 $index['log_search'] = 'ls_field_val';
930 $index['logging'] = 'PRIMARY';
931 $options[] = 'DISTINCT';
932 # Avoid usage of the wrong index by limiting
933 # the choices of available indexes. This mainly
934 # avoids site-breaking filesorts.
935 } else if( $this->title ||
$this->pattern ||
$this->user
) {
936 $index['logging'] = array( 'page_time', 'user_time' );
937 if( count($this->types
) == 1 ) {
938 $index['logging'][] = 'log_user_type_time';
940 } else if( count($this->types
) == 1 ) {
941 $index['logging'] = 'type_time';
943 $index['logging'] = 'times';
945 $options['USE INDEX'] = $index;
946 # Don't show duplicate rows when using log_search
949 'fields' => array( 'log_type', 'log_action', 'log_user', 'log_namespace',
950 'log_title', 'log_params', 'log_comment', 'log_id', 'log_deleted',
951 'log_timestamp', 'user_name', 'user_editcount' ),
952 'conds' => $this->mConds
,
953 'options' => $options,
954 'join_conds' => array(
955 'user' => array( 'INNER JOIN', 'user_id=log_user' ),
956 'log_search' => array( 'INNER JOIN', 'ls_log_id=log_id' )
959 # Add ChangeTags filter query
960 ChangeTags
::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'],
961 $info['join_conds'], $info['options'], $this->mTagFilter
);
965 function getIndexField() {
966 return 'log_timestamp';
969 public function getStartBody() {
970 wfProfileIn( __METHOD__
);
971 # Do a link batch query
972 if( $this->getNumRows() > 0 ) {
974 while( $row = $this->mResult
->fetchObject() ) {
975 $lb->add( $row->log_namespace
, $row->log_title
);
976 $lb->addObj( Title
::makeTitleSafe( NS_USER
, $row->user_name
) );
977 $lb->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->user_name
) );
980 $this->mResult
->seek( 0 );
982 wfProfileOut( __METHOD__
);
986 public function formatRow( $row ) {
987 return $this->mLogEventsList
->logLine( $row );
990 public function getType() {
994 public function getUser() {
998 public function getPage() {
1002 public function getPattern() {
1003 return $this->pattern
;
1006 public function getYear() {
1007 return $this->mYear
;
1010 public function getMonth() {
1011 return $this->mMonth
;
1014 public function getTagFilter() {
1015 return $this->mTagFilter
;
1018 public function doQuery() {
1019 // Workaround MySQL optimizer bug
1020 $this->mDb
->setBigSelects();
1022 $this->mDb
->setBigSelects( 'default' );
1028 * @ingroup SpecialPage
1034 * @param $request WebRequest: for internal use use a FauxRequest object to pass arbitrary parameters.
1036 function __construct( $request ) {
1037 global $wgUser, $wgOut;
1038 wfDeprecated(__METHOD__
);
1040 $type = $request->getVal( 'type' );
1041 $user = $request->getText( 'user' );
1042 $title = $request->getText( 'page' );
1043 $pattern = $request->getBool( 'pattern' );
1044 $year = $request->getIntOrNull( 'year' );
1045 $month = $request->getIntOrNull( 'month' );
1046 $tagFilter = $request->getVal( 'tagfilter' );
1047 # Don't let the user get stuck with a certain date
1048 $skip = $request->getText( 'offset' ) ||
$request->getText( 'dir' ) == 'prev';
1053 # Use new list class to output results
1054 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
1055 $this->pager
= new LogPager( $loglist, $type, $user, $title, $pattern, $year, $month, $tagFilter );
1059 * Is there at least one row?
1062 public function hasRows() {
1063 return isset($this->pager
) ?
($this->pager
->getNumRows() > 0) : false;
1069 * @ingroup SpecialPage
1072 const NO_ACTION_LINK
= 1;
1080 * @param &$reader LogReader: where to get our data from
1081 * @param $flags Integer: Bitwise combination of flags:
1082 * LogEventsList::NO_ACTION_LINK Don't show restore/unblock/block links
1084 function __construct( &$reader, $flags = 0 ) {
1085 wfDeprecated(__METHOD__
);
1086 $this->reader
=& $reader;
1087 $this->reader
->pager
->mLogEventsList
->flags
= $flags;
1088 # Aliases for shorter code...
1089 $this->pager
=& $this->reader
->pager
;
1090 $this->list =& $this->reader
->pager
->mLogEventsList
;
1094 * Take over the whole output page in $wgOut with the log display.
1096 public function show() {
1098 # Set title and add header
1099 $this->list->showHeader( $pager->getType() );
1101 $this->list->showOptions( $this->pager
->getType(), $this->pager
->getUser(), $this->pager
->getPage(),
1102 $this->pager
->getPattern(), $this->pager
->getYear(), $this->pager
->getMonth() );
1104 $logBody = $this->pager
->getBody();
1107 $this->pager
->getNavigationBar() .
1108 $this->list->beginLogEventsList() .
1110 $this->list->endLogEventsList() .
1111 $this->pager
->getNavigationBar()
1114 $wgOut->addWikiMsg( 'logempty' );
1119 * Output just the list of entries given by the linked LogReader,
1120 * with extraneous UI elements. Use for displaying log fragments in
1121 * another page (eg at Special:Undelete)
1123 * @param $out OutputPage: where to send output
1125 public function showList( &$out ) {
1126 $logBody = $this->pager
->getBody();
1129 $this->list->beginLogEventsList() .
1131 $this->list->endLogEventsList()
1134 $out->addWikiMsg( 'logempty' );