From: Mark A. Hershberger Date: Sat, 4 Sep 2010 00:01:30 +0000 (+0000) Subject: * add wfRunMaintenance() script to simplify maint script writing X-Git-Tag: 1.31.0-rc.0~35184 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=154081e4a26ce15bb107da0b170f9e05105f4509;p=lhc%2Fweb%2Fwiklou.git * add wfRunMaintenance() script to simplify maint script writing * replace use of array_key_exists with isset() * add helloWorld example to go with http://www.mediawiki.org/wiki/Manual:Writing_maintenance_scripts --- diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index a649e42e33..8e6b5e3d52 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -9,6 +9,11 @@ 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 ) { die ( "Sorry! This version of MediaWiki requires PHP 5; you are running " . @@ -400,7 +405,7 @@ abstract class Maintenance { 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 ); } diff --git a/maintenance/doMaintenance.php b/maintenance/doMaintenance.php index f10480f591..7547a498f4 100644 --- a/maintenance/doMaintenance.php +++ b/maintenance/doMaintenance.php @@ -51,6 +51,7 @@ $maintenance->setup(); $self = $maintenance->getName(); # Setup the profiler +global $IP; if ( file_exists( "$IP/StartProfiler.php" ) ) { require_once( "$IP/StartProfiler.php" ); } else { diff --git a/maintenance/helloWorld.php b/maintenance/helloWorld.php new file mode 100644 index 0000000000..c50c454b93 --- /dev/null +++ b/maintenance/helloWorld.php @@ -0,0 +1,28 @@ + + * @ingroup Maintenance + */ + +require_once( dirname( __FILE__ ) . "/Maintenance.php" ); + +class CommandLineInstaller extends Maintenance { + + public function __construct() { + parent::__construct(); + + $this->addOption( 'name', 'Who to say Hello to', false, true); + } + + public function execute() { + $name = $this->getOption( 'name', 'World' ); + echo "Hello, $name!\n"; + } +} + +wfRunMaintenance( "CommandLineInstaller" ); +