[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/maintenance/ -> eval.php (source)

   1  <?php
   2  /**
   3   * This script lets a command-line user start up the wiki engine and then poke
   4   * about by issuing PHP commands directly.
   5   *
   6   * Unlike eg Python, you need to use a 'return' statement explicitly for the
   7   * interactive shell to print out the value of the expression. Multiple lines
   8   * are evaluated separately, so blocks need to be input without a line break.
   9   * Fatal errors such as use of undeclared functions can kill the shell.
  10   *
  11   * To get decent line editing behavior, you should compile PHP with support
  12   * for GNU readline (pass --with-readline to configure).
  13   *
  14   * This program is free software; you can redistribute it and/or modify
  15   * it under the terms of the GNU General Public License as published by
  16   * the Free Software Foundation; either version 2 of the License, or
  17   * (at your option) any later version.
  18   *
  19   * This program is distributed in the hope that it will be useful,
  20   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22   * GNU General Public License for more details.
  23   *
  24   * You should have received a copy of the GNU General Public License along
  25   * with this program; if not, write to the Free Software Foundation, Inc.,
  26   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  27   * http://www.gnu.org/copyleft/gpl.html
  28   *
  29   * @file
  30   * @ingroup Maintenance
  31   */
  32  
  33  $optionsWithArgs = array( 'd' );
  34  
  35  /** */
  36  require_once  __DIR__ . "/commandLine.inc";
  37  
  38  if ( isset( $options['d'] ) ) {
  39      $d = $options['d'];
  40      if ( $d > 0 ) {
  41          $wgDebugLogFile = '/dev/stdout';
  42      }
  43      if ( $d > 1 ) {
  44          $lb = wfGetLB();
  45          $serverCount = $lb->getServerCount();
  46          for ( $i = 0; $i < $serverCount; $i++ ) {
  47              $server = $lb->getServerInfo( $i );
  48              $server['flags'] |= DBO_DEBUG;
  49              $lb->setServerInfo( $i, $server );
  50          }
  51      }
  52      if ( $d > 2 ) {
  53          $wgDebugFunctionEntry = true;
  54      }
  55  }
  56  
  57  $useReadline = function_exists( 'readline_add_history' )
  58      && Maintenance::posix_isatty( 0 /*STDIN*/ );
  59  
  60  if ( $useReadline ) {
  61      $historyFile = isset( $_ENV['HOME'] ) ?
  62          "{$_ENV['HOME']}/.mweval_history" : "$IP/maintenance/.mweval_history";
  63      readline_read_history( $historyFile );
  64  }
  65  
  66  $e = null; // PHP exception
  67  while ( ( $line = Maintenance::readconsole() ) !== false ) {
  68      if ( $e && !preg_match( '/^(exit|die);?$/', $line ) ) {
  69          // Internal state may be corrupted or fatals may occur later due
  70          // to some object not being set. Don't drop out of eval in case
  71          // lines were being pasted in (which would then get dumped to the shell).
  72          // Instead, just absorb the remaning commands. Let "exit" through per DWIM.
  73          echo "Exception was thrown before; please restart eval.php\n";
  74          continue;
  75      }
  76      if ( $useReadline ) {
  77          readline_add_history( $line );
  78          readline_write_history( $historyFile );
  79      }
  80      try {
  81          $val = eval( $line . ";" );
  82      } catch ( Exception $e ) {
  83          echo "Caught exception " . get_class( $e ) .
  84              ": {$e->getMessage()}\n" . $e->getTraceAsString() . "\n";
  85          continue;
  86      }
  87      if ( wfIsHHVM() || is_null( $val ) ) {
  88          echo "\n";
  89      } elseif ( is_string( $val ) || is_numeric( $val ) ) {
  90          echo "$val\n";
  91      } else {
  92          var_dump( $val );
  93      }
  94  }
  95  
  96  print "\n";


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1