]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/HistoryPage.php
MediaWiki 1.16.1
[autoinstallsdev/mediawiki.git] / includes / HistoryPage.php
1 <?php
2 /**
3  * Page history
4  *
5  * Split off from Article.php and Skin.php, 2003-12-22
6  * @file
7  */
8
9 /**
10  * This class handles printing the history page for an article.  In order to
11  * be efficient, it uses timestamps rather than offsets for paging, to avoid
12  * costly LIMIT,offset queries.
13  *
14  * Construct it by passing in an Article, and call $h->history() to print the
15  * history.
16  *
17  */
18 class HistoryPage {
19         const DIR_PREV = 0;
20         const DIR_NEXT = 1;
21
22         var $article, $title, $skin;
23
24         /**
25          * Construct a new HistoryPage.
26          *
27          * @param $article Article
28          */
29         function __construct( $article ) {
30                 global $wgUser;
31                 $this->article = $article;
32                 $this->title = $article->getTitle();
33                 $this->skin = $wgUser->getSkin();
34                 $this->preCacheMessages();
35         }
36
37         function getArticle() {
38                 return $this->article;
39         }
40
41         function getTitle() {
42                 return $this->title;
43         }
44
45         /**
46          * As we use the same small set of messages in various methods and that
47          * they are called often, we call them once and save them in $this->message
48          */
49         function preCacheMessages() {
50                 // Precache various messages
51                 if( !isset( $this->message ) ) {
52                         $msgs = array( 'cur', 'last', 'pipe-separator' );
53                         foreach( $msgs as $msg ) {
54                                 $this->message[$msg] = wfMsgExt( $msg, array( 'escapenoentities') );
55                         }
56                 }
57         }
58
59         /**
60          * Print the history page for an article.
61          * @return nothing
62          */
63         function history() {
64                 global $wgOut, $wgRequest, $wgScript;
65
66                 /*
67                  * Allow client caching.
68                  */
69                 if( $wgOut->checkLastModified( $this->article->getTouched() ) )
70                         return; // Client cache fresh and headers sent, nothing more to do.
71
72                 wfProfileIn( __METHOD__ );
73
74                 /*
75                  * Setup page variables.
76                  */
77                 $wgOut->setPageTitle( wfMsg( 'history-title', $this->title->getPrefixedText() ) );
78                 $wgOut->setPageTitleActionText( wfMsg( 'history_short' ) );
79                 $wgOut->setArticleFlag( false );
80                 $wgOut->setArticleRelated( true );
81                 $wgOut->setRobotPolicy( 'noindex,nofollow' );
82                 $wgOut->setSyndicated( true );
83                 $wgOut->setFeedAppendQuery( 'action=history' );
84                 $wgOut->addScriptFile( 'history.js' );
85
86                 $logPage = SpecialPage::getTitleFor( 'Log' );
87                 $logLink = $this->skin->link(
88                         $logPage,
89                         wfMsgHtml( 'viewpagelogs' ),
90                         array(),
91                         array( 'page' => $this->title->getPrefixedText() ),
92                         array( 'known', 'noclasses' )
93                 );
94                 $wgOut->setSubtitle( $logLink );
95
96                 $feedType = $wgRequest->getVal( 'feed' );
97                 if( $feedType ) {
98                         wfProfileOut( __METHOD__ );
99                         return $this->feed( $feedType );
100                 }
101
102                 /*
103                  * Fail if article doesn't exist.
104                  */
105                 if( !$this->title->exists() ) {
106                         $wgOut->addWikiMsg( 'nohistory' );
107                         # show deletion/move log if there is an entry
108                         LogEventsList::showLogExtract(
109                                 $wgOut,
110                                 array( 'delete', 'move' ),
111                                 $this->title->getPrefixedText(),
112                                 '',
113                                 array(  'lim' => 10,
114                                         'conds' => array( "log_action != 'revision'" ),
115                                         'showIfEmpty' => false,
116                                         'msgKey' => array( 'moveddeleted-notice' )
117                                 )
118                         );
119                         wfProfileOut( __METHOD__ );
120                         return;
121                 }
122
123                 /**
124                  * Add date selector to quickly get to a certain time
125                  */
126                 $year = $wgRequest->getInt( 'year' );
127                 $month = $wgRequest->getInt( 'month' );
128                 $tagFilter = $wgRequest->getVal( 'tagfilter' );
129                 $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter );
130                 /**
131                  * Option to show only revisions that have been (partially) hidden via RevisionDelete
132                  */
133                 if ( $wgRequest->getBool( 'deleted' ) ) {
134                         $conds = array("rev_deleted != '0'");
135                 } else {
136                         $conds = array();
137                 }
138                 $checkDeleted = Xml::checkLabel( wfMsg( 'history-show-deleted' ),
139                         'deleted', 'mw-show-deleted-only', $wgRequest->getBool( 'deleted' ) ) . "\n";
140
141                 $action = htmlspecialchars( $wgScript );
142                 $wgOut->addHTML(
143                         "<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" .
144                         Xml::fieldset(
145                                 wfMsg( 'history-fieldset-title' ),
146                                 false,
147                                 array( 'id' => 'mw-history-search' )
148                         ) .
149                         Xml::hidden( 'title', $this->title->getPrefixedDBKey() ) . "\n" .
150                         Xml::hidden( 'action', 'history' ) . "\n" .
151                         Xml::dateMenu( $year, $month ) . '&nbsp;' .
152                         ( $tagSelector ? ( implode( '&nbsp;', $tagSelector ) . '&nbsp;' ) : '' ) .
153                         $checkDeleted .
154                         Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
155                         '</fieldset></form>'
156                 );
157
158                 wfRunHooks( 'PageHistoryBeforeList', array( &$this->article ) );
159
160                 /**
161                  * Do the list
162                  */
163                 $pager = new HistoryPager( $this, $year, $month, $tagFilter, $conds );
164                 $wgOut->addHTML(
165                         $pager->getNavigationBar() .
166                         $pager->getBody() .
167                         $pager->getNavigationBar()
168                 );
169                 $wgOut->preventClickjacking( $pager->getPreventClickjacking() );
170
171                 wfProfileOut( __METHOD__ );
172         }
173
174         /**
175          * Fetch an array of revisions, specified by a given limit, offset and
176          * direction. This is now only used by the feeds. It was previously
177          * used by the main UI but that's now handled by the pager.
178          *
179          * @param $limit Integer: the limit number of revisions to get
180          * @param $offset Integer
181          * @param $direction Integer: either HistoryPage::DIR_PREV or HistoryPage::DIR_NEXT
182          * @return ResultWrapper
183          */
184         function fetchRevisions( $limit, $offset, $direction ) {
185                 $dbr = wfGetDB( DB_SLAVE );
186
187                 if( $direction == HistoryPage::DIR_PREV )
188                         list($dirs, $oper) = array("ASC", ">=");
189                 else /* $direction == HistoryPage::DIR_NEXT */
190                         list($dirs, $oper) = array("DESC", "<=");
191
192                 if( $offset )
193                         $offsets = array("rev_timestamp $oper '$offset'");
194                 else
195                         $offsets = array();
196
197                 $page_id = $this->title->getArticleID();
198
199                 return $dbr->select( 'revision',
200                         Revision::selectFields(),
201                         array_merge(array("rev_page=$page_id"), $offsets),
202                         __METHOD__,
203                         array( 'ORDER BY' => "rev_timestamp $dirs",
204                                 'USE INDEX' => 'page_timestamp', 'LIMIT' => $limit)
205                 );
206         }
207
208         /**
209          * Output a subscription feed listing recent edits to this page.
210          *
211          * @param $type String: feed type
212          */
213         function feed( $type ) {
214                 global $wgFeedClasses, $wgRequest, $wgFeedLimit;
215                 if( !FeedUtils::checkFeedOutput($type) ) {
216                         return;
217                 }
218
219                 $feed = new $wgFeedClasses[$type](
220                         $this->title->getPrefixedText() . ' - ' .
221                         wfMsgForContent( 'history-feed-title' ),
222                         wfMsgForContent( 'history-feed-description' ),
223                         $this->title->getFullUrl( 'action=history' )
224                 );
225
226                 // Get a limit on number of feed entries. Provide a sane default
227                 // of 10 if none is defined (but limit to $wgFeedLimit max)
228                 $limit = $wgRequest->getInt( 'limit', 10 );
229                 if( $limit > $wgFeedLimit || $limit < 1 ) {
230                         $limit = 10;
231                 }
232                 $items = $this->fetchRevisions($limit, 0, HistoryPage::DIR_NEXT);
233
234                 $feed->outHeader();
235                 if( $items ) {
236                         foreach( $items as $row ) {
237                                 $feed->outItem( $this->feedItem( $row ) );
238                         }
239                 } else {
240                         $feed->outItem( $this->feedEmpty() );
241                 }
242                 $feed->outFooter();
243         }
244
245         function feedEmpty() {
246                 global $wgOut;
247                 return new FeedItem(
248                         wfMsgForContent( 'nohistory' ),
249                         $wgOut->parse( wfMsgForContent( 'history-feed-empty' ) ),
250                         $this->title->getFullUrl(),
251                         wfTimestamp( TS_MW ),
252                         '',
253                         $this->title->getTalkPage()->getFullUrl()
254                 );
255         }
256
257         /**
258          * Generate a FeedItem object from a given revision table row
259          * Borrows Recent Changes' feed generation functions for formatting;
260          * includes a diff to the previous revision (if any).
261          *
262          * @param $row Object: database row
263          * @return FeedItem
264          */
265         function feedItem( $row ) {
266                 $rev = new Revision( $row );
267                 $rev->setTitle( $this->title );
268                 $text = FeedUtils::formatDiffRow(
269                         $this->title,
270                         $this->title->getPreviousRevisionID( $rev->getId() ),
271                         $rev->getId(),
272                         $rev->getTimestamp(),
273                         $rev->getComment()
274                 );
275                 if( $rev->getComment() == '' ) {
276                         global $wgContLang;
277                         $title = wfMsgForContent( 'history-feed-item-nocomment',
278                                 $rev->getUserText(),
279                                 $wgContLang->timeanddate( $rev->getTimestamp() ),
280                                 $wgContLang->date( $rev->getTimestamp() ),
281                                 $wgContLang->time( $rev->getTimestamp() )
282                         );
283                 } else {
284                         $title = $rev->getUserText() .
285                         wfMsgForContent( 'colon-separator' ) .
286                         FeedItem::stripComment( $rev->getComment() );
287                 }
288                 return new FeedItem(
289                         $title,
290                         $text,
291                         $this->title->getFullUrl( 'diff=' . $rev->getId() . '&oldid=prev' ),
292                         $rev->getTimestamp(),
293                         $rev->getUserText(),
294                         $this->title->getTalkPage()->getFullUrl()
295                 );
296         }
297 }
298
299 /**
300  * @ingroup Pager
301  */
302 class HistoryPager extends ReverseChronologicalPager {
303         public $lastRow = false, $counter, $historyPage, $title, $buttons, $conds;
304         protected $oldIdChecked;
305         protected $preventClickjacking = false;
306
307         function __construct( $historyPage, $year='', $month='', $tagFilter = '', $conds = array() ) {
308                 parent::__construct();
309                 $this->historyPage = $historyPage;
310                 $this->title = $this->historyPage->title;
311                 $this->tagFilter = $tagFilter;
312                 $this->getDateCond( $year, $month );
313                 $this->conds = $conds;
314         }
315
316         // For hook compatibility...
317         function getArticle() {
318                 return $this->historyPage->getArticle();
319         }
320
321         function getSqlComment() {
322                 if ( $this->conds ) {
323                         return 'history page filtered'; // potentially slow, see CR r58153
324                 } else {
325                         return 'history page unfiltered';
326                 }
327         }
328
329         function getQueryInfo() {
330                 $queryInfo = array(
331                         'tables'  => array('revision'),
332                         'fields'  => Revision::selectFields(),
333                         'conds'   => array_merge(
334                                 array( 'rev_page' => $this->historyPage->title->getArticleID() ),
335                                 $this->conds ),
336                         'options' => array( 'USE INDEX' => array('revision' => 'page_timestamp') ),
337                         'join_conds' => array( 'tag_summary' => array( 'LEFT JOIN', 'ts_rev_id=rev_id' ) ),
338                 );
339                 ChangeTags::modifyDisplayQuery(
340                         $queryInfo['tables'],
341                         $queryInfo['fields'],
342                         $queryInfo['conds'],
343                         $queryInfo['join_conds'],
344                         $queryInfo['options'],
345                         $this->tagFilter
346                 );
347                 wfRunHooks( 'PageHistoryPager::getQueryInfo', array( &$this, &$queryInfo ) );
348                 return $queryInfo;
349         }
350
351         function getIndexField() {
352                 return 'rev_timestamp';
353         }
354
355         function formatRow( $row ) {
356                 if( $this->lastRow ) {
357                         $latest = ($this->counter == 1 && $this->mIsFirst);
358                         $firstInList = $this->counter == 1;
359                         $s = $this->historyLine( $this->lastRow, $row, $this->counter++,
360                                 $this->title->getNotificationTimestamp(), $latest, $firstInList );
361                 } else {
362                         $s = '';
363                 }
364                 $this->lastRow = $row;
365                 return $s;
366         }
367
368         /**
369          * Creates begin of history list with a submit button
370          *
371          * @return string HTML output
372          */
373         function getStartBody() {
374                 global $wgScript, $wgUser, $wgOut, $wgContLang;
375                 $this->lastRow = false;
376                 $this->counter = 1;
377                 $this->oldIdChecked = 0;
378
379                 $wgOut->wrapWikiMsg( "<div class='mw-history-legend'>\n$1</div>", 'histlegend' );
380                 $s = Xml::openElement( 'form', array( 'action' => $wgScript,
381                         'id' => 'mw-history-compare' ) ) . "\n";
382                 $s .= Xml::hidden( 'title', $this->title->getPrefixedDbKey() ) . "\n";
383                 $s .= Xml::hidden( 'action', 'historysubmit' ) . "\n";
384
385                 $this->buttons = '<div>';
386                 if( $wgUser->isAllowed('deleterevision') ) {
387                         $this->preventClickjacking();
388                         $float = $wgContLang->alignEnd();
389                         # Note bug #20966, <button> is non-standard in IE<8
390                         $this->buttons .= Xml::element( 'button',
391                                 array(
392                                         'type' => 'submit',
393                                         'name' => 'revisiondelete',
394                                         'value' => '1',
395                                         'style' => "float: $float;",
396                                         'class' => 'mw-history-revisiondelete-button',
397                                 ),
398                                 wfMsg( 'showhideselectedversions' )
399                         ) . "\n";
400                 }
401                 $this->buttons .= $this->submitButton( wfMsg( 'compareselectedversions'),
402                         array(
403                                 'class'     => 'historysubmit',
404                                 'accesskey' => wfMsg( 'accesskey-compareselectedversions' ),
405                                 'title'     => wfMsg( 'tooltip-compareselectedversions' ),
406                         )
407                 ) . "\n";
408                 $this->buttons .= '</div>';
409                 $s .= $this->buttons . '<ul id="pagehistory">' . "\n";
410                 return $s;
411         }
412
413         function getEndBody() {
414                 if( $this->lastRow ) {
415                         $latest = $this->counter == 1 && $this->mIsFirst;
416                         $firstInList = $this->counter == 1;
417                         if( $this->mIsBackwards ) {
418                                 # Next row is unknown, but for UI reasons, probably exists if an offset has been specified
419                                 if( $this->mOffset == '' ) {
420                                         $next = null;
421                                 } else {
422                                         $next = 'unknown';
423                                 }
424                         } else {
425                                 # The next row is the past-the-end row
426                                 $next = $this->mPastTheEndRow;
427                         }
428                         $s = $this->historyLine( $this->lastRow, $next, $this->counter++,
429                                 $this->title->getNotificationTimestamp(), $latest, $firstInList );
430                 } else {
431                         $s = '';
432                 }
433                 $s .= "</ul>\n";
434                 # Add second buttons only if there is more than one rev
435                 if( $this->getNumRows() > 2 ) {
436                         $s .= $this->buttons;
437                 }
438                 $s .= '</form>';
439                 return $s;
440         }
441
442         /**
443          * Creates a submit button
444          *
445          * @param $message String: text of the submit button, will be escaped
446          * @param $attributes Array: attributes
447          * @return String: HTML output for the submit button
448          */
449         function submitButton( $message, $attributes = array() ) {
450                 # Disable submit button if history has 1 revision only
451                 if( $this->getNumRows() > 1 ) {
452                         return Xml::submitButton( $message , $attributes );
453                 } else {
454                         return '';
455                 }
456         }
457
458         /**
459          * Returns a row from the history printout.
460          *
461          * @todo document some more, and maybe clean up the code (some params redundant?)
462          *
463          * @param $row Object: the database row corresponding to the previous line.
464          * @param $next Mixed: the database row corresponding to the next line.
465          * @param $counter Integer: apparently a counter of what row number we're at, counted from the top row = 1.
466          * @param $notificationtimestamp
467          * @param $latest Boolean: whether this row corresponds to the page's latest revision.
468          * @param $firstInList Boolean: whether this row corresponds to the first displayed on this history page.
469          * @return String: HTML output for the row
470          */
471         function historyLine( $row, $next, $counter = '', $notificationtimestamp = false,
472                 $latest = false, $firstInList = false )
473         {
474                 global $wgUser, $wgLang;
475                 $rev = new Revision( $row );
476                 $rev->setTitle( $this->title );
477
478                 $curlink = $this->curLink( $rev, $latest );
479                 $lastlink = $this->lastLink( $rev, $next, $counter );
480                 $diffButtons = $this->diffButtons( $rev, $firstInList, $counter );
481                 $histLinks = Html::rawElement(
482                                 'span',
483                                 array( 'class' => 'mw-history-histlinks' ),
484                                 '(' . $curlink . $this->historyPage->message['pipe-separator'] . $lastlink . ') '
485                 );
486                 $s = $histLinks . $diffButtons;
487
488                 $link = $this->revLink( $rev );
489                 $classes = array();
490
491                 $del = '';
492                 // User can delete revisions...
493                 if( $wgUser->isAllowed( 'deleterevision' ) ) {
494                         $this->preventClickjacking();
495                         // If revision was hidden from sysops, disable the checkbox
496                         if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
497                                 $del = Xml::check( 'deleterevisions', false, array( 'disabled' => 'disabled' ) );
498                         // Otherwise, enable the checkbox...
499                         } else {
500                                 $del = Xml::check( 'showhiderevisions', false,
501                                         array( 'name' => 'ids['.$rev->getId().']' ) );
502                         }
503                 // User can only view deleted revisions...
504                 } else if( $rev->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) {
505                         // If revision was hidden from sysops, disable the link
506                         if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
507                                 $cdel = $this->getSkin()->revDeleteLinkDisabled( false );
508                         // Otherwise, show the link...
509                         } else {
510                                 $query = array( 'type' => 'revision',
511                                         'target' => $this->title->getPrefixedDbkey(), 'ids' => $rev->getId() );          
512                                 $del .= $this->getSkin()->revDeleteLink( $query,
513                                         $rev->isDeleted( Revision::DELETED_RESTRICTED ), false );
514                         }
515                 }
516                 if( $del ) $s .= " $del ";
517
518                 $s .= " $link";
519                 $s .= " <span class='history-user'>" .
520                         $this->getSkin()->revUserTools( $rev, true ) . "</span>";
521
522                 if( $rev->isMinor() ) {
523                         $s .= ' ' . ChangesList::flag( 'minor' );
524                 }
525
526                 if( !is_null( $size = $rev->getSize() ) && !$rev->isDeleted( Revision::DELETED_TEXT ) ) {
527                         $s .= ' ' . $this->getSkin()->formatRevisionSize( $size );
528                 }
529
530                 $s .= $this->getSkin()->revComment( $rev, false, true );
531
532                 if( $notificationtimestamp && ($row->rev_timestamp >= $notificationtimestamp) ) {
533                         $s .= ' <span class="updatedmarker">' .  wfMsgHtml( 'updatedmarker' ) . '</span>';
534                 }
535
536                 $tools = array();
537
538                 # Rollback and undo links
539                 if( !is_null( $next ) && is_object( $next ) ) {
540                         if( $latest && $this->title->userCan( 'rollback' ) && $this->title->userCan( 'edit' ) ) {
541                                 $this->preventClickjacking();
542                                 $tools[] = '<span class="mw-rollback-link">'.
543                                         $this->getSkin()->buildRollbackLink( $rev ).'</span>';
544                         }
545
546                         if( $this->title->quickUserCan( 'edit' )
547                                 && !$rev->isDeleted( Revision::DELETED_TEXT )
548                                 && !$next->rev_deleted & Revision::DELETED_TEXT )
549                         {
550                                 # Create undo tooltip for the first (=latest) line only
551                                 $undoTooltip = $latest
552                                         ? array( 'title' => wfMsg( 'tooltip-undo' ) )
553                                         : array();
554                                 $undolink = $this->getSkin()->link(
555                                         $this->title,
556                                         wfMsgHtml( 'editundo' ),
557                                         $undoTooltip,
558                                         array(
559                                                 'action' => 'edit',
560                                                 'undoafter' => $next->rev_id,
561                                                 'undo' => $rev->getId()
562                                         ),
563                                         array( 'known', 'noclasses' )
564                                 );
565                                 $tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>";
566                         }
567                 }
568
569                 if( $tools ) {
570                         $s .= ' (' . $wgLang->pipeList( $tools ) . ')';
571                 }
572
573                 # Tags
574                 list($tagSummary, $newClasses) = ChangeTags::formatSummaryRow( $row->ts_tags, 'history' );
575                 $classes = array_merge( $classes, $newClasses );
576                 $s .= " $tagSummary";
577
578                 wfRunHooks( 'PageHistoryLineEnding', array( $this, &$row , &$s, &$classes ) );
579
580                 $attribs = array();
581                 if ( $classes ) {
582                         $attribs['class'] = implode( ' ', $classes );
583                 }
584
585                 return Xml::tags( 'li', $attribs, $s ) . "\n";
586         }
587
588         /**
589          * Create a link to view this revision of the page
590          *
591          * @param $rev Revision
592          * @return String
593          */
594         function revLink( $rev ) {
595                 global $wgLang;
596                 $date = $wgLang->timeanddate( wfTimestamp(TS_MW, $rev->getTimestamp()), true );
597                 $date = htmlspecialchars( $date );
598                 if( !$rev->isDeleted( Revision::DELETED_TEXT ) ) {
599                         $link = $this->getSkin()->link(
600                                 $this->title,
601                                 $date,
602                                 array(),
603                                 array( 'oldid' => $rev->getId() ),
604                                 array( 'known', 'noclasses' )
605                         );
606                 } else {
607                         $link = "<span class=\"history-deleted\">$date</span>";
608                 }
609                 return $link;
610         }
611
612         /**
613          * Create a diff-to-current link for this revision for this page
614          *
615          * @param $rev Revision
616          * @param $latest Boolean: this is the latest revision of the page?
617          * @return String
618          */
619         function curLink( $rev, $latest ) {
620                 $cur = $this->historyPage->message['cur'];
621                 if( $latest || !$rev->userCan( Revision::DELETED_TEXT ) ) {
622                         return $cur;
623                 } else {
624                         return $this->getSkin()->link(
625                                 $this->title,
626                                 $cur,
627                                 array(),
628                                 array(
629                                         'diff' => $this->title->getLatestRevID(),
630                                         'oldid' => $rev->getId()
631                                 ),
632                                 array( 'known', 'noclasses' )
633                         );
634                 }
635         }
636
637         /**
638          * Create a diff-to-previous link for this revision for this page.
639          *
640          * @param $prevRev Revision: the previous revision
641          * @param $next Mixed: the newer revision
642          * @param $counter Integer: what row on the history list this is
643          * @return String
644          */
645         function lastLink( $prevRev, $next, $counter ) {
646                 $last = $this->historyPage->message['last'];
647                 # $next may either be a Row, null, or "unkown"
648                 $nextRev = is_object($next) ? new Revision( $next ) : $next;
649                 if( is_null($next) ) {
650                         # Probably no next row
651                         return $last;
652                 } elseif( $next === 'unknown' ) {
653                         # Next row probably exists but is unknown, use an oldid=prev link
654                         return $this->getSkin()->link(
655                                 $this->title,
656                                 $last,
657                                 array(),
658                                 array(
659                                         'diff' => $prevRev->getId(),
660                                         'oldid' => 'prev'
661                                 ),
662                                 array( 'known', 'noclasses' )
663                         );
664                 } elseif( !$prevRev->userCan(Revision::DELETED_TEXT)
665                         || !$nextRev->userCan(Revision::DELETED_TEXT) )
666                 {
667                         return $last;
668                 } else {
669                         return $this->getSkin()->link(
670                                 $this->title,
671                                 $last,
672                                 array(),
673                                 array(
674                                         'diff' => $prevRev->getId(),
675                                         'oldid' => $next->rev_id
676                                 ),
677                                 array( 'known', 'noclasses' )
678                         );
679                 }
680         }
681
682         /**
683          * Create radio buttons for page history
684          *
685          * @param $rev Revision object
686          * @param $firstInList Boolean: is this version the first one?
687          * @param $counter Integer: a counter of what row number we're at, counted from the top row = 1.
688          * @return String: HTML output for the radio buttons
689          */
690         function diffButtons( $rev, $firstInList, $counter ) {
691                 if( $this->getNumRows() > 1 ) {
692                         $id = $rev->getId();
693                         $radio = array( 'type'  => 'radio', 'value' => $id );
694                         /** @todo: move title texts to javascript */
695                         if( $firstInList ) {
696                                 $first = Xml::element( 'input',
697                                         array_merge( $radio, array(
698                                                 'style' => 'visibility:hidden',
699                                                 'name'  => 'oldid',
700                                                 'id' => 'mw-oldid-null' ) )
701                                 );
702                                 $checkmark = array( 'checked' => 'checked' );
703                         } else {
704                                 # Check visibility of old revisions
705                                 if( !$rev->userCan( Revision::DELETED_TEXT ) ) {
706                                         $radio['disabled'] = 'disabled';
707                                         $checkmark = array(); // We will check the next possible one
708                                 } else if( $counter == 2 || !$this->oldIdChecked ) {
709                                         $checkmark = array( 'checked' => 'checked' );
710                                         $this->oldIdChecked = $id;
711                                 } else {
712                                         $checkmark = array();
713                                 }
714                                 $first = Xml::element( 'input',
715                                         array_merge( $radio, $checkmark, array(
716                                                 'name'  => 'oldid',
717                                                 'id' => "mw-oldid-$id" ) ) );
718                                 $checkmark = array();
719                         }
720                         $second = Xml::element( 'input',
721                                 array_merge( $radio, $checkmark, array(
722                                         'name'  => 'diff',
723                                         'id' => "mw-diff-$id" ) ) );
724                         return $first . $second;
725                 } else {
726                         return '';
727                 }
728         }
729
730         /**
731          * This is called if a write operation is possible from the generated HTML
732          */
733         function preventClickjacking( $enable = true ) {
734                 $this->preventClickjacking = $enable;
735         }
736
737         /**
738          * Get the "prevent clickjacking" flag
739          */
740         function getPreventClickjacking() {
741                 return $this->preventClickjacking;
742         }
743 }
744
745 /**
746  * Backwards-compatibility aliases
747  */
748 class PageHistory extends HistoryPage {}
749 class PageHistoryPager extends HistoryPager {}