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