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