MediaWiki  1.29.2
shell.php
Go to the documentation of this file.
1 <?php
37 require_once __DIR__ . '/Maintenance.php';
38 
43 class MediaWikiShell extends Maintenance {
44 
45  public function __construct() {
46  parent::__construct();
47  $this->addOption( 'd',
48  'For back compatibility with eval.php. ' .
49  '0 send debug to stdout. ' .
50  'With 1 additionally initialize database with debugging ',
51  false, true
52  );
53  }
54 
55  public function execute() {
56  if ( !class_exists( \Psy\Shell::class ) ) {
57  $this->error( 'PsySH not found. Please run composer with the --dev option.', 1 );
58  }
59 
60  $traverser = new \PhpParser\NodeTraverser();
61  $codeCleaner = new \Psy\CodeCleaner( null, null, $traverser );
62 
63  // add this after initializing the code cleaner so all the default passes get added first
64  $traverser->addVisitor( new CodeCleanerGlobalsPass() );
65 
66  $config = new \Psy\Configuration( [ 'codeCleaner' => $codeCleaner ] );
67  $config->setUpdateCheck( \Psy\VersionUpdater\Checker::NEVER );
68  $shell = new \Psy\Shell( $config );
69  if ( $this->hasOption( 'd' ) ) {
70  $this->setupLegacy();
71  }
72 
73  $shell->run();
74  }
75 
79  protected function setupLegacy() {
80  global $wgDebugLogFile;
81 
82  $d = intval( $this->getOption( 'd' ) );
83  if ( $d > 0 ) {
84  $wgDebugLogFile = 'php://stdout';
85  }
86  if ( $d > 1 ) {
87  # Set DBO_DEBUG (equivalent of $wgDebugDumpSql)
88  # XXX copy pasted from eval.php :(
89  $lb = wfGetLB();
90  $serverCount = $lb->getServerCount();
91  for ( $i = 0; $i < $serverCount; $i++ ) {
92  $server = $lb->getServerInfo( $i );
93  $server['flags'] |= DBO_DEBUG;
94  $lb->setServerInfo( $i, $server );
95  }
96  }
97  }
98 
99 }
100 
101 $maintClass = 'MediaWikiShell';
102 require_once RUN_MAINTENANCE_IF_MAIN;
MediaWikiShell
Interactive shell with completion and global scope.
Definition: shell.php:43
wfGetLB
wfGetLB( $wiki=false)
Get a load balancer object.
Definition: GlobalFunctions.php:3073
MediaWikiShell\execute
execute()
Do the actual work.
Definition: shell.php:55
DBO_DEBUG
const DBO_DEBUG
Definition: defines.php:9
MediaWikiShell\__construct
__construct()
Default constructor.
Definition: shell.php:45
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:79
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
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
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
$maintClass
$maintClass
Definition: shell.php:101
CodeCleanerGlobalsPass
Prefix the real command with a bunch of 'global $VAR;' commands, one for each global.
Definition: CodeCleanerGlobalsPass.inc:36
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
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
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular param exists.
Definition: Maintenance.php:236