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