1545c3079e40c5ef76746735f3d5aa92f6c76e62
[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 * @addtogroup Maintenance
16 */
17
18 $wgUseNormalUser = (bool)getenv('MW_WIKIUSER');
19
20 $optionsWithArgs = array( 'd' );
21
22 /** */
23 require_once( "commandLine.inc" );
24
25 if ( isset( $options['d'] ) ) {
26 $d = $options['d'];
27 if ( $d > 0 ) {
28 $wgDebugLogFile = '/dev/stdout';
29 }
30 if ( $d > 1 ) {
31 $lb = wfGetLB();
32 foreach ( $lb->mServers as $i => $server ) {
33 $lb->mServers[$i]['flags'] |= DBO_DEBUG;
34 }
35 }
36 if ( $d > 2 ) {
37 $wgDebugFunctionEntry = true;
38 }
39 }
40
41
42 while ( ( $line = readconsole( '> ' ) ) !== false ) {
43 $val = eval( $line . ";" );
44 if( is_null( $val ) ) {
45 echo "\n";
46 } elseif( is_string( $val ) || is_numeric( $val ) ) {
47 echo "$val\n";
48 } else {
49 var_dump( $val );
50 }
51 if ( function_exists( "readline_add_history" ) ) {
52 readline_add_history( $line );
53 }
54 }
55
56 print "\n";
57
58