Index: trunk/phase3/includes/HistoryPage.php |
— | — | @@ -15,36 +15,33 @@ |
16 | 16 | * history. |
17 | 17 | * |
18 | 18 | */ |
19 | | -class HistoryPage { |
| 19 | +class HistoryPage extends ContextSource { |
20 | 20 | const DIR_PREV = 0; |
21 | 21 | const DIR_NEXT = 1; |
22 | 22 | |
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; |
27 | 25 | |
28 | 26 | /** |
29 | 27 | * Construct a new HistoryPage. |
30 | 28 | * |
31 | 29 | * @param $article Article |
32 | 30 | */ |
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 |
36 | 35 | $this->preCacheMessages(); |
37 | 36 | } |
38 | 37 | |
39 | | - /** Get the Article object we are working on. */ |
| 38 | + /** |
| 39 | + * Get the Article object we are working on. |
| 40 | + * @return Page |
| 41 | + */ |
40 | 42 | public function getArticle() { |
41 | 43 | return $this->article; |
42 | 44 | } |
43 | 45 | |
44 | | - /** Get the Title object. */ |
45 | | - public function getTitle() { |
46 | | - return $this->title; |
47 | | - } |
48 | | - |
49 | 46 | /** |
50 | 47 | * As we use the same small set of messages in various methods and that |
51 | 48 | * they are called often, we call them once and save them in $this->message |
— | — | @@ -64,35 +61,36 @@ |
65 | 62 | * @return nothing |
66 | 63 | */ |
67 | 64 | function history() { |
68 | | - global $wgOut, $wgRequest, $wgScript, $wgUseFileCache; |
| 65 | + global $wgScript, $wgUseFileCache; |
| 66 | + $out = $this->getOutput(); |
| 67 | + $request = $this->getRequest(); |
69 | 68 | |
70 | 69 | /** |
71 | 70 | * Allow client caching. |
72 | 71 | */ |
73 | | - if ( $wgOut->checkLastModified( $this->article->getTouched() ) ) { |
| 72 | + if ( $out->checkLastModified( $this->article->getTouched() ) ) { |
74 | 73 | return; // Client cache fresh and headers sent, nothing more to do. |
75 | 74 | } |
76 | 75 | |
77 | 76 | wfProfileIn( __METHOD__ ); |
78 | 77 | |
79 | | - $context = RequestContext::getMain(); |
80 | 78 | # 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' ); |
83 | 81 | if ( !$cache->isCacheGood( /* Assume up to date */ ) ) { |
84 | 82 | ob_start( array( &$cache, 'saveToFileCache' ) ); |
85 | 83 | } |
86 | 84 | } |
87 | 85 | |
88 | 86 | // 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' ) ); |
97 | 95 | |
98 | 96 | // Creation of a subtitle link pointing to [[Special:Log]] |
99 | 97 | $logPage = SpecialPage::getTitleFor( 'Log' ); |
— | — | @@ -100,25 +98,25 @@ |
101 | 99 | $logPage, |
102 | 100 | wfMsgHtml( 'viewpagelogs' ), |
103 | 101 | array(), |
104 | | - array( 'page' => $this->title->getPrefixedText() ) |
| 102 | + array( 'page' => $this->getTitle()->getPrefixedText() ) |
105 | 103 | ); |
106 | | - $wgOut->setSubtitle( $logLink ); |
| 104 | + $out->setSubtitle( $logLink ); |
107 | 105 | |
108 | 106 | // Handle atom/RSS feeds. |
109 | | - $feedType = $wgRequest->getVal( 'feed' ); |
| 107 | + $feedType = $request->getVal( 'feed' ); |
110 | 108 | if ( $feedType ) { |
111 | 109 | wfProfileOut( __METHOD__ ); |
112 | 110 | return $this->feed( $feedType ); |
113 | 111 | } |
114 | 112 | |
115 | 113 | // 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' ); |
118 | 116 | # show deletion/move log if there is an entry |
119 | 117 | LogEventsList::showLogExtract( |
120 | | - $wgOut, |
| 118 | + $out, |
121 | 119 | array( 'delete', 'move' ), |
122 | | - $this->title, |
| 120 | + $this->getTitle(), |
123 | 121 | '', |
124 | 122 | array( 'lim' => 10, |
125 | 123 | 'conds' => array( "log_action != 'revision'" ), |
— | — | @@ -133,32 +131,32 @@ |
134 | 132 | /** |
135 | 133 | * Add date selector to quickly get to a certain time |
136 | 134 | */ |
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' ); |
140 | 138 | $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter ); |
141 | 139 | |
142 | 140 | /** |
143 | 141 | * Option to show only revisions that have been (partially) hidden via RevisionDelete |
144 | 142 | */ |
145 | | - if ( $wgRequest->getBool( 'deleted' ) ) { |
| 143 | + if ( $request->getBool( 'deleted' ) ) { |
146 | 144 | $conds = array( "rev_deleted != '0'" ); |
147 | 145 | } else { |
148 | 146 | $conds = array(); |
149 | 147 | } |
150 | 148 | $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"; |
152 | 150 | |
153 | 151 | // Add the general form |
154 | 152 | $action = htmlspecialchars( $wgScript ); |
155 | | - $wgOut->addHTML( |
| 153 | + $out->addHTML( |
156 | 154 | "<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" . |
157 | 155 | Xml::fieldset( |
158 | 156 | wfMsg( 'history-fieldset-title' ), |
159 | 157 | false, |
160 | 158 | array( 'id' => 'mw-history-search' ) |
161 | 159 | ) . |
162 | | - Html::hidden( 'title', $this->title->getPrefixedDBKey() ) . "\n" . |
| 160 | + Html::hidden( 'title', $this->getTitle()->getPrefixedDBKey() ) . "\n" . |
163 | 161 | Html::hidden( 'action', 'history' ) . "\n" . |
164 | 162 | Xml::dateMenu( $year, $month ) . ' ' . |
165 | 163 | ( $tagSelector ? ( implode( ' ', $tagSelector ) . ' ' ) : '' ) . |
— | — | @@ -171,12 +169,12 @@ |
172 | 170 | |
173 | 171 | // Create and output the list. |
174 | 172 | $pager = new HistoryPager( $this, $year, $month, $tagFilter, $conds ); |
175 | | - $wgOut->addHTML( |
| 173 | + $out->addHTML( |
176 | 174 | $pager->getNavigationBar() . |
177 | 175 | $pager->getBody() . |
178 | 176 | $pager->getNavigationBar() |
179 | 177 | ); |
180 | | - $wgOut->preventClickjacking( $pager->getPreventClickjacking() ); |
| 178 | + $out->preventClickjacking( $pager->getPreventClickjacking() ); |
181 | 179 | |
182 | 180 | wfProfileOut( __METHOD__ ); |
183 | 181 | } |
— | — | @@ -206,7 +204,7 @@ |
207 | 205 | $offsets = array(); |
208 | 206 | } |
209 | 207 | |
210 | | - $page_id = $this->title->getArticleID(); |
| 208 | + $page_id = $this->getTitle()->getArticleID(); |
211 | 209 | |
212 | 210 | return $dbr->select( 'revision', |
213 | 211 | Revision::selectFields(), |
— | — | @@ -223,21 +221,22 @@ |
224 | 222 | * @param $type String: feed type |
225 | 223 | */ |
226 | 224 | function feed( $type ) { |
227 | | - global $wgFeedClasses, $wgRequest, $wgFeedLimit; |
| 225 | + global $wgFeedClasses, $wgFeedLimit; |
228 | 226 | if ( !FeedUtils::checkFeedOutput( $type ) ) { |
229 | 227 | return; |
230 | 228 | } |
| 229 | + $request = $this->getRequest(); |
231 | 230 | |
232 | 231 | $feed = new $wgFeedClasses[$type]( |
233 | | - $this->title->getPrefixedText() . ' - ' . |
| 232 | + $this->getTitle()->getPrefixedText() . ' - ' . |
234 | 233 | wfMsgForContent( 'history-feed-title' ), |
235 | 234 | wfMsgForContent( 'history-feed-description' ), |
236 | | - $this->title->getFullUrl( 'action=history' ) |
| 235 | + $this->getTitle()->getFullUrl( 'action=history' ) |
237 | 236 | ); |
238 | 237 | |
239 | 238 | // Get a limit on number of feed entries. Provide a sane default |
240 | 239 | // of 10 if none is defined (but limit to $wgFeedLimit max) |
241 | | - $limit = $wgRequest->getInt( 'limit', 10 ); |
| 240 | + $limit = $request->getInt( 'limit', 10 ); |
242 | 241 | if ( $limit > $wgFeedLimit || $limit < 1 ) { |
243 | 242 | $limit = 10; |
244 | 243 | } |
— | — | @@ -256,14 +255,13 @@ |
257 | 256 | } |
258 | 257 | |
259 | 258 | function feedEmpty() { |
260 | | - global $wgOut; |
261 | 259 | return new FeedItem( |
262 | 260 | 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(), |
265 | 263 | wfTimestamp( TS_MW ), |
266 | 264 | '', |
267 | | - $this->title->getTalkPage()->getFullUrl() |
| 265 | + $this->getTitle()->getTalkPage()->getFullUrl() |
268 | 266 | ); |
269 | 267 | } |
270 | 268 | |
— | — | @@ -277,10 +275,10 @@ |
278 | 276 | */ |
279 | 277 | function feedItem( $row ) { |
280 | 278 | $rev = new Revision( $row ); |
281 | | - $rev->setTitle( $this->title ); |
| 279 | + $rev->setTitle( $this->getTitle() ); |
282 | 280 | $text = FeedUtils::formatDiffRow( |
283 | | - $this->title, |
284 | | - $this->title->getPreviousRevisionID( $rev->getId() ), |
| 281 | + $this->getTitle(), |
| 282 | + $this->getTitle()->getPreviousRevisionID( $rev->getId() ), |
285 | 283 | $rev->getId(), |
286 | 284 | $rev->getTimestamp(), |
287 | 285 | $rev->getComment() |
— | — | @@ -301,10 +299,10 @@ |
302 | 300 | return new FeedItem( |
303 | 301 | $title, |
304 | 302 | $text, |
305 | | - $this->title->getFullUrl( 'diff=' . $rev->getId() . '&oldid=prev' ), |
| 303 | + $this->getTitle()->getFullUrl( 'diff=' . $rev->getId() . '&oldid=prev' ), |
306 | 304 | $rev->getTimestamp(), |
307 | 305 | $rev->getUserText(), |
308 | | - $this->title->getTalkPage()->getFullUrl() |
| 306 | + $this->getTitle()->getTalkPage()->getFullUrl() |
309 | 307 | ); |
310 | 308 | } |
311 | 309 | } |