X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FHistoryPage.php;h=11315acfd510ecde00b1800110a5431a277c68d6;hb=0399907dbddd4c9808a91a06f64e44beb1fc2c26;hp=961e8639eb697ce30eb13aa6a3afc6ba3aa2220d;hpb=efe4525d2c407437a33de0c11b14f89d4208e201;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/HistoryPage.php b/includes/HistoryPage.php index 961e8639eb..11315acfd5 100644 --- a/includes/HistoryPage.php +++ b/includes/HistoryPage.php @@ -15,40 +15,33 @@ * 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 @@ -68,52 +61,61 @@ class HistoryPage { * @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.action.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'" ), @@ -128,32 +130,32 @@ class HistoryPage { /** * 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( "
" . 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 ) . ' ' ) : '' ) . @@ -166,12 +168,12 @@ class HistoryPage { // Create and output the list. $pager = new HistoryPager( $this, $year, $month, $tagFilter, $conds ); - $wgOut->addHTML( + $out->addHTML( $pager->getNavigationBar() . $pager->getBody() . $pager->getNavigationBar() ); - $wgOut->preventClickjacking( $pager->getPreventClickjacking() ); + $out->preventClickjacking( $pager->getPreventClickjacking() ); wfProfileOut( __METHOD__ ); } @@ -201,7 +203,7 @@ class HistoryPage { $offsets = array(); } - $page_id = $this->title->getArticleID(); + $page_id = $this->getTitle()->getArticleID(); return $dbr->select( 'revision', Revision::selectFields(), @@ -218,21 +220,22 @@ class HistoryPage { * @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; } @@ -251,14 +254,13 @@ class HistoryPage { } 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() ); } @@ -272,10 +274,10 @@ class HistoryPage { */ 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() @@ -296,10 +298,10 @@ class HistoryPage { 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() ); } } @@ -326,6 +328,10 @@ class HistoryPager extends ReverseChronologicalPager { return $this->historyPage->getArticle(); } + function getTitle() { + return $this->title; + } + function getSqlComment() { if ( $this->conds ) { return 'history page filtered'; // potentially slow, see CR r58153 @@ -339,7 +345,7 @@ class HistoryPager extends ReverseChronologicalPager { 'tables' => array( 'revision' ), 'fields' => Revision::selectFields(), 'conds' => array_merge( - array( 'rev_page' => $this->historyPage->getTitle()->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' ) ), @@ -397,7 +403,7 @@ class HistoryPager extends ReverseChronologicalPager { $this->buttons = '
'; $this->buttons .= $this->submitButton( wfMsg( 'compareselectedversions' ), array( 'class' => 'historysubmit' ) - + $wgUser->getSkin()->tooltipAndAccessKeyAttribs( 'compareselectedversions' ) + + Linker::tooltipAndAccesskeyAttribs( 'compareselectedversions' ) ) . "\n"; if ( $wgUser->isAllowed( 'deleterevision' ) ) { @@ -409,16 +415,13 @@ class HistoryPager extends ReverseChronologicalPager { } private function getRevisionButton( $name, $msg ) { - global $wgContLang; $this->preventClickjacking(); - $float = $wgContLang->alignEnd(); # Note bug #20966,