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