r12646 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r12645‎ | r12646 | r12647 >
Date:12:52, 13 January 2006
Author:magnus_manske
Status:old
Tags:
Comment:
index.php now fits on a single screen :-)
Modified paths:
  • /trunk/phase3/includes/Wiki.php (modified) (history)
  • /trunk/phase3/index.php (modified) (history)

Diff [purge]

Index: trunk/phase3/index.php
@@ -3,46 +3,40 @@
44 * Main wiki script; see docs/design.txt
55 * @package MediaWiki
66 */
7 -$wgRequestTime = microtime();
87
9 -# getrusage() does not exist on the Window$ platform, catching this
10 -if ( function_exists ( 'getrusage' ) ) {
11 - $wgRUstart = getrusage();
12 -} else {
13 - $wgRUstart = array();
14 -}
15 -
 8+# In the beginning...
 9+require_once( "./includes/Wiki.php" );
 10+$wgRequestTime = microtime();
 11+$wgRUstart = MediaWiki::getRUsage();
1612 unset( $IP );
17 -@ini_set( 'allow_url_fopen', 0 ); # For security...
 13+MediaWiki::ckeckGlobalsVulnerability();
1814
19 -if ( isset( $_REQUEST['GLOBALS'] ) ) {
20 - die( '<a href="http://www.hardened-php.net/index.76.html">$GLOBALS overwrite vulnerability</a>');
21 -}
22 -
2315 # Valid web server entry point, enable includes.
2416 # Please don't move this line to includes/Defines.php. This line essentially defines
2517 # a valid entry point. If you put it in includes/Defines.php, then any script that includes
2618 # it becomes an entry point, thereby defeating its purpose.
2719 define( 'MEDIAWIKI', true );
2820 require_once( './includes/Defines.php' );
29 -@include_once( './LocalSettings.php' ); # Will die later if not included anyway
3021
3122
3223 # Initialize MediaWiki base class
33 -require_once( "includes/Wiki.php" );
3424 $mediaWiki = new MediaWiki();
35 -
36 -
3725 $mediaWiki->checkSetup();
38 -require_once( 'includes/Setup.php' ); # This can't be done in mdiaWiki.php for some weird reason
3926
 27+# These can't be done in mdiaWiki.php for some weird reason
 28+require_once( './LocalSettings.php' );
 29+require_once( 'includes/Setup.php' );
 30+
4031 OutputPage::setEncodings(); # Not really used yet
4132
 33+$mediaWiki->setVal( "Request", $wgRequest );
 34+
4235 # Query string fields
43 -$action = $wgRequest->getVal( 'action', 'view' );
44 -$title = $wgRequest->getVal( 'title' );
 36+$mediaWiki->initializeActionTitle();
 37+$action = $mediaWiki->getVal( 'action' ); # Global might be needed somewhere, sadly...
4538
46 -$wgTitle = $mediaWiki->checkInitialQueries( $title,$action,$wgOut, $wgRequest, $wgContLang );
 39+# Run initial queries
 40+$wgTitle = $mediaWiki->checkInitialQueries( $wgOut, $wgContLang );
4741
4842 # Is this necessary? Who knows...
4943 if ($wgTitle == NULL) {
@@ -52,7 +46,6 @@
5347 # Setting global variables in mediaWiki
5448 $mediaWiki->setVal( "Server", $wgServer );
5549 $mediaWiki->setVal( "DisableInternalSearch", $wgDisableInternalSearch );
56 -$mediaWiki->setVal( "action", $action );
5750 $mediaWiki->setVal( "SquidMaxage", $wgSquidMaxage );
5851 $mediaWiki->setVal( "EnableDublinCoreRdf", $wgEnableDublinCoreRdf );
5952 $mediaWiki->setVal( "EnableCreativeCommonsRdf", $wgEnableCreativeCommonsRdf );
@@ -60,11 +53,8 @@
6154 $mediaWiki->setVal( "UseExternalEditor", $wgUseExternalEditor );
6255 $mediaWiki->setVal( "DisabledActions", $wgDisabledActions );
6356
64 -$wgArticle = $mediaWiki->initialize ( $wgTitle, $wgOut, $wgUser, $wgRequest );
 57+$wgArticle = $mediaWiki->initialize ( $wgTitle, $wgOut, $wgUser );
6558 $mediaWiki->finalCleanup ( $wgDeferredUpdateList, $wgLoadBalancer, $wgOut );
66 -
67 -# Not sure when $wgPostCommitUpdateList gets set, so I keep this separate from finalCleanup
6859 $mediaWiki->doUpdates( $wgPostCommitUpdateList );
69 -
7060 $mediaWiki->restInPeace( $wgLoadBalancer );
7161 ?>
Index: trunk/phase3/includes/Wiki.php
@@ -37,6 +37,28 @@
3838 }
3939
4040 /**
 41+ * Wrapper for getrusage, if it exists
 42+ * getrusage() does not exist on the Window$ platform, catching this
 43+ */
 44+ function getRUsage() {
 45+ if ( function_exists ( 'getrusage' ) ) {
 46+ return getrusage();
 47+ } else {
 48+ return array();
 49+ }
 50+ }
 51+
 52+ /**
 53+ * CHeck for $GLOBALS vulnerability
 54+ */
 55+ function ckeckGlobalsVulnerability() {
 56+ @ini_set( 'allow_url_fopen', 0 ); # For security...
 57+ if ( isset( $_REQUEST['GLOBALS'] ) ) {
 58+ die( '<a href="http://www.hardened-php.net/index.76.html">$GLOBALS overwrite vulnerability</a>');
 59+ }
 60+ }
 61+
 62+ /**
4163 * Checks if the wiki is set up at all, or configured but not activated
4264 */
4365 function checkSetup() {
@@ -56,22 +78,32 @@
5779 $msg = "Please <a href='config/index.php' title='setup'>setup the wiki</a> first.";
5880 }
5981 $out = str_replace( "$2", $msg, $out );
60 - echo $out ;
 82+ echo $out;
6183 die();
6284 }
6385
6486 /**
 87+ * Reads title and action values from request
 88+ */
 89+ function initializeActionTitle () {
 90+ $request = $this->getVal( 'Request' );
 91+ $this->setVal( 'action', $request->getVal( 'action', 'view' ) );
 92+ $this->setVal( 'urltitle', $request->getVal( 'title' ) );
 93+ }
 94+
 95+ /**
6596 * Initialization of ... everything
6697 @return Article either the object to become $wgArticle, or NULL
6798 */
68 - function initialize ( &$title, &$output, &$user, $request) {
 99+ function initialize ( &$title, &$output, &$user ) {
69100 wfProfileIn( 'MediaWiki::initialize' );
70 - $this->preliminaryChecks ( $title, $output, $request ) ;
 101+ $request = $this->getVal( 'Request' );
 102+ $this->preliminaryChecks ( $title, $output );
71103 $article = NULL;
72 - if ( !$this->initializeSpecialCases( $title, $output, $request ) ) {
73 - $article = $this->initializeArticle( $title, $request );
 104+ if ( !$this->initializeSpecialCases( $title, $output ) ) {
 105+ $article = $this->initializeArticle( $title );
74106 if( is_object( $article ) ) {
75 - $this->performAction( $output, $article, $title, $user, $request );
 107+ $this->performAction( $output, $article, $title, $user );
76108 } elseif( is_string( $article ) ) {
77109 $output->redirect( $article );
78110 } else {
@@ -84,15 +116,17 @@
85117
86118 /**
87119 * Checks some initial queries
88 - * Note that $title here is *not* a Title object, but a string!
89120 */
90 - function checkInitialQueries( $title,$action,&$output,$request, $lang) {
 121+ function checkInitialQueries( &$output, $lang) {
91122 wfProfileIn( 'MediaWiki::checkInitialQueries' );
 123+ $request = $this->getVal( 'Request' );
 124+ $action = $this->getVal( 'action' );
 125+ $title = $this->getVal( 'urltitle' );
92126 if ($request->getVal( 'printable' ) == 'yes') {
93127 $output->setPrintable();
94128 }
95129
96 - $ret = NULL ;
 130+ $ret = NULL;
97131
98132
99133 if ( '' == $title && 'delete' != $action ) {
@@ -110,14 +144,14 @@
111145
112146 }
113147 wfProfileOut( 'MediaWiki::checkInitialQueries' );
114 - return $ret ;
 148+ return $ret;
115149 }
116150
117151 /**
118152 * Checks for search query and anon-cannot-read case
119153 */
120 - function preliminaryChecks ( &$title, &$output, $request ) {
121 -
 154+ function preliminaryChecks ( &$title, &$output ) {
 155+ $request = $this->getVal( 'Request' );
122156 # Debug statement for user levels
123157 // print_r($wgUser);
124158
@@ -143,9 +177,9 @@
144178 /**
145179 * Initialize the object to be known as $wgArticle for special cases
146180 */
147 - function initializeSpecialCases ( &$title, &$output, $request ) {
148 -
 181+ function initializeSpecialCases ( &$title, &$output ) {
149182 wfProfileIn( 'MediaWiki::initializeSpecialCases' );
 183+ $request = $this->getVal( 'Request' );
150184
151185 $search = $this->getVal('Search');
152186 $action = $this->getVal('Action');
@@ -216,13 +250,12 @@
217251 * Initialize the object to be known as $wgArticle for "standard" actions
218252 * Create an Article object for the page, following redirects if needed.
219253 * @param Title $title
220 - * @param Request $request
221 - * @param string $action
222254 * @return mixed an Article, or a string to redirect to another URL
223255 */
224 - function initializeArticle( $title, $request ) {
 256+ function initializeArticle( $title ) {
225257 wfProfileIn( 'MediaWiki::initializeArticle' );
226258
 259+ $request = $this->getVal( 'Request' );
227260 $action = $this->getVal('Action');
228261 $article = $this->articleFromTitle( $title );
229262
@@ -288,10 +321,10 @@
289322 /**
290323 * Perform one of the "standard" actions
291324 */
292 - function performAction( &$output, &$article, &$title, &$user, &$request ) {
293 -
 325+ function performAction( &$output, &$article, &$title, &$user ) {
294326 wfProfileIn( 'MediaWiki::performAction' );
295 -
 327+
 328+ $request = $this->getVal( 'Request' );
296329 $action = $this->getVal('Action');
297330 if( in_array( $action, $this->getVal('DisabledActions',array()) ) ) {
298331 /* No such action; this will switch to the default case */

Status & tagging log