Index: trunk/phase3/includes/Wiki.php |
— | — | @@ -15,6 +15,20 @@ |
16 | 16 | private $params = array(); |
17 | 17 | |
18 | 18 | /** |
| 19 | + * The request object |
| 20 | + * @var WebRequest |
| 21 | + */ |
| 22 | + private $request; |
| 23 | + |
| 24 | + /** |
| 25 | + * Output to deliver content to |
| 26 | + * FIXME: most stuff in the codebase doesn't actually write to this, it'll write to |
| 27 | + * $wgOut instead. So in practice this has to be $wgOut; |
| 28 | + * @var OutputPage |
| 29 | + */ |
| 30 | + private $output; |
| 31 | + |
| 32 | + /** |
19 | 33 | * Stores key/value pairs to circumvent global variables |
20 | 34 | * Note that keys are case-insensitive! |
21 | 35 | * |
— | — | @@ -42,47 +56,65 @@ |
43 | 57 | return $default; |
44 | 58 | } |
45 | 59 | |
| 60 | + public function request( WebRequest &$x = null ){ |
| 61 | + return wfSetVar( $this->request, $x ); |
| 62 | + } |
| 63 | + |
| 64 | + public function output( OutputPage &$x = null ){ |
| 65 | + return wfSetVar( $this->output, $x ); |
| 66 | + } |
| 67 | + |
| 68 | + public function __construct( WebRequest &$request, /*OutputPage*/ &$output ){ |
| 69 | + $this->request =& $request; |
| 70 | + $this->output =& $output; |
| 71 | + } |
| 72 | + |
46 | 73 | /** |
47 | 74 | * Initialization of ... everything |
48 | 75 | * Performs the request too |
49 | 76 | * |
50 | 77 | * @param $title Title ($wgTitle) |
51 | 78 | * @param $article Article |
52 | | - * @param $output OutputPage |
53 | 79 | * @param $user User |
54 | | - * @param $request WebRequest |
55 | 80 | */ |
56 | | - public function performRequestForTitle( &$title, &$article, &$output, &$user, $request ) { |
| 81 | + public function performRequestForTitle( &$title, &$article, &$user ) { |
57 | 82 | wfProfileIn( __METHOD__ ); |
58 | 83 | |
59 | | - $output->setTitle( $title ); |
60 | | - if ( $request->getVal( 'printable' ) === 'yes' ) { |
61 | | - $output->setPrintable(); |
| 84 | + $this->output->setTitle( $title ); |
| 85 | + if ( $this->request->getVal( 'printable' ) === 'yes' ) { |
| 86 | + $this->output->setPrintable(); |
62 | 87 | } |
63 | 88 | |
64 | | - wfRunHooks( 'BeforeInitialize', array( &$title, &$article, &$output, &$user, $request, $this ) ); |
| 89 | + wfRunHooks( 'BeforeInitialize', array( |
| 90 | + &$title, |
| 91 | + &$article, |
| 92 | + &$this->output, |
| 93 | + &$user, |
| 94 | + $this->request, |
| 95 | + $this |
| 96 | + ) ); |
65 | 97 | |
66 | 98 | // If the user is not logged in, the Namespace:title of the article must be in |
67 | 99 | // the Read array in order for the user to see it. (We have to check here to |
68 | 100 | // catch special pages etc. We check again in Article::view()) |
69 | 101 | if ( !is_null( $title ) && !$title->userCanRead() ) { |
70 | | - $output->loginToUse(); |
71 | | - $this->finalCleanup( $output ); |
72 | | - $output->disable(); |
| 102 | + $this->output->loginToUse(); |
| 103 | + $this->finalCleanup(); |
| 104 | + $this->output->disable(); |
73 | 105 | wfProfileOut( __METHOD__ ); |
74 | 106 | return false; |
75 | 107 | } |
76 | 108 | |
77 | 109 | // Call handleSpecialCases() to deal with all special requests... |
78 | | - if ( !$this->handleSpecialCases( $title, $output, $request ) ) { |
| 110 | + if ( !$this->handleSpecialCases( $title ) ) { |
79 | 111 | // ...otherwise treat it as an article view. The article |
80 | 112 | // may be a redirect to another article or URL. |
81 | | - $new_article = $this->initializeArticle( $title, $output, $request ); |
| 113 | + $new_article = $this->initializeArticle( $title ); |
82 | 114 | if ( is_object( $new_article ) ) { |
83 | 115 | $article = $new_article; |
84 | | - $this->performAction( $output, $article, $title, $user, $request ); |
| 116 | + $this->performAction( $article, $title, $user ); |
85 | 117 | } elseif ( is_string( $new_article ) ) { |
86 | | - $output->redirect( $new_article ); |
| 118 | + $this->output->redirect( $new_article ); |
87 | 119 | } else { |
88 | 120 | wfProfileOut( __METHOD__ ); |
89 | 121 | throw new MWException( "Shouldn't happen: MediaWiki::initializeArticle() returned neither an object nor a URL" ); |
— | — | @@ -95,16 +127,15 @@ |
96 | 128 | * Checks some initial queries |
97 | 129 | * FIXME: rename to parseTitle() ? |
98 | 130 | * |
99 | | - * @param $request WebRequest |
100 | 131 | * @return Title object to be $wgTitle |
101 | 132 | */ |
102 | | - /* private */ function checkInitialQueries( WebRequest $request ) { |
| 133 | + /* private */ function checkInitialQueries() { |
103 | 134 | global $wgContLang; |
104 | 135 | |
105 | | - $curid = $request->getInt( 'curid' ); |
106 | | - $title = $request->getVal( 'title' ); |
| 136 | + $curid = $this->request->getInt( 'curid' ); |
| 137 | + $title = $this->request->getVal( 'title' ); |
107 | 138 | |
108 | | - if ( $request->getCheck( 'search' ) ) { |
| 139 | + if ( $this->request->getCheck( 'search' ) ) { |
109 | 140 | // Compatibility with old search URLs which didn't use Special:Search |
110 | 141 | // Just check for presence here, so blank requests still |
111 | 142 | // show the search page when using ugly URLs (bug 8054). |
— | — | @@ -112,7 +143,7 @@ |
113 | 144 | } elseif ( $curid ) { |
114 | 145 | // URLs like this are generated by RC, because rc_title isn't always accurate |
115 | 146 | $ret = Title::newFromID( $curid ); |
116 | | - } elseif ( $title == '' && $this->getAction( $request ) != 'delete' ) { |
| 147 | + } elseif ( $title == '' && $this->getAction() != 'delete' ) { |
117 | 148 | $ret = Title::newMainPage(); |
118 | 149 | } else { |
119 | 150 | $ret = Title::newFromURL( $title ); |
— | — | @@ -124,8 +155,8 @@ |
125 | 156 | // For non-special titles, check for implicit titles |
126 | 157 | if ( is_null( $ret ) || $ret->getNamespace() != NS_SPECIAL ) { |
127 | 158 | // We can have urls with just ?diff=,?oldid= or even just ?diff= |
128 | | - $oldid = $request->getInt( 'oldid' ); |
129 | | - $oldid = $oldid ? $oldid : $request->getInt( 'diff' ); |
| 159 | + $oldid = $this->request->getInt( 'oldid' ); |
| 160 | + $oldid = $oldid ? $oldid : $this->request->getInt( 'diff' ); |
130 | 161 | // Allow oldid to override a changed or missing title |
131 | 162 | if ( $oldid ) { |
132 | 163 | $rev = Revision::newFromId( $oldid ); |
— | — | @@ -143,44 +174,42 @@ |
144 | 175 | * - special pages |
145 | 176 | * |
146 | 177 | * @param $title Title |
147 | | - * @param $output OutputPage |
148 | | - * @param $request WebRequest |
149 | 178 | * @return bool true if the request is already executed |
150 | 179 | */ |
151 | | - private function handleSpecialCases( &$title, &$output, $request ) { |
| 180 | + private function handleSpecialCases( &$title ) { |
152 | 181 | wfProfileIn( __METHOD__ ); |
153 | 182 | |
154 | 183 | // Invalid titles. Bug 21776: The interwikis must redirect even if the page name is empty. |
155 | 184 | if ( is_null( $title ) || ( ( $title->getDBkey() == '' ) && ( $title->getInterwiki() == '' ) ) ) { |
156 | 185 | $title = SpecialPage::getTitleFor( 'Badtitle' ); |
157 | | - $output->setTitle( $title ); // bug 21456 |
| 186 | + $this->output->setTitle( $title ); // bug 21456 |
158 | 187 | // Die now before we mess up $wgArticle and the skin stops working |
159 | 188 | throw new ErrorPageError( 'badtitle', 'badtitletext' ); |
160 | 189 | |
161 | 190 | // Interwiki redirects |
162 | 191 | } else if ( $title->getInterwiki() != '' ) { |
163 | | - $rdfrom = $request->getVal( 'rdfrom' ); |
| 192 | + $rdfrom = $this->request->getVal( 'rdfrom' ); |
164 | 193 | if ( $rdfrom ) { |
165 | 194 | $url = $title->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) ); |
166 | 195 | } else { |
167 | | - $query = $request->getValues(); |
| 196 | + $query = $this->request->getValues(); |
168 | 197 | unset( $query['title'] ); |
169 | 198 | $url = $title->getFullURL( $query ); |
170 | 199 | } |
171 | 200 | /* Check for a redirect loop */ |
172 | 201 | if ( !preg_match( '/^' . preg_quote( $this->getVal( 'Server' ), '/' ) . '/', $url ) && $title->isLocal() ) { |
173 | 202 | // 301 so google et al report the target as the actual url. |
174 | | - $output->redirect( $url, 301 ); |
| 203 | + $this->output->redirect( $url, 301 ); |
175 | 204 | } else { |
176 | 205 | $title = SpecialPage::getTitleFor( 'Badtitle' ); |
177 | | - $output->setTitle( $title ); // bug 21456 |
| 206 | + $this->output->setTitle( $title ); // bug 21456 |
178 | 207 | wfProfileOut( __METHOD__ ); |
179 | 208 | throw new ErrorPageError( 'badtitle', 'badtitletext' ); |
180 | 209 | } |
181 | 210 | // Redirect loops, no title in URL, $wgUsePathInfo URLs, and URLs with a variant |
182 | | - } else if ( $request->getVal( 'action', 'view' ) == 'view' && !$request->wasPosted() |
183 | | - && ( $request->getVal( 'title' ) === null || $title->getPrefixedDBKey() != $request->getVal( 'title' ) ) |
184 | | - && !count( array_diff( array_keys( $request->getValues() ), array( 'action', 'title' ) ) ) ) |
| 211 | + } else if ( $this->request->getVal( 'action', 'view' ) == 'view' && !$this->request->wasPosted() |
| 212 | + && ( $this->request->getVal( 'title' ) === null || $title->getPrefixedDBKey() != $this->request->getVal( 'title' ) ) |
| 213 | + && !count( array_diff( array_keys( $this->request->getValues() ), array( 'action', 'title' ) ) ) ) |
185 | 214 | { |
186 | 215 | if ( $title->getNamespace() == NS_SPECIAL ) { |
187 | 216 | list( $name, $subpage ) = SpecialPage::resolveAliasWithSubpage( $title->getDBkey() ); |
— | — | @@ -190,7 +219,7 @@ |
191 | 220 | } |
192 | 221 | $targetUrl = $title->getFullURL(); |
193 | 222 | // Redirect to canonical url, make it a 301 to allow caching |
194 | | - if ( $targetUrl == $request->getFullRequestURL() ) { |
| 223 | + if ( $targetUrl == $this->request->getFullRequestURL() ) { |
195 | 224 | $message = "Redirect loop detected!\n\n" . |
196 | 225 | "This means the wiki got confused about what page was " . |
197 | 226 | "requested; this sometimes happens when moving a wiki " . |
— | — | @@ -214,8 +243,8 @@ |
215 | 244 | wfProfileOut( __METHOD__ ); |
216 | 245 | return false; |
217 | 246 | } else { |
218 | | - $output->setSquidMaxage( 1200 ); |
219 | | - $output->redirect( $targetUrl, '301' ); |
| 247 | + $this->output->setSquidMaxage( 1200 ); |
| 248 | + $this->output->redirect( $targetUrl, '301' ); |
220 | 249 | } |
221 | 250 | // Special pages |
222 | 251 | } else if ( NS_SPECIAL == $title->getNamespace() ) { |
— | — | @@ -264,13 +293,12 @@ |
265 | 294 | * passed through the "action" parameter. Actions disabled in |
266 | 295 | * $wgDisabledActions will be replaced by "nosuchaction" |
267 | 296 | * |
268 | | - * @param $request WebRequest |
269 | 297 | * @return String: action |
270 | 298 | */ |
271 | | - public function getAction( WebRequest $request ) { |
| 299 | + public function getAction() { |
272 | 300 | global $wgDisabledActions; |
273 | 301 | |
274 | | - $action = $request->getVal( 'action', 'view' ); |
| 302 | + $action = $this->request->getVal( 'action', 'view' ); |
275 | 303 | |
276 | 304 | // Check for disabled actions |
277 | 305 | if ( in_array( $action, $wgDisabledActions ) ) { |
— | — | @@ -280,9 +308,9 @@ |
281 | 309 | // Workaround for bug #20966: inability of IE to provide an action dependent |
282 | 310 | // on which submit button is clicked. |
283 | 311 | if ( $action === 'historysubmit' ) { |
284 | | - if ( $request->getBool( 'revisiondelete' ) ) { |
| 312 | + if ( $this->request->getBool( 'revisiondelete' ) ) { |
285 | 313 | return 'revisiondelete'; |
286 | | - } elseif ( $request->getBool( 'revisionmove' ) ) { |
| 314 | + } elseif ( $this->request->getBool( 'revisionmove' ) ) { |
287 | 315 | return 'revisionmove'; |
288 | 316 | } else { |
289 | 317 | return 'view'; |
— | — | @@ -299,14 +327,12 @@ |
300 | 328 | * Create an Article object for the page, following redirects if needed. |
301 | 329 | * |
302 | 330 | * @param $title Title ($wgTitle) |
303 | | - * @param $output OutputPage ($wgOut) |
304 | | - * @param $request WebRequest ($wgRequest) |
305 | 331 | * @return mixed an Article, or a string to redirect to another URL |
306 | 332 | */ |
307 | | - private function initializeArticle( &$title, &$output, $request ) { |
| 333 | + private function initializeArticle( &$title ) { |
308 | 334 | wfProfileIn( __METHOD__ ); |
309 | 335 | |
310 | | - $action = $request->getVal( 'action', 'view' ); |
| 336 | + $action = $this->request->getVal( 'action', 'view' ); |
311 | 337 | $article = self::articleFromTitle( $title ); |
312 | 338 | // NS_MEDIAWIKI has no redirects. |
313 | 339 | // It is also used for CSS/JS, so performance matters here... |
— | — | @@ -318,9 +344,9 @@ |
319 | 345 | // Check for redirects ... |
320 | 346 | $file = ( $title->getNamespace() == NS_FILE ) ? $article->getFile() : null; |
321 | 347 | if ( ( $action == 'view' || $action == 'render' ) // ... for actions that show content |
322 | | - && !$request->getVal( 'oldid' ) && // ... and are not old revisions |
323 | | - !$request->getVal( 'diff' ) && // ... and not when showing diff |
324 | | - $request->getVal( 'redirect' ) != 'no' && // ... unless explicitly told not to |
| 348 | + && !$this->request->getVal( 'oldid' ) && // ... and are not old revisions |
| 349 | + !$this->request->getVal( 'diff' ) && // ... and not when showing diff |
| 350 | + $this->request->getVal( 'redirect' ) != 'no' && // ... unless explicitly told not to |
325 | 351 | // ... and the article is not a non-redirect image page with associated file |
326 | 352 | !( is_object( $file ) && $file->exists() && !$file->getRedirected() ) ) |
327 | 353 | { |
— | — | @@ -328,7 +354,7 @@ |
329 | 355 | $ignoreRedirect = $target = false; |
330 | 356 | |
331 | 357 | wfRunHooks( 'InitializeArticleMaybeRedirect', |
332 | | - array( &$title, &$request, &$ignoreRedirect, &$target, &$article ) ); |
| 358 | + array( &$title, &$this->request, &$ignoreRedirect, &$target, &$article ) ); |
333 | 359 | |
334 | 360 | // Follow redirects only for... redirects. |
335 | 361 | // If $target is set, then a hook wanted to redirect. |
— | — | @@ -350,7 +376,7 @@ |
351 | 377 | $rarticle->setRedirectedFrom( $title ); |
352 | 378 | $article = $rarticle; |
353 | 379 | $title = $target; |
354 | | - $output->setTitle( $title ); |
| 380 | + $this->output->setTitle( $title ); |
355 | 381 | } |
356 | 382 | } |
357 | 383 | } else { |
— | — | @@ -363,17 +389,15 @@ |
364 | 390 | |
365 | 391 | /** |
366 | 392 | * Cleaning up request by doing deferred updates, DB transaction, and the output |
367 | | - * |
368 | | - * @param $output OutputPage |
369 | 393 | */ |
370 | | - public function finalCleanup( &$output ) { |
| 394 | + public function finalCleanup() { |
371 | 395 | wfProfileIn( __METHOD__ ); |
372 | 396 | // Now commit any transactions, so that unreported errors after |
373 | 397 | // output() don't roll back the whole DB transaction |
374 | 398 | $factory = wfGetLBFactory(); |
375 | 399 | $factory->commitMasterChanges(); |
376 | 400 | // Output everything! |
377 | | - $output->output(); |
| 401 | + $this->output->output(); |
378 | 402 | // Do any deferred jobs |
379 | 403 | wfDoUpdates( 'commit' ); |
380 | 404 | // Close the session so that jobs don't access the current session |
— | — | @@ -432,25 +456,23 @@ |
433 | 457 | /** |
434 | 458 | * Perform one of the "standard" actions |
435 | 459 | * |
436 | | - * @param $output OutputPage |
437 | 460 | * @param $article Article |
438 | 461 | * @param $title Title |
439 | 462 | * @param $user User |
440 | | - * @param $request WebRequest |
441 | 463 | */ |
442 | | - private function performAction( &$output, &$article, &$title, &$user, &$request ) { |
| 464 | + private function performAction( &$article, &$title, &$user ) { |
443 | 465 | wfProfileIn( __METHOD__ ); |
444 | 466 | |
445 | | - if ( !wfRunHooks( 'MediaWikiPerformAction', array( $output, $article, $title, $user, $request, $this ) ) ) { |
| 467 | + if ( !wfRunHooks( 'MediaWikiPerformAction', array( $this->output, $article, $title, $user, $this->request, $this ) ) ) { |
446 | 468 | wfProfileOut( __METHOD__ ); |
447 | 469 | return; |
448 | 470 | } |
449 | 471 | |
450 | | - $action = $this->getAction( $request ); |
| 472 | + $action = $this->getAction(); |
451 | 473 | |
452 | 474 | switch( $action ) { |
453 | 475 | case 'view': |
454 | | - $output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) ); |
| 476 | + $this->output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) ); |
455 | 477 | $article->view(); |
456 | 478 | break; |
457 | 479 | case 'raw': // includes JS/CSS |
— | — | @@ -503,24 +525,24 @@ |
504 | 526 | /* Continue... */ |
505 | 527 | case 'edit': |
506 | 528 | if ( wfRunHooks( 'CustomEditor', array( $article, $user ) ) ) { |
507 | | - $internal = $request->getVal( 'internaledit' ); |
508 | | - $external = $request->getVal( 'externaledit' ); |
509 | | - $section = $request->getVal( 'section' ); |
510 | | - $oldid = $request->getVal( 'oldid' ); |
| 529 | + $internal = $this->request->getVal( 'internaledit' ); |
| 530 | + $external = $this->request->getVal( 'externaledit' ); |
| 531 | + $section = $this->request->getVal( 'section' ); |
| 532 | + $oldid = $this->request->getVal( 'oldid' ); |
511 | 533 | if ( !$this->getVal( 'UseExternalEditor' ) || $action == 'submit' || $internal || |
512 | 534 | $section || $oldid || ( !$user->getOption( 'externaleditor' ) && !$external ) ) { |
513 | 535 | $editor = new EditPage( $article ); |
514 | 536 | $editor->submit(); |
515 | 537 | } elseif ( $this->getVal( 'UseExternalEditor' ) && ( $external || $user->getOption( 'externaleditor' ) ) ) { |
516 | | - $mode = $request->getVal( 'mode' ); |
| 538 | + $mode = $this->request->getVal( 'mode' ); |
517 | 539 | $extedit = new ExternalEdit( $article, $mode ); |
518 | 540 | $extedit->edit(); |
519 | 541 | } |
520 | 542 | } |
521 | 543 | break; |
522 | 544 | case 'history': |
523 | | - if ( $request->getFullRequestURL() == $title->getInternalURL( 'action=history' ) ) { |
524 | | - $output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) ); |
| 545 | + if ( $this->request->getFullRequestURL() == $title->getInternalURL( 'action=history' ) ) { |
| 546 | + $this->output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) ); |
525 | 547 | } |
526 | 548 | $history = new HistoryPage( $article ); |
527 | 549 | $history->history(); |
— | — | @@ -537,7 +559,7 @@ |
538 | 560 | break; |
539 | 561 | default: |
540 | 562 | if ( wfRunHooks( 'UnknownAction', array( $action, $article ) ) ) { |
541 | | - $output->showErrorPage( 'nosuchaction', 'nosuchactiontext' ); |
| 563 | + $this->output->showErrorPage( 'nosuchaction', 'nosuchactiontext' ); |
542 | 564 | } |
543 | 565 | } |
544 | 566 | wfProfileOut( __METHOD__ ); |
Index: trunk/phase3/index.php |
— | — | @@ -44,7 +44,7 @@ |
45 | 45 | wfProfileIn( 'index.php-setup' ); |
46 | 46 | |
47 | 47 | # Initialize MediaWiki base class |
48 | | -$mediaWiki = new MediaWiki(); |
| 48 | +$mediaWiki = new MediaWiki( $wgRequest, $wgOut ); |
49 | 49 | |
50 | 50 | $maxLag = $wgRequest->getVal( 'maxlag' ); |
51 | 51 | if ( !is_null( $maxLag ) ) { |
— | — | @@ -56,7 +56,7 @@ |
57 | 57 | } |
58 | 58 | |
59 | 59 | # Set title from request parameters |
60 | | -$wgTitle = $mediaWiki->checkInitialQueries( $wgRequest ); |
| 60 | +$wgTitle = $mediaWiki->checkInitialQueries(); |
61 | 61 | $action = $wgRequest->getVal( 'action', 'view' ); |
62 | 62 | |
63 | 63 | wfProfileOut( 'index.php-setup' ); |
— | — | @@ -88,7 +88,7 @@ |
89 | 89 | # Tell $wgOut that output is taken care of |
90 | 90 | $wgOut->disable(); |
91 | 91 | wfProfileOut( 'index.php-filecache' ); |
92 | | - $mediaWiki->finalCleanup( $wgOut ); |
| 92 | + $mediaWiki->finalCleanup(); |
93 | 93 | wfProfileOut( 'index.php' ); |
94 | 94 | $mediaWiki->restInPeace(); |
95 | 95 | exit; |
— | — | @@ -106,8 +106,8 @@ |
107 | 107 | $mediaWiki->setVal( 'UseExternalEditor', $wgUseExternalEditor ); |
108 | 108 | $mediaWiki->setVal( 'UsePathInfo', $wgUsePathInfo ); |
109 | 109 | |
110 | | -$mediaWiki->performRequestForTitle( $wgTitle, $wgArticle, $wgOut, $wgUser, $wgRequest ); |
111 | | -$mediaWiki->finalCleanup( $wgOut ); |
| 110 | +$mediaWiki->performRequestForTitle( $wgTitle, $wgArticle, $wgUser ); |
| 111 | +$mediaWiki->finalCleanup(); |
112 | 112 | |
113 | 113 | wfProfileOut( 'index.php' ); |
114 | 114 | |