PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/maintenance/eval.php

https://bitbucket.org/ghostfreeman/freeside-wiki
PHP | 84 lines | 43 code | 9 blank | 32 comment | 13 complexity | 653cbe9a0d42afd0c08a01db026708d2 MD5 | raw file
Possible License(s): GPL-2.0, Apache-2.0, LGPL-3.0
  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. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License along
  26. * with this program; if not, write to the Free Software Foundation, Inc.,
  27. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  28. * http://www.gnu.org/copyleft/gpl.html
  29. *
  30. * @file
  31. * @ingroup Maintenance
  32. */
  33. $optionsWithArgs = array( 'd' );
  34. /** */
  35. require_once( __DIR__ . "/commandLine.inc" );
  36. if ( isset( $options['d'] ) ) {
  37. $d = $options['d'];
  38. if ( $d > 0 ) {
  39. $wgDebugLogFile = '/dev/stdout';
  40. }
  41. if ( $d > 1 ) {
  42. $lb = wfGetLB();
  43. $serverCount = $lb->getServerCount();
  44. for ( $i = 0; $i < $serverCount; $i++ ) {
  45. $server = $lb->getServerInfo( $i );
  46. $server['flags'] |= DBO_DEBUG;
  47. $lb->setServerInfo( $i, $server );
  48. }
  49. }
  50. if ( $d > 2 ) {
  51. $wgDebugFunctionEntry = true;
  52. }
  53. }
  54. $useReadline = function_exists( 'readline_add_history' )
  55. && Maintenance::posix_isatty( 0 /*STDIN*/ );
  56. if ( $useReadline ) {
  57. $historyFile = isset( $_ENV['HOME'] ) ?
  58. "{$_ENV['HOME']}/.mweval_history" : "$IP/maintenance/.mweval_history";
  59. readline_read_history( $historyFile );
  60. }
  61. while ( ( $line = Maintenance::readconsole() ) !== false ) {
  62. if ( $useReadline ) {
  63. readline_add_history( $line );
  64. readline_write_history( $historyFile );
  65. }
  66. $val = eval( $line . ";" );
  67. if ( wfIsHipHop() || is_null( $val ) ) {
  68. echo "\n";
  69. } elseif ( is_string( $val ) || is_numeric( $val ) ) {
  70. echo "$val\n";
  71. } else {
  72. var_dump( $val );
  73. }
  74. }
  75. print "\n";