From: Magnus Manske Date: Fri, 13 Jan 2006 12:52:04 +0000 (+0000) Subject: index.php now fits on a single screen :-) X-Git-Tag: 1.6.0~574 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=b71834bdecb980febf07dcbfd5522caf37e76aa2;p=lhc%2Fweb%2Fwiklou.git index.php now fits on a single screen :-) --- diff --git a/includes/Wiki.php b/includes/Wiki.php index 3551d487e3..30994a5fd6 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -36,6 +36,28 @@ class MediaWiki { return $default; } + /** + * Wrapper for getrusage, if it exists + * getrusage() does not exist on the Window$ platform, catching this + */ + function getRUsage() { + if ( function_exists ( 'getrusage' ) ) { + return getrusage(); + } else { + return array(); + } + } + + /** + * CHeck for $GLOBALS vulnerability + */ + function ckeckGlobalsVulnerability() { + @ini_set( 'allow_url_fopen', 0 ); # For security... + if ( isset( $_REQUEST['GLOBALS'] ) ) { + die( '$GLOBALS overwrite vulnerability'); + } + } + /** * Checks if the wiki is set up at all, or configured but not activated */ @@ -56,22 +78,32 @@ class MediaWiki { $msg = "Please setup the wiki first."; } $out = str_replace( "$2", $msg, $out ); - echo $out ; + echo $out; die(); } + /** + * Reads title and action values from request + */ + function initializeActionTitle () { + $request = $this->getVal( 'Request' ); + $this->setVal( 'action', $request->getVal( 'action', 'view' ) ); + $this->setVal( 'urltitle', $request->getVal( 'title' ) ); + } + /** * Initialization of ... everything @return Article either the object to become $wgArticle, or NULL */ - function initialize ( &$title, &$output, &$user, $request) { + function initialize ( &$title, &$output, &$user ) { wfProfileIn( 'MediaWiki::initialize' ); - $this->preliminaryChecks ( $title, $output, $request ) ; + $request = $this->getVal( 'Request' ); + $this->preliminaryChecks ( $title, $output ); $article = NULL; - if ( !$this->initializeSpecialCases( $title, $output, $request ) ) { - $article = $this->initializeArticle( $title, $request ); + if ( !$this->initializeSpecialCases( $title, $output ) ) { + $article = $this->initializeArticle( $title ); if( is_object( $article ) ) { - $this->performAction( $output, $article, $title, $user, $request ); + $this->performAction( $output, $article, $title, $user ); } elseif( is_string( $article ) ) { $output->redirect( $article ); } else { @@ -84,15 +116,17 @@ class MediaWiki { /** * Checks some initial queries - * Note that $title here is *not* a Title object, but a string! */ - function checkInitialQueries( $title,$action,&$output,$request, $lang) { + function checkInitialQueries( &$output, $lang) { wfProfileIn( 'MediaWiki::checkInitialQueries' ); + $request = $this->getVal( 'Request' ); + $action = $this->getVal( 'action' ); + $title = $this->getVal( 'urltitle' ); if ($request->getVal( 'printable' ) == 'yes') { $output->setPrintable(); } - $ret = NULL ; + $ret = NULL; if ( '' == $title && 'delete' != $action ) { @@ -110,14 +144,14 @@ class MediaWiki { } wfProfileOut( 'MediaWiki::checkInitialQueries' ); - return $ret ; + return $ret; } /** * Checks for search query and anon-cannot-read case */ - function preliminaryChecks ( &$title, &$output, $request ) { - + function preliminaryChecks ( &$title, &$output ) { + $request = $this->getVal( 'Request' ); # Debug statement for user levels // print_r($wgUser); @@ -143,9 +177,9 @@ class MediaWiki { /** * Initialize the object to be known as $wgArticle for special cases */ - function initializeSpecialCases ( &$title, &$output, $request ) { - + function initializeSpecialCases ( &$title, &$output ) { wfProfileIn( 'MediaWiki::initializeSpecialCases' ); + $request = $this->getVal( 'Request' ); $search = $this->getVal('Search'); $action = $this->getVal('Action'); @@ -216,13 +250,12 @@ class MediaWiki { * Initialize the object to be known as $wgArticle for "standard" actions * Create an Article object for the page, following redirects if needed. * @param Title $title - * @param Request $request - * @param string $action * @return mixed an Article, or a string to redirect to another URL */ - function initializeArticle( $title, $request ) { + function initializeArticle( $title ) { wfProfileIn( 'MediaWiki::initializeArticle' ); + $request = $this->getVal( 'Request' ); $action = $this->getVal('Action'); $article = $this->articleFromTitle( $title ); @@ -288,10 +321,10 @@ class MediaWiki { /** * Perform one of the "standard" actions */ - function performAction( &$output, &$article, &$title, &$user, &$request ) { - + function performAction( &$output, &$article, &$title, &$user ) { wfProfileIn( 'MediaWiki::performAction' ); - + + $request = $this->getVal( 'Request' ); $action = $this->getVal('Action'); if( in_array( $action, $this->getVal('DisabledActions',array()) ) ) { /* No such action; this will switch to the default case */ diff --git a/index.php b/index.php index 97b2bf80bf..eb8531f32d 100644 --- a/index.php +++ b/index.php @@ -3,21 +3,13 @@ * Main wiki script; see docs/design.txt * @package MediaWiki */ -$wgRequestTime = microtime(); - -# getrusage() does not exist on the Window$ platform, catching this -if ( function_exists ( 'getrusage' ) ) { - $wgRUstart = getrusage(); -} else { - $wgRUstart = array(); -} +# In the beginning... +require_once( "./includes/Wiki.php" ); +$wgRequestTime = microtime(); +$wgRUstart = MediaWiki::getRUsage(); unset( $IP ); -@ini_set( 'allow_url_fopen', 0 ); # For security... - -if ( isset( $_REQUEST['GLOBALS'] ) ) { - die( '$GLOBALS overwrite vulnerability'); -} +MediaWiki::ckeckGlobalsVulnerability(); # Valid web server entry point, enable includes. # Please don't move this line to includes/Defines.php. This line essentially defines @@ -25,24 +17,26 @@ if ( isset( $_REQUEST['GLOBALS'] ) ) { # it becomes an entry point, thereby defeating its purpose. define( 'MEDIAWIKI', true ); require_once( './includes/Defines.php' ); -@include_once( './LocalSettings.php' ); # Will die later if not included anyway # Initialize MediaWiki base class -require_once( "includes/Wiki.php" ); $mediaWiki = new MediaWiki(); - - $mediaWiki->checkSetup(); -require_once( 'includes/Setup.php' ); # This can't be done in mdiaWiki.php for some weird reason + +# These can't be done in mdiaWiki.php for some weird reason +require_once( './LocalSettings.php' ); +require_once( 'includes/Setup.php' ); OutputPage::setEncodings(); # Not really used yet +$mediaWiki->setVal( "Request", $wgRequest ); + # Query string fields -$action = $wgRequest->getVal( 'action', 'view' ); -$title = $wgRequest->getVal( 'title' ); +$mediaWiki->initializeActionTitle(); +$action = $mediaWiki->getVal( 'action' ); # Global might be needed somewhere, sadly... -$wgTitle = $mediaWiki->checkInitialQueries( $title,$action,$wgOut, $wgRequest, $wgContLang ); +# Run initial queries +$wgTitle = $mediaWiki->checkInitialQueries( $wgOut, $wgContLang ); # Is this necessary? Who knows... if ($wgTitle == NULL) { @@ -52,7 +46,6 @@ if ($wgTitle == NULL) { # Setting global variables in mediaWiki $mediaWiki->setVal( "Server", $wgServer ); $mediaWiki->setVal( "DisableInternalSearch", $wgDisableInternalSearch ); -$mediaWiki->setVal( "action", $action ); $mediaWiki->setVal( "SquidMaxage", $wgSquidMaxage ); $mediaWiki->setVal( "EnableDublinCoreRdf", $wgEnableDublinCoreRdf ); $mediaWiki->setVal( "EnableCreativeCommonsRdf", $wgEnableCreativeCommonsRdf ); @@ -60,11 +53,8 @@ $mediaWiki->setVal( "CommandLineMode", $wgCommandLineMode ); $mediaWiki->setVal( "UseExternalEditor", $wgUseExternalEditor ); $mediaWiki->setVal( "DisabledActions", $wgDisabledActions ); -$wgArticle = $mediaWiki->initialize ( $wgTitle, $wgOut, $wgUser, $wgRequest ); +$wgArticle = $mediaWiki->initialize ( $wgTitle, $wgOut, $wgUser ); $mediaWiki->finalCleanup ( $wgDeferredUpdateList, $wgLoadBalancer, $wgOut ); - -# Not sure when $wgPostCommitUpdateList gets set, so I keep this separate from finalCleanup $mediaWiki->doUpdates( $wgPostCommitUpdateList ); - $mediaWiki->restInPeace( $wgLoadBalancer ); ?>