Merge "Added MapCacheLRU::getAllKeys() method"
[lhc/web/wiklou.git] / includes / actions / HistoryAction.php
1 <?php
2 /**
3 * Page history
4 *
5 * Split off from Article.php and Skin.php, 2003-12-22
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
21 *
22 * @file
23 * @ingroup Actions
24 */
25
26 /**
27 * This class handles printing the history page for an article. In order to
28 * be efficient, it uses timestamps rather than offsets for paging, to avoid
29 * costly LIMIT,offset queries.
30 *
31 * Construct it by passing in an Article, and call $h->history() to print the
32 * history.
33 *
34 * @ingroup Actions
35 */
36 class HistoryAction extends FormlessAction {
37 const DIR_PREV = 0;
38 const DIR_NEXT = 1;
39
40 /** @var array Array of message keys and strings */
41 public $message;
42
43 public function getName() {
44 return 'history';
45 }
46
47 public function requiresWrite() {
48 return false;
49 }
50
51 public function requiresUnblock() {
52 return false;
53 }
54
55 protected function getPageTitle() {
56 return $this->msg( 'history-title', $this->getTitle()->getPrefixedText() )->text();
57 }
58
59 protected function getDescription() {
60 // Creation of a subtitle link pointing to [[Special:Log]]
61 return Linker::linkKnown(
62 SpecialPage::getTitleFor( 'Log' ),
63 $this->msg( 'viewpagelogs' )->escaped(),
64 array(),
65 array( 'page' => $this->getTitle()->getPrefixedText() )
66 );
67 }
68
69 /**
70 * Get the Article object we are working on.
71 * @return Page
72 */
73 public function getArticle() {
74 return $this->page;
75 }
76
77 /**
78 * As we use the same small set of messages in various methods and that
79 * they are called often, we call them once and save them in $this->message
80 */
81 private function preCacheMessages() {
82 // Precache various messages
83 if ( !isset( $this->message ) ) {
84 $msgs = array( 'cur', 'last', 'pipe-separator' );
85 foreach ( $msgs as $msg ) {
86 $this->message[$msg] = $this->msg( $msg )->escaped();
87 }
88 }
89 }
90
91 /**
92 * Print the history page for an article.
93 */
94 function onView() {
95 $out = $this->getOutput();
96 $request = $this->getRequest();
97
98 /**
99 * Allow client caching.
100 */
101 if ( $out->checkLastModified( $this->page->getTouched() ) ) {
102 return; // Client cache fresh and headers sent, nothing more to do.
103 }
104
105
106 $this->preCacheMessages();
107 $config = $this->context->getConfig();
108
109 # Fill in the file cache if not set already
110 $useFileCache = $config->get( 'UseFileCache' );
111 if ( $useFileCache && HTMLFileCache::useFileCache( $this->getContext() ) ) {
112 $cache = new HTMLFileCache( $this->getTitle(), 'history' );
113 if ( !$cache->isCacheGood( /* Assume up to date */ ) ) {
114 ob_start( array( &$cache, 'saveToFileCache' ) );
115 }
116 }
117
118 // Setup page variables.
119 $out->setFeedAppendQuery( 'action=history' );
120 $out->addModules( 'mediawiki.action.history' );
121 if ( $config->get( 'UseMediaWikiUIEverywhere' ) ) {
122 $out = $this->getOutput();
123 $out->addModuleStyles( array(
124 'mediawiki.ui.input',
125 'mediawiki.ui.checkbox',
126 ) );
127 }
128
129 // Handle atom/RSS feeds.
130 $feedType = $request->getVal( 'feed' );
131 if ( $feedType ) {
132 $this->feed( $feedType );
133
134 return;
135 }
136
137 // Fail nicely if article doesn't exist.
138 if ( !$this->page->exists() ) {
139 $out->addWikiMsg( 'nohistory' );
140 # show deletion/move log if there is an entry
141 LogEventsList::showLogExtract(
142 $out,
143 array( 'delete', 'move' ),
144 $this->getTitle(),
145 '',
146 array( 'lim' => 10,
147 'conds' => array( "log_action != 'revision'" ),
148 'showIfEmpty' => false,
149 'msgKey' => array( 'moveddeleted-notice' )
150 )
151 );
152
153 return;
154 }
155
156 /**
157 * Add date selector to quickly get to a certain time
158 */
159 $year = $request->getInt( 'year' );
160 $month = $request->getInt( 'month' );
161 $tagFilter = $request->getVal( 'tagfilter' );
162 $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter );
163
164 /**
165 * Option to show only revisions that have been (partially) hidden via RevisionDelete
166 */
167 if ( $request->getBool( 'deleted' ) ) {
168 $conds = array( 'rev_deleted != 0' );
169 } else {
170 $conds = array();
171 }
172 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
173 $checkDeleted = Xml::checkLabel( $this->msg( 'history-show-deleted' )->text(),
174 'deleted', 'mw-show-deleted-only', $request->getBool( 'deleted' ) ) . "\n";
175 } else {
176 $checkDeleted = '';
177 }
178
179 // Add the general form
180 $action = htmlspecialchars( wfScript() );
181 $out->addHTML(
182 "<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" .
183 Xml::fieldset(
184 $this->msg( 'history-fieldset-title' )->text(),
185 false,
186 array( 'id' => 'mw-history-search' )
187 ) .
188 Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n" .
189 Html::hidden( 'action', 'history' ) . "\n" .
190 Xml::dateMenu(
191 ( $year == null ? MWTimestamp::getLocalInstance()->format( 'Y' ) : $year ),
192 $month
193 ) . '&#160;' .
194 ( $tagSelector ? ( implode( '&#160;', $tagSelector ) . '&#160;' ) : '' ) .
195 $checkDeleted .
196 Html::submitButton(
197 $this->msg( 'allpagessubmit' )->text(),
198 array(),
199 array( 'mw-ui-progressive' )
200 ) . "\n" .
201 '</fieldset></form>'
202 );
203
204 Hooks::run( 'PageHistoryBeforeList', array( &$this->page, $this->getContext() ) );
205
206 // Create and output the list.
207 $pager = new HistoryPager( $this, $year, $month, $tagFilter, $conds );
208 $out->addHTML(
209 $pager->getNavigationBar() .
210 $pager->getBody() .
211 $pager->getNavigationBar()
212 );
213 $out->preventClickjacking( $pager->getPreventClickjacking() );
214
215 }
216
217 /**
218 * Fetch an array of revisions, specified by a given limit, offset and
219 * direction. This is now only used by the feeds. It was previously
220 * used by the main UI but that's now handled by the pager.
221 *
222 * @param int $limit The limit number of revisions to get
223 * @param int $offset
224 * @param int $direction Either self::DIR_PREV or self::DIR_NEXT
225 * @return ResultWrapper
226 */
227 function fetchRevisions( $limit, $offset, $direction ) {
228 // Fail if article doesn't exist.
229 if ( !$this->getTitle()->exists() ) {
230 return new FakeResultWrapper( array() );
231 }
232
233 $dbr = wfGetDB( DB_SLAVE );
234
235 if ( $direction === self::DIR_PREV ) {
236 list( $dirs, $oper ) = array( "ASC", ">=" );
237 } else { /* $direction === self::DIR_NEXT */
238 list( $dirs, $oper ) = array( "DESC", "<=" );
239 }
240
241 if ( $offset ) {
242 $offsets = array( "rev_timestamp $oper " . $dbr->addQuotes( $dbr->timestamp( $offset ) ) );
243 } else {
244 $offsets = array();
245 }
246
247 $page_id = $this->page->getId();
248
249 return $dbr->select( 'revision',
250 Revision::selectFields(),
251 array_merge( array( 'rev_page' => $page_id ), $offsets ),
252 __METHOD__,
253 array( 'ORDER BY' => "rev_timestamp $dirs",
254 'USE INDEX' => 'page_timestamp', 'LIMIT' => $limit )
255 );
256 }
257
258 /**
259 * Output a subscription feed listing recent edits to this page.
260 *
261 * @param string $type Feed type
262 */
263 function feed( $type ) {
264 if ( !FeedUtils::checkFeedOutput( $type ) ) {
265 return;
266 }
267 $request = $this->getRequest();
268
269 $feedClasses = $this->context->getConfig()->get( 'FeedClasses' );
270 /** @var RSSFeed|AtomFeed $feed */
271 $feed = new $feedClasses[$type](
272 $this->getTitle()->getPrefixedText() . ' - ' .
273 $this->msg( 'history-feed-title' )->inContentLanguage()->text(),
274 $this->msg( 'history-feed-description' )->inContentLanguage()->text(),
275 $this->getTitle()->getFullURL( 'action=history' )
276 );
277
278 // Get a limit on number of feed entries. Provide a sane default
279 // of 10 if none is defined (but limit to $wgFeedLimit max)
280 $limit = $request->getInt( 'limit', 10 );
281 $limit = min(
282 max( $limit, 1 ),
283 $this->context->getConfig()->get( 'FeedLimit' )
284 );
285
286 $items = $this->fetchRevisions( $limit, 0, self::DIR_NEXT );
287
288 // Generate feed elements enclosed between header and footer.
289 $feed->outHeader();
290 if ( $items->numRows() ) {
291 foreach ( $items as $row ) {
292 $feed->outItem( $this->feedItem( $row ) );
293 }
294 } else {
295 $feed->outItem( $this->feedEmpty() );
296 }
297 $feed->outFooter();
298 }
299
300 function feedEmpty() {
301 return new FeedItem(
302 $this->msg( 'nohistory' )->inContentLanguage()->text(),
303 $this->msg( 'history-feed-empty' )->inContentLanguage()->parseAsBlock(),
304 $this->getTitle()->getFullURL(),
305 wfTimestamp( TS_MW ),
306 '',
307 $this->getTitle()->getTalkPage()->getFullURL()
308 );
309 }
310
311 /**
312 * Generate a FeedItem object from a given revision table row
313 * Borrows Recent Changes' feed generation functions for formatting;
314 * includes a diff to the previous revision (if any).
315 *
316 * @param stdClass|array $row Database row
317 * @return FeedItem
318 */
319 function feedItem( $row ) {
320 $rev = new Revision( $row );
321 $rev->setTitle( $this->getTitle() );
322 $text = FeedUtils::formatDiffRow(
323 $this->getTitle(),
324 $this->getTitle()->getPreviousRevisionID( $rev->getId() ),
325 $rev->getId(),
326 $rev->getTimestamp(),
327 $rev->getComment()
328 );
329 if ( $rev->getComment() == '' ) {
330 global $wgContLang;
331 $title = $this->msg( 'history-feed-item-nocomment',
332 $rev->getUserText(),
333 $wgContLang->timeanddate( $rev->getTimestamp() ),
334 $wgContLang->date( $rev->getTimestamp() ),
335 $wgContLang->time( $rev->getTimestamp() ) )->inContentLanguage()->text();
336 } else {
337 $title = $rev->getUserText() .
338 $this->msg( 'colon-separator' )->inContentLanguage()->text() .
339 FeedItem::stripComment( $rev->getComment() );
340 }
341
342 return new FeedItem(
343 $title,
344 $text,
345 $this->getTitle()->getFullURL( 'diff=' . $rev->getId() . '&oldid=prev' ),
346 $rev->getTimestamp(),
347 $rev->getUserText(),
348 $this->getTitle()->getTalkPage()->getFullURL()
349 );
350 }
351 }
352
353 /**
354 * @ingroup Pager
355 * @ingroup Actions
356 */
357 class HistoryPager extends ReverseChronologicalPager {
358 /**
359 * @var bool|stdClass
360 */
361 public $lastRow = false;
362
363 public $counter, $historyPage, $buttons, $conds;
364
365 protected $oldIdChecked;
366
367 protected $preventClickjacking = false;
368 /**
369 * @var array
370 */
371 protected $parentLens;
372
373 /**
374 * @param HistoryAction $historyPage
375 * @param string $year
376 * @param string $month
377 * @param string $tagFilter
378 * @param array $conds
379 */
380 function __construct( $historyPage, $year = '', $month = '', $tagFilter = '', $conds = array() ) {
381 parent::__construct( $historyPage->getContext() );
382 $this->historyPage = $historyPage;
383 $this->tagFilter = $tagFilter;
384 $this->getDateCond( $year, $month );
385 $this->conds = $conds;
386 }
387
388 // For hook compatibility...
389 function getArticle() {
390 return $this->historyPage->getArticle();
391 }
392
393 function getSqlComment() {
394 if ( $this->conds ) {
395 return 'history page filtered'; // potentially slow, see CR r58153
396 } else {
397 return 'history page unfiltered';
398 }
399 }
400
401 function getQueryInfo() {
402 $queryInfo = array(
403 'tables' => array( 'revision', 'user' ),
404 'fields' => array_merge( Revision::selectFields(), Revision::selectUserFields() ),
405 'conds' => array_merge(
406 array( 'rev_page' => $this->getWikiPage()->getId() ),
407 $this->conds ),
408 'options' => array( 'USE INDEX' => array( 'revision' => 'page_timestamp' ) ),
409 'join_conds' => array( 'user' => Revision::userJoinCond() ),
410 );
411 ChangeTags::modifyDisplayQuery(
412 $queryInfo['tables'],
413 $queryInfo['fields'],
414 $queryInfo['conds'],
415 $queryInfo['join_conds'],
416 $queryInfo['options'],
417 $this->tagFilter
418 );
419 Hooks::run( 'PageHistoryPager::getQueryInfo', array( &$this, &$queryInfo ) );
420
421 return $queryInfo;
422 }
423
424 function getIndexField() {
425 return 'rev_timestamp';
426 }
427
428 /**
429 * @param stdClass $row
430 * @return string
431 */
432 function formatRow( $row ) {
433 if ( $this->lastRow ) {
434 $latest = ( $this->counter == 1 && $this->mIsFirst );
435 $firstInList = $this->counter == 1;
436 $this->counter++;
437 $s = $this->historyLine( $this->lastRow, $row,
438 $this->getTitle()->getNotificationTimestamp( $this->getUser() ), $latest, $firstInList );
439 } else {
440 $s = '';
441 }
442 $this->lastRow = $row;
443
444 return $s;
445 }
446
447 function doBatchLookups() {
448 # Do a link batch query
449 $this->mResult->seek( 0 );
450 $batch = new LinkBatch();
451 $revIds = array();
452 foreach ( $this->mResult as $row ) {
453 if ( $row->rev_parent_id ) {
454 $revIds[] = $row->rev_parent_id;
455 }
456 if ( !is_null( $row->user_name ) ) {
457 $batch->add( NS_USER, $row->user_name );
458 $batch->add( NS_USER_TALK, $row->user_name );
459 } else { # for anons or usernames of imported revisions
460 $batch->add( NS_USER, $row->rev_user_text );
461 $batch->add( NS_USER_TALK, $row->rev_user_text );
462 }
463 }
464 $this->parentLens = Revision::getParentLengths( $this->mDb, $revIds );
465 $batch->execute();
466 $this->mResult->seek( 0 );
467 }
468
469 /**
470 * Creates begin of history list with a submit button
471 *
472 * @return string HTML output
473 */
474 function getStartBody() {
475 $this->lastRow = false;
476 $this->counter = 1;
477 $this->oldIdChecked = 0;
478
479 $this->getOutput()->wrapWikiMsg( "<div class='mw-history-legend'>\n$1\n</div>", 'histlegend' );
480 $s = Html::openElement( 'form', array( 'action' => wfScript(),
481 'id' => 'mw-history-compare' ) ) . "\n";
482 $s .= Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n";
483 $s .= Html::hidden( 'action', 'historysubmit' ) . "\n";
484
485 // Button container stored in $this->buttons for re-use in getEndBody()
486 $this->buttons = '<div>';
487 $className = 'historysubmit mw-history-compareselectedversions-button';
488 $attrs = array( 'class' => $className )
489 + Linker::tooltipAndAccesskeyAttribs( 'compareselectedversions' );
490 $this->buttons .= $this->submitButton( $this->msg( 'compareselectedversions' )->text(),
491 $attrs
492 ) . "\n";
493
494 if ( $this->getUser()->isAllowed( 'deleterevision' ) ) {
495 $this->buttons .= $this->getRevisionButton( 'revisiondelete', 'showhideselectedversions' );
496 }
497 $this->buttons .= '</div>';
498
499 $s .= $this->buttons;
500 $s .= '<ul id="pagehistory">' . "\n";
501
502 return $s;
503 }
504
505 private function getRevisionButton( $name, $msg ) {
506 $this->preventClickjacking();
507 # Note bug #20966, <button> is non-standard in IE<8
508 $element = Html::element(
509 'button',
510 array(
511 'type' => 'submit',
512 'name' => $name,
513 'value' => '1',
514 'class' => "historysubmit mw-history-$name-button",
515 ),
516 $this->msg( $msg )->text()
517 ) . "\n";
518 return $element;
519 }
520
521 function getEndBody() {
522 if ( $this->lastRow ) {
523 $latest = $this->counter == 1 && $this->mIsFirst;
524 $firstInList = $this->counter == 1;
525 if ( $this->mIsBackwards ) {
526 # Next row is unknown, but for UI reasons, probably exists if an offset has been specified
527 if ( $this->mOffset == '' ) {
528 $next = null;
529 } else {
530 $next = 'unknown';
531 }
532 } else {
533 # The next row is the past-the-end row
534 $next = $this->mPastTheEndRow;
535 }
536 $this->counter++;
537 $s = $this->historyLine( $this->lastRow, $next,
538 $this->getTitle()->getNotificationTimestamp( $this->getUser() ), $latest, $firstInList );
539 } else {
540 $s = '';
541 }
542 $s .= "</ul>\n";
543 # Add second buttons only if there is more than one rev
544 if ( $this->getNumRows() > 2 ) {
545 $s .= $this->buttons;
546 }
547 $s .= '</form>';
548
549 return $s;
550 }
551
552 /**
553 * Creates a submit button
554 *
555 * @param string $message Text of the submit button, will be escaped
556 * @param array $attributes Attributes
557 * @return string HTML output for the submit button
558 */
559 function submitButton( $message, $attributes = array() ) {
560 # Disable submit button if history has 1 revision only
561 if ( $this->getNumRows() > 1 ) {
562 return Html::submitButton( $message, $attributes );
563 } else {
564 return '';
565 }
566 }
567
568 /**
569 * Returns a row from the history printout.
570 *
571 * @todo document some more, and maybe clean up the code (some params redundant?)
572 *
573 * @param stdClass $row The database row corresponding to the previous line.
574 * @param mixed $next The database row corresponding to the next line
575 * (chronologically previous)
576 * @param bool|string $notificationtimestamp
577 * @param bool $latest Whether this row corresponds to the page's latest revision.
578 * @param bool $firstInList Whether this row corresponds to the first
579 * displayed on this history page.
580 * @return string HTML output for the row
581 */
582 function historyLine( $row, $next, $notificationtimestamp = false,
583 $latest = false, $firstInList = false ) {
584 $rev = new Revision( $row );
585 $rev->setTitle( $this->getTitle() );
586
587 if ( is_object( $next ) ) {
588 $prevRev = new Revision( $next );
589 $prevRev->setTitle( $this->getTitle() );
590 } else {
591 $prevRev = null;
592 }
593
594 $curlink = $this->curLink( $rev, $latest );
595 $lastlink = $this->lastLink( $rev, $next );
596 $curLastlinks = $curlink . $this->historyPage->message['pipe-separator'] . $lastlink;
597 $histLinks = Html::rawElement(
598 'span',
599 array( 'class' => 'mw-history-histlinks' ),
600 $this->msg( 'parentheses' )->rawParams( $curLastlinks )->escaped()
601 );
602
603 $diffButtons = $this->diffButtons( $rev, $firstInList );
604 $s = $histLinks . $diffButtons;
605
606 $link = $this->revLink( $rev );
607 $classes = array();
608
609 $del = '';
610 $user = $this->getUser();
611 // Show checkboxes for each revision
612 if ( $user->isAllowed( 'deleterevision' ) ) {
613 $this->preventClickjacking();
614 // If revision was hidden from sysops, disable the checkbox
615 if ( !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
616 $del = Xml::check( 'deleterevisions', false, array( 'disabled' => 'disabled' ) );
617 // Otherwise, enable the checkbox...
618 } else {
619 $del = Xml::check( 'showhiderevisions', false,
620 array( 'name' => 'ids[' . $rev->getId() . ']' ) );
621 }
622 // User can only view deleted revisions...
623 } elseif ( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) {
624 // If revision was hidden from sysops, disable the link
625 if ( !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
626 $del = Linker::revDeleteLinkDisabled( false );
627 // Otherwise, show the link...
628 } else {
629 $query = array( 'type' => 'revision',
630 'target' => $this->getTitle()->getPrefixedDBkey(), 'ids' => $rev->getId() );
631 $del .= Linker::revDeleteLink( $query,
632 $rev->isDeleted( Revision::DELETED_RESTRICTED ), false );
633 }
634 }
635 if ( $del ) {
636 $s .= " $del ";
637 }
638
639 $lang = $this->getLanguage();
640 $dirmark = $lang->getDirMark();
641
642 $s .= " $link";
643 $s .= $dirmark;
644 $s .= " <span class='history-user'>" .
645 Linker::revUserTools( $rev, true ) . "</span>";
646 $s .= $dirmark;
647
648 if ( $rev->isMinor() ) {
649 $s .= ' ' . ChangesList::flag( 'minor' );
650 }
651
652 # Sometimes rev_len isn't populated
653 if ( $rev->getSize() !== null ) {
654 # Size is always public data
655 $prevSize = isset( $this->parentLens[$row->rev_parent_id] )
656 ? $this->parentLens[$row->rev_parent_id]
657 : 0;
658 $sDiff = ChangesList::showCharacterDifference( $prevSize, $rev->getSize() );
659 $fSize = Linker::formatRevisionSize( $rev->getSize() );
660 $s .= ' <span class="mw-changeslist-separator">. .</span> ' . "$fSize $sDiff";
661 }
662
663 # Text following the character difference is added just before running hooks
664 $s2 = Linker::revComment( $rev, false, true );
665
666 if ( $notificationtimestamp && ( $row->rev_timestamp >= $notificationtimestamp ) ) {
667 $s2 .= ' <span class="updatedmarker">' . $this->msg( 'updatedmarker' )->escaped() . '</span>';
668 $classes[] = 'mw-history-line-updated';
669 }
670
671 $tools = array();
672
673 # Rollback and undo links
674 if ( $prevRev && $this->getTitle()->quickUserCan( 'edit', $user ) ) {
675 if ( $latest && $this->getTitle()->quickUserCan( 'rollback', $user ) ) {
676 // Get a rollback link without the brackets
677 $rollbackLink = Linker::generateRollback(
678 $rev,
679 $this->getContext(),
680 array( 'verify', 'noBrackets' )
681 );
682 if ( $rollbackLink ) {
683 $this->preventClickjacking();
684 $tools[] = $rollbackLink;
685 }
686 }
687
688 if ( !$rev->isDeleted( Revision::DELETED_TEXT )
689 && !$prevRev->isDeleted( Revision::DELETED_TEXT )
690 ) {
691 # Create undo tooltip for the first (=latest) line only
692 $undoTooltip = $latest
693 ? array( 'title' => $this->msg( 'tooltip-undo' )->text() )
694 : array();
695 $undolink = Linker::linkKnown(
696 $this->getTitle(),
697 $this->msg( 'editundo' )->escaped(),
698 $undoTooltip,
699 array(
700 'action' => 'edit',
701 'undoafter' => $prevRev->getId(),
702 'undo' => $rev->getId()
703 )
704 );
705 $tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>";
706 }
707 }
708 // Allow extension to add their own links here
709 Hooks::run( 'HistoryRevisionTools', array( $rev, &$tools ) );
710
711 if ( $tools ) {
712 $s2 .= ' ' . $this->msg( 'parentheses' )->rawParams( $lang->pipeList( $tools ) )->escaped();
713 }
714
715 # Tags
716 list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow( $row->ts_tags, 'history' );
717 $classes = array_merge( $classes, $newClasses );
718 if ( $tagSummary !== '' ) {
719 $s2 .= " $tagSummary";
720 }
721
722 # Include separator between character difference and following text
723 if ( $s2 !== '' ) {
724 $s .= ' <span class="mw-changeslist-separator">. .</span> ' . $s2;
725 }
726
727 Hooks::run( 'PageHistoryLineEnding', array( $this, &$row, &$s, &$classes ) );
728
729 $attribs = array();
730 if ( $classes ) {
731 $attribs['class'] = implode( ' ', $classes );
732 }
733
734 return Xml::tags( 'li', $attribs, $s ) . "\n";
735 }
736
737 /**
738 * Create a link to view this revision of the page
739 *
740 * @param Revision $rev
741 * @return string
742 */
743 function revLink( $rev ) {
744 $date = $this->getLanguage()->userTimeAndDate( $rev->getTimestamp(), $this->getUser() );
745 $date = htmlspecialchars( $date );
746 if ( $rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
747 $link = Linker::linkKnown(
748 $this->getTitle(),
749 $date,
750 array( 'class' => 'mw-changeslist-date' ),
751 array( 'oldid' => $rev->getId() )
752 );
753 } else {
754 $link = $date;
755 }
756 if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
757 $link = "<span class=\"history-deleted\">$link</span>";
758 }
759
760 return $link;
761 }
762
763 /**
764 * Create a diff-to-current link for this revision for this page
765 *
766 * @param Revision $rev
767 * @param bool $latest This is the latest revision of the page?
768 * @return string
769 */
770 function curLink( $rev, $latest ) {
771 $cur = $this->historyPage->message['cur'];
772 if ( $latest || !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
773 return $cur;
774 } else {
775 return Linker::linkKnown(
776 $this->getTitle(),
777 $cur,
778 array(),
779 array(
780 'diff' => $this->getWikiPage()->getLatest(),
781 'oldid' => $rev->getId()
782 )
783 );
784 }
785 }
786
787 /**
788 * Create a diff-to-previous link for this revision for this page.
789 *
790 * @param Revision $prevRev The revision being displayed
791 * @param stdClass|string|null $next The next revision in list (that is
792 * the previous one in chronological order).
793 * May either be a row, "unknown" or null.
794 * @return string
795 */
796 function lastLink( $prevRev, $next ) {
797 $last = $this->historyPage->message['last'];
798
799 if ( $next === null ) {
800 # Probably no next row
801 return $last;
802 }
803
804 if ( $next === 'unknown' ) {
805 # Next row probably exists but is unknown, use an oldid=prev link
806 return Linker::linkKnown(
807 $this->getTitle(),
808 $last,
809 array(),
810 array(
811 'diff' => $prevRev->getId(),
812 'oldid' => 'prev'
813 )
814 );
815 }
816
817 $nextRev = new Revision( $next );
818
819 if ( !$prevRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
820 || !$nextRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
821 ) {
822 return $last;
823 }
824
825 return Linker::linkKnown(
826 $this->getTitle(),
827 $last,
828 array(),
829 array(
830 'diff' => $prevRev->getId(),
831 'oldid' => $next->rev_id
832 )
833 );
834 }
835
836 /**
837 * Create radio buttons for page history
838 *
839 * @param Revision $rev
840 * @param bool $firstInList Is this version the first one?
841 *
842 * @return string HTML output for the radio buttons
843 */
844 function diffButtons( $rev, $firstInList ) {
845 if ( $this->getNumRows() > 1 ) {
846 $id = $rev->getId();
847 $radio = array( 'type' => 'radio', 'value' => $id );
848 /** @todo Move title texts to javascript */
849 if ( $firstInList ) {
850 $first = Xml::element( 'input',
851 array_merge( $radio, array(
852 'style' => 'visibility:hidden',
853 'name' => 'oldid',
854 'id' => 'mw-oldid-null' ) )
855 );
856 $checkmark = array( 'checked' => 'checked' );
857 } else {
858 # Check visibility of old revisions
859 if ( !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
860 $radio['disabled'] = 'disabled';
861 $checkmark = array(); // We will check the next possible one
862 } elseif ( !$this->oldIdChecked ) {
863 $checkmark = array( 'checked' => 'checked' );
864 $this->oldIdChecked = $id;
865 } else {
866 $checkmark = array();
867 }
868 $first = Xml::element( 'input',
869 array_merge( $radio, $checkmark, array(
870 'name' => 'oldid',
871 'id' => "mw-oldid-$id" ) ) );
872 $checkmark = array();
873 }
874 $second = Xml::element( 'input',
875 array_merge( $radio, $checkmark, array(
876 'name' => 'diff',
877 'id' => "mw-diff-$id" ) ) );
878
879 return $first . $second;
880 } else {
881 return '';
882 }
883 }
884
885 /**
886 * This is called if a write operation is possible from the generated HTML
887 * @param bool $enable
888 */
889 function preventClickjacking( $enable = true ) {
890 $this->preventClickjacking = $enable;
891 }
892
893 /**
894 * Get the "prevent clickjacking" flag
895 * @return bool
896 */
897 function getPreventClickjacking() {
898 return $this->preventClickjacking;
899 }
900 }