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";
98 // Title pattern, if allowed
100 $html .= $this->getTitlePattern( $pattern ) . "\n";
104 $html .= Xml
::tags( 'p', null, Xml
::dateMenu( $year, $month ) );
108 $html .= Xml
::tags( 'p', null, implode( ' ', $tagSelector ) );
113 $html .= Xml
::tags( 'p', null, $this->getFilterLinks( $filter ) );
117 $html .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) );
120 $html = Xml
::fieldset( wfMsg( 'log' ), $html );
123 $html = Xml
::tags( 'form', array( 'action' => $action, 'method' => 'get' ), $html );
125 $this->out
->addHTML( $html );
129 * @param $filter Array
130 * @return String: Formatted HTML
132 private function getFilterLinks( $filter ) {
133 global $wgTitle, $wgLang;
135 $messages = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
136 // Option value -> message mapping
138 $hiddens = ''; // keep track for "go" button
139 foreach( $filter as $type => $val ) {
140 // Should the below assignment be outside the foreach?
141 // Then it would have to be copied. Not certain what is more expensive.
142 $query = $this->getDefaultQuery();
143 $queryKey = "hide_{$type}_log";
145 $hideVal = 1 - intval($val);
146 $query[$queryKey] = $hideVal;
148 $link = $this->skin
->link(
153 array( 'known', 'noclasses' )
156 $links[$type] = wfMsgHtml( "log-show-hide-{$type}", $link );
157 $hiddens .= Xml
::hidden( "hide_{$type}_log", $val ) . "\n";
160 return '<small>'.$wgLang->pipeList( $links ) . '</small>' . $hiddens;
163 private function getDefaultQuery() {
164 if ( !isset( $this->mDefaultQuery
) ) {
165 $this->mDefaultQuery
= $_GET;
166 unset( $this->mDefaultQuery
['title'] );
167 unset( $this->mDefaultQuery
['dir'] );
168 unset( $this->mDefaultQuery
['offset'] );
169 unset( $this->mDefaultQuery
['limit'] );
170 unset( $this->mDefaultQuery
['order'] );
171 unset( $this->mDefaultQuery
['month'] );
172 unset( $this->mDefaultQuery
['year'] );
174 return $this->mDefaultQuery
;
178 * @param $queryTypes Array
179 * @return String: Formatted HTML
181 private function getTypeMenu( $queryTypes ) {
182 global $wgLogRestrictions, $wgUser;
184 $html = "<select name='type'>\n";
186 $validTypes = LogPage
::validTypes();
187 $typesByName = array(); // Temporary array
189 // First pass to load the log names
190 foreach( $validTypes as $type ) {
191 $text = LogPage
::logName( $type );
192 $typesByName[$text] = $type;
195 // Second pass to sort by name
198 // Note the query type
199 $queryType = count($queryTypes) == 1 ?
$queryTypes[0] : '';
200 // Third pass generates sorted XHTML content
201 foreach( $typesByName as $text => $type ) {
202 $selected = ($type == $queryType);
204 if ( isset($wgLogRestrictions[$type]) ) {
205 if ( $wgUser->isAllowed( $wgLogRestrictions[$type] ) ) {
206 $html .= Xml
::option( $text, $type, $selected ) . "\n";
209 $html .= Xml
::option( $text, $type, $selected ) . "\n";
213 $html .= '</select>';
218 * @param $user String
219 * @return String: Formatted HTML
221 private function getUserInput( $user ) {
222 return Xml
::inputLabel( wfMsg( 'specialloguserlabel' ), 'user', 'mw-log-user', 15, $user );
226 * @param $title String
227 * @return String: Formatted HTML
229 private function getTitleInput( $title ) {
230 return Xml
::inputLabel( wfMsg( 'speciallogtitlelabel' ), 'page', 'mw-log-page', 20, $title );
234 * @return boolean Checkbox
236 private function getTitlePattern( $pattern ) {
237 return '<span style="white-space: nowrap">' .
238 Xml
::checkLabel( wfMsg( 'log-title-wildcard' ), 'pattern', 'pattern', $pattern ) .
242 public function beginLogEventsList() {
246 public function endLogEventsList() {
251 * @param $row Row: a single row from the result set
252 * @return String: Formatted HTML list item
254 public function logLine( $row ) {
255 global $wgLang, $wgUser, $wgContLang;
257 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
258 $classes = array( "mw-logline-{$row->log_type}" );
259 $time = $wgLang->timeanddate( wfTimestamp(TS_MW
, $row->log_timestamp
), true );
261 if( self
::isDeleted($row,LogPage
::DELETED_USER
) ) {
262 $userLink = '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
264 $userLink = $this->skin
->userLink( $row->log_user
, $row->user_name
) .
265 $this->skin
->userToolLinks( $row->log_user
, $row->user_name
, true, 0, $row->user_editcount
);
268 if( self
::isDeleted($row,LogPage
::DELETED_COMMENT
) ) {
269 $comment = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
271 $comment = $wgContLang->getDirMark() . $this->skin
->commentBlock( $row->log_comment
);
273 // Extract extra parameters
274 $paramArray = LogPage
::extractParams( $row->log_params
);
276 // Some user can hide log items and have review links
277 if( !($this->flags
& self
::NO_ACTION_LINK
) && $wgUser->isAllowed( 'deleterevision' ) ) {
278 $del = $this->getShowHideLinks( $row ) . ' ';
280 // Add review links and such...
281 if( ($this->flags
& self
::NO_ACTION_LINK
) ||
($row->log_deleted
& LogPage
::DELETED_ACTION
) ) {
282 // Action text is suppressed...
283 } else if( self
::typeAction($row,'move','move','move') && !empty($paramArray[0]) ) {
284 $destTitle = Title
::newFromText( $paramArray[0] );
286 $revert = '(' . $this->skin
->link(
287 SpecialPage
::getTitleFor( 'Movepage' ),
288 $this->message
['revertmove'],
291 'wpOldTitle' => $destTitle->getPrefixedDBkey(),
292 'wpNewTitle' => $title->getPrefixedDBkey(),
293 'wpReason' => wfMsgForContent( 'revertmove' ),
296 array( 'known', 'noclasses' )
299 // Show undelete link
300 } else if( self
::typeAction($row,array('delete','suppress'),'delete','deletedhistory') ) {
301 if( !$wgUser->isAllowed( 'undelete' ) ) {
302 $viewdeleted = $this->message
['undeleteviewlink'];
304 $viewdeleted = $this->message
['undeletelink'];
307 $revert = '(' . $this->skin
->link(
308 SpecialPage
::getTitleFor( 'Undelete' ),
311 array( 'target' => $title->getPrefixedDBkey() ),
312 array( 'known', 'noclasses' )
314 // Show unblock/change block link
315 } else if( self
::typeAction($row,array('block','suppress'),array('block','reblock'),'block') ) {
318 SpecialPage
::getTitleFor( 'Ipblocklist' ),
319 $this->message
['unblocklink'],
322 'action' => 'unblock',
323 'ip' => $row->log_title
327 $this->message
['pipe-separator'] .
329 SpecialPage
::getTitleFor( 'Blockip', $row->log_title
),
330 $this->message
['change-blocklink'],
336 // Show change protection link
337 } else if( self
::typeAction( $row, 'protect', array( 'modify', 'protect', 'unprotect' ) ) ) {
339 $this->skin
->link( $title,
340 $this->message
['hist'],
343 'action' => 'history',
344 'offset' => $row->log_timestamp
347 if( $wgUser->isAllowed( 'protect' ) ) {
348 $revert .= $this->message
['pipe-separator'] .
349 $this->skin
->link( $title,
350 $this->message
['protect_change'],
352 array( 'action' => 'protect' ),
357 } else if( self
::typeAction($row,'merge','merge','mergehistory') ) {
358 $merge = SpecialPage
::getTitleFor( 'Mergehistory' );
359 $revert = '(' . $this->skin
->link(
361 $this->message
['revertmerge'],
364 'target' => $paramArray[0],
365 'dest' => $title->getPrefixedDBkey(),
366 'mergepoint' => $paramArray[1]
368 array( 'known', 'noclasses' )
370 // If an edit was hidden from a page give a review link to the history
371 } else if( self
::typeAction($row,array('delete','suppress'),'revision','deleterevision') ) {
372 if( count($paramArray) >= 2 ) {
373 // Different revision types use different URL params...
374 $key = $paramArray[0];
375 // $paramArray[1] is a CSV of the IDs
376 $Ids = explode( ',', $paramArray[1] );
377 $query = $paramArray[1];
379 // Diff link for single rev deletions
380 if( count($Ids) == 1 ) {
381 // Live revision diffs...
382 if( in_array($key, array('oldid','revision')) ) {
383 $revert[] = $this->skin
->link(
385 $this->message
['diff'],
388 'diff' => intval( $Ids[0] ),
391 array( 'known', 'noclasses' )
393 // Deleted revision diffs...
394 } else if( in_array($key, array('artimestamp','archive')) ) {
395 $revert[] = $this->skin
->link(
396 SpecialPage
::getTitleFor( 'Undelete' ),
397 $this->message
['diff'],
400 'target' => $title->getPrefixedDBKey(),
402 'timestamp' => $Ids[0]
404 array( 'known', 'noclasses' )
408 // View/modify link...
409 $revert[] = $this->skin
->link(
410 SpecialPage
::getTitleFor( 'Revisiondelete' ),
411 $this->message
['revdel-restore'],
414 'target' => $title->getPrefixedText(),
418 array( 'known', 'noclasses' )
421 $revert = wfMsg( 'parentheses', $wgLang->pipeList( $revert ) );
423 // Hidden log items, give review link
424 } else if( self
::typeAction($row,array('delete','suppress'),'event','deleterevision') ) {
425 if( count($paramArray) >= 1 ) {
426 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
427 // $paramArray[1] is a CSV of the IDs
428 $Ids = explode( ',', $paramArray[0] );
429 $query = $paramArray[0];
430 // Link to each hidden object ID, $paramArray[1] is the url param
431 $revert = '(' . $this->skin
->link(
433 $this->message
['revdel-restore'],
436 'target' => $title->getPrefixedText(),
440 array( 'known', 'noclasses' )
443 // Self-created users
444 } else if( self
::typeAction($row,'newusers','create2') ) {
445 if( isset( $paramArray[0] ) ) {
446 $revert = $this->skin
->userToolLinks( $paramArray[0], $title->getDBkey(), true );
448 # Fall back to a blue contributions link
449 $revert = $this->skin
->userToolLinks( 1, $title->getDBkey() );
451 if( $time < '20080129000000' ) {
452 # Suppress $comment from old entries (before 2008-01-29),
453 # not needed and can contain incorrect links
456 // Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
458 wfRunHooks( 'LogLine', array( $row->log_type
, $row->log_action
, $title, $paramArray,
459 &$comment, &$revert, $row->log_timestamp
) );
462 if( self
::isDeleted($row,LogPage
::DELETED_ACTION
) ) {
463 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
465 $action = LogPage
::actionText( $row->log_type
, $row->log_action
, $title,
466 $this->skin
, $paramArray, true );
470 list($tagDisplay, $newClasses) = ChangeTags
::formatSummaryRow( $row->ts_tags
, 'logevent' );
471 $classes = array_merge( $classes, $newClasses );
473 if( $revert != '' ) {
474 $revert = '<span class="mw-logevent-actionlink">' . $revert . '</span>';
477 $time = htmlspecialchars( $time );
479 return Xml
::tags( 'li', array( "class" => implode( ' ', $classes ) ),
480 $del . $time . ' ' . $userLink . ' ' . $action . ' ' . $comment . ' ' . $revert . " $tagDisplay" ) . "\n";
487 private function getShowHideLinks( $row ) {
488 // If event was hidden from sysops
489 if( !self
::userCan( $row, LogPage
::DELETED_RESTRICTED
) ) {
490 $del = Xml
::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
491 '('.$this->message
['rev-delundel'].')' );
492 } else if( $row->log_type
== 'suppress' ) {
493 $del = ''; // No one should be hiding from the oversight log
495 $target = SpecialPage
::getTitleFor( 'Log', $row->log_type
);
496 $page = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
498 'target' => $target->getPrefixedDBkey(),
500 'ids' => $row->log_id
,
502 $del = $this->skin
->revDeleteLink( $query,
503 self
::isDeleted( $row, LogPage
::DELETED_RESTRICTED
) );
510 * @param $type Mixed: string/array
511 * @param $action Mixed: string/array
512 * @param $right string
515 public static function typeAction( $row, $type, $action, $right='' ) {
516 $match = is_array($type) ?
517 in_array($row->log_type
,$type) : $row->log_type
== $type;
519 $match = is_array($action) ?
520 in_array($row->log_action
,$action) : $row->log_action
== $action;
521 if( $match && $right ) {
523 $match = $wgUser->isAllowed( $right );
530 * Determine if the current user is allowed to view a particular
531 * field of this log row, if it's marked as deleted.
533 * @param $field Integer
536 public static function userCan( $row, $field ) {
537 if( ( $row->log_deleted
& $field ) == $field ) {
539 $permission = ( $row->log_deleted
& LogPage
::DELETED_RESTRICTED
) == LogPage
::DELETED_RESTRICTED
542 wfDebug( "Checking for $permission due to $field match on $row->log_deleted\n" );
543 return $wgUser->isAllowed( $permission );
551 * @param $field Integer: one of DELETED_* bitfield constants
554 public static function isDeleted( $row, $field ) {
555 return ($row->log_deleted
& $field) == $field;
559 * Quick function to show a short log extract
560 * @param $out OutputPage
561 * @param $types String or Array
562 * @param $page String
563 * @param $user String
564 * @param $lim Integer
565 * @param $conds Array
567 public static function showLogExtract( $out, $types=array(), $page='', $user='', $lim=0, $conds=array() ) {
569 # Insert list of top 50 or so items
570 $loglist = new LogEventsList( $wgUser->getSkin(), $out, 0 );
571 $pager = new LogPager( $loglist, $types, $user, $page, '', $conds );
572 if( $lim > 0 ) $pager->mLimit
= $lim;
573 $logBody = $pager->getBody();
576 $loglist->beginLogEventsList() .
578 $loglist->endLogEventsList()
581 $out->addWikiMsg( 'logempty' );
583 return $pager->getNumRows();
587 * SQL clause to skip forbidden log types for this user
588 * @param $db Database
589 * @param $audience string, public/user
590 * @return mixed (string or false)
592 public static function getExcludeClause( $db, $audience = 'public' ) {
593 global $wgLogRestrictions, $wgUser;
594 // Reset the array, clears extra "where" clauses when $par is used
595 $hiddenLogs = array();
596 // Don't show private logs to unprivileged users
597 foreach( $wgLogRestrictions as $logType => $right ) {
598 if( $audience == 'public' ||
!$wgUser->isAllowed($right) ) {
599 $safeType = $db->strencode( $logType );
600 $hiddenLogs[] = $safeType;
603 if( count($hiddenLogs) == 1 ) {
604 return 'log_type != ' . $db->addQuotes( $hiddenLogs[0] );
605 } elseif( $hiddenLogs ) {
606 return 'log_type NOT IN (' . $db->makeList($hiddenLogs) . ')';
615 class LogPager
extends ReverseChronologicalPager
{
616 private $types = array(), $user = '', $title = '', $pattern = '';
617 private $typeCGI = '';
618 public $mLogEventsList;
622 * @param $list LogEventsList
623 * @param $types String or Array
624 * @param $user String
625 * @param $title String
626 * @param $pattern String
627 * @param $conds Array
628 * @param $year Integer
629 * @param $month Integer
631 public function __construct( $list, $types = array(), $user = '', $title = '', $pattern = '',
632 $conds = array(), $year = false, $month = false, $tagFilter = '' )
634 parent
::__construct();
635 $this->mConds
= $conds;
637 $this->mLogEventsList
= $list;
639 $this->limitType( $types ); // also excludes hidden types
640 $this->limitUser( $user );
641 $this->limitTitle( $title, $pattern );
642 $this->getDateCond( $year, $month );
643 $this->mTagFilter
= $tagFilter;
646 public function getDefaultQuery() {
647 $query = parent
::getDefaultQuery();
648 $query['type'] = $this->typeCGI
; // arrays won't work here
649 $query['user'] = $this->user
;
650 $query['month'] = $this->mMonth
;
651 $query['year'] = $this->mYear
;
655 // Call ONLY after calling $this->limitType() already!
656 public function getFilterParams() {
657 global $wgFilterLogTypes, $wgUser, $wgRequest;
659 if( count($this->types
) ) {
662 foreach( $wgFilterLogTypes as $type => $default ) {
663 // Avoid silly filtering
664 if( $type !== 'patrol' ||
$wgUser->useNPPatrol() ) {
665 $hide = $wgRequest->getInt( "hide_{$type}_log", $default );
666 $filters[$type] = $hide;
668 $this->mConds
[] = 'log_type != ' . $this->mDb
->addQuotes( $type );
675 * Set the log reader to return only entries of the given type.
676 * Type restrictions enforced here
677 * @param $types String or array: Log types ('upload', 'delete', etc);
678 * empty string means no restriction
680 private function limitType( $types ) {
681 global $wgLogRestrictions, $wgUser;
682 // If $types is not an array, make it an array
683 $types = ($types === '') ?
array() : (array)$types;
684 // Don't even show header for private logs; don't recognize it...
685 foreach ( $types as $type ) {
686 if( isset( $wgLogRestrictions[$type] ) && !$wgUser->isAllowed($wgLogRestrictions[$type]) ) {
687 $types = array_diff( $types, array( $type ) );
690 // Don't show private logs to unprivileged users.
691 // Also, only show them upon specific request to avoid suprises.
692 $audience = $types ?
'user' : 'public';
693 $hideLogs = LogEventsList
::getExcludeClause( $this->mDb
, $audience );
694 if( $hideLogs !== false ) {
695 $this->mConds
[] = $hideLogs;
697 if( count($types) ) {
698 $this->types
= $types;
699 $this->mConds
['log_type'] = $types;
700 // Set typeCGI; used in url param for paging
701 if( count($types) == 1 ) $this->typeCGI
= $types[0];
706 * Set the log reader to return only entries by the given user.
707 * @param $name String: (In)valid user name
709 private function limitUser( $name ) {
713 $usertitle = Title
::makeTitleSafe( NS_USER
, $name );
714 if( is_null($usertitle) ) {
717 /* Fetch userid at first, if known, provides awesome query plan afterwards */
718 $userid = User
::idFromName( $name );
720 /* It should be nicer to abort query at all,
721 but for now it won't pass anywhere behind the optimizer */
722 $this->mConds
[] = "NULL";
725 $this->mConds
['log_user'] = $userid;
726 // Paranoia: avoid brute force searches (bug 17342)
727 if( !$wgUser->isAllowed( 'deleterevision' ) ) {
728 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::DELETED_USER
) . ' = 0';
729 } else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
730 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::SUPPRESSED_USER
) .
731 ' != ' . LogPage
::SUPPRESSED_USER
;
733 $this->user
= $usertitle->getText();
738 * Set the log reader to return only entries affecting the given page.
739 * (For the block and rights logs, this is a user page.)
740 * @param $page String: Title name as text
741 * @param $pattern String
743 private function limitTitle( $page, $pattern ) {
744 global $wgMiserMode, $wgUser;
746 $title = Title
::newFromText( $page );
747 if( strlen($page) == 0 ||
!$title instanceof Title
)
750 $this->title
= $title->getPrefixedText();
751 $ns = $title->getNamespace();
752 # Using the (log_namespace, log_title, log_timestamp) index with a
753 # range scan (LIKE) on the first two parts, instead of simple equality,
754 # makes it unusable for sorting. Sorted retrieval using another index
755 # would be possible, but then we might have to scan arbitrarily many
756 # nodes of that index. Therefore, we need to avoid this if $wgMiserMode
759 # This is not a problem with simple title matches, because then we can
760 # use the page_time index. That should have no more than a few hundred
761 # log entries for even the busiest pages, so it can be safely scanned
762 # in full to satisfy an impossible condition on user or similar.
763 if( $pattern && !$wgMiserMode ) {
764 # use escapeLike to avoid expensive search patterns like 't%st%'
765 $safetitle = $this->mDb
->escapeLike( $title->getDBkey() );
766 $this->mConds
['log_namespace'] = $ns;
767 $this->mConds
[] = "log_title LIKE '$safetitle%'";
768 $this->pattern
= $pattern;
770 $this->mConds
['log_namespace'] = $ns;
771 $this->mConds
['log_title'] = $title->getDBkey();
773 // Paranoia: avoid brute force searches (bug 17342)
774 if( !$wgUser->isAllowed( 'deleterevision' ) ) {
775 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::DELETED_ACTION
) . ' = 0';
776 } else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
777 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::SUPPRESSED_ACTION
) .
778 ' != ' . LogPage
::SUPPRESSED_ACTION
;
782 public function getQueryInfo() {
783 $tables = array( 'logging', 'user' );
784 $this->mConds
[] = 'user_id = log_user';
786 # Add log_search table if there are conditions on it
787 if( array_key_exists('ls_field',$this->mConds
) ) {
788 $tables[] = 'log_search';
789 $index = array( 'log_search' => 'ls_field_val', 'logging' => 'PRIMARY' );
790 $groupBy = 'ls_log_id';
791 # Don't use the wrong logging index
792 } else if( $this->title ||
$this->pattern ||
$this->user
) {
793 $index = array( 'logging' => array('page_time','user_time') );
794 } else if( $this->types
) {
795 $index = array( 'logging' => 'type_time' );
797 $index = array( 'logging' => 'times' );
799 $options = array( 'USE INDEX' => $index );
800 # Don't show duplicate rows when using log_search
801 if( $groupBy ) $options['GROUP BY'] = $groupBy;
804 'fields' => array( 'log_type', 'log_action', 'log_user', 'log_namespace',
805 'log_title', 'log_params', 'log_comment', 'log_id', 'log_deleted',
806 'log_timestamp', 'user_name', 'user_editcount' ),
807 'conds' => $this->mConds
,
808 'options' => $options,
809 'join_conds' => array(
810 'user' => array( 'INNER JOIN', 'user_id=log_user' ),
811 'log_search' => array( 'INNER JOIN', 'ls_log_id=log_id' )
814 # Add ChangeTags filter query
815 ChangeTags
::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'],
816 $info['join_conds'], $info['options'], $this->mTagFilter
);
821 function getIndexField() {
822 return 'log_timestamp';
825 public function getStartBody() {
826 wfProfileIn( __METHOD__
);
827 # Do a link batch query
828 if( $this->getNumRows() > 0 ) {
830 while( $row = $this->mResult
->fetchObject() ) {
831 $lb->add( $row->log_namespace
, $row->log_title
);
832 $lb->addObj( Title
::makeTitleSafe( NS_USER
, $row->user_name
) );
833 $lb->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->user_name
) );
836 $this->mResult
->seek( 0 );
838 wfProfileOut( __METHOD__
);
842 public function formatRow( $row ) {
843 return $this->mLogEventsList
->logLine( $row );
846 public function getType() {
850 public function getUser() {
854 public function getPage() {
858 public function getPattern() {
859 return $this->pattern
;
862 public function getYear() {
866 public function getMonth() {
867 return $this->mMonth
;
870 public function getTagFilter() {
871 return $this->mTagFilter
;
874 public function doQuery() {
875 // Workaround MySQL optimizer bug
876 $this->mDb
->setBigSelects();
878 $this->mDb
->setBigSelects( 'default' );
884 * @ingroup SpecialPage
889 * @param $request WebRequest: for internal use use a FauxRequest object to pass arbitrary parameters.
891 function __construct( $request ) {
892 global $wgUser, $wgOut;
893 wfDeprecated(__METHOD__
);
895 $type = $request->getVal( 'type' );
896 $user = $request->getText( 'user' );
897 $title = $request->getText( 'page' );
898 $pattern = $request->getBool( 'pattern' );
899 $year = $request->getIntOrNull( 'year' );
900 $month = $request->getIntOrNull( 'month' );
901 $tagFilter = $request->getVal( 'tagfilter' );
902 # Don't let the user get stuck with a certain date
903 $skip = $request->getText( 'offset' ) ||
$request->getText( 'dir' ) == 'prev';
908 # Use new list class to output results
909 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
910 $this->pager
= new LogPager( $loglist, $type, $user, $title, $pattern, $year, $month, $tagFilter );
914 * Is there at least one row?
917 public function hasRows() {
918 return isset($this->pager
) ?
($this->pager
->getNumRows() > 0) : false;
924 * @ingroup SpecialPage
927 const NO_ACTION_LINK
= 1;
935 * @param &$reader LogReader: where to get our data from
936 * @param $flags Integer: Bitwise combination of flags:
937 * LogEventsList::NO_ACTION_LINK Don't show restore/unblock/block links
939 function __construct( &$reader, $flags = 0 ) {
940 wfDeprecated(__METHOD__
);
941 $this->reader
=& $reader;
942 $this->reader
->pager
->mLogEventsList
->flags
= $flags;
943 # Aliases for shorter code...
944 $this->pager
=& $this->reader
->pager
;
945 $this->list =& $this->reader
->pager
->mLogEventsList
;
949 * Take over the whole output page in $wgOut with the log display.
951 public function show() {
952 # Set title and add header
953 $this->list->showHeader( $pager->getType() );
955 $this->list->showOptions( $this->pager
->getType(), $this->pager
->getUser(), $this->pager
->getPage(),
956 $this->pager
->getPattern(), $this->pager
->getYear(), $this->pager
->getMonth() );
958 $logBody = $this->pager
->getBody();
961 $this->pager
->getNavigationBar() .
962 $this->list->beginLogEventsList() .
964 $this->list->endLogEventsList() .
965 $this->pager
->getNavigationBar()
968 $wgOut->addWikiMsg( 'logempty' );
973 * Output just the list of entries given by the linked LogReader,
974 * with extraneous UI elements. Use for displaying log fragments in
975 * another page (eg at Special:Undelete)
976 * @param $out OutputPage: where to send output
978 public function showList( &$out ) {
979 $logBody = $this->pager
->getBody();
982 $this->list->beginLogEventsList() .
984 $this->list->endLogEventsList()
987 $out->addWikiMsg( 'logempty' );