Index: trunk/phase3/maintenance/eval.php |
— | — | @@ -12,85 +12,61 @@ |
13 | 13 | * To get decent line editing behavior, you should compile PHP with support |
14 | 14 | * for GNU readline (pass --with-readline to configure). |
15 | 15 | * |
16 | | - * This program is free software; you can redistribute it and/or modify |
17 | | - * it under the terms of the GNU General Public License as published by |
18 | | - * the Free Software Foundation; either version 2 of the License, or |
19 | | - * (at your option) any later version. |
20 | | - * |
21 | | - * This program is distributed in the hope that it will be useful, |
22 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
23 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24 | | - * GNU General Public License for more details. |
25 | | - * |
26 | | - * You should have received a copy of the GNU General Public License along |
27 | | - * with this program; if not, write to the Free Software Foundation, Inc., |
28 | | - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
29 | | - * http://www.gnu.org/copyleft/gpl.html |
30 | | - * |
| 16 | + * @file |
31 | 17 | * @ingroup Maintenance |
32 | 18 | */ |
33 | 19 | |
34 | | -require_once( dirname(__FILE__) . '/Maintenance.php' ); |
| 20 | +$wgUseNormalUser = (bool)getenv('MW_WIKIUSER'); |
35 | 21 | |
36 | | -class EvalPrompt extends Maintenance { |
| 22 | +$optionsWithArgs = array( 'd' ); |
37 | 23 | |
38 | | - public function __construct() { |
39 | | - global $wgUseNormalUser; |
40 | | - parent::__construct(); |
41 | | - $this->mDescription = "This script lets a command-line user start up the wiki engine and then poke\n" . |
42 | | - "about by issuing PHP commands directly."; |
43 | | - $this->addOption( 'd', "Enable MediaWiki debug output", false, true ); |
44 | | - $wgUseNormalUser = (bool)getenv('MW_WIKIUSER'); |
| 24 | +/** */ |
| 25 | +require_once( "commandLine.inc" ); |
| 26 | + |
| 27 | +if ( isset( $options['d'] ) ) { |
| 28 | + $d = $options['d']; |
| 29 | + if ( $d > 0 ) { |
| 30 | + $wgDebugLogFile = '/dev/stdout'; |
45 | 31 | } |
46 | | - |
47 | | - public function execute() { |
48 | | - global $wgDebugFunctionEntry, $wgDebugLogFile; |
49 | | - if ( $this->hasOption('d') ) { |
50 | | - $d = $this->getOption('d'); |
51 | | - if ( $d > 0 ) { |
52 | | - $wgDebugLogFile = '/dev/stdout'; |
53 | | - } |
54 | | - if ( $d > 1 ) { |
55 | | - $lb = wfGetLB(); |
56 | | - foreach ( $lb->mServers as $i => $server ) { |
57 | | - $lb->mServers[$i]['flags'] |= DBO_DEBUG; |
58 | | - } |
59 | | - } |
60 | | - if ( $d > 2 ) { |
61 | | - $wgDebugFunctionEntry = true; |
62 | | - } |
| 32 | + if ( $d > 1 ) { |
| 33 | + $lb = wfGetLB(); |
| 34 | + foreach ( $lb->mServers as $i => $server ) { |
| 35 | + $lb->mServers[$i]['flags'] |= DBO_DEBUG; |
63 | 36 | } |
64 | | - |
65 | | - if ( function_exists( 'readline_add_history' ) |
66 | | - && function_exists( 'posix_isatty' ) && posix_isatty( 0 /*STDIN*/ ) ) |
67 | | - { |
68 | | - $useReadline = true; |
69 | | - } else { |
70 | | - $useReadline = false; |
71 | | - } |
72 | | - |
73 | | - if ( $useReadline ) { |
74 | | - $historyFile = "{$_ENV['HOME']}/.mweval_history"; |
75 | | - readline_read_history( $historyFile ); |
76 | | - } |
77 | | - |
78 | | - while ( ( $line = readconsole( '> ' ) ) !== false ) { |
79 | | - if ( $useReadline ) { |
80 | | - readline_add_history( $line ); |
81 | | - readline_write_history( $historyFile ); |
82 | | - } |
83 | | - $val = eval( $line . ";" ); |
84 | | - if( is_null( $val ) ) { |
85 | | - echo "\n"; |
86 | | - } elseif( is_string( $val ) || is_numeric( $val ) ) { |
87 | | - echo "$val\n"; |
88 | | - } else { |
89 | | - var_dump( $val ); |
90 | | - } |
91 | | - } |
92 | | - print "\n"; |
93 | 37 | } |
| 38 | + if ( $d > 2 ) { |
| 39 | + $wgDebugFunctionEntry = true; |
| 40 | + } |
94 | 41 | } |
95 | 42 | |
96 | | -$maintClass = "EvalPrompt"; |
97 | | -require_once( DO_MAINTENANCE ); |
| 43 | +if ( function_exists( 'readline_add_history' ) |
| 44 | + && function_exists( 'posix_isatty' ) && posix_isatty( 0 /*STDIN*/ ) ) |
| 45 | +{ |
| 46 | + $useReadline = true; |
| 47 | +} else { |
| 48 | + $useReadline = false; |
| 49 | +} |
| 50 | + |
| 51 | +if ( $useReadline ) { |
| 52 | + $historyFile = "{$_ENV['HOME']}/.mweval_history"; |
| 53 | + readline_read_history( $historyFile ); |
| 54 | +} |
| 55 | + |
| 56 | +while ( ( $line = readconsole( '> ' ) ) !== false ) { |
| 57 | + if ( $useReadline ) { |
| 58 | + readline_add_history( $line ); |
| 59 | + readline_write_history( $historyFile ); |
| 60 | + } |
| 61 | + $val = eval( $line . ";" ); |
| 62 | + if( is_null( $val ) ) { |
| 63 | + echo "\n"; |
| 64 | + } elseif( is_string( $val ) || is_numeric( $val ) ) { |
| 65 | + echo "$val\n"; |
| 66 | + } else { |
| 67 | + var_dump( $val ); |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +print "\n"; |
| 72 | + |
| 73 | + |