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