2 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>, 2008 Aaron Schulz
3 # http://www.mediawiki.org/
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # http://www.gnu.org/copyleft/gpl.html
21 const NO_ACTION_LINK
= 1;
22 const NO_EXTRA_USER_LINKS
= 2;
28 public function __construct( $skin, $out, $flags = 0 ) {
31 $this->flags
= $flags;
32 $this->preCacheMessages();
36 * As we use the same small set of messages in various methods and that
37 * they are called often, we call them once and save them in $this->message
39 private function preCacheMessages() {
40 // Precache various messages
41 if( !isset( $this->message
) ) {
42 $messages = array( 'revertmerge', 'protect_change', 'unblocklink', 'change-blocklink',
43 'revertmove', 'undeletelink', 'undeleteviewlink', 'revdel-restore', 'hist', 'diff',
44 'pipe-separator', 'revdel-restore-deleted', 'revdel-restore-visible' );
45 foreach( $messages as $msg ) {
46 $this->message
[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
52 * Set page title and show header for this log type
55 public function showHeader( $type ) {
56 // If only one log type is used, then show a special message...
57 $headerType = (count($type) == 1) ?
$type[0] : '';
58 if( LogPage
::isLogType( $headerType ) ) {
59 $this->out
->setPageTitle( LogPage
::logName( $headerType ) );
60 $this->out
->addHTML( LogPage
::logHeader( $headerType ) );
62 $this->out
->addHTML( wfMsgExt('alllogstext',array('parseinline')) );
67 * Show options for the log list
68 * @param $types string or Array
71 * @param $pattern String
72 * @param $year Integer: year
73 * @param $month Integer: month
74 * @param $filter: array
75 * @param $tagFilter: array?
77 public function showOptions( $types=array(), $user='', $page='', $pattern='', $year='',
78 $month = '', $filter = null, $tagFilter='' )
80 global $wgScript, $wgMiserMode;
83 $title = SpecialPage
::getTitleFor( 'Log' );
84 $special = $title->getPrefixedDBkey();
86 // For B/C, we take strings, but make sure they are converted...
87 $types = ($types === '') ?
array() : (array)$types;
89 $tagSelector = ChangeTags
::buildTagFilterSelector( $tagFilter );
92 $html .= Xml
::hidden( 'title', $special );
95 $html .= $this->getTypeMenu( $types ) . "\n";
96 $html .= $this->getUserInput( $user ) . "\n";
97 $html .= $this->getTitleInput( $page ) . "\n";
98 $html .= $this->getExtraInputs( $types ) . "\n";
100 // Title pattern, if allowed
102 $html .= $this->getTitlePattern( $pattern ) . "\n";
106 $html .= Xml
::tags( 'p', null, Xml
::dateMenu( $year, $month ) );
110 $html .= Xml
::tags( 'p', null, implode( ' ', $tagSelector ) );
115 $html .= Xml
::tags( 'p', null, $this->getFilterLinks( $filter ) );
119 $html .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) );
122 $html = Xml
::fieldset( wfMsg( 'log' ), $html );
125 $html = Xml
::tags( 'form', array( 'action' => $action, 'method' => 'get' ), $html );
127 $this->out
->addHTML( $html );
131 * @param $filter Array
132 * @return String: Formatted HTML
134 private function getFilterLinks( $filter ) {
135 global $wgTitle, $wgLang;
137 $messages = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
138 // Option value -> message mapping
140 $hiddens = ''; // keep track for "go" button
141 foreach( $filter as $type => $val ) {
142 // Should the below assignment be outside the foreach?
143 // Then it would have to be copied. Not certain what is more expensive.
144 $query = $this->getDefaultQuery();
145 $queryKey = "hide_{$type}_log";
147 $hideVal = 1 - intval($val);
148 $query[$queryKey] = $hideVal;
150 $link = $this->skin
->link(
155 array( 'known', 'noclasses' )
158 $links[$type] = wfMsgHtml( "log-show-hide-{$type}", $link );
159 $hiddens .= Xml
::hidden( "hide_{$type}_log", $val ) . "\n";
162 return '<small>'.$wgLang->pipeList( $links ) . '</small>' . $hiddens;
165 private function getDefaultQuery() {
166 if ( !isset( $this->mDefaultQuery
) ) {
167 $this->mDefaultQuery
= $_GET;
168 unset( $this->mDefaultQuery
['title'] );
169 unset( $this->mDefaultQuery
['dir'] );
170 unset( $this->mDefaultQuery
['offset'] );
171 unset( $this->mDefaultQuery
['limit'] );
172 unset( $this->mDefaultQuery
['order'] );
173 unset( $this->mDefaultQuery
['month'] );
174 unset( $this->mDefaultQuery
['year'] );
176 return $this->mDefaultQuery
;
180 * @param $queryTypes Array
181 * @return String: Formatted HTML
183 private function getTypeMenu( $queryTypes ) {
184 global $wgLogRestrictions, $wgUser;
186 $html = "<select name='type'>\n";
188 $validTypes = LogPage
::validTypes();
189 $typesByName = array(); // Temporary array
191 // First pass to load the log names
192 foreach( $validTypes as $type ) {
193 $text = LogPage
::logName( $type );
194 $typesByName[$type] = $text;
197 // Second pass to sort by name
200 // Note the query type
201 $queryType = count($queryTypes) == 1 ?
$queryTypes[0] : '';
203 // Always put "All public logs" on top
204 if ( isset( $typesByName[''] ) ) {
205 $all = $typesByName[''];
206 unset( $typesByName[''] );
207 $typesByName = array( '' => $all ) +
$typesByName;
210 // Third pass generates sorted XHTML content
211 foreach( $typesByName as $type => $text ) {
212 $selected = ($type == $queryType);
214 if ( isset($wgLogRestrictions[$type]) ) {
215 if ( $wgUser->isAllowed( $wgLogRestrictions[$type] ) ) {
216 $html .= Xml
::option( $text, $type, $selected ) . "\n";
219 $html .= Xml
::option( $text, $type, $selected ) . "\n";
223 $html .= '</select>';
228 * @param $user String
229 * @return String: Formatted HTML
231 private function getUserInput( $user ) {
232 return '<span style="white-space: nowrap">' .
233 Xml
::inputLabel( wfMsg( 'specialloguserlabel' ), 'user', 'mw-log-user', 15, $user ) .
238 * @param $title String
239 * @return String: Formatted HTML
241 private function getTitleInput( $title ) {
242 return '<span style="white-space: nowrap">' .
243 Xml
::inputLabel( wfMsg( 'speciallogtitlelabel' ), 'page', 'mw-log-page', 20, $title ) .
248 * @return boolean Checkbox
250 private function getTitlePattern( $pattern ) {
251 return '<span style="white-space: nowrap">' .
252 Xml
::checkLabel( wfMsg( 'log-title-wildcard' ), 'pattern', 'pattern', $pattern ) .
256 private function getExtraInputs( $types ) {
258 $offender = $wgRequest->getVal('offender');
259 $user = User
::newFromName( $offender, false );
260 if( !$user ||
($user->getId() == 0 && !IP
::isIPAddress($offender) ) ) {
261 $offender = ''; // Blank field if invalid
263 if( count($types) == 1 && $types[0] == 'suppress' ) {
264 return Xml
::inputLabel( wfMsg('revdelete-offender'), 'offender',
265 'mw-log-offender', 20, $offender );
270 public function beginLogEventsList() {
274 public function endLogEventsList() {
279 * @param $row Row: a single row from the result set
280 * @return String: Formatted HTML list item
282 public function logLine( $row ) {
283 $classes = array( 'mw-logline-' . $row->log_type
);
284 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
286 $time = $this->logTimestamp( $row );
288 $userLink = $this->logUserLinks( $row );
289 // Extract extra parameters
290 $paramArray = LogPage
::extractParams( $row->log_params
);
292 $action = $this->logAction( $row, $title, $paramArray );
294 $comment = $this->logComment( $row );
295 // Add review/revert links and such...
296 $revert = $this->logActionLinks( $row, $title, $paramArray, $comment );
298 // Some user can hide log items and have review links
299 $del = $this->getShowHideLinks( $row );
300 if( $del != '' ) $del .= ' ';
303 list( $tagDisplay, $newClasses ) = ChangeTags
::formatSummaryRow( $row->ts_tags
, 'logevent' );
304 $classes = array_merge( $classes, $newClasses );
306 return Xml
::tags( 'li', array( "class" => implode( ' ', $classes ) ),
307 $del . "$time $userLink $action $comment $revert $tagDisplay" ) . "\n";
310 private function logTimestamp( $row ) {
312 $time = $wgLang->timeanddate( wfTimestamp( TS_MW
, $row->log_timestamp
), true );
313 return htmlspecialchars( $time );
316 private function logUserLinks( $row ) {
318 if( self
::isDeleted( $row, LogPage
::DELETED_USER
) ) {
319 $userLinks = '<span class="history-deleted">' .
320 wfMsgHtml( 'rev-deleted-user' ) . '</span>';
322 $userLinks = $this->skin
->userLink( $row->log_user
, $row->user_name
);
323 // Talk|Contribs links...
324 if( !( $this->flags
& self
::NO_EXTRA_USER_LINKS
) ) {
325 $userLinks .= $this->skin
->userToolLinks(
326 $row->log_user
, $row->user_name
, true, 0, $row->user_editcount
);
332 private function logAction( $row, $title, $paramArray ) {
334 if( self
::isDeleted( $row, LogPage
::DELETED_ACTION
) ) {
335 $action = '<span class="history-deleted">' .
336 wfMsgHtml( 'rev-deleted-event' ) . '</span>';
338 $action = LogPage
::actionText(
339 $row->log_type
, $row->log_action
, $title, $this->skin
, $paramArray, true );
344 private function logComment( $row ) {
347 if( self
::isDeleted( $row, LogPage
::DELETED_COMMENT
) ) {
348 $comment = '<span class="history-deleted">' .
349 wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
351 $comment = $wgContLang->getDirMark() .
352 $this->skin
->commentBlock( $row->log_comment
);
358 private function logActionLinks( $row, $title, $paramArray, &$comment ) {
359 global $wgUser, $wgLang;
360 if( ( $this->flags
& self
::NO_ACTION_LINK
) // we don't want to see the action
361 || self
::isDeleted( $row, LogPage
::DELETED_ACTION
) ) // action is hidden
366 if( self
::typeAction( $row, 'move', 'move', 'move' ) && !empty( $paramArray[0] ) ) {
367 $destTitle = Title
::newFromText( $paramArray[0] );
369 $revert = '(' . $this->skin
->link(
370 SpecialPage
::getTitleFor( 'Movepage' ),
371 $this->message
['revertmove'],
374 'wpOldTitle' => $destTitle->getPrefixedDBkey(),
375 'wpNewTitle' => $title->getPrefixedDBkey(),
376 'wpReason' => wfMsgForContent( 'revertmove' ),
379 array( 'known', 'noclasses' )
382 // Show undelete link
383 } else if( self
::typeAction( $row, array( 'delete', 'suppress' ), 'delete', 'deletedhistory' ) ) {
384 if( !$wgUser->isAllowed( 'undelete' ) ) {
385 $viewdeleted = $this->message
['undeleteviewlink'];
387 $viewdeleted = $this->message
['undeletelink'];
389 $revert = '(' . $this->skin
->link(
390 SpecialPage
::getTitleFor( 'Undelete' ),
393 array( 'target' => $title->getPrefixedDBkey() ),
394 array( 'known', 'noclasses' )
396 // Show unblock/change block link
397 } else if( self
::typeAction( $row, array( 'block', 'suppress' ), array( 'block', 'reblock' ), 'block' ) ) {
400 SpecialPage
::getTitleFor( 'Ipblocklist' ),
401 $this->message
['unblocklink'],
404 'action' => 'unblock',
405 'ip' => $row->log_title
409 $this->message
['pipe-separator'] .
411 SpecialPage
::getTitleFor( 'Blockip', $row->log_title
),
412 $this->message
['change-blocklink'],
418 // Show change protection link
419 } else if( self
::typeAction( $row, 'protect', array( 'modify', 'protect', 'unprotect' ) ) ) {
421 $this->skin
->link( $title,
422 $this->message
['hist'],
425 'action' => 'history',
426 'offset' => $row->log_timestamp
429 if( $wgUser->isAllowed( 'protect' ) ) {
430 $revert .= $this->message
['pipe-separator'] .
431 $this->skin
->link( $title,
432 $this->message
['protect_change'],
434 array( 'action' => 'protect' ),
439 } else if( self
::typeAction( $row, 'merge', 'merge', 'mergehistory' ) ) {
440 $revert = '(' . $this->skin
->link(
441 SpecialPage
::getTitleFor( 'MergeHistory' ),
442 $this->message
['revertmerge'],
445 'target' => $paramArray[0],
446 'dest' => $title->getPrefixedDBkey(),
447 'mergepoint' => $paramArray[1]
449 array( 'known', 'noclasses' )
451 // If an edit was hidden from a page give a review link to the history
452 } else if( self
::typeAction( $row, array( 'delete', 'suppress' ), 'revision', 'deletedhistory' ) ) {
453 $revert = RevisionDeleter
::getLogLinks( $title, $paramArray,
454 $this->skin
, $this->message
);
455 // Hidden log items, give review link
456 } else if( self
::typeAction( $row, array( 'delete', 'suppress' ), 'event', 'deletedhistory' ) ) {
457 if( count($paramArray) >= 1 ) {
458 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
459 // $paramArray[1] is a CSV of the IDs
460 $Ids = explode( ',', $paramArray[0] );
461 $query = $paramArray[0];
462 // Link to each hidden object ID, $paramArray[1] is the url param
463 $revert = '(' . $this->skin
->link(
465 $this->message
['revdel-restore'],
468 'target' => $title->getPrefixedText(),
472 array( 'known', 'noclasses' )
475 // Self-created users
476 } else if( self
::typeAction( $row, 'newusers', 'create2' ) ) {
477 if( isset( $paramArray[0] ) ) {
478 $revert = $this->skin
->userToolLinks( $paramArray[0], $title->getDBkey(), true );
480 # Fall back to a blue contributions link
481 $revert = $this->skin
->userToolLinks( 1, $title->getDBkey() );
483 $ts = wfTimestamp( TS_UNIX
, $row->log_timestamp
);
484 if( $ts < '20080129000000' ) {
485 # Suppress $comment from old entries (before 2008-01-29),
486 # not needed and can contain incorrect links
489 // Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
491 wfRunHooks( 'LogLine', array( $row->log_type
, $row->log_action
, $title, $paramArray,
492 &$comment, &$revert, $row->log_timestamp
) );
494 if( $revert != '' ) {
495 $revert = '<span class="mw-logevent-actionlink">' . $revert . '</span>';
504 private function getShowHideLinks( $row ) {
506 if( ( $this->flags
& self
::NO_ACTION_LINK
) // we don't want to see the links
507 ||
$row->log_type
== 'suppress' ) // no one can hide items from the suppress log
512 // Don't show useless link to people who cannot hide revisions
513 if( $wgUser->isAllowed( 'deletedhistory' ) ) {
514 if( $row->log_deleted ||
$wgUser->isAllowed( 'deleterevision' ) ) {
515 $canHide = $wgUser->isAllowed( 'deleterevision' );
516 // If event was hidden from sysops
517 if( !self
::userCan( $row, LogPage
::DELETED_RESTRICTED
) ) {
518 $del = $this->skin
->revDeleteLinkDisabled( $canHide );
520 $target = SpecialPage
::getTitleFor( 'Log', $row->log_type
);
522 'target' => $target->getPrefixedDBkey(),
524 'ids' => $row->log_id
,
526 $del = $this->skin
->revDeleteLink( $query,
527 self
::isDeleted( $row, LogPage
::DELETED_RESTRICTED
), $canHide );
536 * @param $type Mixed: string/array
537 * @param $action Mixed: string/array
538 * @param $right string
541 public static function typeAction( $row, $type, $action, $right='' ) {
542 $match = is_array($type) ?
543 in_array( $row->log_type
, $type ) : $row->log_type
== $type;
545 $match = is_array( $action ) ?
546 in_array( $row->log_action
, $action ) : $row->log_action
== $action;
547 if( $match && $right ) {
549 $match = $wgUser->isAllowed( $right );
556 * Determine if the current user is allowed to view a particular
557 * field of this log row, if it's marked as deleted.
559 * @param $field Integer
562 public static function userCan( $row, $field ) {
563 return self
::userCanBitfield( $row->log_deleted
, $field );
567 * Determine if the current user is allowed to view a particular
568 * field of this log row, if it's marked as deleted.
569 * @param $bitfield Integer (current field)
570 * @param $field Integer
573 public static function userCanBitfield( $bitfield, $field ) {
574 if( $bitfield & $field ) {
577 if ( $bitfield & LogPage
::DELETED_RESTRICTED
) {
578 $permission = 'suppressrevision';
580 $permission = 'deletedhistory';
582 wfDebug( "Checking for $permission due to $field match on $bitfield\n" );
583 return $wgUser->isAllowed( $permission );
591 * @param $field Integer: one of DELETED_* bitfield constants
594 public static function isDeleted( $row, $field ) {
595 return ( $row->log_deleted
& $field ) == $field;
599 * Show log extract. Either with text and a box (set $msgKey) or without (don't set $msgKey)
600 * @param $out OutputPage or String-by-reference
601 * @param $types String or Array
602 * @param $page String The page title to show log entries for
603 * @param $user String The user who made the log entries
604 * @param $param Associative Array with the following additional options:
605 * - lim Integer Limit of items to show, default is 50
606 * - conds Array Extra conditions for the query (e.g. "log_action != 'revision'")
607 * - showIfEmpty boolean Set to false if you don't want any output in case the loglist is empty
608 * if set to true (default), "No matching items in log" is displayed if loglist is empty
609 * - msgKey Array If you want a nice box with a message, set this to the key of the message.
610 * First element is the message key, additional optional elements are parameters for the key
611 * that are processed with wgMsgExt and option 'parse'
612 * - offset Set to overwrite offset parameter in $wgRequest
613 * set to '' to unset offset
614 * - wrap String Wrap the message in html (usually something like "<div ...>$1</div>").
615 * - flags Integer display flags (NO_ACTION_LINK,NO_EXTRA_USER_LINKS)
616 * @return Integer Number of total log items (not limited by $lim)
618 public static function showLogExtract(
619 &$out, $types=array(), $page='', $user='', $param = array()
621 global $wgUser, $wgOut;
622 $defaultParameters = array(
625 'showIfEmpty' => true,
626 'msgKey' => array(''),
630 # The + operator appends elements of remaining keys from the right
631 # handed array to the left handed, whereas duplicated keys are NOT overwritten.
632 $param +
= $defaultParameters;
633 # Convert $param array to individual variables
634 $lim = $param['lim'];
635 $conds = $param['conds'];
636 $showIfEmpty = $param['showIfEmpty'];
637 $msgKey = $param['msgKey'];
638 $wrap = $param['wrap'];
639 $flags = $param['flags'];
640 if ( !is_array( $msgKey ) ) {
641 $msgKey = array( $msgKey );
643 # Insert list of top 50 (or top $lim) items
644 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, $flags );
645 $pager = new LogPager( $loglist, $types, $user, $page, '', $conds );
646 if ( isset( $param['offset'] ) ) { # Tell pager to ignore $wgRequest offset
647 $pager->setOffset( $param['offset'] );
649 if( $lim > 0 ) $pager->mLimit
= $lim;
650 $logBody = $pager->getBody();
654 $s = '<div class="mw-warning-with-logexcerpt">';
656 if ( count( $msgKey ) == 1 ) {
657 $s .= wfMsgExt( $msgKey[0], array( 'parse' ) );
658 } else { // Process additional arguments
660 array_shift( $args );
661 $s .= wfMsgExt( $msgKey[0], array( 'parse' ), $args );
664 $s .= $loglist->beginLogEventsList() .
666 $loglist->endLogEventsList();
669 $s = Html
::rawElement( 'div', array( 'class' => 'mw-warning-logempty' ),
670 wfMsgExt( 'logempty', array( 'parseinline' ) ) );
672 if( $pager->getNumRows() > $pager->mLimit
) { # Show "Full log" link
675 $urlParam['page'] = $page;
677 $urlParam['user'] = $user;
678 if ( !is_array( $types ) ) # Make it an array, if it isn't
679 $types = array( $types );
680 # If there is exactly one log type, we can link to Special:Log?type=foo
681 if ( count( $types ) == 1 )
682 $urlParam['type'] = $types[0];
683 $s .= $wgUser->getSkin()->link(
684 SpecialPage
::getTitleFor( 'Log' ),
685 wfMsgHtml( 'log-fulllog' ),
690 if ( $logBody && $msgKey[0] ) {
694 if ( $wrap!='' ) { // Wrap message in html
695 $s = str_replace( '$1', $s, $wrap );
698 // $out can be either an OutputPage object or a String-by-reference
699 if( $out instanceof OutputPage
){
704 return $pager->getNumRows();
708 * SQL clause to skip forbidden log types for this user
709 * @param $db Database
710 * @param $audience string, public/user
711 * @return mixed (string or false)
713 public static function getExcludeClause( $db, $audience = 'public' ) {
714 global $wgLogRestrictions, $wgUser;
715 // Reset the array, clears extra "where" clauses when $par is used
716 $hiddenLogs = array();
717 // Don't show private logs to unprivileged users
718 foreach( $wgLogRestrictions as $logType => $right ) {
719 if( $audience == 'public' ||
!$wgUser->isAllowed($right) ) {
720 $safeType = $db->strencode( $logType );
721 $hiddenLogs[] = $safeType;
724 if( count($hiddenLogs) == 1 ) {
725 return 'log_type != ' . $db->addQuotes( $hiddenLogs[0] );
726 } elseif( $hiddenLogs ) {
727 return 'log_type NOT IN (' . $db->makeList($hiddenLogs) . ')';
736 class LogPager
extends ReverseChronologicalPager
{
737 private $types = array(), $user = '', $title = '', $pattern = '';
738 private $typeCGI = '';
739 public $mLogEventsList;
743 * @param $list LogEventsList
744 * @param $types String or Array log types to show
745 * @param $user String The user who made the log entries
746 * @param $title String The page title the log entries are for
747 * @param $pattern String Do a prefix search rather than an exact title match
748 * @param $conds Array Extra conditions for the query
749 * @param $year Integer The year to start from
750 * @param $month Integer The month to start from
752 public function __construct( $list, $types = array(), $user = '', $title = '', $pattern = '',
753 $conds = array(), $year = false, $month = false, $tagFilter = '' )
755 parent
::__construct();
756 $this->mConds
= $conds;
758 $this->mLogEventsList
= $list;
760 $this->limitType( $types ); // also excludes hidden types
761 $this->limitUser( $user );
762 $this->limitTitle( $title, $pattern );
763 $this->getDateCond( $year, $month );
764 $this->mTagFilter
= $tagFilter;
767 public function getDefaultQuery() {
768 $query = parent
::getDefaultQuery();
769 $query['type'] = $this->typeCGI
; // arrays won't work here
770 $query['user'] = $this->user
;
771 $query['month'] = $this->mMonth
;
772 $query['year'] = $this->mYear
;
776 // Call ONLY after calling $this->limitType() already!
777 public function getFilterParams() {
778 global $wgFilterLogTypes, $wgUser, $wgRequest;
780 if( count($this->types
) ) {
783 foreach( $wgFilterLogTypes as $type => $default ) {
784 // Avoid silly filtering
785 if( $type !== 'patrol' ||
$wgUser->useNPPatrol() ) {
786 $hide = $wgRequest->getInt( "hide_{$type}_log", $default );
787 $filters[$type] = $hide;
789 $this->mConds
[] = 'log_type != ' . $this->mDb
->addQuotes( $type );
796 * Set the log reader to return only entries of the given type.
797 * Type restrictions enforced here
798 * @param $types String or array: Log types ('upload', 'delete', etc);
799 * empty string means no restriction
801 private function limitType( $types ) {
802 global $wgLogRestrictions, $wgUser;
803 // If $types is not an array, make it an array
804 $types = ($types === '') ?
array() : (array)$types;
805 // Don't even show header for private logs; don't recognize it...
806 foreach ( $types as $type ) {
807 if( isset( $wgLogRestrictions[$type] )
808 && !$wgUser->isAllowed($wgLogRestrictions[$type])
810 $types = array_diff( $types, array( $type ) );
813 $this->types
= $types;
814 // Don't show private logs to unprivileged users.
815 // Also, only show them upon specific request to avoid suprises.
816 $audience = $types ?
'user' : 'public';
817 $hideLogs = LogEventsList
::getExcludeClause( $this->mDb
, $audience );
818 if( $hideLogs !== false ) {
819 $this->mConds
[] = $hideLogs;
821 if( count($types) ) {
822 $this->mConds
['log_type'] = $types;
823 // Set typeCGI; used in url param for paging
824 if( count($types) == 1 ) $this->typeCGI
= $types[0];
829 * Set the log reader to return only entries by the given user.
830 * @param $name String: (In)valid user name
832 private function limitUser( $name ) {
836 $usertitle = Title
::makeTitleSafe( NS_USER
, $name );
837 if( is_null($usertitle) ) {
840 /* Fetch userid at first, if known, provides awesome query plan afterwards */
841 $userid = User
::idFromName( $name );
843 /* It should be nicer to abort query at all,
844 but for now it won't pass anywhere behind the optimizer */
845 $this->mConds
[] = "NULL";
848 $this->mConds
['log_user'] = $userid;
849 // Paranoia: avoid brute force searches (bug 17342)
850 if( !$wgUser->isAllowed( 'deletedhistory' ) ) {
851 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::DELETED_USER
) . ' = 0';
852 } else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
853 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::SUPPRESSED_USER
) .
854 ' != ' . LogPage
::SUPPRESSED_USER
;
856 $this->user
= $usertitle->getText();
861 * Set the log reader to return only entries affecting the given page.
862 * (For the block and rights logs, this is a user page.)
863 * @param $page String: Title name as text
864 * @param $pattern String
866 private function limitTitle( $page, $pattern ) {
867 global $wgMiserMode, $wgUser;
869 $title = Title
::newFromText( $page );
870 if( strlen( $page ) == 0 ||
!$title instanceof Title
)
873 $this->title
= $title->getPrefixedText();
874 $ns = $title->getNamespace();
877 # Using the (log_namespace, log_title, log_timestamp) index with a
878 # range scan (LIKE) on the first two parts, instead of simple equality,
879 # makes it unusable for sorting. Sorted retrieval using another index
880 # would be possible, but then we might have to scan arbitrarily many
881 # nodes of that index. Therefore, we need to avoid this if $wgMiserMode
884 # This is not a problem with simple title matches, because then we can
885 # use the page_time index. That should have no more than a few hundred
886 # log entries for even the busiest pages, so it can be safely scanned
887 # in full to satisfy an impossible condition on user or similar.
888 if( $pattern && !$wgMiserMode ) {
889 $this->mConds
['log_namespace'] = $ns;
890 $this->mConds
[] = 'log_title ' . $db->buildLike( $title->getDBkey(), $db->anyString() );
891 $this->pattern
= $pattern;
893 $this->mConds
['log_namespace'] = $ns;
894 $this->mConds
['log_title'] = $title->getDBkey();
896 // Paranoia: avoid brute force searches (bug 17342)
897 if( !$wgUser->isAllowed( 'deletedhistory' ) ) {
898 $this->mConds
[] = $db->bitAnd('log_deleted', LogPage
::DELETED_ACTION
) . ' = 0';
899 } else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
900 $this->mConds
[] = $db->bitAnd('log_deleted', LogPage
::SUPPRESSED_ACTION
) .
901 ' != ' . LogPage
::SUPPRESSED_ACTION
;
905 public function getQueryInfo() {
907 $tables = array( 'logging', 'user' );
908 $this->mConds
[] = 'user_id = log_user';
911 # Add log_search table if there are conditions on it
912 if( array_key_exists('ls_field',$this->mConds
) ) {
913 $tables[] = 'log_search';
914 $index['log_search'] = 'ls_field_val';
915 $index['logging'] = 'PRIMARY';
916 $options[] = 'DISTINCT';
917 # Avoid usage of the wrong index by limiting
918 # the choices of available indexes. This mainly
919 # avoids site-breaking filesorts.
920 } else if( $this->title ||
$this->pattern ||
$this->user
) {
921 $index['logging'] = array( 'page_time', 'user_time' );
922 if( count($this->types
) == 1 ) {
923 $index['logging'][] = 'log_user_type_time';
925 } else if( count($this->types
) == 1 ) {
926 $index['logging'] = 'type_time';
928 $index['logging'] = 'times';
930 $options['USE INDEX'] = $index;
931 # Don't show duplicate rows when using log_search
934 'fields' => array( 'log_type', 'log_action', 'log_user', 'log_namespace',
935 'log_title', 'log_params', 'log_comment', 'log_id', 'log_deleted',
936 'log_timestamp', 'user_name', 'user_editcount' ),
937 'conds' => $this->mConds
,
938 'options' => $options,
939 'join_conds' => array(
940 'user' => array( 'INNER JOIN', 'user_id=log_user' ),
941 'log_search' => array( 'INNER JOIN', 'ls_log_id=log_id' )
944 # Add ChangeTags filter query
945 ChangeTags
::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'],
946 $info['join_conds'], $info['options'], $this->mTagFilter
);
950 function getIndexField() {
951 return 'log_timestamp';
954 public function getStartBody() {
955 wfProfileIn( __METHOD__
);
956 # Do a link batch query
957 if( $this->getNumRows() > 0 ) {
959 while( $row = $this->mResult
->fetchObject() ) {
960 $lb->add( $row->log_namespace
, $row->log_title
);
961 $lb->addObj( Title
::makeTitleSafe( NS_USER
, $row->user_name
) );
962 $lb->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->user_name
) );
965 $this->mResult
->seek( 0 );
967 wfProfileOut( __METHOD__
);
971 public function formatRow( $row ) {
972 return $this->mLogEventsList
->logLine( $row );
975 public function getType() {
979 public function getUser() {
983 public function getPage() {
987 public function getPattern() {
988 return $this->pattern
;
991 public function getYear() {
995 public function getMonth() {
996 return $this->mMonth
;
999 public function getTagFilter() {
1000 return $this->mTagFilter
;
1003 public function doQuery() {
1004 // Workaround MySQL optimizer bug
1005 $this->mDb
->setBigSelects();
1007 $this->mDb
->setBigSelects( 'default' );
1013 * @ingroup SpecialPage
1018 * @param $request WebRequest: for internal use use a FauxRequest object to pass arbitrary parameters.
1020 function __construct( $request ) {
1021 global $wgUser, $wgOut;
1022 wfDeprecated(__METHOD__
);
1024 $type = $request->getVal( 'type' );
1025 $user = $request->getText( 'user' );
1026 $title = $request->getText( 'page' );
1027 $pattern = $request->getBool( 'pattern' );
1028 $year = $request->getIntOrNull( 'year' );
1029 $month = $request->getIntOrNull( 'month' );
1030 $tagFilter = $request->getVal( 'tagfilter' );
1031 # Don't let the user get stuck with a certain date
1032 $skip = $request->getText( 'offset' ) ||
$request->getText( 'dir' ) == 'prev';
1037 # Use new list class to output results
1038 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
1039 $this->pager
= new LogPager( $loglist, $type, $user, $title, $pattern, $year, $month, $tagFilter );
1043 * Is there at least one row?
1046 public function hasRows() {
1047 return isset($this->pager
) ?
($this->pager
->getNumRows() > 0) : false;
1053 * @ingroup SpecialPage
1056 const NO_ACTION_LINK
= 1;
1064 * @param &$reader LogReader: where to get our data from
1065 * @param $flags Integer: Bitwise combination of flags:
1066 * LogEventsList::NO_ACTION_LINK Don't show restore/unblock/block links
1068 function __construct( &$reader, $flags = 0 ) {
1069 wfDeprecated(__METHOD__
);
1070 $this->reader
=& $reader;
1071 $this->reader
->pager
->mLogEventsList
->flags
= $flags;
1072 # Aliases for shorter code...
1073 $this->pager
=& $this->reader
->pager
;
1074 $this->list =& $this->reader
->pager
->mLogEventsList
;
1078 * Take over the whole output page in $wgOut with the log display.
1080 public function show() {
1081 # Set title and add header
1082 $this->list->showHeader( $pager->getType() );
1084 $this->list->showOptions( $this->pager
->getType(), $this->pager
->getUser(), $this->pager
->getPage(),
1085 $this->pager
->getPattern(), $this->pager
->getYear(), $this->pager
->getMonth() );
1087 $logBody = $this->pager
->getBody();
1090 $this->pager
->getNavigationBar() .
1091 $this->list->beginLogEventsList() .
1093 $this->list->endLogEventsList() .
1094 $this->pager
->getNavigationBar()
1097 $wgOut->addWikiMsg( 'logempty' );
1102 * Output just the list of entries given by the linked LogReader,
1103 * with extraneous UI elements. Use for displaying log fragments in
1104 * another page (eg at Special:Undelete)
1105 * @param $out OutputPage: where to send output
1107 public function showList( &$out ) {
1108 $logBody = $this->pager
->getBody();
1111 $this->list->beginLogEventsList() .
1113 $this->list->endLogEventsList()
1116 $out->addWikiMsg( 'logempty' );