WARNING: HUGE COMMIT
[lhc/web/wiklou.git] / maintenance / eval.php
1 <?php
2 /**
3 * PHP lacks an interactive mode, but this can be very helpful when debugging.
4 * This script lets a command-line user start up the wiki engine and then poke
5 * about by issuing PHP commands directly.
6 *
7 * Unlike eg Python, you need to use a 'return' statement explicitly for the
8 * interactive shell to print out the value of the expression. Multiple lines
9 * are evaluated separately, so blocks need to be input without a line break.
10 * Fatal errors such as use of undeclared functions can kill the shell.
11 *
12 * To get decent line editing behavior, you should compile PHP with support
13 * for GNU readline (pass --with-readline to configure).
14 *
15 * @file
16 * @ingroup Maintenance
17 */
18
19 $wgUseNormalUser = (bool)getenv('MW_WIKIUSER');
20
21 $optionsWithArgs = array( 'd' );
22
23 /** */
24 require_once( "commandLine.inc" );
25
26 if ( isset( $options['d'] ) ) {
27 $d = $options['d'];
28 if ( $d > 0 ) {
29 $wgDebugLogFile = '/dev/stdout';
30 }
31 if ( $d > 1 ) {
32 $lb = wfGetLB();
33 foreach ( $lb->mServers as $i => $server ) {
34 $lb->mServers[$i]['flags'] |= DBO_DEBUG;
35 }
36 }
37 if ( $d > 2 ) {
38 $wgDebugFunctionEntry = true;
39 }
40 }
41
42
43 while ( ( $line = readconsole( '> ' ) ) !== false ) {
44 $val = eval( $line . ";" );
45 if( is_null( $val ) ) {
46 echo "\n";
47 } elseif( is_string( $val ) || is_numeric( $val ) ) {
48 echo "$val\n";
49 } else {
50 var_dump( $val );
51 }
52 if ( function_exists( "readline_add_history" ) ) {
53 readline_add_history( $line );
54 }
55 }
56
57 print "\n";
58
59