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.
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.
12 * To get decent line editing behavior, you should compile PHP with support
13 * for GNU readline (pass --with-readline to configure).
16 * @ingroup Maintenance
19 require_once( "Maintenance.php" );
21 class EvalPrompt
extends Maintenance
{
23 public function __construct() {
24 parent
::__construct();
25 $this->mDescription
= "This script lets a command-line user start up the wiki engine and then poke\n" .
26 "about by issuing PHP commands directly.";
27 $this->addParam( 'd', "Enable MediaWiki debug output", false, true );
30 public function execute() {
31 global $wgUseNormalUser;
32 $wgUseNormalUser = (bool)getenv('MW_WIKIUSER');
33 if ( $this->hasOption('d') ) {
34 $d = $this->getOption('d');
36 $wgDebugLogFile = '/dev/stdout';
40 foreach ( $lb->mServers
as $i => $server ) {
41 $lb->mServers
[$i]['flags'] |
= DBO_DEBUG
;
45 $wgDebugFunctionEntry = true;
49 if ( function_exists( 'readline_add_history' )
50 && function_exists( 'posix_isatty' ) && posix_isatty( 0 /*STDIN*/ ) )
58 $historyFile = "{$_ENV['HOME']}/.mweval_history";
59 readline_read_history( $historyFile );
62 while ( ( $line = readconsole( '> ' ) ) !== false ) {
64 readline_add_history( $line );
65 readline_write_history( $historyFile );
67 $val = eval( $line . ";" );
68 if( is_null( $val ) ) {
70 } elseif( is_string( $val ) ||
is_numeric( $val ) ) {
80 $maintClass = "EvalPrompt";
81 require_once( DO_MAINTENANCE
);