From: Sam Reed Date: Thu, 12 Jan 2012 23:10:22 +0000 (+0000) Subject: Maintenance class-ify eval.php X-Git-Tag: 1.31.0-rc.0~25315 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/?a=commitdiff_plain;h=a528b8ba92e6d949496f017f9f448dcfeb1b283d;p=lhc%2Fweb%2Fwiklou.git Maintenance class-ify eval.php --- diff --git a/maintenance/eval.php b/maintenance/eval.php index 3bd164fdaf..ac0fe55c9c 100644 --- a/maintenance/eval.php +++ b/maintenance/eval.php @@ -31,54 +31,69 @@ * @ingroup Maintenance */ -$optionsWithArgs = array( 'd' ); +require_once( dirname( __FILE__ ) . '/Maintenance.php' ); -/** */ -require_once( dirname( __FILE__ ) . "/commandLine.inc" ); - -if ( isset( $options['d'] ) ) { - $d = $options['d']; - if ( $d > 0 ) { - $wgDebugLogFile = '/dev/stdout'; +class MwEval extends Maintenance { + public function __construct() { + parent::__construct(); + $this->mDescription = "This script lets a command-line user start up the wiki engine and then poke about by issuing PHP commands directly."; + $this->addOption( 'd', 'Debug level' ); } - if ( $d > 1 ) { - $lb = wfGetLB(); - $serverCount = $lb->getServerCount(); - for ( $i = 0; $i < $serverCount; $i++ ) { - $server = $lb->getServerInfo( $i ); - $server['flags'] |= DBO_DEBUG; - $lb->setServerInfo( $i, $server ); + + public function execute() { + if ( $this->hasOption( 'd' ) ) { + $d = $this->getOption( 'd' ); + + if ( $d > 0 ) { + global $wgDebugLogFile; + $wgDebugLogFile = '/dev/stdout'; + } + if ( $d > 1 ) { + $lb = wfGetLB(); + $serverCount = $lb->getServerCount(); + for ( $i = 0; $i < $serverCount; $i++ ) { + $server = $lb->getServerInfo( $i ); + $server['flags'] |= DBO_DEBUG; + $lb->setServerInfo( $i, $server ); + } + } + if ( $d > 2 ) { + global $wgDebugFunctionEntry; + $wgDebugFunctionEntry = true; + } } - } - if ( $d > 2 ) { - $wgDebugFunctionEntry = true; - } -} -$useReadline = function_exists( 'readline_add_history' ) - && Maintenance::posix_isatty( 0 /*STDIN*/ ); + $useReadline = function_exists( 'readline_add_history' ) + && Maintenance::posix_isatty( 0 /*STDIN*/ ); -if ( $useReadline ) { - $historyFile = isset( $_ENV['HOME'] ) ? - "{$_ENV['HOME']}/.mweval_history" : "$IP/maintenance/.mweval_history"; - readline_read_history( $historyFile ); -} + if ( $useReadline ) { + global $IP; + $historyFile = isset( $_ENV['HOME'] ) ? + "{$_ENV['HOME']}/.mweval_history" : "$IP/maintenance/.mweval_history"; + readline_read_history( $historyFile ); + } -while ( ( $line = Maintenance::readconsole() ) !== false ) { - if ( $useReadline ) { - readline_add_history( $line ); - readline_write_history( $historyFile ); - } - $val = eval( $line . ";" ); - if ( wfIsHipHop() || is_null( $val ) ) { - echo "\n"; - } elseif ( is_string( $val ) || is_numeric( $val ) ) { - echo "$val\n"; - } else { - var_dump( $val ); + while ( ( $line = Maintenance::readconsole() ) !== false ) { + if ( $useReadline ) { + readline_add_history( $line ); + readline_write_history( $historyFile ); + } + $val = eval( $line . ";" ); + if ( wfIsHipHop() || is_null( $val ) ) { + $this->output( "\n" ); + echo "\n"; + } elseif ( is_string( $val ) || is_numeric( $val ) ) { + $this->output( "$val\n" ); + } else { + $var = ''; + var_export( $val, $var ); + $this->output( "$var" ); + } + } + + $this->output( "\n" ); } } -print "\n"; - - +$maintClass = "MwEval"; +require_once( RUN_MAINTENANCE_IF_MAIN );