Update index.php and Wiki.php to make better use of the context.
authorDaniel Friesen <dantman@users.mediawiki.org>
Mon, 4 Apr 2011 00:18:33 +0000 (00:18 +0000)
committerDaniel Friesen <dantman@users.mediawiki.org>
Mon, 4 Apr 2011 00:18:33 +0000 (00:18 +0000)
includes/RequestContext.php
includes/Setup.php
includes/Wiki.php
index.php

index b0c4ecd..4fd7222 100644 (file)
@@ -59,15 +59,6 @@ class RequestContext {
                return $this->mTitle;
        }
 
-       /**
-        * Set the OutputPage object
-        *
-        * @param $u OutputPage
-        */
-       public function setOutput( OutputPage $o ) {
-               $this->mOutput = $o;
-       }
-
        /**
         * Get the OutputPage object
         *
index 37d9a47..9bfe418 100644 (file)
@@ -365,7 +365,7 @@ $wgContLang = new StubContLang;
 
 // Now that variant lists may be available...
 $wgRequest->interpolateTitle();
-$wgUser = $wgCommandLineMode ? new User : User::newFromSession();
+$wgUser = RequestContext::getMain()->user; # BackCompat
 
 /**
  * @var Language
@@ -375,7 +375,7 @@ $wgLang = new StubUserLang;
 /**
  * @var OutputPage
  */
-$wgOut = new OutputPage;
+$wgOut = RequestContext::getMain()->output; # BackCompat
 
 /**
  * @var Parser
index 6ef86f1..b8c966b 100644 (file)
@@ -56,10 +56,8 @@ class MediaWiki {
                return wfSetVar( $this->context->output, $x );
        }
 
-       public function __construct( WebRequest &$request, /*OutputPage*/ &$output ){
-               $this->context = new RequestContext();
-               $this->context->setRequest( $request );
-               $this->context->setOutput( $output );
+       public function __construct( RequestContext $context ){
+               $this->context = $context;
                $this->context->setTitle( $this->parseTitle() );
        }
 
@@ -68,9 +66,8 @@ class MediaWiki {
         * Performs the request too
         *
         * @param $article Article
-        * @param $user User
         */
-       public function performRequestForTitle( &$article, &$user ) {
+       public function performRequestForTitle( &$article ) {
                wfProfileIn( __METHOD__ );
 
                if ( $this->context->request->getVal( 'printable' ) === 'yes' ) {
@@ -81,7 +78,7 @@ class MediaWiki {
                        &$this->context->title,
                        &$article,
                        &$this->context->output,
-                       &$user,
+                       &$this->context->user,
                        $this->context->request,
                        $this
                ) );
@@ -104,7 +101,7 @@ class MediaWiki {
                        $new_article = $this->initializeArticle();
                        if ( is_object( $new_article ) ) {
                                $article = $new_article;
-                               $this->performAction( $article, $user );
+                               $this->performAction( $article );
                        } elseif ( is_string( $new_article ) ) {
                                $this->context->output->redirect( $new_article );
                        } else {
@@ -454,14 +451,13 @@ class MediaWiki {
         * Perform one of the "standard" actions
         *
         * @param $article Article
-        * @param $user User
         */
-       private function performAction( &$article, &$user ) {
+       private function performAction( &$article ) {
                wfProfileIn( __METHOD__ );
 
                if ( !wfRunHooks( 'MediaWikiPerformAction', array(
                                $this->context->output, $article, $this->context->title,
-                               $user, $this->context->request, $this ) ) )
+                               $this->context->user, $this->context->request, $this ) ) )
                {
                        wfProfileOut( __METHOD__ );
                        return;
@@ -523,16 +519,16 @@ class MediaWiki {
                                }
                                /* Continue... */
                        case 'edit':
-                               if ( wfRunHooks( 'CustomEditor', array( $article, $user ) ) ) {
+                               if ( wfRunHooks( 'CustomEditor', array( $article, $this->context->user ) ) ) {
                                        $internal = $this->context->request->getVal( 'internaledit' );
                                        $external = $this->context->request->getVal( 'externaledit' );
                                        $section = $this->context->request->getVal( 'section' );
                                        $oldid = $this->context->request->getVal( 'oldid' );
                                        if ( !$this->getVal( 'UseExternalEditor' ) || $action == 'submit' || $internal ||
-                                          $section || $oldid || ( !$user->getOption( 'externaleditor' ) && !$external ) ) {
+                                          $section || $oldid || ( !$this->context->user->getOption( 'externaleditor' ) && !$external ) ) {
                                                $editor = new EditPage( $article );
                                                $editor->submit();
-                                       } elseif ( $this->getVal( 'UseExternalEditor' ) && ( $external || $user->getOption( 'externaleditor' ) ) ) {
+                                       } elseif ( $this->getVal( 'UseExternalEditor' ) && ( $external || $this->context->user->getOption( 'externaleditor' ) ) ) {
                                                $mode = $this->context->request->getVal( 'mode' );
                                                $extedit = new ExternalEdit( $article, $mode );
                                                $extedit->edit();
index 560ee92..8faead5 100644 (file)
--- a/index.php
+++ b/index.php
@@ -63,7 +63,8 @@ if ( !is_null( $maxLag ) ) {
 }
 
 # Initialize MediaWiki base class
-$mediaWiki = new MediaWiki( $wgRequest, $wgOut );
+$context = RequestContext::getMain();
+$mediaWiki = new MediaWiki( $context );
 
 # Set title from request parameters
 $wgTitle = $mediaWiki->getTitle();
@@ -89,14 +90,14 @@ if ( $wgUseFileCache && $wgTitle !== null ) {
                $cache = new HTMLFileCache( $wgTitle, $action );
                if ( $cache->isFileCacheGood( /* Assume up to date */ ) ) {
                        /* Check incoming headers to see if client has this cached */
-                       if ( !$wgOut->checkLastModified( $cache->fileCacheTime() ) ) {
+                       if ( !$context->output->checkLastModified( $cache->fileCacheTime() ) ) {
                                $cache->loadFromFileCache();
                        }
                        # Do any stats increment/watchlist stuff
                        $wgArticle = MediaWiki::articleFromTitle( $wgTitle );
                        $wgArticle->viewUpdates();
-                       # Tell $wgOut that output is taken care of
-                       $wgOut->disable();
+                       # Tell OutputPage that output is taken care of
+                       $context->output->disable();
                        wfProfileOut( 'index.php-filecache' );
                        $mediaWiki->finalCleanup();
                        wfProfileOut( 'index.php' );
@@ -116,7 +117,7 @@ $mediaWiki->setVal( 'SquidMaxage', $wgSquidMaxage );
 $mediaWiki->setVal( 'UseExternalEditor', $wgUseExternalEditor );
 $mediaWiki->setVal( 'UsePathInfo', $wgUsePathInfo );
 
-$mediaWiki->performRequestForTitle( $wgArticle, $wgUser );
+$mediaWiki->performRequestForTitle( $wgArticle );
 $mediaWiki->finalCleanup();
 
 wfProfileOut( 'index.php' );