http://www.mediawiki.org/wiki/Special:Code/MediaWiki/72335

Revision: 72335
Author:   mah
Date:     2010-09-04 00:01:30 +0000 (Sat, 04 Sep 2010)

Log Message:
-----------
* 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

Modified Paths:
--------------
    trunk/phase3/maintenance/Maintenance.php
    trunk/phase3/maintenance/doMaintenance.php

Added Paths:
-----------
    trunk/phase3/maintenance/helloWorld.php

Modified: trunk/phase3/maintenance/Maintenance.php
===================================================================
--- trunk/phase3/maintenance/Maintenance.php    2010-09-03 23:17:51 UTC (rev 
72334)
+++ trunk/phase3/maintenance/Maintenance.php    2010-09-04 00:01:30 UTC (rev 
72335)
@@ -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 @@
                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 );
                }
 

Modified: trunk/phase3/maintenance/doMaintenance.php
===================================================================
--- trunk/phase3/maintenance/doMaintenance.php  2010-09-03 23:17:51 UTC (rev 
72334)
+++ trunk/phase3/maintenance/doMaintenance.php  2010-09-04 00:01:30 UTC (rev 
72335)
@@ -51,6 +51,7 @@
 $self = $maintenance->getName();
 
 # Setup the profiler
+global $IP;
 if ( file_exists( "$IP/StartProfiler.php" ) ) {
        require_once( "$IP/StartProfiler.php" );
 } else {

Added: trunk/phase3/maintenance/helloWorld.php
===================================================================
--- trunk/phase3/maintenance/helloWorld.php                             (rev 0)
+++ trunk/phase3/maintenance/helloWorld.php     2010-09-04 00:01:30 UTC (rev 
72335)
@@ -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 <m...@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" );
+


Property changes on: trunk/phase3/maintenance/helloWorld.php
___________________________________________________________________
Added: svn:eol-syle
   + native



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to