00001 <?php
00018 class HistoryPage {
00019 const DIR_PREV = 0;
00020 const DIR_NEXT = 1;
00021
00022 var $article, $title, $skin;
00023
00029 function __construct( $article ) {
00030 global $wgUser;
00031 $this->article = $article;
00032 $this->title = $article->getTitle();
00033 $this->skin = $wgUser->getSkin();
00034 $this->preCacheMessages();
00035 }
00036
00037 function getArticle() {
00038 return $this->article;
00039 }
00040
00041 function getTitle() {
00042 return $this->title;
00043 }
00044
00049 function preCacheMessages() {
00050
00051 if( !isset( $this->message ) ) {
00052 $msgs = array( 'cur', 'last', 'pipe-separator' );
00053 foreach( $msgs as $msg ) {
00054 $this->message[$msg] = wfMsgExt( $msg, array( 'escapenoentities') );
00055 }
00056 }
00057 }
00058
00063 function history() {
00064 global $wgOut, $wgRequest, $wgScript;
00065
00066
00067
00068
00069 if( $wgOut->checkLastModified( $this->article->getTouched() ) )
00070 return;
00071
00072 wfProfileIn( __METHOD__ );
00073
00074
00075
00076
00077 $wgOut->setPageTitle( wfMsg( 'history-title', $this->title->getPrefixedText() ) );
00078 $wgOut->setPageTitleActionText( wfMsg( 'history_short' ) );
00079 $wgOut->setArticleFlag( false );
00080 $wgOut->setArticleRelated( true );
00081 $wgOut->setRobotPolicy( 'noindex,nofollow' );
00082 $wgOut->setSyndicated( true );
00083 $wgOut->setFeedAppendQuery( 'action=history' );
00084 $wgOut->addScriptFile( 'history.js' );
00085
00086 $logPage = SpecialPage::getTitleFor( 'Log' );
00087 $logLink = $this->skin->link(
00088 $logPage,
00089 wfMsgHtml( 'viewpagelogs' ),
00090 array(),
00091 array( 'page' => $this->title->getPrefixedText() ),
00092 array( 'known', 'noclasses' )
00093 );
00094 $wgOut->setSubtitle( $logLink );
00095
00096 $feedType = $wgRequest->getVal( 'feed' );
00097 if( $feedType ) {
00098 wfProfileOut( __METHOD__ );
00099 return $this->feed( $feedType );
00100 }
00101
00102
00103
00104
00105 if( !$this->title->exists() ) {
00106 $wgOut->addWikiMsg( 'nohistory' );
00107 # show deletion/move log if there is an entry
00108 LogEventsList::showLogExtract(
00109 $wgOut,
00110 array( 'delete', 'move' ),
00111 $this->title->getPrefixedText(),
00112 '',
00113 array( 'lim' => 10,
00114 'conds' => array( "log_action != 'revision'" ),
00115 'showIfEmpty' => false,
00116 'msgKey' => array( 'moveddeleted-notice' )
00117 )
00118 );
00119 wfProfileOut( __METHOD__ );
00120 return;
00121 }
00122
00126 $year = $wgRequest->getInt( 'year' );
00127 $month = $wgRequest->getInt( 'month' );
00128 $tagFilter = $wgRequest->getVal( 'tagfilter' );
00129 $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter );
00133 if ( $wgRequest->getBool( 'deleted' ) ) {
00134 $conds = array("rev_deleted != '0'");
00135 } else {
00136 $conds = array();
00137 }
00138 $checkDeleted = Xml::checkLabel( wfMsg( 'history-show-deleted' ),
00139 'deleted', 'mw-show-deleted-only', $wgRequest->getBool( 'deleted' ) ) . "\n";
00140
00141 $action = htmlspecialchars( $wgScript );
00142 $wgOut->addHTML(
00143 "<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" .
00144 Xml::fieldset(
00145 wfMsg( 'history-fieldset-title' ),
00146 false,
00147 array( 'id' => 'mw-history-search' )
00148 ) .
00149 Xml::hidden( 'title', $this->title->getPrefixedDBKey() ) . "\n" .
00150 Xml::hidden( 'action', 'history' ) . "\n" .
00151 Xml::dateMenu( $year, $month ) . ' ' .
00152 ( $tagSelector ? ( implode( ' ', $tagSelector ) . ' ' ) : '' ) .
00153 $checkDeleted .
00154 Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
00155 '</fieldset></form>'
00156 );
00157
00158 wfRunHooks( 'PageHistoryBeforeList', array( &$this->article ) );
00159
00163 $pager = new HistoryPager( $this, $year, $month, $tagFilter, $conds );
00164 $wgOut->addHTML(
00165 $pager->getNavigationBar() .
00166 $pager->getBody() .
00167 $pager->getNavigationBar()
00168 );
00169 $wgOut->preventClickjacking( $pager->getPreventClickjacking() );
00170
00171 wfProfileOut( __METHOD__ );
00172 }
00173
00184 function fetchRevisions( $limit, $offset, $direction ) {
00185 $dbr = wfGetDB( DB_SLAVE );
00186
00187 if( $direction == HistoryPage::DIR_PREV )
00188 list($dirs, $oper) = array("ASC", ">=");
00189 else
00190 list($dirs, $oper) = array("DESC", "<=");
00191
00192 if( $offset )
00193 $offsets = array("rev_timestamp $oper '$offset'");
00194 else
00195 $offsets = array();
00196
00197 $page_id = $this->title->getArticleID();
00198
00199 return $dbr->select( 'revision',
00200 Revision::selectFields(),
00201 array_merge(array("rev_page=$page_id"), $offsets),
00202 __METHOD__,
00203 array( 'ORDER BY' => "rev_timestamp $dirs",
00204 'USE INDEX' => 'page_timestamp', 'LIMIT' => $limit)
00205 );
00206 }
00207
00213 function feed( $type ) {
00214 global $wgFeedClasses, $wgRequest, $wgFeedLimit;
00215 if( !FeedUtils::checkFeedOutput($type) ) {
00216 return;
00217 }
00218
00219 $feed = new $wgFeedClasses[$type](
00220 $this->title->getPrefixedText() . ' - ' .
00221 wfMsgForContent( 'history-feed-title' ),
00222 wfMsgForContent( 'history-feed-description' ),
00223 $this->title->getFullUrl( 'action=history' )
00224 );
00225
00226
00227
00228 $limit = $wgRequest->getInt( 'limit', 10 );
00229 if( $limit > $wgFeedLimit || $limit < 1 ) {
00230 $limit = 10;
00231 }
00232 $items = $this->fetchRevisions($limit, 0, HistoryPage::DIR_NEXT);
00233
00234 $feed->outHeader();
00235 if( $items ) {
00236 foreach( $items as $row ) {
00237 $feed->outItem( $this->feedItem( $row ) );
00238 }
00239 } else {
00240 $feed->outItem( $this->feedEmpty() );
00241 }
00242 $feed->outFooter();
00243 }
00244
00245 function feedEmpty() {
00246 global $wgOut;
00247 return new FeedItem(
00248 wfMsgForContent( 'nohistory' ),
00249 $wgOut->parse( wfMsgForContent( 'history-feed-empty' ) ),
00250 $this->title->getFullUrl(),
00251 wfTimestamp( TS_MW ),
00252 '',
00253 $this->title->getTalkPage()->getFullUrl()
00254 );
00255 }
00256
00265 function feedItem( $row ) {
00266 $rev = new Revision( $row );
00267 $rev->setTitle( $this->title );
00268 $text = FeedUtils::formatDiffRow(
00269 $this->title,
00270 $this->title->getPreviousRevisionID( $rev->getId() ),
00271 $rev->getId(),
00272 $rev->getTimestamp(),
00273 $rev->getComment()
00274 );
00275 if( $rev->getComment() == '' ) {
00276 global $wgContLang;
00277 $title = wfMsgForContent( 'history-feed-item-nocomment',
00278 $rev->getUserText(),
00279 $wgContLang->timeanddate( $rev->getTimestamp() ),
00280 $wgContLang->date( $rev->getTimestamp() ),
00281 $wgContLang->time( $rev->getTimestamp() )
00282 );
00283 } else {
00284 $title = $rev->getUserText() .
00285 wfMsgForContent( 'colon-separator' ) .
00286 FeedItem::stripComment( $rev->getComment() );
00287 }
00288 return new FeedItem(
00289 $title,
00290 $text,
00291 $this->title->getFullUrl( 'diff=' . $rev->getId() . '&oldid=prev' ),
00292 $rev->getTimestamp(),
00293 $rev->getUserText(),
00294 $this->title->getTalkPage()->getFullUrl()
00295 );
00296 }
00297 }
00298
00302 class HistoryPager extends ReverseChronologicalPager {
00303 public $lastRow = false, $counter, $historyPage, $title, $buttons, $conds;
00304 protected $oldIdChecked;
00305 protected $preventClickjacking = false;
00306
00307 function __construct( $historyPage, $year='', $month='', $tagFilter = '', $conds = array() ) {
00308 parent::__construct();
00309 $this->historyPage = $historyPage;
00310 $this->title = $this->historyPage->title;
00311 $this->tagFilter = $tagFilter;
00312 $this->getDateCond( $year, $month );
00313 $this->conds = $conds;
00314 }
00315
00316
00317 function getArticle() {
00318 return $this->historyPage->getArticle();
00319 }
00320
00321 function getSqlComment() {
00322 if ( $this->conds ) {
00323 return 'history page filtered';
00324 } else {
00325 return 'history page unfiltered';
00326 }
00327 }
00328
00329 function getQueryInfo() {
00330 $queryInfo = array(
00331 'tables' => array('revision'),
00332 'fields' => Revision::selectFields(),
00333 'conds' => array_merge(
00334 array( 'rev_page' => $this->historyPage->title->getArticleID() ),
00335 $this->conds ),
00336 'options' => array( 'USE INDEX' => array('revision' => 'page_timestamp') ),
00337 'join_conds' => array( 'tag_summary' => array( 'LEFT JOIN', 'ts_rev_id=rev_id' ) ),
00338 );
00339 ChangeTags::modifyDisplayQuery(
00340 $queryInfo['tables'],
00341 $queryInfo['fields'],
00342 $queryInfo['conds'],
00343 $queryInfo['join_conds'],
00344 $queryInfo['options'],
00345 $this->tagFilter
00346 );
00347 wfRunHooks( 'PageHistoryPager::getQueryInfo', array( &$this, &$queryInfo ) );
00348 return $queryInfo;
00349 }
00350
00351 function getIndexField() {
00352 return 'rev_timestamp';
00353 }
00354
00355 function formatRow( $row ) {
00356 if( $this->lastRow ) {
00357 $latest = ($this->counter == 1 && $this->mIsFirst);
00358 $firstInList = $this->counter == 1;
00359 $s = $this->historyLine( $this->lastRow, $row, $this->counter++,
00360 $this->title->getNotificationTimestamp(), $latest, $firstInList );
00361 } else {
00362 $s = '';
00363 }
00364 $this->lastRow = $row;
00365 return $s;
00366 }
00367
00373 function getStartBody() {
00374 global $wgScript, $wgUser, $wgOut, $wgContLang;
00375 $this->lastRow = false;
00376 $this->counter = 1;
00377 $this->oldIdChecked = 0;
00378
00379 $wgOut->wrapWikiMsg( "<div class='mw-history-legend'>\n$1</div>", 'histlegend' );
00380 $s = Xml::openElement( 'form', array( 'action' => $wgScript,
00381 'id' => 'mw-history-compare' ) ) . "\n";
00382 $s .= Xml::hidden( 'title', $this->title->getPrefixedDbKey() ) . "\n";
00383 $s .= Xml::hidden( 'action', 'historysubmit' ) . "\n";
00384
00385 $this->buttons = '<div>';
00386 if( $wgUser->isAllowed('deleterevision') ) {
00387 $this->preventClickjacking();
00388 $float = $wgContLang->alignEnd();
00389 # Note bug #20966, <button> is non-standard in IE<8
00390 $this->buttons .= Xml::element( 'button',
00391 array(
00392 'type' => 'submit',
00393 'name' => 'revisiondelete',
00394 'value' => '1',
00395 'style' => "float: $float;",
00396 'class' => 'mw-history-revisiondelete-button',
00397 ),
00398 wfMsg( 'showhideselectedversions' )
00399 ) . "\n";
00400 }
00401 $this->buttons .= $this->submitButton( wfMsg( 'compareselectedversions'),
00402 array(
00403 'class' => 'historysubmit',
00404 'accesskey' => wfMsg( 'accesskey-compareselectedversions' ),
00405 'title' => wfMsg( 'tooltip-compareselectedversions' ),
00406 )
00407 ) . "\n";
00408 $this->buttons .= '</div>';
00409 $s .= $this->buttons . '<ul id="pagehistory">' . "\n";
00410 return $s;
00411 }
00412
00413 function getEndBody() {
00414 if( $this->lastRow ) {
00415 $latest = $this->counter == 1 && $this->mIsFirst;
00416 $firstInList = $this->counter == 1;
00417 if( $this->mIsBackwards ) {
00418 # Next row is unknown, but for UI reasons, probably exists if an offset has been specified
00419 if( $this->mOffset == '' ) {
00420 $next = null;
00421 } else {
00422 $next = 'unknown';
00423 }
00424 } else {
00425 # The next row is the past-the-end row
00426 $next = $this->mPastTheEndRow;
00427 }
00428 $s = $this->historyLine( $this->lastRow, $next, $this->counter++,
00429 $this->title->getNotificationTimestamp(), $latest, $firstInList );
00430 } else {
00431 $s = '';
00432 }
00433 $s .= "</ul>\n";
00434 # Add second buttons only if there is more than one rev
00435 if( $this->getNumRows() > 2 ) {
00436 $s .= $this->buttons;
00437 }
00438 $s .= '</form>';
00439 return $s;
00440 }
00441
00449 function submitButton( $message, $attributes = array() ) {
00450 # Disable submit button if history has 1 revision only
00451 if( $this->getNumRows() > 1 ) {
00452 return Xml::submitButton( $message , $attributes );
00453 } else {
00454 return '';
00455 }
00456 }
00457
00471 function historyLine( $row, $next, $counter = '', $notificationtimestamp = false,
00472 $latest = false, $firstInList = false )
00473 {
00474 global $wgUser, $wgLang;
00475 $rev = new Revision( $row );
00476 $rev->setTitle( $this->title );
00477
00478 $curlink = $this->curLink( $rev, $latest );
00479 $lastlink = $this->lastLink( $rev, $next, $counter );
00480 $diffButtons = $this->diffButtons( $rev, $firstInList, $counter );
00481 $histLinks = Html::rawElement(
00482 'span',
00483 array( 'class' => 'mw-history-histlinks' ),
00484 '(' . $curlink . $this->historyPage->message['pipe-separator'] . $lastlink . ') '
00485 );
00486 $s = $histLinks . $diffButtons;
00487
00488 $link = $this->revLink( $rev );
00489 $classes = array();
00490
00491 $del = '';
00492
00493 if( $wgUser->isAllowed( 'deleterevision' ) ) {
00494 $this->preventClickjacking();
00495
00496 if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
00497 $del = Xml::check( 'deleterevisions', false, array( 'disabled' => 'disabled' ) );
00498
00499 } else {
00500 $del = Xml::check( 'showhiderevisions', false,
00501 array( 'name' => 'ids['.$rev->getId().']' ) );
00502 }
00503
00504 } else if( $rev->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) {
00505
00506 if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
00507 $cdel = $this->getSkin()->revDeleteLinkDisabled( false );
00508
00509 } else {
00510 $query = array( 'type' => 'revision',
00511 'target' => $this->title->getPrefixedDbkey(), 'ids' => $rev->getId() );
00512 $del .= $this->getSkin()->revDeleteLink( $query,
00513 $rev->isDeleted( Revision::DELETED_RESTRICTED ), false );
00514 }
00515 }
00516 if( $del ) $s .= " $del ";
00517
00518 $s .= " $link";
00519 $s .= " <span class='history-user'>" .
00520 $this->getSkin()->revUserTools( $rev, true ) . "</span>";
00521
00522 if( $rev->isMinor() ) {
00523 $s .= ' ' . ChangesList::flag( 'minor' );
00524 }
00525
00526 if( !is_null( $size = $rev->getSize() ) && !$rev->isDeleted( Revision::DELETED_TEXT ) ) {
00527 $s .= ' ' . $this->getSkin()->formatRevisionSize( $size );
00528 }
00529
00530 $s .= $this->getSkin()->revComment( $rev, false, true );
00531
00532 if( $notificationtimestamp && ($row->rev_timestamp >= $notificationtimestamp) ) {
00533 $s .= ' <span class="updatedmarker">' . wfMsgHtml( 'updatedmarker' ) . '</span>';
00534 }
00535
00536 $tools = array();
00537
00538 # Rollback and undo links
00539 if( !is_null( $next ) && is_object( $next ) ) {
00540 if( $latest && $this->title->userCan( 'rollback' ) && $this->title->userCan( 'edit' ) ) {
00541 $this->preventClickjacking();
00542 $tools[] = '<span class="mw-rollback-link">'.
00543 $this->getSkin()->buildRollbackLink( $rev ).'</span>';
00544 }
00545
00546 if( $this->title->quickUserCan( 'edit' )
00547 && !$rev->isDeleted( Revision::DELETED_TEXT )
00548 && !$next->rev_deleted & Revision::DELETED_TEXT )
00549 {
00550 # Create undo tooltip for the first (=latest) line only
00551 $undoTooltip = $latest
00552 ? array( 'title' => wfMsg( 'tooltip-undo' ) )
00553 : array();
00554 $undolink = $this->getSkin()->link(
00555 $this->title,
00556 wfMsgHtml( 'editundo' ),
00557 $undoTooltip,
00558 array(
00559 'action' => 'edit',
00560 'undoafter' => $next->rev_id,
00561 'undo' => $rev->getId()
00562 ),
00563 array( 'known', 'noclasses' )
00564 );
00565 $tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>";
00566 }
00567 }
00568
00569 if( $tools ) {
00570 $s .= ' (' . $wgLang->pipeList( $tools ) . ')';
00571 }
00572
00573 # Tags
00574 list($tagSummary, $newClasses) = ChangeTags::formatSummaryRow( $row->ts_tags, 'history' );
00575 $classes = array_merge( $classes, $newClasses );
00576 $s .= " $tagSummary";
00577
00578 wfRunHooks( 'PageHistoryLineEnding', array( $this, &$row , &$s, &$classes ) );
00579
00580 $attribs = array();
00581 if ( $classes ) {
00582 $attribs['class'] = implode( ' ', $classes );
00583 }
00584
00585 return Xml::tags( 'li', $attribs, $s ) . "\n";
00586 }
00587
00594 function revLink( $rev ) {
00595 global $wgLang;
00596 $date = $wgLang->timeanddate( wfTimestamp(TS_MW, $rev->getTimestamp()), true );
00597 $date = htmlspecialchars( $date );
00598 if( !$rev->isDeleted( Revision::DELETED_TEXT ) ) {
00599 $link = $this->getSkin()->link(
00600 $this->title,
00601 $date,
00602 array(),
00603 array( 'oldid' => $rev->getId() ),
00604 array( 'known', 'noclasses' )
00605 );
00606 } else {
00607 $link = "<span class=\"history-deleted\">$date</span>";
00608 }
00609 return $link;
00610 }
00611
00619 function curLink( $rev, $latest ) {
00620 $cur = $this->historyPage->message['cur'];
00621 if( $latest || !$rev->userCan( Revision::DELETED_TEXT ) ) {
00622 return $cur;
00623 } else {
00624 return $this->getSkin()->link(
00625 $this->title,
00626 $cur,
00627 array(),
00628 array(
00629 'diff' => $this->title->getLatestRevID(),
00630 'oldid' => $rev->getId()
00631 ),
00632 array( 'known', 'noclasses' )
00633 );
00634 }
00635 }
00636
00645 function lastLink( $prevRev, $next, $counter ) {
00646 $last = $this->historyPage->message['last'];
00647 # $next may either be a Row, null, or "unkown"
00648 $nextRev = is_object($next) ? new Revision( $next ) : $next;
00649 if( is_null($next) ) {
00650 # Probably no next row
00651 return $last;
00652 } elseif( $next === 'unknown' ) {
00653 # Next row probably exists but is unknown, use an oldid=prev link
00654 return $this->getSkin()->link(
00655 $this->title,
00656 $last,
00657 array(),
00658 array(
00659 'diff' => $prevRev->getId(),
00660 'oldid' => 'prev'
00661 ),
00662 array( 'known', 'noclasses' )
00663 );
00664 } elseif( !$prevRev->userCan(Revision::DELETED_TEXT)
00665 || !$nextRev->userCan(Revision::DELETED_TEXT) )
00666 {
00667 return $last;
00668 } else {
00669 return $this->getSkin()->link(
00670 $this->title,
00671 $last,
00672 array(),
00673 array(
00674 'diff' => $prevRev->getId(),
00675 'oldid' => $next->rev_id
00676 ),
00677 array( 'known', 'noclasses' )
00678 );
00679 }
00680 }
00681
00690 function diffButtons( $rev, $firstInList, $counter ) {
00691 if( $this->getNumRows() > 1 ) {
00692 $id = $rev->getId();
00693 $radio = array( 'type' => 'radio', 'value' => $id );
00695 if( $firstInList ) {
00696 $first = Xml::element( 'input',
00697 array_merge( $radio, array(
00698 'style' => 'visibility:hidden',
00699 'name' => 'oldid',
00700 'id' => 'mw-oldid-null' ) )
00701 );
00702 $checkmark = array( 'checked' => 'checked' );
00703 } else {
00704 # Check visibility of old revisions
00705 if( !$rev->userCan( Revision::DELETED_TEXT ) ) {
00706 $radio['disabled'] = 'disabled';
00707 $checkmark = array();
00708 } else if( $counter == 2 || !$this->oldIdChecked ) {
00709 $checkmark = array( 'checked' => 'checked' );
00710 $this->oldIdChecked = $id;
00711 } else {
00712 $checkmark = array();
00713 }
00714 $first = Xml::element( 'input',
00715 array_merge( $radio, $checkmark, array(
00716 'name' => 'oldid',
00717 'id' => "mw-oldid-$id" ) ) );
00718 $checkmark = array();
00719 }
00720 $second = Xml::element( 'input',
00721 array_merge( $radio, $checkmark, array(
00722 'name' => 'diff',
00723 'id' => "mw-diff-$id" ) ) );
00724 return $first . $second;
00725 } else {
00726 return '';
00727 }
00728 }
00729
00733 function preventClickjacking( $enable = true ) {
00734 $this->preventClickjacking = $enable;
00735 }
00736
00740 function getPreventClickjacking() {
00741 return $this->preventClickjacking;
00742 }
00743 }
00744
00748 class PageHistory extends HistoryPage {}
00749 class PageHistoryPager extends HistoryPager {}