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