Consolidation of mediaWIki calls into Wiki.php
authorMagnus Manske <magnusmanske@users.mediawiki.org>
Wed, 11 Jan 2006 14:42:32 +0000 (14:42 +0000)
committerMagnus Manske <magnusmanske@users.mediawiki.org>
Wed, 11 Jan 2006 14:42:32 +0000 (14:42 +0000)
includes/Wiki.php
index.php

index 46efdf9..6362783 100644 (file)
@@ -15,10 +15,19 @@ class MediaWiki {
                $this->GET = $_GET;
        }
        
+       /**
+        * Stores key/value pairs to circumvent global variables
+        * Note that keys are case-insensitive!
+        */
        function setVal( $key, &$value ) {
-               $this->param[strtolower( $key )] = $value;
+               $key = strtolower( $key );
+               $this->params[$key] =& $value;
        }
        
+       /**
+        * Retieves key/value pairs to circumvent global variables
+        * Note that keys are case-insensitive!
+        */
        function getVal( $key, $default = "" ) {
                $key = strtolower( $key );
                if( isset( $this->params[$key] ) ) {
@@ -27,11 +36,30 @@ class MediaWiki {
                return $default;
        }
        
+       /**
+        * Initialization of ... everything
+        @return Article either the object to become $wgArticle, or NULL
+        */
+       function initialize ( &$title, &$output, &$user, $request ) {
+               wfProfileIn( 'MediaWiki::initialize' );
+               $article = NULL;
+               if ( !$this->initializeSpecialCases( $title, $output, $request ) ) {
+                       $article = $this->initializeArticle( $title, $request );
+                       $this->performAction( $output, $article, $title, $user, $request );
+               }
+               wfProfileOut( 'MediaWiki::initialize' );
+               return $article;
+       }
+       
        /**
         * Initialize the object to be known as $wgArticle for special cases
         */
-       function initializeSpecialCases ( &$title , &$output , $request , $action , &$search ) {
+       function initializeSpecialCases ( &$title, &$output, $request ) {
+
                wfProfileIn( 'MediaWiki::initializeSpecialCases' );
+               
+               $search = $this->getVal('Search');
+               $action = $this->getVal('Action');
                if( !$this->getVal('DisableInternalSearch') && !is_null( $search ) && $search !== '' ) {
                        require_once( 'includes/SpecialSearch.php' );
                        $title = Title::makeTitle( NS_SPECIAL, 'Search' );
@@ -75,9 +103,11 @@ class MediaWiki {
        /**
         * Initialize the object to be known as $wgArticle for "standard" actions
         */
-       function initializeArticle( &$title, $request, $action ) {
+       function initializeArticle( &$title, $request ) {
 
                wfProfileIn( 'MediaWiki::initializeArticle' );
+               
+               $action = $this->getVal('Action');
 
                if( NS_MEDIA == $title->getNamespace() ) {
                        $title = Title::makeTitle( NS_IMAGE, $title->getDBkey() );
@@ -119,10 +149,16 @@ class MediaWiki {
        /**
         * Perform one of the "standard" actions
         */
-       function performAction( $action, &$output, &$article, &$title, &$user, &$request ) {
+       function performAction( &$output, &$article, &$title, &$user, &$request ) {
 
                wfProfileIn( 'MediaWiki::performAction' );
 
+               $action = $this->getVal('Action');
+               if( in_array( $action, $this->getVal('DisabledActions',array()) ) ) {
+                       /* No such action; this will switch to the default case */
+                       $action = "nosuchaction"; 
+               }
+
                switch( $action ) {
                        case 'view':
                                $output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) );
index d1428aa..1d8d63e 100644 (file)
--- a/index.php
+++ b/index.php
@@ -9,7 +9,7 @@ $wgRequestTime = microtime();
 if ( function_exists ( 'getrusage' ) ) {
        $wgRUstart = getrusage();
 } else {
-       $wgRUstart = array() ;
+       $wgRUstart = array();
 }
 
 unset( $IP );
@@ -120,29 +120,22 @@ if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
 wfProfileIn( 'main-action' );
 
 # Initialize MediaWiki base class
-require_once( "includes/Wiki.php" ) ;
-$mediaWiki = new MediaWiki() ;
+require_once( "includes/Wiki.php" );
+$mediaWiki = new MediaWiki();
 
 $mediaWiki->setVal( "Server", $wgServer );
 $mediaWiki->setVal( "DisableInternalSearch", $wgDisableInternalSearch );
+$mediaWiki->setVal( "Search", $search );
+$mediaWiki->setVal( "action", $action );
+$mediaWiki->setVal( "SquidMaxage", $wgSquidMaxage );
+$mediaWiki->setVal( "EnableDublinCoreRdf", $wgEnableDublinCoreRdf );
+$mediaWiki->setVal( "EnableCreativeCommonsRdf", $wgEnableCreativeCommonsRdf );
+$mediaWiki->setVal( "CommandLineMode", $wgCommandLineMode );
+$mediaWiki->setVal( "UseExternalEditor", $wgUseExternalEditor );
+$mediaWiki->setVal( "DisabledActions", $wgDisabledActions );
 
-if ( !$mediaWiki->initializeSpecialCases( $wgTitle , $wgOut , $wgRequest , $action , $search ) ) {
+$wgArticle = $mediaWiki->initialize ( $wgTitle, $wgOut, $wgUser, $wgRequest );
 
-       $wgArticle = $mediaWiki->initializeArticle( $wgTitle, $wgRequest, $action );
-
-       if( in_array( $action, $wgDisabledActions ) ) {
-               $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
-       } else {
-               $mediaWiki->setVal( "SquidMaxage", $wgSquidMaxage );
-               $mediaWiki->setVal( "EnableDublinCoreRdf", $wgEnableDublinCoreRdf );
-               $mediaWiki->setVal( "EnableCreativeCommonsRdf", $wgEnableCreativeCommonsRdf );
-               $mediaWiki->setVal( "CommandLineMode", $wgCommandLineMode );
-               $mediaWiki->setVal( "UseExternalEditor", $wgUseExternalEditor );
-               $mediaWiki->performAction( $action, $wgOut, $wgArticle, $wgTitle, $wgUser, $wgRequest );
-       }
-
-
-}
 wfProfileOut( 'main-action' );
 
 # Deferred updates aren't really deferred anymore. It's important to report errors to the