X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FMaintenance.php;h=98b7d471aa12497d2a97d7ddc7f20bff71aaabf8;hb=beb1c4a0eced04ce2098433c383f1fbe469569c9;hp=aab7bb3896e31fa60a9a99010b92f6c28e5a5ba3;hpb=cb22c53a79da34ff351b9b7332dcc437ab12cfc8;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index aab7bb3896..98b7d471aa 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -20,14 +20,10 @@ * @defgroup Maintenance Maintenance */ -if( PHP_SAPI != 'cli' ) { - die( "Run me from the command line please.\n" ); -} - // Make sure we're on PHP5.3.2 or better if ( !function_exists( 'version_compare' ) || version_compare( PHP_VERSION, '5.3.2' ) < 0 ) { // We need to use dirname( __FILE__ ) here cause __DIR__ is PHP5.3+ - require_once( dirname( __FILE__ ) . '/../includes/PHPVersionError.php' ); + require_once dirname( __FILE__ ) . '/../includes/PHPVersionError.php'; wfPHPVersionError( 'cli' ); } @@ -58,8 +54,8 @@ abstract class Maintenance { * Constants for DB access type * @see Maintenance::getDbType() */ - const DB_NONE = 0; - const DB_STD = 1; + const DB_NONE = 0; + const DB_STD = 1; const DB_ADMIN = 2; // Const for getStdin() @@ -157,7 +153,7 @@ abstract class Maintenance { return false; // last call should be to this function } $includeFuncs = array( 'require_once', 'require', 'include', 'include_once' ); - for( $i=1; $i < $count; $i++ ) { + for ( $i = 1; $i < $count; $i++ ) { if ( !in_array( $bt[$i]['function'], $includeFuncs ) ) { return false; // previous calls should all be "requires" } @@ -331,7 +327,7 @@ abstract class Maintenance { } if ( $channel === null ) { $this->cleanupChanneled(); - print( $out ); + print $out; } else { $out = preg_replace( '/\n\z/', '', $out ); $this->outputChanneled( $out, $channel ); @@ -432,7 +428,7 @@ abstract class Maintenance { "server name detection may fail in command line scripts.", false, true ); # Save generic options to display them separately in help - $this->mGenericParameters = $this->mParams ; + $this->mGenericParameters = $this->mParams; # Script dependant options: @@ -458,7 +454,7 @@ abstract class Maintenance { // Make sure the class is loaded first if ( !MWInit::classExists( $maintClass ) ) { if ( $classFile ) { - require_once( $classFile ); + require_once $classFile; } if ( !MWInit::classExists( $maintClass ) ) { $this->error( "Cannot spawn child: $maintClass" ); @@ -517,8 +513,11 @@ abstract class Maintenance { define( 'MEDIAWIKI', true ); $wgCommandLineMode = true; + # Turn off output buffering if it's on - @ob_end_flush(); + while ( ob_get_level() > 0 ) { + ob_end_flush(); + } $this->validateParamsAndArgs(); } @@ -635,7 +634,7 @@ abstract class Maintenance { } elseif ( substr( $arg, 0, 1 ) == '-' ) { # Short options for ( $p = 1; $p < strlen( $arg ); $p++ ) { - $option = $arg { $p } ; + $option = $arg { $p }; if ( !isset( $this->mParams[$option] ) && isset( $this->mShortParamsMap[$option] ) ) { $option = $this->mShortParamsMap[$option]; } @@ -713,7 +712,7 @@ abstract class Maintenance { * @param $force boolean Whether to force the help to show, default false */ protected function maybeHelp( $force = false ) { - if( !$force && !$this->hasOption( 'help' ) ) { + if ( !$force && !$this->hasOption( 'help' ) ) { return; } @@ -744,8 +743,9 @@ abstract class Maintenance { } else { $output .= '[' . $arg['name'] . ']'; } - if ( $k < count( $this->mArgList ) - 1 ) + if ( $k < count( $this->mArgList ) - 1 ) { $output .= ' '; + } } } $this->output( "$output\n\n" ); @@ -766,7 +766,7 @@ abstract class Maintenance { $this->output( "\n" ); $scriptDependantParams = $this->mDependantParameters; - if( count($scriptDependantParams) > 0 ) { + if ( count( $scriptDependantParams ) > 0 ) { $this->output( "Script dependant parameters:\n" ); // Parameters description foreach ( $scriptDependantParams as $par => $info ) { @@ -791,7 +791,7 @@ abstract class Maintenance { $this->mGenericParameters, $this->mDependantParameters ); - if( count($scriptSpecificParams) > 0 ) { + if ( count( $scriptSpecificParams ) > 0 ) { $this->output( "Script specific parameters:\n" ); // Parameters description foreach ( $scriptSpecificParams as $par => $info ) { @@ -807,7 +807,7 @@ abstract class Maintenance { } // Print arguments - if( count( $this->mArgList ) > 0 ) { + if ( count( $this->mArgList ) > 0 ) { $this->output( "Arguments:\n" ); // Arguments description foreach ( $this->mArgList as $info ) { @@ -840,7 +840,7 @@ abstract class Maintenance { $wgCommandLineMode = true; # Override $wgServer - if( $this->hasOption( 'server') ) { + if ( $this->hasOption( 'server' ) ) { $wgServer = $this->getOption( 'server', $wgServer ); } @@ -907,7 +907,7 @@ abstract class Maintenance { if ( isset( $this->mOptions['conf'] ) ) { $settingsFile = $this->mOptions['conf']; - } elseif ( defined("MW_CONFIG_FILE") ) { + } elseif ( defined( "MW_CONFIG_FILE" ) ) { $settingsFile = MW_CONFIG_FILE; } else { $settingsFile = "$IP/LocalSettings.php"; @@ -1026,7 +1026,7 @@ abstract class Maintenance { ( strpos( file_get_contents( $file ), '$maintClass' ) === false ) ) { continue; } - require( $file ); + require $file; $vars = get_defined_vars(); if ( array_key_exists( 'maintClass', $vars ) ) { self::$mCoreScripts[$vars['maintClass']] = $file; @@ -1077,7 +1077,7 @@ abstract class Maintenance { * @param &$db DatabaseBase object */ private function unlockSearchindex( &$db ) { - $db->unlockTables( __CLASS__ . '::' . __METHOD__ ); + $db->unlockTables( __CLASS__ . '::' . __METHOD__ ); } /** @@ -1191,7 +1191,9 @@ abstract class Maintenance { $st = fgets( STDIN, 1024 ); } } - if ( $st === false ) return false; + if ( $st === false ) { + return false; + } $resp = trim( $st ); return $resp; }