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 );
98 $html = Html
::hidden( 'title', $special );
101 $html .= $this->getTypeMenu( $types ) . "\n";
102 $html .= $this->getUserInput( $user ) . "\n";
103 $html .= $this->getTitleInput( $page ) . "\n";
104 $html .= $this->getExtraInputs( $types ) . "\n";
106 // Title pattern, if allowed
108 $html .= $this->getTitlePattern( $pattern ) . "\n";
112 $html .= Xml
::tags( 'p', null, Xml
::dateMenu( $year, $month ) );
116 $html .= Xml
::tags( 'p', null, implode( ' ', $tagSelector ) );
121 $html .= Xml
::tags( 'p', null, $this->getFilterLinks( $filter ) );
125 $html .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) );
128 $html = Xml
::fieldset( wfMsg( 'log' ), $html );
131 $html = Xml
::tags( 'form', array( 'action' => $action, 'method' => 'get' ), $html );
133 $this->out
->addHTML( $html );
137 * @param $filter Array
138 * @return String: Formatted HTML
140 private function getFilterLinks( $filter ) {
141 global $wgTitle, $wgLang;
143 $messages = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
144 // Option value -> message mapping
146 $hiddens = ''; // keep track for "go" button
147 foreach( $filter as $type => $val ) {
148 // Should the below assignment be outside the foreach?
149 // Then it would have to be copied. Not certain what is more expensive.
150 $query = $this->getDefaultQuery();
151 $queryKey = "hide_{$type}_log";
153 $hideVal = 1 - intval($val);
154 $query[$queryKey] = $hideVal;
156 $link = $this->skin
->link(
161 array( 'known', 'noclasses' )
164 $links[$type] = wfMsgHtml( "log-show-hide-{$type}", $link );
165 $hiddens .= Html
::hidden( "hide_{$type}_log", $val ) . "\n";
168 return '<small>'.$wgLang->pipeList( $links ) . '</small>' . $hiddens;
171 private function getDefaultQuery() {
172 if ( !isset( $this->mDefaultQuery
) ) {
173 $this->mDefaultQuery
= $_GET;
174 unset( $this->mDefaultQuery
['title'] );
175 unset( $this->mDefaultQuery
['dir'] );
176 unset( $this->mDefaultQuery
['offset'] );
177 unset( $this->mDefaultQuery
['limit'] );
178 unset( $this->mDefaultQuery
['order'] );
179 unset( $this->mDefaultQuery
['month'] );
180 unset( $this->mDefaultQuery
['year'] );
182 return $this->mDefaultQuery
;
186 * @param $queryTypes Array
187 * @return String: Formatted HTML
189 private function getTypeMenu( $queryTypes ) {
190 global $wgLogRestrictions, $wgUser;
192 $html = "<select name='type'>\n";
194 $validTypes = LogPage
::validTypes();
195 $typesByName = array(); // Temporary array
197 // First pass to load the log names
198 foreach( $validTypes as $type ) {
199 $text = LogPage
::logName( $type );
200 $typesByName[$type] = $text;
203 // Second pass to sort by name
206 // Note the query type
207 $queryType = count($queryTypes) == 1 ?
$queryTypes[0] : '';
209 // Always put "All public logs" on top
210 if ( isset( $typesByName[''] ) ) {
211 $all = $typesByName[''];
212 unset( $typesByName[''] );
213 $typesByName = array( '' => $all ) +
$typesByName;
216 // Third pass generates sorted XHTML content
217 foreach( $typesByName as $type => $text ) {
218 $selected = ($type == $queryType);
220 if ( isset($wgLogRestrictions[$type]) ) {
221 if ( $wgUser->isAllowed( $wgLogRestrictions[$type] ) ) {
222 $html .= Xml
::option( $text, $type, $selected ) . "\n";
225 $html .= Xml
::option( $text, $type, $selected ) . "\n";
229 $html .= '</select>';
234 * @param $user String
235 * @return String: Formatted HTML
237 private function getUserInput( $user ) {
238 return '<span style="white-space: nowrap">' .
239 Xml
::inputLabel( wfMsg( 'specialloguserlabel' ), 'user', 'mw-log-user', 15, $user ) .
244 * @param $title String
245 * @return String: Formatted HTML
247 private function getTitleInput( $title ) {
248 return '<span style="white-space: nowrap">' .
249 Xml
::inputLabel( wfMsg( 'speciallogtitlelabel' ), 'page', 'mw-log-page', 20, $title ) .
254 * @return boolean Checkbox
256 private function getTitlePattern( $pattern ) {
257 return '<span style="white-space: nowrap">' .
258 Xml
::checkLabel( wfMsg( 'log-title-wildcard' ), 'pattern', 'pattern', $pattern ) .
262 private function getExtraInputs( $types ) {
264 $offender = $wgRequest->getVal('offender');
265 $user = User
::newFromName( $offender, false );
266 if( !$user ||
($user->getId() == 0 && !IP
::isIPAddress($offender) ) ) {
267 $offender = ''; // Blank field if invalid
269 if( count($types) == 1 && $types[0] == 'suppress' ) {
270 return Xml
::inputLabel( wfMsg('revdelete-offender'), 'offender',
271 'mw-log-offender', 20, $offender );
276 public function beginLogEventsList() {
280 public function endLogEventsList() {
285 * @param $row Row: a single row from the result set
286 * @return String: Formatted HTML list item
288 public function logLine( $row ) {
289 $classes = array( 'mw-logline-' . $row->log_type
);
290 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
292 $time = $this->logTimestamp( $row );
294 $userLink = $this->logUserLinks( $row );
295 // Extract extra parameters
296 $paramArray = LogPage
::extractParams( $row->log_params
);
298 $action = $this->logAction( $row, $title, $paramArray );
300 $comment = $this->logComment( $row );
301 // Add review/revert links and such...
302 $revert = $this->logActionLinks( $row, $title, $paramArray, $comment );
304 // Some user can hide log items and have review links
305 $del = $this->getShowHideLinks( $row );
306 if( $del != '' ) $del .= ' ';
309 list( $tagDisplay, $newClasses ) = ChangeTags
::formatSummaryRow( $row->ts_tags
, 'logevent' );
310 $classes = array_merge( $classes, $newClasses );
312 return Xml
::tags( 'li', array( "class" => implode( ' ', $classes ) ),
313 $del . "$time $userLink $action $comment $revert $tagDisplay" ) . "\n";
316 private function logTimestamp( $row ) {
318 $time = $wgLang->timeanddate( wfTimestamp( TS_MW
, $row->log_timestamp
), true );
319 return htmlspecialchars( $time );
322 private function logUserLinks( $row ) {
323 if( self
::isDeleted( $row, LogPage
::DELETED_USER
) ) {
324 $userLinks = '<span class="history-deleted">' .
325 wfMsgHtml( 'rev-deleted-user' ) . '</span>';
327 $userLinks = $this->skin
->userLink( $row->log_user
, $row->user_name
);
328 // Talk|Contribs links...
329 if( !( $this->flags
& self
::NO_EXTRA_USER_LINKS
) ) {
330 $userLinks .= $this->skin
->userToolLinks(
331 $row->log_user
, $row->user_name
, true, 0, $row->user_editcount
);
337 private function logAction( $row, $title, $paramArray ) {
338 if( self
::isDeleted( $row, LogPage
::DELETED_ACTION
) ) {
339 $action = '<span class="history-deleted">' .
340 wfMsgHtml( 'rev-deleted-event' ) . '</span>';
342 $action = LogPage
::actionText(
343 $row->log_type
, $row->log_action
, $title, $this->skin
, $paramArray, true );
348 private function logComment( $row ) {
350 if( self
::isDeleted( $row, LogPage
::DELETED_COMMENT
) ) {
351 $comment = '<span class="history-deleted">' .
352 wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
354 $comment = $wgContLang->getDirMark() .
355 $this->skin
->commentBlock( $row->log_comment
);
361 private function logActionLinks( $row, $title, $paramArray, &$comment ) {
363 if( ( $this->flags
& self
::NO_ACTION_LINK
) // we don't want to see the action
364 || self
::isDeleted( $row, LogPage
::DELETED_ACTION
) ) // action is hidden
369 if( self
::typeAction( $row, 'move', 'move', 'move' ) && !empty( $paramArray[0] ) ) {
370 $destTitle = Title
::newFromText( $paramArray[0] );
372 $revert = '(' . $this->skin
->link(
373 SpecialPage
::getTitleFor( 'Movepage' ),
374 $this->message
['revertmove'],
377 'wpOldTitle' => $destTitle->getPrefixedDBkey(),
378 'wpNewTitle' => $title->getPrefixedDBkey(),
379 'wpReason' => wfMsgForContent( 'revertmove' ),
382 array( 'known', 'noclasses' )
385 // Show undelete link
386 } else if( self
::typeAction( $row, array( 'delete', 'suppress' ), 'delete', 'deletedhistory' ) ) {
387 if( !$wgUser->isAllowed( 'undelete' ) ) {
388 $viewdeleted = $this->message
['undeleteviewlink'];
390 $viewdeleted = $this->message
['undeletelink'];
392 $revert = '(' . $this->skin
->link(
393 SpecialPage
::getTitleFor( 'Undelete' ),
396 array( 'target' => $title->getPrefixedDBkey() ),
397 array( 'known', 'noclasses' )
399 // Show unblock/change block link
400 } else if( self
::typeAction( $row, array( 'block', 'suppress' ), array( 'block', 'reblock' ), 'block' ) ) {
403 SpecialPage
::getTitleFor( 'Ipblocklist' ),
404 $this->message
['unblocklink'],
407 'action' => 'unblock',
408 'ip' => $row->log_title
412 $this->message
['pipe-separator'] .
414 SpecialPage
::getTitleFor( 'Blockip', $row->log_title
),
415 $this->message
['change-blocklink'],
421 // Show change protection link
422 } else if( self
::typeAction( $row, 'protect', array( 'modify', 'protect', 'unprotect' ) ) ) {
424 $this->skin
->link( $title,
425 $this->message
['hist'],
428 'action' => 'history',
429 'offset' => $row->log_timestamp
432 if( $wgUser->isAllowed( 'protect' ) ) {
433 $revert .= $this->message
['pipe-separator'] .
434 $this->skin
->link( $title,
435 $this->message
['protect_change'],
437 array( 'action' => 'protect' ),
442 } else if( self
::typeAction( $row, 'merge', 'merge', 'mergehistory' ) ) {
443 $revert = '(' . $this->skin
->link(
444 SpecialPage
::getTitleFor( 'MergeHistory' ),
445 $this->message
['revertmerge'],
448 'target' => $paramArray[0],
449 'dest' => $title->getPrefixedDBkey(),
450 'mergepoint' => $paramArray[1]
452 array( 'known', 'noclasses' )
454 // If an edit was hidden from a page give a review link to the history
455 } else if( self
::typeAction( $row, array( 'delete', 'suppress' ), 'revision', 'deletedhistory' ) ) {
456 $revert = RevisionDeleter
::getLogLinks( $title, $paramArray,
457 $this->skin
, $this->message
);
458 // Hidden log items, give review link
459 } else if( self
::typeAction( $row, array( 'delete', 'suppress' ), 'event', 'deletedhistory' ) ) {
460 if( count($paramArray) >= 1 ) {
461 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
462 // $paramArray[1] is a CSV of the IDs
463 $Ids = explode( ',', $paramArray[0] );
464 $query = $paramArray[0];
465 // Link to each hidden object ID, $paramArray[1] is the url param
466 $revert = '(' . $this->skin
->link(
468 $this->message
['revdel-restore'],
471 'target' => $title->getPrefixedText(),
475 array( 'known', 'noclasses' )
478 // Self-created users
479 } else if( self
::typeAction( $row, 'newusers', 'create2' ) ) {
480 if( isset( $paramArray[0] ) ) {
481 $revert = $this->skin
->userToolLinks( $paramArray[0], $title->getDBkey(), true );
483 # Fall back to a blue contributions link
484 $revert = $this->skin
->userToolLinks( 1, $title->getDBkey() );
486 $ts = wfTimestamp( TS_UNIX
, $row->log_timestamp
);
487 if( $ts < '20080129000000' ) {
488 # Suppress $comment from old entries (before 2008-01-29),
489 # not needed and can contain incorrect links
492 // Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
494 wfRunHooks( 'LogLine', array( $row->log_type
, $row->log_action
, $title, $paramArray,
495 &$comment, &$revert, $row->log_timestamp
) );
497 if( $revert != '' ) {
498 $revert = '<span class="mw-logevent-actionlink">' . $revert . '</span>';
507 private function getShowHideLinks( $row ) {
509 if( ( $this->flags
& self
::NO_ACTION_LINK
) // we don't want to see the links
510 ||
$row->log_type
== 'suppress' ) // no one can hide items from the suppress log
515 // Don't show useless link to people who cannot hide revisions
516 if( $wgUser->isAllowed( 'deletedhistory' ) ) {
517 if( $row->log_deleted ||
$wgUser->isAllowed( 'deleterevision' ) ) {
518 $canHide = $wgUser->isAllowed( 'deleterevision' );
519 // If event was hidden from sysops
520 if( !self
::userCan( $row, LogPage
::DELETED_RESTRICTED
) ) {
521 $del = $this->skin
->revDeleteLinkDisabled( $canHide );
523 $target = SpecialPage
::getTitleFor( 'Log', $row->log_type
);
525 'target' => $target->getPrefixedDBkey(),
527 'ids' => $row->log_id
,
529 $del = $this->skin
->revDeleteLink( $query,
530 self
::isDeleted( $row, LogPage
::DELETED_RESTRICTED
), $canHide );
539 * @param $type Mixed: string/array
540 * @param $action Mixed: string/array
541 * @param $right string
544 public static function typeAction( $row, $type, $action, $right='' ) {
545 $match = is_array($type) ?
546 in_array( $row->log_type
, $type ) : $row->log_type
== $type;
548 $match = is_array( $action ) ?
549 in_array( $row->log_action
, $action ) : $row->log_action
== $action;
550 if( $match && $right ) {
552 $match = $wgUser->isAllowed( $right );
559 * Determine if the current user is allowed to view a particular
560 * field of this log row, if it's marked as deleted.
563 * @param $field Integer
566 public static function userCan( $row, $field ) {
567 return self
::userCanBitfield( $row->log_deleted
, $field );
571 * Determine if the current user is allowed to view a particular
572 * field of this log row, if it's marked as deleted.
574 * @param $bitfield Integer (current field)
575 * @param $field Integer
578 public static function userCanBitfield( $bitfield, $field ) {
579 if( $bitfield & $field ) {
582 if ( $bitfield & LogPage
::DELETED_RESTRICTED
) {
583 $permission = 'suppressrevision';
585 $permission = 'deletedhistory';
587 wfDebug( "Checking for $permission due to $field match on $bitfield\n" );
588 return $wgUser->isAllowed( $permission );
596 * @param $field Integer: one of DELETED_* bitfield constants
599 public static function isDeleted( $row, $field ) {
600 return ( $row->log_deleted
& $field ) == $field;
604 * Show log extract. Either with text and a box (set $msgKey) or without (don't set $msgKey)
606 * @param $out OutputPage or String-by-reference
607 * @param $types String or Array
608 * @param $page String The page title to show log entries for
609 * @param $user String The user who made the log entries
610 * @param $param Associative Array with the following additional options:
611 * - lim Integer Limit of items to show, default is 50
612 * - conds Array Extra conditions for the query (e.g. "log_action != 'revision'")
613 * - showIfEmpty boolean Set to false if you don't want any output in case the loglist is empty
614 * if set to true (default), "No matching items in log" is displayed if loglist is empty
615 * - msgKey Array If you want a nice box with a message, set this to the key of the message.
616 * First element is the message key, additional optional elements are parameters for the key
617 * that are processed with wgMsgExt and option 'parse'
618 * - offset Set to overwrite offset parameter in $wgRequest
619 * set to '' to unset offset
620 * - wrap String Wrap the message in html (usually something like "<div ...>$1</div>").
621 * - flags Integer display flags (NO_ACTION_LINK,NO_EXTRA_USER_LINKS)
622 * @return Integer Number of total log items (not limited by $lim)
624 public static function showLogExtract(
625 &$out, $types=array(), $page='', $user='', $param = array()
627 global $wgUser, $wgOut;
628 $defaultParameters = array(
631 'showIfEmpty' => true,
632 'msgKey' => array(''),
636 # The + operator appends elements of remaining keys from the right
637 # handed array to the left handed, whereas duplicated keys are NOT overwritten.
638 $param +
= $defaultParameters;
639 # Convert $param array to individual variables
640 $lim = $param['lim'];
641 $conds = $param['conds'];
642 $showIfEmpty = $param['showIfEmpty'];
643 $msgKey = $param['msgKey'];
644 $wrap = $param['wrap'];
645 $flags = $param['flags'];
646 if ( !is_array( $msgKey ) ) {
647 $msgKey = array( $msgKey );
649 # Insert list of top 50 (or top $lim) items
650 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, $flags );
651 $pager = new LogPager( $loglist, $types, $user, $page, '', $conds );
652 if ( isset( $param['offset'] ) ) { # Tell pager to ignore $wgRequest offset
653 $pager->setOffset( $param['offset'] );
655 if( $lim > 0 ) $pager->mLimit
= $lim;
656 $logBody = $pager->getBody();
660 $s = '<div class="mw-warning-with-logexcerpt">';
662 if ( count( $msgKey ) == 1 ) {
663 $s .= wfMsgExt( $msgKey[0], array( 'parse' ) );
664 } else { // Process additional arguments
666 array_shift( $args );
667 $s .= wfMsgExt( $msgKey[0], array( 'parse' ), $args );
670 $s .= $loglist->beginLogEventsList() .
672 $loglist->endLogEventsList();
675 $s = Html
::rawElement( 'div', array( 'class' => 'mw-warning-logempty' ),
676 wfMsgExt( 'logempty', array( 'parseinline' ) ) );
678 if( $pager->getNumRows() > $pager->mLimit
) { # Show "Full log" link
681 $urlParam['page'] = $page;
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 .= $wgUser->getSkin()->link(
690 SpecialPage
::getTitleFor( 'Log' ),
691 wfMsgHtml( 'log-fulllog' ),
696 if ( $logBody && $msgKey[0] ) {
700 if ( $wrap!='' ) { // Wrap message in html
701 $s = str_replace( '$1', $s, $wrap );
704 // $out can be either an OutputPage object or a String-by-reference
705 if( $out instanceof OutputPage
){
710 return $pager->getNumRows();
714 * SQL clause to skip forbidden log types for this user
716 * @param $db Database
717 * @param $audience string, public/user
718 * @return Mixed: string or false
720 public static function getExcludeClause( $db, $audience = 'public' ) {
721 global $wgLogRestrictions, $wgUser;
722 // Reset the array, clears extra "where" clauses when $par is used
723 $hiddenLogs = array();
724 // Don't show private logs to unprivileged users
725 foreach( $wgLogRestrictions as $logType => $right ) {
726 if( $audience == 'public' ||
!$wgUser->isAllowed($right) ) {
727 $safeType = $db->strencode( $logType );
728 $hiddenLogs[] = $safeType;
731 if( count($hiddenLogs) == 1 ) {
732 return 'log_type != ' . $db->addQuotes( $hiddenLogs[0] );
733 } elseif( $hiddenLogs ) {
734 return 'log_type NOT IN (' . $db->makeList($hiddenLogs) . ')';
743 class LogPager
extends ReverseChronologicalPager
{
744 private $types = array(), $user = '', $title = '', $pattern = '';
745 private $typeCGI = '';
746 public $mLogEventsList;
751 * @param $list LogEventsList
752 * @param $types String or Array: log types to show
753 * @param $user String: the user who made the log entries
754 * @param $title String: the page title the log entries are for
755 * @param $pattern String: do a prefix search rather than an exact title match
756 * @param $conds Array: extra conditions for the query
757 * @param $year Integer: the year to start from
758 * @param $month Integer: the month to start from
759 * @param $tagFilter String: tag
761 public function __construct( $list, $types = array(), $user = '', $title = '', $pattern = '',
762 $conds = array(), $year = false, $month = false, $tagFilter = '' )
764 parent
::__construct();
765 $this->mConds
= $conds;
767 $this->mLogEventsList
= $list;
769 $this->limitType( $types ); // also excludes hidden types
770 $this->limitUser( $user );
771 $this->limitTitle( $title, $pattern );
772 $this->getDateCond( $year, $month );
773 $this->mTagFilter
= $tagFilter;
776 public function getDefaultQuery() {
777 $query = parent
::getDefaultQuery();
778 $query['type'] = $this->typeCGI
; // arrays won't work here
779 $query['user'] = $this->user
;
780 $query['month'] = $this->mMonth
;
781 $query['year'] = $this->mYear
;
785 // Call ONLY after calling $this->limitType() already!
786 public function getFilterParams() {
787 global $wgFilterLogTypes, $wgUser, $wgRequest;
789 if( count($this->types
) ) {
792 foreach( $wgFilterLogTypes as $type => $default ) {
793 // Avoid silly filtering
794 if( $type !== 'patrol' ||
$wgUser->useNPPatrol() ) {
795 $hide = $wgRequest->getInt( "hide_{$type}_log", $default );
796 $filters[$type] = $hide;
798 $this->mConds
[] = 'log_type != ' . $this->mDb
->addQuotes( $type );
805 * Set the log reader to return only entries of the given type.
806 * Type restrictions enforced here
808 * @param $types String or array: Log types ('upload', 'delete', etc);
809 * empty string means no restriction
811 private function limitType( $types ) {
812 global $wgLogRestrictions, $wgUser;
813 // If $types is not an array, make it an array
814 $types = ($types === '') ?
array() : (array)$types;
815 // Don't even show header for private logs; don't recognize it...
816 foreach ( $types as $type ) {
817 if( isset( $wgLogRestrictions[$type] )
818 && !$wgUser->isAllowed($wgLogRestrictions[$type])
820 $types = array_diff( $types, array( $type ) );
823 $this->types
= $types;
824 // Don't show private logs to unprivileged users.
825 // Also, only show them upon specific request to avoid suprises.
826 $audience = $types ?
'user' : 'public';
827 $hideLogs = LogEventsList
::getExcludeClause( $this->mDb
, $audience );
828 if( $hideLogs !== false ) {
829 $this->mConds
[] = $hideLogs;
831 if( count($types) ) {
832 $this->mConds
['log_type'] = $types;
833 // Set typeCGI; used in url param for paging
834 if( count($types) == 1 ) $this->typeCGI
= $types[0];
839 * Set the log reader to return only entries by the given user.
841 * @param $name String: (In)valid user name
843 private function limitUser( $name ) {
847 $usertitle = Title
::makeTitleSafe( NS_USER
, $name );
848 if( is_null($usertitle) ) {
851 /* Fetch userid at first, if known, provides awesome query plan afterwards */
852 $userid = User
::idFromName( $name );
854 /* It should be nicer to abort query at all,
855 but for now it won't pass anywhere behind the optimizer */
856 $this->mConds
[] = "NULL";
859 $this->mConds
['log_user'] = $userid;
860 // Paranoia: avoid brute force searches (bug 17342)
861 if( !$wgUser->isAllowed( 'deletedhistory' ) ) {
862 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::DELETED_USER
) . ' = 0';
863 } else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
864 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::SUPPRESSED_USER
) .
865 ' != ' . LogPage
::SUPPRESSED_USER
;
867 $this->user
= $usertitle->getText();
872 * Set the log reader to return only entries affecting the given page.
873 * (For the block and rights logs, this is a user page.)
875 * @param $page String: Title name as text
876 * @param $pattern String
878 private function limitTitle( $page, $pattern ) {
879 global $wgMiserMode, $wgUser;
881 $title = Title
::newFromText( $page );
882 if( strlen( $page ) == 0 ||
!$title instanceof Title
)
885 $this->title
= $title->getPrefixedText();
886 $ns = $title->getNamespace();
889 # Using the (log_namespace, log_title, log_timestamp) index with a
890 # range scan (LIKE) on the first two parts, instead of simple equality,
891 # makes it unusable for sorting. Sorted retrieval using another index
892 # would be possible, but then we might have to scan arbitrarily many
893 # nodes of that index. Therefore, we need to avoid this if $wgMiserMode
896 # This is not a problem with simple title matches, because then we can
897 # use the page_time index. That should have no more than a few hundred
898 # log entries for even the busiest pages, so it can be safely scanned
899 # in full to satisfy an impossible condition on user or similar.
900 if( $pattern && !$wgMiserMode ) {
901 $this->mConds
['log_namespace'] = $ns;
902 $this->mConds
[] = 'log_title ' . $db->buildLike( $title->getDBkey(), $db->anyString() );
903 $this->pattern
= $pattern;
905 $this->mConds
['log_namespace'] = $ns;
906 $this->mConds
['log_title'] = $title->getDBkey();
908 // Paranoia: avoid brute force searches (bug 17342)
909 if( !$wgUser->isAllowed( 'deletedhistory' ) ) {
910 $this->mConds
[] = $db->bitAnd('log_deleted', LogPage
::DELETED_ACTION
) . ' = 0';
911 } else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
912 $this->mConds
[] = $db->bitAnd('log_deleted', LogPage
::SUPPRESSED_ACTION
) .
913 ' != ' . LogPage
::SUPPRESSED_ACTION
;
917 public function getQueryInfo() {
918 $tables = array( 'logging', 'user' );
919 $this->mConds
[] = 'user_id = log_user';
922 # Add log_search table if there are conditions on it
923 if( array_key_exists('ls_field',$this->mConds
) ) {
924 $tables[] = 'log_search';
925 $index['log_search'] = 'ls_field_val';
926 $index['logging'] = 'PRIMARY';
927 $options[] = 'DISTINCT';
928 # Avoid usage of the wrong index by limiting
929 # the choices of available indexes. This mainly
930 # avoids site-breaking filesorts.
931 } else if( $this->title ||
$this->pattern ||
$this->user
) {
932 $index['logging'] = array( 'page_time', 'user_time' );
933 if( count($this->types
) == 1 ) {
934 $index['logging'][] = 'log_user_type_time';
936 } else if( count($this->types
) == 1 ) {
937 $index['logging'] = 'type_time';
939 $index['logging'] = 'times';
941 $options['USE INDEX'] = $index;
942 # Don't show duplicate rows when using log_search
945 'fields' => array( 'log_type', 'log_action', 'log_user', 'log_namespace',
946 'log_title', 'log_params', 'log_comment', 'log_id', 'log_deleted',
947 'log_timestamp', 'user_name', 'user_editcount' ),
948 'conds' => $this->mConds
,
949 'options' => $options,
950 'join_conds' => array(
951 'user' => array( 'INNER JOIN', 'user_id=log_user' ),
952 'log_search' => array( 'INNER JOIN', 'ls_log_id=log_id' )
955 # Add ChangeTags filter query
956 ChangeTags
::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'],
957 $info['join_conds'], $info['options'], $this->mTagFilter
);
961 function getIndexField() {
962 return 'log_timestamp';
965 public function getStartBody() {
966 wfProfileIn( __METHOD__
);
967 # Do a link batch query
968 if( $this->getNumRows() > 0 ) {
970 foreach ( $this->mResult
as $row ) {
971 $lb->add( $row->log_namespace
, $row->log_title
);
972 $lb->addObj( Title
::makeTitleSafe( NS_USER
, $row->user_name
) );
973 $lb->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->user_name
) );
976 $this->mResult
->seek( 0 );
978 wfProfileOut( __METHOD__
);
982 public function formatRow( $row ) {
983 return $this->mLogEventsList
->logLine( $row );
986 public function getType() {
990 public function getUser() {
994 public function getPage() {
998 public function getPattern() {
999 return $this->pattern
;
1002 public function getYear() {
1003 return $this->mYear
;
1006 public function getMonth() {
1007 return $this->mMonth
;
1010 public function getTagFilter() {
1011 return $this->mTagFilter
;
1014 public function doQuery() {
1015 // Workaround MySQL optimizer bug
1016 $this->mDb
->setBigSelects();
1018 $this->mDb
->setBigSelects( 'default' );
1024 * @ingroup SpecialPage
1030 * @param $request WebRequest: for internal use use a FauxRequest object to pass arbitrary parameters.
1032 function __construct( $request ) {
1033 global $wgUser, $wgOut;
1034 wfDeprecated(__METHOD__
);
1036 $type = $request->getVal( 'type' );
1037 $user = $request->getText( 'user' );
1038 $title = $request->getText( 'page' );
1039 $pattern = $request->getBool( 'pattern' );
1040 $year = $request->getIntOrNull( 'year' );
1041 $month = $request->getIntOrNull( 'month' );
1042 $tagFilter = $request->getVal( 'tagfilter' );
1043 # Don't let the user get stuck with a certain date
1044 $skip = $request->getText( 'offset' ) ||
$request->getText( 'dir' ) == 'prev';
1049 # Use new list class to output results
1050 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
1051 $this->pager
= new LogPager( $loglist, $type, $user, $title, $pattern, $year, $month, $tagFilter );
1055 * Is there at least one row?
1058 public function hasRows() {
1059 return isset($this->pager
) ?
($this->pager
->getNumRows() > 0) : false;
1065 * @ingroup SpecialPage
1068 const NO_ACTION_LINK
= 1;
1076 * @param &$reader LogReader: where to get our data from
1077 * @param $flags Integer: Bitwise combination of flags:
1078 * LogEventsList::NO_ACTION_LINK Don't show restore/unblock/block links
1080 function __construct( &$reader, $flags = 0 ) {
1081 wfDeprecated(__METHOD__
);
1082 $this->reader
=& $reader;
1083 $this->reader
->pager
->mLogEventsList
->flags
= $flags;
1084 # Aliases for shorter code...
1085 $this->pager
=& $this->reader
->pager
;
1086 $this->list =& $this->reader
->pager
->mLogEventsList
;
1090 * Take over the whole output page in $wgOut with the log display.
1092 public function show() {
1094 # Set title and add header
1095 $this->list->showHeader( $pager->getType() );
1097 $this->list->showOptions( $this->pager
->getType(), $this->pager
->getUser(), $this->pager
->getPage(),
1098 $this->pager
->getPattern(), $this->pager
->getYear(), $this->pager
->getMonth() );
1100 $logBody = $this->pager
->getBody();
1103 $this->pager
->getNavigationBar() .
1104 $this->list->beginLogEventsList() .
1106 $this->list->endLogEventsList() .
1107 $this->pager
->getNavigationBar()
1110 $wgOut->addWikiMsg( 'logempty' );
1115 * Output just the list of entries given by the linked LogReader,
1116 * with extraneous UI elements. Use for displaying log fragments in
1117 * another page (eg at Special:Undelete)
1119 * @param $out OutputPage: where to send output
1121 public function showList( &$out ) {
1122 $logBody = $this->pager
->getBody();
1125 $this->list->beginLogEventsList() .
1127 $this->list->endLogEventsList()
1130 $out->addWikiMsg( 'logempty' );