MediaWiki  REL1_31
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->fatalError( 'PsySH not found. Please run composer with the --dev option.' );
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 
100 require_once RUN_MAINTENANCE_IF_MAIN;
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
MediaWikiShell
Interactive shell with completion and global scope.
Definition: shell.php:47
Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition: Maintenance.php:439
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
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:37
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2812
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:16
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:219
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
DB_MASTER
const DB_MASTER
Definition: defines.php:29
$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:134
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:254
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
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:56
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:25
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular param exists.
Definition: Maintenance.php:240