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