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