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