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