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 @@ |
46 | 46 | abstract protected function execute();
|
47 | 47 |
|
48 | 48 | /**
|
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 | | - /**
|
82 | 49 | * Add a parameter to the script. Will be displayed on --help
|
83 | 50 | * with the associated description
|
84 | 51 | *
|
— | — | @@ -154,7 +121,9 @@ |
155 | 122 | /**
|
156 | 123 | * Do some sanity checking
|
157 | 124 | */
|
158 | | - private function sanityChecks() {
|
| 125 | + public function setup() {
|
| 126 | + global $IP, $wgCommandLineMode, $wgUseNormalUser, $wgRequestTime;
|
| 127 | +
|
159 | 128 | # Abort if called from a web server
|
160 | 129 | if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) {
|
161 | 130 | $this->error( "This script must be run from the command line\n", true );
|
— | — | @@ -190,14 +159,7 @@ |
191 | 160 |
|
192 | 161 | # Set the memory limit
|
193 | 162 | ini_set( 'memory_limit', -1 );
|
194 | | - }
|
195 | 163 |
|
196 | | - /**
|
197 | | - * Setup the maintenance envinronment
|
198 | | - */
|
199 | | - private function setupEnvironment() {
|
200 | | - global $IP, $wgCommandLineMode, $wgUseNormalUser, $wgRequestTime;
|
201 | | -
|
202 | 164 | $wgRequestTime = microtime(true);
|
203 | 165 |
|
204 | 166 | # Define us as being in Mediawiki
|
— | — | @@ -207,14 +169,7 @@ |
208 | 170 | $IP = strval( getenv('MW_INSTALL_PATH') ) !== ''
|
209 | 171 | ? getenv('MW_INSTALL_PATH')
|
210 | 172 | : 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 | +
|
219 | 174 | $wgCommandLineMode = true;
|
220 | 175 | # Turn off output buffering if it's on
|
221 | 176 | @ob_end_flush();
|
— | — | @@ -222,6 +177,9 @@ |
223 | 178 | if (!isset( $wgUseNormalUser ) ) {
|
224 | 179 | $wgUseNormalUser = false;
|
225 | 180 | }
|
| 181 | +
|
| 182 | + $this->loadArgs();
|
| 183 | + $this->maybeHelp();
|
226 | 184 | }
|
227 | 185 |
|
228 | 186 | /**
|
— | — | @@ -363,26 +321,17 @@ |
364 | 322 | }
|
365 | 323 |
|
366 | 324 | $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
|
371 | 325 | @set_time_limit(0);
|
372 | 326 |
|
373 | 327 | $wgProfiling = false; // only for Profiler.php mode; avoids OOM errors
|
374 | 328 | }
|
375 | 329 |
|
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;
|
378 | 335 |
|
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 | | -
|
387 | 336 | if ( empty( $wgNoDBParam ) ) {
|
388 | 337 | # Check if we were passed a db name
|
389 | 338 | if ( isset( $this->mOptions['wiki'] ) ) {
|
— | — | @@ -425,13 +374,13 @@ |
426 | 375 | if ( $lang == 'test' && $site == 'wikipedia' ) {
|
427 | 376 | define( 'TESTWIKI', 1 );
|
428 | 377 | }
|
429 | | -
|
430 | | - #require_once( $IP.'/includes/ProfilerStub.php' );
|
431 | | - require( $IP.'/includes/Defines.php' );
|
432 | | - require( $IP.'/CommonSettings.php' );
|
433 | 378 | }
|
434 | 379 |
|
435 | | - private function loadSettings() {
|
| 380 | + /**
|
| 381 | + * Generic setup for most installs. Returns the location of LocalSettings
|
| 382 | + * @return String
|
| 383 | + */
|
| 384 | + public function loadSettings() {
|
436 | 385 | global $wgWikiFarm, $wgCommandLineMode, $IP, $DP;
|
437 | 386 |
|
438 | 387 | $wgWikiFarm = false;
|
— | — | @@ -455,8 +404,7 @@ |
456 | 405 | }
|
457 | 406 | $wgCommandLineMode = true;
|
458 | 407 | $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;
|
462 | 410 | }
|
463 | 411 | } |
\ No newline at end of file |
Index: branches/maintenance-work/docs/maintenance.txt |
— | — | @@ -40,12 +40,11 @@ |
41 | 41 | }
|
42 | 42 |
|
43 | 43 | protected function execute() {
|
44 | | -
|
45 | 44 | }
|
46 | 45 | }
|
47 | 46 |
|
48 | | -$m = new DemoMaint();
|
49 | | -$m->go();
|
| 47 | +$maintClass = "DemoMaint";
|
| 48 | +require_once( "doMaintenance.php" );
|
50 | 49 |
|
51 | 50 | ==END==
|
52 | 51 |
|