define( 'DO_MAINTENANCE', dirname( __FILE__ ) . '/doMaintenance.php' );
$maintClass = false;
+function wfRunMaintenance( $class ) {
+ $maintClass = $class;
+ require_once( DO_MAINTENANCE );
+}
+
// Make sure we're on PHP5 or better
-if ( version_compare( PHP_VERSION, '5.0.0' ) < 0 ) {
- echo( "Sorry! This version of MediaWiki requires PHP 5; you are running " .
+if ( version_compare( PHP_VERSION, '5.1.0' ) < 0 ) {
+ die ( "Sorry! This version of MediaWiki requires PHP 5.1.x; you are running " .
PHP_VERSION . ".\n\n" .
- "If you are sure you already have PHP 5 installed, it may be installed\n" .
- "in a different path from PHP 4. Check with your system administrator.\n" );
- die();
+ "If you are sure you already have PHP 5.1.x or higher installed, it may be\n" .
+ "installed in a different path from PHP " . PHP_VERSION . ". Check with your system\n" .
+ "administrator.\n" );
}
/**
);
}
+ /**
+ * Remove an option. Useful for removing options that won't be used in your script.
+ * @param $name String: the option to remove.
+ */
+ protected function deleteOption( $name ) {
+ unset( $this->mParams[$name] );
+ }
+
+ /**
+ * Set the description text.
+ * @param $text String: the text of the description
+ */
+ protected function addDescription( $text ) {
+ $this->mDescription = $text;
+ }
+
/**
* Does a given argument exist?
* @param $argId Integer: the integer value (from zero) for the arg
/**
* Return input from stdin.
- * @param $length Integer: the number of bytes to read. If null,
+ * @param $len Integer: the number of bytes to read. If null,
* just return the handle. Maintenance::STDIN_ALL returns
* the full length
* @return Mixed
* Throw some output to the user. Scripts can call this with no fears,
* as we handle all --quiet stuff here
* @param $out String: the text to show to the user
- * @param $channel Mixed: unique identifier for the channel. See function outputChanneled.
+ * @param $channel Mixed: unique identifier for the channel. See
+ * function outputChanneled.
*/
protected function output( $out, $channel = null ) {
if ( $this->mQuiet ) {
return;
}
if ( $channel === null ) {
+ $this->cleanupChanneled();
+
$f = fopen( 'php://stdout', 'w' );
fwrite( $f, $out );
fclose( $f );
private $atLineStart = true;
private $lastChannel = null;
-
+
+ /**
+ * Clean up channeled output. Output a newline if necessary.
+ */
+ public function cleanupChanneled() {
+ if ( !$this->atLineStart ) {
+ $handle = fopen( 'php://stdout', 'w' );
+ fwrite( $handle, "\n" );
+ fclose( $handle );
+ $this->atLineStart = true;
+ }
+ }
+
/**
* Message outputter with channeled message support. Messages on the
* same channel are concatenated, but any intervening messages in another
* channel start a new line.
* @param $msg String: the message without trailing newline
- * @param $channel Channel identifier or null for no channel. Channel comparison uses ===.
+ * @param $channel Channel identifier or null for no
+ * channel. Channel comparison uses ===.
*/
public function outputChanneled( $msg, $channel = null ) {
- $handle = fopen( 'php://stdout', 'w' );
-
if ( $msg === false ) {
- // For cleanup
- if ( !$this->atLineStart ) {
- fwrite( $handle, "\n" );
- }
- fclose( $handle );
+ $this->cleanupChanneled();
return;
}
+ $handle = fopen( 'php://stdout', 'w' );
+
// End the current line if necessary
if ( !$this->atLineStart && $channel !== $this->lastChannel ) {
fwrite( $handle, "\n" );
global $IP, $wgCommandLineMode, $wgRequestTime;
# Abort if called from a web server
- if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) {
+ if ( isset( $_SERVER ) && isset( $_SERVER['REQUEST_METHOD'] ) ) {
$this->error( 'This script must be run from the command line', true );
}
$die = true;
}
}
-
+
if ( $die ) {
$this->maybeHelp( true );
}
$screenWidth = 80; // TODO: Caculate this!
$tab = " ";
$descWidth = $screenWidth - ( 2 * strlen( $tab ) );
-
+
ksort( $this->mParams );
if ( $this->hasOption( 'help' ) || $force ) {
$this->mQuiet = false;
*/
public function finalSetup() {
global $wgCommandLineMode, $wgShowSQLErrors;
- global $wgProfiling, $IP, $wgDBadminuser, $wgDBadminpassword;
+ global $wgProfiling, $wgDBadminuser, $wgDBadminpassword;
global $wgDBuser, $wgDBpassword, $wgDBservers, $wgLBFactoryConf;
# Turn off output buffering again, it might have been turned on in the settings files
$wgLBFactoryConf['serverTemplate']['user'] = $wgDBuser;
$wgLBFactoryConf['serverTemplate']['password'] = $wgDBpassword;
}
+ LBFactory::destroyInstance();
}
- if ( defined( 'MW_CMDLINE_CALLBACK' ) ) {
- $fn = MW_CMDLINE_CALLBACK;
- $fn();
- }
+ $this->afterFinalSetup();
$wgShowSQLErrors = true;
@set_time_limit( 0 );
$wgProfiling = false; // only for Profiler.php mode; avoids OOM errors
}
+ /**
+ * Execute a callback function at the end of initialisation
+ */
+ protected function afterFinalSetup() {
+ if ( defined( 'MW_CMDLINE_CALLBACK' ) ) {
+ call_user_func( MW_CMDLINE_CALLBACK );
+ }
+ }
+
/**
* Potentially debug globals. Originally a feature only
* for refreshLinks
putenv( 'wikilang=' . $lang );
- $DP = $IP;
ini_set( 'include_path', ".:$IP:$IP/includes:$IP/languages:$IP/maintenance" );
if ( $lang == 'test' && $site == 'wikipedia' ) {
* @return String
*/
public function loadSettings() {
- global $wgWikiFarm, $wgCommandLineMode, $IP, $DP;
+ global $wgWikiFarm, $wgCommandLineMode, $IP;
$wgWikiFarm = false;
if ( isset( $this->mOptions['conf'] ) ) {
if ( !is_readable( $settingsFile ) ) {
$this->error( "A copy of your installation's LocalSettings.php\n" .
- "must exist and be readable in the source directory.", true );
+ "must exist and be readable in the source directory.", true );
}
$wgCommandLineMode = true;
- $DP = $IP;
return $settingsFile;
}
* @param $delete Boolean: whether or not to actually delete the records
* @author Rob Church <robchur@gmail.com>
*/
- protected function purgeRedundantText( $delete = true ) {
+ public function purgeRedundantText( $delete = true ) {
# Data should come off the master, wrapped in a transaction
$dbw = wfGetDB( DB_MASTER );
$dbw->begin();