r98459 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98458‎ | r98459 | r98460 >
Date:21:20, 29 September 2011
Author:aaron
Status:resolved
Tags:
Comment:
Refactored HistoryPage to use RequestContext
Modified paths:
  • /trunk/phase3/includes/HistoryPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/HistoryPage.php
@@ -15,36 +15,33 @@
1616 * history.
1717 *
1818 */
19 -class HistoryPage {
 19+class HistoryPage extends ContextSource {
2020 const DIR_PREV = 0;
2121 const DIR_NEXT = 1;
2222
23 - /** Contains the Article object. Passed on construction. */
24 - private $article;
25 - /** The $article title object. Found on construction. */
26 - private $title;
 23+ /** Contains the Page object. Passed on construction. */
 24+ protected $article;
2725
2826 /**
2927 * Construct a new HistoryPage.
3028 *
3129 * @param $article Article
3230 */
33 - function __construct( $article ) {
34 - $this->article = $article;
35 - $this->title = $article->getTitle();
 31+ function __construct( Page $page, IContextSource $context ) {
 32+ $this->article = $page;
 33+ $this->context = clone $context; // don't clobber the main context
 34+ $this->context->setTitle( $page->getTitle() ); // must match
3635 $this->preCacheMessages();
3736 }
3837
39 - /** Get the Article object we are working on. */
 38+ /**
 39+ * Get the Article object we are working on.
 40+ * @return Page
 41+ */
4042 public function getArticle() {
4143 return $this->article;
4244 }
4345
44 - /** Get the Title object. */
45 - public function getTitle() {
46 - return $this->title;
47 - }
48 -
4946 /**
5047 * As we use the same small set of messages in various methods and that
5148 * they are called often, we call them once and save them in $this->message
@@ -64,35 +61,36 @@
6562 * @return nothing
6663 */
6764 function history() {
68 - global $wgOut, $wgRequest, $wgScript, $wgUseFileCache;
 65+ global $wgScript, $wgUseFileCache;
 66+ $out = $this->getOutput();
 67+ $request = $this->getRequest();
6968
7069 /**
7170 * Allow client caching.
7271 */
73 - if ( $wgOut->checkLastModified( $this->article->getTouched() ) ) {
 72+ if ( $out->checkLastModified( $this->article->getTouched() ) ) {
7473 return; // Client cache fresh and headers sent, nothing more to do.
7574 }
7675
7776 wfProfileIn( __METHOD__ );
7877
79 - $context = RequestContext::getMain();
8078 # Fill in the file cache if not set already
81 - if ( $wgUseFileCache && HTMLFileCache::useFileCache( $context ) ) {
82 - $cache = HTMLFileCache::newFromTitle( $this->title, 'history' );
 79+ if ( $wgUseFileCache && HTMLFileCache::useFileCache( $this->getContext() ) ) {
 80+ $cache = HTMLFileCache::newFromTitle( $this->getTitle(), 'history' );
8381 if ( !$cache->isCacheGood( /* Assume up to date */ ) ) {
8482 ob_start( array( &$cache, 'saveToFileCache' ) );
8583 }
8684 }
8785
8886 // Setup page variables.
89 - $wgOut->setPageTitle( wfMsg( 'history-title', $this->title->getPrefixedText() ) );
90 - $wgOut->setPageTitleActionText( wfMsg( 'history_short' ) );
91 - $wgOut->setArticleFlag( false );
92 - $wgOut->setArticleRelated( true );
93 - $wgOut->setRobotPolicy( 'noindex,nofollow' );
94 - $wgOut->setSyndicated( true );
95 - $wgOut->setFeedAppendQuery( 'action=history' );
96 - $wgOut->addModules( array( 'mediawiki.legacy.history', 'mediawiki.action.history' ) );
 87+ $out->setPageTitle( wfMsg( 'history-title', $this->getTitle()->getPrefixedText() ) );
 88+ $out->setPageTitleActionText( wfMsg( 'history_short' ) );
 89+ $out->setArticleFlag( false );
 90+ $out->setArticleRelated( true );
 91+ $out->setRobotPolicy( 'noindex,nofollow' );
 92+ $out->setSyndicated( true );
 93+ $out->setFeedAppendQuery( 'action=history' );
 94+ $out->addModules( array( 'mediawiki.legacy.history', 'mediawiki.action.history' ) );
9795
9896 // Creation of a subtitle link pointing to [[Special:Log]]
9997 $logPage = SpecialPage::getTitleFor( 'Log' );
@@ -100,25 +98,25 @@
10199 $logPage,
102100 wfMsgHtml( 'viewpagelogs' ),
103101 array(),
104 - array( 'page' => $this->title->getPrefixedText() )
 102+ array( 'page' => $this->getTitle()->getPrefixedText() )
105103 );
106 - $wgOut->setSubtitle( $logLink );
 104+ $out->setSubtitle( $logLink );
107105
108106 // Handle atom/RSS feeds.
109 - $feedType = $wgRequest->getVal( 'feed' );
 107+ $feedType = $request->getVal( 'feed' );
110108 if ( $feedType ) {
111109 wfProfileOut( __METHOD__ );
112110 return $this->feed( $feedType );
113111 }
114112
115113 // Fail nicely if article doesn't exist.
116 - if ( !$this->title->exists() ) {
117 - $wgOut->addWikiMsg( 'nohistory' );
 114+ if ( !$this->getTitle()->exists() ) {
 115+ $out->addWikiMsg( 'nohistory' );
118116 # show deletion/move log if there is an entry
119117 LogEventsList::showLogExtract(
120 - $wgOut,
 118+ $out,
121119 array( 'delete', 'move' ),
122 - $this->title,
 120+ $this->getTitle(),
123121 '',
124122 array( 'lim' => 10,
125123 'conds' => array( "log_action != 'revision'" ),
@@ -133,32 +131,32 @@
134132 /**
135133 * Add date selector to quickly get to a certain time
136134 */
137 - $year = $wgRequest->getInt( 'year' );
138 - $month = $wgRequest->getInt( 'month' );
139 - $tagFilter = $wgRequest->getVal( 'tagfilter' );
 135+ $year = $request->getInt( 'year' );
 136+ $month = $request->getInt( 'month' );
 137+ $tagFilter = $request->getVal( 'tagfilter' );
140138 $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter );
141139
142140 /**
143141 * Option to show only revisions that have been (partially) hidden via RevisionDelete
144142 */
145 - if ( $wgRequest->getBool( 'deleted' ) ) {
 143+ if ( $request->getBool( 'deleted' ) ) {
146144 $conds = array( "rev_deleted != '0'" );
147145 } else {
148146 $conds = array();
149147 }
150148 $checkDeleted = Xml::checkLabel( wfMsg( 'history-show-deleted' ),
151 - 'deleted', 'mw-show-deleted-only', $wgRequest->getBool( 'deleted' ) ) . "\n";
 149+ 'deleted', 'mw-show-deleted-only', $request->getBool( 'deleted' ) ) . "\n";
152150
153151 // Add the general form
154152 $action = htmlspecialchars( $wgScript );
155 - $wgOut->addHTML(
 153+ $out->addHTML(
156154 "<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" .
157155 Xml::fieldset(
158156 wfMsg( 'history-fieldset-title' ),
159157 false,
160158 array( 'id' => 'mw-history-search' )
161159 ) .
162 - Html::hidden( 'title', $this->title->getPrefixedDBKey() ) . "\n" .
 160+ Html::hidden( 'title', $this->getTitle()->getPrefixedDBKey() ) . "\n" .
163161 Html::hidden( 'action', 'history' ) . "\n" .
164162 Xml::dateMenu( $year, $month ) . '&#160;' .
165163 ( $tagSelector ? ( implode( '&#160;', $tagSelector ) . '&#160;' ) : '' ) .
@@ -171,12 +169,12 @@
172170
173171 // Create and output the list.
174172 $pager = new HistoryPager( $this, $year, $month, $tagFilter, $conds );
175 - $wgOut->addHTML(
 173+ $out->addHTML(
176174 $pager->getNavigationBar() .
177175 $pager->getBody() .
178176 $pager->getNavigationBar()
179177 );
180 - $wgOut->preventClickjacking( $pager->getPreventClickjacking() );
 178+ $out->preventClickjacking( $pager->getPreventClickjacking() );
181179
182180 wfProfileOut( __METHOD__ );
183181 }
@@ -206,7 +204,7 @@
207205 $offsets = array();
208206 }
209207
210 - $page_id = $this->title->getArticleID();
 208+ $page_id = $this->getTitle()->getArticleID();
211209
212210 return $dbr->select( 'revision',
213211 Revision::selectFields(),
@@ -223,21 +221,22 @@
224222 * @param $type String: feed type
225223 */
226224 function feed( $type ) {
227 - global $wgFeedClasses, $wgRequest, $wgFeedLimit;
 225+ global $wgFeedClasses, $wgFeedLimit;
228226 if ( !FeedUtils::checkFeedOutput( $type ) ) {
229227 return;
230228 }
 229+ $request = $this->getRequest();
231230
232231 $feed = new $wgFeedClasses[$type](
233 - $this->title->getPrefixedText() . ' - ' .
 232+ $this->getTitle()->getPrefixedText() . ' - ' .
234233 wfMsgForContent( 'history-feed-title' ),
235234 wfMsgForContent( 'history-feed-description' ),
236 - $this->title->getFullUrl( 'action=history' )
 235+ $this->getTitle()->getFullUrl( 'action=history' )
237236 );
238237
239238 // Get a limit on number of feed entries. Provide a sane default
240239 // of 10 if none is defined (but limit to $wgFeedLimit max)
241 - $limit = $wgRequest->getInt( 'limit', 10 );
 240+ $limit = $request->getInt( 'limit', 10 );
242241 if ( $limit > $wgFeedLimit || $limit < 1 ) {
243242 $limit = 10;
244243 }
@@ -256,14 +255,13 @@
257256 }
258257
259258 function feedEmpty() {
260 - global $wgOut;
261259 return new FeedItem(
262260 wfMsgForContent( 'nohistory' ),
263 - $wgOut->parse( wfMsgForContent( 'history-feed-empty' ) ),
264 - $this->title->getFullUrl(),
 261+ $this->getOutput()->parse( wfMsgForContent( 'history-feed-empty' ) ),
 262+ $this->getTitle()->getFullUrl(),
265263 wfTimestamp( TS_MW ),
266264 '',
267 - $this->title->getTalkPage()->getFullUrl()
 265+ $this->getTitle()->getTalkPage()->getFullUrl()
268266 );
269267 }
270268
@@ -277,10 +275,10 @@
278276 */
279277 function feedItem( $row ) {
280278 $rev = new Revision( $row );
281 - $rev->setTitle( $this->title );
 279+ $rev->setTitle( $this->getTitle() );
282280 $text = FeedUtils::formatDiffRow(
283 - $this->title,
284 - $this->title->getPreviousRevisionID( $rev->getId() ),
 281+ $this->getTitle(),
 282+ $this->getTitle()->getPreviousRevisionID( $rev->getId() ),
285283 $rev->getId(),
286284 $rev->getTimestamp(),
287285 $rev->getComment()
@@ -301,10 +299,10 @@
302300 return new FeedItem(
303301 $title,
304302 $text,
305 - $this->title->getFullUrl( 'diff=' . $rev->getId() . '&oldid=prev' ),
 303+ $this->getTitle()->getFullUrl( 'diff=' . $rev->getId() . '&oldid=prev' ),
306304 $rev->getTimestamp(),
307305 $rev->getUserText(),
308 - $this->title->getTalkPage()->getFullUrl()
 306+ $this->getTitle()->getTalkPage()->getFullUrl()
309307 );
310308 }
311309 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r98464FR r98459: forgot to commit this!aaron21:34, 29 September 2011

Status & tagging log