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