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