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