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