2 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>, 2008 Aaron Schulz
3 # http://www.mediawiki.org/
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # http://www.gnu.org/copyleft/gpl.html
21 const NO_ACTION_LINK
= 1;
22 const NO_EXTRA_USER_LINKS
= 2;
28 public function __construct( $skin, $out, $flags = 0 ) {
31 $this->flags
= $flags;
32 $this->preCacheMessages();
36 * As we use the same small set of messages in various methods and that
37 * they are called often, we call them once and save them in $this->message
39 private function preCacheMessages() {
40 // Precache various messages
41 if( !isset( $this->message
) ) {
42 $messages = array( 'revertmerge', 'protect_change', 'unblocklink', 'change-blocklink',
43 'revertmove', 'undeletelink', 'undeleteviewlink', 'revdel-restore', 'hist', 'diff',
44 'pipe-separator', 'revdel-restore-deleted', 'revdel-restore-visible' );
45 foreach( $messages as $msg ) {
46 $this->message
[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
52 * Set page title and show header for this log type
55 public function showHeader( $type ) {
56 // If only one log type is used, then show a special message...
57 $headerType = (count($type) == 1) ?
$type[0] : '';
58 if( LogPage
::isLogType( $headerType ) ) {
59 $this->out
->setPageTitle( LogPage
::logName( $headerType ) );
60 $this->out
->addHTML( LogPage
::logHeader( $headerType ) );
62 $this->out
->addHTML( wfMsgExt('alllogstext',array('parseinline')) );
67 * Show options for the log list
69 * @param $types string or Array
72 * @param $pattern String
73 * @param $year Integer: year
74 * @param $month Integer: month
75 * @param $filter: array
76 * @param $tagFilter: array?
78 public function showOptions( $types=array(), $user='', $page='', $pattern='', $year='',
79 $month = '', $filter = null, $tagFilter='' )
81 global $wgScript, $wgMiserMode;
84 $title = SpecialPage
::getTitleFor( 'Log' );
85 $special = $title->getPrefixedDBkey();
87 // For B/C, we take strings, but make sure they are converted...
88 $types = ($types === '') ?
array() : (array)$types;
90 $tagSelector = ChangeTags
::buildTagFilterSelector( $tagFilter );
93 $html .= Xml
::hidden( 'title', $special );
96 $html .= $this->getTypeMenu( $types ) . "\n";
97 $html .= $this->getUserInput( $user ) . "\n";
98 $html .= $this->getTitleInput( $page ) . "\n";
99 $html .= $this->getExtraInputs( $types ) . "\n";
101 // Title pattern, if allowed
103 $html .= $this->getTitlePattern( $pattern ) . "\n";
107 $html .= Xml
::tags( 'p', null, Xml
::dateMenu( $year, $month ) );
111 $html .= Xml
::tags( 'p', null, implode( ' ', $tagSelector ) );
116 $html .= Xml
::tags( 'p', null, $this->getFilterLinks( $filter ) );
120 $html .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) );
123 $html = Xml
::fieldset( wfMsg( 'log' ), $html );
126 $html = Xml
::tags( 'form', array( 'action' => $action, 'method' => 'get' ), $html );
128 $this->out
->addHTML( $html );
132 * @param $filter Array
133 * @return String: Formatted HTML
135 private function getFilterLinks( $filter ) {
136 global $wgTitle, $wgLang;
138 $messages = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
139 // Option value -> message mapping
141 $hiddens = ''; // keep track for "go" button
142 foreach( $filter as $type => $val ) {
143 // Should the below assignment be outside the foreach?
144 // Then it would have to be copied. Not certain what is more expensive.
145 $query = $this->getDefaultQuery();
146 $queryKey = "hide_{$type}_log";
148 $hideVal = 1 - intval($val);
149 $query[$queryKey] = $hideVal;
151 $link = $this->skin
->link(
156 array( 'known', 'noclasses' )
159 $links[$type] = wfMsgHtml( "log-show-hide-{$type}", $link );
160 $hiddens .= Xml
::hidden( "hide_{$type}_log", $val ) . "\n";
163 return '<small>'.$wgLang->pipeList( $links ) . '</small>' . $hiddens;
166 private function getDefaultQuery() {
167 if ( !isset( $this->mDefaultQuery
) ) {
168 $this->mDefaultQuery
= $_GET;
169 unset( $this->mDefaultQuery
['title'] );
170 unset( $this->mDefaultQuery
['dir'] );
171 unset( $this->mDefaultQuery
['offset'] );
172 unset( $this->mDefaultQuery
['limit'] );
173 unset( $this->mDefaultQuery
['order'] );
174 unset( $this->mDefaultQuery
['month'] );
175 unset( $this->mDefaultQuery
['year'] );
177 return $this->mDefaultQuery
;
181 * @param $queryTypes Array
182 * @return String: Formatted HTML
184 private function getTypeMenu( $queryTypes ) {
185 global $wgLogRestrictions, $wgUser;
187 $html = "<select name='type'>\n";
189 $validTypes = LogPage
::validTypes();
190 $typesByName = array(); // Temporary array
192 // First pass to load the log names
193 foreach( $validTypes as $type ) {
194 $text = LogPage
::logName( $type );
195 $typesByName[$type] = $text;
198 // Second pass to sort by name
201 // Note the query type
202 $queryType = count($queryTypes) == 1 ?
$queryTypes[0] : '';
204 // Always put "All public logs" on top
205 if ( isset( $typesByName[''] ) ) {
206 $all = $typesByName[''];
207 unset( $typesByName[''] );
208 $typesByName = array( '' => $all ) +
$typesByName;
211 // Third pass generates sorted XHTML content
212 foreach( $typesByName as $type => $text ) {
213 $selected = ($type == $queryType);
215 if ( isset($wgLogRestrictions[$type]) ) {
216 if ( $wgUser->isAllowed( $wgLogRestrictions[$type] ) ) {
217 $html .= Xml
::option( $text, $type, $selected ) . "\n";
220 $html .= Xml
::option( $text, $type, $selected ) . "\n";
224 $html .= '</select>';
229 * @param $user String
230 * @return String: Formatted HTML
232 private function getUserInput( $user ) {
233 return '<span style="white-space: nowrap">' .
234 Xml
::inputLabel( wfMsg( 'specialloguserlabel' ), 'user', 'mw-log-user', 15, $user ) .
239 * @param $title String
240 * @return String: Formatted HTML
242 private function getTitleInput( $title ) {
243 return '<span style="white-space: nowrap">' .
244 Xml
::inputLabel( wfMsg( 'speciallogtitlelabel' ), 'page', 'mw-log-page', 20, $title ) .
249 * @return boolean Checkbox
251 private function getTitlePattern( $pattern ) {
252 return '<span style="white-space: nowrap">' .
253 Xml
::checkLabel( wfMsg( 'log-title-wildcard' ), 'pattern', 'pattern', $pattern ) .
257 private function getExtraInputs( $types ) {
259 $offender = $wgRequest->getVal('offender');
260 $user = User
::newFromName( $offender, false );
261 if( !$user ||
($user->getId() == 0 && !IP
::isIPAddress($offender) ) ) {
262 $offender = ''; // Blank field if invalid
264 if( count($types) == 1 && $types[0] == 'suppress' ) {
265 return Xml
::inputLabel( wfMsg('revdelete-offender'), 'offender',
266 'mw-log-offender', 20, $offender );
271 public function beginLogEventsList() {
275 public function endLogEventsList() {
280 * @param $row Row: a single row from the result set
281 * @return String: Formatted HTML list item
283 public function logLine( $row ) {
284 $classes = array( 'mw-logline-' . $row->log_type
);
285 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
287 $time = $this->logTimestamp( $row );
289 $userLink = $this->logUserLinks( $row );
290 // Extract extra parameters
291 $paramArray = LogPage
::extractParams( $row->log_params
);
293 $action = $this->logAction( $row, $title, $paramArray );
295 $comment = $this->logComment( $row );
296 // Add review/revert links and such...
297 $revert = $this->logActionLinks( $row, $title, $paramArray, $comment );
299 // Some user can hide log items and have review links
300 $del = $this->getShowHideLinks( $row );
301 if( $del != '' ) $del .= ' ';
304 list( $tagDisplay, $newClasses ) = ChangeTags
::formatSummaryRow( $row->ts_tags
, 'logevent' );
305 $classes = array_merge( $classes, $newClasses );
307 return Xml
::tags( 'li', array( "class" => implode( ' ', $classes ) ),
308 $del . "$time $userLink $action $comment $revert $tagDisplay" ) . "\n";
311 private function logTimestamp( $row ) {
313 $time = $wgLang->timeanddate( wfTimestamp( TS_MW
, $row->log_timestamp
), true );
314 return htmlspecialchars( $time );
317 private function logUserLinks( $row ) {
319 if( self
::isDeleted( $row, LogPage
::DELETED_USER
) ) {
320 $userLinks = '<span class="history-deleted">' .
321 wfMsgHtml( 'rev-deleted-user' ) . '</span>';
323 $userLinks = $this->skin
->userLink( $row->log_user
, $row->user_name
);
324 // Talk|Contribs links...
325 if( !( $this->flags
& self
::NO_EXTRA_USER_LINKS
) ) {
326 $userLinks .= $this->skin
->userToolLinks(
327 $row->log_user
, $row->user_name
, true, 0, $row->user_editcount
);
333 private function logAction( $row, $title, $paramArray ) {
335 if( self
::isDeleted( $row, LogPage
::DELETED_ACTION
) ) {
336 $action = '<span class="history-deleted">' .
337 wfMsgHtml( 'rev-deleted-event' ) . '</span>';
339 $action = LogPage
::actionText(
340 $row->log_type
, $row->log_action
, $title, $this->skin
, $paramArray, true );
345 private function logComment( $row ) {
348 if( self
::isDeleted( $row, LogPage
::DELETED_COMMENT
) ) {
349 $comment = '<span class="history-deleted">' .
350 wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
352 $comment = $wgContLang->getDirMark() .
353 $this->skin
->commentBlock( $row->log_comment
);
359 private function logActionLinks( $row, $title, $paramArray, &$comment ) {
361 if( ( $this->flags
& self
::NO_ACTION_LINK
) // we don't want to see the action
362 || self
::isDeleted( $row, LogPage
::DELETED_ACTION
) ) // action is hidden
367 if( self
::typeAction( $row, 'move', 'move', 'move' ) && !empty( $paramArray[0] ) ) {
368 $destTitle = Title
::newFromText( $paramArray[0] );
370 $revert = '(' . $this->skin
->link(
371 SpecialPage
::getTitleFor( 'Movepage' ),
372 $this->message
['revertmove'],
375 'wpOldTitle' => $destTitle->getPrefixedDBkey(),
376 'wpNewTitle' => $title->getPrefixedDBkey(),
377 'wpReason' => wfMsgForContent( 'revertmove' ),
380 array( 'known', 'noclasses' )
383 // Show undelete link
384 } else if( self
::typeAction( $row, array( 'delete', 'suppress' ), 'delete', 'deletedhistory' ) ) {
385 if( !$wgUser->isAllowed( 'undelete' ) ) {
386 $viewdeleted = $this->message
['undeleteviewlink'];
388 $viewdeleted = $this->message
['undeletelink'];
390 $revert = '(' . $this->skin
->link(
391 SpecialPage
::getTitleFor( 'Undelete' ),
394 array( 'target' => $title->getPrefixedDBkey() ),
395 array( 'known', 'noclasses' )
397 // Show unblock/change block link
398 } else if( self
::typeAction( $row, array( 'block', 'suppress' ), array( 'block', 'reblock' ), 'block' ) ) {
401 SpecialPage
::getTitleFor( 'Ipblocklist' ),
402 $this->message
['unblocklink'],
405 'action' => 'unblock',
406 'ip' => $row->log_title
410 $this->message
['pipe-separator'] .
412 SpecialPage
::getTitleFor( 'Blockip', $row->log_title
),
413 $this->message
['change-blocklink'],
419 // Show change protection link
420 } else if( self
::typeAction( $row, 'protect', array( 'modify', 'protect', 'unprotect' ) ) ) {
422 $this->skin
->link( $title,
423 $this->message
['hist'],
426 'action' => 'history',
427 'offset' => $row->log_timestamp
430 if( $wgUser->isAllowed( 'protect' ) ) {
431 $revert .= $this->message
['pipe-separator'] .
432 $this->skin
->link( $title,
433 $this->message
['protect_change'],
435 array( 'action' => 'protect' ),
440 } else if( self
::typeAction( $row, 'merge', 'merge', 'mergehistory' ) ) {
441 $revert = '(' . $this->skin
->link(
442 SpecialPage
::getTitleFor( 'MergeHistory' ),
443 $this->message
['revertmerge'],
446 'target' => $paramArray[0],
447 'dest' => $title->getPrefixedDBkey(),
448 'mergepoint' => $paramArray[1]
450 array( 'known', 'noclasses' )
452 // If an edit was hidden from a page give a review link to the history
453 } else if( self
::typeAction( $row, array( 'delete', 'suppress' ), 'revision', 'deletedhistory' ) ) {
454 $revert = RevisionDeleter
::getLogLinks( $title, $paramArray,
455 $this->skin
, $this->message
);
456 // Hidden log items, give review link
457 } else if( self
::typeAction( $row, array( 'delete', 'suppress' ), 'event', 'deletedhistory' ) ) {
458 if( count($paramArray) >= 1 ) {
459 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
460 // $paramArray[1] is a CSV of the IDs
461 $Ids = explode( ',', $paramArray[0] );
462 $query = $paramArray[0];
463 // Link to each hidden object ID, $paramArray[1] is the url param
464 $revert = '(' . $this->skin
->link(
466 $this->message
['revdel-restore'],
469 'target' => $title->getPrefixedText(),
473 array( 'known', 'noclasses' )
476 // Self-created users
477 } else if( self
::typeAction( $row, 'newusers', 'create2' ) ) {
478 if( isset( $paramArray[0] ) ) {
479 $revert = $this->skin
->userToolLinks( $paramArray[0], $title->getDBkey(), true );
481 # Fall back to a blue contributions link
482 $revert = $this->skin
->userToolLinks( 1, $title->getDBkey() );
484 $ts = wfTimestamp( TS_UNIX
, $row->log_timestamp
);
485 if( $ts < '20080129000000' ) {
486 # Suppress $comment from old entries (before 2008-01-29),
487 # not needed and can contain incorrect links
490 // Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
492 wfRunHooks( 'LogLine', array( $row->log_type
, $row->log_action
, $title, $paramArray,
493 &$comment, &$revert, $row->log_timestamp
) );
495 if( $revert != '' ) {
496 $revert = '<span class="mw-logevent-actionlink">' . $revert . '</span>';
505 private function getShowHideLinks( $row ) {
507 if( ( $this->flags
& self
::NO_ACTION_LINK
) // we don't want to see the links
508 ||
$row->log_type
== 'suppress' ) // no one can hide items from the suppress log
513 // Don't show useless link to people who cannot hide revisions
514 if( $wgUser->isAllowed( 'deletedhistory' ) ) {
515 if( $row->log_deleted ||
$wgUser->isAllowed( 'deleterevision' ) ) {
516 $canHide = $wgUser->isAllowed( 'deleterevision' );
517 // If event was hidden from sysops
518 if( !self
::userCan( $row, LogPage
::DELETED_RESTRICTED
) ) {
519 $del = $this->skin
->revDeleteLinkDisabled( $canHide );
521 $target = SpecialPage
::getTitleFor( 'Log', $row->log_type
);
523 'target' => $target->getPrefixedDBkey(),
525 'ids' => $row->log_id
,
527 $del = $this->skin
->revDeleteLink( $query,
528 self
::isDeleted( $row, LogPage
::DELETED_RESTRICTED
), $canHide );
537 * @param $type Mixed: string/array
538 * @param $action Mixed: string/array
539 * @param $right string
542 public static function typeAction( $row, $type, $action, $right='' ) {
543 $match = is_array($type) ?
544 in_array( $row->log_type
, $type ) : $row->log_type
== $type;
546 $match = is_array( $action ) ?
547 in_array( $row->log_action
, $action ) : $row->log_action
== $action;
548 if( $match && $right ) {
550 $match = $wgUser->isAllowed( $right );
557 * Determine if the current user is allowed to view a particular
558 * field of this log row, if it's marked as deleted.
561 * @param $field Integer
564 public static function userCan( $row, $field ) {
565 return self
::userCanBitfield( $row->log_deleted
, $field );
569 * Determine if the current user is allowed to view a particular
570 * field of this log row, if it's marked as deleted.
572 * @param $bitfield Integer (current field)
573 * @param $field Integer
576 public static function userCanBitfield( $bitfield, $field ) {
577 if( $bitfield & $field ) {
580 if ( $bitfield & LogPage
::DELETED_RESTRICTED
) {
581 $permission = 'suppressrevision';
583 $permission = 'deletedhistory';
585 wfDebug( "Checking for $permission due to $field match on $bitfield\n" );
586 return $wgUser->isAllowed( $permission );
594 * @param $field Integer: one of DELETED_* bitfield constants
597 public static function isDeleted( $row, $field ) {
598 return ( $row->log_deleted
& $field ) == $field;
602 * Show log extract. Either with text and a box (set $msgKey) or without (don't set $msgKey)
604 * @param $out OutputPage or String-by-reference
605 * @param $types String or Array
606 * @param $page String The page title to show log entries for
607 * @param $user String The user who made the log entries
608 * @param $param Associative Array with the following additional options:
609 * - lim Integer Limit of items to show, default is 50
610 * - conds Array Extra conditions for the query (e.g. "log_action != 'revision'")
611 * - showIfEmpty boolean Set to false if you don't want any output in case the loglist is empty
612 * if set to true (default), "No matching items in log" is displayed if loglist is empty
613 * - msgKey Array If you want a nice box with a message, set this to the key of the message.
614 * First element is the message key, additional optional elements are parameters for the key
615 * that are processed with wgMsgExt and option 'parse'
616 * - offset Set to overwrite offset parameter in $wgRequest
617 * set to '' to unset offset
618 * - wrap String Wrap the message in html (usually something like "<div ...>$1</div>").
619 * - flags Integer display flags (NO_ACTION_LINK,NO_EXTRA_USER_LINKS)
620 * @return Integer Number of total log items (not limited by $lim)
622 public static function showLogExtract(
623 &$out, $types=array(), $page='', $user='', $param = array()
625 global $wgUser, $wgOut;
626 $defaultParameters = array(
629 'showIfEmpty' => true,
630 'msgKey' => array(''),
634 # The + operator appends elements of remaining keys from the right
635 # handed array to the left handed, whereas duplicated keys are NOT overwritten.
636 $param +
= $defaultParameters;
637 # Convert $param array to individual variables
638 $lim = $param['lim'];
639 $conds = $param['conds'];
640 $showIfEmpty = $param['showIfEmpty'];
641 $msgKey = $param['msgKey'];
642 $wrap = $param['wrap'];
643 $flags = $param['flags'];
644 if ( !is_array( $msgKey ) ) {
645 $msgKey = array( $msgKey );
647 # Insert list of top 50 (or top $lim) items
648 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, $flags );
649 $pager = new LogPager( $loglist, $types, $user, $page, '', $conds );
650 if ( isset( $param['offset'] ) ) { # Tell pager to ignore $wgRequest offset
651 $pager->setOffset( $param['offset'] );
653 if( $lim > 0 ) $pager->mLimit
= $lim;
654 $logBody = $pager->getBody();
658 $s = '<div class="mw-warning-with-logexcerpt">';
660 if ( count( $msgKey ) == 1 ) {
661 $s .= wfMsgExt( $msgKey[0], array( 'parse' ) );
662 } else { // Process additional arguments
664 array_shift( $args );
665 $s .= wfMsgExt( $msgKey[0], array( 'parse' ), $args );
668 $s .= $loglist->beginLogEventsList() .
670 $loglist->endLogEventsList();
673 $s = Html
::rawElement( 'div', array( 'class' => 'mw-warning-logempty' ),
674 wfMsgExt( 'logempty', array( 'parseinline' ) ) );
676 if( $pager->getNumRows() > $pager->mLimit
) { # Show "Full log" link
679 $urlParam['page'] = $page;
681 $urlParam['user'] = $user;
682 if ( !is_array( $types ) ) # Make it an array, if it isn't
683 $types = array( $types );
684 # If there is exactly one log type, we can link to Special:Log?type=foo
685 if ( count( $types ) == 1 )
686 $urlParam['type'] = $types[0];
687 $s .= $wgUser->getSkin()->link(
688 SpecialPage
::getTitleFor( 'Log' ),
689 wfMsgHtml( 'log-fulllog' ),
694 if ( $logBody && $msgKey[0] ) {
698 if ( $wrap!='' ) { // Wrap message in html
699 $s = str_replace( '$1', $s, $wrap );
702 // $out can be either an OutputPage object or a String-by-reference
703 if( $out instanceof OutputPage
){
708 return $pager->getNumRows();
712 * SQL clause to skip forbidden log types for this user
714 * @param $db Database
715 * @param $audience string, public/user
716 * @return Mixed: string or false
718 public static function getExcludeClause( $db, $audience = 'public' ) {
719 global $wgLogRestrictions, $wgUser;
720 // Reset the array, clears extra "where" clauses when $par is used
721 $hiddenLogs = array();
722 // Don't show private logs to unprivileged users
723 foreach( $wgLogRestrictions as $logType => $right ) {
724 if( $audience == 'public' ||
!$wgUser->isAllowed($right) ) {
725 $safeType = $db->strencode( $logType );
726 $hiddenLogs[] = $safeType;
729 if( count($hiddenLogs) == 1 ) {
730 return 'log_type != ' . $db->addQuotes( $hiddenLogs[0] );
731 } elseif( $hiddenLogs ) {
732 return 'log_type NOT IN (' . $db->makeList($hiddenLogs) . ')';
741 class LogPager
extends ReverseChronologicalPager
{
742 private $types = array(), $user = '', $title = '', $pattern = '';
743 private $typeCGI = '';
744 public $mLogEventsList;
749 * @param $list LogEventsList
750 * @param $types String or Array: log types to show
751 * @param $user String: the user who made the log entries
752 * @param $title String: the page title the log entries are for
753 * @param $pattern String: do a prefix search rather than an exact title match
754 * @param $conds Array: extra conditions for the query
755 * @param $year Integer: the year to start from
756 * @param $month Integer: the month to start from
757 * @param $tagFilter String: tag
759 public function __construct( $list, $types = array(), $user = '', $title = '', $pattern = '',
760 $conds = array(), $year = false, $month = false, $tagFilter = '' )
762 parent
::__construct();
763 $this->mConds
= $conds;
765 $this->mLogEventsList
= $list;
767 $this->limitType( $types ); // also excludes hidden types
768 $this->limitUser( $user );
769 $this->limitTitle( $title, $pattern );
770 $this->getDateCond( $year, $month );
771 $this->mTagFilter
= $tagFilter;
774 public function getDefaultQuery() {
775 $query = parent
::getDefaultQuery();
776 $query['type'] = $this->typeCGI
; // arrays won't work here
777 $query['user'] = $this->user
;
778 $query['month'] = $this->mMonth
;
779 $query['year'] = $this->mYear
;
783 // Call ONLY after calling $this->limitType() already!
784 public function getFilterParams() {
785 global $wgFilterLogTypes, $wgUser, $wgRequest;
787 if( count($this->types
) ) {
790 foreach( $wgFilterLogTypes as $type => $default ) {
791 // Avoid silly filtering
792 if( $type !== 'patrol' ||
$wgUser->useNPPatrol() ) {
793 $hide = $wgRequest->getInt( "hide_{$type}_log", $default );
794 $filters[$type] = $hide;
796 $this->mConds
[] = 'log_type != ' . $this->mDb
->addQuotes( $type );
803 * Set the log reader to return only entries of the given type.
804 * Type restrictions enforced here
806 * @param $types String or array: Log types ('upload', 'delete', etc);
807 * empty string means no restriction
809 private function limitType( $types ) {
810 global $wgLogRestrictions, $wgUser;
811 // If $types is not an array, make it an array
812 $types = ($types === '') ?
array() : (array)$types;
813 // Don't even show header for private logs; don't recognize it...
814 foreach ( $types as $type ) {
815 if( isset( $wgLogRestrictions[$type] )
816 && !$wgUser->isAllowed($wgLogRestrictions[$type])
818 $types = array_diff( $types, array( $type ) );
821 $this->types
= $types;
822 // Don't show private logs to unprivileged users.
823 // Also, only show them upon specific request to avoid suprises.
824 $audience = $types ?
'user' : 'public';
825 $hideLogs = LogEventsList
::getExcludeClause( $this->mDb
, $audience );
826 if( $hideLogs !== false ) {
827 $this->mConds
[] = $hideLogs;
829 if( count($types) ) {
830 $this->mConds
['log_type'] = $types;
831 // Set typeCGI; used in url param for paging
832 if( count($types) == 1 ) $this->typeCGI
= $types[0];
837 * Set the log reader to return only entries by the given user.
839 * @param $name String: (In)valid user name
841 private function limitUser( $name ) {
845 $usertitle = Title
::makeTitleSafe( NS_USER
, $name );
846 if( is_null($usertitle) ) {
849 /* Fetch userid at first, if known, provides awesome query plan afterwards */
850 $userid = User
::idFromName( $name );
852 /* It should be nicer to abort query at all,
853 but for now it won't pass anywhere behind the optimizer */
854 $this->mConds
[] = "NULL";
857 $this->mConds
['log_user'] = $userid;
858 // Paranoia: avoid brute force searches (bug 17342)
859 if( !$wgUser->isAllowed( 'deletedhistory' ) ) {
860 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::DELETED_USER
) . ' = 0';
861 } else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
862 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::SUPPRESSED_USER
) .
863 ' != ' . LogPage
::SUPPRESSED_USER
;
865 $this->user
= $usertitle->getText();
870 * Set the log reader to return only entries affecting the given page.
871 * (For the block and rights logs, this is a user page.)
873 * @param $page String: Title name as text
874 * @param $pattern String
876 private function limitTitle( $page, $pattern ) {
877 global $wgMiserMode, $wgUser;
879 $title = Title
::newFromText( $page );
880 if( strlen( $page ) == 0 ||
!$title instanceof Title
)
883 $this->title
= $title->getPrefixedText();
884 $ns = $title->getNamespace();
887 # Using the (log_namespace, log_title, log_timestamp) index with a
888 # range scan (LIKE) on the first two parts, instead of simple equality,
889 # makes it unusable for sorting. Sorted retrieval using another index
890 # would be possible, but then we might have to scan arbitrarily many
891 # nodes of that index. Therefore, we need to avoid this if $wgMiserMode
894 # This is not a problem with simple title matches, because then we can
895 # use the page_time index. That should have no more than a few hundred
896 # log entries for even the busiest pages, so it can be safely scanned
897 # in full to satisfy an impossible condition on user or similar.
898 if( $pattern && !$wgMiserMode ) {
899 $this->mConds
['log_namespace'] = $ns;
900 $this->mConds
[] = 'log_title ' . $db->buildLike( $title->getDBkey(), $db->anyString() );
901 $this->pattern
= $pattern;
903 $this->mConds
['log_namespace'] = $ns;
904 $this->mConds
['log_title'] = $title->getDBkey();
906 // Paranoia: avoid brute force searches (bug 17342)
907 if( !$wgUser->isAllowed( 'deletedhistory' ) ) {
908 $this->mConds
[] = $db->bitAnd('log_deleted', LogPage
::DELETED_ACTION
) . ' = 0';
909 } else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
910 $this->mConds
[] = $db->bitAnd('log_deleted', LogPage
::SUPPRESSED_ACTION
) .
911 ' != ' . LogPage
::SUPPRESSED_ACTION
;
915 public function getQueryInfo() {
916 $tables = array( 'logging', 'user' );
917 $this->mConds
[] = 'user_id = log_user';
920 # Add log_search table if there are conditions on it
921 if( array_key_exists('ls_field',$this->mConds
) ) {
922 $tables[] = 'log_search';
923 $index['log_search'] = 'ls_field_val';
924 $index['logging'] = 'PRIMARY';
925 $options[] = 'DISTINCT';
926 # Avoid usage of the wrong index by limiting
927 # the choices of available indexes. This mainly
928 # avoids site-breaking filesorts.
929 } else if( $this->title ||
$this->pattern ||
$this->user
) {
930 $index['logging'] = array( 'page_time', 'user_time' );
931 if( count($this->types
) == 1 ) {
932 $index['logging'][] = 'log_user_type_time';
934 } else if( count($this->types
) == 1 ) {
935 $index['logging'] = 'type_time';
937 $index['logging'] = 'times';
939 $options['USE INDEX'] = $index;
940 # Don't show duplicate rows when using log_search
943 'fields' => array( 'log_type', 'log_action', 'log_user', 'log_namespace',
944 'log_title', 'log_params', 'log_comment', 'log_id', 'log_deleted',
945 'log_timestamp', 'user_name', 'user_editcount' ),
946 'conds' => $this->mConds
,
947 'options' => $options,
948 'join_conds' => array(
949 'user' => array( 'INNER JOIN', 'user_id=log_user' ),
950 'log_search' => array( 'INNER JOIN', 'ls_log_id=log_id' )
953 # Add ChangeTags filter query
954 ChangeTags
::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'],
955 $info['join_conds'], $info['options'], $this->mTagFilter
);
959 function getIndexField() {
960 return 'log_timestamp';
963 public function getStartBody() {
964 wfProfileIn( __METHOD__
);
965 # Do a link batch query
966 if( $this->getNumRows() > 0 ) {
968 while( $row = $this->mResult
->fetchObject() ) {
969 $lb->add( $row->log_namespace
, $row->log_title
);
970 $lb->addObj( Title
::makeTitleSafe( NS_USER
, $row->user_name
) );
971 $lb->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->user_name
) );
974 $this->mResult
->seek( 0 );
976 wfProfileOut( __METHOD__
);
980 public function formatRow( $row ) {
981 return $this->mLogEventsList
->logLine( $row );
984 public function getType() {
988 public function getUser() {
992 public function getPage() {
996 public function getPattern() {
997 return $this->pattern
;
1000 public function getYear() {
1001 return $this->mYear
;
1004 public function getMonth() {
1005 return $this->mMonth
;
1008 public function getTagFilter() {
1009 return $this->mTagFilter
;
1012 public function doQuery() {
1013 // Workaround MySQL optimizer bug
1014 $this->mDb
->setBigSelects();
1016 $this->mDb
->setBigSelects( 'default' );
1022 * @ingroup SpecialPage
1028 * @param $request WebRequest: for internal use use a FauxRequest object to pass arbitrary parameters.
1030 function __construct( $request ) {
1031 global $wgUser, $wgOut;
1032 wfDeprecated(__METHOD__
);
1034 $type = $request->getVal( 'type' );
1035 $user = $request->getText( 'user' );
1036 $title = $request->getText( 'page' );
1037 $pattern = $request->getBool( 'pattern' );
1038 $year = $request->getIntOrNull( 'year' );
1039 $month = $request->getIntOrNull( 'month' );
1040 $tagFilter = $request->getVal( 'tagfilter' );
1041 # Don't let the user get stuck with a certain date
1042 $skip = $request->getText( 'offset' ) ||
$request->getText( 'dir' ) == 'prev';
1047 # Use new list class to output results
1048 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
1049 $this->pager
= new LogPager( $loglist, $type, $user, $title, $pattern, $year, $month, $tagFilter );
1053 * Is there at least one row?
1056 public function hasRows() {
1057 return isset($this->pager
) ?
($this->pager
->getNumRows() > 0) : false;
1063 * @ingroup SpecialPage
1066 const NO_ACTION_LINK
= 1;
1074 * @param &$reader LogReader: where to get our data from
1075 * @param $flags Integer: Bitwise combination of flags:
1076 * LogEventsList::NO_ACTION_LINK Don't show restore/unblock/block links
1078 function __construct( &$reader, $flags = 0 ) {
1079 wfDeprecated(__METHOD__
);
1080 $this->reader
=& $reader;
1081 $this->reader
->pager
->mLogEventsList
->flags
= $flags;
1082 # Aliases for shorter code...
1083 $this->pager
=& $this->reader
->pager
;
1084 $this->list =& $this->reader
->pager
->mLogEventsList
;
1088 * Take over the whole output page in $wgOut with the log display.
1090 public function show() {
1092 # Set title and add header
1093 $this->list->showHeader( $pager->getType() );
1095 $this->list->showOptions( $this->pager
->getType(), $this->pager
->getUser(), $this->pager
->getPage(),
1096 $this->pager
->getPattern(), $this->pager
->getYear(), $this->pager
->getMonth() );
1098 $logBody = $this->pager
->getBody();
1101 $this->pager
->getNavigationBar() .
1102 $this->list->beginLogEventsList() .
1104 $this->list->endLogEventsList() .
1105 $this->pager
->getNavigationBar()
1108 $wgOut->addWikiMsg( 'logempty' );
1113 * Output just the list of entries given by the linked LogReader,
1114 * with extraneous UI elements. Use for displaying log fragments in
1115 * another page (eg at Special:Undelete)
1117 * @param $out OutputPage: where to send output
1119 public function showList( &$out ) {
1120 $logBody = $this->pager
->getBody();
1123 $this->list->beginLogEventsList() .
1125 $this->list->endLogEventsList()
1128 $out->addWikiMsg( 'logempty' );