* add wfRunMaintenance() script to simplify maint script writing
authorMark A. Hershberger <mah@users.mediawiki.org>
Sat, 4 Sep 2010 00:01:30 +0000 (00:01 +0000)
committerMark A. Hershberger <mah@users.mediawiki.org>
Sat, 4 Sep 2010 00:01:30 +0000 (00:01 +0000)
* replace use of array_key_exists with isset()
* add helloWorld example to go with http://www.mediawiki.org/wiki/Manual:Writing_maintenance_scripts

maintenance/Maintenance.php
maintenance/doMaintenance.php
maintenance/helloWorld.php [new file with mode: 0644]

index a649e42..8e6b5e3 100644 (file)
@@ -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 );
                }
 
index f10480f..7547a49 100644 (file)
@@ -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 (file)
index 0000000..c50c454
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+
+/**
+ * To the extent possible under law,  I, Mark Hershberger, have waived all copyright and
+ * related or neighboring rights to Hello World. This work is published from United States.
+ * @copyright CC0 http://creativecommons.org/publicdomain/zero/1.0/
+ * @author Mark A. Hershberger <mah@everybody.org>
+ * @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" );
+