Most of index.php now in Wiki.php
authorMagnus Manske <magnusmanske@users.mediawiki.org>
Wed, 11 Jan 2006 15:46:01 +0000 (15:46 +0000)
committerMagnus Manske <magnusmanske@users.mediawiki.org>
Wed, 11 Jan 2006 15:46:01 +0000 (15:46 +0000)
RELEASE-NOTES
includes/Wiki.php
index.php

index d0b5524..17d9f85 100644 (file)
@@ -460,6 +460,8 @@ fully support the editing toolbar, but was found to be too confusing.
 * Cleanup and error checking on Special:Listredirects
 * Clear up some instances of old OutputPage::sysopRequired() function usage
 * Improve "upload disabled" notice
+* Move parts of index.php to include/Wiki.php in an attempt to both cleanup index.php 
+  and create a MediaWiki-class mediaWiki base object
 
 === Caveats ===
 
index 6362783..0c8633e 100644 (file)
@@ -42,6 +42,7 @@ class MediaWiki {
         */
        function initialize ( &$title, &$output, &$user, $request ) {
                wfProfileIn( 'MediaWiki::initialize' );
+               $this->preliminaryChecks ( $title , $output , $request ) ;
                $article = NULL;
                if ( !$this->initializeSpecialCases( $title, $output, $request ) ) {
                        $article = $this->initializeArticle( $title, $request );
@@ -51,6 +52,30 @@ class MediaWiki {
                return $article;
        }
        
+       function preliminaryChecks ( &$title , &$output , $request ) {
+       
+               # Debug statement for user levels
+               // print_r($wgUser);
+               
+               $search = $request->getText( 'search' );
+               if( !is_null( $search ) && $search !== '' ) {
+                       // Compatibility with old search URLs which didn't use Special:Search
+                       // Do this above the read whitelist check for security...
+                       $title = Title::makeTitle( NS_SPECIAL, 'Search' );
+               }
+               $this->setVal( "Search", $search );
+
+               # If the user is not logged in, the Namespace:title of the article must be in
+               # the Read array in order for the user to see it. (We have to check here to
+               # catch special pages etc. We check again in Article::view())
+               if ( !is_null( $title ) && !$title->userCanRead() ) {
+                       $output->loginToUse();
+                       $output->output();
+                       exit;
+               }
+               
+       }
+       
        /**
         * Initialize the object to be known as $wgArticle for special cases
         */
@@ -146,6 +171,42 @@ class MediaWiki {
                return $article;
        }
 
+       /**
+        * Cleaning up by doing deferred updates, calling loadbalancer and doing the output
+        */
+       function finalCleanup ( &$deferredUpdates , &$loadBalancer , &$output ) {
+               wfProfileIn( 'MediaWiki::finalCleanup' );
+               $this->doUpdates( $deferredUpdates );
+               $loadBalancer->saveMasterPos();
+               # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
+               $loadBalancer->commitAll();
+               $output->output();
+               wfProfileOut( 'MediaWiki::finalCleanup' );
+       }
+
+       /**
+        * Deferred updates aren't really deferred anymore. It's important to report errors to the
+        * user, and that means doing this before OutputPage::output(). Note that for page saves,
+        * the client will wait until the script exits anyway before following the redirect.
+        */
+       function doUpdates ( &$updates ) {
+               wfProfileIn( 'MediaWiki::doUpdates' );
+               foreach( $updates as $up ) {
+                       $up->doUpdate();
+               }
+               wfProfileOut( 'MediaWiki::doUpdates' );         
+       }
+       
+       /**
+        * Ends this task peacefully
+        */
+       function restInPeace ( &$loadBalancer ) {
+               wfProfileClose();
+               logProfilingData();
+               $loadBalancer->closeAll();
+               wfDebug( "Request ended normally\n" );
+       }
+
        /**
         * Perform one of the "standard" actions
         */
@@ -243,8 +304,9 @@ class MediaWiki {
                                        $output->errorpage( 'nosuchaction', 'nosuchactiontext' );
                                }
                wfProfileOut( 'MediaWiki::performAction' );
+       }
 
-               }
+       
        }
 
 }; /* End of class MediaWiki */
index 1d8d63e..883f42d 100644 (file)
--- a/index.php
+++ b/index.php
@@ -98,34 +98,14 @@ if ( '' == $title && 'delete' != $action ) {
 }
 wfProfileOut( 'main-misc-setup' );
 
-# Debug statement for user levels
-// print_r($wgUser);
-
-$search = $wgRequest->getText( 'search' );
-if( !is_null( $search ) && $search !== '' ) {
-       // Compatibility with old search URLs which didn't use Special:Search
-       // Do this above the read whitelist check for security...
-       $wgTitle = Title::makeTitle( NS_SPECIAL, 'Search' );
-}
-
-# If the user is not logged in, the Namespace:title of the article must be in
-# the Read array in order for the user to see it. (We have to check here to
-# catch special pages etc. We check again in Article::view())
-if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
-       $wgOut->loginToUse();
-       $wgOut->output();
-       exit;
-}
-
-wfProfileIn( 'main-action' );
 
 # Initialize MediaWiki base class
 require_once( "includes/Wiki.php" );
 $mediaWiki = new MediaWiki();
 
+# Setting global variables in 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 );
@@ -135,34 +115,10 @@ $mediaWiki->setVal( "UseExternalEditor", $wgUseExternalEditor );
 $mediaWiki->setVal( "DisabledActions", $wgDisabledActions );
 
 $wgArticle = $mediaWiki->initialize ( $wgTitle, $wgOut, $wgUser, $wgRequest );
+$mediaWiki->finalCleanup ( $wgDeferredUpdateList , $wgLoadBalancer , $wgOut ) ;
 
-wfProfileOut( 'main-action' );
-
-# Deferred updates aren't really deferred anymore. It's important to report errors to the
-# user, and that means doing this before OutputPage::output(). Note that for page saves,
-# the client will wait until the script exits anyway before following the redirect.
-wfProfileIn( 'main-updates' );
-foreach( $wgDeferredUpdateList as $up ) {
-       $up->doUpdate();
-}
-wfProfileOut( 'main-updates' );
-
-wfProfileIn( 'main-cleanup' );
-$wgLoadBalancer->saveMasterPos();
-
-# Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
-$wgLoadBalancer->commitAll();
-
-$wgOut->output();
-
-foreach( $wgPostCommitUpdateList as $up ) {
-       $up->doUpdate();
-}
-
-wfProfileOut( 'main-cleanup' );
+# Not sure when $wgPostCommitUpdateList gets set, so I keep this separate from finalCleanup
+$mediaWiki->doUpdates( $wgPostCommitUpdateList );
 
-wfProfileClose();
-logProfilingData();
-$wgLoadBalancer->closeAll();
-wfDebug( "Request ended normally\n" );
+$mediaWiki->restInPeace( $wgLoadBalancer );
 ?>