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;
80 $action = htmlspecialchars( $wgScript );
81 $title = SpecialPage
::getTitleFor( 'Log' );
82 $special = htmlspecialchars( $title->getPrefixedDBkey() );
83 // For B/C, we take strings, but make sure they are converted...
84 $types = ($types === '') ?
array() : (array)$types;
86 $tagSelector = ChangeTags
::buildTagFilterSelector( $tagFilter );
88 $this->out
->addHTML( "<form action=\"$action\" method=\"get\"><fieldset>" .
89 Xml
::element( 'legend', array(), wfMsg( 'log' ) ) .
90 Xml
::hidden( 'title', $special ) . "\n" .
91 $this->getTypeMenu( $types ) . "\n" .
92 $this->getUserInput( $user ) . "\n" .
93 $this->getTitleInput( $page ) . "\n" .
94 ( !$wgMiserMode ?
($this->getTitlePattern( $pattern )."\n") : "" ) .
95 "<p>" . Xml
::dateMenu( $year, $month ) . "\n" .
96 ( $tagSelector ? Xml
::tags( 'p', null, implode( ' ', $tagSelector ) ) :'' ). "\n" .
97 ( $filter ?
"</p><p>".$this->getFilterLinks( $filter )."\n" : "" ) . "\n" .
98 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . "</p>\n" .
104 * @param $filter Array
105 * @return String: Formatted HTML
107 private function getFilterLinks( $filter ) {
108 global $wgTitle, $wgLang;
110 $messages = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
111 // Option value -> message mapping
113 $hiddens = ''; // keep track for "go" button
114 foreach( $filter as $type => $val ) {
115 // Should the below assignment be outside the foreach?
116 // Then it would have to be copied. Not certain what is more expensive.
117 $query = $this->getDefaultQuery();
118 $queryKey = "hide_{$type}_log";
120 $hideVal = 1 - intval($val);
121 $query[$queryKey] = $hideVal;
123 $link = $this->skin
->link(
128 array( 'known', 'noclasses' )
131 $links[$type] = wfMsgHtml( "log-show-hide-{$type}", $link );
132 $hiddens .= Xml
::hidden( "hide_{$type}_log", $val ) . "\n";
135 return '<small>'.$wgLang->pipeList( $links ) . '</small>' . $hiddens;
138 private function getDefaultQuery() {
139 if ( !isset( $this->mDefaultQuery
) ) {
140 $this->mDefaultQuery
= $_GET;
141 unset( $this->mDefaultQuery
['title'] );
142 unset( $this->mDefaultQuery
['dir'] );
143 unset( $this->mDefaultQuery
['offset'] );
144 unset( $this->mDefaultQuery
['limit'] );
145 unset( $this->mDefaultQuery
['order'] );
146 unset( $this->mDefaultQuery
['month'] );
147 unset( $this->mDefaultQuery
['year'] );
149 return $this->mDefaultQuery
;
153 * @param $queryTypes Array
154 * @return String: Formatted HTML
156 private function getTypeMenu( $queryTypes ) {
157 global $wgLogRestrictions, $wgUser;
159 $html = "<select name='type'>\n";
161 $validTypes = LogPage
::validTypes();
162 $typesByName = array(); // Temporary array
164 // First pass to load the log names
165 foreach( $validTypes as $type ) {
166 $text = LogPage
::logName( $type );
167 $typesByName[$text] = $type;
170 // Second pass to sort by name
173 // Note the query type
174 $queryType = count($queryTypes) == 1 ?
$queryTypes[0] : '';
175 // Third pass generates sorted XHTML content
176 foreach( $typesByName as $text => $type ) {
177 $selected = ($type == $queryType);
179 if ( isset($wgLogRestrictions[$type]) ) {
180 if ( $wgUser->isAllowed( $wgLogRestrictions[$type] ) ) {
181 $html .= Xml
::option( $text, $type, $selected ) . "\n";
184 $html .= Xml
::option( $text, $type, $selected ) . "\n";
188 $html .= '</select>';
193 * @param $user String
194 * @return String: Formatted HTML
196 private function getUserInput( $user ) {
197 return Xml
::inputLabel( wfMsg( 'specialloguserlabel' ), 'user', 'mw-log-user', 15, $user );
201 * @param $title String
202 * @return String: Formatted HTML
204 private function getTitleInput( $title ) {
205 return Xml
::inputLabel( wfMsg( 'speciallogtitlelabel' ), 'page', 'mw-log-page', 20, $title );
209 * @return boolean Checkbox
211 private function getTitlePattern( $pattern ) {
212 return '<span style="white-space: nowrap">' .
213 Xml
::checkLabel( wfMsg( 'log-title-wildcard' ), 'pattern', 'pattern', $pattern ) .
217 public function beginLogEventsList() {
221 public function endLogEventsList() {
226 * @param $row Row: a single row from the result set
227 * @return String: Formatted HTML list item
229 public function logLine( $row ) {
230 global $wgLang, $wgUser, $wgContLang;
232 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
233 $classes = array( "mw-logline-{$row->log_type}" );
234 $time = $wgLang->timeanddate( wfTimestamp(TS_MW
, $row->log_timestamp
), true );
236 if( self
::isDeleted($row,LogPage
::DELETED_USER
) ) {
237 $userLink = '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
239 $userLink = $this->skin
->userLink( $row->log_user
, $row->user_name
) .
240 $this->skin
->userToolLinks( $row->log_user
, $row->user_name
, true, 0, $row->user_editcount
);
243 if( self
::isDeleted($row,LogPage
::DELETED_COMMENT
) ) {
244 $comment = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
246 $comment = $wgContLang->getDirMark() . $this->skin
->commentBlock( $row->log_comment
);
248 // Extract extra parameters
249 $paramArray = LogPage
::extractParams( $row->log_params
);
251 // Some user can hide log items and have review links
252 if( !($this->flags
& self
::NO_ACTION_LINK
) && $wgUser->isAllowed( 'deleterevision' ) ) {
253 $del = $this->getShowHideLinks( $row ) . ' ';
255 // Add review links and such...
256 if( ($this->flags
& self
::NO_ACTION_LINK
) ||
($row->log_deleted
& LogPage
::DELETED_ACTION
) ) {
257 // Action text is suppressed...
258 } else if( self
::typeAction($row,'move','move','move') && !empty($paramArray[0]) ) {
259 $destTitle = Title
::newFromText( $paramArray[0] );
261 $revert = '(' . $this->skin
->link(
262 SpecialPage
::getTitleFor( 'Movepage' ),
263 $this->message
['revertmove'],
266 'wpOldTitle' => $destTitle->getPrefixedDBkey(),
267 'wpNewTitle' => $title->getPrefixedDBkey(),
268 'wpReason' => wfMsgForContent( 'revertmove' ),
271 array( 'known', 'noclasses' )
274 // Show undelete link
275 } else if( self
::typeAction($row,array('delete','suppress'),'delete','deletedhistory') ) {
276 if( !$wgUser->isAllowed( 'undelete' ) ) {
277 $viewdeleted = $this->message
['undeleteviewlink'];
279 $viewdeleted = $this->message
['undeletelink'];
282 $revert = '(' . $this->skin
->link(
283 SpecialPage
::getTitleFor( 'Undelete' ),
286 array( 'target' => $title->getPrefixedDBkey() ),
287 array( 'known', 'noclasses' )
289 // Show unblock/change block link
290 } else if( self
::typeAction($row,array('block','suppress'),array('block','reblock'),'block') ) {
293 SpecialPage
::getTitleFor( 'Ipblocklist' ),
294 $this->message
['unblocklink'],
297 'action' => 'unblock',
298 'ip' => $row->log_title
302 $this->message
['pipe-separator'] .
304 SpecialPage
::getTitleFor( 'Blockip', $row->log_title
),
305 $this->message
['change-blocklink'],
311 // Show change protection link
312 } else if( self
::typeAction( $row, 'protect', array( 'modify', 'protect', 'unprotect' ) ) ) {
314 $this->skin
->link( $title,
315 $this->message
['hist'],
318 'action' => 'history',
319 'offset' => $row->log_timestamp
322 if( $wgUser->isAllowed( 'protect' ) ) {
323 $revert .= $this->message
['pipe-separator'] .
324 $this->skin
->link( $title,
325 $this->message
['protect_change'],
327 array( 'action' => 'protect' ),
332 } else if( self
::typeAction($row,'merge','merge','mergehistory') ) {
333 $merge = SpecialPage
::getTitleFor( 'Mergehistory' );
334 $revert = '(' . $this->skin
->link(
336 $this->message
['revertmerge'],
339 'target' => $paramArray[0],
340 'dest' => $title->getPrefixedDBkey(),
341 'mergepoint' => $paramArray[1]
343 array( 'known', 'noclasses' )
345 // If an edit was hidden from a page give a review link to the history
346 } else if( self
::typeAction($row,array('delete','suppress'),'revision','deleterevision') ) {
347 if( count($paramArray) >= 2 ) {
348 // Different revision types use different URL params...
349 $key = $paramArray[0];
350 // $paramArray[1] is a CSV of the IDs
351 $Ids = explode( ',', $paramArray[1] );
352 $query = $paramArray[1];
354 // Diff link for single rev deletions
355 if( count($Ids) == 1 ) {
356 // Live revision diffs...
357 if( in_array($key, array('oldid','revision')) ) {
358 $revert[] = $this->skin
->link(
360 $this->message
['diff'],
363 'diff' => intval( $Ids[0] ),
366 array( 'known', 'noclasses' )
368 // Deleted revision diffs...
369 } else if( in_array($key, array('artimestamp','archive')) ) {
370 $revert[] = $this->skin
->link(
371 SpecialPage
::getTitleFor( 'Undelete' ),
372 $this->message
['diff'],
375 'target' => $title->getPrefixedDBKey(),
377 'timestamp' => $Ids[0]
379 array( 'known', 'noclasses' )
383 // View/modify link...
384 $revert[] = $this->skin
->link(
385 SpecialPage
::getTitleFor( 'Revisiondelete' ),
386 $this->message
['revdel-restore'],
389 'target' => $title->getPrefixedText(),
393 array( 'known', 'noclasses' )
396 $revert = wfMsg( 'parentheses', $wgLang->pipeList( $revert ) );
398 // Hidden log items, give review link
399 } else if( self
::typeAction($row,array('delete','suppress'),'event','deleterevision') ) {
400 if( count($paramArray) >= 1 ) {
401 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
402 // $paramArray[1] is a CSV of the IDs
403 $Ids = explode( ',', $paramArray[0] );
404 $query = $paramArray[0];
405 // Link to each hidden object ID, $paramArray[1] is the url param
406 $revert = '(' . $this->skin
->link(
408 $this->message
['revdel-restore'],
411 'target' => $title->getPrefixedText(),
415 array( 'known', 'noclasses' )
418 // Self-created users
419 } else if( self
::typeAction($row,'newusers','create2') ) {
420 if( isset( $paramArray[0] ) ) {
421 $revert = $this->skin
->userToolLinks( $paramArray[0], $title->getDBkey(), true );
423 # Fall back to a blue contributions link
424 $revert = $this->skin
->userToolLinks( 1, $title->getDBkey() );
426 if( $time < '20080129000000' ) {
427 # Suppress $comment from old entries (before 2008-01-29),
428 # not needed and can contain incorrect links
431 // Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
433 wfRunHooks( 'LogLine', array( $row->log_type
, $row->log_action
, $title, $paramArray,
434 &$comment, &$revert, $row->log_timestamp
) );
437 if( self
::isDeleted($row,LogPage
::DELETED_ACTION
) ) {
438 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
440 $action = LogPage
::actionText( $row->log_type
, $row->log_action
, $title,
441 $this->skin
, $paramArray, true );
445 list($tagDisplay, $newClasses) = ChangeTags
::formatSummaryRow( $row->ts_tags
, 'logevent' );
446 $classes = array_merge( $classes, $newClasses );
448 if( $revert != '' ) {
449 $revert = '<span class="mw-logevent-actionlink">' . $revert . '</span>';
452 $time = htmlspecialchars( $time );
454 return Xml
::tags( 'li', array( "class" => implode( ' ', $classes ) ),
455 $del . $time . ' ' . $userLink . ' ' . $action . ' ' . $comment . ' ' . $revert . " $tagDisplay" ) . "\n";
462 private function getShowHideLinks( $row ) {
463 // If event was hidden from sysops
464 if( !self
::userCan( $row, LogPage
::DELETED_RESTRICTED
) ) {
465 $del = Xml
::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
466 '('.$this->message
['rev-delundel'].')' );
467 } else if( $row->log_type
== 'suppress' ) {
468 $del = ''; // No one should be hiding from the oversight log
470 $target = SpecialPage
::getTitleFor( 'Log', $row->log_type
);
471 $page = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
473 'target' => $target->getPrefixedDBkey(),
475 'ids' => $row->log_id
,
477 $del = $this->skin
->revDeleteLink( $query,
478 self
::isDeleted( $row, LogPage
::DELETED_RESTRICTED
) );
485 * @param $type Mixed: string/array
486 * @param $action Mixed: string/array
487 * @param $right string
490 public static function typeAction( $row, $type, $action, $right='' ) {
491 $match = is_array($type) ?
492 in_array($row->log_type
,$type) : $row->log_type
== $type;
494 $match = is_array($action) ?
495 in_array($row->log_action
,$action) : $row->log_action
== $action;
496 if( $match && $right ) {
498 $match = $wgUser->isAllowed( $right );
505 * Determine if the current user is allowed to view a particular
506 * field of this log row, if it's marked as deleted.
508 * @param $field Integer
511 public static function userCan( $row, $field ) {
512 if( ( $row->log_deleted
& $field ) == $field ) {
514 $permission = ( $row->log_deleted
& LogPage
::DELETED_RESTRICTED
) == LogPage
::DELETED_RESTRICTED
517 wfDebug( "Checking for $permission due to $field match on $row->log_deleted\n" );
518 return $wgUser->isAllowed( $permission );
526 * @param $field Integer: one of DELETED_* bitfield constants
529 public static function isDeleted( $row, $field ) {
530 return ($row->log_deleted
& $field) == $field;
534 * Quick function to show a short log extract
535 * @param $out OutputPage
536 * @param $types String or Array
537 * @param $page String
538 * @param $user String
539 * @param $lim Integer
540 * @param $conds Array
542 public static function showLogExtract( $out, $types=array(), $page='', $user='', $lim=0, $conds=array() ) {
544 # Insert list of top 50 or so items
545 $loglist = new LogEventsList( $wgUser->getSkin(), $out, 0 );
546 $pager = new LogPager( $loglist, $types, $user, $page, '', $conds );
547 if( $lim > 0 ) $pager->mLimit
= $lim;
548 $logBody = $pager->getBody();
551 $loglist->beginLogEventsList() .
553 $loglist->endLogEventsList()
556 $out->addWikiMsg( 'logempty' );
558 return $pager->getNumRows();
562 * SQL clause to skip forbidden log types for this user
563 * @param $db Database
564 * @param $audience string, public/user
565 * @return mixed (string or false)
567 public static function getExcludeClause( $db, $audience = 'public' ) {
568 global $wgLogRestrictions, $wgUser;
569 // Reset the array, clears extra "where" clauses when $par is used
570 $hiddenLogs = array();
571 // Don't show private logs to unprivileged users
572 foreach( $wgLogRestrictions as $logType => $right ) {
573 if( $audience == 'public' ||
!$wgUser->isAllowed($right) ) {
574 $safeType = $db->strencode( $logType );
575 $hiddenLogs[] = $safeType;
578 if( count($hiddenLogs) == 1 ) {
579 return 'log_type != ' . $db->addQuotes( $hiddenLogs[0] );
580 } elseif( $hiddenLogs ) {
581 return 'log_type NOT IN (' . $db->makeList($hiddenLogs) . ')';
590 class LogPager
extends ReverseChronologicalPager
{
591 private $types = array(), $user = '', $title = '', $pattern = '';
592 private $typeCGI = '';
593 public $mLogEventsList;
597 * @param $list LogEventsList
598 * @param $types String or Array
599 * @param $user String
600 * @param $title String
601 * @param $pattern String
602 * @param $conds Array
603 * @param $year Integer
604 * @param $month Integer
606 public function __construct( $list, $types = array(), $user = '', $title = '', $pattern = '',
607 $conds = array(), $year = false, $month = false, $tagFilter = '' )
609 parent
::__construct();
610 $this->mConds
= $conds;
612 $this->mLogEventsList
= $list;
614 $this->limitType( $types ); // also excludes hidden types
615 $this->limitUser( $user );
616 $this->limitTitle( $title, $pattern );
617 $this->getDateCond( $year, $month );
618 $this->mTagFilter
= $tagFilter;
621 public function getDefaultQuery() {
622 $query = parent
::getDefaultQuery();
623 $query['type'] = $this->typeCGI
; // arrays won't work here
624 $query['user'] = $this->user
;
625 $query['month'] = $this->mMonth
;
626 $query['year'] = $this->mYear
;
630 // Call ONLY after calling $this->limitType() already!
631 public function getFilterParams() {
632 global $wgFilterLogTypes, $wgUser, $wgRequest;
634 if( count($this->types
) ) {
637 foreach( $wgFilterLogTypes as $type => $default ) {
638 // Avoid silly filtering
639 if( $type !== 'patrol' ||
$wgUser->useNPPatrol() ) {
640 $hide = $wgRequest->getInt( "hide_{$type}_log", $default );
641 $filters[$type] = $hide;
643 $this->mConds
[] = 'log_type != ' . $this->mDb
->addQuotes( $type );
650 * Set the log reader to return only entries of the given type.
651 * Type restrictions enforced here
652 * @param $types String or array: Log types ('upload', 'delete', etc);
653 * empty string means no restriction
655 private function limitType( $types ) {
656 global $wgLogRestrictions, $wgUser;
657 // If $types is not an array, make it an array
658 $types = ($types === '') ?
array() : (array)$types;
659 // Don't even show header for private logs; don't recognize it...
660 foreach ( $types as $type ) {
661 if( isset( $wgLogRestrictions[$type] ) && !$wgUser->isAllowed($wgLogRestrictions[$type]) ) {
662 $types = array_diff( $types, array( $type ) );
665 // Don't show private logs to unprivileged users.
666 // Also, only show them upon specific request to avoid suprises.
667 $audience = $types ?
'user' : 'public';
668 $hideLogs = LogEventsList
::getExcludeClause( $this->mDb
, $audience );
669 if( $hideLogs !== false ) {
670 $this->mConds
[] = $hideLogs;
672 if( count($types) ) {
673 $this->types
= $types;
674 $this->mConds
['log_type'] = $types;
675 // Set typeCGI; used in url param for paging
676 if( count($types) == 1 ) $this->typeCGI
= $types[0];
681 * Set the log reader to return only entries by the given user.
682 * @param $name String: (In)valid user name
684 private function limitUser( $name ) {
688 $usertitle = Title
::makeTitleSafe( NS_USER
, $name );
689 if( is_null($usertitle) ) {
692 /* Fetch userid at first, if known, provides awesome query plan afterwards */
693 $userid = User
::idFromName( $name );
695 /* It should be nicer to abort query at all,
696 but for now it won't pass anywhere behind the optimizer */
697 $this->mConds
[] = "NULL";
700 $this->mConds
['log_user'] = $userid;
701 // Paranoia: avoid brute force searches (bug 17342)
702 if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
703 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::DELETED_USER
) . ' = 0';
705 $this->user
= $usertitle->getText();
710 * Set the log reader to return only entries affecting the given page.
711 * (For the block and rights logs, this is a user page.)
712 * @param $page String: Title name as text
713 * @param $pattern String
715 private function limitTitle( $page, $pattern ) {
716 global $wgMiserMode, $wgUser;
718 $title = Title
::newFromText( $page );
719 if( strlen($page) == 0 ||
!$title instanceof Title
)
722 $this->title
= $title->getPrefixedText();
723 $ns = $title->getNamespace();
724 # Using the (log_namespace, log_title, log_timestamp) index with a
725 # range scan (LIKE) on the first two parts, instead of simple equality,
726 # makes it unusable for sorting. Sorted retrieval using another index
727 # would be possible, but then we might have to scan arbitrarily many
728 # nodes of that index. Therefore, we need to avoid this if $wgMiserMode
731 # This is not a problem with simple title matches, because then we can
732 # use the page_time index. That should have no more than a few hundred
733 # log entries for even the busiest pages, so it can be safely scanned
734 # in full to satisfy an impossible condition on user or similar.
735 if( $pattern && !$wgMiserMode ) {
736 # use escapeLike to avoid expensive search patterns like 't%st%'
737 $safetitle = $this->mDb
->escapeLike( $title->getDBkey() );
738 $this->mConds
['log_namespace'] = $ns;
739 $this->mConds
[] = "log_title LIKE '$safetitle%'";
740 $this->pattern
= $pattern;
742 $this->mConds
['log_namespace'] = $ns;
743 $this->mConds
['log_title'] = $title->getDBkey();
745 // Paranoia: avoid brute force searches (bug 17342)
746 if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
747 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::DELETED_ACTION
) . ' = 0';
751 public function getQueryInfo() {
752 $tables = array( 'logging', 'user' );
753 $this->mConds
[] = 'user_id = log_user';
755 # Add log_search table if there are conditions on it
756 if( array_key_exists('ls_field',$this->mConds
) ) {
757 $tables[] = 'log_search';
758 $index = array( 'log_search' => 'ls_field_val', 'logging' => 'PRIMARY' );
759 $groupBy = 'ls_log_id';
760 # Don't use the wrong logging index
761 } else if( $this->title ||
$this->pattern ||
$this->user
) {
762 $index = array( 'logging' => array('page_time','user_time') );
763 } else if( $this->types
) {
764 $index = array( 'logging' => 'type_time' );
766 $index = array( 'logging' => 'times' );
768 $options = array( 'USE INDEX' => $index );
769 # Don't show duplicate rows when using log_search
770 if( $groupBy ) $options['GROUP BY'] = $groupBy;
773 'fields' => array( 'log_type', 'log_action', 'log_user', 'log_namespace',
774 'log_title', 'log_params', 'log_comment', 'log_id', 'log_deleted',
775 'log_timestamp', 'user_name', 'user_editcount' ),
776 'conds' => $this->mConds
,
777 'options' => $options,
778 'join_conds' => array(
779 'user' => array( 'INNER JOIN', 'user_id=log_user' ),
780 'log_search' => array( 'INNER JOIN', 'ls_log_id=log_id' )
783 # Add ChangeTags filter query
784 ChangeTags
::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'],
785 $info['join_conds'], $info['options'], $this->mTagFilter
);
790 function getIndexField() {
791 return 'log_timestamp';
794 public function getStartBody() {
795 wfProfileIn( __METHOD__
);
796 # Do a link batch query
797 if( $this->getNumRows() > 0 ) {
799 while( $row = $this->mResult
->fetchObject() ) {
800 $lb->add( $row->log_namespace
, $row->log_title
);
801 $lb->addObj( Title
::makeTitleSafe( NS_USER
, $row->user_name
) );
802 $lb->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->user_name
) );
805 $this->mResult
->seek( 0 );
807 wfProfileOut( __METHOD__
);
811 public function formatRow( $row ) {
812 return $this->mLogEventsList
->logLine( $row );
815 public function getType() {
819 public function getUser() {
823 public function getPage() {
827 public function getPattern() {
828 return $this->pattern
;
831 public function getYear() {
835 public function getMonth() {
836 return $this->mMonth
;
839 public function getTagFilter() {
840 return $this->mTagFilter
;
843 public function doQuery() {
844 // Workaround MySQL optimizer bug
845 $this->mDb
->setBigSelects();
847 $this->mDb
->setBigSelects( 'default' );
853 * @ingroup SpecialPage
858 * @param $request WebRequest: for internal use use a FauxRequest object to pass arbitrary parameters.
860 function __construct( $request ) {
861 global $wgUser, $wgOut;
862 wfDeprecated(__METHOD__
);
864 $type = $request->getVal( 'type' );
865 $user = $request->getText( 'user' );
866 $title = $request->getText( 'page' );
867 $pattern = $request->getBool( 'pattern' );
868 $year = $request->getIntOrNull( 'year' );
869 $month = $request->getIntOrNull( 'month' );
870 $tagFilter = $request->getVal( 'tagfilter' );
871 # Don't let the user get stuck with a certain date
872 $skip = $request->getText( 'offset' ) ||
$request->getText( 'dir' ) == 'prev';
877 # Use new list class to output results
878 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
879 $this->pager
= new LogPager( $loglist, $type, $user, $title, $pattern, $year, $month, $tagFilter );
883 * Is there at least one row?
886 public function hasRows() {
887 return isset($this->pager
) ?
($this->pager
->getNumRows() > 0) : false;
893 * @ingroup SpecialPage
896 const NO_ACTION_LINK
= 1;
904 * @param &$reader LogReader: where to get our data from
905 * @param $flags Integer: Bitwise combination of flags:
906 * LogEventsList::NO_ACTION_LINK Don't show restore/unblock/block links
908 function __construct( &$reader, $flags = 0 ) {
909 wfDeprecated(__METHOD__
);
910 $this->reader
=& $reader;
911 $this->reader
->pager
->mLogEventsList
->flags
= $flags;
912 # Aliases for shorter code...
913 $this->pager
=& $this->reader
->pager
;
914 $this->list =& $this->reader
->pager
->mLogEventsList
;
918 * Take over the whole output page in $wgOut with the log display.
920 public function show() {
921 # Set title and add header
922 $this->list->showHeader( $pager->getType() );
924 $this->list->showOptions( $this->pager
->getType(), $this->pager
->getUser(), $this->pager
->getPage(),
925 $this->pager
->getPattern(), $this->pager
->getYear(), $this->pager
->getMonth() );
927 $logBody = $this->pager
->getBody();
930 $this->pager
->getNavigationBar() .
931 $this->list->beginLogEventsList() .
933 $this->list->endLogEventsList() .
934 $this->pager
->getNavigationBar()
937 $wgOut->addWikiMsg( 'logempty' );
942 * Output just the list of entries given by the linked LogReader,
943 * with extraneous UI elements. Use for displaying log fragments in
944 * another page (eg at Special:Undelete)
945 * @param $out OutputPage: where to send output
947 public function showList( &$out ) {
948 $logBody = $this->pager
->getBody();
951 $this->list->beginLogEventsList() .
953 $this->list->endLogEventsList()
956 $out->addWikiMsg( 'logempty' );