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( 'deleterevision' ) ) {
288 $del = $this->getShowHideLinks( $row ) . ' ';
290 // Add review links and such...
291 if( ($this->flags
& self
::NO_ACTION_LINK
) ||
($row->log_deleted
& LogPage
::DELETED_ACTION
) ) {
292 // Action text is suppressed...
293 } else if( self
::typeAction($row,'move','move','move') && !empty($paramArray[0]) ) {
294 $destTitle = Title
::newFromText( $paramArray[0] );
296 $revert = '(' . $this->skin
->link(
297 SpecialPage
::getTitleFor( 'Movepage' ),
298 $this->message
['revertmove'],
301 'wpOldTitle' => $destTitle->getPrefixedDBkey(),
302 'wpNewTitle' => $title->getPrefixedDBkey(),
303 'wpReason' => wfMsgForContent( 'revertmove' ),
306 array( 'known', 'noclasses' )
309 // Show undelete link
310 } else if( self
::typeAction($row,array('delete','suppress'),'delete','deletedhistory') ) {
311 if( !$wgUser->isAllowed( 'undelete' ) ) {
312 $viewdeleted = $this->message
['undeleteviewlink'];
314 $viewdeleted = $this->message
['undeletelink'];
317 $revert = '(' . $this->skin
->link(
318 SpecialPage
::getTitleFor( 'Undelete' ),
321 array( 'target' => $title->getPrefixedDBkey() ),
322 array( 'known', 'noclasses' )
324 // Show unblock/change block link
325 } else if( self
::typeAction($row,array('block','suppress'),array('block','reblock'),'block') ) {
328 SpecialPage
::getTitleFor( 'Ipblocklist' ),
329 $this->message
['unblocklink'],
332 'action' => 'unblock',
333 'ip' => $row->log_title
337 $this->message
['pipe-separator'] .
339 SpecialPage
::getTitleFor( 'Blockip', $row->log_title
),
340 $this->message
['change-blocklink'],
346 // Show change protection link
347 } else if( self
::typeAction( $row, 'protect', array( 'modify', 'protect', 'unprotect' ) ) ) {
349 $this->skin
->link( $title,
350 $this->message
['hist'],
353 'action' => 'history',
354 'offset' => $row->log_timestamp
357 if( $wgUser->isAllowed( 'protect' ) ) {
358 $revert .= $this->message
['pipe-separator'] .
359 $this->skin
->link( $title,
360 $this->message
['protect_change'],
362 array( 'action' => 'protect' ),
367 } else if( self
::typeAction($row,'merge','merge','mergehistory') ) {
368 $merge = SpecialPage
::getTitleFor( 'Mergehistory' );
369 $revert = '(' . $this->skin
->link(
371 $this->message
['revertmerge'],
374 'target' => $paramArray[0],
375 'dest' => $title->getPrefixedDBkey(),
376 'mergepoint' => $paramArray[1]
378 array( 'known', 'noclasses' )
380 // If an edit was hidden from a page give a review link to the history
381 } else if( self
::typeAction($row,array('delete','suppress'),'revision','deleterevision') ) {
382 if( count($paramArray) >= 2 ) {
383 // Different revision types use different URL params...
384 $key = $paramArray[0];
385 // $paramArray[1] is a CSV of the IDs
386 $Ids = explode( ',', $paramArray[1] );
387 $query = $paramArray[1];
389 // Diff link for single rev deletions
390 if( count($Ids) == 1 ) {
391 // Live revision diffs...
392 if( in_array($key, array('oldid','revision')) ) {
393 $revert[] = $this->skin
->link(
395 $this->message
['diff'],
398 'diff' => intval( $Ids[0] ),
401 array( 'known', 'noclasses' )
403 // Deleted revision diffs...
404 } else if( in_array($key, array('artimestamp','archive')) ) {
405 $revert[] = $this->skin
->link(
406 SpecialPage
::getTitleFor( 'Undelete' ),
407 $this->message
['diff'],
410 'target' => $title->getPrefixedDBKey(),
412 'timestamp' => $Ids[0]
414 array( 'known', 'noclasses' )
418 // View/modify link...
419 $revert[] = $this->skin
->link(
420 SpecialPage
::getTitleFor( 'Revisiondelete' ),
421 $this->message
['revdel-restore'],
424 'target' => $title->getPrefixedText(),
428 array( 'known', 'noclasses' )
431 $revert = wfMsg( 'parentheses', $wgLang->pipeList( $revert ) );
433 // Hidden log items, give review link
434 } else if( self
::typeAction($row,array('delete','suppress'),'event','deleterevision') ) {
435 if( count($paramArray) >= 1 ) {
436 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
437 // $paramArray[1] is a CSV of the IDs
438 $Ids = explode( ',', $paramArray[0] );
439 $query = $paramArray[0];
440 // Link to each hidden object ID, $paramArray[1] is the url param
441 $revert = '(' . $this->skin
->link(
443 $this->message
['revdel-restore'],
446 'target' => $title->getPrefixedText(),
450 array( 'known', 'noclasses' )
453 // Self-created users
454 } else if( self
::typeAction($row,'newusers','create2') ) {
455 if( isset( $paramArray[0] ) ) {
456 $revert = $this->skin
->userToolLinks( $paramArray[0], $title->getDBkey(), true );
458 # Fall back to a blue contributions link
459 $revert = $this->skin
->userToolLinks( 1, $title->getDBkey() );
461 if( $time < '20080129000000' ) {
462 # Suppress $comment from old entries (before 2008-01-29),
463 # not needed and can contain incorrect links
466 // Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
468 wfRunHooks( 'LogLine', array( $row->log_type
, $row->log_action
, $title, $paramArray,
469 &$comment, &$revert, $row->log_timestamp
) );
472 if( self
::isDeleted($row,LogPage
::DELETED_ACTION
) ) {
473 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
475 $action = LogPage
::actionText( $row->log_type
, $row->log_action
, $title,
476 $this->skin
, $paramArray, true );
480 list($tagDisplay, $newClasses) = ChangeTags
::formatSummaryRow( $row->ts_tags
, 'logevent' );
481 $classes = array_merge( $classes, $newClasses );
483 if( $revert != '' ) {
484 $revert = '<span class="mw-logevent-actionlink">' . $revert . '</span>';
487 $time = htmlspecialchars( $time );
489 return Xml
::tags( 'li', array( "class" => implode( ' ', $classes ) ),
490 $del . $time . ' ' . $userLink . ' ' . $action . ' ' . $comment . ' ' . $revert . " $tagDisplay" ) . "\n";
497 private function getShowHideLinks( $row ) {
498 // If event was hidden from sysops
499 if( !self
::userCan( $row, LogPage
::DELETED_RESTRICTED
) ) {
500 $del = Xml
::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
501 '('.$this->message
['rev-delundel'].')' );
502 } else if( $row->log_type
== 'suppress' ) {
503 $del = ''; // No one should be hiding from the oversight log
505 $target = SpecialPage
::getTitleFor( 'Log', $row->log_type
);
506 $page = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
508 'target' => $target->getPrefixedDBkey(),
510 'ids' => $row->log_id
,
512 $del = $this->skin
->revDeleteLink( $query,
513 self
::isDeleted( $row, LogPage
::DELETED_RESTRICTED
) );
520 * @param $type Mixed: string/array
521 * @param $action Mixed: string/array
522 * @param $right string
525 public static function typeAction( $row, $type, $action, $right='' ) {
526 $match = is_array($type) ?
527 in_array($row->log_type
,$type) : $row->log_type
== $type;
529 $match = is_array($action) ?
530 in_array($row->log_action
,$action) : $row->log_action
== $action;
531 if( $match && $right ) {
533 $match = $wgUser->isAllowed( $right );
540 * Determine if the current user is allowed to view a particular
541 * field of this log row, if it's marked as deleted.
543 * @param $field Integer
546 public static function userCan( $row, $field ) {
547 if( ( $row->log_deleted
& $field ) == $field ) {
549 $permission = ( $row->log_deleted
& LogPage
::DELETED_RESTRICTED
) == LogPage
::DELETED_RESTRICTED
552 wfDebug( "Checking for $permission due to $field match on $row->log_deleted\n" );
553 return $wgUser->isAllowed( $permission );
561 * @param $field Integer: one of DELETED_* bitfield constants
564 public static function isDeleted( $row, $field ) {
565 return ($row->log_deleted
& $field) == $field;
569 * Show log extract. Either with text and a box (set $msgKey) or without (don't set $msgKey)
570 * @param $out OutputPage or String-by-reference
571 * @param $types String or Array
572 * @param $page String The page title to show log entries for
573 * @param $user String The user who made the log entries
574 * @param $param Associative Array with the following additional options:
575 * lim Integer Limit of items to show, default is 50
576 * conds Array Extra conditions for the query (e.g. "log_action != 'revision'")
577 * showIfEmpty boolean Set to false if you don't want any output in case the loglist is empty
578 * if set to true (default), "No matching items in log" is displayed if loglist is empty
579 * msgKey Array If you want a nice box with a message, set this
580 * to the key of the message. First element is the message
581 * key, additional optional elements are parameters for the
582 * key that are processed with wgMsgExt and option 'parse'
583 * @return Integer Number of total log items (not limited by $lim)
585 public static function showLogExtract( &$out, $types=array(), $page='', $user='',
588 $defaultParameters = array(
591 'showIfEmpty' => true,
592 'msgKey' => array('')
595 # The + operator appends elements of remaining keys from the right
596 # handed array to the left handed, whereas duplicated keys are NOT overwritten.
597 $param +
= $defaultParameters;
599 global $wgUser, $wgOut;
600 # Convert $param array to individual variables
601 $lim = $param['lim'];
602 $conds = $param['conds'];
603 $showIfEmpty = $param['showIfEmpty'];
604 $msgKey = $param['msgKey'];
605 if ( !is_array($msgKey) )
606 $msgKey = array( $msgKey );
607 # Insert list of top 50 (or top $lim) items
608 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
609 $pager = new LogPager( $loglist, $types, $user, $page, '', $conds );
610 if( $lim > 0 ) $pager->mLimit
= $lim;
611 $logBody = $pager->getBody();
615 $s = '<div class="mw-warning-with-logexcerpt">';
617 if ( count( $msgKey ) == 1 ) {
618 $s .= wfMsgExt( $msgKey[0], array('parse') );
619 } else { // Process additional arguments
621 array_shift( $args );
622 $s .= wfMsgExt( $msgKey[0], array('parse'), $args );
625 $s .= $loglist->beginLogEventsList() .
627 $loglist->endLogEventsList();
630 $s = wfMsgExt( 'logempty', array('parse') );
632 if( $pager->getNumRows() > $pager->mLimit
) { # Show "Full log" link
635 $urlParam['page'] = $page;
637 $urlParam['user'] = $user;
638 if ( !is_array( $types ) ) # Make it an array, if it isn't
639 $types = array( $types );
640 # If there is exactly one log type, we can link to Special:Log?type=foo
641 if ( count( $types ) == 1 )
642 $urlParam['type'] = $types[0];
643 $s .= $wgUser->getSkin()->link(
644 SpecialPage
::getTitleFor( 'Log' ),
645 wfMsgHtml( 'log-fulllog' ),
651 if ( $logBody && $msgKey[0] )
654 if( $out instanceof OutputPage
){
659 return $pager->getNumRows();
663 * SQL clause to skip forbidden log types for this user
664 * @param $db Database
665 * @param $audience string, public/user
666 * @return mixed (string or false)
668 public static function getExcludeClause( $db, $audience = 'public' ) {
669 global $wgLogRestrictions, $wgUser;
670 // Reset the array, clears extra "where" clauses when $par is used
671 $hiddenLogs = array();
672 // Don't show private logs to unprivileged users
673 foreach( $wgLogRestrictions as $logType => $right ) {
674 if( $audience == 'public' ||
!$wgUser->isAllowed($right) ) {
675 $safeType = $db->strencode( $logType );
676 $hiddenLogs[] = $safeType;
679 if( count($hiddenLogs) == 1 ) {
680 return 'log_type != ' . $db->addQuotes( $hiddenLogs[0] );
681 } elseif( $hiddenLogs ) {
682 return 'log_type NOT IN (' . $db->makeList($hiddenLogs) . ')';
691 class LogPager
extends ReverseChronologicalPager
{
692 private $types = array(), $user = '', $title = '', $pattern = '';
693 private $typeCGI = '';
694 public $mLogEventsList;
698 * @param $list LogEventsList
699 * @param $types String or Array log types to show
700 * @param $user String The user who made the log entries
701 * @param $title String The page title the log entries are for
702 * @param $pattern String Do a prefix search rather than an exact title match
703 * @param $conds Array Extra conditions for the query
704 * @param $year Integer The year to start from
705 * @param $month Integer The month to start from
707 public function __construct( $list, $types = array(), $user = '', $title = '', $pattern = '',
708 $conds = array(), $year = false, $month = false, $tagFilter = '' )
710 parent
::__construct();
711 $this->mConds
= $conds;
713 $this->mLogEventsList
= $list;
715 $this->limitType( $types ); // also excludes hidden types
716 $this->limitUser( $user );
717 $this->limitTitle( $title, $pattern );
718 $this->getDateCond( $year, $month );
719 $this->mTagFilter
= $tagFilter;
722 public function getDefaultQuery() {
723 $query = parent
::getDefaultQuery();
724 $query['type'] = $this->typeCGI
; // arrays won't work here
725 $query['user'] = $this->user
;
726 $query['month'] = $this->mMonth
;
727 $query['year'] = $this->mYear
;
731 // Call ONLY after calling $this->limitType() already!
732 public function getFilterParams() {
733 global $wgFilterLogTypes, $wgUser, $wgRequest;
735 if( count($this->types
) ) {
738 foreach( $wgFilterLogTypes as $type => $default ) {
739 // Avoid silly filtering
740 if( $type !== 'patrol' ||
$wgUser->useNPPatrol() ) {
741 $hide = $wgRequest->getInt( "hide_{$type}_log", $default );
742 $filters[$type] = $hide;
744 $this->mConds
[] = 'log_type != ' . $this->mDb
->addQuotes( $type );
751 * Set the log reader to return only entries of the given type.
752 * Type restrictions enforced here
753 * @param $types String or array: Log types ('upload', 'delete', etc);
754 * empty string means no restriction
756 private function limitType( $types ) {
757 global $wgLogRestrictions, $wgUser;
758 // If $types is not an array, make it an array
759 $types = ($types === '') ?
array() : (array)$types;
760 // Don't even show header for private logs; don't recognize it...
761 foreach ( $types as $type ) {
762 if( isset( $wgLogRestrictions[$type] ) && !$wgUser->isAllowed($wgLogRestrictions[$type]) ) {
763 $types = array_diff( $types, array( $type ) );
766 // Don't show private logs to unprivileged users.
767 // Also, only show them upon specific request to avoid suprises.
768 $audience = $types ?
'user' : 'public';
769 $hideLogs = LogEventsList
::getExcludeClause( $this->mDb
, $audience );
770 if( $hideLogs !== false ) {
771 $this->mConds
[] = $hideLogs;
773 if( count($types) ) {
774 $this->types
= $types;
775 $this->mConds
['log_type'] = $types;
776 // Set typeCGI; used in url param for paging
777 if( count($types) == 1 ) $this->typeCGI
= $types[0];
782 * Set the log reader to return only entries by the given user.
783 * @param $name String: (In)valid user name
785 private function limitUser( $name ) {
789 $usertitle = Title
::makeTitleSafe( NS_USER
, $name );
790 if( is_null($usertitle) ) {
793 /* Fetch userid at first, if known, provides awesome query plan afterwards */
794 $userid = User
::idFromName( $name );
796 /* It should be nicer to abort query at all,
797 but for now it won't pass anywhere behind the optimizer */
798 $this->mConds
[] = "NULL";
801 $this->mConds
['log_user'] = $userid;
802 // Paranoia: avoid brute force searches (bug 17342)
803 if( !$wgUser->isAllowed( 'deleterevision' ) ) {
804 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::DELETED_USER
) . ' = 0';
805 } else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
806 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::SUPPRESSED_USER
) .
807 ' != ' . LogPage
::SUPPRESSED_USER
;
809 $this->user
= $usertitle->getText();
814 * Set the log reader to return only entries affecting the given page.
815 * (For the block and rights logs, this is a user page.)
816 * @param $page String: Title name as text
817 * @param $pattern String
819 private function limitTitle( $page, $pattern ) {
820 global $wgMiserMode, $wgUser;
822 $title = Title
::newFromText( $page );
823 if( strlen($page) == 0 ||
!$title instanceof Title
)
826 $this->title
= $title->getPrefixedText();
827 $ns = $title->getNamespace();
828 # Using the (log_namespace, log_title, log_timestamp) index with a
829 # range scan (LIKE) on the first two parts, instead of simple equality,
830 # makes it unusable for sorting. Sorted retrieval using another index
831 # would be possible, but then we might have to scan arbitrarily many
832 # nodes of that index. Therefore, we need to avoid this if $wgMiserMode
835 # This is not a problem with simple title matches, because then we can
836 # use the page_time index. That should have no more than a few hundred
837 # log entries for even the busiest pages, so it can be safely scanned
838 # in full to satisfy an impossible condition on user or similar.
839 if( $pattern && !$wgMiserMode ) {
840 # use escapeLike to avoid expensive search patterns like 't%st%'
841 $safetitle = $this->mDb
->escapeLike( $title->getDBkey() );
842 $this->mConds
['log_namespace'] = $ns;
843 $this->mConds
[] = "log_title LIKE '$safetitle%'";
844 $this->pattern
= $pattern;
846 $this->mConds
['log_namespace'] = $ns;
847 $this->mConds
['log_title'] = $title->getDBkey();
849 // Paranoia: avoid brute force searches (bug 17342)
850 if( !$wgUser->isAllowed( 'deleterevision' ) ) {
851 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::DELETED_ACTION
) . ' = 0';
852 } else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
853 $this->mConds
[] = $this->mDb
->bitAnd('log_deleted', LogPage
::SUPPRESSED_ACTION
) .
854 ' != ' . LogPage
::SUPPRESSED_ACTION
;
858 public function getQueryInfo() {
859 $tables = array( 'logging', 'user' );
860 $this->mConds
[] = 'user_id = log_user';
862 # Add log_search table if there are conditions on it
863 if( array_key_exists('ls_field',$this->mConds
) ) {
864 $tables[] = 'log_search';
865 $index = array( 'log_search' => 'ls_field_val', 'logging' => 'PRIMARY' );
866 $groupBy = 'ls_log_id';
867 # Don't use the wrong logging index
868 } else if( $this->title ||
$this->pattern ||
$this->user
) {
869 $index = array( 'logging' => array('page_time','user_time') );
870 } else if( $this->types
) {
871 $index = array( 'logging' => 'type_time' );
873 $index = array( 'logging' => 'times' );
875 $options = array( 'USE INDEX' => $index );
876 # Don't show duplicate rows when using log_search
877 if( $groupBy ) $options['GROUP BY'] = $groupBy;
880 'fields' => array( 'log_type', 'log_action', 'log_user', 'log_namespace',
881 'log_title', 'log_params', 'log_comment', 'log_id', 'log_deleted',
882 'log_timestamp', 'user_name', 'user_editcount' ),
883 'conds' => $this->mConds
,
884 'options' => $options,
885 'join_conds' => array(
886 'user' => array( 'INNER JOIN', 'user_id=log_user' ),
887 'log_search' => array( 'INNER JOIN', 'ls_log_id=log_id' )
890 # Add ChangeTags filter query
891 ChangeTags
::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'],
892 $info['join_conds'], $info['options'], $this->mTagFilter
);
897 function getIndexField() {
898 return 'log_timestamp';
901 public function getStartBody() {
902 wfProfileIn( __METHOD__
);
903 # Do a link batch query
904 if( $this->getNumRows() > 0 ) {
906 while( $row = $this->mResult
->fetchObject() ) {
907 $lb->add( $row->log_namespace
, $row->log_title
);
908 $lb->addObj( Title
::makeTitleSafe( NS_USER
, $row->user_name
) );
909 $lb->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->user_name
) );
912 $this->mResult
->seek( 0 );
914 wfProfileOut( __METHOD__
);
918 public function formatRow( $row ) {
919 return $this->mLogEventsList
->logLine( $row );
922 public function getType() {
926 public function getUser() {
930 public function getPage() {
934 public function getPattern() {
935 return $this->pattern
;
938 public function getYear() {
942 public function getMonth() {
943 return $this->mMonth
;
946 public function getTagFilter() {
947 return $this->mTagFilter
;
950 public function doQuery() {
951 // Workaround MySQL optimizer bug
952 $this->mDb
->setBigSelects();
954 $this->mDb
->setBigSelects( 'default' );
960 * @ingroup SpecialPage
965 * @param $request WebRequest: for internal use use a FauxRequest object to pass arbitrary parameters.
967 function __construct( $request ) {
968 global $wgUser, $wgOut;
969 wfDeprecated(__METHOD__
);
971 $type = $request->getVal( 'type' );
972 $user = $request->getText( 'user' );
973 $title = $request->getText( 'page' );
974 $pattern = $request->getBool( 'pattern' );
975 $year = $request->getIntOrNull( 'year' );
976 $month = $request->getIntOrNull( 'month' );
977 $tagFilter = $request->getVal( 'tagfilter' );
978 # Don't let the user get stuck with a certain date
979 $skip = $request->getText( 'offset' ) ||
$request->getText( 'dir' ) == 'prev';
984 # Use new list class to output results
985 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
986 $this->pager
= new LogPager( $loglist, $type, $user, $title, $pattern, $year, $month, $tagFilter );
990 * Is there at least one row?
993 public function hasRows() {
994 return isset($this->pager
) ?
($this->pager
->getNumRows() > 0) : false;
1000 * @ingroup SpecialPage
1003 const NO_ACTION_LINK
= 1;
1011 * @param &$reader LogReader: where to get our data from
1012 * @param $flags Integer: Bitwise combination of flags:
1013 * LogEventsList::NO_ACTION_LINK Don't show restore/unblock/block links
1015 function __construct( &$reader, $flags = 0 ) {
1016 wfDeprecated(__METHOD__
);
1017 $this->reader
=& $reader;
1018 $this->reader
->pager
->mLogEventsList
->flags
= $flags;
1019 # Aliases for shorter code...
1020 $this->pager
=& $this->reader
->pager
;
1021 $this->list =& $this->reader
->pager
->mLogEventsList
;
1025 * Take over the whole output page in $wgOut with the log display.
1027 public function show() {
1028 # Set title and add header
1029 $this->list->showHeader( $pager->getType() );
1031 $this->list->showOptions( $this->pager
->getType(), $this->pager
->getUser(), $this->pager
->getPage(),
1032 $this->pager
->getPattern(), $this->pager
->getYear(), $this->pager
->getMonth() );
1034 $logBody = $this->pager
->getBody();
1037 $this->pager
->getNavigationBar() .
1038 $this->list->beginLogEventsList() .
1040 $this->list->endLogEventsList() .
1041 $this->pager
->getNavigationBar()
1044 $wgOut->addWikiMsg( 'logempty' );
1049 * Output just the list of entries given by the linked LogReader,
1050 * with extraneous UI elements. Use for displaying log fragments in
1051 * another page (eg at Special:Undelete)
1052 * @param $out OutputPage: where to send output
1054 public function showList( &$out ) {
1055 $logBody = $this->pager
->getBody();
1058 $this->list->beginLogEventsList() .
1060 $this->list->endLogEventsList()
1063 $out->addWikiMsg( 'logempty' );