r108777 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108776‎ | r108777 | r108778 >
Date:23:10, 12 January 2012
Author:reedy
Status:reverted (Comments)
Tags:
Comment:
Maintenance class-ify eval.php
Modified paths:
  • /trunk/phase3/maintenance/eval.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/eval.php
@@ -31,54 +31,69 @@
3232 * @ingroup Maintenance
3333 */
3434
35 -$optionsWithArgs = array( 'd' );
 35+require_once( dirname( __FILE__ ) . '/Maintenance.php' );
3636
37 -/** */
38 -require_once( dirname( __FILE__ ) . "/commandLine.inc" );
 37+class MwEval extends Maintenance {
 38+ public function __construct() {
 39+ parent::__construct();
 40+ $this->mDescription = "This script lets a command-line user start up the wiki engine and then poke about by issuing PHP commands directly.";
 41+ $this->addOption( 'd', 'Debug level' );
 42+ }
3943
40 -if ( isset( $options['d'] ) ) {
41 - $d = $options['d'];
42 - if ( $d > 0 ) {
43 - $wgDebugLogFile = '/dev/stdout';
44 - }
45 - if ( $d > 1 ) {
46 - $lb = wfGetLB();
47 - $serverCount = $lb->getServerCount();
48 - for ( $i = 0; $i < $serverCount; $i++ ) {
49 - $server = $lb->getServerInfo( $i );
50 - $server['flags'] |= DBO_DEBUG;
51 - $lb->setServerInfo( $i, $server );
 44+ public function execute() {
 45+ if ( $this->hasOption( 'd' ) ) {
 46+ $d = $this->getOption( 'd' );
 47+
 48+ if ( $d > 0 ) {
 49+ global $wgDebugLogFile;
 50+ $wgDebugLogFile = '/dev/stdout';
 51+ }
 52+ if ( $d > 1 ) {
 53+ $lb = wfGetLB();
 54+ $serverCount = $lb->getServerCount();
 55+ for ( $i = 0; $i < $serverCount; $i++ ) {
 56+ $server = $lb->getServerInfo( $i );
 57+ $server['flags'] |= DBO_DEBUG;
 58+ $lb->setServerInfo( $i, $server );
 59+ }
 60+ }
 61+ if ( $d > 2 ) {
 62+ global $wgDebugFunctionEntry;
 63+ $wgDebugFunctionEntry = true;
 64+ }
5265 }
53 - }
54 - if ( $d > 2 ) {
55 - $wgDebugFunctionEntry = true;
56 - }
57 -}
5866
59 -$useReadline = function_exists( 'readline_add_history' )
60 - && Maintenance::posix_isatty( 0 /*STDIN*/ );
 67+ $useReadline = function_exists( 'readline_add_history' )
 68+ && Maintenance::posix_isatty( 0 /*STDIN*/ );
6169
62 -if ( $useReadline ) {
63 - $historyFile = isset( $_ENV['HOME'] ) ?
64 - "{$_ENV['HOME']}/.mweval_history" : "$IP/maintenance/.mweval_history";
65 - readline_read_history( $historyFile );
66 -}
 70+ if ( $useReadline ) {
 71+ global $IP;
 72+ $historyFile = isset( $_ENV['HOME'] ) ?
 73+ "{$_ENV['HOME']}/.mweval_history" : "$IP/maintenance/.mweval_history";
 74+ readline_read_history( $historyFile );
 75+ }
6776
68 -while ( ( $line = Maintenance::readconsole() ) !== false ) {
69 - if ( $useReadline ) {
70 - readline_add_history( $line );
71 - readline_write_history( $historyFile );
 77+ while ( ( $line = Maintenance::readconsole() ) !== false ) {
 78+ if ( $useReadline ) {
 79+ readline_add_history( $line );
 80+ readline_write_history( $historyFile );
 81+ }
 82+ $val = eval( $line . ";" );
 83+ if ( wfIsHipHop() || is_null( $val ) ) {
 84+ $this->output( "\n" );
 85+ echo "\n";
 86+ } elseif ( is_string( $val ) || is_numeric( $val ) ) {
 87+ $this->output( "$val\n" );
 88+ } else {
 89+ $var = '';
 90+ var_export( $val, $var );
 91+ $this->output( "$var" );
 92+ }
 93+ }
 94+
 95+ $this->output( "\n" );
7296 }
73 - $val = eval( $line . ";" );
74 - if ( wfIsHipHop() || is_null( $val ) ) {
75 - echo "\n";
76 - } elseif ( is_string( $val ) || is_numeric( $val ) ) {
77 - echo "$val\n";
78 - } else {
79 - var_dump( $val );
80 - }
8197 }
8298
83 -print "\n";
84 -
85 -
 99+$maintClass = "MwEval";
 100+require_once( RUN_MAINTENANCE_IF_MAIN );

Follow-up revisions

RevisionCommit summaryAuthorDate
r108942Revert r108777 (making eval subclass maintenance). eval's supposed to be in t...demon22:21, 14 January 2012

Comments

#Comment by 😂 (talk | contribs)   04:58, 13 January 2012

I did this before, but Tim reverted me because eval.php should be run in the global context.

#Comment by Skizzerz (talk | contribs)   05:24, 13 January 2012

possible workaround is to loop through $GLOBALS and global each of them, which will emulate global context.

#Comment by Reedy (talk | contribs)   16:58, 13 January 2012

Hmm. Whenever I used it, I just always did "global $wgUser;" etc first...

Status & tagging log