* history.
*
*/
-class HistoryPage {
+class HistoryPage extends ContextSource {
const DIR_PREV = 0;
const DIR_NEXT = 1;
- /** Contains the Article object. Passed on construction. */
- private $article;
- /** The $article title object. Found on construction. */
- private $title;
- /** Shortcut to the user Skin object. */
- private $skin;
+ /** Contains the Page object. Passed on construction. */
+ protected $article;
/**
* Construct a new HistoryPage.
*
* @param $article Article
*/
- function __construct( $article ) {
- global $wgUser;
- $this->article = $article;
- $this->title = $article->getTitle();
- $this->skin = $wgUser->getSkin();
+ function __construct( Page $page, IContextSource $context ) {
+ $this->article = $page;
+ $this->context = clone $context; // don't clobber the main context
+ $this->context->setTitle( $page->getTitle() ); // must match
$this->preCacheMessages();
}
- /** Get the Article object we are working on. */
+ /**
+ * Get the Article object we are working on.
+ * @return Page
+ */
public function getArticle() {
return $this->article;
}
- /** Get the Title object. */
- public function getTitle() {
- return $this->title;
- }
-
/**
* As we use the same small set of messages in various methods and that
* they are called often, we call them once and save them in $this->message
* @return nothing
*/
function history() {
- global $wgOut, $wgRequest, $wgScript;
+ global $wgScript, $wgUseFileCache;
+ $out = $this->getOutput();
+ $request = $this->getRequest();
/**
* Allow client caching.
*/
- if ( $wgOut->checkLastModified( $this->article->getTouched() ) )
+ if ( $out->checkLastModified( $this->article->getTouched() ) ) {
return; // Client cache fresh and headers sent, nothing more to do.
+ }
wfProfileIn( __METHOD__ );
+ # 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.
- $wgOut->setPageTitle( wfMsg( 'history-title', $this->title->getPrefixedText() ) );
- $wgOut->setPageTitleActionText( wfMsg( 'history_short' ) );
- $wgOut->setArticleFlag( false );
- $wgOut->setArticleRelated( true );
- $wgOut->setRobotPolicy( 'noindex,nofollow' );
- $wgOut->setSyndicated( true );
- $wgOut->setFeedAppendQuery( 'action=history' );
- $wgOut->addModules( array( 'mediawiki.legacy.history', 'mediawiki.views.history' ) );
+ $out->setPageTitle( wfMsg( 'history-title', $this->getTitle()->getPrefixedText() ) );
+ $out->setPageTitleActionText( wfMsg( 'history_short' ) );
+ $out->setArticleFlag( false );
+ $out->setArticleRelated( true );
+ $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 = $this->skin->link(
+ $logLink = Linker::linkKnown(
$logPage,
wfMsgHtml( 'viewpagelogs' ),
array(),
- array( 'page' => $this->title->getPrefixedText() ),
- array( 'known', 'noclasses' )
+ array( 'page' => $this->getTitle()->getPrefixedText() )
);
- $wgOut->setSubtitle( $logLink );
+ $out->setSubtitle( $logLink );
// Handle atom/RSS feeds.
- $feedType = $wgRequest->getVal( 'feed' );
+ $feedType = $request->getVal( 'feed' );
if ( $feedType ) {
wfProfileOut( __METHOD__ );
return $this->feed( $feedType );
}
// Fail nicely if article doesn't exist.
- if ( !$this->title->exists() ) {
- $wgOut->addWikiMsg( 'nohistory' );
+ if ( !$this->getTitle()->exists() ) {
+ $out->addWikiMsg( 'nohistory' );
# show deletion/move log if there is an entry
LogEventsList::showLogExtract(
- $wgOut,
+ $out,
array( 'delete', 'move' ),
- $this->title->getPrefixedText(),
+ $this->getTitle(),
'',
array( 'lim' => 10,
'conds' => array( "log_action != 'revision'" ),
/**
* Add date selector to quickly get to a certain time
*/
- $year = $wgRequest->getInt( 'year' );
- $month = $wgRequest->getInt( 'month' );
- $tagFilter = $wgRequest->getVal( 'tagfilter' );
+ $year = $request->getInt( 'year' );
+ $month = $request->getInt( 'month' );
+ $tagFilter = $request->getVal( 'tagfilter' );
$tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter );
/**
* Option to show only revisions that have been (partially) hidden via RevisionDelete
*/
- if ( $wgRequest->getBool( 'deleted' ) ) {
+ if ( $request->getBool( 'deleted' ) ) {
$conds = array( "rev_deleted != '0'" );
} else {
$conds = array();
}
$checkDeleted = Xml::checkLabel( wfMsg( 'history-show-deleted' ),
- 'deleted', 'mw-show-deleted-only', $wgRequest->getBool( 'deleted' ) ) . "\n";
+ 'deleted', 'mw-show-deleted-only', $request->getBool( 'deleted' ) ) . "\n";
// Add the general form
$action = htmlspecialchars( $wgScript );
- $wgOut->addHTML(
+ $out->addHTML(
"<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" .
Xml::fieldset(
wfMsg( 'history-fieldset-title' ),
false,
array( 'id' => 'mw-history-search' )
) .
- Html::hidden( 'title', $this->title->getPrefixedDBKey() ) . "\n" .
+ Html::hidden( 'title', $this->getTitle()->getPrefixedDBKey() ) . "\n" .
Html::hidden( 'action', 'history' ) . "\n" .
Xml::dateMenu( $year, $month ) . ' ' .
( $tagSelector ? ( implode( ' ', $tagSelector ) . ' ' ) : '' ) .
// Create and output the list.
$pager = new HistoryPager( $this, $year, $month, $tagFilter, $conds );
- $wgOut->addHTML(
+ $out->addHTML(
$pager->getNavigationBar() .
$pager->getBody() .
$pager->getNavigationBar()
);
+ $out->preventClickjacking( $pager->getPreventClickjacking() );
wfProfileOut( __METHOD__ );
}
$offsets = array();
}
- $page_id = $this->title->getArticleID();
+ $page_id = $this->getTitle()->getArticleID();
return $dbr->select( 'revision',
Revision::selectFields(),
* @param $type String: feed type
*/
function feed( $type ) {
- global $wgFeedClasses, $wgRequest, $wgFeedLimit;
+ global $wgFeedClasses, $wgFeedLimit;
if ( !FeedUtils::checkFeedOutput( $type ) ) {
return;
}
+ $request = $this->getRequest();
$feed = new $wgFeedClasses[$type](
- $this->title->getPrefixedText() . ' - ' .
+ $this->getTitle()->getPrefixedText() . ' - ' .
wfMsgForContent( 'history-feed-title' ),
wfMsgForContent( 'history-feed-description' ),
- $this->title->getFullUrl( 'action=history' )
+ $this->getTitle()->getFullUrl( 'action=history' )
);
// Get a limit on number of feed entries. Provide a sane default
// of 10 if none is defined (but limit to $wgFeedLimit max)
- $limit = $wgRequest->getInt( 'limit', 10 );
+ $limit = $request->getInt( 'limit', 10 );
if ( $limit > $wgFeedLimit || $limit < 1 ) {
$limit = 10;
}
}
function feedEmpty() {
- global $wgOut;
return new FeedItem(
wfMsgForContent( 'nohistory' ),
- $wgOut->parse( wfMsgForContent( 'history-feed-empty' ) ),
- $this->title->getFullUrl(),
+ $this->getOutput()->parse( wfMsgForContent( 'history-feed-empty' ) ),
+ $this->getTitle()->getFullUrl(),
wfTimestamp( TS_MW ),
'',
- $this->title->getTalkPage()->getFullUrl()
+ $this->getTitle()->getTalkPage()->getFullUrl()
);
}
*/
function feedItem( $row ) {
$rev = new Revision( $row );
- $rev->setTitle( $this->title );
+ $rev->setTitle( $this->getTitle() );
$text = FeedUtils::formatDiffRow(
- $this->title,
- $this->title->getPreviousRevisionID( $rev->getId() ),
+ $this->getTitle(),
+ $this->getTitle()->getPreviousRevisionID( $rev->getId() ),
$rev->getId(),
$rev->getTimestamp(),
$rev->getComment()
return new FeedItem(
$title,
$text,
- $this->title->getFullUrl( 'diff=' . $rev->getId() . '&oldid=prev' ),
+ $this->getTitle()->getFullUrl( 'diff=' . $rev->getId() . '&oldid=prev' ),
$rev->getTimestamp(),
$rev->getUserText(),
- $this->title->getTalkPage()->getFullUrl()
+ $this->getTitle()->getTalkPage()->getFullUrl()
);
}
}
class HistoryPager extends ReverseChronologicalPager {
public $lastRow = false, $counter, $historyPage, $title, $buttons, $conds;
protected $oldIdChecked;
+ protected $preventClickjacking = false;
function __construct( $historyPage, $year = '', $month = '', $tagFilter = '', $conds = array() ) {
parent::__construct();
$this->historyPage = $historyPage;
- $this->title = $this->historyPage->title;
+ $this->title = $this->historyPage->getTitle();
$this->tagFilter = $tagFilter;
$this->getDateCond( $year, $month );
$this->conds = $conds;
return $this->historyPage->getArticle();
}
+ function getTitle() {
+ return $this->title;
+ }
+
function getSqlComment() {
if ( $this->conds ) {
return 'history page filtered'; // potentially slow, see CR r58153
'tables' => array( 'revision' ),
'fields' => Revision::selectFields(),
'conds' => array_merge(
- array( 'rev_page' => $this->historyPage->title->getArticleID() ),
+ array( 'rev_page' => $this->title->getArticleID() ),
$this->conds ),
'options' => array( 'USE INDEX' => array( 'revision' => 'page_timestamp' ) ),
'join_conds' => array( 'tag_summary' => array( 'LEFT JOIN', 'ts_rev_id=rev_id' ) ),
* @return string HTML output
*/
function getStartBody() {
- global $wgScript, $wgUser, $wgOut, $wgContLang;
+ global $wgScript, $wgUser, $wgOut;
$this->lastRow = false;
$this->counter = 1;
$this->oldIdChecked = 0;
$this->buttons = '<div>';
$this->buttons .= $this->submitButton( wfMsg( 'compareselectedversions' ),
array( 'class' => 'historysubmit' )
- + $wgUser->getSkin()->tooltipAndAccessKeyAttribs( 'compareselectedversions' )
+ + Linker::tooltipAndAccesskeyAttribs( 'compareselectedversions' )
) . "\n";
if ( $wgUser->isAllowed( 'deleterevision' ) ) {
- $float = $wgContLang->alignEnd();
- # Note bug #20966, <button> is non-standard in IE<8
- $element = Html::element( 'button',
- array(
- 'type' => 'submit',
- 'name' => 'revisiondelete',
- 'value' => '1',
- 'style' => "float: $float;",
- 'class' => 'mw-history-revisiondelete-button',
- ),
- wfMsg( 'showhideselectedversions' )
- ) . "\n";
- $s .= $element;
- $this->buttons .= $element;
- }
- if ( $wgUser->isAllowed( 'revisionmove' ) ) {
- $float = $wgContLang->alignEnd();
- # Note bug #20966, <button> is non-standard in IE<8
- $element = Html::element( 'button',
- array(
- 'type' => 'submit',
- 'name' => 'revisionmove',
- 'value' => '1',
- 'style' => "float: $float;",
- 'class' => 'mw-history-revisionmove-button',
- ),
- wfMsg( 'revisionmoveselectedversions' )
- ) . "\n";
- $s .= $element;
- $this->buttons .= $element;
+ $s .= $this->getRevisionButton( 'revisiondelete', 'showhideselectedversions' );
}
$this->buttons .= '</div>';
$s .= '</div><ul id="pagehistory">' . "\n";
return $s;
}
+ private function getRevisionButton( $name, $msg ) {
+ $this->preventClickjacking();
+ # Note bug #20966, <button> is non-standard in IE<8
+ $element = Html::element( 'button',
+ array(
+ 'type' => 'submit',
+ 'name' => $name,
+ 'value' => '1',
+ 'class' => "mw-history-$name-button",
+ ),
+ wfMsg( $msg )
+ ) . "\n";
+ $this->buttons .= $element;
+ return $element;
+ }
+
function getEndBody() {
if ( $this->lastRow ) {
$latest = $this->counter == 1 && $this->mIsFirst;
$del = '';
// Show checkboxes for each revision
- if ( $wgUser->isAllowed( 'deleterevision' ) || $wgUser->isAllowed( 'revisionmove' ) ) {
+ if ( $wgUser->isAllowed( 'deleterevision' ) ) {
+ $this->preventClickjacking();
// If revision was hidden from sysops, disable the checkbox
- // However, if the user has revisionmove rights, we cannot disable the checkbox
- if ( !$rev->userCan( Revision::DELETED_RESTRICTED ) && !$wgUser->isAllowed( 'revisionmove' ) ) {
+ if ( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
$del = Xml::check( 'deleterevisions', false, array( 'disabled' => 'disabled' ) );
// Otherwise, enable the checkbox...
} else {
array( 'name' => 'ids[' . $rev->getId() . ']' ) );
}
// User can only view deleted revisions...
- } else if ( $rev->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) {
+ } elseif ( $rev->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) {
// If revision was hidden from sysops, disable the link
if ( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
- $cdel = $this->getSkin()->revDeleteLinkDisabled( false );
+ $cdel = Linker::revDeleteLinkDisabled( false );
// Otherwise, show the link...
} else {
$query = array( 'type' => 'revision',
'target' => $this->title->getPrefixedDbkey(), 'ids' => $rev->getId() );
- $del .= $this->getSkin()->revDeleteLink( $query,
+ $del .= Linker::revDeleteLink( $query,
$rev->isDeleted( Revision::DELETED_RESTRICTED ), false );
}
}
$s .= " $del ";
}
+ $dirmark = $wgLang->getDirMark();
+
$s .= " $link";
+ $s .= $dirmark;
$s .= " <span class='history-user'>" .
- $this->getSkin()->revUserTools( $rev, true ) . "</span>";
+ Linker::revUserTools( $rev, true ) . "</span>";
+ $s .= $dirmark;
if ( $rev->isMinor() ) {
$s .= ' ' . ChangesList::flag( 'minor' );
}
if ( !is_null( $size = $rev->getSize() ) && !$rev->isDeleted( Revision::DELETED_TEXT ) ) {
- $s .= ' ' . $this->getSkin()->formatRevisionSize( $size );
+ $s .= ' ' . Linker::formatRevisionSize( $size );
}
- $s .= $this->getSkin()->revComment( $rev, false, true );
+ $s .= Linker::revComment( $rev, false, true );
if ( $notificationtimestamp && ( $row->rev_timestamp >= $notificationtimestamp ) ) {
$s .= ' <span class="updatedmarker">' . wfMsgHtml( 'updatedmarker' ) . '</span>';
# Rollback and undo links
if ( !is_null( $next ) && is_object( $next ) ) {
if ( $latest && $this->title->userCan( 'rollback' ) && $this->title->userCan( 'edit' ) ) {
+ $this->preventClickjacking();
$tools[] = '<span class="mw-rollback-link">' .
- $this->getSkin()->buildRollbackLink( $rev ) . '</span>';
+ Linker::buildRollbackLink( $rev ) . '</span>';
}
if ( $this->title->quickUserCan( 'edit' )
$undoTooltip = $latest
? array( 'title' => wfMsg( 'tooltip-undo' ) )
: array();
- $undolink = $this->getSkin()->link(
+ $undolink = Linker::linkKnown(
$this->title,
wfMsgHtml( 'editundo' ),
$undoTooltip,
'action' => 'edit',
'undoafter' => $next->rev_id,
'undo' => $rev->getId()
- ),
- array( 'known', 'noclasses' )
+ )
);
$tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>";
}
$date = $wgLang->timeanddate( wfTimestamp( TS_MW, $rev->getTimestamp() ), true );
$date = htmlspecialchars( $date );
if ( $rev->userCan( Revision::DELETED_TEXT ) ) {
- $link = $this->getSkin()->link(
+ $link = Linker::linkKnown(
$this->title,
$date,
array(),
- array( 'oldid' => $rev->getId() ),
- array( 'known', 'noclasses' )
+ array( 'oldid' => $rev->getId() )
);
} else {
$link = $date;
if ( $latest || !$rev->userCan( Revision::DELETED_TEXT ) ) {
return $cur;
} else {
- return $this->getSkin()->link(
+ return Linker::linkKnown(
$this->title,
$cur,
array(),
array(
'diff' => $this->title->getLatestRevID(),
'oldid' => $rev->getId()
- ),
- array( 'known', 'noclasses' )
+ )
);
}
}
return $last;
} elseif ( $next === 'unknown' ) {
# Next row probably exists but is unknown, use an oldid=prev link
- return $this->getSkin()->link(
+ return Linker::linkKnown(
$this->title,
$last,
array(),
array(
'diff' => $prevRev->getId(),
'oldid' => 'prev'
- ),
- array( 'known', 'noclasses' )
+ )
);
} elseif ( !$prevRev->userCan( Revision::DELETED_TEXT )
|| !$nextRev->userCan( Revision::DELETED_TEXT ) )
{
return $last;
} else {
- return $this->getSkin()->link(
+ return Linker::linkKnown(
$this->title,
$last,
array(),
array(
'diff' => $prevRev->getId(),
'oldid' => $next->rev_id
- ),
- array( 'known', 'noclasses' )
+ )
);
}
}
if ( !$rev->userCan( Revision::DELETED_TEXT ) ) {
$radio['disabled'] = 'disabled';
$checkmark = array(); // We will check the next possible one
- } else if ( !$this->oldIdChecked ) {
+ } elseif ( !$this->oldIdChecked ) {
$checkmark = array( 'checked' => 'checked' );
$this->oldIdChecked = $id;
} else {
return '';
}
}
+
+ /**
+ * This is called if a write operation is possible from the generated HTML
+ */
+ function preventClickjacking( $enable = true ) {
+ $this->preventClickjacking = $enable;
+ }
+
+ /**
+ * Get the "prevent clickjacking" flag
+ */
+ function getPreventClickjacking() {
+ return $this->preventClickjacking;
+ }
}
/**