<?php
/**
- * Handles action=history.
+ * Page history
+ *
* Split off from Article.php and Skin.php, 2003-12-22
*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
* @file
*/
* This class handles printing the history page for an article. In order to
* be efficient, it uses timestamps rather than offsets for paging, to avoid
* costly LIMIT,offset queries.
+ *
+ * Construct it by passing in an Article, and call $h->history() to print the
+ * history.
+ *
*/
class HistoryAction extends FormlessAction {
const DIR_PREV = 0;
return 'history';
}
- public function getRestriction() {
- return 'read';
+ public function requiresWrite() {
+ return false;
+ }
+
+ public function requiresUnblock() {
+ return false;
+ }
+
+ protected function getPageTitle() {
+ return $this->msg( 'history-title', $this->getTitle()->getPrefixedText() )->text();
+ }
+
+ protected function getDescription() {
+ // Creation of a subtitle link pointing to [[Special:Log]]
+ return Linker::linkKnown(
+ SpecialPage::getTitleFor( 'Log' ),
+ $this->msg( 'viewpagelogs' )->escaped(),
+ array(),
+ array( 'page' => $this->getTitle()->getPrefixedText() )
+ );
}
/**
- * Get the Page object we are working on.
- *
+ * Get the Article object we are working on.
* @return Page
*/
public function getArticle() {
if ( !isset( $this->message ) ) {
$msgs = array( 'cur', 'last', 'pipe-separator' );
foreach ( $msgs as $msg ) {
- $this->message[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
+ $this->message[$msg] = $this->msg( $msg )->escaped();
}
}
}
/**
* Print the history page for an article.
- * @return nothing
*/
function onView() {
- global $wgSquidMaxage, $wgScript;
+ global $wgScript, $wgUseFileCache;
$out = $this->getOutput();
$request = $this->getRequest();
- // Allow client caching.
+ /**
+ * Allow client caching.
+ */
if ( $out->checkLastModified( $this->page->getTouched() ) ) {
return; // Client cache fresh and headers sent, nothing more to do.
}
- if ( $request->getFullRequestURL() == $this->getTitle()->getInternalURL( 'action=history' ) ) {
- $out->setSquidMaxage( $wgSquidMaxage );
- }
-
wfProfileIn( __METHOD__ );
$this->preCacheMessages();
+ # Fill in the file cache if not set already
+ if ( $wgUseFileCache && HTMLFileCache::useFileCache( $this->getContext() ) ) {
+ $cache = HTMLFileCache::newFromTitle( $this->getTitle(), 'history' );
+ if ( !$cache->isCacheGood( /* Assume up to date */ ) ) {
+ ob_start( array( &$cache, 'saveToFileCache' ) );
+ }
+ }
+
// Setup page variables.
- $out->setPageTitle( wfMsg( 'history-title', $this->getTitle()->getPrefixedText() ) );
- $out->setRobotPolicy( 'noindex,nofollow' );
$out->setFeedAppendQuery( 'action=history' );
$out->addModules( array( 'mediawiki.legacy.history', 'mediawiki.action.history' ) );
- // Creation of a subtitle link pointing to [[Special:Log]]
- $logPage = SpecialPage::getTitleFor( 'Log' );
- $logLink = Linker::linkKnown(
- $logPage,
- wfMsgHtml( 'viewpagelogs' ),
- array(),
- array( 'page' => $this->getTitle()->getPrefixedText() )
- );
- $out->setSubtitle( $logLink );
-
// Handle atom/RSS feeds.
$feedType = $request->getVal( 'feed' );
if ( $feedType ) {
+ $this->feed( $feedType );
wfProfileOut( __METHOD__ );
- return $this->feed( $feedType );
+ return;
}
// Fail nicely if article doesn't exist.
- if ( !$this->getTitle()->exists() ) {
+ if ( !$this->page->exists() ) {
$out->addWikiMsg( 'nohistory' );
# show deletion/move log if there is an entry
LogEventsList::showLogExtract(
$out,
array( 'delete', 'move' ),
- $this->getTitle()->getPrefixedText(),
+ $this->getTitle(),
'',
array( 'lim' => 10,
'conds' => array( "log_action != 'revision'" ),
} else {
$conds = array();
}
- $checkDeleted = Xml::checkLabel( wfMsg( 'history-show-deleted' ),
+ $checkDeleted = Xml::checkLabel( $this->msg( 'history-show-deleted' )->text(),
'deleted', 'mw-show-deleted-only', $request->getBool( 'deleted' ) ) . "\n";
// Add the general form
$out->addHTML(
"<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" .
Xml::fieldset(
- wfMsg( 'history-fieldset-title' ),
+ $this->msg( 'history-fieldset-title' )->text(),
false,
array( 'id' => 'mw-history-search' )
) .
Xml::dateMenu( $year, $month ) . ' ' .
( $tagSelector ? ( implode( ' ', $tagSelector ) . ' ' ) : '' ) .
$checkDeleted .
- Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
+ Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
'</fieldset></form>'
);
*
* @param $limit Integer: the limit number of revisions to get
* @param $offset Integer
- * @param $direction Integer: either HistoryAction::DIR_PREV or HistoryAction::DIR_NEXT
+ * @param $direction Integer: either HistoryPage::DIR_PREV or HistoryPage::DIR_NEXT
* @return ResultWrapper
*/
function fetchRevisions( $limit, $offset, $direction ) {
+ // Fail if article doesn't exist.
+ if( !$this->getTitle()->exists() ) {
+ return new FakeResultWrapper( array() );
+ }
+
$dbr = wfGetDB( DB_SLAVE );
- if ( $direction == self::DIR_PREV ) {
+ if ( $direction == HistoryPage::DIR_PREV ) {
list( $dirs, $oper ) = array( "ASC", ">=" );
- } else { /* $direction == self::DIR_NEXT */
+ } else { /* $direction == HistoryPage::DIR_NEXT */
list( $dirs, $oper ) = array( "DESC", "<=" );
}
$offsets = array();
}
- $page_id = $this->getTitle()->getArticleID();
+ $page_id = $this->page->getId();
return $dbr->select( 'revision',
Revision::selectFields(),
if ( !FeedUtils::checkFeedOutput( $type ) ) {
return;
}
+ $request = $this->getRequest();
$feed = new $wgFeedClasses[$type](
$this->getTitle()->getPrefixedText() . ' - ' .
// Get a limit on number of feed entries. Provide a sane default
// of 10 if none is defined (but limit to $wgFeedLimit max)
- $limit = $this->getRequest()->getInt( 'limit', 10 );
+ $limit = $request->getInt( 'limit', 10 );
if ( $limit > $wgFeedLimit || $limit < 1 ) {
$limit = 10;
}
- $items = $this->fetchRevisions( $limit, 0, self::DIR_NEXT );
+ $items = $this->fetchRevisions( $limit, 0, HistoryPage::DIR_NEXT );
// Generate feed elements enclosed between header and footer.
$feed->outHeader();
*/
function feedItem( $row ) {
$rev = new Revision( $row );
- $titleObj = $this->getTitle();
- $rev->setTitle( $titleObj );
+ $rev->setTitle( $this->getTitle() );
$text = FeedUtils::formatDiffRow(
- $titleObj,
- $titleObj->getPreviousRevisionID( $rev->getId() ),
+ $this->getTitle(),
+ $this->getTitle()->getPreviousRevisionID( $rev->getId() ),
$rev->getId(),
$rev->getTimestamp(),
$rev->getComment()
return new FeedItem(
$title,
$text,
- $titleObj->getFullUrl( 'diff=' . $rev->getId() . '&oldid=prev' ),
+ $this->getTitle()->getFullUrl( 'diff=' . $rev->getId() . '&oldid=prev' ),
$rev->getTimestamp(),
$rev->getUserText(),
- $titleObj->getTalkPage()->getFullUrl()
+ $this->getTitle()->getTalkPage()->getFullUrl()
);
}
}
* @ingroup Pager
*/
class HistoryPager extends ReverseChronologicalPager {
- public $lastRow = false, $counter, $history, $buttons, $conds;
+ public $lastRow = false, $counter, $historyPage, $buttons, $conds;
protected $oldIdChecked;
protected $preventClickjacking = false;
+ /**
+ * @var array
+ */
+ protected $parentLens;
- function __construct( $history, $year = '', $month = '', $tagFilter = '', $conds = array() ) {
- parent::__construct();
- $this->history = $history;
+ function __construct( $historyPage, $year = '', $month = '', $tagFilter = '', $conds = array() ) {
+ parent::__construct( $historyPage->getContext() );
+ $this->historyPage = $historyPage;
$this->tagFilter = $tagFilter;
$this->getDateCond( $year, $month );
$this->conds = $conds;
// For hook compatibility...
function getArticle() {
- return $this->history->getArticle();
+ return $this->historyPage->getArticle();
}
function getSqlComment() {
function getQueryInfo() {
$queryInfo = array(
- 'tables' => array( 'revision' ),
- 'fields' => Revision::selectFields(),
+ 'tables' => array( 'revision', 'user' ),
+ 'fields' => array_merge( Revision::selectFields(), Revision::selectUserFields() ),
'conds' => array_merge(
- array( 'rev_page' => $this->getTitle()->getArticleID() ),
+ array( 'rev_page' => $this->getWikiPage()->getId() ),
$this->conds ),
'options' => array( 'USE INDEX' => array( 'revision' => 'page_timestamp' ) ),
- 'join_conds' => array( 'tag_summary' => array( 'LEFT JOIN', 'ts_rev_id=rev_id' ) ),
+ 'join_conds' => array(
+ 'user' => Revision::userJoinCond(),
+ 'tag_summary' => array( 'LEFT JOIN', 'ts_rev_id=rev_id' ) ),
);
ChangeTags::modifyDisplayQuery(
$queryInfo['tables'],
$firstInList = $this->counter == 1;
$this->counter++;
$s = $this->historyLine( $this->lastRow, $row,
- $this->getTitle()->getNotificationTimestamp(), $latest, $firstInList );
+ $this->getTitle()->getNotificationTimestamp( $this->getUser() ), $latest, $firstInList );
} else {
$s = '';
}
return $s;
}
+ function doBatchLookups() {
+ # Do a link batch query
+ $this->mResult->seek( 0 );
+ $batch = new LinkBatch();
+ $revIds = array();
+ foreach ( $this->mResult as $row ) {
+ if( $row->rev_parent_id ) {
+ $revIds[] = $row->rev_parent_id;
+ }
+ if( !is_null( $row->user_name ) ) {
+ $batch->add( NS_USER, $row->user_name );
+ $batch->add( NS_USER_TALK, $row->user_name );
+ } else { # for anons or usernames of imported revisions
+ $batch->add( NS_USER, $row->rev_user_text );
+ $batch->add( NS_USER_TALK, $row->rev_user_text );
+ }
+ }
+ $this->parentLens = $this->getParentLengths( $revIds );
+ $batch->execute();
+ $this->mResult->seek( 0 );
+ }
+
+ /**
+ * Do a batched query to get the parent revision lengths
+ * @param $revIds array
+ * @return array
+ * @TODO: stolen from Contributions, refactor
+ */
+ private function getParentLengths( array $revIds ) {
+ $revLens = array();
+ if ( !$revIds ) {
+ return $revLens; // empty
+ }
+ wfProfileIn( __METHOD__ );
+ $res = $this->mDb->select( 'revision',
+ array( 'rev_id', 'rev_len' ),
+ array( 'rev_id' => $revIds ),
+ __METHOD__ );
+ foreach ( $res as $row ) {
+ $revLens[$row->rev_id] = $row->rev_len;
+ }
+ wfProfileOut( __METHOD__ );
+ return $revLens;
+ }
+
/**
* Creates begin of history list with a submit button
*
$s .= Html::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) . "\n";
$s .= Html::hidden( 'action', 'historysubmit' ) . "\n";
- $s .= '<div>' . $this->submitButton( wfMsg( 'compareselectedversions' ),
- array( 'class' => 'historysubmit' ) ) . "\n";
-
+ // Button container stored in $this->buttons for re-use in getEndBody()
$this->buttons = '<div>';
- $this->buttons .= $this->submitButton( wfMsg( 'compareselectedversions' ),
- array( 'class' => 'historysubmit' )
+ $this->buttons .= $this->submitButton( $this->msg( 'compareselectedversions' )->text(),
+ array( 'class' => 'historysubmit mw-history-compareselectedversions-button' )
+ Linker::tooltipAndAccesskeyAttribs( 'compareselectedversions' )
) . "\n";
if ( $this->getUser()->isAllowed( 'deleterevision' ) ) {
- $s .= $this->getRevisionButton( 'revisiondelete', 'showhideselectedversions' );
+ $this->buttons .= $this->getRevisionButton( 'revisiondelete', 'showhideselectedversions' );
}
$this->buttons .= '</div>';
- $s .= '</div><ul id="pagehistory">' . "\n";
+
+ $s .= $this->buttons;
+ $s .= '<ul id="pagehistory">' . "\n";
return $s;
}
'type' => 'submit',
'name' => $name,
'value' => '1',
- 'class' => "mw-history-$name-button mw-float-end",
+ 'class' => "historysubmit mw-history-$name-button",
),
- wfMsg( $msg )
+ $this->msg( $msg )->text()
) . "\n";
- $this->buttons .= $element;
return $element;
}
}
$this->counter++;
$s = $this->historyLine( $this->lastRow, $next,
- $this->getTitle()->getNotificationTimestamp(), $latest, $firstInList );
+ $this->getTitle()->getNotificationTimestamp( $this->getUser() ), $latest, $firstInList );
} else {
$s = '';
}
* @todo document some more, and maybe clean up the code (some params redundant?)
*
* @param $row Object: the database row corresponding to the previous line.
- * @param $next Mixed: the database row corresponding to the next line.
+ * @param $next Mixed: the database row corresponding to the next line. (chronologically previous)
* @param $notificationtimestamp
* @param $latest Boolean: whether this row corresponds to the page's latest revision.
* @param $firstInList Boolean: whether this row corresponds to the first displayed on this history page.
$rev = new Revision( $row );
$rev->setTitle( $this->getTitle() );
+ if ( is_object( $next ) ) {
+ $prevRev = new Revision( $next );
+ $prevRev->setTitle( $this->getTitle() );
+ } else {
+ $prevRev = null;
+ }
+
$curlink = $this->curLink( $rev, $latest );
$lastlink = $this->lastLink( $rev, $next );
$diffButtons = $this->diffButtons( $rev, $firstInList );
$histLinks = Html::rawElement(
'span',
array( 'class' => 'mw-history-histlinks' ),
- '(' . $curlink . $this->history->message['pipe-separator'] . $lastlink . ') '
+ $this->msg( 'parentheses' )->rawParams( $curlink . $this->historyPage->message['pipe-separator'] . $lastlink )->escaped()
);
$s = $histLinks . $diffButtons;
$classes = array();
$del = '';
+ $user = $this->getUser();
// Show checkboxes for each revision
- if ( $this->getUser()->isAllowed( 'deleterevision' ) ) {
+ if ( $user->isAllowed( 'deleterevision' ) ) {
$this->preventClickjacking();
// If revision was hidden from sysops, disable the checkbox
- if ( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
+ if ( !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
$del = Xml::check( 'deleterevisions', false, array( 'disabled' => 'disabled' ) );
// Otherwise, enable the checkbox...
} else {
array( 'name' => 'ids[' . $rev->getId() . ']' ) );
}
// User can only view deleted revisions...
- } elseif ( $rev->getVisibility() && $this->getUser()->isAllowed( 'deletedhistory' ) ) {
+ } elseif ( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) {
// If revision was hidden from sysops, disable the link
- if ( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
+ if ( !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
$cdel = Linker::revDeleteLinkDisabled( false );
// Otherwise, show the link...
} else {
$s .= " $del ";
}
- $dirmark = $this->getLang()->getDirMark();
+ $lang = $this->getLanguage();
+ $dirmark = $lang->getDirMark();
$s .= " $link";
$s .= $dirmark;
$s .= ' ' . ChangesList::flag( 'minor' );
}
- if ( !is_null( $size = $rev->getSize() ) && !$rev->isDeleted( Revision::DELETED_TEXT ) ) {
- $s .= ' ' . Linker::formatRevisionSize( $size );
- }
+ # Size is always public data
+ $prevSize = isset( $this->parentLens[$row->rev_parent_id] )
+ ? $this->parentLens[$row->rev_parent_id]
+ : 0;
+ $sDiff = ChangesList::showCharacterDifference( $prevSize, $rev->getSize() );
+ $fSize = Linker::formatRevisionSize($rev->getSize());
+ $s .= " . . $fSize $sDiff";
- $s .= Linker::revComment( $rev, false, true );
+ # Text following the character difference is added just before running hooks
+ $s2 = Linker::revComment( $rev, false, true );
if ( $notificationtimestamp && ( $row->rev_timestamp >= $notificationtimestamp ) ) {
- $s .= ' <span class="updatedmarker">' . wfMsgHtml( 'updatedmarker' ) . '</span>';
+ $s2 .= ' <span class="updatedmarker">' . $this->msg( 'updatedmarker' )->escaped() . '</span>';
}
$tools = array();
# Rollback and undo links
- if ( !is_null( $next ) && is_object( $next ) ) {
- if ( $latest && $this->getTitle()->userCan( 'rollback' ) && $this->getTitle()->userCan( 'edit' ) ) {
+ if ( $prevRev &&
+ !count( $this->getTitle()->getUserPermissionsErrors( 'edit', $this->getUser() ) ) )
+ {
+ if ( $latest && !count( $this->getTitle()->getUserPermissionsErrors( 'rollback', $this->getUser() ) ) ) {
$this->preventClickjacking();
$tools[] = '<span class="mw-rollback-link">' .
Linker::buildRollbackLink( $rev ) . '</span>';
}
- if ( $this->getTitle()->quickUserCan( 'edit' )
- && !$rev->isDeleted( Revision::DELETED_TEXT )
- && !$next->rev_deleted & Revision::DELETED_TEXT )
+ if ( !$rev->isDeleted( Revision::DELETED_TEXT )
+ && !$prevRev->isDeleted( Revision::DELETED_TEXT ) )
{
# Create undo tooltip for the first (=latest) line only
$undoTooltip = $latest
- ? array( 'title' => wfMsg( 'tooltip-undo' ) )
+ ? array( 'title' => $this->msg( 'tooltip-undo' )->text() )
: array();
$undolink = Linker::linkKnown(
$this->getTitle(),
- wfMsgHtml( 'editundo' ),
+ $this->msg( 'editundo' )->escaped(),
$undoTooltip,
array(
- 'action' => 'edit',
- 'undoafter' => $next->rev_id,
- 'undo' => $rev->getId()
+ 'action' => 'edit',
+ 'undoafter' => $prevRev->getId(),
+ 'undo' => $rev->getId()
)
);
$tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>";
}
if ( $tools ) {
- $s .= ' (' . $this->getLang()->pipeList( $tools ) . ')';
+ $s2 .= ' '. $this->msg( 'parentheses' )->rawParams( $lang->pipeList( $tools ) )->escaped();
}
# Tags
list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow( $row->ts_tags, 'history' );
$classes = array_merge( $classes, $newClasses );
- $s .= " $tagSummary";
+ if ( $tagSummary !== '' ) {
+ $s2 .= " $tagSummary";
+ }
+
+ # Include separator between character difference and following text
+ if ( $s2 !== '' ) {
+ $s .= " . . $s2";
+ }
wfRunHooks( 'PageHistoryLineEnding', array( $this, &$row , &$s, &$classes ) );
* @return String
*/
function revLink( $rev ) {
- $date = $this->getLang()->timeanddate( wfTimestamp( TS_MW, $rev->getTimestamp() ), true );
+ $date = $this->getLanguage()->userTimeAndDate( $rev->getTimestamp(), $this->getUser() );
$date = htmlspecialchars( $date );
- if ( $rev->userCan( Revision::DELETED_TEXT ) ) {
+ if ( $rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
$link = Linker::linkKnown(
$this->getTitle(),
$date,
* @return String
*/
function curLink( $rev, $latest ) {
- $cur = $this->history->message['cur'];
- if ( $latest || !$rev->userCan( Revision::DELETED_TEXT ) ) {
+ $cur = $this->historyPage->message['cur'];
+ if ( $latest || !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
return $cur;
} else {
return Linker::linkKnown(
$cur,
array(),
array(
- 'diff' => $this->getTitle()->getLatestRevID(),
+ 'diff' => $this->getWikiPage()->getLatest(),
'oldid' => $rev->getId()
)
);
* @return String
*/
function lastLink( $prevRev, $next ) {
- $last = $this->history->message['last'];
+ $last = $this->historyPage->message['last'];
# $next may either be a Row, null, or "unkown"
$nextRev = is_object( $next ) ? new Revision( $next ) : $next;
if ( is_null( $next ) ) {
return $last;
} elseif ( $next === 'unknown' ) {
# Next row probably exists but is unknown, use an oldid=prev link
- return Linker::link(
+ return Linker::linkKnown(
$this->getTitle(),
$last,
array(),
'oldid' => 'prev'
)
);
- } elseif ( !$prevRev->userCan( Revision::DELETED_TEXT )
- || !$nextRev->userCan( Revision::DELETED_TEXT ) )
+ } elseif ( !$prevRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
+ || !$nextRev->userCan( Revision::DELETED_TEXT, $this->getUser() ) )
{
return $last;
} else {
$checkmark = array( 'checked' => 'checked' );
} else {
# Check visibility of old revisions
- if ( !$rev->userCan( Revision::DELETED_TEXT ) ) {
+ if ( !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
$radio['disabled'] = 'disabled';
$checkmark = array(); // We will check the next possible one
} elseif ( !$this->oldIdChecked ) {
/**
* Get the "prevent clickjacking" flag
+ * @return bool
*/
function getPreventClickjacking() {
return $this->preventClickjacking;
}
/**
- * Backwards-compatibility aliases
+ * Backwards-compatibility alias
*/
class HistoryPage extends HistoryAction {
public function __construct( Page $article ) { # Just to make it public