MediaWiki  1.30.0
shell.php
Go to the documentation of this file.
1 <?php
40 
41 require_once __DIR__ . '/Maintenance.php';
42 
47 class MediaWikiShell extends Maintenance {
48 
49  public function __construct() {
50  parent::__construct();
51  $this->addOption( 'd',
52  'For back compatibility with eval.php. ' .
53  '1 send debug to stderr. ' .
54  'With 2 additionally initialize database with debugging ',
55  false, true
56  );
57  }
58 
59  public function execute() {
60  if ( !class_exists( \Psy\Shell::class ) ) {
61  $this->error( 'PsySH not found. Please run composer with the --dev option.', 1 );
62  }
63 
64  $traverser = new \PhpParser\NodeTraverser();
65  $codeCleaner = new \Psy\CodeCleaner( null, null, $traverser );
66 
67  // add this after initializing the code cleaner so all the default passes get added first
68  $traverser->addVisitor( new CodeCleanerGlobalsPass() );
69 
70  $config = new \Psy\Configuration( [ 'codeCleaner' => $codeCleaner ] );
71  $config->setUpdateCheck( \Psy\VersionUpdater\Checker::NEVER );
72  $shell = new \Psy\Shell( $config );
73  if ( $this->hasOption( 'd' ) ) {
74  $this->setupLegacy();
75  }
76 
77  $shell->run();
78  }
79 
83  protected function setupLegacy() {
84  $d = intval( $this->getOption( 'd' ) );
85  if ( $d > 0 ) {
86  LoggerFactory::registerProvider( new ConsoleSpi );
87  // Some services hold Logger instances in object properties
88  MediaWikiServices::resetGlobalInstance();
89  }
90  if ( $d > 1 ) {
91  # Set DBO_DEBUG (equivalent of $wgDebugDumpSql)
92  wfGetDB( DB_MASTER )->setFlag( DBO_DEBUG );
93  wfGetDB( DB_REPLICA )->setFlag( DBO_DEBUG );
94  }
95  }
96 
97 }
98 
99 $maintClass = 'MediaWikiShell';
100 require_once RUN_MAINTENANCE_IF_MAIN;
MediaWikiShell
Interactive shell with completion and global scope.
Definition: shell.php:47
MediaWikiShell\execute
execute()
Do the actual work.
Definition: shell.php:59
DBO_DEBUG
const DBO_DEBUG
Definition: defines.php:9
MediaWikiShell\__construct
__construct()
Default constructor.
Definition: shell.php:49
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
MediaWikiShell\setupLegacy
setupLegacy()
For back compatibility with eval.php.
Definition: shell.php:83
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2856
Configuration
MediaWiki s SiteStore can be cached and stored in a flat in a json format If the SiteStore is frequently the file cache may provide a performance benefit over a database even with memcached in front of it Configuration
Definition: sitescache.txt:1
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:215
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
DB_MASTER
const DB_MASTER
Definition: defines.php:26
$maintClass
$maintClass
Definition: shell.php:99
CodeCleanerGlobalsPass
Prefix the real command with a bunch of 'global $VAR;' commands, one for each global.
Definition: CodeCleanerGlobalsPass.inc:36
MediaWiki\Logger\ConsoleSpi
Definition: ConsoleSpi.php:4
Maintenance\$config
Config $config
Accessible via getConfig()
Definition: Maintenance.php:130
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:250
LoggerFactory
MediaWiki Logger LoggerFactory implements a PSR[0] compatible message logging system Named Psr Log LoggerInterface instances can be obtained from the MediaWiki Logger LoggerFactory::getInstance() static method. MediaWiki\Logger\LoggerFactory expects a class implementing the MediaWiki\Logger\Spi interface to act as a factory for new Psr\Log\LoggerInterface instances. The "Spi" in MediaWiki\Logger\Spi stands for "service provider interface". An SPI is an API intended to be implemented or extended by a third party. This software design pattern is intended to enable framework extension and replaceable components. It is specifically used in the MediaWiki\Logger\LoggerFactory service to allow alternate PSR-3 logging implementations to be easily integrated with MediaWiki. The service provider interface allows the backend logging library to be implemented in multiple ways. The $wgMWLoggerDefaultSpi global provides the classname of the default MediaWiki\Logger\Spi implementation to be loaded at runtime. This can either be the name of a class implementing the MediaWiki\Logger\Spi with a zero argument const ructor or a callable that will return an MediaWiki\Logger\Spi instance. Alternately the MediaWiki\Logger\LoggerFactory MediaWiki Logger LoggerFactory
Definition: logger.txt:5
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:392
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
MediaWikiServices
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular param exists.
Definition: Maintenance.php:236