r54839 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54838‎ | r54839 | r54840 >
Date:03:44, 12 August 2009
Author:tstarling
Status:ok (Comments)
Tags:
Comment:
Revert eval.php changes from r54653, r54312, r54225 (maintenance-work branch merge), these changes totally broke eval.php due to the change in scope, from global to function.
Modified paths:
  • /trunk/phase3/maintenance/eval.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/eval.php
@@ -12,85 +12,61 @@
1313 * To get decent line editing behavior, you should compile PHP with support
1414 * for GNU readline (pass --with-readline to configure).
1515 *
16 - * This program is free software; you can redistribute it and/or modify
17 - * it under the terms of the GNU General Public License as published by
18 - * the Free Software Foundation; either version 2 of the License, or
19 - * (at your option) any later version.
20 - *
21 - * This program is distributed in the hope that it will be useful,
22 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 - * GNU General Public License for more details.
25 - *
26 - * You should have received a copy of the GNU General Public License along
27 - * with this program; if not, write to the Free Software Foundation, Inc.,
28 - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 - * http://www.gnu.org/copyleft/gpl.html
30 - *
 16+ * @file
3117 * @ingroup Maintenance
3218 */
3319
34 -require_once( dirname(__FILE__) . '/Maintenance.php' );
 20+$wgUseNormalUser = (bool)getenv('MW_WIKIUSER');
3521
36 -class EvalPrompt extends Maintenance {
 22+$optionsWithArgs = array( 'd' );
3723
38 - public function __construct() {
39 - global $wgUseNormalUser;
40 - parent::__construct();
41 - $this->mDescription = "This script lets a command-line user start up the wiki engine and then poke\n" .
42 - "about by issuing PHP commands directly.";
43 - $this->addOption( 'd', "Enable MediaWiki debug output", false, true );
44 - $wgUseNormalUser = (bool)getenv('MW_WIKIUSER');
 24+/** */
 25+require_once( "commandLine.inc" );
 26+
 27+if ( isset( $options['d'] ) ) {
 28+ $d = $options['d'];
 29+ if ( $d > 0 ) {
 30+ $wgDebugLogFile = '/dev/stdout';
4531 }
46 -
47 - public function execute() {
48 - global $wgDebugFunctionEntry, $wgDebugLogFile;
49 - if ( $this->hasOption('d') ) {
50 - $d = $this->getOption('d');
51 - if ( $d > 0 ) {
52 - $wgDebugLogFile = '/dev/stdout';
53 - }
54 - if ( $d > 1 ) {
55 - $lb = wfGetLB();
56 - foreach ( $lb->mServers as $i => $server ) {
57 - $lb->mServers[$i]['flags'] |= DBO_DEBUG;
58 - }
59 - }
60 - if ( $d > 2 ) {
61 - $wgDebugFunctionEntry = true;
62 - }
 32+ if ( $d > 1 ) {
 33+ $lb = wfGetLB();
 34+ foreach ( $lb->mServers as $i => $server ) {
 35+ $lb->mServers[$i]['flags'] |= DBO_DEBUG;
6336 }
64 -
65 - if ( function_exists( 'readline_add_history' )
66 - && function_exists( 'posix_isatty' ) && posix_isatty( 0 /*STDIN*/ ) )
67 - {
68 - $useReadline = true;
69 - } else {
70 - $useReadline = false;
71 - }
72 -
73 - if ( $useReadline ) {
74 - $historyFile = "{$_ENV['HOME']}/.mweval_history";
75 - readline_read_history( $historyFile );
76 - }
77 -
78 - while ( ( $line = readconsole( '> ' ) ) !== false ) {
79 - if ( $useReadline ) {
80 - readline_add_history( $line );
81 - readline_write_history( $historyFile );
82 - }
83 - $val = eval( $line . ";" );
84 - if( is_null( $val ) ) {
85 - echo "\n";
86 - } elseif( is_string( $val ) || is_numeric( $val ) ) {
87 - echo "$val\n";
88 - } else {
89 - var_dump( $val );
90 - }
91 - }
92 - print "\n";
9337 }
 38+ if ( $d > 2 ) {
 39+ $wgDebugFunctionEntry = true;
 40+ }
9441 }
9542
96 -$maintClass = "EvalPrompt";
97 -require_once( DO_MAINTENANCE );
 43+if ( function_exists( 'readline_add_history' )
 44+ && function_exists( 'posix_isatty' ) && posix_isatty( 0 /*STDIN*/ ) )
 45+{
 46+ $useReadline = true;
 47+} else {
 48+ $useReadline = false;
 49+}
 50+
 51+if ( $useReadline ) {
 52+ $historyFile = "{$_ENV['HOME']}/.mweval_history";
 53+ readline_read_history( $historyFile );
 54+}
 55+
 56+while ( ( $line = readconsole( '> ' ) ) !== false ) {
 57+ if ( $useReadline ) {
 58+ readline_add_history( $line );
 59+ readline_write_history( $historyFile );
 60+ }
 61+ $val = eval( $line . ";" );
 62+ if( is_null( $val ) ) {
 63+ echo "\n";
 64+ } elseif( is_string( $val ) || is_numeric( $val ) ) {
 65+ echo "$val\n";
 66+ } else {
 67+ var_dump( $val );
 68+ }
 69+}
 70+
 71+print "\n";
 72+
 73+

Follow-up revisions

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

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r54225Merge maintenance-work branch (now with less errors!):...demon19:35, 2 August 2009
r54312Revert r54244 which was stupid and fix this properly. Require commandLine.inc...demon21:56, 3 August 2009
r54653Move $wgUseNormalUser setting to constructors.demon12:26, 9 August 2009

Comments

#Comment by Catrope (talk | contribs)   08:26, 12 August 2009

How does it "totally break"? Some basic tests of eval.php with this revision undone work just fine for me.

#Comment by Bryan (talk | contribs)   10:37, 12 August 2009

Vars need to be explicitly defined as global, which is annoying. Is there some way in PHP to inject all globals in the local variable space?

#Comment by Bryan (talk | contribs)   10:41, 12 August 2009

Could probably do extract( $GLOBALS, EXTR_OVERWRITE | EXTR_REFS ); Still that does not insert local variables into the global space.

#Comment by Tim Starling (talk | contribs)   04:14, 16 August 2009

It's annoying and a b/c break. What's wrong with how it was before?

Status & tagging log