Partial revert of r47192 (* removed DefaultQuery cruft) -- That cruft was kinda impor...
[lhc/web/wiklou.git] / includes / LogEventsList.php
1 <?php
2 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>, 2008 Aaron Schulz
3 # http://www.mediawiki.org/
4 #
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.
9 #
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.
14 #
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
19
20 class LogEventsList {
21 const NO_ACTION_LINK = 1;
22
23 private $skin;
24 private $out;
25 public $flags;
26
27 public function __construct( $skin, $out, $flags = 0 ) {
28 $this->skin = $skin;
29 $this->out = $out;
30 $this->flags = $flags;
31 $this->preCacheMessages();
32 }
33
34 /**
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
37 */
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', 'revdel-restore', 'rev-delundel', 'hist', 'pipe-separator' );
43 foreach( $messages as $msg ) {
44 $this->message[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
45 }
46 }
47 }
48
49 /**
50 * Set page title and show header for this log type
51 * @param $type String
52 */
53 public function showHeader( $type ) {
54 if( LogPage::isLogType( $type ) ) {
55 $this->out->setPageTitle( LogPage::logName( $type ) );
56 $this->out->addHTML( LogPage::logHeader( $type ) );
57 }
58 }
59
60 /**
61 * Show options for the log list
62 * @param $type String
63 * @param $user String
64 * @param $page String
65 * @param $pattern String
66 * @param $year Integer: year
67 * @param $month Integer: month
68 * @param $filter: array
69 * @param $tagFilter: array?
70 */
71 public function showOptions( $type = '', $user = '', $page = '', $pattern = '', $year = '',
72 $month = '', $filter = null, $tagFilter='' )
73 {
74 global $wgScript, $wgMiserMode;
75 $action = htmlspecialchars( $wgScript );
76 $title = SpecialPage::getTitleFor( 'Log' );
77 $special = htmlspecialchars( $title->getPrefixedDBkey() );
78
79 $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter );
80
81 $this->out->addHTML( "<form action=\"$action\" method=\"get\"><fieldset>" .
82 Xml::element( 'legend', array(), wfMsg( 'log' ) ) .
83 Xml::hidden( 'title', $special ) . "\n" .
84 $this->getTypeMenu( $type ) . "\n" .
85 $this->getUserInput( $user ) . "\n" .
86 $this->getTitleInput( $page ) . "\n" .
87 ( !$wgMiserMode ? ($this->getTitlePattern( $pattern )."\n") : "" ) .
88 "<p>" . Xml::dateMenu( $year, $month ) . "\n" .
89 ( $tagSelector ? Xml::tags( 'p', null, implode( '&nbsp;', $tagSelector ) ) :'' ). "\n" .
90 ( $filter ? "</p><p>".$this->getFilterLinks( $type, $filter )."\n" : "" ) . "\n" .
91 Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "</p>\n" .
92 "</fieldset></form>"
93 );
94 }
95
96 private function getFilterLinks( $logType, $filter ) {
97 global $wgTitle, $wgLang;
98 // show/hide links
99 $messages = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
100 // Option value -> message mapping
101 $links = array();
102 $hiddens = ''; // keep track for "go" button
103 foreach( $filter as $type => $val ) {
104 $hideVal = 1 - intval($val);
105 $link = $this->skin->makeKnownLinkObj( $wgTitle, $messages[$hideVal],
106 wfArrayToCGI( array( "hide_{$type}_log" => $hideVal ), $this->getDefaultQuery() )
107 );
108 $links[$type] = wfMsgHtml( "log-show-hide-{$type}", $link );
109 $hiddens .= Xml::hidden( "hide_{$type}_log", $val ) . "\n";
110 }
111 // Build links
112 return '<small>'.$wgLang->pipeList( $links ) . '</small>' . $hiddens;
113 }
114
115 private function getDefaultQuery() {
116 if ( !isset( $this->mDefaultQuery ) ) {
117 $this->mDefaultQuery = $_GET;
118 unset( $this->mDefaultQuery['title'] );
119 unset( $this->mDefaultQuery['dir'] );
120 unset( $this->mDefaultQuery['offset'] );
121 unset( $this->mDefaultQuery['limit'] );
122 unset( $this->mDefaultQuery['order'] );
123 unset( $this->mDefaultQuery['month'] );
124 unset( $this->mDefaultQuery['year'] );
125 }
126 return $this->mDefaultQuery;
127 }
128
129 /**
130 * @param $queryType String
131 * @return String: Formatted HTML
132 */
133 private function getTypeMenu( $queryType ) {
134 global $wgLogRestrictions, $wgUser;
135
136 $html = "<select name='type'>\n";
137
138 $validTypes = LogPage::validTypes();
139 $typesByName = array(); // Temporary array
140
141 // First pass to load the log names
142 foreach( $validTypes as $type ) {
143 $text = LogPage::logName( $type );
144 $typesByName[$text] = $type;
145 }
146
147 // Second pass to sort by name
148 ksort($typesByName);
149
150 // Third pass generates sorted XHTML content
151 foreach( $typesByName as $text => $type ) {
152 $selected = ($type == $queryType);
153 // Restricted types
154 if ( isset($wgLogRestrictions[$type]) ) {
155 if ( $wgUser->isAllowed( $wgLogRestrictions[$type] ) ) {
156 $html .= Xml::option( $text, $type, $selected ) . "\n";
157 }
158 } else {
159 $html .= Xml::option( $text, $type, $selected ) . "\n";
160 }
161 }
162
163 $html .= '</select>';
164 return $html;
165 }
166
167 /**
168 * @param $user String
169 * @return String: Formatted HTML
170 */
171 private function getUserInput( $user ) {
172 return Xml::inputLabel( wfMsg( 'specialloguserlabel' ), 'user', 'user', 15, $user );
173 }
174
175 /**
176 * @param $title String
177 * @return String: Formatted HTML
178 */
179 private function getTitleInput( $title ) {
180 return Xml::inputLabel( wfMsg( 'speciallogtitlelabel' ), 'page', 'page', 20, $title );
181 }
182
183 /**
184 * @return boolean Checkbox
185 */
186 private function getTitlePattern( $pattern ) {
187 return '<span style="white-space: nowrap">' .
188 Xml::checkLabel( wfMsg( 'log-title-wildcard' ), 'pattern', 'pattern', $pattern ) .
189 '</span>';
190 }
191
192 public function beginLogEventsList() {
193 return "<ul>\n";
194 }
195
196 public function endLogEventsList() {
197 return "</ul>\n";
198 }
199
200 /**
201 * @param $row Row: a single row from the result set
202 * @return String: Formatted HTML list item
203 */
204 public function logLine( $row ) {
205 global $wgLang, $wgUser, $wgContLang;
206
207 $title = Title::makeTitle( $row->log_namespace, $row->log_title );
208 $classes = array( "mw-logline-{$row->log_type}" );
209 $time = $wgLang->timeanddate( wfTimestamp(TS_MW, $row->log_timestamp), true );
210 // User links
211 if( self::isDeleted($row,LogPage::DELETED_USER) ) {
212 $userLink = '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
213 } else {
214 $userLink = $this->skin->userLink( $row->log_user, $row->user_name ) .
215 $this->skin->userToolLinks( $row->log_user, $row->user_name, true, 0, $row->user_editcount );
216 }
217 // Comment
218 if( self::isDeleted($row,LogPage::DELETED_COMMENT) ) {
219 $comment = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
220 } else {
221 $comment = $wgContLang->getDirMark() . $this->skin->commentBlock( $row->log_comment );
222 }
223 // Extract extra parameters
224 $paramArray = LogPage::extractParams( $row->log_params );
225 $revert = $del = '';
226 // Some user can hide log items and have review links
227 if( $wgUser->isAllowed( 'deleterevision' ) ) {
228 $del = $this->getShowHideLinks( $row ) . ' ';
229 }
230 // Add review links and such...
231 if( ($this->flags & self::NO_ACTION_LINK) || ($row->log_deleted & LogPage::DELETED_ACTION) ) {
232 // Action text is suppressed...
233 } else if( self::typeAction($row,'move','move','move') && !empty($paramArray[0]) ) {
234 $destTitle = Title::newFromText( $paramArray[0] );
235 if( $destTitle ) {
236 $revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
237 $this->message['revertmove'],
238 'wpOldTitle=' . urlencode( $destTitle->getPrefixedDBkey() ) .
239 '&wpNewTitle=' . urlencode( $title->getPrefixedDBkey() ) .
240 '&wpReason=' . urlencode( wfMsgForContent( 'revertmove' ) ) .
241 '&wpMovetalk=0' ) . ')';
242 }
243 // Show undelete link
244 } else if( self::typeAction($row,array('delete','suppress'),'delete','delete') ) {
245 $revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Undelete' ),
246 $this->message['undeletelink'], 'target='. urlencode( $title->getPrefixedDBkey() ) ) . ')';
247 // Show unblock/change block link
248 } else if( self::typeAction($row,array('block','suppress'),array('block','reblock'),'block') ) {
249 $revert = '(' .
250 $this->skin->link( SpecialPage::getTitleFor( 'Ipblocklist' ),
251 $this->message['unblocklink'],
252 array(),
253 array( 'action' => 'unblock', 'ip' => $row->log_title ),
254 'known' )
255 . $this->message['pipe-separator'] .
256 $this->skin->link( SpecialPage::getTitleFor( 'Blockip', $row->log_title ),
257 $this->message['change-blocklink'],
258 array(), array(), 'known' ) .
259 ')';
260 // Show change protection link
261 } else if( self::typeAction( $row, 'protect', array( 'modify', 'protect', 'unprotect' ) ) ) {
262 $revert .= ' (' .
263 $this->skin->link( $title,
264 $this->message['hist'],
265 array(),
266 array( 'action' => 'history', 'offset' => $row->log_timestamp ) );
267 if( $wgUser->isAllowed( 'protect' ) ) {
268 $revert .= $this->message['pipe-separator'] .
269 $this->skin->link( $title,
270 $this->message['protect_change'],
271 array(),
272 array( 'action' => 'protect' ),
273 'known' );
274 }
275 $revert .= ')';
276 // Show unmerge link
277 } else if( self::typeAction($row,'merge','merge','mergehistory') ) {
278 $merge = SpecialPage::getTitleFor( 'Mergehistory' );
279 $revert = '(' . $this->skin->makeKnownLinkObj( $merge, $this->message['revertmerge'],
280 wfArrayToCGI( array('target' => $paramArray[0], 'dest' => $title->getPrefixedDBkey(),
281 'mergepoint' => $paramArray[1] ) ) ) . ')';
282 // If an edit was hidden from a page give a review link to the history
283 } else if( self::typeAction($row,array('delete','suppress'),'revision','deleterevision') ) {
284 if( count($paramArray) == 2 ) {
285 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
286 // Different revision types use different URL params...
287 $key = $paramArray[0];
288 // Link to each hidden object ID, $paramArray[1] is the url param
289 $Ids = explode( ',', $paramArray[1] );
290 $revParams = '';
291 foreach( $Ids as $n => $id ) {
292 $revParams .= '&' . urlencode($key) . '[]=' . urlencode($id);
293 }
294 $revert = '(' . $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'],
295 'target=' . $title->getPrefixedUrl() . $revParams ) . ')';
296 }
297 // Hidden log items, give review link
298 } else if( self::typeAction($row,array('delete','suppress'),'event','deleterevision') ) {
299 if( count($paramArray) == 1 ) {
300 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
301 $Ids = explode( ',', $paramArray[0] );
302 // Link to each hidden object ID, $paramArray[1] is the url param
303 $logParams = '';
304 foreach( $Ids as $n => $id ) {
305 $logParams .= '&logid[]=' . intval($id);
306 }
307 $revert = '(' . $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'],
308 'target=' . $title->getPrefixedUrl() . $logParams ) . ')';
309 }
310 // Self-created users
311 } else if( self::typeAction($row,'newusers','create2') ) {
312 if( isset( $paramArray[0] ) ) {
313 $revert = $this->skin->userToolLinks( $paramArray[0], $title->getDBkey(), true );
314 } else {
315 # Fall back to a blue contributions link
316 $revert = $this->skin->userToolLinks( 1, $title->getDBkey() );
317 }
318 if( $time < '20080129000000' ) {
319 # Suppress $comment from old entries (before 2008-01-29),
320 # not needed and can contain incorrect links
321 $comment = '';
322 }
323 // Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
324 } else {
325 wfRunHooks( 'LogLine', array( $row->log_type, $row->log_action, $title, $paramArray,
326 &$comment, &$revert, $row->log_timestamp ) );
327 }
328 // Event description
329 if( self::isDeleted($row,LogPage::DELETED_ACTION) ) {
330 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
331 } else {
332 $action = LogPage::actionText( $row->log_type, $row->log_action, $title,
333 $this->skin, $paramArray, true );
334 }
335
336 // Any tags...
337 list($tagDisplay, $newClasses) = ChangeTags::formatSummaryRow( $row->ts_tags, 'logevent' );
338 $classes = array_merge( $classes, $newClasses );
339
340 if( $revert != '' ) {
341 $revert = '<span class="mw-logevent-actionlink">' . $revert . '</span>';
342 }
343
344 return Xml::tags( 'li', array( "class" => implode( ' ', $classes ) ),
345 $del . $time . ' ' . $userLink . ' ' . $action . ' ' . $comment . ' ' . $revert . " $tagDisplay" ) . "\n";
346 }
347
348 /**
349 * @param $row Row
350 * @return string
351 */
352 private function getShowHideLinks( $row ) {
353 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
354 // If event was hidden from sysops
355 if( !self::userCan( $row, LogPage::DELETED_RESTRICTED ) ) {
356 $del = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ), '('.$this->message['rev-delundel'].')' );
357 } else if( $row->log_type == 'suppress' ) {
358 // No one should be hiding from the oversight log
359 $del = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ), '('.$this->message['rev-delundel'].')' );
360 } else {
361 $target = SpecialPage::getTitleFor( 'Log', $row->log_type );
362 $query = array( 'target' => $target->getPrefixedDBkey(),
363 'logid' => $row->log_id
364 );
365 $del = $this->skin->revDeleteLink( $query, self::isDeleted( $row, LogPage::DELETED_RESTRICTED ) );
366 }
367 return $del;
368 }
369
370 /**
371 * @param $row Row
372 * @param $type Mixed: string/array
373 * @param $action Mixed: string/array
374 * @param $right string
375 * @return bool
376 */
377 public static function typeAction( $row, $type, $action, $right='' ) {
378 $match = is_array($type) ? in_array($row->log_type,$type) : $row->log_type == $type;
379 if( $match ) {
380 $match = is_array($action) ?
381 in_array($row->log_action,$action) : $row->log_action == $action;
382 if( $match && $right ) {
383 global $wgUser;
384 $match = $wgUser->isAllowed( $right );
385 }
386 }
387 return $match;
388 }
389
390 /**
391 * Determine if the current user is allowed to view a particular
392 * field of this log row, if it's marked as deleted.
393 * @param $row Row
394 * @param $field Integer
395 * @return Boolean
396 */
397 public static function userCan( $row, $field ) {
398 if( ( $row->log_deleted & $field ) == $field ) {
399 global $wgUser;
400 $permission = ( $row->log_deleted & LogPage::DELETED_RESTRICTED ) == LogPage::DELETED_RESTRICTED
401 ? 'suppressrevision'
402 : 'deleterevision';
403 wfDebug( "Checking for $permission due to $field match on $row->log_deleted\n" );
404 return $wgUser->isAllowed( $permission );
405 } else {
406 return true;
407 }
408 }
409
410 /**
411 * @param $row Row
412 * @param $field Integer: one of DELETED_* bitfield constants
413 * @return Boolean
414 */
415 public static function isDeleted( $row, $field ) {
416 return ($row->log_deleted & $field) == $field;
417 }
418
419 /**
420 * Quick function to show a short log extract
421 * @param $out OutputPage
422 * @param $type String
423 * @param $page String
424 * @param $user String
425 * @param $lim Integer
426 * @param $conds Array
427 */
428 public static function showLogExtract( $out, $type='', $page='', $user='', $lim=0, $conds=array() ) {
429 global $wgUser;
430 # Insert list of top 50 or so items
431 $loglist = new LogEventsList( $wgUser->getSkin(), $out, 0 );
432 $pager = new LogPager( $loglist, $type, $user, $page, '', $conds );
433 if( $lim > 0 ) $pager->mLimit = $lim;
434 $logBody = $pager->getBody();
435 if( $logBody ) {
436 $out->addHTML(
437 $loglist->beginLogEventsList() .
438 $logBody .
439 $loglist->endLogEventsList()
440 );
441 } else {
442 $out->addWikiMsg( 'logempty' );
443 }
444 return $pager->getNumRows();
445 }
446
447 /**
448 * SQL clause to skip forbidden log types for this user
449 * @param $db Database
450 * @return mixed (string or false)
451 */
452 public static function getExcludeClause( $db ) {
453 global $wgLogRestrictions, $wgUser;
454 // Reset the array, clears extra "where" clauses when $par is used
455 $hiddenLogs = array();
456 // Don't show private logs to unprivileged users
457 foreach( $wgLogRestrictions as $logType => $right ) {
458 if( !$wgUser->isAllowed($right) ) {
459 $safeType = $db->strencode( $logType );
460 $hiddenLogs[] = $safeType;
461 }
462 }
463 if( count($hiddenLogs) == 1 ) {
464 return 'log_type != ' . $db->addQuotes( $hiddenLogs[0] );
465 } elseif( $hiddenLogs ) {
466 return 'log_type NOT IN (' . $db->makeList($hiddenLogs) . ')';
467 }
468 return false;
469 }
470 }
471
472 /**
473 * @ingroup Pager
474 */
475 class LogPager extends ReverseChronologicalPager {
476 private $type = '', $user = '', $title = '', $pattern = '';
477 public $mLogEventsList;
478
479 /**
480 * constructor
481 * @param $list LogEventsList
482 * @param $type String
483 * @param $user String
484 * @param $title String
485 * @param $pattern String
486 * @param $conds Array
487 * @param $year Integer
488 * @param $month Integer
489 */
490 public function __construct( $list, $type = '', $user = '', $title = '', $pattern = '',
491 $conds = array(), $year = false, $month = false, $tagFilter = '' )
492 {
493 parent::__construct();
494 $this->mConds = $conds;
495
496 $this->mLogEventsList = $list;
497
498 $this->limitType( $type ); // also excludes hidden types
499 $this->limitUser( $user );
500 $this->limitTitle( $title, $pattern );
501 $this->getDateCond( $year, $month );
502 $this->mTagFilter = $tagFilter;
503 }
504
505 public function getDefaultQuery() {
506 $query = parent::getDefaultQuery();
507 $query['type'] = $this->type;
508 $query['user'] = $this->user;
509 $query['month'] = $this->mMonth;
510 $query['year'] = $this->mYear;
511 return $query;
512 }
513
514 public function getFilterParams() {
515 global $wgFilterLogTypes, $wgUser, $wgRequest;
516 $filters = array();
517 if( $this->type ) {
518 return $filters;
519 }
520 foreach( $wgFilterLogTypes as $type => $default ) {
521 // Avoid silly filtering
522 if( $type !== 'patrol' || $wgUser->useNPPatrol() ) {
523 $hide = $wgRequest->getInt( "hide_{$type}_log", $default );
524 $filters[$type] = $hide;
525 if( $hide )
526 $this->mConds[] = 'log_type != ' . $this->mDb->addQuotes( $type );
527 }
528 }
529 return $filters;
530 }
531
532 /**
533 * Set the log reader to return only entries of the given type.
534 * Type restrictions enforced here
535 * @param $type String: A log type ('upload', 'delete', etc)
536 */
537 private function limitType( $type ) {
538 global $wgLogRestrictions, $wgUser;
539 // Don't even show header for private logs; don't recognize it...
540 if( isset($wgLogRestrictions[$type]) && !$wgUser->isAllowed($wgLogRestrictions[$type]) ) {
541 $type = '';
542 }
543 // Don't show private logs to unpriviledged users
544 $hideLogs = LogEventsList::getExcludeClause( $this->mDb );
545 if( $hideLogs !== false ) {
546 $this->mConds[] = $hideLogs;
547 }
548 if( !$type ) {
549 return false;
550 }
551 $this->type = $type;
552 $this->mConds['log_type'] = $type;
553 }
554
555 /**
556 * Set the log reader to return only entries by the given user.
557 * @param $name String: (In)valid user name
558 */
559 private function limitUser( $name ) {
560 if( $name == '' ) {
561 return false;
562 }
563 $usertitle = Title::makeTitleSafe( NS_USER, $name );
564 if( is_null($usertitle) ) {
565 return false;
566 }
567 /* Fetch userid at first, if known, provides awesome query plan afterwards */
568 $userid = User::idFromName( $name );
569 if( !$userid ) {
570 /* It should be nicer to abort query at all,
571 but for now it won't pass anywhere behind the optimizer */
572 $this->mConds[] = "NULL";
573 } else {
574 $this->mConds['log_user'] = $userid;
575 // Paranoia: avoid brute force searches (bug 17342)
576 $this->mConds[] = 'log_deleted & ' . LogPage::DELETED_USER . ' = 0';
577 $this->user = $usertitle->getText();
578 }
579 }
580
581 /**
582 * Set the log reader to return only entries affecting the given page.
583 * (For the block and rights logs, this is a user page.)
584 * @param $page String: Title name as text
585 * @param $pattern String
586 */
587 private function limitTitle( $page, $pattern ) {
588 global $wgMiserMode;
589
590 $title = Title::newFromText( $page );
591 if( strlen($page) == 0 || !$title instanceof Title )
592 return false;
593
594 $this->title = $title->getPrefixedText();
595 $ns = $title->getNamespace();
596 # Using the (log_namespace, log_title, log_timestamp) index with a
597 # range scan (LIKE) on the first two parts, instead of simple equality,
598 # makes it unusable for sorting. Sorted retrieval using another index
599 # would be possible, but then we might have to scan arbitrarily many
600 # nodes of that index. Therefore, we need to avoid this if $wgMiserMode
601 # is on.
602 #
603 # This is not a problem with simple title matches, because then we can
604 # use the page_time index. That should have no more than a few hundred
605 # log entries for even the busiest pages, so it can be safely scanned
606 # in full to satisfy an impossible condition on user or similar.
607 if( $pattern && !$wgMiserMode ) {
608 # use escapeLike to avoid expensive search patterns like 't%st%'
609 $safetitle = $this->mDb->escapeLike( $title->getDBkey() );
610 $this->mConds['log_namespace'] = $ns;
611 $this->mConds[] = "log_title LIKE '$safetitle%'";
612 $this->pattern = $pattern;
613 } else {
614 $this->mConds['log_namespace'] = $ns;
615 $this->mConds['log_title'] = $title->getDBkey();
616 }
617 // Paranoia: avoid brute force searches (bug 17342)
618 $this->mConds[] = 'log_deleted & ' . LogPage::DELETED_ACTION . ' = 0';
619 }
620
621 public function getQueryInfo() {
622 $this->mConds[] = 'user_id = log_user';
623 # Don't use the wrong logging index
624 if( $this->title || $this->pattern || $this->user ) {
625 $index = array( 'USE INDEX' => array( 'logging' => array('page_time','user_time') ) );
626 } else if( $this->type ) {
627 $index = array( 'USE INDEX' => array( 'logging' => 'type_time' ) );
628 } else {
629 $index = array( 'USE INDEX' => array( 'logging' => 'times' ) );
630 }
631 $info = array(
632 'tables' => array( 'logging', 'user' ),
633 'fields' => array( 'log_type', 'log_action', 'log_user', 'log_namespace', 'log_title', 'log_params',
634 'log_comment', 'log_id', 'log_deleted', 'log_timestamp', 'user_name', 'user_editcount' ),
635 'conds' => $this->mConds,
636 'options' => $index,
637 'join_conds' => array( 'user' => array( 'INNER JOIN', 'user_id=log_user' ) ),
638 );
639
640 ChangeTags::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'], $info['join_conds'], $this->mTagFilter );
641
642 return $info;
643 }
644
645 function getIndexField() {
646 return 'log_timestamp';
647 }
648
649 public function getStartBody() {
650 wfProfileIn( __METHOD__ );
651 # Do a link batch query
652 if( $this->getNumRows() > 0 ) {
653 $lb = new LinkBatch;
654 while( $row = $this->mResult->fetchObject() ) {
655 $lb->add( $row->log_namespace, $row->log_title );
656 $lb->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
657 $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
658 }
659 $lb->execute();
660 $this->mResult->seek( 0 );
661 }
662 wfProfileOut( __METHOD__ );
663 return '';
664 }
665
666 public function formatRow( $row ) {
667 return $this->mLogEventsList->logLine( $row );
668 }
669
670 public function getType() {
671 return $this->type;
672 }
673
674 public function getUser() {
675 return $this->user;
676 }
677
678 public function getPage() {
679 return $this->title;
680 }
681
682 public function getPattern() {
683 return $this->pattern;
684 }
685
686 public function getYear() {
687 return $this->mYear;
688 }
689
690 public function getMonth() {
691 return $this->mMonth;
692 }
693
694 public function getTagFilter() {
695 return $this->mTagFilter;
696 }
697 }
698
699 /**
700 * @deprecated
701 * @ingroup SpecialPage
702 */
703 class LogReader {
704 var $pager;
705 /**
706 * @param $request WebRequest: for internal use use a FauxRequest object to pass arbitrary parameters.
707 */
708 function __construct( $request ) {
709 global $wgUser, $wgOut;
710 wfDeprecated(__METHOD__);
711 # Get parameters
712 $type = $request->getVal( 'type' );
713 $user = $request->getText( 'user' );
714 $title = $request->getText( 'page' );
715 $pattern = $request->getBool( 'pattern' );
716 $year = $request->getIntOrNull( 'year' );
717 $month = $request->getIntOrNull( 'month' );
718 $tagFilter = $request->getVal( 'tagfilter' );
719 # Don't let the user get stuck with a certain date
720 $skip = $request->getText( 'offset' ) || $request->getText( 'dir' ) == 'prev';
721 if( $skip ) {
722 $year = '';
723 $month = '';
724 }
725 # Use new list class to output results
726 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
727 $this->pager = new LogPager( $loglist, $type, $user, $title, $pattern, $year, $month, $tagFilter );
728 }
729
730 /**
731 * Is there at least one row?
732 * @return bool
733 */
734 public function hasRows() {
735 return isset($this->pager) ? ($this->pager->getNumRows() > 0) : false;
736 }
737 }
738
739 /**
740 * @deprecated
741 * @ingroup SpecialPage
742 */
743 class LogViewer {
744 const NO_ACTION_LINK = 1;
745
746 /**
747 * LogReader object
748 */
749 var $reader;
750
751 /**
752 * @param &$reader LogReader: where to get our data from
753 * @param $flags Integer: Bitwise combination of flags:
754 * LogEventsList::NO_ACTION_LINK Don't show restore/unblock/block links
755 */
756 function __construct( &$reader, $flags = 0 ) {
757 global $wgUser;
758 wfDeprecated(__METHOD__);
759 $this->reader =& $reader;
760 $this->reader->pager->mLogEventsList->flags = $flags;
761 # Aliases for shorter code...
762 $this->pager =& $this->reader->pager;
763 $this->list =& $this->reader->pager->mLogEventsList;
764 }
765
766 /**
767 * Take over the whole output page in $wgOut with the log display.
768 */
769 public function show() {
770 # Set title and add header
771 $this->list->showHeader( $pager->getType() );
772 # Show form options
773 $this->list->showOptions( $this->pager->getType(), $this->pager->getUser(), $this->pager->getPage(),
774 $this->pager->getPattern(), $this->pager->getYear(), $this->pager->getMonth() );
775 # Insert list
776 $logBody = $this->pager->getBody();
777 if( $logBody ) {
778 $wgOut->addHTML(
779 $this->pager->getNavigationBar() .
780 $this->list->beginLogEventsList() .
781 $logBody .
782 $this->list->endLogEventsList() .
783 $this->pager->getNavigationBar()
784 );
785 } else {
786 $wgOut->addWikiMsg( 'logempty' );
787 }
788 }
789
790 /**
791 * Output just the list of entries given by the linked LogReader,
792 * with extraneous UI elements. Use for displaying log fragments in
793 * another page (eg at Special:Undelete)
794 * @param $out OutputPage: where to send output
795 */
796 public function showList( &$out ) {
797 $logBody = $this->pager->getBody();
798 if( $logBody ) {
799 $out->addHTML(
800 $this->list->beginLogEventsList() .
801 $logBody .
802 $this->list->endLogEventsList()
803 );
804 } else {
805 $out->addWikiMsg( 'logempty' );
806 }
807 }
808 }