Merge "Typo fix"
[mediawiki.git] / includes / actions / HistoryAction.php
blob6a1edd6a84209169c5839bdbdb769410c5b430fa
1 <?php
2 /**
3 * Page history
5 * Split off from Article.php and Skin.php, 2003-12-22
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.
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.
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
22 * @file
23 * @ingroup Actions
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.
31 * Construct it by passing in an Article, and call $h->history() to print the
32 * history.
34 * @ingroup Actions
36 class HistoryAction extends FormlessAction {
37 const DIR_PREV = 0;
38 const DIR_NEXT = 1;
40 public function getName() {
41 return 'history';
44 public function requiresWrite() {
45 return false;
48 public function requiresUnblock() {
49 return false;
52 protected function getPageTitle() {
53 return $this->msg( 'history-title', $this->getTitle()->getPrefixedText() )->text();
56 protected function getDescription() {
57 // Creation of a subtitle link pointing to [[Special:Log]]
58 return Linker::linkKnown(
59 SpecialPage::getTitleFor( 'Log' ),
60 $this->msg( 'viewpagelogs' )->escaped(),
61 array(),
62 array( 'page' => $this->getTitle()->getPrefixedText() )
66 /**
67 * Get the Article object we are working on.
68 * @return Page
70 public function getArticle() {
71 return $this->page;
74 /**
75 * As we use the same small set of messages in various methods and that
76 * they are called often, we call them once and save them in $this->message
78 private function preCacheMessages() {
79 // Precache various messages
80 if ( !isset( $this->message ) ) {
81 $msgs = array( 'cur', 'last', 'pipe-separator' );
82 foreach ( $msgs as $msg ) {
83 $this->message[$msg] = $this->msg( $msg )->escaped();
88 /**
89 * Print the history page for an article.
91 function onView() {
92 global $wgScript, $wgUseFileCache;
94 $out = $this->getOutput();
95 $request = $this->getRequest();
97 /**
98 * Allow client caching.
100 if ( $out->checkLastModified( $this->page->getTouched() ) ) {
101 return; // Client cache fresh and headers sent, nothing more to do.
104 wfProfileIn( __METHOD__ );
106 $this->preCacheMessages();
108 # Fill in the file cache if not set already
109 if ( $wgUseFileCache && HTMLFileCache::useFileCache( $this->getContext() ) ) {
110 $cache = HTMLFileCache::newFromTitle( $this->getTitle(), 'history' );
111 if ( !$cache->isCacheGood( /* Assume up to date */ ) ) {
112 ob_start( array( &$cache, 'saveToFileCache' ) );
116 // Setup page variables.
117 $out->setFeedAppendQuery( 'action=history' );
118 $out->addModules( array( 'mediawiki.legacy.history', 'mediawiki.action.history' ) );
120 // Handle atom/RSS feeds.
121 $feedType = $request->getVal( 'feed' );
122 if ( $feedType ) {
123 $this->feed( $feedType );
124 wfProfileOut( __METHOD__ );
125 return;
128 // Fail nicely if article doesn't exist.
129 if ( !$this->page->exists() ) {
130 $out->addWikiMsg( 'nohistory' );
131 # show deletion/move log if there is an entry
132 LogEventsList::showLogExtract(
133 $out,
134 array( 'delete', 'move' ),
135 $this->getTitle(),
137 array( 'lim' => 10,
138 'conds' => array( "log_action != 'revision'" ),
139 'showIfEmpty' => false,
140 'msgKey' => array( 'moveddeleted-notice' )
143 wfProfileOut( __METHOD__ );
144 return;
148 * Add date selector to quickly get to a certain time
150 $year = $request->getInt( 'year' );
151 $month = $request->getInt( 'month' );
152 $tagFilter = $request->getVal( 'tagfilter' );
153 $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter );
156 * Option to show only revisions that have been (partially) hidden via RevisionDelete
158 if ( $request->getBool( 'deleted' ) ) {
159 $conds = array( 'rev_deleted != 0' );
160 } else {
161 $conds = array();
163 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
164 $checkDeleted = Xml::checkLabel( $this->msg( 'history-show-deleted' )->text(),
165 'deleted', 'mw-show-deleted-only', $request->getBool( 'deleted' ) ) . "\n";
166 } else {
167 $checkDeleted = '';
170 // Add the general form
171 $action = htmlspecialchars( $wgScript );
172 $out->addHTML(
173 "<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" .
174 Xml::fieldset(
175 $this->msg( 'history-fieldset-title' )->text(),
176 false,
177 array( 'id' => 'mw-history-search' )
179 Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n" .
180 Html::hidden( 'action', 'history' ) . "\n" .
181 Xml::dateMenu( ( $year == null ? MWTimestamp::getLocalInstance()->format( 'Y' ) : $year ), $month ) . '&#160;' .
182 ( $tagSelector ? ( implode( '&#160;', $tagSelector ) . '&#160;' ) : '' ) .
183 $checkDeleted .
184 Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
185 '</fieldset></form>'
188 wfRunHooks( 'PageHistoryBeforeList', array( &$this->page, $this->getContext() ) );
190 // Create and output the list.
191 $pager = new HistoryPager( $this, $year, $month, $tagFilter, $conds );
192 $out->addHTML(
193 $pager->getNavigationBar() .
194 $pager->getBody() .
195 $pager->getNavigationBar()
197 $out->preventClickjacking( $pager->getPreventClickjacking() );
199 wfProfileOut( __METHOD__ );
203 * Fetch an array of revisions, specified by a given limit, offset and
204 * direction. This is now only used by the feeds. It was previously
205 * used by the main UI but that's now handled by the pager.
207 * @param $limit Integer: the limit number of revisions to get
208 * @param $offset Integer
209 * @param $direction Integer: either HistoryPage::DIR_PREV or HistoryPage::DIR_NEXT
210 * @return ResultWrapper
212 function fetchRevisions( $limit, $offset, $direction ) {
213 // Fail if article doesn't exist.
214 if ( !$this->getTitle()->exists() ) {
215 return new FakeResultWrapper( array() );
218 $dbr = wfGetDB( DB_SLAVE );
220 if ( $direction == HistoryPage::DIR_PREV ) {
221 list( $dirs, $oper ) = array( "ASC", ">=" );
222 } else { /* $direction == HistoryPage::DIR_NEXT */
223 list( $dirs, $oper ) = array( "DESC", "<=" );
226 if ( $offset ) {
227 $offsets = array( "rev_timestamp $oper " . $dbr->addQuotes( $dbr->timestamp( $offset ) ) );
228 } else {
229 $offsets = array();
232 $page_id = $this->page->getId();
234 return $dbr->select( 'revision',
235 Revision::selectFields(),
236 array_merge( array( 'rev_page' => $page_id ), $offsets ),
237 __METHOD__,
238 array( 'ORDER BY' => "rev_timestamp $dirs",
239 'USE INDEX' => 'page_timestamp', 'LIMIT' => $limit )
244 * Output a subscription feed listing recent edits to this page.
246 * @param string $type feed type
248 function feed( $type ) {
249 global $wgFeedClasses, $wgFeedLimit;
250 if ( !FeedUtils::checkFeedOutput( $type ) ) {
251 return;
253 $request = $this->getRequest();
255 $feed = new $wgFeedClasses[$type](
256 $this->getTitle()->getPrefixedText() . ' - ' .
257 $this->msg( 'history-feed-title' )->inContentLanguage()->text(),
258 $this->msg( 'history-feed-description' )->inContentLanguage()->text(),
259 $this->getTitle()->getFullURL( 'action=history' )
262 // Get a limit on number of feed entries. Provide a sane default
263 // of 10 if none is defined (but limit to $wgFeedLimit max)
264 $limit = $request->getInt( 'limit', 10 );
265 $limit = min( max( $limit, 1 ), $wgFeedLimit );
267 $items = $this->fetchRevisions( $limit, 0, HistoryPage::DIR_NEXT );
269 // Generate feed elements enclosed between header and footer.
270 $feed->outHeader();
271 if ( $items->numRows() ) {
272 foreach ( $items as $row ) {
273 $feed->outItem( $this->feedItem( $row ) );
275 } else {
276 $feed->outItem( $this->feedEmpty() );
278 $feed->outFooter();
281 function feedEmpty() {
282 return new FeedItem(
283 $this->msg( 'nohistory' )->inContentLanguage()->text(),
284 $this->msg( 'history-feed-empty' )->inContentLanguage()->parseAsBlock(),
285 $this->getTitle()->getFullURL(),
286 wfTimestamp( TS_MW ),
288 $this->getTitle()->getTalkPage()->getFullURL()
293 * Generate a FeedItem object from a given revision table row
294 * Borrows Recent Changes' feed generation functions for formatting;
295 * includes a diff to the previous revision (if any).
297 * @param $row Object: database row
298 * @return FeedItem
300 function feedItem( $row ) {
301 $rev = new Revision( $row );
302 $rev->setTitle( $this->getTitle() );
303 $text = FeedUtils::formatDiffRow(
304 $this->getTitle(),
305 $this->getTitle()->getPreviousRevisionID( $rev->getId() ),
306 $rev->getId(),
307 $rev->getTimestamp(),
308 $rev->getComment()
310 if ( $rev->getComment() == '' ) {
311 global $wgContLang;
312 $title = $this->msg( 'history-feed-item-nocomment',
313 $rev->getUserText(),
314 $wgContLang->timeanddate( $rev->getTimestamp() ),
315 $wgContLang->date( $rev->getTimestamp() ),
316 $wgContLang->time( $rev->getTimestamp() ) )->inContentLanguage()->text();
317 } else {
318 $title = $rev->getUserText() .
319 $this->msg( 'colon-separator' )->inContentLanguage()->text() .
320 FeedItem::stripComment( $rev->getComment() );
322 return new FeedItem(
323 $title,
324 $text,
325 $this->getTitle()->getFullURL( 'diff=' . $rev->getId() . '&oldid=prev' ),
326 $rev->getTimestamp(),
327 $rev->getUserText(),
328 $this->getTitle()->getTalkPage()->getFullURL()
334 * @ingroup Pager
335 * @ingroup Actions
337 class HistoryPager extends ReverseChronologicalPager {
338 public $lastRow = false, $counter, $historyPage, $buttons, $conds;
339 protected $oldIdChecked;
340 protected $preventClickjacking = false;
342 * @var array
344 protected $parentLens;
346 function __construct( $historyPage, $year = '', $month = '', $tagFilter = '', $conds = array() ) {
347 parent::__construct( $historyPage->getContext() );
348 $this->historyPage = $historyPage;
349 $this->tagFilter = $tagFilter;
350 $this->getDateCond( $year, $month );
351 $this->conds = $conds;
354 // For hook compatibility...
355 function getArticle() {
356 return $this->historyPage->getArticle();
359 function getSqlComment() {
360 if ( $this->conds ) {
361 return 'history page filtered'; // potentially slow, see CR r58153
362 } else {
363 return 'history page unfiltered';
367 function getQueryInfo() {
368 $queryInfo = array(
369 'tables' => array( 'revision', 'user' ),
370 'fields' => array_merge( Revision::selectFields(), Revision::selectUserFields() ),
371 'conds' => array_merge(
372 array( 'rev_page' => $this->getWikiPage()->getId() ),
373 $this->conds ),
374 'options' => array( 'USE INDEX' => array( 'revision' => 'page_timestamp' ) ),
375 'join_conds' => array( 'user' => Revision::userJoinCond() ),
377 ChangeTags::modifyDisplayQuery(
378 $queryInfo['tables'],
379 $queryInfo['fields'],
380 $queryInfo['conds'],
381 $queryInfo['join_conds'],
382 $queryInfo['options'],
383 $this->tagFilter
385 wfRunHooks( 'PageHistoryPager::getQueryInfo', array( &$this, &$queryInfo ) );
386 return $queryInfo;
389 function getIndexField() {
390 return 'rev_timestamp';
393 function formatRow( $row ) {
394 if ( $this->lastRow ) {
395 $latest = ( $this->counter == 1 && $this->mIsFirst );
396 $firstInList = $this->counter == 1;
397 $this->counter++;
398 $s = $this->historyLine( $this->lastRow, $row,
399 $this->getTitle()->getNotificationTimestamp( $this->getUser() ), $latest, $firstInList );
400 } else {
401 $s = '';
403 $this->lastRow = $row;
404 return $s;
407 function doBatchLookups() {
408 # Do a link batch query
409 $this->mResult->seek( 0 );
410 $batch = new LinkBatch();
411 $revIds = array();
412 foreach ( $this->mResult as $row ) {
413 if ( $row->rev_parent_id ) {
414 $revIds[] = $row->rev_parent_id;
416 if ( !is_null( $row->user_name ) ) {
417 $batch->add( NS_USER, $row->user_name );
418 $batch->add( NS_USER_TALK, $row->user_name );
419 } else { # for anons or usernames of imported revisions
420 $batch->add( NS_USER, $row->rev_user_text );
421 $batch->add( NS_USER_TALK, $row->rev_user_text );
424 $this->parentLens = Revision::getParentLengths( $this->mDb, $revIds );
425 $batch->execute();
426 $this->mResult->seek( 0 );
430 * Creates begin of history list with a submit button
432 * @return string HTML output
434 function getStartBody() {
435 global $wgScript;
436 $this->lastRow = false;
437 $this->counter = 1;
438 $this->oldIdChecked = 0;
440 $this->getOutput()->wrapWikiMsg( "<div class='mw-history-legend'>\n$1\n</div>", 'histlegend' );
441 $s = Html::openElement( 'form', array( 'action' => $wgScript,
442 'id' => 'mw-history-compare' ) ) . "\n";
443 $s .= Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n";
444 $s .= Html::hidden( 'action', 'historysubmit' ) . "\n";
446 // Button container stored in $this->buttons for re-use in getEndBody()
447 $this->buttons = '<div>';
448 $this->buttons .= $this->submitButton( $this->msg( 'compareselectedversions' )->text(),
449 array( 'class' => 'historysubmit mw-history-compareselectedversions-button' )
450 + Linker::tooltipAndAccesskeyAttribs( 'compareselectedversions' )
451 ) . "\n";
453 if ( $this->getUser()->isAllowed( 'deleterevision' ) ) {
454 $this->buttons .= $this->getRevisionButton( 'revisiondelete', 'showhideselectedversions' );
456 $this->buttons .= '</div>';
458 $s .= $this->buttons;
459 $s .= '<ul id="pagehistory">' . "\n";
460 return $s;
463 private function getRevisionButton( $name, $msg ) {
464 $this->preventClickjacking();
465 # Note bug #20966, <button> is non-standard in IE<8
466 $element = Html::element( 'button',
467 array(
468 'type' => 'submit',
469 'name' => $name,
470 'value' => '1',
471 'class' => "historysubmit mw-history-$name-button",
473 $this->msg( $msg )->text()
474 ) . "\n";
475 return $element;
478 function getEndBody() {
479 if ( $this->lastRow ) {
480 $latest = $this->counter == 1 && $this->mIsFirst;
481 $firstInList = $this->counter == 1;
482 if ( $this->mIsBackwards ) {
483 # Next row is unknown, but for UI reasons, probably exists if an offset has been specified
484 if ( $this->mOffset == '' ) {
485 $next = null;
486 } else {
487 $next = 'unknown';
489 } else {
490 # The next row is the past-the-end row
491 $next = $this->mPastTheEndRow;
493 $this->counter++;
494 $s = $this->historyLine( $this->lastRow, $next,
495 $this->getTitle()->getNotificationTimestamp( $this->getUser() ), $latest, $firstInList );
496 } else {
497 $s = '';
499 $s .= "</ul>\n";
500 # Add second buttons only if there is more than one rev
501 if ( $this->getNumRows() > 2 ) {
502 $s .= $this->buttons;
504 $s .= '</form>';
505 return $s;
509 * Creates a submit button
511 * @param string $message text of the submit button, will be escaped
512 * @param array $attributes attributes
513 * @return String: HTML output for the submit button
515 function submitButton( $message, $attributes = array() ) {
516 # Disable submit button if history has 1 revision only
517 if ( $this->getNumRows() > 1 ) {
518 return Xml::submitButton( $message, $attributes );
519 } else {
520 return '';
525 * Returns a row from the history printout.
527 * @todo document some more, and maybe clean up the code (some params redundant?)
529 * @param $row Object: the database row corresponding to the previous line.
530 * @param $next Mixed: the database row corresponding to the next line. (chronologically previous)
531 * @param $notificationtimestamp
532 * @param $latest Boolean: whether this row corresponds to the page's latest revision.
533 * @param $firstInList Boolean: whether this row corresponds to the first displayed on this history page.
534 * @return String: HTML output for the row
536 function historyLine( $row, $next, $notificationtimestamp = false,
537 $latest = false, $firstInList = false )
539 $rev = new Revision( $row );
540 $rev->setTitle( $this->getTitle() );
542 if ( is_object( $next ) ) {
543 $prevRev = new Revision( $next );
544 $prevRev->setTitle( $this->getTitle() );
545 } else {
546 $prevRev = null;
549 $curlink = $this->curLink( $rev, $latest );
550 $lastlink = $this->lastLink( $rev, $next );
551 $diffButtons = $this->diffButtons( $rev, $firstInList );
552 $histLinks = Html::rawElement(
553 'span',
554 array( 'class' => 'mw-history-histlinks' ),
555 $this->msg( 'parentheses' )->rawParams( $curlink . $this->historyPage->message['pipe-separator'] . $lastlink )->escaped()
557 $s = $histLinks . $diffButtons;
559 $link = $this->revLink( $rev );
560 $classes = array();
562 $del = '';
563 $user = $this->getUser();
564 // Show checkboxes for each revision
565 if ( $user->isAllowed( 'deleterevision' ) ) {
566 $this->preventClickjacking();
567 // If revision was hidden from sysops, disable the checkbox
568 if ( !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
569 $del = Xml::check( 'deleterevisions', false, array( 'disabled' => 'disabled' ) );
570 // Otherwise, enable the checkbox...
571 } else {
572 $del = Xml::check( 'showhiderevisions', false,
573 array( 'name' => 'ids[' . $rev->getId() . ']' ) );
575 // User can only view deleted revisions...
576 } elseif ( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) {
577 // If revision was hidden from sysops, disable the link
578 if ( !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
579 $del = Linker::revDeleteLinkDisabled( false );
580 // Otherwise, show the link...
581 } else {
582 $query = array( 'type' => 'revision',
583 'target' => $this->getTitle()->getPrefixedDBkey(), 'ids' => $rev->getId() );
584 $del .= Linker::revDeleteLink( $query,
585 $rev->isDeleted( Revision::DELETED_RESTRICTED ), false );
588 if ( $del ) {
589 $s .= " $del ";
592 $lang = $this->getLanguage();
593 $dirmark = $lang->getDirMark();
595 $s .= " $link";
596 $s .= $dirmark;
597 $s .= " <span class='history-user'>" .
598 Linker::revUserTools( $rev, true ) . "</span>";
599 $s .= $dirmark;
601 if ( $rev->isMinor() ) {
602 $s .= ' ' . ChangesList::flag( 'minor' );
605 # Sometimes rev_len isn't populated
606 if ( $rev->getSize() !== null ) {
607 # Size is always public data
608 $prevSize = isset( $this->parentLens[$row->rev_parent_id] )
609 ? $this->parentLens[$row->rev_parent_id]
610 : 0;
611 $sDiff = ChangesList::showCharacterDifference( $prevSize, $rev->getSize() );
612 $fSize = Linker::formatRevisionSize( $rev->getSize() );
613 $s .= ' <span class="mw-changeslist-separator">. .</span> ' . "$fSize $sDiff";
616 # Text following the character difference is added just before running hooks
617 $s2 = Linker::revComment( $rev, false, true );
619 if ( $notificationtimestamp && ( $row->rev_timestamp >= $notificationtimestamp ) ) {
620 $s2 .= ' <span class="updatedmarker">' . $this->msg( 'updatedmarker' )->escaped() . '</span>';
621 $classes[] = 'mw-history-line-updated';
624 $tools = array();
626 # Rollback and undo links
627 if ( $prevRev && $this->getTitle()->quickUserCan( 'edit', $user ) ) {
628 if ( $latest && $this->getTitle()->quickUserCan( 'rollback', $user ) ) {
629 // Get a rollback link without the brackets
630 $rollbackLink = Linker::generateRollback( $rev, $this->getContext(), array( 'verify', 'noBrackets' ) );
631 if ( $rollbackLink ) {
632 $this->preventClickjacking();
633 $tools[] = $rollbackLink;
637 if ( !$rev->isDeleted( Revision::DELETED_TEXT )
638 && !$prevRev->isDeleted( Revision::DELETED_TEXT ) )
640 # Create undo tooltip for the first (=latest) line only
641 $undoTooltip = $latest
642 ? array( 'title' => $this->msg( 'tooltip-undo' )->text() )
643 : array();
644 $undolink = Linker::linkKnown(
645 $this->getTitle(),
646 $this->msg( 'editundo' )->escaped(),
647 $undoTooltip,
648 array(
649 'action' => 'edit',
650 'undoafter' => $prevRev->getId(),
651 'undo' => $rev->getId()
654 $tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>";
657 // Allow extension to add their own links here
658 wfRunHooks( 'HistoryRevisionTools', array( $rev, &$tools ) );
660 if ( $tools ) {
661 $s2 .= ' ' . $this->msg( 'parentheses' )->rawParams( $lang->pipeList( $tools ) )->escaped();
664 # Tags
665 list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow( $row->ts_tags, 'history' );
666 $classes = array_merge( $classes, $newClasses );
667 if ( $tagSummary !== '' ) {
668 $s2 .= " $tagSummary";
671 # Include separator between character difference and following text
672 if ( $s2 !== '' ) {
673 $s .= ' <span class="mw-changeslist-separator">. .</span> ' . $s2;
676 wfRunHooks( 'PageHistoryLineEnding', array( $this, &$row, &$s, &$classes ) );
678 $attribs = array();
679 if ( $classes ) {
680 $attribs['class'] = implode( ' ', $classes );
683 return Xml::tags( 'li', $attribs, $s ) . "\n";
687 * Create a link to view this revision of the page
689 * @param $rev Revision
690 * @return String
692 function revLink( $rev ) {
693 $date = $this->getLanguage()->userTimeAndDate( $rev->getTimestamp(), $this->getUser() );
694 $date = htmlspecialchars( $date );
695 if ( $rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
696 $link = Linker::linkKnown(
697 $this->getTitle(),
698 $date,
699 array( 'class' => 'mw-changeslist-date' ),
700 array( 'oldid' => $rev->getId() )
702 } else {
703 $link = $date;
705 if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
706 $link = "<span class=\"history-deleted\">$link</span>";
708 return $link;
712 * Create a diff-to-current link for this revision for this page
714 * @param $rev Revision
715 * @param $latest Boolean: this is the latest revision of the page?
716 * @return String
718 function curLink( $rev, $latest ) {
719 $cur = $this->historyPage->message['cur'];
720 if ( $latest || !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
721 return $cur;
722 } else {
723 return Linker::linkKnown(
724 $this->getTitle(),
725 $cur,
726 array(),
727 array(
728 'diff' => $this->getWikiPage()->getLatest(),
729 'oldid' => $rev->getId()
736 * Create a diff-to-previous link for this revision for this page.
738 * @param $prevRev Revision: the previous revision
739 * @param $next Mixed: the newer revision
740 * @return String
742 function lastLink( $prevRev, $next ) {
743 $last = $this->historyPage->message['last'];
744 # $next may either be a Row, null, or "unkown"
745 $nextRev = is_object( $next ) ? new Revision( $next ) : $next;
746 if ( is_null( $next ) ) {
747 # Probably no next row
748 return $last;
749 } elseif ( $next === 'unknown' ) {
750 # Next row probably exists but is unknown, use an oldid=prev link
751 return Linker::linkKnown(
752 $this->getTitle(),
753 $last,
754 array(),
755 array(
756 'diff' => $prevRev->getId(),
757 'oldid' => 'prev'
760 } elseif ( !$prevRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
761 || !$nextRev->userCan( Revision::DELETED_TEXT, $this->getUser() ) )
763 return $last;
764 } else {
765 return Linker::linkKnown(
766 $this->getTitle(),
767 $last,
768 array(),
769 array(
770 'diff' => $prevRev->getId(),
771 'oldid' => $next->rev_id
778 * Create radio buttons for page history
780 * @param $rev Revision object
781 * @param $firstInList Boolean: is this version the first one?
783 * @return String: HTML output for the radio buttons
785 function diffButtons( $rev, $firstInList ) {
786 if ( $this->getNumRows() > 1 ) {
787 $id = $rev->getId();
788 $radio = array( 'type' => 'radio', 'value' => $id );
789 /** @todo Move title texts to javascript */
790 if ( $firstInList ) {
791 $first = Xml::element( 'input',
792 array_merge( $radio, array(
793 'style' => 'visibility:hidden',
794 'name' => 'oldid',
795 'id' => 'mw-oldid-null' ) )
797 $checkmark = array( 'checked' => 'checked' );
798 } else {
799 # Check visibility of old revisions
800 if ( !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
801 $radio['disabled'] = 'disabled';
802 $checkmark = array(); // We will check the next possible one
803 } elseif ( !$this->oldIdChecked ) {
804 $checkmark = array( 'checked' => 'checked' );
805 $this->oldIdChecked = $id;
806 } else {
807 $checkmark = array();
809 $first = Xml::element( 'input',
810 array_merge( $radio, $checkmark, array(
811 'name' => 'oldid',
812 'id' => "mw-oldid-$id" ) ) );
813 $checkmark = array();
815 $second = Xml::element( 'input',
816 array_merge( $radio, $checkmark, array(
817 'name' => 'diff',
818 'id' => "mw-diff-$id" ) ) );
819 return $first . $second;
820 } else {
821 return '';
826 * This is called if a write operation is possible from the generated HTML
828 function preventClickjacking( $enable = true ) {
829 $this->preventClickjacking = $enable;
833 * Get the "prevent clickjacking" flag
834 * @return bool
836 function getPreventClickjacking() {
837 return $this->preventClickjacking;
842 * Backwards-compatibility alias
844 class HistoryPage extends HistoryAction {
845 public function __construct( Page $article ) { # Just to make it public
846 parent::__construct( $article );
849 public function history() {
850 $this->onView();