From: Magnus Manske Date: Wed, 11 Jan 2006 14:42:32 +0000 (+0000) Subject: Consolidation of mediaWIki calls into Wiki.php X-Git-Tag: 1.6.0~600 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/password.php?a=commitdiff_plain;h=a0302856fc2e578328c16e78678539d676b9ef32;p=lhc%2Fweb%2Fwiklou.git Consolidation of mediaWIki calls into Wiki.php --- diff --git a/includes/Wiki.php b/includes/Wiki.php index 46efdf9379..63627838e5 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -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' ) ); diff --git a/index.php b/index.php index d1428aa070..1d8d63e650 100644 --- 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