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