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 * Show log extract. Either with text and a box (set $msgKey) or without (don't set $msgKey)
560 * @param $out OutputPage or String-by-reference
561 * @param $types String or Array
562 * @param $page String
563 * @param $user String
564 * @param $lim Integer Limit of items to show, default is 50
565 * @param $conds Array
566 * @param $showIfEmpty boolean Set to false if you don't want any output in case the loglist is empty
567 * if set to true (default), "No matching items in log" is displayed if loglist is empty
568 * @param $msgKey String if you want a nice box with a message, set this to the key of the message
569 * @return Integer Number of total log items (not limited by $lim)
571 public static function showLogExtract( &$out, $types=array(), $page='', $user='', $lim=0, $conds=array(), $showIfEmpty = true, $msgKey = '' ) {
572 global $wgUser, $wgOut;
573 # Insert list of top 50 or so items
574 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
575 $pager = new LogPager( $loglist, $types, $user, $page, '', $conds );
576 if( $lim > 0 ) $pager->mLimit
= $lim;
577 $logBody = $pager->getBody();
580 $s = '<div class="mw-warning-with-logexcerpt">' . wfMsg( $msgKey ) ;
581 $s .= $loglist->beginLogEventsList() .
583 $loglist->endLogEventsList();
586 $s = wfMsgExt( 'logempty', array('parse') );
588 if( $pager->getNumRows() > $pager->mLimit
) { # Show "Full log" link
591 $urlParam['page'] = $page;
593 $urlParam['user'] = $user;
594 if ( !is_array( $types ) ) # Make it an array, if it isn't
595 $types = array( $types );
596 # If there is exactly one log type, we can link to Special:Log?type=foo
597 if ( count( $types ) == 1 )
598 $urlParam['type'] = $types[0];
599 $s .= $wgUser->getSkin()->link(
600 SpecialPage
::getTitleFor( 'Log' ),
601 wfMsgHtml( 'log-fulllog' ),
607 if ( $logBody && $msgKey )
610 if( $out instanceof OutputPage
){
615 return $pager->getNumRows();
619 * SQL clause to skip forbidden log types for this user
620 * @param $db Database
621 * @param $audience string, public/user
622 * @return mixed (string or false)
624 public static function getExcludeClause( $db, $audience = 'public' ) {
625 global $wgLogRestrictions, $wgUser;
626 // Reset the array, clears extra "where" clauses when $par is used
627 $hiddenLogs = array();
628 // Don't show private logs to unprivileged users
629 foreach( $wgLogRestrictions as $logType => $right ) {
630 if( $audience == 'public' ||
!$wgUser->isAllowed($right) ) {
631 $safeType = $db->strencode( $logType );
632 $hiddenLogs[] = $safeType;
635 if( count($hiddenLogs) == 1 ) {
636 return 'log_type != ' . $db->addQuotes( $hiddenLogs[0] );
637 } elseif( $hiddenLogs ) {
638 return 'log_type NOT IN (' . $db->makeList($hiddenLogs) . ')';
647 class LogPager
extends ReverseChronologicalPager
{
648 private $types = array(), $user = '', $title = '', $pattern = '';
649 private $typeCGI = '';
650 public $mLogEventsList;
654 * @param $list LogEventsList
655 * @param $types String or Array
656 * @param $user String
657 * @param $title String
658 * @param $pattern String
659 * @param $conds Array
660 * @param $year Integer
661 * @param $month Integer
663 public function __construct( $list, $types = array(), $user = '', $title = '', $pattern = '',
664 $conds = array(), $year = false, $month = false, $tagFilter = '' )
666 parent
::__construct();
667 $this->mConds
= $conds;
669 $this->mLogEventsList
= $list;
671 $this->limitType( $types ); // also excludes hidden types
672 $this->limitUser( $user );
673 $this->limitTitle( $title, $pattern );
674 $this->getDateCond( $year, $month );
675 $this->mTagFilter
= $tagFilter;
678 public function getDefaultQuery() {
679 $query = parent
::getDefaultQuery();
680 $query['type'] = $this->typeCGI
; // arrays won't work here
681 $query['user'] = $this->user
;
682 $query['month'] = $this->mMonth
;
683 $query['year'] = $this->mYear
;
687 // Call ONLY after calling $this->limitType() already!
688 public function getFilterParams() {
689 global $wgFilterLogTypes, $wgUser, $wgRequest;
691 if( count($this->types
) ) {
694 foreach( $wgFilterLogTypes as $type => $default ) {
695 // Avoid silly filtering
696 if( $type !== 'patrol' ||
$wgUser->useNPPatrol() ) {
697 $hide = $wgRequest->getInt( "hide_{$type}_log", $default );
698 $filters[$type] = $hide;
700 $this->mConds
[] = 'log_type != ' . $this->mDb
->addQuotes( $type );
707 * Set the log reader to return only entries of the given type.
708 * Type restrictions enforced here
709 * @param $types String or array: Log types ('upload', 'delete', etc);
710 * empty string means no restriction
712 private function limitType( $types ) {
713 global $wgLogRestrictions, $wgUser;
714 // If $types is not an array, make it an array
715 $types = ($types === '') ?
array() : (array)$types;
716 // Don't even show header for private logs; don't recognize it...
717 foreach ( $types as $type ) {
718 if( isset( $wgLogRestrictions[$type] ) && !$wgUser->isAllowed($wgLogRestrictions[$type]) ) {
719 $types = array_diff( $types, array( $type ) );
722 // Don't show private logs to unprivileged users.
723 // Also, only show them upon specific request to avoid suprises.
724 $audience = $types ?
'user' : 'public';
725 $hideLogs = LogEventsList
::getExcludeClause( $this->mDb
, $audience );
726 if( $hideLogs !== false ) {
727 $this->mConds
[] = $hideLogs;
729 if( count($types) ) {
730 $this->types
= $types;
731 $this->mConds
['log_type'] = $types;
732 // Set typeCGI; used in url param for paging
733 if( count($types) == 1 ) $this->typeCGI
= $types[0];
738 * Set the log reader to return only entries by the given user.
739 * @param $name String: (In)valid user name
741 private function limitUser( $name ) {
745 $usertitle = Title
::makeTitleSafe( NS_USER
, $name );
746 if( is_null($usertitle) ) {
749 /* Fetch userid at first, if known, provides awesome query plan afterwards */
750 $userid = User
::idFromName( $name );
752 /* It should be nicer to abort query at all,
753 but for now it won't pass anywhere behind the optimizer */
754 $this->mConds
[] = "NULL";
757 $this->mConds
['log_user'] = $userid;
758 // Paranoia: avoid brute force searches (bug 17342)
759 if( !$wgUser->isAllowed( 'deleterevision' ) ) {
760 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::DELETED_USER
) . ' = 0';
761 } else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
762 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::SUPPRESSED_USER
) .
763 ' != ' . LogPage
::SUPPRESSED_USER
;
765 $this->user
= $usertitle->getText();
770 * Set the log reader to return only entries affecting the given page.
771 * (For the block and rights logs, this is a user page.)
772 * @param $page String: Title name as text
773 * @param $pattern String
775 private function limitTitle( $page, $pattern ) {
776 global $wgMiserMode, $wgUser;
778 $title = Title
::newFromText( $page );
779 if( strlen($page) == 0 ||
!$title instanceof Title
)
782 $this->title
= $title->getPrefixedText();
783 $ns = $title->getNamespace();
784 # Using the (log_namespace, log_title, log_timestamp) index with a
785 # range scan (LIKE) on the first two parts, instead of simple equality,
786 # makes it unusable for sorting. Sorted retrieval using another index
787 # would be possible, but then we might have to scan arbitrarily many
788 # nodes of that index. Therefore, we need to avoid this if $wgMiserMode
791 # This is not a problem with simple title matches, because then we can
792 # use the page_time index. That should have no more than a few hundred
793 # log entries for even the busiest pages, so it can be safely scanned
794 # in full to satisfy an impossible condition on user or similar.
795 if( $pattern && !$wgMiserMode ) {
796 # use escapeLike to avoid expensive search patterns like 't%st%'
797 $safetitle = $this->mDb
->escapeLike( $title->getDBkey() );
798 $this->mConds
['log_namespace'] = $ns;
799 $this->mConds
[] = "log_title LIKE '$safetitle%'";
800 $this->pattern
= $pattern;
802 $this->mConds
['log_namespace'] = $ns;
803 $this->mConds
['log_title'] = $title->getDBkey();
805 // Paranoia: avoid brute force searches (bug 17342)
806 if( !$wgUser->isAllowed( 'deleterevision' ) ) {
807 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::DELETED_ACTION
) . ' = 0';
808 } else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
809 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::SUPPRESSED_ACTION
) .
810 ' != ' . LogPage
::SUPPRESSED_ACTION
;
814 public function getQueryInfo() {
815 $tables = array( 'logging', 'user' );
816 $this->mConds
[] = 'user_id = log_user';
818 # Add log_search table if there are conditions on it
819 if( array_key_exists('ls_field',$this->mConds
) ) {
820 $tables[] = 'log_search';
821 $index = array( 'log_search' => 'ls_field_val', 'logging' => 'PRIMARY' );
822 $groupBy = 'ls_log_id';
823 # Don't use the wrong logging index
824 } else if( $this->title ||
$this->pattern ||
$this->user
) {
825 $index = array( 'logging' => array('page_time','user_time') );
826 } else if( $this->types
) {
827 $index = array( 'logging' => 'type_time' );
829 $index = array( 'logging' => 'times' );
831 $options = array( 'USE INDEX' => $index );
832 # Don't show duplicate rows when using log_search
833 if( $groupBy ) $options['GROUP BY'] = $groupBy;
836 'fields' => array( 'log_type', 'log_action', 'log_user', 'log_namespace',
837 'log_title', 'log_params', 'log_comment', 'log_id', 'log_deleted',
838 'log_timestamp', 'user_name', 'user_editcount' ),
839 'conds' => $this->mConds
,
840 'options' => $options,
841 'join_conds' => array(
842 'user' => array( 'INNER JOIN', 'user_id=log_user' ),
843 'log_search' => array( 'INNER JOIN', 'ls_log_id=log_id' )
846 # Add ChangeTags filter query
847 ChangeTags
::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'],
848 $info['join_conds'], $info['options'], $this->mTagFilter
);
853 function getIndexField() {
854 return 'log_timestamp';
857 public function getStartBody() {
858 wfProfileIn( __METHOD__
);
859 # Do a link batch query
860 if( $this->getNumRows() > 0 ) {
862 while( $row = $this->mResult
->fetchObject() ) {
863 $lb->add( $row->log_namespace
, $row->log_title
);
864 $lb->addObj( Title
::makeTitleSafe( NS_USER
, $row->user_name
) );
865 $lb->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->user_name
) );
868 $this->mResult
->seek( 0 );
870 wfProfileOut( __METHOD__
);
874 public function formatRow( $row ) {
875 return $this->mLogEventsList
->logLine( $row );
878 public function getType() {
882 public function getUser() {
886 public function getPage() {
890 public function getPattern() {
891 return $this->pattern
;
894 public function getYear() {
898 public function getMonth() {
899 return $this->mMonth
;
902 public function getTagFilter() {
903 return $this->mTagFilter
;
906 public function doQuery() {
907 // Workaround MySQL optimizer bug
908 $this->mDb
->setBigSelects();
910 $this->mDb
->setBigSelects( 'default' );
916 * @ingroup SpecialPage
921 * @param $request WebRequest: for internal use use a FauxRequest object to pass arbitrary parameters.
923 function __construct( $request ) {
924 global $wgUser, $wgOut;
925 wfDeprecated(__METHOD__
);
927 $type = $request->getVal( 'type' );
928 $user = $request->getText( 'user' );
929 $title = $request->getText( 'page' );
930 $pattern = $request->getBool( 'pattern' );
931 $year = $request->getIntOrNull( 'year' );
932 $month = $request->getIntOrNull( 'month' );
933 $tagFilter = $request->getVal( 'tagfilter' );
934 # Don't let the user get stuck with a certain date
935 $skip = $request->getText( 'offset' ) ||
$request->getText( 'dir' ) == 'prev';
940 # Use new list class to output results
941 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
942 $this->pager
= new LogPager( $loglist, $type, $user, $title, $pattern, $year, $month, $tagFilter );
946 * Is there at least one row?
949 public function hasRows() {
950 return isset($this->pager
) ?
($this->pager
->getNumRows() > 0) : false;
956 * @ingroup SpecialPage
959 const NO_ACTION_LINK
= 1;
967 * @param &$reader LogReader: where to get our data from
968 * @param $flags Integer: Bitwise combination of flags:
969 * LogEventsList::NO_ACTION_LINK Don't show restore/unblock/block links
971 function __construct( &$reader, $flags = 0 ) {
972 wfDeprecated(__METHOD__
);
973 $this->reader
=& $reader;
974 $this->reader
->pager
->mLogEventsList
->flags
= $flags;
975 # Aliases for shorter code...
976 $this->pager
=& $this->reader
->pager
;
977 $this->list =& $this->reader
->pager
->mLogEventsList
;
981 * Take over the whole output page in $wgOut with the log display.
983 public function show() {
984 # Set title and add header
985 $this->list->showHeader( $pager->getType() );
987 $this->list->showOptions( $this->pager
->getType(), $this->pager
->getUser(), $this->pager
->getPage(),
988 $this->pager
->getPattern(), $this->pager
->getYear(), $this->pager
->getMonth() );
990 $logBody = $this->pager
->getBody();
993 $this->pager
->getNavigationBar() .
994 $this->list->beginLogEventsList() .
996 $this->list->endLogEventsList() .
997 $this->pager
->getNavigationBar()
1000 $wgOut->addWikiMsg( 'logempty' );
1005 * Output just the list of entries given by the linked LogReader,
1006 * with extraneous UI elements. Use for displaying log fragments in
1007 * another page (eg at Special:Undelete)
1008 * @param $out OutputPage: where to send output
1010 public function showList( &$out ) {
1011 $logBody = $this->pager
->getBody();
1014 $this->list->beginLogEventsList() .
1016 $this->list->endLogEventsList()
1019 $out->addWikiMsg( 'logempty' );