2004-06-02 02:16:40 +00:00
|
|
|
<?php
|
2004-09-03 20:33:01 +00:00
|
|
|
/**
|
2004-11-15 00:15:58 +00:00
|
|
|
* This script lets a command-line user start up the wiki engine and then poke
|
|
|
|
|
* about by issuing PHP commands directly.
|
|
|
|
|
*
|
|
|
|
|
* Unlike eg Python, you need to use a 'return' statement explicitly for the
|
|
|
|
|
* interactive shell to print out the value of the expression. Multiple lines
|
|
|
|
|
* are evaluated separately, so blocks need to be input without a line break.
|
|
|
|
|
* Fatal errors such as use of undeclared functions can kill the shell.
|
|
|
|
|
*
|
2006-01-07 13:09:30 +00:00
|
|
|
* To get decent line editing behavior, you should compile PHP with support
|
2004-11-15 00:15:58 +00:00
|
|
|
* for GNU readline (pass --with-readline to configure).
|
|
|
|
|
*
|
2010-12-16 19:15:12 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2009-08-12 03:44:06 +00:00
|
|
|
* @file
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Maintenance
|
2004-09-03 20:33:01 +00:00
|
|
|
*/
|
|
|
|
|
|
2017-04-27 23:56:38 +00:00
|
|
|
use MediaWiki\Logger\ConsoleSpi;
|
2020-01-10 00:00:51 +00:00
|
|
|
use MediaWiki\Logger\LoggerFactory;
|
2017-04-28 01:50:10 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2017-04-27 23:56:38 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$optionsWithArgs = [ 'd' ];
|
2020-12-10 03:02:53 +00:00
|
|
|
$optionsWithoutArgs = [ 'ignore-errors' ];
|
2005-04-12 04:03:21 +00:00
|
|
|
|
2020-09-23 10:52:01 +00:00
|
|
|
require_once __DIR__ . "/CommandLineInc.php";
|
2012-01-12 23:10:22 +00:00
|
|
|
|
2012-01-14 22:21:30 +00:00
|
|
|
if ( isset( $options['d'] ) ) {
|
|
|
|
|
$d = $options['d'];
|
|
|
|
|
if ( $d > 0 ) {
|
2017-04-27 23:56:38 +00:00
|
|
|
LoggerFactory::registerProvider( new ConsoleSpi );
|
2017-04-28 01:50:10 +00:00
|
|
|
// Some services hold Logger instances in object properties
|
|
|
|
|
MediaWikiServices::resetGlobalInstance();
|
2012-01-14 22:21:30 +00:00
|
|
|
}
|
|
|
|
|
if ( $d > 1 ) {
|
2021-04-29 02:37:11 +00:00
|
|
|
wfGetDB( DB_PRIMARY )->setFlag( DBO_DEBUG );
|
2017-04-28 01:50:10 +00:00
|
|
|
wfGetDB( DB_REPLICA )->setFlag( DBO_DEBUG );
|
2012-01-14 22:21:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
2009-08-12 03:44:06 +00:00
|
|
|
|
2020-12-10 03:02:53 +00:00
|
|
|
$__ignoreErrors = isset( $options['ignore-errors'] );
|
|
|
|
|
|
2014-10-18 22:37:56 +00:00
|
|
|
$__useReadline = function_exists( 'readline_add_history' )
|
2014-01-09 22:58:20 +00:00
|
|
|
&& Maintenance::posix_isatty( 0 /*STDIN*/ );
|
2009-08-12 03:44:06 +00:00
|
|
|
|
2014-10-18 22:37:56 +00:00
|
|
|
if ( $__useReadline ) {
|
|
|
|
|
$__historyFile = isset( $_ENV['HOME'] ) ?
|
2012-01-14 22:21:30 +00:00
|
|
|
"{$_ENV['HOME']}/.mweval_history" : "$IP/maintenance/.mweval_history";
|
2014-10-18 22:37:56 +00:00
|
|
|
readline_read_history( $__historyFile );
|
2012-01-14 22:21:30 +00:00
|
|
|
}
|
2012-01-12 23:10:22 +00:00
|
|
|
|
2020-08-26 07:40:40 +00:00
|
|
|
Hooks::runner()->onMaintenanceShellStart();
|
|
|
|
|
|
2014-10-18 22:37:56 +00:00
|
|
|
$__e = null; // PHP exception
|
|
|
|
|
while ( ( $__line = Maintenance::readconsole() ) !== false ) {
|
2020-12-10 03:02:53 +00:00
|
|
|
if ( !$__ignoreErrors && $__e && !preg_match( '/^(exit|die);?$/', $__line ) ) {
|
2014-01-09 22:58:20 +00:00
|
|
|
// Internal state may be corrupted or fatals may occur later due
|
|
|
|
|
// to some object not being set. Don't drop out of eval in case
|
|
|
|
|
// lines were being pasted in (which would then get dumped to the shell).
|
|
|
|
|
// Instead, just absorb the remaning commands. Let "exit" through per DWIM.
|
|
|
|
|
echo "Exception was thrown before; please restart eval.php\n";
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2014-10-18 22:37:56 +00:00
|
|
|
if ( $__useReadline ) {
|
|
|
|
|
readline_add_history( $__line );
|
|
|
|
|
readline_write_history( $__historyFile );
|
2012-01-14 22:21:30 +00:00
|
|
|
}
|
2014-01-09 22:58:20 +00:00
|
|
|
try {
|
2021-08-28 08:40:44 +00:00
|
|
|
// @phan-suppress-next-line SecurityCheck-RCE
|
2015-02-18 22:21:56 +00:00
|
|
|
$__val = eval( $__line . ";" );
|
2014-10-18 22:37:56 +00:00
|
|
|
} catch ( Exception $__e ) {
|
2018-10-19 18:45:54 +00:00
|
|
|
fwrite( STDERR, "Caught exception " . get_class( $__e ) .
|
|
|
|
|
": {$__e->getMessage()}\n" . $__e->getTraceAsString() . "\n" );
|
2014-01-09 22:58:20 +00:00
|
|
|
continue;
|
2020-12-10 03:02:53 +00:00
|
|
|
} catch ( Throwable $__e ) {
|
|
|
|
|
if ( $__ignoreErrors ) {
|
|
|
|
|
fwrite( STDERR, "Caught " . get_class( $__e ) .
|
|
|
|
|
": {$__e->getMessage()}\n" . $__e->getTraceAsString() . "\n" );
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
throw $__e;
|
|
|
|
|
}
|
2014-01-09 22:58:20 +00:00
|
|
|
}
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $__val === null ) {
|
2012-01-14 22:21:30 +00:00
|
|
|
echo "\n";
|
2014-10-18 22:37:56 +00:00
|
|
|
} elseif ( is_string( $__val ) || is_numeric( $__val ) ) {
|
|
|
|
|
echo "$__val\n";
|
2012-01-14 22:21:30 +00:00
|
|
|
} else {
|
2014-10-18 22:37:56 +00:00
|
|
|
var_dump( $__val );
|
2009-06-24 02:49:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-14 22:21:30 +00:00
|
|
|
print "\n";
|