r85301 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85300‎ | r85301 | r85302 >
Date:00:18, 4 April 2011
Author:dantman
Status:ok
Tags:
Comment:
Update index.php and Wiki.php to make better use of the context.
Modified paths:
  • /trunk/phase3/includes/RequestContext.php (modified) (history)
  • /trunk/phase3/includes/Setup.php (modified) (history)
  • /trunk/phase3/includes/Wiki.php (modified) (history)
  • /trunk/phase3/index.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Setup.php
@@ -365,7 +365,7 @@
366366
367367 // Now that variant lists may be available...
368368 $wgRequest->interpolateTitle();
369 -$wgUser = $wgCommandLineMode ? new User : User::newFromSession();
 369+$wgUser = RequestContext::getMain()->user; # BackCompat
370370
371371 /**
372372 * @var Language
@@ -375,7 +375,7 @@
376376 /**
377377 * @var OutputPage
378378 */
379 -$wgOut = new OutputPage;
 379+$wgOut = RequestContext::getMain()->output; # BackCompat
380380
381381 /**
382382 * @var Parser
Index: trunk/phase3/includes/RequestContext.php
@@ -60,15 +60,6 @@
6161 }
6262
6363 /**
64 - * Set the OutputPage object
65 - *
66 - * @param $u OutputPage
67 - */
68 - public function setOutput( OutputPage $o ) {
69 - $this->mOutput = $o;
70 - }
71 -
72 - /**
7364 * Get the OutputPage object
7465 *
7566 * @return OutputPage object
Index: trunk/phase3/includes/Wiki.php
@@ -56,10 +56,8 @@
5757 return wfSetVar( $this->context->output, $x );
5858 }
5959
60 - public function __construct( WebRequest &$request, /*OutputPage*/ &$output ){
61 - $this->context = new RequestContext();
62 - $this->context->setRequest( $request );
63 - $this->context->setOutput( $output );
 60+ public function __construct( RequestContext $context ){
 61+ $this->context = $context;
6462 $this->context->setTitle( $this->parseTitle() );
6563 }
6664
@@ -68,9 +66,8 @@
6967 * Performs the request too
7068 *
7169 * @param $article Article
72 - * @param $user User
7370 */
74 - public function performRequestForTitle( &$article, &$user ) {
 71+ public function performRequestForTitle( &$article ) {
7572 wfProfileIn( __METHOD__ );
7673
7774 if ( $this->context->request->getVal( 'printable' ) === 'yes' ) {
@@ -81,7 +78,7 @@
8279 &$this->context->title,
8380 &$article,
8481 &$this->context->output,
85 - &$user,
 82+ &$this->context->user,
8683 $this->context->request,
8784 $this
8885 ) );
@@ -104,7 +101,7 @@
105102 $new_article = $this->initializeArticle();
106103 if ( is_object( $new_article ) ) {
107104 $article = $new_article;
108 - $this->performAction( $article, $user );
 105+ $this->performAction( $article );
109106 } elseif ( is_string( $new_article ) ) {
110107 $this->context->output->redirect( $new_article );
111108 } else {
@@ -454,14 +451,13 @@
455452 * Perform one of the "standard" actions
456453 *
457454 * @param $article Article
458 - * @param $user User
459455 */
460 - private function performAction( &$article, &$user ) {
 456+ private function performAction( &$article ) {
461457 wfProfileIn( __METHOD__ );
462458
463459 if ( !wfRunHooks( 'MediaWikiPerformAction', array(
464460 $this->context->output, $article, $this->context->title,
465 - $user, $this->context->request, $this ) ) )
 461+ $this->context->user, $this->context->request, $this ) ) )
466462 {
467463 wfProfileOut( __METHOD__ );
468464 return;
@@ -523,16 +519,16 @@
524520 }
525521 /* Continue... */
526522 case 'edit':
527 - if ( wfRunHooks( 'CustomEditor', array( $article, $user ) ) ) {
 523+ if ( wfRunHooks( 'CustomEditor', array( $article, $this->context->user ) ) ) {
528524 $internal = $this->context->request->getVal( 'internaledit' );
529525 $external = $this->context->request->getVal( 'externaledit' );
530526 $section = $this->context->request->getVal( 'section' );
531527 $oldid = $this->context->request->getVal( 'oldid' );
532528 if ( !$this->getVal( 'UseExternalEditor' ) || $action == 'submit' || $internal ||
533 - $section || $oldid || ( !$user->getOption( 'externaleditor' ) && !$external ) ) {
 529+ $section || $oldid || ( !$this->context->user->getOption( 'externaleditor' ) && !$external ) ) {
534530 $editor = new EditPage( $article );
535531 $editor->submit();
536 - } elseif ( $this->getVal( 'UseExternalEditor' ) && ( $external || $user->getOption( 'externaleditor' ) ) ) {
 532+ } elseif ( $this->getVal( 'UseExternalEditor' ) && ( $external || $this->context->user->getOption( 'externaleditor' ) ) ) {
537533 $mode = $this->context->request->getVal( 'mode' );
538534 $extedit = new ExternalEdit( $article, $mode );
539535 $extedit->edit();
Index: trunk/phase3/index.php
@@ -63,7 +63,8 @@
6464 }
6565
6666 # Initialize MediaWiki base class
67 -$mediaWiki = new MediaWiki( $wgRequest, $wgOut );
 67+$context = RequestContext::getMain();
 68+$mediaWiki = new MediaWiki( $context );
6869
6970 # Set title from request parameters
7071 $wgTitle = $mediaWiki->getTitle();
@@ -89,14 +90,14 @@
9091 $cache = new HTMLFileCache( $wgTitle, $action );
9192 if ( $cache->isFileCacheGood( /* Assume up to date */ ) ) {
9293 /* Check incoming headers to see if client has this cached */
93 - if ( !$wgOut->checkLastModified( $cache->fileCacheTime() ) ) {
 94+ if ( !$context->output->checkLastModified( $cache->fileCacheTime() ) ) {
9495 $cache->loadFromFileCache();
9596 }
9697 # Do any stats increment/watchlist stuff
9798 $wgArticle = MediaWiki::articleFromTitle( $wgTitle );
9899 $wgArticle->viewUpdates();
99 - # Tell $wgOut that output is taken care of
100 - $wgOut->disable();
 100+ # Tell OutputPage that output is taken care of
 101+ $context->output->disable();
101102 wfProfileOut( 'index.php-filecache' );
102103 $mediaWiki->finalCleanup();
103104 wfProfileOut( 'index.php' );
@@ -116,7 +117,7 @@
117118 $mediaWiki->setVal( 'UseExternalEditor', $wgUseExternalEditor );
118119 $mediaWiki->setVal( 'UsePathInfo', $wgUsePathInfo );
119120
120 -$mediaWiki->performRequestForTitle( $wgArticle, $wgUser );
 121+$mediaWiki->performRequestForTitle( $wgArticle );
121122 $mediaWiki->finalCleanup();
122123
123124 wfProfileOut( 'index.php' );

Status & tagging log