r51722 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51721‎ | r51722 | r51723 >
Date:00:58, 11 June 2009
Author:demon
Status:deferred
Tags:
Comment:
I long for the day MediaWiki uses no globals. *sigh*
Modified paths:
  • /branches/maintenance-work/docs/maintenance.txt (modified) (history)
  • /branches/maintenance-work/maintenance/Maintenance.php (modified) (history)
  • /branches/maintenance-work/maintenance/doMaintenance.php (added) (history)

Diff [purge]

Index: branches/maintenance-work/maintenance/doMaintenance.php
@@ -0,0 +1,47 @@
 2+<?php
 3+/**
 4+ * We want to make this whole thing as seamless as possible to the
 5+ * end-user. Unfortunately, we can't do _all_ of the work in the class
 6+ * because A) included files are not in global scope, but in the scope
 7+ * of their caller, and B) MediaWiki has way too many globals. So instead
 8+ * we'll kinda fake it, and do the requires() inline. <3 PHP
 9+ */
 10+
 11+// Get an object to start us off
 12+$maintenance = new $maintClass();
 13+
 14+// Basic sanity checks and such
 15+$maintenance->setup();
 16+
 17+# Setup the profiler
 18+if ( file_exists( "$IP/StartProfiler.php" ) ) {
 19+ require_once( "$IP/StartProfiler.php" );
 20+} else {
 21+ require_once( "$IP/includes/ProfilerStub.php" );
 22+}
 23+
 24+// Load settings, using wikimedia-mode if needed
 25+if( file_exists( dirname(__FILE__).'/wikimedia-mode' ) ) {
 26+ # TODO FIXME! Wikimedia-specific stuff needs to go away to an ext
 27+ # Maybe a hook?
 28+ global $cluster;
 29+ $wgWikiFarm = true;
 30+ $cluster = 'pmtma';
 31+ require_once( "$IP/includes/AutoLoader.php" );
 32+ require_once( "$IP/includes/SiteConfiguration.php" );
 33+ require( "$IP/wgConf.php" );
 34+ $maintenance->loadWikimediaSettings();
 35+ require( $IP.'/includes/Defines.php' );
 36+ require( $IP.'/CommonSettings.php' );
 37+} else {
 38+ require_once( "$IP/includes/AutoLoader.php" );
 39+ require_once( "$IP/includes/Defines.php" );
 40+ require_once( $maintenance->loadSettings() );
 41+}
 42+// Some last includes
 43+require_once( "$IP/includes/Setup.php" );
 44+require_once( "$IP/install-utils.inc" );
 45+
 46+$wgTitle = null; # Much much faster startup than creating a title object
 47+
 48+$maintenance->execute();
Index: branches/maintenance-work/maintenance/Maintenance.php
@@ -45,39 +45,6 @@
4646 abstract protected function execute();
4747
4848 /**
49 - * Our public interface for doing everything. We'll run some sanity
50 - * checks and then call the script's execute() method.
51 - */
52 - public function go() {
53 - // Basic stuff to make sure we can go
54 - $this->sanityChecks();
55 -
56 - // Begin setting up the environment for script execution
57 - $this->setupEnvironment();
58 -
59 - // Get all of the arguments
60 - $this->loadArgs();
61 -
62 - // Show the help and die if we can
63 - $this->maybeHelp();
64 -
65 - // Load settings, using wikimedia-mode if needed
66 - if( file_exists( dirname(__FILE__).'/wikimedia-mode' ) ) {
67 - # TODO FIXME! Wikimedia-specific stuff needs to go away to an ext
68 - # Maybe a hook?
69 - $this->loadWikimediaSettings();
70 - } else {
71 - $this->loadSettings();
72 - }
73 -
74 - // Final setup
75 - $this->finalSetup();
76 -
77 - // Execute the actual script
78 - $this->execute();
79 - }
80 -
81 - /**
8249 * Add a parameter to the script. Will be displayed on --help
8350 * with the associated description
8451 *
@@ -154,7 +121,9 @@
155122 /**
156123 * Do some sanity checking
157124 */
158 - private function sanityChecks() {
 125+ public function setup() {
 126+ global $IP, $wgCommandLineMode, $wgUseNormalUser, $wgRequestTime;
 127+
159128 # Abort if called from a web server
160129 if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) {
161130 $this->error( "This script must be run from the command line\n", true );
@@ -190,14 +159,7 @@
191160
192161 # Set the memory limit
193162 ini_set( 'memory_limit', -1 );
194 - }
195163
196 - /**
197 - * Setup the maintenance envinronment
198 - */
199 - private function setupEnvironment() {
200 - global $IP, $wgCommandLineMode, $wgUseNormalUser, $wgRequestTime;
201 -
202164 $wgRequestTime = microtime(true);
203165
204166 # Define us as being in Mediawiki
@@ -207,14 +169,7 @@
208170 $IP = strval( getenv('MW_INSTALL_PATH') ) !== ''
209171 ? getenv('MW_INSTALL_PATH')
210172 : realpath( dirname( __FILE__ ) . '/..' );
211 -
212 - # Setup the profiler
213 - if ( file_exists( "$IP/StartProfiler.php" ) ) {
214 - require_once( "$IP/StartProfiler.php" );
215 - } else {
216 - require_once( "$IP/includes/ProfilerStub.php" );
217 - }
218 -
 173+
219174 $wgCommandLineMode = true;
220175 # Turn off output buffering if it's on
221176 @ob_end_flush();
@@ -222,6 +177,9 @@
223178 if (!isset( $wgUseNormalUser ) ) {
224179 $wgUseNormalUser = false;
225180 }
 181+
 182+ $this->loadArgs();
 183+ $this->maybeHelp();
226184 }
227185
228186 /**
@@ -363,26 +321,17 @@
364322 }
365323
366324 $wgShowSQLErrors = true;
367 -
368 - require_once( "$IP/includes/Setup.php" );
369 - require_once( "$IP/install-utils.inc" );
370 - $wgTitle = null; # Much much faster startup than creating a title object
371325 @set_time_limit(0);
372326
373327 $wgProfiling = false; // only for Profiler.php mode; avoids OOM errors
374328 }
375329
376 - private function loadWikimediaSettings() {
377 - global $wgWikiFarm, $cluster, $IP, $wgNoDBParam, $wgUseNormalUser;
 330+ /**
 331+ * Do setup specific to WMF
 332+ */
 333+ public function loadWikimediaSettings() {
 334+ global $IP, $wgNoDBParam, $wgUseNormalUser, $wgConf;
378335
379 - $wgWikiFarm = true;
380 - $cluster = 'pmtpa';
381 - require_once( "$IP/includes/AutoLoader.php" );
382 - require_once( "$IP/includes/SiteConfiguration.php" );
383 -
384 - # Get $wgConf
385 - require( "$IP/wgConf.php" );
386 -
387336 if ( empty( $wgNoDBParam ) ) {
388337 # Check if we were passed a db name
389338 if ( isset( $this->mOptions['wiki'] ) ) {
@@ -425,13 +374,13 @@
426375 if ( $lang == 'test' && $site == 'wikipedia' ) {
427376 define( 'TESTWIKI', 1 );
428377 }
429 -
430 - #require_once( $IP.'/includes/ProfilerStub.php' );
431 - require( $IP.'/includes/Defines.php' );
432 - require( $IP.'/CommonSettings.php' );
433378 }
434379
435 - private function loadSettings() {
 380+ /**
 381+ * Generic setup for most installs. Returns the location of LocalSettings
 382+ * @return String
 383+ */
 384+ public function loadSettings() {
436385 global $wgWikiFarm, $wgCommandLineMode, $IP, $DP;
437386
438387 $wgWikiFarm = false;
@@ -455,8 +404,7 @@
456405 }
457406 $wgCommandLineMode = true;
458407 $DP = $IP;
459 - require_once( "$IP/includes/AutoLoader.php" );
460 - require_once( "$IP/includes/Defines.php" );
461 - require_once( $settingsFile );
 408+ $this->finalSetup();
 409+ return $settingsFile;
462410 }
463411 }
\ No newline at end of file
Index: branches/maintenance-work/docs/maintenance.txt
@@ -40,12 +40,11 @@
4141 }
4242
4343 protected function execute() {
44 -
4544 }
4645 }
4746
48 -$m = new DemoMaint();
49 -$m->go();
 47+$maintClass = "DemoMaint";
 48+require_once( "doMaintenance.php" );
5049
5150 ==END==
5251

Status & tagging log