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 ) {
324 if( self
::isDeleted( $row, LogPage
::DELETED_USER
) ) {
325 $userLinks = '<span class="history-deleted">' .
326 wfMsgHtml( 'rev-deleted-user' ) . '</span>';
328 $userLinks = $this->skin
->userLink( $row->log_user
, $row->user_name
);
329 // Talk|Contribs links...
330 if( !( $this->flags
& self
::NO_EXTRA_USER_LINKS
) ) {
331 $userLinks .= $this->skin
->userToolLinks(
332 $row->log_user
, $row->user_name
, true, 0, $row->user_editcount
);
338 private function logAction( $row, $title, $paramArray ) {
339 if( self
::isDeleted( $row, LogPage
::DELETED_ACTION
) ) {
340 $action = '<span class="history-deleted">' .
341 wfMsgHtml( 'rev-deleted-event' ) . '</span>';
343 $action = LogPage
::actionText(
344 $row->log_type
, $row->log_action
, $title, $this->skin
, $paramArray, true );
349 private function logComment( $row ) {
351 if( self
::isDeleted( $row, LogPage
::DELETED_COMMENT
) ) {
352 $comment = '<span class="history-deleted">' .
353 wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
355 $comment = $wgContLang->getDirMark() .
356 $this->skin
->commentBlock( $row->log_comment
);
362 private function logActionLinks( $row, $title, $paramArray, &$comment ) {
364 if( ( $this->flags
& self
::NO_ACTION_LINK
) // we don't want to see the action
365 || self
::isDeleted( $row, LogPage
::DELETED_ACTION
) ) // action is hidden
370 if( self
::typeAction( $row, 'move', 'move', 'move' ) && !empty( $paramArray[0] ) ) {
371 $destTitle = Title
::newFromText( $paramArray[0] );
373 $revert = '(' . $this->skin
->link(
374 SpecialPage
::getTitleFor( 'Movepage' ),
375 $this->message
['revertmove'],
378 'wpOldTitle' => $destTitle->getPrefixedDBkey(),
379 'wpNewTitle' => $title->getPrefixedDBkey(),
380 'wpReason' => wfMsgForContent( 'revertmove' ),
383 array( 'known', 'noclasses' )
386 // Show undelete link
387 } else if( self
::typeAction( $row, array( 'delete', 'suppress' ), 'delete', 'deletedhistory' ) ) {
388 if( !$wgUser->isAllowed( 'undelete' ) ) {
389 $viewdeleted = $this->message
['undeleteviewlink'];
391 $viewdeleted = $this->message
['undeletelink'];
393 $revert = '(' . $this->skin
->link(
394 SpecialPage
::getTitleFor( 'Undelete' ),
397 array( 'target' => $title->getPrefixedDBkey() ),
398 array( 'known', 'noclasses' )
400 // Show unblock/change block link
401 } else if( self
::typeAction( $row, array( 'block', 'suppress' ), array( 'block', 'reblock' ), 'block' ) ) {
404 SpecialPage
::getTitleFor( 'Ipblocklist' ),
405 $this->message
['unblocklink'],
408 'action' => 'unblock',
409 'ip' => $row->log_title
413 $this->message
['pipe-separator'] .
415 SpecialPage
::getTitleFor( 'Blockip', $row->log_title
),
416 $this->message
['change-blocklink'],
422 // Show change protection link
423 } else if( self
::typeAction( $row, 'protect', array( 'modify', 'protect', 'unprotect' ) ) ) {
425 $this->skin
->link( $title,
426 $this->message
['hist'],
429 'action' => 'history',
430 'offset' => $row->log_timestamp
433 if( $wgUser->isAllowed( 'protect' ) ) {
434 $revert .= $this->message
['pipe-separator'] .
435 $this->skin
->link( $title,
436 $this->message
['protect_change'],
438 array( 'action' => 'protect' ),
443 } else if( self
::typeAction( $row, 'merge', 'merge', 'mergehistory' ) ) {
444 $revert = '(' . $this->skin
->link(
445 SpecialPage
::getTitleFor( 'MergeHistory' ),
446 $this->message
['revertmerge'],
449 'target' => $paramArray[0],
450 'dest' => $title->getPrefixedDBkey(),
451 'mergepoint' => $paramArray[1]
453 array( 'known', 'noclasses' )
455 // If an edit was hidden from a page give a review link to the history
456 } else if( self
::typeAction( $row, array( 'delete', 'suppress' ), 'revision', 'deletedhistory' ) ) {
457 $revert = RevisionDeleter
::getLogLinks( $title, $paramArray,
458 $this->skin
, $this->message
);
459 // Hidden log items, give review link
460 } else if( self
::typeAction( $row, array( 'delete', 'suppress' ), 'event', 'deletedhistory' ) ) {
461 if( count($paramArray) >= 1 ) {
462 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
463 // $paramArray[1] is a CSV of the IDs
464 $Ids = explode( ',', $paramArray[0] );
465 $query = $paramArray[0];
466 // Link to each hidden object ID, $paramArray[1] is the url param
467 $revert = '(' . $this->skin
->link(
469 $this->message
['revdel-restore'],
472 'target' => $title->getPrefixedText(),
476 array( 'known', 'noclasses' )
479 // Self-created users
480 } else if( self
::typeAction( $row, 'newusers', 'create2' ) ) {
481 if( isset( $paramArray[0] ) ) {
482 $revert = $this->skin
->userToolLinks( $paramArray[0], $title->getDBkey(), true );
484 # Fall back to a blue contributions link
485 $revert = $this->skin
->userToolLinks( 1, $title->getDBkey() );
487 $ts = wfTimestamp( TS_UNIX
, $row->log_timestamp
);
488 if( $ts < '20080129000000' ) {
489 # Suppress $comment from old entries (before 2008-01-29),
490 # not needed and can contain incorrect links
493 // Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
495 wfRunHooks( 'LogLine', array( $row->log_type
, $row->log_action
, $title, $paramArray,
496 &$comment, &$revert, $row->log_timestamp
) );
498 if( $revert != '' ) {
499 $revert = '<span class="mw-logevent-actionlink">' . $revert . '</span>';
508 private function getShowHideLinks( $row ) {
510 if( ( $this->flags
& self
::NO_ACTION_LINK
) // we don't want to see the links
511 ||
$row->log_type
== 'suppress' ) // no one can hide items from the suppress log
516 // Don't show useless link to people who cannot hide revisions
517 if( $wgUser->isAllowed( 'deletedhistory' ) ) {
518 if( $row->log_deleted ||
$wgUser->isAllowed( 'deleterevision' ) ) {
519 $canHide = $wgUser->isAllowed( 'deleterevision' );
520 // If event was hidden from sysops
521 if( !self
::userCan( $row, LogPage
::DELETED_RESTRICTED
) ) {
522 $del = $this->skin
->revDeleteLinkDisabled( $canHide );
524 $target = SpecialPage
::getTitleFor( 'Log', $row->log_type
);
526 'target' => $target->getPrefixedDBkey(),
528 'ids' => $row->log_id
,
530 $del = $this->skin
->revDeleteLink( $query,
531 self
::isDeleted( $row, LogPage
::DELETED_RESTRICTED
), $canHide );
540 * @param $type Mixed: string/array
541 * @param $action Mixed: string/array
542 * @param $right string
545 public static function typeAction( $row, $type, $action, $right='' ) {
546 $match = is_array($type) ?
547 in_array( $row->log_type
, $type ) : $row->log_type
== $type;
549 $match = is_array( $action ) ?
550 in_array( $row->log_action
, $action ) : $row->log_action
== $action;
551 if( $match && $right ) {
553 $match = $wgUser->isAllowed( $right );
560 * Determine if the current user is allowed to view a particular
561 * field of this log row, if it's marked as deleted.
564 * @param $field Integer
567 public static function userCan( $row, $field ) {
568 return self
::userCanBitfield( $row->log_deleted
, $field );
572 * Determine if the current user is allowed to view a particular
573 * field of this log row, if it's marked as deleted.
575 * @param $bitfield Integer (current field)
576 * @param $field Integer
579 public static function userCanBitfield( $bitfield, $field ) {
580 if( $bitfield & $field ) {
583 if ( $bitfield & LogPage
::DELETED_RESTRICTED
) {
584 $permission = 'suppressrevision';
586 $permission = 'deletedhistory';
588 wfDebug( "Checking for $permission due to $field match on $bitfield\n" );
589 return $wgUser->isAllowed( $permission );
597 * @param $field Integer: one of DELETED_* bitfield constants
600 public static function isDeleted( $row, $field ) {
601 return ( $row->log_deleted
& $field ) == $field;
605 * Show log extract. Either with text and a box (set $msgKey) or without (don't set $msgKey)
607 * @param $out OutputPage or String-by-reference
608 * @param $types String or Array
609 * @param $page String The page title to show log entries for
610 * @param $user String The user who made the log entries
611 * @param $param Associative Array with the following additional options:
612 * - lim Integer Limit of items to show, default is 50
613 * - conds Array Extra conditions for the query (e.g. "log_action != 'revision'")
614 * - showIfEmpty boolean Set to false if you don't want any output in case the loglist is empty
615 * if set to true (default), "No matching items in log" is displayed if loglist is empty
616 * - msgKey Array If you want a nice box with a message, set this to the key of the message.
617 * First element is the message key, additional optional elements are parameters for the key
618 * that are processed with wgMsgExt and option 'parse'
619 * - offset Set to overwrite offset parameter in $wgRequest
620 * set to '' to unset offset
621 * - wrap String Wrap the message in html (usually something like "<div ...>$1</div>").
622 * - flags Integer display flags (NO_ACTION_LINK,NO_EXTRA_USER_LINKS)
623 * @return Integer Number of total log items (not limited by $lim)
625 public static function showLogExtract(
626 &$out, $types=array(), $page='', $user='', $param = array()
628 global $wgUser, $wgOut;
629 $defaultParameters = array(
632 'showIfEmpty' => true,
633 'msgKey' => array(''),
637 # The + operator appends elements of remaining keys from the right
638 # handed array to the left handed, whereas duplicated keys are NOT overwritten.
639 $param +
= $defaultParameters;
640 # Convert $param array to individual variables
641 $lim = $param['lim'];
642 $conds = $param['conds'];
643 $showIfEmpty = $param['showIfEmpty'];
644 $msgKey = $param['msgKey'];
645 $wrap = $param['wrap'];
646 $flags = $param['flags'];
647 if ( !is_array( $msgKey ) ) {
648 $msgKey = array( $msgKey );
650 # Insert list of top 50 (or top $lim) items
651 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, $flags );
652 $pager = new LogPager( $loglist, $types, $user, $page, '', $conds );
653 if ( isset( $param['offset'] ) ) { # Tell pager to ignore $wgRequest offset
654 $pager->setOffset( $param['offset'] );
656 if( $lim > 0 ) $pager->mLimit
= $lim;
657 $logBody = $pager->getBody();
661 $s = '<div class="mw-warning-with-logexcerpt">';
663 if ( count( $msgKey ) == 1 ) {
664 $s .= wfMsgExt( $msgKey[0], array( 'parse' ) );
665 } else { // Process additional arguments
667 array_shift( $args );
668 $s .= wfMsgExt( $msgKey[0], array( 'parse' ), $args );
671 $s .= $loglist->beginLogEventsList() .
673 $loglist->endLogEventsList();
676 $s = Html
::rawElement( 'div', array( 'class' => 'mw-warning-logempty' ),
677 wfMsgExt( 'logempty', array( 'parseinline' ) ) );
679 if( $pager->getNumRows() > $pager->mLimit
) { # Show "Full log" link
682 $urlParam['page'] = $page;
684 $urlParam['user'] = $user;
685 if ( !is_array( $types ) ) # Make it an array, if it isn't
686 $types = array( $types );
687 # If there is exactly one log type, we can link to Special:Log?type=foo
688 if ( count( $types ) == 1 )
689 $urlParam['type'] = $types[0];
690 $s .= $wgUser->getSkin()->link(
691 SpecialPage
::getTitleFor( 'Log' ),
692 wfMsgHtml( 'log-fulllog' ),
697 if ( $logBody && $msgKey[0] ) {
701 if ( $wrap!='' ) { // Wrap message in html
702 $s = str_replace( '$1', $s, $wrap );
705 // $out can be either an OutputPage object or a String-by-reference
706 if( $out instanceof OutputPage
){
711 return $pager->getNumRows();
715 * SQL clause to skip forbidden log types for this user
717 * @param $db Database
718 * @param $audience string, public/user
719 * @return Mixed: string or false
721 public static function getExcludeClause( $db, $audience = 'public' ) {
722 global $wgLogRestrictions, $wgUser;
723 // Reset the array, clears extra "where" clauses when $par is used
724 $hiddenLogs = array();
725 // Don't show private logs to unprivileged users
726 foreach( $wgLogRestrictions as $logType => $right ) {
727 if( $audience == 'public' ||
!$wgUser->isAllowed($right) ) {
728 $safeType = $db->strencode( $logType );
729 $hiddenLogs[] = $safeType;
732 if( count($hiddenLogs) == 1 ) {
733 return 'log_type != ' . $db->addQuotes( $hiddenLogs[0] );
734 } elseif( $hiddenLogs ) {
735 return 'log_type NOT IN (' . $db->makeList($hiddenLogs) . ')';
744 class LogPager
extends ReverseChronologicalPager
{
745 private $types = array(), $user = '', $title = '', $pattern = '';
746 private $typeCGI = '';
747 public $mLogEventsList;
752 * @param $list LogEventsList
753 * @param $types String or Array: log types to show
754 * @param $user String: the user who made the log entries
755 * @param $title String: the page title the log entries are for
756 * @param $pattern String: do a prefix search rather than an exact title match
757 * @param $conds Array: extra conditions for the query
758 * @param $year Integer: the year to start from
759 * @param $month Integer: the month to start from
760 * @param $tagFilter String: tag
762 public function __construct( $list, $types = array(), $user = '', $title = '', $pattern = '',
763 $conds = array(), $year = false, $month = false, $tagFilter = '' )
765 parent
::__construct();
766 $this->mConds
= $conds;
768 $this->mLogEventsList
= $list;
770 $this->limitType( $types ); // also excludes hidden types
771 $this->limitUser( $user );
772 $this->limitTitle( $title, $pattern );
773 $this->getDateCond( $year, $month );
774 $this->mTagFilter
= $tagFilter;
777 public function getDefaultQuery() {
778 $query = parent
::getDefaultQuery();
779 $query['type'] = $this->typeCGI
; // arrays won't work here
780 $query['user'] = $this->user
;
781 $query['month'] = $this->mMonth
;
782 $query['year'] = $this->mYear
;
786 // Call ONLY after calling $this->limitType() already!
787 public function getFilterParams() {
788 global $wgFilterLogTypes, $wgUser, $wgRequest;
790 if( count($this->types
) ) {
793 foreach( $wgFilterLogTypes as $type => $default ) {
794 // Avoid silly filtering
795 if( $type !== 'patrol' ||
$wgUser->useNPPatrol() ) {
796 $hide = $wgRequest->getInt( "hide_{$type}_log", $default );
797 $filters[$type] = $hide;
799 $this->mConds
[] = 'log_type != ' . $this->mDb
->addQuotes( $type );
806 * Set the log reader to return only entries of the given type.
807 * Type restrictions enforced here
809 * @param $types String or array: Log types ('upload', 'delete', etc);
810 * empty string means no restriction
812 private function limitType( $types ) {
813 global $wgLogRestrictions, $wgUser;
814 // If $types is not an array, make it an array
815 $types = ($types === '') ?
array() : (array)$types;
816 // Don't even show header for private logs; don't recognize it...
817 foreach ( $types as $type ) {
818 if( isset( $wgLogRestrictions[$type] )
819 && !$wgUser->isAllowed($wgLogRestrictions[$type])
821 $types = array_diff( $types, array( $type ) );
824 $this->types
= $types;
825 // Don't show private logs to unprivileged users.
826 // Also, only show them upon specific request to avoid suprises.
827 $audience = $types ?
'user' : 'public';
828 $hideLogs = LogEventsList
::getExcludeClause( $this->mDb
, $audience );
829 if( $hideLogs !== false ) {
830 $this->mConds
[] = $hideLogs;
832 if( count($types) ) {
833 $this->mConds
['log_type'] = $types;
834 // Set typeCGI; used in url param for paging
835 if( count($types) == 1 ) $this->typeCGI
= $types[0];
840 * Set the log reader to return only entries by the given user.
842 * @param $name String: (In)valid user name
844 private function limitUser( $name ) {
848 $usertitle = Title
::makeTitleSafe( NS_USER
, $name );
849 if( is_null($usertitle) ) {
852 /* Fetch userid at first, if known, provides awesome query plan afterwards */
853 $userid = User
::idFromName( $name );
855 /* It should be nicer to abort query at all,
856 but for now it won't pass anywhere behind the optimizer */
857 $this->mConds
[] = "NULL";
860 $this->mConds
['log_user'] = $userid;
861 // Paranoia: avoid brute force searches (bug 17342)
862 if( !$wgUser->isAllowed( 'deletedhistory' ) ) {
863 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::DELETED_USER
) . ' = 0';
864 } else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
865 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::SUPPRESSED_USER
) .
866 ' != ' . LogPage
::SUPPRESSED_USER
;
868 $this->user
= $usertitle->getText();
873 * Set the log reader to return only entries affecting the given page.
874 * (For the block and rights logs, this is a user page.)
876 * @param $page String: Title name as text
877 * @param $pattern String
879 private function limitTitle( $page, $pattern ) {
880 global $wgMiserMode, $wgUser;
882 $title = Title
::newFromText( $page );
883 if( strlen( $page ) == 0 ||
!$title instanceof Title
)
886 $this->title
= $title->getPrefixedText();
887 $ns = $title->getNamespace();
890 # Using the (log_namespace, log_title, log_timestamp) index with a
891 # range scan (LIKE) on the first two parts, instead of simple equality,
892 # makes it unusable for sorting. Sorted retrieval using another index
893 # would be possible, but then we might have to scan arbitrarily many
894 # nodes of that index. Therefore, we need to avoid this if $wgMiserMode
897 # This is not a problem with simple title matches, because then we can
898 # use the page_time index. That should have no more than a few hundred
899 # log entries for even the busiest pages, so it can be safely scanned
900 # in full to satisfy an impossible condition on user or similar.
901 if( $pattern && !$wgMiserMode ) {
902 $this->mConds
['log_namespace'] = $ns;
903 $this->mConds
[] = 'log_title ' . $db->buildLike( $title->getDBkey(), $db->anyString() );
904 $this->pattern
= $pattern;
906 $this->mConds
['log_namespace'] = $ns;
907 $this->mConds
['log_title'] = $title->getDBkey();
909 // Paranoia: avoid brute force searches (bug 17342)
910 if( !$wgUser->isAllowed( 'deletedhistory' ) ) {
911 $this->mConds
[] = $db->bitAnd('log_deleted', LogPage
::DELETED_ACTION
) . ' = 0';
912 } else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
913 $this->mConds
[] = $db->bitAnd('log_deleted', LogPage
::SUPPRESSED_ACTION
) .
914 ' != ' . LogPage
::SUPPRESSED_ACTION
;
918 public function getQueryInfo() {
919 $tables = array( 'logging', 'user' );
920 $this->mConds
[] = 'user_id = log_user';
923 # Add log_search table if there are conditions on it
924 if( array_key_exists('ls_field',$this->mConds
) ) {
925 $tables[] = 'log_search';
926 $index['log_search'] = 'ls_field_val';
927 $index['logging'] = 'PRIMARY';
928 $options[] = 'DISTINCT';
929 # Avoid usage of the wrong index by limiting
930 # the choices of available indexes. This mainly
931 # avoids site-breaking filesorts.
932 } else if( $this->title ||
$this->pattern ||
$this->user
) {
933 $index['logging'] = array( 'page_time', 'user_time' );
934 if( count($this->types
) == 1 ) {
935 $index['logging'][] = 'log_user_type_time';
937 } else if( count($this->types
) == 1 ) {
938 $index['logging'] = 'type_time';
940 $index['logging'] = 'times';
942 $options['USE INDEX'] = $index;
943 # Don't show duplicate rows when using log_search
946 'fields' => array( 'log_type', 'log_action', 'log_user', 'log_namespace',
947 'log_title', 'log_params', 'log_comment', 'log_id', 'log_deleted',
948 'log_timestamp', 'user_name', 'user_editcount' ),
949 'conds' => $this->mConds
,
950 'options' => $options,
951 'join_conds' => array(
952 'user' => array( 'INNER JOIN', 'user_id=log_user' ),
953 'log_search' => array( 'INNER JOIN', 'ls_log_id=log_id' )
956 # Add ChangeTags filter query
957 ChangeTags
::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'],
958 $info['join_conds'], $info['options'], $this->mTagFilter
);
962 function getIndexField() {
963 return 'log_timestamp';
966 public function getStartBody() {
967 wfProfileIn( __METHOD__
);
968 # Do a link batch query
969 if( $this->getNumRows() > 0 ) {
971 foreach ( $this->mResult
as $row ) {
972 $lb->add( $row->log_namespace
, $row->log_title
);
973 $lb->addObj( Title
::makeTitleSafe( NS_USER
, $row->user_name
) );
974 $lb->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->user_name
) );
977 $this->mResult
->seek( 0 );
979 wfProfileOut( __METHOD__
);
983 public function formatRow( $row ) {
984 return $this->mLogEventsList
->logLine( $row );
987 public function getType() {
991 public function getUser() {
995 public function getPage() {
999 public function getPattern() {
1000 return $this->pattern
;
1003 public function getYear() {
1004 return $this->mYear
;
1007 public function getMonth() {
1008 return $this->mMonth
;
1011 public function getTagFilter() {
1012 return $this->mTagFilter
;
1015 public function doQuery() {
1016 // Workaround MySQL optimizer bug
1017 $this->mDb
->setBigSelects();
1019 $this->mDb
->setBigSelects( 'default' );
1025 * @ingroup SpecialPage
1031 * @param $request WebRequest: for internal use use a FauxRequest object to pass arbitrary parameters.
1033 function __construct( $request ) {
1034 global $wgUser, $wgOut;
1035 wfDeprecated(__METHOD__
);
1037 $type = $request->getVal( 'type' );
1038 $user = $request->getText( 'user' );
1039 $title = $request->getText( 'page' );
1040 $pattern = $request->getBool( 'pattern' );
1041 $year = $request->getIntOrNull( 'year' );
1042 $month = $request->getIntOrNull( 'month' );
1043 $tagFilter = $request->getVal( 'tagfilter' );
1044 # Don't let the user get stuck with a certain date
1045 $skip = $request->getText( 'offset' ) ||
$request->getText( 'dir' ) == 'prev';
1050 # Use new list class to output results
1051 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
1052 $this->pager
= new LogPager( $loglist, $type, $user, $title, $pattern, $year, $month, $tagFilter );
1056 * Is there at least one row?
1059 public function hasRows() {
1060 return isset($this->pager
) ?
($this->pager
->getNumRows() > 0) : false;
1066 * @ingroup SpecialPage
1069 const NO_ACTION_LINK
= 1;
1077 * @param &$reader LogReader: where to get our data from
1078 * @param $flags Integer: Bitwise combination of flags:
1079 * LogEventsList::NO_ACTION_LINK Don't show restore/unblock/block links
1081 function __construct( &$reader, $flags = 0 ) {
1082 wfDeprecated(__METHOD__
);
1083 $this->reader
=& $reader;
1084 $this->reader
->pager
->mLogEventsList
->flags
= $flags;
1085 # Aliases for shorter code...
1086 $this->pager
=& $this->reader
->pager
;
1087 $this->list =& $this->reader
->pager
->mLogEventsList
;
1091 * Take over the whole output page in $wgOut with the log display.
1093 public function show() {
1095 # Set title and add header
1096 $this->list->showHeader( $pager->getType() );
1098 $this->list->showOptions( $this->pager
->getType(), $this->pager
->getUser(), $this->pager
->getPage(),
1099 $this->pager
->getPattern(), $this->pager
->getYear(), $this->pager
->getMonth() );
1101 $logBody = $this->pager
->getBody();
1104 $this->pager
->getNavigationBar() .
1105 $this->list->beginLogEventsList() .
1107 $this->list->endLogEventsList() .
1108 $this->pager
->getNavigationBar()
1111 $wgOut->addWikiMsg( 'logempty' );
1116 * Output just the list of entries given by the linked LogReader,
1117 * with extraneous UI elements. Use for displaying log fragments in
1118 * another page (eg at Special:Undelete)
1120 * @param $out OutputPage: where to send output
1122 public function showList( &$out ) {
1123 $logBody = $this->pager
->getBody();
1126 $this->list->beginLogEventsList() .
1128 $this->list->endLogEventsList()
1131 $out->addWikiMsg( 'logempty' );