* Changed action=history to use an Action subclass
[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 * @file
7 */
8
9 /**
10 * This class handles printing the history page for an article. In order to
11 * be efficient, it uses timestamps rather than offsets for paging, to avoid
12 * costly LIMIT,offset queries.
13 *
14 * Construct it by passing in an Article, and call $h->history() to print the
15 * history.
16 *
17 */
18 class HistoryAction extends FormlessAction {
19 const DIR_PREV = 0;
20 const DIR_NEXT = 1;
21
22 public function getName() {
23 return 'history';
24 }
25
26 public function getRestriction() {
27 return 'read';
28 }
29
30 public function requiresWrite() {
31 return false;
32 }
33
34 public function requiresUnblock() {
35 return false;
36 }
37
38 protected function getPageTitle() {
39 return $this->msg( 'history-title', $this->getTitle()->getPrefixedText() )->text();
40 }
41
42 protected function getDescription() {
43 // Creation of a subtitle link pointing to [[Special:Log]]
44 return Linker::linkKnown(
45 SpecialPage::getTitleFor( 'Log' ),
46 $this->msg( 'viewpagelogs' )->escaped(),
47 array(),
48 array( 'page' => $this->getTitle()->getPrefixedText() )
49 );
50 }
51
52 /**
53 * Get the Article object we are working on.
54 * @return Page
55 */
56 public function getArticle() {
57 return $this->page;
58 }
59
60 /**
61 * As we use the same small set of messages in various methods and that
62 * they are called often, we call them once and save them in $this->message
63 */
64 private function preCacheMessages() {
65 // Precache various messages
66 if ( !isset( $this->message ) ) {
67 $msgs = array( 'cur', 'last', 'pipe-separator' );
68 foreach ( $msgs as $msg ) {
69 $this->message[$msg] = $this->msg( $msg )->escaped();
70 }
71 }
72 }
73
74 /**
75 * Print the history page for an article.
76 * @return nothing
77 */
78 function onView() {
79 global $wgScript, $wgUseFileCache, $wgSquidMaxage;
80
81 $out = $this->getOutput();
82 $request = $this->getRequest();
83
84 /**
85 * Allow client caching.
86 */
87 if ( $out->checkLastModified( $this->page->getTouched() ) ) {
88 return; // Client cache fresh and headers sent, nothing more to do.
89 }
90
91 wfProfileIn( __METHOD__ );
92
93 if ( $request->getFullRequestURL() == $this->getTitle()->getInternalURL( 'action=history' ) ) {
94 $out->setSquidMaxage( $wgSquidMaxage );
95 }
96
97 $this->preCacheMessages();
98
99 # Fill in the file cache if not set already
100 if ( $wgUseFileCache && HTMLFileCache::useFileCache( $this->getContext() ) ) {
101 $cache = HTMLFileCache::newFromTitle( $this->getTitle(), 'history' );
102 if ( !$cache->isCacheGood( /* Assume up to date */ ) ) {
103 ob_start( array( &$cache, 'saveToFileCache' ) );
104 }
105 }
106
107 // Setup page variables.
108 $out->setFeedAppendQuery( 'action=history' );
109 $out->addModules( array( 'mediawiki.legacy.history', 'mediawiki.action.history' ) );
110
111 // Handle atom/RSS feeds.
112 $feedType = $request->getVal( 'feed' );
113 if ( $feedType ) {
114 wfProfileOut( __METHOD__ );
115 return $this->feed( $feedType );
116 }
117
118 // Fail nicely if article doesn't exist.
119 if ( !$this->getTitle()->exists() ) {
120 $out->addWikiMsg( 'nohistory' );
121 # show deletion/move log if there is an entry
122 LogEventsList::showLogExtract(
123 $out,
124 array( 'delete', 'move' ),
125 $this->getTitle(),
126 '',
127 array( 'lim' => 10,
128 'conds' => array( "log_action != 'revision'" ),
129 'showIfEmpty' => false,
130 'msgKey' => array( 'moveddeleted-notice' )
131 )
132 );
133 wfProfileOut( __METHOD__ );
134 return;
135 }
136
137 /**
138 * Add date selector to quickly get to a certain time
139 */
140 $year = $request->getInt( 'year' );
141 $month = $request->getInt( 'month' );
142 $tagFilter = $request->getVal( 'tagfilter' );
143 $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter );
144
145 /**
146 * Option to show only revisions that have been (partially) hidden via RevisionDelete
147 */
148 if ( $request->getBool( 'deleted' ) ) {
149 $conds = array( "rev_deleted != '0'" );
150 } else {
151 $conds = array();
152 }
153 $checkDeleted = Xml::checkLabel( $this->msg( 'history-show-deleted' )->text(),
154 'deleted', 'mw-show-deleted-only', $request->getBool( 'deleted' ) ) . "\n";
155
156 // Add the general form
157 $action = htmlspecialchars( $wgScript );
158 $out->addHTML(
159 "<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" .
160 Xml::fieldset(
161 $this->msg( 'history-fieldset-title' )->text(),
162 false,
163 array( 'id' => 'mw-history-search' )
164 ) .
165 Html::hidden( 'title', $this->getTitle()->getPrefixedDBKey() ) . "\n" .
166 Html::hidden( 'action', 'history' ) . "\n" .
167 Xml::dateMenu( $year, $month ) . '&#160;' .
168 ( $tagSelector ? ( implode( '&#160;', $tagSelector ) . '&#160;' ) : '' ) .
169 $checkDeleted .
170 Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
171 '</fieldset></form>'
172 );
173
174 wfRunHooks( 'PageHistoryBeforeList', array( &$this->article ) );
175
176 // Create and output the list.
177 $pager = new HistoryPager( $this, $year, $month, $tagFilter, $conds );
178 $out->addHTML(
179 $pager->getNavigationBar() .
180 $pager->getBody() .
181 $pager->getNavigationBar()
182 );
183 $out->preventClickjacking( $pager->getPreventClickjacking() );
184
185 wfProfileOut( __METHOD__ );
186 }
187
188 /**
189 * Fetch an array of revisions, specified by a given limit, offset and
190 * direction. This is now only used by the feeds. It was previously
191 * used by the main UI but that's now handled by the pager.
192 *
193 * @param $limit Integer: the limit number of revisions to get
194 * @param $offset Integer
195 * @param $direction Integer: either HistoryPage::DIR_PREV or HistoryPage::DIR_NEXT
196 * @return ResultWrapper
197 */
198 function fetchRevisions( $limit, $offset, $direction ) {
199 $dbr = wfGetDB( DB_SLAVE );
200
201 if ( $direction == HistoryPage::DIR_PREV ) {
202 list( $dirs, $oper ) = array( "ASC", ">=" );
203 } else { /* $direction == HistoryPage::DIR_NEXT */
204 list( $dirs, $oper ) = array( "DESC", "<=" );
205 }
206
207 if ( $offset ) {
208 $offsets = array( "rev_timestamp $oper '$offset'" );
209 } else {
210 $offsets = array();
211 }
212
213 $page_id = $this->getTitle()->getArticleID();
214
215 return $dbr->select( 'revision',
216 Revision::selectFields(),
217 array_merge( array( "rev_page=$page_id" ), $offsets ),
218 __METHOD__,
219 array( 'ORDER BY' => "rev_timestamp $dirs",
220 'USE INDEX' => 'page_timestamp', 'LIMIT' => $limit )
221 );
222 }
223
224 /**
225 * Output a subscription feed listing recent edits to this page.
226 *
227 * @param $type String: feed type
228 */
229 function feed( $type ) {
230 global $wgFeedClasses, $wgFeedLimit;
231 if ( !FeedUtils::checkFeedOutput( $type ) ) {
232 return;
233 }
234 $request = $this->getRequest();
235
236 $feed = new $wgFeedClasses[$type](
237 $this->getTitle()->getPrefixedText() . ' - ' .
238 wfMsgForContent( 'history-feed-title' ),
239 wfMsgForContent( 'history-feed-description' ),
240 $this->getTitle()->getFullUrl( 'action=history' )
241 );
242
243 // Get a limit on number of feed entries. Provide a sane default
244 // of 10 if none is defined (but limit to $wgFeedLimit max)
245 $limit = $request->getInt( 'limit', 10 );
246 if ( $limit > $wgFeedLimit || $limit < 1 ) {
247 $limit = 10;
248 }
249 $items = $this->fetchRevisions( $limit, 0, HistoryPage::DIR_NEXT );
250
251 // Generate feed elements enclosed between header and footer.
252 $feed->outHeader();
253 if ( $items->numRows() ) {
254 foreach ( $items as $row ) {
255 $feed->outItem( $this->feedItem( $row ) );
256 }
257 } else {
258 $feed->outItem( $this->feedEmpty() );
259 }
260 $feed->outFooter();
261 }
262
263 function feedEmpty() {
264 return new FeedItem(
265 wfMsgForContent( 'nohistory' ),
266 $this->getOutput()->parse( wfMsgForContent( 'history-feed-empty' ) ),
267 $this->getTitle()->getFullUrl(),
268 wfTimestamp( TS_MW ),
269 '',
270 $this->getTitle()->getTalkPage()->getFullUrl()
271 );
272 }
273
274 /**
275 * Generate a FeedItem object from a given revision table row
276 * Borrows Recent Changes' feed generation functions for formatting;
277 * includes a diff to the previous revision (if any).
278 *
279 * @param $row Object: database row
280 * @return FeedItem
281 */
282 function feedItem( $row ) {
283 $rev = new Revision( $row );
284 $rev->setTitle( $this->getTitle() );
285 $text = FeedUtils::formatDiffRow(
286 $this->getTitle(),
287 $this->getTitle()->getPreviousRevisionID( $rev->getId() ),
288 $rev->getId(),
289 $rev->getTimestamp(),
290 $rev->getComment()
291 );
292 if ( $rev->getComment() == '' ) {
293 global $wgContLang;
294 $title = wfMsgForContent( 'history-feed-item-nocomment',
295 $rev->getUserText(),
296 $wgContLang->timeanddate( $rev->getTimestamp() ),
297 $wgContLang->date( $rev->getTimestamp() ),
298 $wgContLang->time( $rev->getTimestamp() )
299 );
300 } else {
301 $title = $rev->getUserText() .
302 wfMsgForContent( 'colon-separator' ) .
303 FeedItem::stripComment( $rev->getComment() );
304 }
305 return new FeedItem(
306 $title,
307 $text,
308 $this->getTitle()->getFullUrl( 'diff=' . $rev->getId() . '&oldid=prev' ),
309 $rev->getTimestamp(),
310 $rev->getUserText(),
311 $this->getTitle()->getTalkPage()->getFullUrl()
312 );
313 }
314 }
315
316 /**
317 * @ingroup Pager
318 */
319 class HistoryPager extends ReverseChronologicalPager {
320 public $lastRow = false, $counter, $historyPage, $buttons, $conds;
321 protected $oldIdChecked;
322 protected $preventClickjacking = false;
323
324 function __construct( $historyPage, $year = '', $month = '', $tagFilter = '', $conds = array() ) {
325 parent::__construct( $historyPage->getContext() );
326 $this->historyPage = $historyPage;
327 $this->tagFilter = $tagFilter;
328 $this->getDateCond( $year, $month );
329 $this->conds = $conds;
330 }
331
332 // For hook compatibility...
333 function getArticle() {
334 return $this->historyPage->getArticle();
335 }
336
337 function getSqlComment() {
338 if ( $this->conds ) {
339 return 'history page filtered'; // potentially slow, see CR r58153
340 } else {
341 return 'history page unfiltered';
342 }
343 }
344
345 function getQueryInfo() {
346 $queryInfo = array(
347 'tables' => array( 'revision', 'user' ),
348 'fields' => array_merge( Revision::selectFields(), Revision::selectUserFields() ),
349 'conds' => array_merge(
350 array( 'rev_page' => $this->getTitle()->getArticleID() ),
351 $this->conds ),
352 'options' => array( 'USE INDEX' => array( 'revision' => 'page_timestamp' ) ),
353 'join_conds' => array(
354 'user' => array( 'LEFT JOIN', 'rev_user != 0 AND user_id = rev_user' ),
355 'tag_summary' => array( 'LEFT JOIN', 'ts_rev_id=rev_id' ) ),
356 );
357 ChangeTags::modifyDisplayQuery(
358 $queryInfo['tables'],
359 $queryInfo['fields'],
360 $queryInfo['conds'],
361 $queryInfo['join_conds'],
362 $queryInfo['options'],
363 $this->tagFilter
364 );
365 wfRunHooks( 'PageHistoryPager::getQueryInfo', array( &$this, &$queryInfo ) );
366 return $queryInfo;
367 }
368
369 function getIndexField() {
370 return 'rev_timestamp';
371 }
372
373 function formatRow( $row ) {
374 if ( $this->lastRow ) {
375 $latest = ( $this->counter == 1 && $this->mIsFirst );
376 $firstInList = $this->counter == 1;
377 $this->counter++;
378 $s = $this->historyLine( $this->lastRow, $row,
379 $this->getTitle()->getNotificationTimestamp( $this->getUser() ), $latest, $firstInList );
380 } else {
381 $s = '';
382 }
383 $this->lastRow = $row;
384 return $s;
385 }
386
387 function doBatchLookups() {
388 # Do a link batch query
389 $this->mResult->seek( 0 );
390 $batch = new LinkBatch();
391 # Give some pointers to make (last) links
392 foreach ( $this->mResult as $row ) {
393 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
394 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
395 }
396 $batch->execute();
397 $this->mResult->seek( 0 );
398 }
399
400 /**
401 * Creates begin of history list with a submit button
402 *
403 * @return string HTML output
404 */
405 function getStartBody() {
406 global $wgScript;
407 $this->lastRow = false;
408 $this->counter = 1;
409 $this->oldIdChecked = 0;
410
411 $this->getOutput()->wrapWikiMsg( "<div class='mw-history-legend'>\n$1\n</div>", 'histlegend' );
412 $s = Html::openElement( 'form', array( 'action' => $wgScript,
413 'id' => 'mw-history-compare' ) ) . "\n";
414 $s .= Html::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) . "\n";
415 $s .= Html::hidden( 'action', 'historysubmit' ) . "\n";
416
417 $s .= '<div>' . $this->submitButton( $this->msg( 'compareselectedversions' )->text(),
418 array( 'class' => 'historysubmit' ) ) . "\n";
419
420 $this->buttons = '<div>';
421 $this->buttons .= $this->submitButton( $this->msg( 'compareselectedversions' )->text(),
422 array( 'class' => 'historysubmit' )
423 + Linker::tooltipAndAccesskeyAttribs( 'compareselectedversions' )
424 ) . "\n";
425
426 if ( $this->getUser()->isAllowed( 'deleterevision' ) ) {
427 $s .= $this->getRevisionButton( 'revisiondelete', 'showhideselectedversions' );
428 }
429 $this->buttons .= '</div>';
430 $s .= '</div><ul id="pagehistory">' . "\n";
431 return $s;
432 }
433
434 private function getRevisionButton( $name, $msg ) {
435 $this->preventClickjacking();
436 # Note bug #20966, <button> is non-standard in IE<8
437 $element = Html::element( 'button',
438 array(
439 'type' => 'submit',
440 'name' => $name,
441 'value' => '1',
442 'class' => "mw-history-$name-button",
443 ),
444 $this->msg( $msg )->text()
445 ) . "\n";
446 $this->buttons .= $element;
447 return $element;
448 }
449
450 function getEndBody() {
451 if ( $this->lastRow ) {
452 $latest = $this->counter == 1 && $this->mIsFirst;
453 $firstInList = $this->counter == 1;
454 if ( $this->mIsBackwards ) {
455 # Next row is unknown, but for UI reasons, probably exists if an offset has been specified
456 if ( $this->mOffset == '' ) {
457 $next = null;
458 } else {
459 $next = 'unknown';
460 }
461 } else {
462 # The next row is the past-the-end row
463 $next = $this->mPastTheEndRow;
464 }
465 $this->counter++;
466 $s = $this->historyLine( $this->lastRow, $next,
467 $this->getTitle()->getNotificationTimestamp( $this->getUser() ), $latest, $firstInList );
468 } else {
469 $s = '';
470 }
471 $s .= "</ul>\n";
472 # Add second buttons only if there is more than one rev
473 if ( $this->getNumRows() > 2 ) {
474 $s .= $this->buttons;
475 }
476 $s .= '</form>';
477 return $s;
478 }
479
480 /**
481 * Creates a submit button
482 *
483 * @param $message String: text of the submit button, will be escaped
484 * @param $attributes Array: attributes
485 * @return String: HTML output for the submit button
486 */
487 function submitButton( $message, $attributes = array() ) {
488 # Disable submit button if history has 1 revision only
489 if ( $this->getNumRows() > 1 ) {
490 return Xml::submitButton( $message , $attributes );
491 } else {
492 return '';
493 }
494 }
495
496 /**
497 * Returns a row from the history printout.
498 *
499 * @todo document some more, and maybe clean up the code (some params redundant?)
500 *
501 * @param $row Object: the database row corresponding to the previous line.
502 * @param $next Mixed: the database row corresponding to the next line.
503 * @param $notificationtimestamp
504 * @param $latest Boolean: whether this row corresponds to the page's latest revision.
505 * @param $firstInList Boolean: whether this row corresponds to the first displayed on this history page.
506 * @return String: HTML output for the row
507 */
508 function historyLine( $row, $next, $notificationtimestamp = false,
509 $latest = false, $firstInList = false )
510 {
511 $rev = new Revision( $row );
512 $rev->setTitle( $this->getTitle() );
513
514 $curlink = $this->curLink( $rev, $latest );
515 $lastlink = $this->lastLink( $rev, $next );
516 $diffButtons = $this->diffButtons( $rev, $firstInList );
517 $histLinks = Html::rawElement(
518 'span',
519 array( 'class' => 'mw-history-histlinks' ),
520 '(' . $curlink . $this->historyPage->message['pipe-separator'] . $lastlink . ') '
521 );
522 $s = $histLinks . $diffButtons;
523
524 $link = $this->revLink( $rev );
525 $classes = array();
526
527 $del = '';
528 $user = $this->getUser();
529 // Show checkboxes for each revision
530 if ( $user->isAllowed( 'deleterevision' ) ) {
531 $this->preventClickjacking();
532 // If revision was hidden from sysops, disable the checkbox
533 if ( !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
534 $del = Xml::check( 'deleterevisions', false, array( 'disabled' => 'disabled' ) );
535 // Otherwise, enable the checkbox...
536 } else {
537 $del = Xml::check( 'showhiderevisions', false,
538 array( 'name' => 'ids[' . $rev->getId() . ']' ) );
539 }
540 // User can only view deleted revisions...
541 } elseif ( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) {
542 // If revision was hidden from sysops, disable the link
543 if ( !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
544 $cdel = Linker::revDeleteLinkDisabled( false );
545 // Otherwise, show the link...
546 } else {
547 $query = array( 'type' => 'revision',
548 'target' => $this->getTitle()->getPrefixedDbkey(), 'ids' => $rev->getId() );
549 $del .= Linker::revDeleteLink( $query,
550 $rev->isDeleted( Revision::DELETED_RESTRICTED ), false );
551 }
552 }
553 if ( $del ) {
554 $s .= " $del ";
555 }
556
557 $lang = $this->getLang();
558 $dirmark = $lang->getDirMark();
559
560 $s .= " $link";
561 $s .= $dirmark;
562 $s .= " <span class='history-user'>" .
563 Linker::revUserTools( $rev, true ) . "</span>";
564 $s .= $dirmark;
565
566 if ( $rev->isMinor() ) {
567 $s .= ' ' . ChangesList::flag( 'minor' );
568 }
569
570 if ( !is_null( $size = $rev->getSize() ) && !$rev->isDeleted( Revision::DELETED_TEXT ) ) {
571 $s .= ' ' . Linker::formatRevisionSize( $size );
572 }
573
574 $s .= Linker::revComment( $rev, false, true );
575
576 if ( $notificationtimestamp && ( $row->rev_timestamp >= $notificationtimestamp ) ) {
577 $s .= ' <span class="updatedmarker">' . $this->msg( 'updatedmarker' )->escaped() . '</span>';
578 }
579
580 $tools = array();
581
582 # Rollback and undo links
583 if ( !is_null( $next ) && is_object( $next ) &&
584 !count( $this->getTitle()->getUserPermissionsErrors( 'edit', $this->getUser() ) ) )
585 {
586 if ( $latest && !count( $this->getTitle()->getUserPermissionsErrors( 'rollback', $this->getUser() ) ) ) {
587 $this->preventClickjacking();
588 $tools[] = '<span class="mw-rollback-link">' .
589 Linker::buildRollbackLink( $rev ) . '</span>';
590 }
591
592 if ( !$rev->isDeleted( Revision::DELETED_TEXT )
593 && !$next->rev_deleted & Revision::DELETED_TEXT )
594 {
595 # Create undo tooltip for the first (=latest) line only
596 $undoTooltip = $latest
597 ? array( 'title' => $this->msg( 'tooltip-undo' )->text() )
598 : array();
599 $undolink = Linker::linkKnown(
600 $this->getTitle(),
601 $this->msg( 'editundo' )->escaped(),
602 $undoTooltip,
603 array(
604 'action' => 'edit',
605 'undoafter' => $next->rev_id,
606 'undo' => $rev->getId()
607 )
608 );
609 $tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>";
610 }
611 }
612
613 if ( $tools ) {
614 $s .= ' (' . $lang->pipeList( $tools ) . ')';
615 }
616
617 # Tags
618 list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow( $row->ts_tags, 'history' );
619 $classes = array_merge( $classes, $newClasses );
620 $s .= " $tagSummary";
621
622 wfRunHooks( 'PageHistoryLineEnding', array( $this, &$row , &$s, &$classes ) );
623
624 $attribs = array();
625 if ( $classes ) {
626 $attribs['class'] = implode( ' ', $classes );
627 }
628
629 return Xml::tags( 'li', $attribs, $s ) . "\n";
630 }
631
632 /**
633 * Create a link to view this revision of the page
634 *
635 * @param $rev Revision
636 * @return String
637 */
638 function revLink( $rev ) {
639 $date = $this->getLang()->userTimeAndDate( $rev->getTimestamp(), $this->getUser() );
640 $date = htmlspecialchars( $date );
641 if ( $rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
642 $link = Linker::linkKnown(
643 $this->getTitle(),
644 $date,
645 array(),
646 array( 'oldid' => $rev->getId() )
647 );
648 } else {
649 $link = $date;
650 }
651 if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
652 $link = "<span class=\"history-deleted\">$link</span>";
653 }
654 return $link;
655 }
656
657 /**
658 * Create a diff-to-current link for this revision for this page
659 *
660 * @param $rev Revision
661 * @param $latest Boolean: this is the latest revision of the page?
662 * @return String
663 */
664 function curLink( $rev, $latest ) {
665 $cur = $this->historyPage->message['cur'];
666 if ( $latest || !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
667 return $cur;
668 } else {
669 return Linker::linkKnown(
670 $this->getTitle(),
671 $cur,
672 array(),
673 array(
674 'diff' => $this->getTitle()->getLatestRevID(),
675 'oldid' => $rev->getId()
676 )
677 );
678 }
679 }
680
681 /**
682 * Create a diff-to-previous link for this revision for this page.
683 *
684 * @param $prevRev Revision: the previous revision
685 * @param $next Mixed: the newer revision
686 * @return String
687 */
688 function lastLink( $prevRev, $next ) {
689 $last = $this->historyPage->message['last'];
690 # $next may either be a Row, null, or "unkown"
691 $nextRev = is_object( $next ) ? new Revision( $next ) : $next;
692 if ( is_null( $next ) ) {
693 # Probably no next row
694 return $last;
695 } elseif ( $next === 'unknown' ) {
696 # Next row probably exists but is unknown, use an oldid=prev link
697 return Linker::linkKnown(
698 $this->getTitle(),
699 $last,
700 array(),
701 array(
702 'diff' => $prevRev->getId(),
703 'oldid' => 'prev'
704 )
705 );
706 } elseif ( !$prevRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
707 || !$nextRev->userCan( Revision::DELETED_TEXT, $this->getUser() ) )
708 {
709 return $last;
710 } else {
711 return Linker::linkKnown(
712 $this->getTitle(),
713 $last,
714 array(),
715 array(
716 'diff' => $prevRev->getId(),
717 'oldid' => $next->rev_id
718 )
719 );
720 }
721 }
722
723 /**
724 * Create radio buttons for page history
725 *
726 * @param $rev Revision object
727 * @param $firstInList Boolean: is this version the first one?
728 *
729 * @return String: HTML output for the radio buttons
730 */
731 function diffButtons( $rev, $firstInList ) {
732 if ( $this->getNumRows() > 1 ) {
733 $id = $rev->getId();
734 $radio = array( 'type' => 'radio', 'value' => $id );
735 /** @todo: move title texts to javascript */
736 if ( $firstInList ) {
737 $first = Xml::element( 'input',
738 array_merge( $radio, array(
739 'style' => 'visibility:hidden',
740 'name' => 'oldid',
741 'id' => 'mw-oldid-null' ) )
742 );
743 $checkmark = array( 'checked' => 'checked' );
744 } else {
745 # Check visibility of old revisions
746 if ( !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
747 $radio['disabled'] = 'disabled';
748 $checkmark = array(); // We will check the next possible one
749 } elseif ( !$this->oldIdChecked ) {
750 $checkmark = array( 'checked' => 'checked' );
751 $this->oldIdChecked = $id;
752 } else {
753 $checkmark = array();
754 }
755 $first = Xml::element( 'input',
756 array_merge( $radio, $checkmark, array(
757 'name' => 'oldid',
758 'id' => "mw-oldid-$id" ) ) );
759 $checkmark = array();
760 }
761 $second = Xml::element( 'input',
762 array_merge( $radio, $checkmark, array(
763 'name' => 'diff',
764 'id' => "mw-diff-$id" ) ) );
765 return $first . $second;
766 } else {
767 return '';
768 }
769 }
770
771 /**
772 * This is called if a write operation is possible from the generated HTML
773 */
774 function preventClickjacking( $enable = true ) {
775 $this->preventClickjacking = $enable;
776 }
777
778 /**
779 * Get the "prevent clickjacking" flag
780 */
781 function getPreventClickjacking() {
782 return $this->preventClickjacking;
783 }
784 }
785
786 /**
787 * Backwards-compatibility alias
788 */
789 class HistoryPage extends HistoryAction {
790 public function __construct( Page $article ) { # Just to make it public
791 parent::__construct( $article );
792 }
793
794 public function history() {
795 $this->onView();
796 }
797 }