2 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>, 2008 Aaron Schulz
3 # http://www.mediawiki.org/
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # http://www.gnu.org/copyleft/gpl.html
21 const NO_ACTION_LINK
= 1;
27 public function __construct( $skin, $out, $flags = 0 ) {
30 $this->flags
= $flags;
31 $this->preCacheMessages();
35 * As we use the same small set of messages in various methods and that
36 * they are called often, we call them once and save them in $this->message
38 private function preCacheMessages() {
39 // Precache various messages
40 if( !isset( $this->message
) ) {
41 $messages = array( 'revertmerge', 'protect_change', 'unblocklink', 'change-blocklink',
42 'revertmove', 'undeletelink', 'undeleteviewlink', 'revdel-restore', 'rev-delundel', 'hist', 'diff',
44 foreach( $messages as $msg ) {
45 $this->message
[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
51 * Set page title and show header for this log type
54 public function showHeader( $type ) {
55 // If only one log type is used, then show a special message...
56 $headerType = (count($type) == 1) ?
$type[0] : '';
57 if( LogPage
::isLogType( $headerType ) ) {
58 $this->out
->setPageTitle( LogPage
::logName( $headerType ) );
59 $this->out
->addHTML( LogPage
::logHeader( $headerType ) );
61 $this->out
->addHTML( wfMsgExt('alllogstext',array('parseinline')) );
66 * Show options for the log list
67 * @param $types string or Array
70 * @param $pattern String
71 * @param $year Integer: year
72 * @param $month Integer: month
73 * @param $filter: array
74 * @param $tagFilter: array?
76 public function showOptions( $types=array(), $user='', $page='', $pattern='', $year='',
77 $month = '', $filter = null, $tagFilter='' )
79 global $wgScript, $wgMiserMode;
82 $title = SpecialPage
::getTitleFor( 'Log' );
83 $special = $title->getPrefixedDBkey();
85 // For B/C, we take strings, but make sure they are converted...
86 $types = ($types === '') ?
array() : (array)$types;
88 $tagSelector = ChangeTags
::buildTagFilterSelector( $tagFilter );
91 $html .= Xml
::hidden( 'title', $special );
94 $html .= $this->getTypeMenu( $types ) . "\n";
95 $html .= $this->getUserInput( $user ) . "\n";
96 $html .= $this->getTitleInput( $page ) . "\n";
97 $html .= $this->getExtraInputs( $types ) . "\n";
99 // Title pattern, if allowed
101 $html .= $this->getTitlePattern( $pattern ) . "\n";
105 $html .= Xml
::tags( 'p', null, Xml
::dateMenu( $year, $month ) );
109 $html .= Xml
::tags( 'p', null, implode( ' ', $tagSelector ) );
114 $html .= Xml
::tags( 'p', null, $this->getFilterLinks( $filter ) );
118 $html .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) );
121 $html = Xml
::fieldset( wfMsg( 'log' ), $html );
124 $html = Xml
::tags( 'form', array( 'action' => $action, 'method' => 'get' ), $html );
126 $this->out
->addHTML( $html );
130 * @param $filter Array
131 * @return String: Formatted HTML
133 private function getFilterLinks( $filter ) {
134 global $wgTitle, $wgLang;
136 $messages = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
137 // Option value -> message mapping
139 $hiddens = ''; // keep track for "go" button
140 foreach( $filter as $type => $val ) {
141 // Should the below assignment be outside the foreach?
142 // Then it would have to be copied. Not certain what is more expensive.
143 $query = $this->getDefaultQuery();
144 $queryKey = "hide_{$type}_log";
146 $hideVal = 1 - intval($val);
147 $query[$queryKey] = $hideVal;
149 $link = $this->skin
->link(
154 array( 'known', 'noclasses' )
157 $links[$type] = wfMsgHtml( "log-show-hide-{$type}", $link );
158 $hiddens .= Xml
::hidden( "hide_{$type}_log", $val ) . "\n";
161 return '<small>'.$wgLang->pipeList( $links ) . '</small>' . $hiddens;
164 private function getDefaultQuery() {
165 if ( !isset( $this->mDefaultQuery
) ) {
166 $this->mDefaultQuery
= $_GET;
167 unset( $this->mDefaultQuery
['title'] );
168 unset( $this->mDefaultQuery
['dir'] );
169 unset( $this->mDefaultQuery
['offset'] );
170 unset( $this->mDefaultQuery
['limit'] );
171 unset( $this->mDefaultQuery
['order'] );
172 unset( $this->mDefaultQuery
['month'] );
173 unset( $this->mDefaultQuery
['year'] );
175 return $this->mDefaultQuery
;
179 * @param $queryTypes Array
180 * @return String: Formatted HTML
182 private function getTypeMenu( $queryTypes ) {
183 global $wgLogRestrictions, $wgUser;
185 $html = "<select name='type'>\n";
187 $validTypes = LogPage
::validTypes();
188 $typesByName = array(); // Temporary array
190 // First pass to load the log names
191 foreach( $validTypes as $type ) {
192 $text = LogPage
::logName( $type );
193 $typesByName[$text] = $type;
196 // Second pass to sort by name
199 // Note the query type
200 $queryType = count($queryTypes) == 1 ?
$queryTypes[0] : '';
201 // Third pass generates sorted XHTML content
202 foreach( $typesByName as $text => $type ) {
203 $selected = ($type == $queryType);
205 if ( isset($wgLogRestrictions[$type]) ) {
206 if ( $wgUser->isAllowed( $wgLogRestrictions[$type] ) ) {
207 $html .= Xml
::option( $text, $type, $selected ) . "\n";
210 $html .= Xml
::option( $text, $type, $selected ) . "\n";
214 $html .= '</select>';
219 * @param $user String
220 * @return String: Formatted HTML
222 private function getUserInput( $user ) {
223 return Xml
::inputLabel( wfMsg( 'specialloguserlabel' ), 'user', 'mw-log-user', 15, $user );
227 * @param $title String
228 * @return String: Formatted HTML
230 private function getTitleInput( $title ) {
231 return Xml
::inputLabel( wfMsg( 'speciallogtitlelabel' ), 'page', 'mw-log-page', 20, $title );
235 * @return boolean Checkbox
237 private function getTitlePattern( $pattern ) {
238 return '<span style="white-space: nowrap">' .
239 Xml
::checkLabel( wfMsg( 'log-title-wildcard' ), 'pattern', 'pattern', $pattern ) .
243 private function getExtraInputs( $types ) {
245 if( count($types) == 1 && $types[0] == 'suppress' ) {
246 return Xml
::inputLabel( wfMsg('revdelete-offender'), 'offender',
247 'mw-log-offender', 20, $wgRequest->getVal('offender') );
252 public function beginLogEventsList() {
256 public function endLogEventsList() {
261 * @param $row Row: a single row from the result set
262 * @return String: Formatted HTML list item
264 public function logLine( $row ) {
265 global $wgLang, $wgUser, $wgContLang;
267 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
268 $classes = array( "mw-logline-{$row->log_type}" );
269 $time = $wgLang->timeanddate( wfTimestamp(TS_MW
, $row->log_timestamp
), true );
271 if( self
::isDeleted($row,LogPage
::DELETED_USER
) ) {
272 $userLink = '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
274 $userLink = $this->skin
->userLink( $row->log_user
, $row->user_name
) .
275 $this->skin
->userToolLinks( $row->log_user
, $row->user_name
, true, 0, $row->user_editcount
);
278 if( self
::isDeleted($row,LogPage
::DELETED_COMMENT
) ) {
279 $comment = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
281 $comment = $wgContLang->getDirMark() . $this->skin
->commentBlock( $row->log_comment
);
283 // Extract extra parameters
284 $paramArray = LogPage
::extractParams( $row->log_params
);
286 // Some user can hide log items and have review links
287 if( !($this->flags
& self
::NO_ACTION_LINK
) && $wgUser->isAllowed( 'deletedrevision' ) ) {
288 // Don't show useless link to people who cannot hide revisions
289 if( $row->log_deleted ||
$wgUser->isAllowed( 'deleterevision' ) ) {
290 $del = $this->getShowHideLinks( $row ) . ' ';
293 // Add review links and such...
294 if( ($this->flags
& self
::NO_ACTION_LINK
) ||
($row->log_deleted
& LogPage
::DELETED_ACTION
) ) {
295 // Action text is suppressed...
296 } else if( self
::typeAction($row,'move','move','move') && !empty($paramArray[0]) ) {
297 $destTitle = Title
::newFromText( $paramArray[0] );
299 $revert = '(' . $this->skin
->link(
300 SpecialPage
::getTitleFor( 'Movepage' ),
301 $this->message
['revertmove'],
304 'wpOldTitle' => $destTitle->getPrefixedDBkey(),
305 'wpNewTitle' => $title->getPrefixedDBkey(),
306 'wpReason' => wfMsgForContent( 'revertmove' ),
309 array( 'known', 'noclasses' )
312 // Show undelete link
313 } else if( self
::typeAction($row,array('delete','suppress'),'delete','deletedhistory') ) {
314 if( !$wgUser->isAllowed( 'undelete' ) ) {
315 $viewdeleted = $this->message
['undeleteviewlink'];
317 $viewdeleted = $this->message
['undeletelink'];
320 $revert = '(' . $this->skin
->link(
321 SpecialPage
::getTitleFor( 'Undelete' ),
324 array( 'target' => $title->getPrefixedDBkey() ),
325 array( 'known', 'noclasses' )
327 // Show unblock/change block link
328 } else if( self
::typeAction($row,array('block','suppress'),array('block','reblock'),'block') ) {
331 SpecialPage
::getTitleFor( 'Ipblocklist' ),
332 $this->message
['unblocklink'],
335 'action' => 'unblock',
336 'ip' => $row->log_title
340 $this->message
['pipe-separator'] .
342 SpecialPage
::getTitleFor( 'Blockip', $row->log_title
),
343 $this->message
['change-blocklink'],
349 // Show change protection link
350 } else if( self
::typeAction( $row, 'protect', array( 'modify', 'protect', 'unprotect' ) ) ) {
352 $this->skin
->link( $title,
353 $this->message
['hist'],
356 'action' => 'history',
357 'offset' => $row->log_timestamp
360 if( $wgUser->isAllowed( 'protect' ) ) {
361 $revert .= $this->message
['pipe-separator'] .
362 $this->skin
->link( $title,
363 $this->message
['protect_change'],
365 array( 'action' => 'protect' ),
370 } else if( self
::typeAction($row,'merge','merge','mergehistory') ) {
371 $merge = SpecialPage
::getTitleFor( 'Mergehistory' );
372 $revert = '(' . $this->skin
->link(
374 $this->message
['revertmerge'],
377 'target' => $paramArray[0],
378 'dest' => $title->getPrefixedDBkey(),
379 'mergepoint' => $paramArray[1]
381 array( 'known', 'noclasses' )
383 // If an edit was hidden from a page give a review link to the history
384 } else if( self
::typeAction($row,array('delete','suppress'),'revision','deletedrevision') ) {
385 if( count($paramArray) >= 2 ) {
386 // Different revision types use different URL params...
387 $key = $paramArray[0];
388 // $paramArray[1] is a CSV of the IDs
389 $Ids = explode( ',', $paramArray[1] );
390 $query = $paramArray[1];
392 // Diff link for single rev deletions
393 if( count($Ids) == 1 ) {
394 // Live revision diffs...
395 if( in_array($key, array('oldid','revision')) ) {
396 $revert[] = $this->skin
->link(
398 $this->message
['diff'],
401 'diff' => intval( $Ids[0] ),
404 array( 'known', 'noclasses' )
406 // Deleted revision diffs...
407 } else if( in_array($key, array('artimestamp','archive')) ) {
408 $revert[] = $this->skin
->link(
409 SpecialPage
::getTitleFor( 'Undelete' ),
410 $this->message
['diff'],
413 'target' => $title->getPrefixedDBKey(),
415 'timestamp' => $Ids[0]
417 array( 'known', 'noclasses' )
421 // View/modify link...
422 $revert[] = $this->skin
->link(
423 SpecialPage
::getTitleFor( 'Revisiondelete' ),
424 $this->message
['revdel-restore'],
427 'target' => $title->getPrefixedText(),
431 array( 'known', 'noclasses' )
434 $revert = wfMsg( 'parentheses', $wgLang->pipeList( $revert ) );
436 // Hidden log items, give review link
437 } else if( self
::typeAction($row,array('delete','suppress'),'event','deletedrevision') ) {
438 if( count($paramArray) >= 1 ) {
439 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
440 // $paramArray[1] is a CSV of the IDs
441 $Ids = explode( ',', $paramArray[0] );
442 $query = $paramArray[0];
443 // Link to each hidden object ID, $paramArray[1] is the url param
444 $revert = '(' . $this->skin
->link(
446 $this->message
['revdel-restore'],
449 'target' => $title->getPrefixedText(),
453 array( 'known', 'noclasses' )
456 // Self-created users
457 } else if( self
::typeAction($row,'newusers','create2') ) {
458 if( isset( $paramArray[0] ) ) {
459 $revert = $this->skin
->userToolLinks( $paramArray[0], $title->getDBkey(), true );
461 # Fall back to a blue contributions link
462 $revert = $this->skin
->userToolLinks( 1, $title->getDBkey() );
464 if( $time < '20080129000000' ) {
465 # Suppress $comment from old entries (before 2008-01-29),
466 # not needed and can contain incorrect links
469 // Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
471 wfRunHooks( 'LogLine', array( $row->log_type
, $row->log_action
, $title, $paramArray,
472 &$comment, &$revert, $row->log_timestamp
) );
475 if( self
::isDeleted($row,LogPage
::DELETED_ACTION
) ) {
476 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
478 $action = LogPage
::actionText( $row->log_type
, $row->log_action
, $title,
479 $this->skin
, $paramArray, true );
483 list($tagDisplay, $newClasses) = ChangeTags
::formatSummaryRow( $row->ts_tags
, 'logevent' );
484 $classes = array_merge( $classes, $newClasses );
486 if( $revert != '' ) {
487 $revert = '<span class="mw-logevent-actionlink">' . $revert . '</span>';
490 $time = htmlspecialchars( $time );
492 return Xml
::tags( 'li', array( "class" => implode( ' ', $classes ) ),
493 $del . $time . ' ' . $userLink . ' ' . $action . ' ' . $comment . ' ' . $revert . " $tagDisplay" ) . "\n";
500 private function getShowHideLinks( $row ) {
501 // If event was hidden from sysops
502 if( !self
::userCan( $row, LogPage
::DELETED_RESTRICTED
) ) {
503 $del = Xml
::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
504 '('.$this->message
['rev-delundel'].')' );
505 } else if( $row->log_type
== 'suppress' ) {
506 $del = ''; // No one should be hiding from the oversight log
508 $target = SpecialPage
::getTitleFor( 'Log', $row->log_type
);
509 $page = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
511 'target' => $target->getPrefixedDBkey(),
513 'ids' => $row->log_id
,
515 $del = $this->skin
->revDeleteLink( $query,
516 self
::isDeleted( $row, LogPage
::DELETED_RESTRICTED
) );
523 * @param $type Mixed: string/array
524 * @param $action Mixed: string/array
525 * @param $right string
528 public static function typeAction( $row, $type, $action, $right='' ) {
529 $match = is_array($type) ?
530 in_array($row->log_type
,$type) : $row->log_type
== $type;
532 $match = is_array($action) ?
533 in_array($row->log_action
,$action) : $row->log_action
== $action;
534 if( $match && $right ) {
536 $match = $wgUser->isAllowed( $right );
543 * Determine if the current user is allowed to view a particular
544 * field of this log row, if it's marked as deleted.
546 * @param $field Integer
549 public static function userCan( $row, $field ) {
550 if( ( $row->log_deleted
& $field ) == $field ) {
552 $permission = ( $row->log_deleted
& LogPage
::DELETED_RESTRICTED
) == LogPage
::DELETED_RESTRICTED
555 wfDebug( "Checking for $permission due to $field match on $row->log_deleted\n" );
556 return $wgUser->isAllowed( $permission );
564 * @param $field Integer: one of DELETED_* bitfield constants
567 public static function isDeleted( $row, $field ) {
568 return ($row->log_deleted
& $field) == $field;
572 * Show log extract. Either with text and a box (set $msgKey) or without (don't set $msgKey)
573 * @param $out OutputPage or String-by-reference
574 * @param $types String or Array
575 * @param $page String The page title to show log entries for
576 * @param $user String The user who made the log entries
577 * @param $param Associative Array with the following additional options:
578 * lim Integer Limit of items to show, default is 50
579 * conds Array Extra conditions for the query (e.g. "log_action != 'revision'")
580 * showIfEmpty boolean Set to false if you don't want any output in case the loglist is empty
581 * if set to true (default), "No matching items in log" is displayed if loglist is empty
582 * msgKey Array If you want a nice box with a message, set this
583 * to the key of the message. First element is the message
584 * key, additional optional elements are parameters for the
585 * key that are processed with wgMsgExt and option 'parse'
586 * offset Set to overwrite offset parameter in $wgRequest
587 * set to '' to unset offset
588 * @return Integer Number of total log items (not limited by $lim)
590 public static function showLogExtract( &$out, $types=array(), $page='', $user='',
593 $defaultParameters = array(
596 'showIfEmpty' => true,
597 'msgKey' => array('')
600 # The + operator appends elements of remaining keys from the right
601 # handed array to the left handed, whereas duplicated keys are NOT overwritten.
602 $param +
= $defaultParameters;
604 global $wgUser, $wgOut;
605 # Convert $param array to individual variables
606 $lim = $param['lim'];
607 $conds = $param['conds'];
608 $showIfEmpty = $param['showIfEmpty'];
609 $msgKey = $param['msgKey'];
610 if ( !is_array($msgKey) )
611 $msgKey = array( $msgKey );
612 # Insert list of top 50 (or top $lim) items
613 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
614 $pager = new LogPager( $loglist, $types, $user, $page, '', $conds );
615 if ( isset( $param['offset'] ) ) # Tell pager to ignore $wgRequest offset
616 $pager->setOffset( $param['offset'] );
617 if( $lim > 0 ) $pager->mLimit
= $lim;
618 $logBody = $pager->getBody();
622 $s = '<div class="mw-warning-with-logexcerpt">';
624 if ( count( $msgKey ) == 1 ) {
625 $s .= wfMsgExt( $msgKey[0], array('parse') );
626 } else { // Process additional arguments
628 array_shift( $args );
629 $s .= wfMsgExt( $msgKey[0], array('parse'), $args );
632 $s .= $loglist->beginLogEventsList() .
634 $loglist->endLogEventsList();
637 $s = wfMsgExt( 'logempty', array('parse') );
639 if( $pager->getNumRows() > $pager->mLimit
) { # Show "Full log" link
642 $urlParam['page'] = $page;
644 $urlParam['user'] = $user;
645 if ( !is_array( $types ) ) # Make it an array, if it isn't
646 $types = array( $types );
647 # If there is exactly one log type, we can link to Special:Log?type=foo
648 if ( count( $types ) == 1 )
649 $urlParam['type'] = $types[0];
650 $s .= $wgUser->getSkin()->link(
651 SpecialPage
::getTitleFor( 'Log' ),
652 wfMsgHtml( 'log-fulllog' ),
658 if ( $logBody && $msgKey[0] )
661 if( $out instanceof OutputPage
){
666 return $pager->getNumRows();
670 * SQL clause to skip forbidden log types for this user
671 * @param $db Database
672 * @param $audience string, public/user
673 * @return mixed (string or false)
675 public static function getExcludeClause( $db, $audience = 'public' ) {
676 global $wgLogRestrictions, $wgUser;
677 // Reset the array, clears extra "where" clauses when $par is used
678 $hiddenLogs = array();
679 // Don't show private logs to unprivileged users
680 foreach( $wgLogRestrictions as $logType => $right ) {
681 if( $audience == 'public' ||
!$wgUser->isAllowed($right) ) {
682 $safeType = $db->strencode( $logType );
683 $hiddenLogs[] = $safeType;
686 if( count($hiddenLogs) == 1 ) {
687 return 'log_type != ' . $db->addQuotes( $hiddenLogs[0] );
688 } elseif( $hiddenLogs ) {
689 return 'log_type NOT IN (' . $db->makeList($hiddenLogs) . ')';
698 class LogPager
extends ReverseChronologicalPager
{
699 private $types = array(), $user = '', $title = '', $pattern = '';
700 private $typeCGI = '';
701 public $mLogEventsList;
705 * @param $list LogEventsList
706 * @param $types String or Array log types to show
707 * @param $user String The user who made the log entries
708 * @param $title String The page title the log entries are for
709 * @param $pattern String Do a prefix search rather than an exact title match
710 * @param $conds Array Extra conditions for the query
711 * @param $year Integer The year to start from
712 * @param $month Integer The month to start from
714 public function __construct( $list, $types = array(), $user = '', $title = '', $pattern = '',
715 $conds = array(), $year = false, $month = false, $tagFilter = '' )
717 parent
::__construct();
718 $this->mConds
= $conds;
720 $this->mLogEventsList
= $list;
722 $this->limitType( $types ); // also excludes hidden types
723 $this->limitUser( $user );
724 $this->limitTitle( $title, $pattern );
725 $this->getDateCond( $year, $month );
726 $this->mTagFilter
= $tagFilter;
729 public function getDefaultQuery() {
730 $query = parent
::getDefaultQuery();
731 $query['type'] = $this->typeCGI
; // arrays won't work here
732 $query['user'] = $this->user
;
733 $query['month'] = $this->mMonth
;
734 $query['year'] = $this->mYear
;
738 // Call ONLY after calling $this->limitType() already!
739 public function getFilterParams() {
740 global $wgFilterLogTypes, $wgUser, $wgRequest;
742 if( count($this->types
) ) {
745 foreach( $wgFilterLogTypes as $type => $default ) {
746 // Avoid silly filtering
747 if( $type !== 'patrol' ||
$wgUser->useNPPatrol() ) {
748 $hide = $wgRequest->getInt( "hide_{$type}_log", $default );
749 $filters[$type] = $hide;
751 $this->mConds
[] = 'log_type != ' . $this->mDb
->addQuotes( $type );
758 * Set the log reader to return only entries of the given type.
759 * Type restrictions enforced here
760 * @param $types String or array: Log types ('upload', 'delete', etc);
761 * empty string means no restriction
763 private function limitType( $types ) {
764 global $wgLogRestrictions, $wgUser;
765 // If $types is not an array, make it an array
766 $types = ($types === '') ?
array() : (array)$types;
767 // Don't even show header for private logs; don't recognize it...
768 foreach ( $types as $type ) {
769 if( isset( $wgLogRestrictions[$type] ) && !$wgUser->isAllowed($wgLogRestrictions[$type]) ) {
770 $types = array_diff( $types, array( $type ) );
773 // Don't show private logs to unprivileged users.
774 // Also, only show them upon specific request to avoid suprises.
775 $audience = $types ?
'user' : 'public';
776 $hideLogs = LogEventsList
::getExcludeClause( $this->mDb
, $audience );
777 if( $hideLogs !== false ) {
778 $this->mConds
[] = $hideLogs;
780 if( count($types) ) {
781 $this->types
= $types;
782 $this->mConds
['log_type'] = $types;
783 // Set typeCGI; used in url param for paging
784 if( count($types) == 1 ) $this->typeCGI
= $types[0];
789 * Set the log reader to return only entries by the given user.
790 * @param $name String: (In)valid user name
792 private function limitUser( $name ) {
796 $usertitle = Title
::makeTitleSafe( NS_USER
, $name );
797 if( is_null($usertitle) ) {
800 /* Fetch userid at first, if known, provides awesome query plan afterwards */
801 $userid = User
::idFromName( $name );
803 /* It should be nicer to abort query at all,
804 but for now it won't pass anywhere behind the optimizer */
805 $this->mConds
[] = "NULL";
808 $this->mConds
['log_user'] = $userid;
809 // Paranoia: avoid brute force searches (bug 17342)
810 if( !$wgUser->isAllowed( 'deletedrevision' ) ) {
811 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::DELETED_USER
) . ' = 0';
812 } else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
813 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::SUPPRESSED_USER
) .
814 ' != ' . LogPage
::SUPPRESSED_USER
;
816 $this->user
= $usertitle->getText();
821 * Set the log reader to return only entries affecting the given page.
822 * (For the block and rights logs, this is a user page.)
823 * @param $page String: Title name as text
824 * @param $pattern String
826 private function limitTitle( $page, $pattern ) {
827 global $wgMiserMode, $wgUser;
829 $title = Title
::newFromText( $page );
830 if( strlen($page) == 0 ||
!$title instanceof Title
)
833 $this->title
= $title->getPrefixedText();
834 $ns = $title->getNamespace();
835 # Using the (log_namespace, log_title, log_timestamp) index with a
836 # range scan (LIKE) on the first two parts, instead of simple equality,
837 # makes it unusable for sorting. Sorted retrieval using another index
838 # would be possible, but then we might have to scan arbitrarily many
839 # nodes of that index. Therefore, we need to avoid this if $wgMiserMode
842 # This is not a problem with simple title matches, because then we can
843 # use the page_time index. That should have no more than a few hundred
844 # log entries for even the busiest pages, so it can be safely scanned
845 # in full to satisfy an impossible condition on user or similar.
846 if( $pattern && !$wgMiserMode ) {
847 # use escapeLike to avoid expensive search patterns like 't%st%'
848 $safetitle = $this->mDb
->escapeLike( $title->getDBkey() );
849 $this->mConds
['log_namespace'] = $ns;
850 $this->mConds
[] = "log_title LIKE '$safetitle%'";
851 $this->pattern
= $pattern;
853 $this->mConds
['log_namespace'] = $ns;
854 $this->mConds
['log_title'] = $title->getDBkey();
856 // Paranoia: avoid brute force searches (bug 17342)
857 if( !$wgUser->isAllowed( 'deletedrevision' ) ) {
858 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::DELETED_ACTION
) . ' = 0';
859 } else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
860 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::SUPPRESSED_ACTION
) .
861 ' != ' . LogPage
::SUPPRESSED_ACTION
;
865 public function getQueryInfo() {
866 $tables = array( 'logging', 'user' );
867 $this->mConds
[] = 'user_id = log_user';
869 # Add log_search table if there are conditions on it
870 if( array_key_exists('ls_field',$this->mConds
) ) {
871 $tables[] = 'log_search';
872 $index = array( 'log_search' => 'ls_field_val', 'logging' => 'PRIMARY' );
873 $groupBy = 'ls_log_id';
874 # Don't use the wrong logging index
875 } else if( $this->title ||
$this->pattern ||
$this->user
) {
876 $index = array( 'logging' => array('page_time','user_time') );
877 } else if( $this->types
) {
878 $index = array( 'logging' => 'type_time' );
880 $index = array( 'logging' => 'times' );
882 $options = array( 'USE INDEX' => $index );
883 # Don't show duplicate rows when using log_search
884 if( $groupBy ) $options['GROUP BY'] = $groupBy;
887 'fields' => array( 'log_type', 'log_action', 'log_user', 'log_namespace',
888 'log_title', 'log_params', 'log_comment', 'log_id', 'log_deleted',
889 'log_timestamp', 'user_name', 'user_editcount' ),
890 'conds' => $this->mConds
,
891 'options' => $options,
892 'join_conds' => array(
893 'user' => array( 'INNER JOIN', 'user_id=log_user' ),
894 'log_search' => array( 'INNER JOIN', 'ls_log_id=log_id' )
897 # Add ChangeTags filter query
898 ChangeTags
::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'],
899 $info['join_conds'], $info['options'], $this->mTagFilter
);
904 function getIndexField() {
905 return 'log_timestamp';
908 public function getStartBody() {
909 wfProfileIn( __METHOD__
);
910 # Do a link batch query
911 if( $this->getNumRows() > 0 ) {
913 while( $row = $this->mResult
->fetchObject() ) {
914 $lb->add( $row->log_namespace
, $row->log_title
);
915 $lb->addObj( Title
::makeTitleSafe( NS_USER
, $row->user_name
) );
916 $lb->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->user_name
) );
919 $this->mResult
->seek( 0 );
921 wfProfileOut( __METHOD__
);
925 public function formatRow( $row ) {
926 return $this->mLogEventsList
->logLine( $row );
929 public function getType() {
933 public function getUser() {
937 public function getPage() {
941 public function getPattern() {
942 return $this->pattern
;
945 public function getYear() {
949 public function getMonth() {
950 return $this->mMonth
;
953 public function getTagFilter() {
954 return $this->mTagFilter
;
957 public function doQuery() {
958 // Workaround MySQL optimizer bug
959 $this->mDb
->setBigSelects();
961 $this->mDb
->setBigSelects( 'default' );
967 * @ingroup SpecialPage
972 * @param $request WebRequest: for internal use use a FauxRequest object to pass arbitrary parameters.
974 function __construct( $request ) {
975 global $wgUser, $wgOut;
976 wfDeprecated(__METHOD__
);
978 $type = $request->getVal( 'type' );
979 $user = $request->getText( 'user' );
980 $title = $request->getText( 'page' );
981 $pattern = $request->getBool( 'pattern' );
982 $year = $request->getIntOrNull( 'year' );
983 $month = $request->getIntOrNull( 'month' );
984 $tagFilter = $request->getVal( 'tagfilter' );
985 # Don't let the user get stuck with a certain date
986 $skip = $request->getText( 'offset' ) ||
$request->getText( 'dir' ) == 'prev';
991 # Use new list class to output results
992 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
993 $this->pager
= new LogPager( $loglist, $type, $user, $title, $pattern, $year, $month, $tagFilter );
997 * Is there at least one row?
1000 public function hasRows() {
1001 return isset($this->pager
) ?
($this->pager
->getNumRows() > 0) : false;
1007 * @ingroup SpecialPage
1010 const NO_ACTION_LINK
= 1;
1018 * @param &$reader LogReader: where to get our data from
1019 * @param $flags Integer: Bitwise combination of flags:
1020 * LogEventsList::NO_ACTION_LINK Don't show restore/unblock/block links
1022 function __construct( &$reader, $flags = 0 ) {
1023 wfDeprecated(__METHOD__
);
1024 $this->reader
=& $reader;
1025 $this->reader
->pager
->mLogEventsList
->flags
= $flags;
1026 # Aliases for shorter code...
1027 $this->pager
=& $this->reader
->pager
;
1028 $this->list =& $this->reader
->pager
->mLogEventsList
;
1032 * Take over the whole output page in $wgOut with the log display.
1034 public function show() {
1035 # Set title and add header
1036 $this->list->showHeader( $pager->getType() );
1038 $this->list->showOptions( $this->pager
->getType(), $this->pager
->getUser(), $this->pager
->getPage(),
1039 $this->pager
->getPattern(), $this->pager
->getYear(), $this->pager
->getMonth() );
1041 $logBody = $this->pager
->getBody();
1044 $this->pager
->getNavigationBar() .
1045 $this->list->beginLogEventsList() .
1047 $this->list->endLogEventsList() .
1048 $this->pager
->getNavigationBar()
1051 $wgOut->addWikiMsg( 'logempty' );
1056 * Output just the list of entries given by the linked LogReader,
1057 * with extraneous UI elements. Use for displaying log fragments in
1058 * another page (eg at Special:Undelete)
1059 * @param $out OutputPage: where to send output
1061 public function showList( &$out ) {
1062 $logBody = $this->pager
->getBody();
1065 $this->list->beginLogEventsList() .
1067 $this->list->endLogEventsList()
1070 $out->addWikiMsg( 'logempty' );