Merge "revert gerrit change 29597 for TextContent constructor"
[lhc/web/wiklou.git] / maintenance / eval.php
index c25c8d6..69cf548 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
+ * @file
  * @ingroup Maintenance
  */
 
-require_once( dirname(__FILE__) . '/Maintenance.php' );
+$optionsWithArgs = array( 'd' );
 
-class EvalPrompt extends Maintenance {
+/** */
+require_once( __DIR__ . "/commandLine.inc" );
 
-       public function __construct() {
-               parent::__construct();
-               $this->mDescription = "This script lets a command-line user start up the wiki engine and then poke\n" .
-                                                               "about by issuing PHP commands directly.";
-               $this->addOption( 'd', "Enable MediaWiki debug output", false, true );
+if ( isset( $options['d'] ) ) {
+       $d = $options['d'];
+       if ( $d > 0 ) {
+               $wgDebugLogFile = '/dev/stdout';
        }
-       
-       public function execute() {
-               global $wgUseNormalUser, $wgDebugFunctionEntry, $wgDebugLogFile;
-               $wgUseNormalUser = (bool)getenv('MW_WIKIUSER');
-               if ( $this->hasOption('d') ) {
-                       $d = $this->getOption('d');
-                       if ( $d > 0 ) {
-                               $wgDebugLogFile = '/dev/stdout';
-                       }
-                       if ( $d > 1 ) {
-                               $lb = wfGetLB();
-                               foreach ( $lb->mServers as $i => $server ) {
-                                       $lb->mServers[$i]['flags'] |= DBO_DEBUG;
-                               }
-                       }
-                       if ( $d > 2 ) {
-                               $wgDebugFunctionEntry = true;
-                       }
+       if ( $d > 1 ) {
+               $lb = wfGetLB();
+               $serverCount = $lb->getServerCount();
+               for ( $i = 0; $i < $serverCount; $i++ ) {
+                       $server = $lb->getServerInfo( $i );
+                       $server['flags'] |= DBO_DEBUG;
+                       $lb->setServerInfo( $i, $server );
                }
-       
-               if ( function_exists( 'readline_add_history' ) 
-                       && function_exists( 'posix_isatty' ) && posix_isatty( 0 /*STDIN*/ ) ) 
-               {
-                       $useReadline = true;
-               } else {
-                       $useReadline = false;
-               }
-       
-               if ( $useReadline ) {
-                       $historyFile = "{$_ENV['HOME']}/.mweval_history";
-                       readline_read_history( $historyFile );
-               }
-       
-               while ( ( $line = readconsole( '> ' ) ) !== false ) {
-                       if ( $useReadline ) {
-                               readline_add_history( $line );
-                               readline_write_history( $historyFile );
-                       }
-                       $val = eval( $line . ";" );
-                       if( is_null( $val ) ) {
-                               echo "\n";
-                       } elseif( is_string( $val ) || is_numeric( $val ) ) {
-                               echo "$val\n";
-                       } else {
-                               var_dump( $val );
-                       }
-               }
-               print "\n";
        }
+       if ( $d > 2 ) {
+               $wgDebugFunctionEntry = true;
+       }
+}
+
+$useReadline = function_exists( 'readline_add_history' )
+                       && Maintenance::posix_isatty( 0 /*STDIN*/ );
+
+if ( $useReadline ) {
+       $historyFile = isset( $_ENV['HOME'] ) ?
+               "{$_ENV['HOME']}/.mweval_history" : "$IP/maintenance/.mweval_history";
+       readline_read_history( $historyFile );
 }
 
-$maintClass = "EvalPrompt";
-require_once( DO_MAINTENANCE );
+while ( ( $line = Maintenance::readconsole() ) !== false ) {
+       if ( $useReadline ) {
+               readline_add_history( $line );
+               readline_write_history( $historyFile );
+       }
+       $val = eval( $line . ";" );
+       if ( wfIsHipHop() || is_null( $val ) ) {
+               echo "\n";
+       } elseif ( is_string( $val ) || is_numeric( $val ) ) {
+               echo "$val\n";
+       } else {
+               var_dump( $val );
+       }
+}
+
+print "\n";
+
+