Index: trunk/phase3/maintenance/eval.php |
— | — | @@ -31,69 +31,54 @@ |
32 | 32 | * @ingroup Maintenance |
33 | 33 | */ |
34 | 34 | |
35 | | -require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
| 35 | +$optionsWithArgs = array( 'd' ); |
36 | 36 | |
37 | | -class MwEval extends Maintenance { |
38 | | - public function __construct() { |
39 | | - parent::__construct(); |
40 | | - $this->mDescription = "This script lets a command-line user start up the wiki engine and then poke about by issuing PHP commands directly."; |
41 | | - $this->addOption( 'd', 'Debug level' ); |
42 | | - } |
| 37 | +/** */ |
| 38 | +require_once( dirname( __FILE__ ) . "/commandLine.inc" ); |
43 | 39 | |
44 | | - public function execute() { |
45 | | - if ( $this->hasOption( 'd' ) ) { |
46 | | - $d = $this->getOption( 'd' ); |
47 | | - |
48 | | - if ( $d > 0 ) { |
49 | | - global $wgDebugLogFile; |
50 | | - $wgDebugLogFile = '/dev/stdout'; |
51 | | - } |
52 | | - if ( $d > 1 ) { |
53 | | - $lb = wfGetLB(); |
54 | | - $serverCount = $lb->getServerCount(); |
55 | | - for ( $i = 0; $i < $serverCount; $i++ ) { |
56 | | - $server = $lb->getServerInfo( $i ); |
57 | | - $server['flags'] |= DBO_DEBUG; |
58 | | - $lb->setServerInfo( $i, $server ); |
59 | | - } |
60 | | - } |
61 | | - if ( $d > 2 ) { |
62 | | - global $wgDebugFunctionEntry; |
63 | | - $wgDebugFunctionEntry = true; |
64 | | - } |
| 40 | +if ( isset( $options['d'] ) ) { |
| 41 | + $d = $options['d']; |
| 42 | + if ( $d > 0 ) { |
| 43 | + $wgDebugLogFile = '/dev/stdout'; |
| 44 | + } |
| 45 | + if ( $d > 1 ) { |
| 46 | + $lb = wfGetLB(); |
| 47 | + $serverCount = $lb->getServerCount(); |
| 48 | + for ( $i = 0; $i < $serverCount; $i++ ) { |
| 49 | + $server = $lb->getServerInfo( $i ); |
| 50 | + $server['flags'] |= DBO_DEBUG; |
| 51 | + $lb->setServerInfo( $i, $server ); |
65 | 52 | } |
| 53 | + } |
| 54 | + if ( $d > 2 ) { |
| 55 | + $wgDebugFunctionEntry = true; |
| 56 | + } |
| 57 | +} |
66 | 58 | |
67 | | - $useReadline = function_exists( 'readline_add_history' ) |
68 | | - && Maintenance::posix_isatty( 0 /*STDIN*/ ); |
| 59 | +$useReadline = function_exists( 'readline_add_history' ) |
| 60 | + && Maintenance::posix_isatty( 0 /*STDIN*/ ); |
69 | 61 | |
70 | | - if ( $useReadline ) { |
71 | | - global $IP; |
72 | | - $historyFile = isset( $_ENV['HOME'] ) ? |
73 | | - "{$_ENV['HOME']}/.mweval_history" : "$IP/maintenance/.mweval_history"; |
74 | | - readline_read_history( $historyFile ); |
75 | | - } |
| 62 | +if ( $useReadline ) { |
| 63 | + $historyFile = isset( $_ENV['HOME'] ) ? |
| 64 | + "{$_ENV['HOME']}/.mweval_history" : "$IP/maintenance/.mweval_history"; |
| 65 | + readline_read_history( $historyFile ); |
| 66 | +} |
76 | 67 | |
77 | | - while ( ( $line = Maintenance::readconsole() ) !== false ) { |
78 | | - if ( $useReadline ) { |
79 | | - readline_add_history( $line ); |
80 | | - readline_write_history( $historyFile ); |
81 | | - } |
82 | | - $val = eval( $line . ";" ); |
83 | | - if ( wfIsHipHop() || is_null( $val ) ) { |
84 | | - $this->output( "\n" ); |
85 | | - echo "\n"; |
86 | | - } elseif ( is_string( $val ) || is_numeric( $val ) ) { |
87 | | - $this->output( "$val\n" ); |
88 | | - } else { |
89 | | - $var = ''; |
90 | | - var_export( $val, $var ); |
91 | | - $this->output( "$var" ); |
92 | | - } |
93 | | - } |
94 | | - |
95 | | - $this->output( "\n" ); |
| 68 | +while ( ( $line = Maintenance::readconsole() ) !== false ) { |
| 69 | + if ( $useReadline ) { |
| 70 | + readline_add_history( $line ); |
| 71 | + readline_write_history( $historyFile ); |
96 | 72 | } |
| 73 | + $val = eval( $line . ";" ); |
| 74 | + if ( wfIsHipHop() || is_null( $val ) ) { |
| 75 | + echo "\n"; |
| 76 | + } elseif ( is_string( $val ) || is_numeric( $val ) ) { |
| 77 | + echo "$val\n"; |
| 78 | + } else { |
| 79 | + var_dump( $val ); |
| 80 | + } |
97 | 81 | } |
98 | 82 | |
99 | | -$maintClass = "MwEval"; |
100 | | -require_once( RUN_MAINTENANCE_IF_MAIN ); |
| 83 | +print "\n"; |
| 84 | + |
| 85 | + |