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