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