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;
27 public function __construct( $skin, $out, $flags = 0 ) {
30 $this->flags
= $flags;
31 $this->preCacheMessages();
35 * As we use the same small set of messages in various methods and that
36 * they are called often, we call them once and save them in $this->message
38 private function preCacheMessages() {
39 // Precache various messages
40 if( !isset( $this->message
) ) {
41 $messages = array( 'revertmerge', 'protect_change', 'unblocklink', 'change-blocklink',
42 'revertmove', 'undeletelink', 'undeleteviewlink', 'revdel-restore', 'rev-delundel', 'hist', 'diff',
44 foreach( $messages as $msg ) {
45 $this->message
[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
51 * Set page title and show header for this log type
54 public function showHeader( $type ) {
55 // If only one log type is used, then show a special message...
56 $headerType = (count($type) == 1) ?
$type[0] : '';
57 if( LogPage
::isLogType( $headerType ) ) {
58 $this->out
->setPageTitle( LogPage
::logName( $headerType ) );
59 $this->out
->addHTML( LogPage
::logHeader( $headerType ) );
61 $this->out
->addHTML( wfMsgExt('alllogstext',array('parseinline')) );
66 * Show options for the log list
67 * @param $types string or Array
70 * @param $pattern String
71 * @param $year Integer: year
72 * @param $month Integer: month
73 * @param $filter: array
74 * @param $tagFilter: array?
76 public function showOptions( $types=array(), $user='', $page='', $pattern='', $year='',
77 $month = '', $filter = null, $tagFilter='' )
79 global $wgScript, $wgMiserMode;
82 $title = SpecialPage
::getTitleFor( 'Log' );
83 $special = $title->getPrefixedDBkey();
85 // For B/C, we take strings, but make sure they are converted...
86 $types = ($types === '') ?
array() : (array)$types;
88 $tagSelector = ChangeTags
::buildTagFilterSelector( $tagFilter );
91 $html .= Xml
::hidden( 'title', $special );
94 $html .= $this->getTypeMenu( $types ) . "\n";
95 $html .= $this->getUserInput( $user ) . "\n";
96 $html .= $this->getTitleInput( $page ) . "\n";
97 $html .= $this->getExtraInputs( $types ) . "\n";
99 // Title pattern, if allowed
101 $html .= $this->getTitlePattern( $pattern ) . "\n";
105 $html .= Xml
::tags( 'p', null, Xml
::dateMenu( $year, $month ) );
109 $html .= Xml
::tags( 'p', null, implode( ' ', $tagSelector ) );
114 $html .= Xml
::tags( 'p', null, $this->getFilterLinks( $filter ) );
118 $html .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) );
121 $html = Xml
::fieldset( wfMsg( 'log' ), $html );
124 $html = Xml
::tags( 'form', array( 'action' => $action, 'method' => 'get' ), $html );
126 $this->out
->addHTML( $html );
130 * @param $filter Array
131 * @return String: Formatted HTML
133 private function getFilterLinks( $filter ) {
134 global $wgTitle, $wgLang;
136 $messages = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
137 // Option value -> message mapping
139 $hiddens = ''; // keep track for "go" button
140 foreach( $filter as $type => $val ) {
141 // Should the below assignment be outside the foreach?
142 // Then it would have to be copied. Not certain what is more expensive.
143 $query = $this->getDefaultQuery();
144 $queryKey = "hide_{$type}_log";
146 $hideVal = 1 - intval($val);
147 $query[$queryKey] = $hideVal;
149 $link = $this->skin
->link(
154 array( 'known', 'noclasses' )
157 $links[$type] = wfMsgHtml( "log-show-hide-{$type}", $link );
158 $hiddens .= Xml
::hidden( "hide_{$type}_log", $val ) . "\n";
161 return '<small>'.$wgLang->pipeList( $links ) . '</small>' . $hiddens;
164 private function getDefaultQuery() {
165 if ( !isset( $this->mDefaultQuery
) ) {
166 $this->mDefaultQuery
= $_GET;
167 unset( $this->mDefaultQuery
['title'] );
168 unset( $this->mDefaultQuery
['dir'] );
169 unset( $this->mDefaultQuery
['offset'] );
170 unset( $this->mDefaultQuery
['limit'] );
171 unset( $this->mDefaultQuery
['order'] );
172 unset( $this->mDefaultQuery
['month'] );
173 unset( $this->mDefaultQuery
['year'] );
175 return $this->mDefaultQuery
;
179 * @param $queryTypes Array
180 * @return String: Formatted HTML
182 private function getTypeMenu( $queryTypes ) {
183 global $wgLogRestrictions, $wgUser;
185 $html = "<select name='type'>\n";
187 $validTypes = LogPage
::validTypes();
188 $typesByName = array(); // Temporary array
190 // First pass to load the log names
191 foreach( $validTypes as $type ) {
192 $text = LogPage
::logName( $type );
193 $typesByName[$text] = $type;
196 // Second pass to sort by name
199 // Note the query type
200 $queryType = count($queryTypes) == 1 ?
$queryTypes[0] : '';
201 // Third pass generates sorted XHTML content
202 foreach( $typesByName as $text => $type ) {
203 $selected = ($type == $queryType);
205 if ( isset($wgLogRestrictions[$type]) ) {
206 if ( $wgUser->isAllowed( $wgLogRestrictions[$type] ) ) {
207 $html .= Xml
::option( $text, $type, $selected ) . "\n";
210 $html .= Xml
::option( $text, $type, $selected ) . "\n";
214 $html .= '</select>';
219 * @param $user String
220 * @return String: Formatted HTML
222 private function getUserInput( $user ) {
223 return Xml
::inputLabel( wfMsg( 'specialloguserlabel' ), 'user', 'mw-log-user', 15, $user );
227 * @param $title String
228 * @return String: Formatted HTML
230 private function getTitleInput( $title ) {
231 return Xml
::inputLabel( wfMsg( 'speciallogtitlelabel' ), 'page', 'mw-log-page', 20, $title );
235 * @return boolean Checkbox
237 private function getTitlePattern( $pattern ) {
238 return '<span style="white-space: nowrap">' .
239 Xml
::checkLabel( wfMsg( 'log-title-wildcard' ), 'pattern', 'pattern', $pattern ) .
243 private function getExtraInputs( $types ) {
245 $offender = $wgRequest->getVal('offender');
246 $user = User
::newFromName( $offender, false );
247 if( !$user ||
($user->getId() == 0 && !IP
::isIPAddress($offender) ) ) {
248 $offender = ''; // Blank field if invalid
250 if( count($types) == 1 && $types[0] == 'suppress' ) {
251 return Xml
::inputLabel( wfMsg('revdelete-offender'), 'offender',
252 'mw-log-offender', 20, $offender );
257 public function beginLogEventsList() {
261 public function endLogEventsList() {
266 * @param $row Row: a single row from the result set
267 * @return String: Formatted HTML list item
269 public function logLine( $row ) {
270 global $wgLang, $wgUser, $wgContLang;
272 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
273 $classes = array( "mw-logline-{$row->log_type}" );
274 $time = $wgLang->timeanddate( wfTimestamp( TS_MW
, $row->log_timestamp
), true );
276 if( self
::isDeleted( $row, LogPage
::DELETED_USER
) ) {
277 $userLink = '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
279 $userLink = $this->skin
->userLink( $row->log_user
, $row->user_name
) .
280 $this->skin
->userToolLinks( $row->log_user
, $row->user_name
, true, 0, $row->user_editcount
);
283 if( self
::isDeleted( $row, LogPage
::DELETED_COMMENT
) ) {
284 $comment = '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
286 $comment = $wgContLang->getDirMark() . $this->skin
->commentBlock( $row->log_comment
);
288 // Extract extra parameters
289 $paramArray = LogPage
::extractParams( $row->log_params
);
291 // Some user can hide log items and have review links
292 if( !( $this->flags
& self
::NO_ACTION_LINK
) && $wgUser->isAllowed( 'deletedhistory' ) ) {
293 // Don't show useless link to people who cannot hide revisions
294 if( $row->log_deleted ||
$wgUser->isAllowed( 'deleterevision' ) ) {
295 $del = $this->getShowHideLinks( $row ) . ' ';
298 // Add review links and such...
299 if( ( $this->flags
& self
::NO_ACTION_LINK
) ||
( $row->log_deleted
& LogPage
::DELETED_ACTION
) ) {
300 // Action text is suppressed...
301 } else if( self
::typeAction( $row, 'move', 'move', 'move' ) && !empty( $paramArray[0] ) ) {
302 $destTitle = Title
::newFromText( $paramArray[0] );
304 $revert = '(' . $this->skin
->link(
305 SpecialPage
::getTitleFor( 'Movepage' ),
306 $this->message
['revertmove'],
309 'wpOldTitle' => $destTitle->getPrefixedDBkey(),
310 'wpNewTitle' => $title->getPrefixedDBkey(),
311 'wpReason' => wfMsgForContent( 'revertmove' ),
314 array( 'known', 'noclasses' )
317 // Show undelete link
318 } else if( self
::typeAction( $row, array( 'delete', 'suppress' ), 'delete', 'deletedhistory' ) ) {
319 if( !$wgUser->isAllowed( 'undelete' ) ) {
320 $viewdeleted = $this->message
['undeleteviewlink'];
322 $viewdeleted = $this->message
['undeletelink'];
325 $revert = '(' . $this->skin
->link(
326 SpecialPage
::getTitleFor( 'Undelete' ),
329 array( 'target' => $title->getPrefixedDBkey() ),
330 array( 'known', 'noclasses' )
332 // Show unblock/change block link
333 } else if( self
::typeAction( $row, array( 'block', 'suppress' ), array( 'block', 'reblock' ), 'block' ) ) {
336 SpecialPage
::getTitleFor( 'Ipblocklist' ),
337 $this->message
['unblocklink'],
340 'action' => 'unblock',
341 'ip' => $row->log_title
345 $this->message
['pipe-separator'] .
347 SpecialPage
::getTitleFor( 'Blockip', $row->log_title
),
348 $this->message
['change-blocklink'],
354 // Show change protection link
355 } else if( self
::typeAction( $row, 'protect', array( 'modify', 'protect', 'unprotect' ) ) ) {
357 $this->skin
->link( $title,
358 $this->message
['hist'],
361 'action' => 'history',
362 'offset' => $row->log_timestamp
365 if( $wgUser->isAllowed( 'protect' ) ) {
366 $revert .= $this->message
['pipe-separator'] .
367 $this->skin
->link( $title,
368 $this->message
['protect_change'],
370 array( 'action' => 'protect' ),
375 } else if( self
::typeAction( $row, 'merge', 'merge', 'mergehistory' ) ) {
376 $merge = SpecialPage
::getTitleFor( 'Mergehistory' );
377 $revert = '(' . $this->skin
->link(
379 $this->message
['revertmerge'],
382 'target' => $paramArray[0],
383 'dest' => $title->getPrefixedDBkey(),
384 'mergepoint' => $paramArray[1]
386 array( 'known', 'noclasses' )
388 // If an edit was hidden from a page give a review link to the history
389 } else if( self
::typeAction( $row, array( 'delete', 'suppress' ), 'revision', 'deletedhistory' ) ) {
390 if( count($paramArray) >= 2 ) {
391 // Different revision types use different URL params...
392 $key = $paramArray[0];
393 // $paramArray[1] is a CSV of the IDs
394 $Ids = explode( ',', $paramArray[1] );
395 $query = $paramArray[1];
397 // Diff link for single rev deletions
398 if( count($Ids) == 1 ) {
399 // Live revision diffs...
400 if( in_array( $key, array( 'oldid', 'revision' ) ) ) {
401 $revert[] = $this->skin
->link(
403 $this->message
['diff'],
406 'diff' => intval( $Ids[0] ),
409 array( 'known', 'noclasses' )
411 // Deleted revision diffs...
412 } else if( in_array( $key, array( 'artimestamp','archive' ) ) ) {
413 $revert[] = $this->skin
->link(
414 SpecialPage
::getTitleFor( 'Undelete' ),
415 $this->message
['diff'],
418 'target' => $title->getPrefixedDBKey(),
420 'timestamp' => $Ids[0]
422 array( 'known', 'noclasses' )
426 // View/modify link...
427 $revert[] = $this->skin
->link(
428 SpecialPage
::getTitleFor( 'Revisiondelete' ),
429 $this->message
['revdel-restore'],
432 'target' => $title->getPrefixedText(),
436 array( 'known', 'noclasses' )
439 $revert = wfMsg( 'parentheses', $wgLang->pipeList( $revert ) );
441 // Hidden log items, give review link
442 } else if( self
::typeAction( $row, array( 'delete', 'suppress' ), 'event', 'deletedhistory' ) ) {
443 if( count($paramArray) >= 1 ) {
444 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
445 // $paramArray[1] is a CSV of the IDs
446 $Ids = explode( ',', $paramArray[0] );
447 $query = $paramArray[0];
448 // Link to each hidden object ID, $paramArray[1] is the url param
449 $revert = '(' . $this->skin
->link(
451 $this->message
['revdel-restore'],
454 'target' => $title->getPrefixedText(),
458 array( 'known', 'noclasses' )
461 // Self-created users
462 } else if( self
::typeAction( $row, 'newusers', 'create2' ) ) {
463 if( isset( $paramArray[0] ) ) {
464 $revert = $this->skin
->userToolLinks( $paramArray[0], $title->getDBkey(), true );
466 # Fall back to a blue contributions link
467 $revert = $this->skin
->userToolLinks( 1, $title->getDBkey() );
469 if( $time < '20080129000000' ) {
470 # Suppress $comment from old entries (before 2008-01-29),
471 # not needed and can contain incorrect links
474 // Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
476 wfRunHooks( 'LogLine', array( $row->log_type
, $row->log_action
, $title, $paramArray,
477 &$comment, &$revert, $row->log_timestamp
) );
480 if( self
::isDeleted( $row, LogPage
::DELETED_ACTION
) ) {
481 $action = '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
483 $action = LogPage
::actionText( $row->log_type
, $row->log_action
, $title,
484 $this->skin
, $paramArray, true );
488 list( $tagDisplay, $newClasses ) = ChangeTags
::formatSummaryRow( $row->ts_tags
, 'logevent' );
489 $classes = array_merge( $classes, $newClasses );
491 if( $revert != '' ) {
492 $revert = '<span class="mw-logevent-actionlink">' . $revert . '</span>';
495 $time = htmlspecialchars( $time );
497 return Xml
::tags( 'li', array( "class" => implode( ' ', $classes ) ),
498 $del . $time . ' ' . $userLink . ' ' . $action . ' ' . $comment . ' ' . $revert . " $tagDisplay" ) . "\n";
505 private function getShowHideLinks( $row ) {
506 // If event was hidden from sysops
507 if( !self
::userCan( $row, LogPage
::DELETED_RESTRICTED
) ) {
508 $del = Xml
::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
509 '(' . $this->message
['rev-delundel'] . ')' );
510 } else if( $row->log_type
== 'suppress' ) {
511 $del = ''; // No one should be hiding from the oversight log
513 $target = SpecialPage
::getTitleFor( 'Log', $row->log_type
);
514 $page = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
516 'target' => $target->getPrefixedDBkey(),
518 'ids' => $row->log_id
,
520 $del = $this->skin
->revDeleteLink( $query,
521 self
::isDeleted( $row, LogPage
::DELETED_RESTRICTED
) );
528 * @param $type Mixed: string/array
529 * @param $action Mixed: string/array
530 * @param $right string
533 public static function typeAction( $row, $type, $action, $right='' ) {
534 $match = is_array($type) ?
535 in_array( $row->log_type
, $type ) : $row->log_type
== $type;
537 $match = is_array( $action ) ?
538 in_array( $row->log_action
, $action ) : $row->log_action
== $action;
539 if( $match && $right ) {
541 $match = $wgUser->isAllowed( $right );
548 * Determine if the current user is allowed to view a particular
549 * field of this log row, if it's marked as deleted.
551 * @param $field Integer
554 public static function userCan( $row, $field ) {
555 if( $row->log_deleted
& $field ) {
558 if ( $row->log_deleted
& LogPage
::DELETED_RESTRICTED
) {
559 $permission = 'suppressrevision';
560 } elseif ( $field & LogPage
::DELETED_TEXT
) {
561 $permission = 'deletedtext';
563 $permission = 'deletedhistory';
565 wfDebug( "Checking for $permission due to $field match on $row->log_deleted\n" );
566 return $wgUser->isAllowed( $permission );
574 * @param $field Integer: one of DELETED_* bitfield constants
577 public static function isDeleted( $row, $field ) {
578 return ( $row->log_deleted
& $field ) == $field;
582 * Show log extract. Either with text and a box (set $msgKey) or without (don't set $msgKey)
583 * @param $out OutputPage or String-by-reference
584 * @param $types String or Array
585 * @param $page String The page title to show log entries for
586 * @param $user String The user who made the log entries
587 * @param $param Associative Array with the following additional options:
588 * - lim Integer Limit of items to show, default is 50
589 * - conds Array Extra conditions for the query (e.g. "log_action != 'revision'")
590 * - showIfEmpty boolean Set to false if you don't want any output in case the loglist is empty
591 * if set to true (default), "No matching items in log" is displayed if loglist is empty
592 * - msgKey Array If you want a nice box with a message, set this to the key of the message.
593 * First element is the message key, additional optional elements are parameters for the key
594 * that are processed with wgMsgExt and option 'parse'
595 * - offset Set to overwrite offset parameter in $wgRequest
596 * set to '' to unset offset
597 * @return Integer Number of total log items (not limited by $lim)
599 public static function showLogExtract( &$out, $types=array(), $page='', $user='',
602 $defaultParameters = array(
605 'showIfEmpty' => true,
606 'msgKey' => array('')
609 # The + operator appends elements of remaining keys from the right
610 # handed array to the left handed, whereas duplicated keys are NOT overwritten.
611 $param +
= $defaultParameters;
613 global $wgUser, $wgOut;
614 # Convert $param array to individual variables
615 $lim = $param['lim'];
616 $conds = $param['conds'];
617 $showIfEmpty = $param['showIfEmpty'];
618 $msgKey = $param['msgKey'];
619 if ( !is_array( $msgKey ) )
620 $msgKey = array( $msgKey );
621 # Insert list of top 50 (or top $lim) items
622 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
623 $pager = new LogPager( $loglist, $types, $user, $page, '', $conds );
624 if ( isset( $param['offset'] ) ) # Tell pager to ignore $wgRequest offset
625 $pager->setOffset( $param['offset'] );
626 if( $lim > 0 ) $pager->mLimit
= $lim;
627 $logBody = $pager->getBody();
631 $s = '<div class="mw-warning-with-logexcerpt">';
633 if ( count( $msgKey ) == 1 ) {
634 $s .= wfMsgExt( $msgKey[0], array( 'parse' ) );
635 } else { // Process additional arguments
637 array_shift( $args );
638 $s .= wfMsgExt( $msgKey[0], array( 'parse' ), $args );
641 $s .= $loglist->beginLogEventsList() .
643 $loglist->endLogEventsList();
646 $s = wfMsgExt( 'logempty', array('parse') );
648 if( $pager->getNumRows() > $pager->mLimit
) { # Show "Full log" link
651 $urlParam['page'] = $page;
653 $urlParam['user'] = $user;
654 if ( !is_array( $types ) ) # Make it an array, if it isn't
655 $types = array( $types );
656 # If there is exactly one log type, we can link to Special:Log?type=foo
657 if ( count( $types ) == 1 )
658 $urlParam['type'] = $types[0];
659 $s .= $wgUser->getSkin()->link(
660 SpecialPage
::getTitleFor( 'Log' ),
661 wfMsgHtml( 'log-fulllog' ),
667 if ( $logBody && $msgKey[0] )
670 if( $out instanceof OutputPage
){
675 return $pager->getNumRows();
679 * SQL clause to skip forbidden log types for this user
680 * @param $db Database
681 * @param $audience string, public/user
682 * @return mixed (string or false)
684 public static function getExcludeClause( $db, $audience = 'public' ) {
685 global $wgLogRestrictions, $wgUser;
686 // Reset the array, clears extra "where" clauses when $par is used
687 $hiddenLogs = array();
688 // Don't show private logs to unprivileged users
689 foreach( $wgLogRestrictions as $logType => $right ) {
690 if( $audience == 'public' ||
!$wgUser->isAllowed($right) ) {
691 $safeType = $db->strencode( $logType );
692 $hiddenLogs[] = $safeType;
695 if( count($hiddenLogs) == 1 ) {
696 return 'log_type != ' . $db->addQuotes( $hiddenLogs[0] );
697 } elseif( $hiddenLogs ) {
698 return 'log_type NOT IN (' . $db->makeList($hiddenLogs) . ')';
707 class LogPager
extends ReverseChronologicalPager
{
708 private $types = array(), $user = '', $title = '', $pattern = '';
709 private $typeCGI = '';
710 public $mLogEventsList;
714 * @param $list LogEventsList
715 * @param $types String or Array log types to show
716 * @param $user String The user who made the log entries
717 * @param $title String The page title the log entries are for
718 * @param $pattern String Do a prefix search rather than an exact title match
719 * @param $conds Array Extra conditions for the query
720 * @param $year Integer The year to start from
721 * @param $month Integer The month to start from
723 public function __construct( $list, $types = array(), $user = '', $title = '', $pattern = '',
724 $conds = array(), $year = false, $month = false, $tagFilter = '' )
726 parent
::__construct();
727 $this->mConds
= $conds;
729 $this->mLogEventsList
= $list;
731 $this->limitType( $types ); // also excludes hidden types
732 $this->limitUser( $user );
733 $this->limitTitle( $title, $pattern );
734 $this->getDateCond( $year, $month );
735 $this->mTagFilter
= $tagFilter;
738 public function getDefaultQuery() {
739 $query = parent
::getDefaultQuery();
740 $query['type'] = $this->typeCGI
; // arrays won't work here
741 $query['user'] = $this->user
;
742 $query['month'] = $this->mMonth
;
743 $query['year'] = $this->mYear
;
747 // Call ONLY after calling $this->limitType() already!
748 public function getFilterParams() {
749 global $wgFilterLogTypes, $wgUser, $wgRequest;
751 if( count($this->types
) ) {
754 foreach( $wgFilterLogTypes as $type => $default ) {
755 // Avoid silly filtering
756 if( $type !== 'patrol' ||
$wgUser->useNPPatrol() ) {
757 $hide = $wgRequest->getInt( "hide_{$type}_log", $default );
758 $filters[$type] = $hide;
760 $this->mConds
[] = 'log_type != ' . $this->mDb
->addQuotes( $type );
767 * Set the log reader to return only entries of the given type.
768 * Type restrictions enforced here
769 * @param $types String or array: Log types ('upload', 'delete', etc);
770 * empty string means no restriction
772 private function limitType( $types ) {
773 global $wgLogRestrictions, $wgUser;
774 // If $types is not an array, make it an array
775 $types = ($types === '') ?
array() : (array)$types;
776 // Don't even show header for private logs; don't recognize it...
777 foreach ( $types as $type ) {
778 if( isset( $wgLogRestrictions[$type] ) && !$wgUser->isAllowed($wgLogRestrictions[$type]) ) {
779 $types = array_diff( $types, array( $type ) );
782 // Don't show private logs to unprivileged users.
783 // Also, only show them upon specific request to avoid suprises.
784 $audience = $types ?
'user' : 'public';
785 $hideLogs = LogEventsList
::getExcludeClause( $this->mDb
, $audience );
786 if( $hideLogs !== false ) {
787 $this->mConds
[] = $hideLogs;
789 if( count($types) ) {
790 $this->types
= $types;
791 $this->mConds
['log_type'] = $types;
792 // Set typeCGI; used in url param for paging
793 if( count($types) == 1 ) $this->typeCGI
= $types[0];
798 * Set the log reader to return only entries by the given user.
799 * @param $name String: (In)valid user name
801 private function limitUser( $name ) {
805 $usertitle = Title
::makeTitleSafe( NS_USER
, $name );
806 if( is_null($usertitle) ) {
809 /* Fetch userid at first, if known, provides awesome query plan afterwards */
810 $userid = User
::idFromName( $name );
812 /* It should be nicer to abort query at all,
813 but for now it won't pass anywhere behind the optimizer */
814 $this->mConds
[] = "NULL";
817 $this->mConds
['log_user'] = $userid;
818 // Paranoia: avoid brute force searches (bug 17342)
819 if( !$wgUser->isAllowed( 'deletedhistory' ) ) {
820 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::DELETED_USER
) . ' = 0';
821 } else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
822 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::SUPPRESSED_USER
) .
823 ' != ' . LogPage
::SUPPRESSED_USER
;
825 $this->user
= $usertitle->getText();
830 * Set the log reader to return only entries affecting the given page.
831 * (For the block and rights logs, this is a user page.)
832 * @param $page String: Title name as text
833 * @param $pattern String
835 private function limitTitle( $page, $pattern ) {
836 global $wgMiserMode, $wgUser;
838 $title = Title
::newFromText( $page );
839 if( strlen( $page ) == 0 ||
!$title instanceof Title
)
842 $this->title
= $title->getPrefixedText();
843 $ns = $title->getNamespace();
844 # Using the (log_namespace, log_title, log_timestamp) index with a
845 # range scan (LIKE) on the first two parts, instead of simple equality,
846 # makes it unusable for sorting. Sorted retrieval using another index
847 # would be possible, but then we might have to scan arbitrarily many
848 # nodes of that index. Therefore, we need to avoid this if $wgMiserMode
851 # This is not a problem with simple title matches, because then we can
852 # use the page_time index. That should have no more than a few hundred
853 # log entries for even the busiest pages, so it can be safely scanned
854 # in full to satisfy an impossible condition on user or similar.
855 if( $pattern && !$wgMiserMode ) {
856 # use escapeLike to avoid expensive search patterns like 't%st%'
857 $safetitle = $this->mDb
->escapeLike( $title->getDBkey() );
858 $this->mConds
['log_namespace'] = $ns;
859 $this->mConds
[] = "log_title LIKE '$safetitle%'";
860 $this->pattern
= $pattern;
862 $this->mConds
['log_namespace'] = $ns;
863 $this->mConds
['log_title'] = $title->getDBkey();
865 // Paranoia: avoid brute force searches (bug 17342)
866 if( !$wgUser->isAllowed( 'deletedhistory' ) ) {
867 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::DELETED_ACTION
) . ' = 0';
868 } else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
869 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::SUPPRESSED_ACTION
) .
870 ' != ' . LogPage
::SUPPRESSED_ACTION
;
874 public function getQueryInfo() {
875 $tables = array( 'logging', 'user' );
876 $this->mConds
[] = 'user_id = log_user';
878 # Add log_search table if there are conditions on it
879 if( array_key_exists('ls_field',$this->mConds
) ) {
880 $tables[] = 'log_search';
881 $index = array( 'log_search' => 'ls_field_val', 'logging' => 'PRIMARY' );
882 $groupBy = 'ls_log_id';
883 # Don't use the wrong logging index
884 } else if( $this->title ||
$this->pattern ||
$this->user
) {
885 $index = array( 'logging' => array('page_time','user_time') );
886 } else if( $this->types
) {
887 $index = array( 'logging' => 'type_time' );
889 $index = array( 'logging' => 'times' );
891 $options = array( 'USE INDEX' => $index );
892 # Don't show duplicate rows when using log_search
893 if( $groupBy ) $options['GROUP BY'] = $groupBy;
896 'fields' => array( 'log_type', 'log_action', 'log_user', 'log_namespace',
897 'log_title', 'log_params', 'log_comment', 'log_id', 'log_deleted',
898 'log_timestamp', 'user_name', 'user_editcount' ),
899 'conds' => $this->mConds
,
900 'options' => $options,
901 'join_conds' => array(
902 'user' => array( 'INNER JOIN', 'user_id=log_user' ),
903 'log_search' => array( 'INNER JOIN', 'ls_log_id=log_id' )
906 # Add ChangeTags filter query
907 ChangeTags
::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'],
908 $info['join_conds'], $info['options'], $this->mTagFilter
);
913 function getIndexField() {
914 return 'log_timestamp';
917 public function getStartBody() {
918 wfProfileIn( __METHOD__
);
919 # Do a link batch query
920 if( $this->getNumRows() > 0 ) {
922 while( $row = $this->mResult
->fetchObject() ) {
923 $lb->add( $row->log_namespace
, $row->log_title
);
924 $lb->addObj( Title
::makeTitleSafe( NS_USER
, $row->user_name
) );
925 $lb->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->user_name
) );
928 $this->mResult
->seek( 0 );
930 wfProfileOut( __METHOD__
);
934 public function formatRow( $row ) {
935 return $this->mLogEventsList
->logLine( $row );
938 public function getType() {
942 public function getUser() {
946 public function getPage() {
950 public function getPattern() {
951 return $this->pattern
;
954 public function getYear() {
958 public function getMonth() {
959 return $this->mMonth
;
962 public function getTagFilter() {
963 return $this->mTagFilter
;
966 public function doQuery() {
967 // Workaround MySQL optimizer bug
968 $this->mDb
->setBigSelects();
970 $this->mDb
->setBigSelects( 'default' );
976 * @ingroup SpecialPage
981 * @param $request WebRequest: for internal use use a FauxRequest object to pass arbitrary parameters.
983 function __construct( $request ) {
984 global $wgUser, $wgOut;
985 wfDeprecated(__METHOD__
);
987 $type = $request->getVal( 'type' );
988 $user = $request->getText( 'user' );
989 $title = $request->getText( 'page' );
990 $pattern = $request->getBool( 'pattern' );
991 $year = $request->getIntOrNull( 'year' );
992 $month = $request->getIntOrNull( 'month' );
993 $tagFilter = $request->getVal( 'tagfilter' );
994 # Don't let the user get stuck with a certain date
995 $skip = $request->getText( 'offset' ) ||
$request->getText( 'dir' ) == 'prev';
1000 # Use new list class to output results
1001 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
1002 $this->pager
= new LogPager( $loglist, $type, $user, $title, $pattern, $year, $month, $tagFilter );
1006 * Is there at least one row?
1009 public function hasRows() {
1010 return isset($this->pager
) ?
($this->pager
->getNumRows() > 0) : false;
1016 * @ingroup SpecialPage
1019 const NO_ACTION_LINK
= 1;
1027 * @param &$reader LogReader: where to get our data from
1028 * @param $flags Integer: Bitwise combination of flags:
1029 * LogEventsList::NO_ACTION_LINK Don't show restore/unblock/block links
1031 function __construct( &$reader, $flags = 0 ) {
1032 wfDeprecated(__METHOD__
);
1033 $this->reader
=& $reader;
1034 $this->reader
->pager
->mLogEventsList
->flags
= $flags;
1035 # Aliases for shorter code...
1036 $this->pager
=& $this->reader
->pager
;
1037 $this->list =& $this->reader
->pager
->mLogEventsList
;
1041 * Take over the whole output page in $wgOut with the log display.
1043 public function show() {
1044 # Set title and add header
1045 $this->list->showHeader( $pager->getType() );
1047 $this->list->showOptions( $this->pager
->getType(), $this->pager
->getUser(), $this->pager
->getPage(),
1048 $this->pager
->getPattern(), $this->pager
->getYear(), $this->pager
->getMonth() );
1050 $logBody = $this->pager
->getBody();
1053 $this->pager
->getNavigationBar() .
1054 $this->list->beginLogEventsList() .
1056 $this->list->endLogEventsList() .
1057 $this->pager
->getNavigationBar()
1060 $wgOut->addWikiMsg( 'logempty' );
1065 * Output just the list of entries given by the linked LogReader,
1066 * with extraneous UI elements. Use for displaying log fragments in
1067 * another page (eg at Special:Undelete)
1068 * @param $out OutputPage: where to send output
1070 public function showList( &$out ) {
1071 $logBody = $this->pager
->getBody();
1074 $this->list->beginLogEventsList() .
1076 $this->list->endLogEventsList()
1079 $out->addWikiMsg( 'logempty' );