3 * Modern interactive shell within the MediaWiki engine.
5 * Merely wraps around http://psysh.org/ and drop an interactive PHP shell in
8 * Copyright © 2017 Antoine Musso <hashar@free.fr>
9 * Copyright © 2017 Gergő Tisza <tgr.huwiki@gmail.com>
10 * Copyright © 2017 Justin Hileman <justin@justinhileman.info>
11 * Copyright © 2017 Wikimedia Foundation Inc.
12 * https://www.mediawiki.org/
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.
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.
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
30 * @ingroup Maintenance
32 * @author Antoine Musso <hashar@free.fr>
33 * @author Justin Hileman <justin@justinhileman.info>
34 * @author Gergő Tisza <tgr.huwiki@gmail.com>
37 use MediaWiki\Logger\LoggerFactory
;
38 use MediaWiki\Logger\ConsoleSpi
;
40 require_once __DIR__
. '/Maintenance.php';
43 * Interactive shell with completion and global scope.
46 class MediaWikiShell
extends Maintenance
{
48 public function __construct() {
49 parent
::__construct();
50 $this->addOption( 'd',
51 'For back compatibility with eval.php. ' .
52 '0 send debug to stderr. ' .
53 'With 1 additionally initialize database with debugging ',
58 public function execute() {
59 if ( !class_exists( \Psy\Shell
::class ) ) {
60 $this->error( 'PsySH not found. Please run composer with the --dev option.', 1 );
63 $traverser = new \PhpParser\
NodeTraverser();
64 $codeCleaner = new \Psy\
CodeCleaner( null, null, $traverser );
66 // add this after initializing the code cleaner so all the default passes get added first
67 $traverser->addVisitor( new CodeCleanerGlobalsPass() );
69 $config = new \Psy\
Configuration( [ 'codeCleaner' => $codeCleaner ] );
70 $config->setUpdateCheck( \Psy\VersionUpdater\Checker
::NEVER
);
71 $shell = new \Psy\
Shell( $config );
72 if ( $this->hasOption( 'd' ) ) {
80 * For back compatibility with eval.php
82 protected function setupLegacy() {
83 $d = intval( $this->getOption( 'd' ) );
85 LoggerFactory
::registerProvider( new ConsoleSpi
);
88 # Set DBO_DEBUG (equivalent of $wgDebugDumpSql)
89 # XXX copy pasted from eval.php :(
91 $serverCount = $lb->getServerCount();
92 for ( $i = 0; $i < $serverCount; $i++
) {
93 $server = $lb->getServerInfo( $i );
94 $server['flags'] |
= DBO_DEBUG
;
95 $lb->setServerInfo( $i, $server );
102 $maintClass = 'MediaWikiShell';
103 require_once RUN_MAINTENANCE_IF_MAIN
;