Fix concern raised by Brion in r74108 (but has really existed since the maintenance...
[lhc/web/wiklou.git] / maintenance / commandLine.inc
index 216ee9c..f57c0b6 100644 (file)
@@ -1,39 +1,65 @@
 <?php
+/**
+ * Backwards-compatibility wrapper for old-style maintenance scripts.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Maintenance
+ */
 
-if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) {
-       print "This script must be run from the command line\n";
-       exit();
-}
+require( dirname( __FILE__ ) . '/Maintenance.php' );
 
-$wgCommandLineMode = true;
-
-$sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ? ";" : ":";
-if ( @$argv[1] ) {
-       $lang = $argv[1];
-       putenv( "wikilang=$lang");
-       $settingsFile = "/apache/htdocs/{$argv[1]}/w/LocalSettings.php";
-       $newpath = "/apache/common/php$sep";
-} else {
-       $settingsFile = "../LocalSettings.php";
-       $newpath = "";
+global $optionsWithArgs;
+if ( !isset( $optionsWithArgs ) ) {
+       $optionsWithArgs = array();
 }
 
-if ( ! is_readable( $settingsFile ) ) {
-       print "A copy of your installation's LocalSettings.php\n" .
-         "must exist in the source directory.\n";
-       exit();
-}
+class CommandLineInc extends Maintenance {
+       public function __construct() {
+               global $optionsWithArgs;
+               parent::__construct();
+               foreach ( $optionsWithArgs as $name ) {
+                       $this->addOption( $name, '', false, true );
+               }
+       }
+
+       public function getDbType() {
+               global $wgUseNormalUser;
 
+               return ( isset( $wgUseNormalUser ) && $wgUseNormalUser ) ?
+                       Maintenance::DB_STD : Maintenance::DB_ADMIN;
+       }
+
+       /**
+        * No help, it would just be misleading since it misses custom options
+        */
+       protected function maybeHelp( $force = false ) {
+               if ( !$force )
+                       return;
+               parent::maybeHelp( true );
+       }
+
+       public function execute() {
+               global $args, $options;
+               $args = $this->mArgs;
+               $options = $this->mOptions;
+       }
+}
 
-$wgCommandLineMode = true;
-$DP = "../includes";
-include_once( $settingsFile );
-ini_set( "include_path", "../includes$sep../languages$sep$newpath$IP$sep$include_path" );
+$maintClass = 'CommandLineInc';
+require( RUN_MAINTENANCE_IF_MAIN );
 
-include_once( "Setup.php" );
-include_once( "./InitialiseMessages.inc" );
-include_once( "../install-utils.inc" );
-$wgTitle = Title::newFromText( "Rebuild messages script" );
-$wgCommandLineMode = true;
-set_time_limit(0);
-?>